Bug 1236452 - Fix DOMHelpers.onceDOMReady against already loaded documents. r=jryans

This commit is contained in:
Alexandre Poirot 2016-01-13 02:55:32 -08:00
parent 67993dab8c
commit 16bfcb7fa8
2 changed files with 9 additions and 4 deletions

View File

@ -356,7 +356,7 @@ Toolbox.prototype = {
iframe.setAttribute("src", this._URL);
iframe.setAttribute("aria-label", toolboxStrings("toolbox.label"));
let domHelper = new DOMHelpers(iframe.contentWindow);
domHelper.onceDOMReady(() => domReady.resolve());
domHelper.onceDOMReady(() => domReady.resolve(), this._URL);
// Optimization: fire up a few other things before waiting on
// the iframe being ready (makes startup faster)
@ -365,7 +365,6 @@ Toolbox.prototype = {
// Attach the thread
this._threadClient = yield attachThread(this);
yield domReady.promise;
this.isReady = true;

View File

@ -137,7 +137,7 @@ DOMHelpers.prototype = {
* chrome iframes are loaded in content docshells (in Firefox
* tabs for example).
*/
onceDOMReady: function Helpers_onLocationChange(callback) {
onceDOMReady: function Helpers_onLocationChange(callback, targetURL) {
let window = this.window;
let docShell = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
@ -151,6 +151,12 @@ DOMHelpers.prototype = {
Services.tm.mainThread.dispatch(callback, 0);
}
}
docShell.chromeEventHandler.addEventListener("DOMContentLoaded", onReady, false);
if ((window.document.readyState == "complete" ||
window.document.readyState == "interactive") &&
window.location.href == targetURL) {
Services.tm.mainThread.dispatch(callback, 0);
} else {
docShell.chromeEventHandler.addEventListener("DOMContentLoaded", onReady, false);
}
}
};