Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Bug 685865 - Don't special case tabs for mozmillDocumentLoaded. r=cta…
Browse files Browse the repository at this point in the history
…lbert
  • Loading branch information
whimboo committed Sep 9, 2011
1 parent 4b65fde commit e252680
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 44 deletions.
29 changes: 10 additions & 19 deletions mozmill/mozmill/extension/resource/modules/controller.js
Expand Up @@ -1268,35 +1268,26 @@ function browserAdditions (controller) {

controller.waitForPageLoad = function(aDocument, aTimeout, aInterval) {
var timeout = aTimeout || 30000;
var owner = null;
var win = null;

// If a user tries to do waitForPageLoad(2000), this will assign the
// interval the first arg which is most likely what they were expecting
if (typeof(aDocument) == "number"){
if (typeof(aDocument) === "number")
timeout = aDocument;
}

// If the document is a tab find the corresponding browser element.
// Otherwise we have to handle an embedded web page.
if (aDocument && typeof(aDocument) == "object") {
owner = this.window.gBrowser.getBrowserForDocument(aDocument);
if (aDocument && "defaultView" in aDocument)
win = aDocument.defaultView;

if (!owner) {
// If the document doesn't belong to a tab it will be a
// HTMLDocument of a browser element embedded inside a tab.
// In such a case use the default window of the document.
owner = aDocument.defaultView;
}
}

// If no owner has been specified, fallback to the selected tab browser
owner = owner || this.window.gBrowser.selectedBrowser;
// If no document has been specified, fallback to the default view of the
// currently selected tab browser
win = win || this.window.gBrowser.selectedBrowser.contentWindow;

// Wait until the content in the tab has been loaded
this.waitFor(function() {
return this.isLoaded(owner);
return this.isLoaded(win);
}, "controller.waitForPageLoad(): Timeout waiting for page loaded.",
timeout, aInterval, this);
timeout, aInterval, this);

frame.events.pass({'function':'controller.waitForPageLoad()'});
}
}
Expand Down
35 changes: 10 additions & 25 deletions mozmill/mozmill/extension/resource/modules/init.js
Expand Up @@ -59,51 +59,36 @@ function attachEventListeners(window) {
window.addEventListener("load", function (event) {
window.mozmillDocumentLoaded = true;

if (window.gBrowser) {
if ("gBrowser" in window) {
// Page is ready
window.gBrowser.addEventListener("load", function (event) {
// this is the content document of the loaded page.
var doc = event.originalTarget;
var tab = window.gBrowser.getBrowserForDocument(doc);

if (tab) {
//dump("*** Loaded tab: location=" + doc.location + ", baseURI=" + doc.baseURI + "\n");
tab.mozmillDocumentLoaded = true;
} else {
//dump("*** Loaded HTML location=" + doc.location + ", baseURI=" + doc.baseURI + "\n");
doc.defaultView.mozmillDocumentLoaded = true;
}
doc.defaultView.mozmillDocumentLoaded = true;
// dump("*** Window content loaded: " + doc.location + ", baseURI=" + doc.baseURI + "\n");
}, true);

// Note: Error pages will never fire a "load" event. For those we
// have to wait for the "DOMContentLoaded" event. That's the final state.
// Error pages will always have a baseURI starting with
// "about:" followed by "error" or "blocked".
window.gBrowser.addEventListener("DOMContentLoaded", function (event) {
var doc = event.originalTarget;

var errorRegex = /about:.+(error)|(blocked)\?/;
if (errorRegex.exec(event.target.baseURI)) {
if (errorRegex.exec(doc.baseURI)) {
// Wait about 1s to be sure the DOM is ready
mozmill.utils.sleep(1000);

var tab = window.gBrowser.getBrowserForDocument(event.target);
if (tab)
tab.mozmillDocumentLoaded = true;
doc.defaultView.mozmillDocumentLoaded = true;
// dump("*** Window content loaded: " + doc.location + ", baseURI=" + doc.baseURI + "\n");
}
}, true);

// Page is about to get unloaded
window.gBrowser.addEventListener("beforeunload", function (event) {
var doc = event.originalTarget;
var tab = window.gBrowser.getBrowserForDocument(event.target);

if (tab) {
//dump("*** Unload tab: location=" + doc.location + ", baseURI=" + doc.baseURI + "\n");
tab.mozmillDocumentLoaded = false;
} else {
//dump("*** Unload HTML location=" + doc.location + ", baseURI=" + doc.baseURI + "\n");
doc.defaultView.mozmillDocumentLoaded = false;
}

doc.defaultView.mozmillDocumentLoaded = false;
// dump("*** Window content unloaded: " + doc.location + ", baseURI=" + doc.baseURI + "\n");
}, true);
}
}, false);
Expand Down

0 comments on commit e252680

Please sign in to comment.