Bug 1479309: Don't load shield-content-frame.js until needed. r=mythmon

MozReview-Commit-ID: 5usNkHYjifd

--HG--
rename : toolkit/components/normandy/content/shield-content-frame.js => toolkit/components/normandy/content/ShieldFrameListener.jsm
extra : rebase_source : 519b450e365166d4e377083c5a926ad07d167fc7
This commit is contained in:
Kris Maglione 2018-07-29 12:29:45 -07:00
Родитель 4a168a8034
Коммит e90505ef2c
3 изменённых файлов: 28 добавлений и 26 удалений

Просмотреть файл

@ -21,14 +21,7 @@ var EXPORTED_SYMBOLS = ["AboutPages"];
const SHIELD_LEARN_MORE_URL_PREF = "app.normandy.shieldLearnMoreUrl"; const SHIELD_LEARN_MORE_URL_PREF = "app.normandy.shieldLearnMoreUrl";
// Due to bug 1051238 frame scripts are cached forever, so we can't update them const PROCESS_SCRIPT = "resource://normandy-content/shield-content-process.js";
// 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()}`
);
/** /**
* Class for managing an about: page that Normandy provides. Adapted from * Class for managing an about: page that Normandy provides. Adapted from
@ -99,7 +92,6 @@ var AboutPages = {
async init() { async init() {
// Load scripts in content processes and tabs // Load scripts in content processes and tabs
Services.ppmm.loadProcessScript(PROCESS_SCRIPT, true); Services.ppmm.loadProcessScript(PROCESS_SCRIPT, true);
Services.mm.loadFrameScript(FRAME_SCRIPT, true);
// Register about: pages and their listeners // Register about: pages and their listeners
this.aboutStudies.register(); this.aboutStudies.register();
@ -109,7 +101,6 @@ var AboutPages = {
// Stop loading processs scripts and notify existing scripts to clean up. // Stop loading processs scripts and notify existing scripts to clean up.
Services.ppmm.removeDelayedProcessScript(PROCESS_SCRIPT); Services.ppmm.removeDelayedProcessScript(PROCESS_SCRIPT);
Services.ppmm.broadcastAsyncMessage("Shield:ShuttingDown"); Services.ppmm.broadcastAsyncMessage("Shield:ShuttingDown");
Services.mm.removeDelayedFrameScript(FRAME_SCRIPT);
Services.mm.broadcastAsyncMessage("Shield:ShuttingDown"); Services.mm.broadcastAsyncMessage("Shield:ShuttingDown");
// Clean up about pages // Clean up about pages

Просмотреть файл

@ -3,6 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict"; "use strict";
var EXPORTED_SYMBOLS = ["ShieldFrameListener"];
/** /**
* Listen for DOM events bubbling up from the about:studies page, and perform * Listen for DOM events bubbling up from the about:studies page, and perform
* privileged actions in response to them. If we need to do anything that the * privileged actions in response to them. If we need to do anything that the
@ -13,11 +15,8 @@
* is opened. * is opened.
*/ */
/* global content addMessageListener removeMessageListener sendAsyncMessage */
ChromeUtils.import("resource://gre/modules/Services.jsm"); ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
const frameGlobal = {}; const frameGlobal = {};
ChromeUtils.defineModuleGetter( ChromeUtils.defineModuleGetter(
@ -38,6 +37,10 @@ XPCOMUtils.defineLazyGetter(this, "gStringBundle", function() {
* @implements EventListener * @implements EventListener
*/ */
class ShieldFrameListener { class ShieldFrameListener {
constructor(mm) {
this.mm = mm;
}
handleEvent(event) { handleEvent(event) {
// Abort if the current page isn't about:studies. // Abort if the current page isn't about:studies.
if (!this.ensureTrustedOrigin()) { if (!this.ensureTrustedOrigin()) {
@ -46,23 +49,23 @@ class ShieldFrameListener {
// We waited until after we received an event to register message listeners // We waited until after we received an event to register message listeners
// in order to save resources for tabs that don't ever load about:studies. // in order to save resources for tabs that don't ever load about:studies.
addMessageListener("Shield:ShuttingDown", this); this.mm.addMessageListener("Shield:ShuttingDown", this);
addMessageListener("Shield:ReceiveStudyList", this); this.mm.addMessageListener("Shield:ReceiveStudyList", this);
addMessageListener("Shield:ReceiveStudiesEnabled", this); this.mm.addMessageListener("Shield:ReceiveStudiesEnabled", this);
switch (event.detail.action) { switch (event.detail.action) {
// Actions that require the parent process // Actions that require the parent process
case "GetRemoteValue:StudyList": case "GetRemoteValue:StudyList":
sendAsyncMessage("Shield:GetStudyList"); this.mm.sendAsyncMessage("Shield:GetStudyList");
break; break;
case "RemoveStudy": case "RemoveStudy":
sendAsyncMessage("Shield:RemoveStudy", event.detail.data); this.mm.sendAsyncMessage("Shield:RemoveStudy", event.detail.data);
break; break;
case "GetRemoteValue:StudiesEnabled": case "GetRemoteValue:StudiesEnabled":
sendAsyncMessage("Shield:GetStudiesEnabled"); this.mm.sendAsyncMessage("Shield:GetStudiesEnabled");
break; break;
case "NavigateToDataPreferences": case "NavigateToDataPreferences":
sendAsyncMessage("Shield:OpenDataPreferences"); this.mm.sendAsyncMessage("Shield:OpenDataPreferences");
break; break;
// Actions that can be performed in the content process // Actions that can be performed in the content process
case "GetRemoteValue:ShieldLearnMoreHref": case "GetRemoteValue:ShieldLearnMoreHref":
@ -94,7 +97,7 @@ class ShieldFrameListener {
* @return {Boolean} * @return {Boolean}
*/ */
ensureTrustedOrigin() { ensureTrustedOrigin() {
return content.document.documentURI.startsWith("about:studies"); return this.mm.content.document.documentURI.startsWith("about:studies");
} }
/** /**
@ -127,6 +130,8 @@ class ShieldFrameListener {
return; return;
} }
let {content} = this.mm;
// Clone details and use the event class from the unprivileged context. // Clone details and use the event class from the unprivileged context.
const event = new content.document.defaultView.CustomEvent(type, { const event = new content.document.defaultView.CustomEvent(type, {
bubbles: true, bubbles: true,
@ -136,10 +141,8 @@ class ShieldFrameListener {
} }
onShutdown() { onShutdown() {
removeMessageListener("Shield:SendStudyList", this); this.mm.removeMessageListener("Shield:SendStudyList", this);
removeMessageListener("Shield:ShuttingDown", this); this.mm.removeMessageListener("Shield:ShuttingDown", this);
removeEventListener("Shield", this); this.mm.removeEventListener("Shield", this);
} }
} }
addEventListener("ShieldPageEvent", new ShieldFrameListener(), false, true);

Просмотреть файл

@ -37,6 +37,12 @@ XPCOMUtils.defineLazyProxy(this, "PopupBlocking", () => {
return new tmp.PopupBlocking(global); return new tmp.PopupBlocking(global);
}); });
XPCOMUtils.defineLazyProxy(this, "ShieldFrameListener", () => {
let tmp = {};
ChromeUtils.import("resource://normandy-content/ShieldFrameListener.jsm", tmp);
return new tmp.ShieldFrameListener(global);
});
XPCOMUtils.defineLazyProxy(this, "SelectionSourceContent", XPCOMUtils.defineLazyProxy(this, "SelectionSourceContent",
"resource://gre/modules/SelectionSourceContent.jsm"); "resource://gre/modules/SelectionSourceContent.jsm");
@ -534,3 +540,5 @@ let ExtFind = {
}; };
ExtFind.init(); ExtFind.init();
addEventListener("ShieldPageEvent", ShieldFrameListener, false, true);