From 50dfaff47437b204b81d0dcf9dcf9766f5bc1cdf Mon Sep 17 00:00:00 2001 From: "Patrick Wang (Chih-Kai Wang)" Date: Tue, 7 Jan 2014 14:39:32 +0800 Subject: [PATCH] Bug 913243 - Load ErrorPage.js only when error occurs. r=fabrice --- b2g/chrome/content/ErrorPage.js | 22 +++++++++++---- b2g/components/ErrorPage.jsm | 32 ++++++++++++++-------- dom/browser-element/BrowserElementChild.js | 5 ---- dom/ipc/preload.js | 5 ---- 4 files changed, 37 insertions(+), 27 deletions(-) diff --git a/b2g/chrome/content/ErrorPage.js b/b2g/chrome/content/ErrorPage.js index 3461da061ff6..cf8fc3532eac 100644 --- a/b2g/chrome/content/ErrorPage.js +++ b/b2g/chrome/content/ErrorPage.js @@ -8,6 +8,8 @@ let Cu = Components.utils; let Cc = Components.classes; let Ci = Components.interfaces; +dump("############ ErrorPage.js\n"); + let ErrorPageHandler = { _reload: function() { docShell.QueryInterface(Ci.nsIWebNavigation).reload(Ci.nsIWebNavigation.LOAD_FLAGS_NONE); @@ -31,12 +33,8 @@ let ErrorPageHandler = { } }, - domContentLoadedHandler: function(e) { - let target = e.originalTarget; - let targetDocShell = target.defaultView - .QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIWebNavigation); - if (targetDocShell != docShell) { + _bindPageEvent: function(target) { + if (!target) { return; } @@ -52,11 +50,23 @@ let ErrorPageHandler = { } }, + domContentLoadedHandler: function(e) { + let target = e.originalTarget; + let targetDocShell = target.defaultView + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation); + if (targetDocShell != docShell) { + return; + } + this._bindPageEvent(target); + }, + init: function() { addMessageListener("ErrorPage:ReloadPage", this._reload.bind(this)); addEventListener('DOMContentLoaded', this.domContentLoadedHandler.bind(this), true); + this._bindPageEvent(content.document); } }; diff --git a/b2g/components/ErrorPage.jsm b/b2g/components/ErrorPage.jsm index 1dbcb5334dcb..8d9c05516c42 100644 --- a/b2g/components/ErrorPage.jsm +++ b/b2g/components/ErrorPage.jsm @@ -149,6 +149,26 @@ let ErrorPage = { } }, + _listenError: function(frameLoader) { + let self = this; + let frameElement = frameLoader.ownerElement; + let injectErrorPageScript = function() { + let mm = frameLoader.messageManager; + try { + mm.loadFrameScript(kErrorPageFrameScript, true, true); + } catch (e) { + dump('Error loading ' + kErrorPageFrameScript + ' as frame script: ' + e + '\n'); + } + mm.addMessageListener('ErrorPage:AddCertException', self._addCertException.bind(self)); + frameElement.removeEventListener('mozbrowsererror', injectErrorPageScript, true); + }; + + frameElement.addEventListener('mozbrowsererror', + injectErrorPageScript, + true // use capture + ); + }, + init: function errorPageInit() { Services.obs.addObserver(this, 'in-process-browser-or-app-frame-shown', false); Services.obs.addObserver(this, 'remote-browser-frame-shown', false); @@ -156,17 +176,7 @@ let ErrorPage = { observe: function errorPageObserve(aSubject, aTopic, aData) { let frameLoader = aSubject.QueryInterface(Ci.nsIFrameLoader); - let mm = frameLoader.messageManager; - - // This won't happen from dom/ipc/preload.js in non-OOP builds. - try { - if (Services.prefs.getBoolPref("dom.ipc.tabs.disabled") === true) { - mm.loadFrameScript(kErrorPageFrameScript, true, true); - } - } catch (e) { - dump('Error loading ' + kErrorPageFrameScript + ' as frame script: ' + e + '\n'); - } - mm.addMessageListener('ErrorPage:AddCertException', this._addCertException.bind(this)); + this._listenError(frameLoader); } }; diff --git a/dom/browser-element/BrowserElementChild.js b/dom/browser-element/BrowserElementChild.js index 661b6c9e3b42..184a5d65fcdf 100644 --- a/dom/browser-element/BrowserElementChild.js +++ b/dom/browser-element/BrowserElementChild.js @@ -49,11 +49,6 @@ if (!('BrowserElementIsPreloaded' in this)) { } catch (e) { } } - // Those are produc-specific files that's sometimes unavailable. - try { - Services.scriptloader.loadSubScript("chrome://browser/content/ErrorPage.js"); - } catch (e) { - } Services.scriptloader.loadSubScript("chrome://global/content/BrowserElementPanning.js"); ContentPanning.init(); diff --git a/dom/ipc/preload.js b/dom/ipc/preload.js index b54faf76ca6e..4207def003ca 100644 --- a/dom/ipc/preload.js +++ b/dom/ipc/preload.js @@ -94,11 +94,6 @@ const BrowserElementIsPreloaded = true; } catch (e) { } - // Those are produc-specific files that's sometimes unavailable. - try { - Services.scriptloader.loadSubScript("chrome://browser/content/ErrorPage.js", global); - } catch (e) { - } Services.scriptloader.loadSubScript("chrome://global/content/BrowserElementPanning.js", global); Services.scriptloader.loadSubScript("chrome://global/content/BrowserElementChildPreload.js", global);