Bug 1514724 - register pocket about pages in the browser AboutRedirector to avoid having a process script specifically for this purpose, r=mconley,thecount
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 28 Dec 2018 11:26:13 +0000
changeset 509146 6b9e37b4b8a343bb6a4ccf5c62c0f2e5daec0000
parent 509145 04943bb8dcdcbb78870d89246939248d3f0f6a56
child 509147 edd35a2dc14e691695ba37bc9753ef273a3260d7
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley, thecount
bugs1514724
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1514724 - register pocket about pages in the browser AboutRedirector to avoid having a process script specifically for this purpose, r=mconley,thecount Differential Revision: https://phabricator.services.mozilla.com/D14801
browser/components/about/AboutRedirector.cpp
browser/components/build/nsModule.cpp
browser/components/pocket/content/AboutPocket.jsm
browser/components/pocket/content/SaveToPocket.jsm
browser/components/pocket/content/pocket-content-process.js
--- a/browser/components/about/AboutRedirector.cpp
+++ b/browser/components/about/AboutRedirector.cpp
@@ -78,16 +78,24 @@ static const RedirEntry kRedirMap[] = {
     {"welcome", "about:blank",
      nsIAboutModule::URI_MUST_LOAD_IN_CHILD |
          nsIAboutModule::URI_CAN_LOAD_IN_PRIVILEGED_CHILD |
          nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
          nsIAboutModule::ALLOW_SCRIPT},
     {"library", "chrome://browser/content/aboutLibrary.xhtml",
      nsIAboutModule::URI_MUST_LOAD_IN_CHILD |
          nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT},
+    {"pocket-saved", "chrome://pocket/content/panels/saved.html",
+     nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
+         nsIAboutModule::URI_CAN_LOAD_IN_CHILD | nsIAboutModule::ALLOW_SCRIPT |
+         nsIAboutModule::HIDE_FROM_ABOUTABOUT},
+    {"pocket-signup", "chrome://pocket/content/panels/signup.html",
+     nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
+         nsIAboutModule::URI_CAN_LOAD_IN_CHILD | nsIAboutModule::ALLOW_SCRIPT |
+         nsIAboutModule::HIDE_FROM_ABOUTABOUT},
     {"preferences",
      "chrome://browser/content/preferences/in-content/preferences.xul",
      nsIAboutModule::ALLOW_SCRIPT},
     {"downloads",
      "chrome://browser/content/downloads/contentAreaDownloadsView.xul",
      nsIAboutModule::ALLOW_SCRIPT},
     {"reader", "chrome://global/content/reader/aboutReader.html",
      nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
--- a/browser/components/build/nsModule.cpp
+++ b/browser/components/build/nsModule.cpp
@@ -108,16 +108,18 @@ static const mozilla::Module::ContractID
     { NS_ABOUT_MODULE_CONTRACTID_PREFIX "newtab", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
     { NS_ABOUT_MODULE_CONTRACTID_PREFIX "library", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
     { NS_ABOUT_MODULE_CONTRACTID_PREFIX "preferences", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
     { NS_ABOUT_MODULE_CONTRACTID_PREFIX "downloads", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
     { NS_ABOUT_MODULE_CONTRACTID_PREFIX "reader", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
     { NS_ABOUT_MODULE_CONTRACTID_PREFIX "restartrequired", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
     { NS_ABOUT_MODULE_CONTRACTID_PREFIX "welcome", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
     { NS_ABOUT_MODULE_CONTRACTID_PREFIX "policies", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
+    { NS_ABOUT_MODULE_CONTRACTID_PREFIX "pocket-saved", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
+    { NS_ABOUT_MODULE_CONTRACTID_PREFIX "pocket-signup", &kNS_BROWSER_ABOUT_REDIRECTOR_CID },
 #if defined(XP_WIN)
     { NS_IEHISTORYENUMERATOR_CONTRACTID, &kNS_WINIEHISTORYENUMERATOR_CID },
 #elif defined(XP_MACOSX)
     { NS_SHELLSERVICE_CONTRACTID, &kNS_SHELLSERVICE_CID },
 #endif
 #if defined(MOZ_WIDGET_COCOA)
     { NS_MACATTRIBUTIONSERVICE_CONTRACTID, &kNS_MACATTRIBUTIONSERVICE_CID },
 #endif
deleted file mode 100644
--- a/browser/components/pocket/content/AboutPocket.jsm
+++ /dev/null
@@ -1,94 +0,0 @@
-/* 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";
-
-const Cm = Components.manager;
-
-ChromeUtils.import("resource://gre/modules/Services.jsm");
-ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
-
-// See LOG_LEVELS in Console.jsm. Common examples: "All", "Info", "Warn", & "Error".
-const PREF_LOG_LEVEL = "loop.debug.loglevel";
-
-// eslint-disable-next-line no-unused-vars
-XPCOMUtils.defineLazyGetter(this, "log", () => {
-  let ConsoleAPI = ChromeUtils.import("resource://gre/modules/Console.jsm", {}).ConsoleAPI;
-  let consoleOptions = {
-    maxLogLevelPref: PREF_LOG_LEVEL,
-    prefix: "Loop",
-  };
-  return new ConsoleAPI(consoleOptions);
-});
-
-
-function AboutPage(chromeURL, aboutHost, classID, description, uriFlags) {
-  this.chromeURL = chromeURL;
-  this.aboutHost = aboutHost;
-  this.classID = Components.ID(classID);
-  this.description = description;
-  this.uriFlags = uriFlags;
-}
-
-AboutPage.prototype = {
-  QueryInterface: ChromeUtils.generateQI([Ci.nsIAboutModule]),
-  getURIFlags(aURI) { // eslint-disable-line no-unused-vars
-    return this.uriFlags;
-  },
-
-  newChannel(aURI, aLoadInfo) {
-    let newURI = Services.io.newURI(this.chromeURL);
-    let channel = Services.io.newChannelFromURIWithLoadInfo(newURI,
-                                                            aLoadInfo);
-    channel.originalURI = aURI;
-
-    if (this.uriFlags & Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT) {
-      let principal = Services.scriptSecurityManager.createCodebasePrincipal(aURI, {});
-      channel.owner = principal;
-    }
-    return channel;
-  },
-
-  createInstance(outer, iid) {
-    if (outer !== null) {
-      throw Cr.NS_ERROR_NO_AGGREGATION;
-    }
-    return this.QueryInterface(iid);
-  },
-
-  register() {
-    Cm.QueryInterface(Ci.nsIComponentRegistrar).registerFactory(
-      this.classID, this.description,
-      "@mozilla.org/network/protocol/about;1?what=" + this.aboutHost, this);
-  },
-
-  unregister() {
-    Cm.QueryInterface(Ci.nsIComponentRegistrar).unregisterFactory(
-      this.classID, this);
-  },
-};
-
-/* exported AboutPocket */
-var AboutPocket = {};
-
-XPCOMUtils.defineLazyGetter(AboutPocket, "aboutSaved", () =>
-  new AboutPage("chrome://pocket/content/panels/saved.html",
-                "pocket-saved",
-                "{3e759f54-37af-7843-9824-f71b5993ceed}",
-                "About Pocket Saved",
-                Ci.nsIAboutModule.ALLOW_SCRIPT |
-                Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT |
-                Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT)
-);
-
-XPCOMUtils.defineLazyGetter(AboutPocket, "aboutSignup", () =>
-  new AboutPage("chrome://pocket/content/panels/signup.html",
-                "pocket-signup",
-                "{8548329d-00c4-234e-8f17-75026db3b56e}",
-                "About Pocket Signup",
-                Ci.nsIAboutModule.ALLOW_SCRIPT |
-                Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT |
-                Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT)
-);
-
-var EXPORTED_SYMBOLS = ["AboutPocket"];
--- a/browser/components/pocket/content/SaveToPocket.jsm
+++ b/browser/components/pocket/content/SaveToPocket.jsm
@@ -2,18 +2,16 @@
 /* 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";
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://services-common/utils.js");
-ChromeUtils.defineModuleGetter(this, "AboutPocket",
-                               "chrome://pocket/content/AboutPocket.jsm");
 ChromeUtils.defineModuleGetter(this, "AddonManagerPrivate",
                                "resource://gre/modules/AddonManager.jsm");
 ChromeUtils.defineModuleGetter(this, "BrowserUtils",
                                "resource://gre/modules/BrowserUtils.jsm");
 ChromeUtils.defineModuleGetter(this, "PageActions",
                                "resource:///modules/PageActions.jsm");
 ChromeUtils.defineModuleGetter(this, "Pocket",
                                "chrome://pocket/content/Pocket.jsm");
@@ -25,20 +23,16 @@ XPCOMUtils.defineLazyGetter(this, "gPock
   return Services.strings.createBundle("chrome://pocket/locale/pocket.properties");
 });
 XPCOMUtils.defineLazyGetter(this, "gPocketStyleURI", function() {
   return Services.io.newURI("chrome://pocket/skin/pocket.css");
 });
 
 var EXPORTED_SYMBOLS = ["SaveToPocket"];
 
-// Due to bug 1051238 frame scripts are cached forever, so we can't update them
-// as a restartless add-on. The Math.random() is the work around for this.
-const PROCESS_SCRIPT = "chrome://pocket/content/pocket-content-process.js?" + Math.random();
-
 const PREF_BRANCH = "extensions.pocket.";
 const PREFS = {
   enabled: true, // bug 1229937, figure out ui tour support
   api: "api.getpocket.com",
   site: "getpocket.com",
 };
 
 function setDefaultPrefs() {
@@ -396,33 +390,26 @@ function pktUIGetter(prop, window) {
 
 var PocketOverlay = {
   startup() {
     let styleSheetService = Cc["@mozilla.org/content/style-sheet-service;1"]
                               .getService(Ci.nsIStyleSheetService);
     this._sheetType = styleSheetService.AUTHOR_SHEET;
     this._cachedSheet = styleSheetService.preloadSheet(gPocketStyleURI,
                                                        this._sheetType);
-    Services.ppmm.loadProcessScript(PROCESS_SCRIPT, true);
     Services.obs.addObserver(this, "browser-delayed-startup-finished");
     PocketReader.startup();
     PocketPageAction.init();
     PocketContextMenu.init();
     for (let win of browserWindows()) {
       this.onWindowOpened(win);
     }
   },
   shutdown() {
-    Services.ppmm.broadcastAsyncMessage("PocketShuttingDown");
     Services.obs.removeObserver(this, "browser-delayed-startup-finished");
-    // Although the ppmm loads the scripts into the chrome process as well,
-    // we need to manually unregister here anyway to ensure these aren't part
-    // of the chrome process and avoid errors.
-    AboutPocket.aboutSaved.unregister();
-    AboutPocket.aboutSignup.unregister();
 
     PocketPageAction.shutdown();
 
     for (let window of browserWindows()) {
       for (let id of ["appMenu-library-pocket-button"]) {
         let element = window.document.getElementById(id) ||
                       window.gNavToolbox.palette.querySelector("#" + id);
         if (element)
deleted file mode 100644
--- a/browser/components/pocket/content/pocket-content-process.js
+++ /dev/null
@@ -1,51 +0,0 @@
-/* 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";
-
-// This file is loaded as a process script, it will be loaded in the parent
-// process as well as all content processes.
-
-ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
-ChromeUtils.import("resource://gre/modules/Services.jsm");
-ChromeUtils.import("chrome://pocket/content/AboutPocket.jsm");
-
-function AboutPocketChildListener() {
-}
-AboutPocketChildListener.prototype = {
-  onStartup: function onStartup() {
-
-    // Only do this in content processes since, as the broadcaster of this
-    // message, the parent process doesn't also receive it.  We handlers
-    // the shutting down separately.
-    if (Services.appinfo.processType ==
-        Services.appinfo.PROCESS_TYPE_CONTENT) {
-
-      Services.cpmm.addMessageListener("PocketShuttingDown", this, true);
-    }
-
-    AboutPocket.aboutSaved.register();
-    AboutPocket.aboutSignup.register();
-  },
-
-  onShutdown: function onShutdown() {
-    AboutPocket.aboutSignup.unregister();
-    AboutPocket.aboutSaved.unregister();
-
-    Services.cpmm.removeMessageListener("PocketShuttingDown", this);
-    Cu.unload("chrome://pocket/content/AboutPocket.jsm");
-  },
-
-  receiveMessage: function receiveMessage(message) {
-    switch (message.name) {
-      case "PocketShuttingDown":
-        this.onShutdown();
-        break;
-      default:
-        break;
-    }
-  },
-};
-
-const listener = new AboutPocketChildListener();
-listener.onStartup();