diff --git a/browser/base/content/test/performance/browser_startup_content.js b/browser/base/content/test/performance/browser_startup_content.js index 62d5961ae994..3b8b2021cfea 100644 --- a/browser/base/content/test/performance/browser_startup_content.js +++ b/browser/base/content/test/performance/browser_startup_content.js @@ -74,9 +74,6 @@ const whitelist = { // Service workers "resource://gre/modules/ServiceWorkerCleanUp.jsm", - - // Shield - "resource://normandy-content/AboutPages.jsm", ]), }; diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in index 6c80d1e47427..f0c1914dc3e2 100644 --- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -370,6 +370,10 @@ @RESPATH@/components/extension-process-script.js @RESPATH@/browser/components/extensions-browser.manifest +; [Normandy] +@RESPATH@/components/shield.manifest +@RESPATH@/components/shield-content-process.js + ; [PDF Viewer] @RESPATH@/browser/components/pdfjs.manifest @RESPATH@/browser/components/pdfjs.js diff --git a/toolkit/components/normandy/content/AboutPages.jsm b/toolkit/components/normandy/content/AboutPages.jsm index ffbb1b52b939..a3546ec714ae 100644 --- a/toolkit/components/normandy/content/AboutPages.jsm +++ b/toolkit/components/normandy/content/AboutPages.jsm @@ -3,7 +3,6 @@ * 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"); @@ -21,14 +20,7 @@ var EXPORTED_SYMBOLS = ["AboutPages"]; const SHIELD_LEARN_MORE_URL_PREF = "app.normandy.shieldLearnMoreUrl"; -// 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 = ( - `resource://normandy-content/shield-content-process.js?${Math.random()}` -); -const FRAME_SCRIPT = ( - `resource://normandy-content/shield-content-frame.js?${Math.random()}` -); +const FRAME_SCRIPT = "resource://normandy-content/shield-content-frame.js"; /** * Class for managing an about: page that Normandy provides. Adapted from @@ -38,10 +30,10 @@ const FRAME_SCRIPT = ( * @implements nsIAboutModule */ class AboutPage { - constructor({chromeUrl, aboutHost, classId, description, uriFlags}) { + constructor({chromeUrl, aboutHost, classID, description, uriFlags}) { this.chromeUrl = chromeUrl; this.aboutHost = aboutHost; - this.classId = Components.ID(classId); + this.classID = Components.ID(classID); this.description = description; this.uriFlags = uriFlags; } @@ -61,34 +53,6 @@ class AboutPage { } return channel; } - - createInstance(outer, iid) { - if (outer !== null) { - throw Cr.NS_ERROR_NO_AGGREGATION; - } - return this.QueryInterface(iid); - } - - /** - * Register this about: page with XPCOM. This must be called once in each - * process (parent and content) to correctly initialize the page. - */ - register() { - Cm.QueryInterface(Ci.nsIComponentRegistrar).registerFactory( - this.classId, - this.description, - `@mozilla.org/network/protocol/about;1?what=${this.aboutHost}`, - this, - ); - } - - /** - * Unregister this about: page with XPCOM. This must be called before the - * add-on is cleaned up if the page has been registered. - */ - unregister() { - Cm.QueryInterface(Ci.nsIComponentRegistrar).unregisterFactory(this.classId, this); - } } AboutPage.prototype.QueryInterface = ChromeUtils.generateQI([Ci.nsIAboutModule]); @@ -98,23 +62,19 @@ AboutPage.prototype.QueryInterface = ChromeUtils.generateQI([Ci.nsIAboutModule]) var AboutPages = { async init() { // Load scripts in content processes and tabs - Services.ppmm.loadProcessScript(PROCESS_SCRIPT, true); Services.mm.loadFrameScript(FRAME_SCRIPT, true); // Register about: pages and their listeners - this.aboutStudies.register(); this.aboutStudies.registerParentListeners(); CleanupManager.addCleanupHandler(() => { // Stop loading processs scripts and notify existing scripts to clean up. - Services.ppmm.removeDelayedProcessScript(PROCESS_SCRIPT); Services.ppmm.broadcastAsyncMessage("Shield:ShuttingDown"); Services.mm.removeDelayedFrameScript(FRAME_SCRIPT); Services.mm.broadcastAsyncMessage("Shield:ShuttingDown"); // Clean up about pages this.aboutStudies.unregisterParentListeners(); - this.aboutStudies.unregister(); }); }, }; @@ -128,7 +88,7 @@ XPCOMUtils.defineLazyGetter(this.AboutPages, "aboutStudies", () => { const aboutStudies = new AboutPage({ chromeUrl: "resource://normandy-content/about-studies/about-studies.html", aboutHost: "studies", - classId: "{6ab96943-a163-482c-9622-4faedc0e827f}", + classID: "{6ab96943-a163-482c-9622-4faedc0e827f}", description: "Shield Study Listing", uriFlags: ( Ci.nsIAboutModule.ALLOW_SCRIPT diff --git a/toolkit/components/normandy/content/shield-content-process.js b/toolkit/components/normandy/content/shield-content-process.js deleted file mode 100644 index 68e69da39384..000000000000 --- a/toolkit/components/normandy/content/shield-content-process.js +++ /dev/null @@ -1,47 +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"; - -/** - * Registers about: pages provided by Shield, and listens for a shutdown event - * from the add-on before un-registering them. - * - * This file is loaded as a process script. It is executed once for each - * process, including the parent one. - */ - -ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); -ChromeUtils.import("resource://gre/modules/Services.jsm"); -ChromeUtils.import("resource://normandy-content/AboutPages.jsm"); - -class ShieldChildListener { - onStartup() { - Services.cpmm.addMessageListener("Shield:ShuttingDown", this, true); - AboutPages.aboutStudies.register(); - } - - onShutdown() { - AboutPages.aboutStudies.unregister(); - Services.cpmm.removeMessageListener("Shield:ShuttingDown", this); - - // Unload AboutPages.jsm in case the add-on is reinstalled and we need to - // load a new version of it. - Cu.unload("resource://normandy-content/AboutPages.jsm"); - } - - receiveMessage(message) { - switch (message.name) { - case "Shield:ShuttingDown": - this.onShutdown(); - break; - } - } -} - -// Only register in content processes; the parent process handles registration -// separately. -if (Services.appinfo.processType === Services.appinfo.PROCESS_TYPE_CONTENT) { - const listener = new ShieldChildListener(); - listener.onStartup(); -} diff --git a/toolkit/components/normandy/moz.build b/toolkit/components/normandy/moz.build index 28ae1ee6806c..a0420e4c55a3 100644 --- a/toolkit/components/normandy/moz.build +++ b/toolkit/components/normandy/moz.build @@ -9,6 +9,11 @@ with Files('**'): JAR_MANIFESTS += ['jar.mn'] +EXTRA_COMPONENTS += [ + 'shield-content-process.js', + 'shield.manifest', +] + SPHINX_TREES['normandy'] = 'docs' BROWSER_CHROME_MANIFESTS += ['test/browser/browser.ini'] diff --git a/toolkit/components/normandy/shield-content-process.js b/toolkit/components/normandy/shield-content-process.js new file mode 100644 index 000000000000..1320351cf406 --- /dev/null +++ b/toolkit/components/normandy/shield-content-process.js @@ -0,0 +1,26 @@ +/* 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"; + +/** + * Registers about: pages provided by Shield, and listens for a shutdown event + * from the add-on before un-registering them. + * + * This file is loaded as a process script. It is executed once for each + * process, including the parent one. + */ + +ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); +ChromeUtils.import("resource://normandy-content/AboutPages.jsm"); + +// generateNSGetFactory only knows how to register factory classes, with +// classID properties on their prototype, and a constructor that returns +// an instance. It can't handle singletons directly. So wrap the +// aboutStudies singleton in a trivial constructor function. +function AboutStudies() { + return AboutStudies.prototype; +} +AboutStudies.prototype = AboutPages.aboutStudies; + +var NSGetFactory = XPCOMUtils.generateNSGetFactory([AboutStudies]); diff --git a/toolkit/components/normandy/shield.manifest b/toolkit/components/normandy/shield.manifest new file mode 100644 index 000000000000..0ce61c9a98dc --- /dev/null +++ b/toolkit/components/normandy/shield.manifest @@ -0,0 +1,3 @@ + +component {6ab96943-a163-482c-9622-4faedc0e827f} shield-content-process.js +contract @mozilla.org/network/protocol/about;1?what=studies {6ab96943-a163-482c-9622-4faedc0e827f}