use of com.gargoylesoftware.htmlunit.javascript.host.Window in project htmlunit by HtmlUnit.
the class HTMLElement method setActive.
/**
* Sets the object as active without setting focus to the object.
* @see <a href="http://msdn.microsoft.com/en-us/library/ms536738.aspx">MSDN documentation</a>
*/
@JsxFunction(IE)
public void setActive() {
final Window window = getWindow();
final HTMLDocument document = (HTMLDocument) window.getDocument();
document.setActiveElement(this);
if (window.getWebWindow() == window.getWebWindow().getWebClient().getCurrentWindow()) {
final HtmlElement element = getDomNodeOrDie();
((HtmlPage) element.getPage()).setFocusedElement(element);
}
}
use of com.gargoylesoftware.htmlunit.javascript.host.Window in project htmlunit by HtmlUnit.
the class XMLHTTPRequest method send.
/**
* Sends an HTTP request to the server and receives a response.
* @param body the body of the message being sent with the request.
*/
@JsxFunction
public void send(final Object body) {
if (webRequest_ == null) {
setState(STATE_DONE, Context.getCurrentContext());
return;
}
if (sent_) {
throw Context.reportRuntimeError("Unspecified error (request already sent).");
}
sent_ = true;
prepareRequest(body);
// quite strange but IE seems to fire state loading twice
setState(STATE_OPENED, Context.getCurrentContext());
final Window w = getWindow();
final WebClient client = w.getWebWindow().getWebClient();
final AjaxController ajaxController = client.getAjaxController();
final HtmlPage page = (HtmlPage) w.getWebWindow().getEnclosedPage();
final boolean synchron = ajaxController.processSynchron(page, webRequest_, async_);
if (synchron) {
doSend(Context.getCurrentContext());
} else {
// Create and start a thread in which to execute the request.
final ContextFactory cf = ((JavaScriptEngine) client.getJavaScriptEngine()).getContextFactory();
final ContextAction<Object> action = cx -> {
// KEY_STARTING_SCOPE maintains a stack of scopes
@SuppressWarnings("unchecked") Deque<Scriptable> stack = (Deque<Scriptable>) cx.getThreadLocal(JavaScriptEngine.KEY_STARTING_SCOPE);
if (null == stack) {
stack = new ArrayDeque<>();
cx.putThreadLocal(JavaScriptEngine.KEY_STARTING_SCOPE, stack);
}
stack.push(w);
try {
doSend(cx);
} finally {
stack.pop();
}
return null;
};
final JavaScriptJob job = BackgroundJavaScriptFactory.theFactory().createJavascriptXMLHttpRequestJob(cf, action);
if (LOG.isDebugEnabled()) {
LOG.debug("Starting XMLHTTPRequest thread for asynchronous request");
}
jobID_ = w.getWebWindow().getJobManager().addJob(job, page);
}
}
use of com.gargoylesoftware.htmlunit.javascript.host.Window in project htmlunit by HtmlUnit.
the class Crypto method getSubtle.
/**
* Returns the {@code subtle} property.
* @return the {@code stuble} property
*/
@JsxGetter({ CHROME, EDGE, FF, FF_ESR })
public SubtleCrypto getSubtle() {
final SubtleCrypto stuble = new SubtleCrypto();
final Window window = getWindow();
stuble.setParentScope(window);
stuble.setPrototype(window.getPrototype(SubtleCrypto.class));
return stuble;
}
use of com.gargoylesoftware.htmlunit.javascript.host.Window in project htmlunit by HtmlUnit.
the class WebClient method processOnlyHashChange.
private static void processOnlyHashChange(final WebWindow window, final URL urlWithOnlyHashChange) {
final Page page = window.getEnclosedPage();
final String oldURL = page.getUrl().toExternalForm();
// update request url
final WebRequest req = page.getWebResponse().getWebRequest();
req.setUrl(urlWithOnlyHashChange);
// update location.hash
final Window jsWindow = window.getScriptableObject();
if (null != jsWindow) {
final Location location = jsWindow.getLocation();
location.setHash(oldURL, urlWithOnlyHashChange.getRef());
}
// add to history
window.getHistory().addPage(page);
}
use of com.gargoylesoftware.htmlunit.javascript.host.Window in project htmlunit by HtmlUnit.
the class WebClient method setCurrentWindow.
/**
* Sets the "current" window for this client. This is the window that will be used when
* <tt>getPage(...)</tt> is called without specifying a window.
* @param window the new "current" window for this client
*/
public void setCurrentWindow(final WebWindow window) {
WebAssert.notNull("window", window);
if (currentWindow_ == window) {
return;
}
// onBlur event is triggered for focused element of old current window
if (currentWindow_ != null && !currentWindow_.isClosed()) {
final Page enclosedPage = currentWindow_.getEnclosedPage();
if (enclosedPage != null && enclosedPage.isHtmlPage()) {
final DomElement focusedElement = ((HtmlPage) enclosedPage).getFocusedElement();
if (focusedElement != null) {
focusedElement.fireEvent(Event.TYPE_BLUR);
}
}
}
currentWindow_ = window;
// when marking an iframe window as current we have no need to move the focus
final boolean isIFrame = currentWindow_ instanceof FrameWindow && ((FrameWindow) currentWindow_).getFrameElement() instanceof HtmlInlineFrame;
if (!isIFrame) {
// 1. activeElement becomes focused element for new current window
// 2. onFocus event is triggered for focusedElement of new current window
final Page enclosedPage = currentWindow_.getEnclosedPage();
if (enclosedPage != null && enclosedPage.isHtmlPage()) {
final Window jsWindow = currentWindow_.getScriptableObject();
if (jsWindow != null) {
final HTMLElement activeElement = ((HTMLDocument) jsWindow.getDocument()).getActiveElement();
if (activeElement != null) {
((HtmlPage) enclosedPage).setFocusedElement(activeElement.getDomNodeOrDie(), true);
}
}
}
}
}
Aggregations