Bug 1287007 - Use frame script to initialize background/popup page r=billm
authorRob Wu <rob@robwu.nl>
Thu, 08 Sep 2016 20:41:43 -0700
changeset 428717 709a07bf036212cc6f667eca11b1ae9d585c79d0
parent 428716 fca5d1ec8c26491ea887e2e6f80cac8a3e32419b
child 428718 54c25251246826c4bca1af8208ddbb0dcb4da0b2
push id33405
push userbcampen@mozilla.com
push dateMon, 24 Oct 2016 15:32:53 +0000
reviewersbillm
bugs1287007
milestone52.0a1
Bug 1287007 - Use frame script to initialize background/popup page r=billm MozReview-Commit-ID: 8Di1nTnwpbU
toolkit/components/extensions/Extension.jsm
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -634,26 +634,23 @@ GlobalManager = {
 
     if (this.extensionMap.size == 0 && this.initialized) {
       Management.off("extension-browser-inserted", this._onExtensionBrowser);
       this.initialized = false;
     }
   },
 
   _onExtensionBrowser(type, browser) {
-    // TODO(robwu): Move this logic inside a frame script.
-    let global = browser.docShell
-      .QueryInterface(Ci.nsIInterfaceRequestor)
-      .getInterface(Ci.nsIContentFrameMessageManager);
-    ExtensionContent.init(global);
-    /* eslint-disable mozilla/balanced-listeners */
-    global.addEventListener("unload", function() {
-      ExtensionContent.uninit(this);
-    });
-    /* eslint-enable mozilla/balanced-listeners */
+    browser.messageManager.loadFrameScript(`data:,
+      Components.utils.import("resource://gre/modules/ExtensionContent.jsm");
+      ExtensionContent.init(this);
+      addEventListener("unload", function() {
+        ExtensionContent.uninit(this);
+      });
+    `, false);
   },
 
   getExtension(extensionId) {
     return this.extensionMap.get(extensionId);
   },
 
   injectInObject(context, isChromeCompat, dest) {
     let apis = {