use of com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.IE 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);
}
}
Aggregations