From db9586885f0db84769e8e36adafd1c01069081db Mon Sep 17 00:00:00 2001 From: Blair McBride Date: Tue, 18 Sep 2012 17:02:33 +1200 Subject: [PATCH] Bug 781689 - Remove usage of nsIDOMWindowUtils.goOnline() in mobile's netError.xhtml. r=mfinkle,f=bnicholson --- mobile/android/chrome/content/browser.js | 8 ++++++-- mobile/android/chrome/content/netError.xhtml | 8 ++------ mobile/xul/chrome/content/browser.js | 5 +++++ mobile/xul/chrome/content/content.js | 6 +++++- mobile/xul/chrome/content/netError.xhtml | 8 ++------ 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 58e62dce7d0f..8cd98df49df4 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -2694,9 +2694,9 @@ Tab.prototype = { // require error page UI to do privileged things, without letting error // pages have any privilege themselves. if (/^about:/.test(target.documentURI)) { - this.browser.addEventListener("click", ErrorPageEventHandler, false); + this.browser.addEventListener("click", ErrorPageEventHandler, true); let listener = function() { - this.browser.removeEventListener("click", ErrorPageEventHandler, false); + this.browser.removeEventListener("click", ErrorPageEventHandler, true); this.browser.removeEventListener("pagehide", listener, true); }.bind(this); @@ -4068,6 +4068,10 @@ var ErrorPageEventHandler = { } else if (target == errorDoc.getElementById("getMeOutOfHereButton")) { errorDoc.location = "about:home"; } + } else if (/^about:neterror\?e=netOffline/.test(ownerDoc.documentURI)) { + let tryAgain = errorDoc.getElementById("errorTryAgain"); + if (target == tryAgain) + Services.io.offline = false; } break; } diff --git a/mobile/android/chrome/content/netError.xhtml b/mobile/android/chrome/content/netError.xhtml index 089943b48d9e..3728306ef30c 100644 --- a/mobile/android/chrome/content/netError.xhtml +++ b/mobile/android/chrome/content/netError.xhtml @@ -76,12 +76,8 @@ function retryThis(buttonEl) { - // If this is the "Offline mode" page, go online! - if (getErrorCode() == "netOffline") { - window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) - .getInterface(Components.interfaces.nsIDOMWindowUtils) - .goOnline(); - } + // Note: The application may wish to handle switching off "offline mode" + // before this event handler runs, but using a capturing event handler. // Session history has the URL of the page that failed // to load, not the one of the error page. So, just call diff --git a/mobile/xul/chrome/content/browser.js b/mobile/xul/chrome/content/browser.js index a247dad8cb74..a2890d6ca4ef 100644 --- a/mobile/xul/chrome/content/browser.js +++ b/mobile/xul/chrome/content/browser.js @@ -385,6 +385,7 @@ var Browser = { messageManager.addMessageListener("Browser:CertException", this); messageManager.addMessageListener("Browser:BlockedSite", this); messageManager.addMessageListener("Browser:ErrorPage", this); + messageManager.addMessageListener("Browser:GoOnline", this); messageManager.addMessageListener("Browser:PluginClickToPlayClicked", this); // Broadcast a UIReady message so add-ons know we are finished with startup @@ -484,6 +485,7 @@ var Browser = { messageManager.removeMessageListener("Browser:CertException", this); messageManager.removeMessageListener("Browser:BlockedSite", this); messageManager.removeMessageListener("Browser:ErrorPage", this); + messageManager.removeMessageListener("Browser:GoOnline", this); messageManager.removeMessageListener("Browser:PluginClickToPlayClicked", this); var os = Services.obs; @@ -1265,6 +1267,9 @@ var Browser = { case "Browser:ErrorPage": this._handleErrorPage(aMessage); break; + case "Browser:GoOnline": + Services.io.offline = false; + break; case "Browser:PluginClickToPlayClicked": { // Save off session history let parent = browser.parentNode; diff --git a/mobile/xul/chrome/content/content.js b/mobile/xul/chrome/content/content.js index 0126afd17f73..07908bbc079b 100644 --- a/mobile/xul/chrome/content/content.js +++ b/mobile/xul/chrome/content/content.js @@ -292,7 +292,7 @@ let Content = { // pages and other similar page. This lets us fix bugs like 401575 which // require error page UI to do privileged things, without letting error // pages have any privilege themselves. - addEventListener("click", this, false); + addEventListener("click", this, true); docShell.QueryInterface(Ci.nsIDocShellHistory).useGlobalHistory = true; }, @@ -384,6 +384,10 @@ let Content = { // http://hg.mozilla.org/mozilla-central/file/855e5cd3c884/browser/base/content/browser.js#l2672 // http://hg.mozilla.org/mozilla-central/file/855e5cd3c884/browser/components/safebrowsing/content/globalstore.js } + } else if (/^about:neterror\?e=netOffline/.test(ownerDoc.documentURI)) { + let tryAgain = errorDoc.getElementById("errorTryAgain"); + if (target == tryAgain) + sendSyncMessage("Browser:GoOnline", { }); } break; } diff --git a/mobile/xul/chrome/content/netError.xhtml b/mobile/xul/chrome/content/netError.xhtml index 089943b48d9e..3728306ef30c 100644 --- a/mobile/xul/chrome/content/netError.xhtml +++ b/mobile/xul/chrome/content/netError.xhtml @@ -76,12 +76,8 @@ function retryThis(buttonEl) { - // If this is the "Offline mode" page, go online! - if (getErrorCode() == "netOffline") { - window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) - .getInterface(Components.interfaces.nsIDOMWindowUtils) - .goOnline(); - } + // Note: The application may wish to handle switching off "offline mode" + // before this event handler runs, but using a capturing event handler. // Session history has the URL of the page that failed // to load, not the one of the error page. So, just call