Bug 1091924 Fix up InstallTrigger for e10s-multi r=kmag draft
authorAndrew Swan <aswan@mozilla.com>
Thu, 13 Oct 2016 11:21:24 -0700
changeset 429026 54b361b3fc6d8af62c8249778187fead7bcacfc9
parent 422225 beb2abb14dbdd9b116c7be5bc46be53071c5f7f0
child 429027 38716932459034f7d86bad77f5ad948af3059ac4
push id33476
push useraswan@mozilla.com
push dateTue, 25 Oct 2016 02:58:01 +0000
reviewerskmag
bugs1091924
milestone52.0a1
Bug 1091924 Fix up InstallTrigger for e10s-multi r=kmag MozReview-Commit-ID: HmGZvanRhxl
toolkit/mozapps/extensions/addonManager.js
toolkit/mozapps/extensions/amInstallTrigger.js
--- a/toolkit/mozapps/extensions/addonManager.js
+++ b/toolkit/mozapps/extensions/addonManager.js
@@ -42,20 +42,20 @@ var gParentMM = null;
 
 
 function amManager() {
   Cu.import("resource://gre/modules/AddonManager.jsm");
   /*globals AddonManagerPrivate*/
 
   let globalMM = Services.mm;
   globalMM.loadFrameScript(CHILD_SCRIPT, true);
+  globalMM.addMessageListener(MSG_INSTALL_ENABLED, this);
   globalMM.addMessageListener(MSG_INSTALL_ADDONS, this);
 
   gParentMM = Services.ppmm;
-  gParentMM.addMessageListener(MSG_INSTALL_ENABLED, this);
   gParentMM.addMessageListener(MSG_PROMISE_REQUEST, this);
   gParentMM.addMessageListener(MSG_INSTALL_CLEANUP, this);
   gParentMM.addMessageListener(MSG_ADDON_EVENT_REQ, this);
 
   Services.obs.addObserver(this, "message-manager-close", false);
   Services.obs.addObserver(this, "message-manager-disconnect", false);
 
   AddonManager.webAPI.setEventHandler(this.sendEvent);
@@ -207,19 +207,20 @@ amManager.prototype = {
 
     switch (aMessage.name) {
       case MSG_INSTALL_ENABLED:
         return AddonManager.isInstallEnabled(payload.mimetype);
 
       case MSG_INSTALL_ADDONS: {
         let callback = null;
         if (payload.callbackID != -1) {
+          let mm = aMessage.target.messageManager;
           callback = {
             onInstallEnded: function(url, status) {
-              gParentMM.broadcastAsyncMessage(MSG_INSTALL_CALLBACK, {
+              mm.sendAsyncMessage(MSG_INSTALL_CALLBACK, {
                 callbackID: payload.callbackID,
                 url: url,
                 status: status
               });
             },
           };
         }
 
--- a/toolkit/mozapps/extensions/amInstallTrigger.js
+++ b/toolkit/mozapps/extensions/amInstallTrigger.js
@@ -34,23 +34,29 @@ function CallbackObject(id, callback, ur
     }
 
     this.urls.delete(url);
     if (this.urls.size == 0)
       mediator._callbacks.delete(id);
   };
 }
 
-function RemoteMediator(windowID) {
-  this._windowID = windowID;
+function RemoteMediator(window) {
+  window.QueryInterface(Ci.nsIInterfaceRequestor);
+  let utils = window.getInterface(Ci.nsIDOMWindowUtils);
+  this._windowID = utils.currentInnerWindowID;
+
+  this.mm = window
+    .getInterface(Ci.nsIDocShell)
+    .QueryInterface(Ci.nsIInterfaceRequestor)
+    .getInterface(Ci.nsIContentFrameMessageManager);
+  this.mm.addWeakMessageListener(MSG_INSTALL_CALLBACK, this);
+
   this._lastCallbackID = 0;
   this._callbacks = new Map();
-  this.mm = Cc["@mozilla.org/childprocessmessagemanager;1"]
-            .getService(Ci.nsISyncMessageSender);
-  this.mm.addWeakMessageListener(MSG_INSTALL_CALLBACK, this);
 }
 
 RemoteMediator.prototype = {
   receiveMessage: function(message) {
     if (message.name == MSG_INSTALL_CALLBACK) {
       let payload = message.data;
       let callbackHandler = this._callbacks.get(payload.callbackID);
       if (callbackHandler) {
@@ -131,19 +137,23 @@ InstallTrigger.prototype = {
   // XPCOM will then duly expose as a property value on the window. All this
   // indirection is necessary because webidl does not (yet) support statics
   // (bug 863952). See bug 926712 for more details about this implementation.
   init: function(window) {
     this._window = window;
     this._principal = window.document.nodePrincipal;
     this._url = window.document.documentURIObject;
 
-    window.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
-    let utils = window.getInterface(Components.interfaces.nsIDOMWindowUtils);
-    this._mediator = new RemoteMediator(utils.currentInnerWindowID);
+    try {
+      this._mediator = new RemoteMediator(window);
+    } catch (ex) {
+      // If we can't set up IPC (e.g., because this is a top-level window
+      // or something), then don't expose InstallTrigger.
+      return null;
+    }
 
     return window.InstallTriggerImpl._create(window, this);
   },
 
   enabled: function() {
     return this._mediator.enabled(this._url.spec);
   },