mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
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 : source : f150e62dcbbdc14bec93db0705470a5d9e71737e
This commit is contained in:
parent
5ccef39c52
commit
dfe5c95ca1
@ -74,9 +74,6 @@ const whitelist = {
|
||||
|
||||
// Service workers
|
||||
"resource://gre/modules/ServiceWorkerCleanUp.jsm",
|
||||
|
||||
// Shield
|
||||
"resource://normandy-content/AboutPages.jsm",
|
||||
]),
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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']
|
||||
|
26
toolkit/components/normandy/shield-content-process.js
Normal file
26
toolkit/components/normandy/shield-content-process.js
Normal file
@ -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]);
|
3
toolkit/components/normandy/shield.manifest
Normal file
3
toolkit/components/normandy/shield.manifest
Normal file
@ -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}
|
Loading…
Reference in New Issue
Block a user