Due to the nature of the application I am writing I need to handle synchronous XMLHttpRequest. I have set the javascript up correctly so it blocks on the send command. I have created a scheme to intercept this request which works perfectly. The javascript does not continue exiting until my scheme handler calls callback->continue("") inside ProcessRequest.
However what I want to do inside ProcessRequest before I call continue on the callback is execute some javascript code using ExecuteJavaScript like so:
- Code: Select all
bool ResourceHandler::ProcessRequest(CefRefPtr<CefRequest> request, CefRefPtr<CefCallback> callback)
{
m_browser->GetMainFrame()->ExecuteJavaScript("alert(\"here\");", m_browser->GetMainFrame()->GetURL(), 0);
callback->Continue();
}
My javascript looks like:
- Code: Select all
function CreateXmlHttpRequest() {
var xmlHttp = null;
if (window.XMLHttpRequest) {
// For Mozilla, Safari, ...
xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlHttp;
}
var sendXml = function(eventName, detail) {
var xmlHttp = CreateXmlHttpRequest();
var para = "";
xmlHttp.open("POST", "http://testdomain/", false);
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttp.send(para);
alert("moved on");
};
Now I expected, and need, for the "here" alert sent from the c++ ExecuteJavaScript to appear before the "moved on" alert after the synchronous XMLHttpResquest has completed. I am guessing that ExecuteJavaScript is an asynchronous call which is how this is happening. Is there any way that I can address this?
Thanks