зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1479241: Don't eagerly load AboutPages.jsm in content processes. r=mythmon
MozReview-Commit-ID: 1ewRIxTVzJR --HG-- rename : toolkit/components/normandy/content/shield-content-process.js => toolkit/components/normandy/shield-content-process.js extra : rebase_source : 4ed1666a824418ee0b769e59b09e6bcf925f4898
This commit is contained in:
Родитель
0b15b2934b
Коммит
67b4db6498
|
@ -67,9 +67,6 @@ const whitelist = {
|
|||
// Extensions
|
||||
"resource://gre/modules/ExtensionUtils.jsm",
|
||||
"resource://gre/modules/MessageChannel.jsm",
|
||||
|
||||
// Shield
|
||||
"resource://normandy-content/AboutPages.jsm",
|
||||
]),
|
||||
};
|
||||
|
||||
|
|
|
@ -369,6 +369,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
|
||||
|
|
|
@ -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,8 +20,6 @@ var EXPORTED_SYMBOLS = ["AboutPages"];
|
|||
|
||||
const SHIELD_LEARN_MORE_URL_PREF = "app.normandy.shieldLearnMoreUrl";
|
||||
|
||||
const PROCESS_SCRIPT = "resource://normandy-content/shield-content-process.js";
|
||||
|
||||
/**
|
||||
* Class for managing an about: page that Normandy provides. Adapted from
|
||||
* browser/extensions/pocket/content/AboutPocket.jsm.
|
||||
|
@ -31,10 +28,10 @@ const PROCESS_SCRIPT = "resource://normandy-content/shield-content-process.js";
|
|||
* @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;
|
||||
}
|
||||
|
@ -54,34 +51,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]);
|
||||
|
||||
|
@ -91,21 +60,17 @@ AboutPage.prototype.QueryInterface = ChromeUtils.generateQI([Ci.nsIAboutModule])
|
|||
var AboutPages = {
|
||||
async init() {
|
||||
// Load scripts in content processes and tabs
|
||||
Services.ppmm.loadProcessScript(PROCESS_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.broadcastAsyncMessage("Shield:ShuttingDown");
|
||||
|
||||
// Clean up about pages
|
||||
this.aboutStudies.unregisterParentListeners();
|
||||
this.aboutStudies.unregister();
|
||||
});
|
||||
},
|
||||
};
|
||||
|
@ -119,7 +84,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
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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']
|
||||
|
|
|
@ -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]);
|
|
@ -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}
|
Загрузка…
Ссылка в новой задаче