Bug 1484373: Part 11 - Fold mostly-empty DocumentManager singleton into ExtensionManager. r=mixedpuppy
authorKris Maglione <maglione.k@gmail.com>
Fri, 17 Aug 2018 22:35:21 -0700
changeset 490967 812ae71cea4f9c4971a6ef2b40b64eb26ba1feeb
parent 490966 091835164b689bd673182068ab7c896cba203449
child 490968 b88f5fa7dca4ba5cb92d9c905f3e52d043977498
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1484373
milestone63.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 1484373: Part 11 - Fold mostly-empty DocumentManager singleton into ExtensionManager. r=mixedpuppy Differential Revision: https://phabricator.services.mozilla.com/D3701
toolkit/components/extensions/extension-process-script.js
--- a/toolkit/components/extensions/extension-process-script.js
+++ b/toolkit/components/extensions/extension-process-script.js
@@ -51,17 +51,16 @@ var extensions = new DefaultWeakMap(poli
     data = data.serialize();
   }
 
   let extension = new ExtensionChild.BrowserExtensionContent(data);
   extension.policy = policy;
   return extension;
 });
 
-var DocumentManager;
 var ExtensionManager;
 
 class ExtensionGlobal {
   constructor(global) {
     this.global = global;
     this.global.addMessageListener("Extension:SetFrameData", this);
 
     this.frameData = null;
@@ -99,53 +98,36 @@ class ExtensionGlobal {
         }
         return;
     }
 
     return ExtensionContent.receiveMessage(this.global, messageName, target, data, recipient);
   }
 }
 
-// Responsible for creating ExtensionContexts and injecting content
-// scripts into them when new documents are created.
-DocumentManager = {
-  globals: new Map(),
-
-  // Initialize listeners that we need regardless of whether extensions are
-  // enabled.
-  earlyInit() {
-    // eslint-disable-next-line mozilla/balanced-listeners
-    Services.obs.addObserver((subject) => this.initGlobal(subject),
-                             "tab-content-frameloader-created");
-  },
-
-  // Initialize a frame script global which extension contexts may be loaded
-  // into.
-  initGlobal(global) {
-    this.globals.set(global, new ExtensionGlobal(global));
-    // eslint-disable-next-line mozilla/balanced-listeners
-    global.addEventListener("unload", () => {
-      this.globals.delete(global);
-    });
-  },
-};
-
 ExtensionManager = {
   // WeakMap<WebExtensionPolicy, Map<string, WebExtensionContentScript>>
   registeredContentScripts: new DefaultWeakMap((policy) => new Map()),
 
+  globals: new WeakMap(),
+
   init() {
     MessageChannel.setupMessageManagers([Services.cpmm]);
 
     Services.cpmm.addMessageListener("Extension:Startup", this);
     Services.cpmm.addMessageListener("Extension:Shutdown", this);
     Services.cpmm.addMessageListener("Extension:FlushJarCache", this);
     Services.cpmm.addMessageListener("Extension:RegisterContentScript", this);
     Services.cpmm.addMessageListener("Extension:UnregisterContentScripts", this);
 
+    // eslint-disable-next-line mozilla/balanced-listeners
+    Services.obs.addObserver(
+      global => this.globals.set(global, new ExtensionGlobal(global)),
+      "tab-content-frameloader-created");
+
     for (let id of sharedData.get("extensions/activeIDs") || []) {
       this.initExtension(getData({id}));
     }
   },
 
   initExtensionPolicy(extension) {
     let policy = WebExtensionPolicy.getByID(extension.id);
     if (!policy) {
@@ -286,17 +268,17 @@ ExtensionProcessScript.prototype = {
 
   _xpcom_factory: XPCOMUtils.generateSingletonFactory(ExtensionProcessScript),
 
   get wrappedJSObject() { return this; },
 
   extensions,
 
   getFrameData(global, force) {
-    let extGlobal = DocumentManager.globals.get(global);
+    let extGlobal = ExtensionManager.globals.get(global);
     return extGlobal && extGlobal.getFrameData(force);
   },
 
   initExtension(extension) {
     return ExtensionManager.initExtensionPolicy(extension);
   },
 
   initExtensionDocument(policy, doc, privileged) {
@@ -321,10 +303,9 @@ ExtensionProcessScript.prototype = {
 
   loadContentScript(contentScript, window) {
     return ExtensionContent.contentScripts.get(contentScript).injectInto(window);
   },
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ExtensionProcessScript]);
 
-DocumentManager.earlyInit();
 ExtensionManager.init();