diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 3d9e6c397ba6..c6b1ee243013 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -109,9 +109,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "SharedPreferences", XPCOMUtils.defineLazyModuleGetter(this, "Notifications", "resource://gre/modules/Notifications.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "AboutReader", - "resource://gre/modules/AboutReader.jsm"); - XPCOMUtils.defineLazyModuleGetter(this, "ReaderMode", "resource://gre/modules/ReaderMode.jsm"); @@ -502,6 +499,8 @@ var BrowserApp = { // Tiles reporting is disabled. } + window.messageManager.loadFrameScript("chrome://browser/content/content.js", true); + // Notify Java that Gecko has loaded. Messaging.sendRequest({ type: "Gecko:Ready" }); }, @@ -3963,14 +3962,6 @@ Tab.prototype = { } if (docURI.startsWith("about:reader")) { - // During browser restart / recovery, duplicate "DOMContentLoaded" messages are received here - // For the visible tab ... where more than one tab is being reloaded, the inital "DOMContentLoaded" - // Message can be received before the document body is available ... so we avoid instantiating an - // AboutReader object, expecting that an eventual valid message will follow. - let contentDocument = this.browser.contentDocument; - if (contentDocument.body) { - new AboutReader(contentDocument, this.browser.contentWindow); - } // Update the page action to show the "reader active" icon. Reader.updatePageAction(this); } diff --git a/mobile/android/chrome/content/content.js b/mobile/android/chrome/content/content.js new file mode 100644 index 000000000000..68856538fdbb --- /dev/null +++ b/mobile/android/chrome/content/content.js @@ -0,0 +1,38 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +let { classes: Cc, interfaces: Ci, utils: Cu } = Components; + +Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); + +XPCOMUtils.defineLazyModuleGetter(this, "AboutReader", "resource://gre/modules/AboutReader.jsm"); + +let dump = Cu.import("resource://gre/modules/AndroidLog.jsm", {}).AndroidLog.d.bind(null, "Content"); + +let AboutReaderListener = { + init: function(chromeGlobal) { + chromeGlobal.addEventListener("AboutReaderContentLoaded", this, false, true); + }, + + handleEvent: function(event) { + if (!event.originalTarget.documentURI.startsWith("about:reader")) { + return; + } + + switch (event.type) { + case "AboutReaderContentLoaded": + // If we are restoring multiple reader mode tabs during session restore, duplicate "DOMContentLoaded" + // events may be fired for the visible tab. The inital "DOMContentLoaded" may be received before the + // document body is available, so we avoid instantiating an AboutReader object, expecting that a + // valid message will follow. See bug 925983. + if (content.document.body) { + new AboutReader(content.document, content); + } + break; + } + } +}; +AboutReaderListener.init(this); diff --git a/mobile/android/chrome/jar.mn b/mobile/android/chrome/jar.mn index f87d6c6384e9..dff080c50dc0 100644 --- a/mobile/android/chrome/jar.mn +++ b/mobile/android/chrome/jar.mn @@ -10,6 +10,7 @@ chrome.jar: * content/about.xhtml (content/about.xhtml) content/config.xhtml (content/config.xhtml) content/config.js (content/config.js) + content/content.js (content/content.js) content/aboutAddons.xhtml (content/aboutAddons.xhtml) content/aboutAddons.js (content/aboutAddons.js) content/aboutCertError.xhtml (content/aboutCertError.xhtml) diff --git a/toolkit/components/reader/AboutReader.jsm b/toolkit/components/reader/AboutReader.jsm index 8dc79f8baa6a..6cc9948f605c 100644 --- a/toolkit/components/reader/AboutReader.jsm +++ b/toolkit/components/reader/AboutReader.jsm @@ -16,14 +16,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "ReaderMode", "resource://gre/modules/Re XPCOMUtils.defineLazyModuleGetter(this, "Task", "resource://gre/modules/Task.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "UITelemetry", "resource://gre/modules/UITelemetry.jsm"); -XPCOMUtils.defineLazyGetter(window, "gChromeWin", function () - window.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIWebNavigation) - .QueryInterface(Ci.nsIDocShellTreeItem) - .rootTreeItem - .QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIDOMWindow) - .QueryInterface(Ci.nsIDOMChromeWindow)); +XPCOMUtils.defineLazyGetter(this, "gChromeWin", () => Services.wm.getMostRecentWindow("navigator:browser")); function dump(s) { Services.console.logStringMessage("AboutReader: " + s); diff --git a/toolkit/components/reader/content/aboutReader.html b/toolkit/components/reader/content/aboutReader.html index 22ef846ef9ac..72c963dec516 100644 --- a/toolkit/components/reader/content/aboutReader.html +++ b/toolkit/components/reader/content/aboutReader.html @@ -6,6 +6,8 @@ + + diff --git a/toolkit/components/reader/content/aboutReader.js b/toolkit/components/reader/content/aboutReader.js new file mode 100644 index 000000000000..17133e69dc52 --- /dev/null +++ b/toolkit/components/reader/content/aboutReader.js @@ -0,0 +1,9 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +window.addEventListener("DOMContentLoaded", function () { + document.dispatchEvent(new CustomEvent("AboutReaderContentLoaded", { bubbles: true })); +}); diff --git a/toolkit/components/reader/jar.mn b/toolkit/components/reader/jar.mn index d519ad12ab40..a8c21fc582d4 100644 --- a/toolkit/components/reader/jar.mn +++ b/toolkit/components/reader/jar.mn @@ -4,6 +4,7 @@ toolkit.jar: content/global/reader/aboutReader.html (content/aboutReader.html) + content/global/reader/aboutReader.js (content/aboutReader.js) content/global/reader/Readability.js (content/Readability.js) content/global/reader/JSDOMParser.js (content/JSDOMParser.js) content/global/reader/readerWorker.js (content/readerWorker.js)