Bug 1472491: Part 5β - Add ShieldFrameChild actor. r=mconley draft
authorKris Maglione <maglione.k@gmail.com>
Sun, 29 Jul 2018 23:45:18 -0700
changeset 828463 7ece0606d4197e0b1fc1acb94bf476d583008908
parent 828462 e4eddd659ca25ade7dcfe68f0392911c7822752a
child 828464 bb638221f8681760e78f06b70ed14066f049b1f8
push id118680
push usermaglione.k@gmail.com
push dateFri, 10 Aug 2018 23:04:22 +0000
reviewersmconley
bugs1472491
milestone63.0a1
Bug 1472491: Part 5β - Add ShieldFrameChild actor. r=mconley MozReview-Commit-ID: 5HqAEEO7nJy
browser/components/nsBrowserGlue.js
toolkit/components/normandy/content/ShieldFrameChild.jsm
toolkit/components/normandy/content/ShieldFrameListener.jsm
toolkit/content/browser-content.js
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -215,16 +215,26 @@ let ACTORS = {
       ],
 
       observers: [
         "decoder-doctor-notification",
       ],
     },
   },
 
+  ShieldFrame: {
+    child: {
+      module: "resource://normandy-content/ShieldFrameChild.jsm",
+      events: {
+        "ShieldPageEvent": {wantUntrusted: true},
+      },
+      matches: ["about:studies"],
+    },
+  },
+
   URIFixup: {
     child: {
       module: "resource:///actors/URIFixupChild.jsm",
       group: "browsers",
       observers: ["keyword-uri-fixup"],
     },
   },
 };
rename from toolkit/components/normandy/content/ShieldFrameListener.jsm
rename to toolkit/components/normandy/content/ShieldFrameChild.jsm
--- a/toolkit/components/normandy/content/ShieldFrameListener.jsm
+++ b/toolkit/components/normandy/content/ShieldFrameChild.jsm
@@ -1,25 +1,26 @@
 /* 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/. */
 "use strict";
 
-var EXPORTED_SYMBOLS = ["ShieldFrameListener"];
+var EXPORTED_SYMBOLS = ["ShieldFrameChild"];
 
 /**
  * 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
  * content process can't handle (such as reading IndexedDB), we send a message
  * to the parent process and handle it there.
  *
  * This file is loaded as a frame script. It will be loaded once per tab that
  * is opened.
  */
 
+ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 const frameGlobal = {};
 ChromeUtils.defineModuleGetter(
   frameGlobal, "AboutPages", "resource://normandy-content/AboutPages.jsm",
 );
 
@@ -31,27 +32,18 @@ XPCOMUtils.defineLazyGetter(this, "gStri
   return Services.strings.createBundle("chrome://global/locale/aboutStudies.properties");
 });
 
 /**
  * Handles incoming events from the parent process and about:studies.
  * @implements nsIMessageListener
  * @implements EventListener
  */
-class ShieldFrameListener {
-  constructor(mm) {
-    this.mm = mm;
-  }
-
+class ShieldFrameChild extends ActorChild {
   handleEvent(event) {
-    // Abort if the current page isn't about:studies.
-    if (!this.ensureTrustedOrigin()) {
-      return;
-    }
-
     // 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.
     this.mm.addMessageListener("Shield:ShuttingDown", this);
     this.mm.addMessageListener("Shield:ReceiveStudyList", this);
     this.mm.addMessageListener("Shield:ReceiveStudiesEnabled", this);
 
     switch (event.detail.action) {
       // Actions that require the parent process
@@ -88,24 +80,16 @@ class ShieldFrameListener {
           "ReceiveRemoteValue:ShieldTranslations",
            strings
         );
         break;
     }
   }
 
   /**
-   * Check that the current webpage's origin is about:studies.
-   * @return {Boolean}
-   */
-  ensureTrustedOrigin() {
-    return this.mm.content.document.documentURI.startsWith("about:studies");
-  }
-
-  /**
    * Handle messages from the parent process.
    * @param {Object} message
    *   See the nsIMessageListener docs.
    */
   receiveMessage(message) {
     switch (message.name) {
       case "Shield:ReceiveStudyList":
         this.triggerPageCallback("ReceiveRemoteValue:StudyList", message.data.studies);
@@ -120,21 +104,16 @@ class ShieldFrameListener {
   }
 
   /**
    * Trigger an event to communicate with the unprivileged about: page.
    * @param {String} type
    * @param {Object} detail
    */
   triggerPageCallback(type, detail) {
-    // Do not communicate with untrusted pages.
-    if (!this.ensureTrustedOrigin()) {
-      return;
-    }
-
     let {content} = this.mm;
 
     // Clone details and use the event class from the unprivileged context.
     const event = new content.document.defaultView.CustomEvent(type, {
       bubbles: true,
       detail: Cu.cloneInto(detail, content.document.defaultView),
     });
     content.document.dispatchEvent(event);
--- a/toolkit/content/browser-content.js
+++ b/toolkit/content/browser-content.js
@@ -19,22 +19,16 @@ ChromeUtils.defineModuleGetter(this, "Au
   "resource://gre/modules/AutoScrollController.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "formFill",
                                    "@mozilla.org/satchel/form-fill-controller;1",
                                    "nsIFormFillController");
 
 var global = this;
 
-XPCOMUtils.defineLazyProxy(this, "ShieldFrameListener", () => {
-  let tmp = {};
-  ChromeUtils.import("resource://normandy-content/ShieldFrameListener.jsm", tmp);
-  return new tmp.ShieldFrameListener(global);
-});
-
 XPCOMUtils.defineLazyProxy(this, "UITourListener", () => {
   let tmp = {};
   ChromeUtils.import("resource:///modules/ContentUITour.jsm", tmp);
   return new tmp.UITourListener(global);
 });
 
 // Lazily load the finder code
 addMessageListener("Finder:Initialize", function() {
@@ -146,11 +140,9 @@ let AutoComplete = {
       }
       break;
     }
   },
 };
 
 AutoComplete.init();
 
-addEventListener("ShieldPageEvent", ShieldFrameListener, false, true);
-
 addEventListener("mozUITour", UITourListener, false, true);