Bug 1472491: Part 5h - Add LightWeightThemeChild actor. r?felipe draft
authorKris Maglione <maglione.k@gmail.com>
Sun, 29 Jul 2018 20:34:21 -0700
changeset 825679 660136b178385ec052e4b3169a7b85c080ce26ba
parent 825678 ebd989677bb51102010e315cde82d9e923300edb
child 825680 62c17e61f9efb2e539595d4902bcf021c98d49a5
push id118150
push usermaglione.k@gmail.com
push dateThu, 02 Aug 2018 04:47:08 +0000
reviewersfelipe
bugs1472491
milestone63.0a1
Bug 1472491: Part 5h - Add LightWeightThemeChild actor. r?felipe MozReview-Commit-ID: CmUbpPZxNeS
browser/base/content/content.js
browser/components/nsBrowserGlue.js
browser/modules/LightWeightThemeInstallChild.jsm
browser/modules/LightWeightThemeWebInstallListener.jsm
browser/modules/moz.build
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -39,19 +39,16 @@ XPCOMUtils.defineLazyGetter(this, "Login
 
 XPCOMUtils.defineLazyProxy(this, "formSubmitObserver", () => {
   return new FormSubmitObserver(content, this);
 }, {
   // stub QI
   QueryInterface: ChromeUtils.generateQI([Ci.nsIFormSubmitObserver, Ci.nsISupportsWeakReference])
 });
 
-XPCOMUtils.defineLazyProxy(this, "LightWeightThemeWebInstallListener",
-                           "resource:///modules/LightWeightThemeWebInstallListener.jsm");
-
 Services.obs.addObserver(formSubmitObserver, "invalidformsubmit", true);
 
 // NOTE: Much of this logic is duplicated in BrowserCLH.js for Android.
 addMessageListener("RemoteLogins:fillForm", function(message) {
   // intercept if ContextMenu.jsm had sent a plain object for remote targets
   message.objects.inputElement = ContextMenuChild.getTarget(global, message, "inputElement");
   LoginManagerContent.receiveMessage(message, content);
 });
@@ -261,20 +258,16 @@ var PageMetadataMessenger = {
         sendAsyncMessage("PageMetadata:MicroformatsResult", result);
         break;
       }
     }
   }
 };
 PageMetadataMessenger.init();
 
-addEventListener("InstallBrowserTheme", LightWeightThemeWebInstallListener, false, true);
-addEventListener("PreviewBrowserTheme", LightWeightThemeWebInstallListener, false, true);
-addEventListener("ResetBrowserThemePreview", LightWeightThemeWebInstallListener, false, true);
-
 let OfflineApps = {
   _docId: 0,
   _docIdMap: new Map(),
 
   _docManifestSet: new Set(),
 
   _observerAdded: false,
   registerWindow(aWindow) {
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -82,16 +82,27 @@ let ACTORS = {
         "ContentSearchClient": {capture: true, wantUntrusted: true},
       },
       messages: [
         "ContentSearch",
       ]
     },
   },
 
+  LightWeightThemeInstall: {
+    module: "resource:///modules/LightWeightThemeInstall",
+    child: {
+      events: {
+        "InstallBrowserTheme": {wantUntrusted: true},
+        "PreviewBrowserTheme": {wantUntrusted: true},
+        "ResetBrowserThemePreview": {wantUntrusted: true},
+      },
+    },
+  },
+
   PageInfo: {
     module: "resource:///modules/PageInfo",
     child: {
       messages: ["PageInfo:getData"],
     },
   },
 
   PageStyle: {
rename from browser/modules/LightWeightThemeWebInstallListener.jsm
rename to browser/modules/LightWeightThemeInstallChild.jsm
--- a/browser/modules/LightWeightThemeWebInstallListener.jsm
+++ b/browser/modules/LightWeightThemeInstallChild.jsm
@@ -1,19 +1,19 @@
 /* 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/. */
 
-var EXPORTED_SYMBOLS = ["LightWeightThemeWebInstallListener"];
+var EXPORTED_SYMBOLS = ["LightWeightThemeInstallChild"];
+
+ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
 
-var LightWeightThemeWebInstallListener = {
-  _previewWindow: null,
-
+class LightWeightThemeInstallChild extends ActorChild {
   handleEvent(event) {
-    let mm = getMessageManagerForContent(event.target.ownerGlobal);
+    let {mm} = this;
     switch (event.type) {
       case "InstallBrowserTheme": {
         mm.sendAsyncMessage("LightWeightThemeWebInstaller:Install", {
           baseURI: event.target.baseURI,
           principal: event.target.nodePrincipal,
           themeData: event.target.getAttribute("data-browsertheme"),
         });
         break;
@@ -37,22 +37,15 @@ var LightWeightThemeWebInstallListener =
         if (this._previewWindow) {
           mm.sendAsyncMessage("LightWeightThemeWebInstaller:ResetPreview",
                            {principal: event.target.nodePrincipal});
           this._resetPreviewWindow();
         }
         break;
       }
     }
-  },
+  }
 
   _resetPreviewWindow() {
     this._previewWindow.removeEventListener("pagehide", this, true);
     this._previewWindow = null;
   }
-};
-
-function getMessageManagerForContent(content) {
-  return content.docShell
-                .sameTypeRootTreeItem
-                .QueryInterface(Ci.nsIInterfaceRequestor)
-                .getInterface(Ci.nsIContentFrameMessageManager);
 }
--- a/browser/modules/moz.build
+++ b/browser/modules/moz.build
@@ -62,17 +62,17 @@ with Files("ExtensionsUI.jsm"):
     BUG_COMPONENT = ("WebExtensions", "General")
 
 with Files("LaterRun.jsm"):
     BUG_COMPONENT = ("Firefox", "Tours")
 
 with Files("LightweightThemeChildHelper.jsm"):
     BUG_COMPONENT = ("WebExtensions", "Themes")
 
-with Files("LightWeightThemeWebInstallListener.jsm"):
+with Files("LightWeightThemeInstallChild.jsm"):
     BUG_COMPONENT = ("Firefox", "Theme")
 
 with Files("OpenInTabsUtils.jsm"):
     BUG_COMPONENT = ("Firefox", "Tabbed Browser")
 
 with Files("PageInfoChild.jsm"):
     BUG_COMPONENT = ("Firefox", "Page Info Window")
 
@@ -152,17 +152,17 @@ EXTRA_JS_MODULES += [
     'ContextMenuChild.jsm',
     'ExtensionsUI.jsm',
     'Feeds.jsm',
     'FormSubmitObserver.jsm',
     'FormValidationHandler.jsm',
     'HomePage.jsm',
     'LaterRun.jsm',
     'LightweightThemeChildHelper.jsm',
-    'LightWeightThemeWebInstallListener.jsm',
+    'LightWeightThemeInstallChild.jsm',
     'NetErrorContent.jsm',
     'OpenInTabsUtils.jsm',
     'PageActions.jsm',
     'PageInfoChild.jsm',
     'PageStyleChild.jsm',
     'PermissionUI.jsm',
     'PingCentre.jsm',
     'PluginContent.jsm',