Bug 1472491: Part 5ζ - Add ControllersChild actor. r=mconley
authorKris Maglione <maglione.k@gmail.com>
Mon, 30 Jul 2018 10:52:29 -0700
changeset 431485 1194a1b4bf239c861da8f8f89ab5e8dacb68848c
parent 431484 2d586e4a214e2e03b7c596872691f57acf240dcb
child 431486 1e3e2acebb2c832fbcc04ed64be7b9bb35941b0c
push id34443
push usercsabou@mozilla.com
push dateWed, 15 Aug 2018 00:53:32 +0000
treeherdermozilla-central@b80906e2fbc9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1472491
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 1472491: Part 5ζ - Add ControllersChild actor. r=mconley MozReview-Commit-ID: 2u6ayRoHvIh
toolkit/actors/ControllersChild.jsm
toolkit/actors/moz.build
toolkit/content/browser-child.js
toolkit/modules/ActorManagerParent.jsm
copy from toolkit/content/browser-child.js
copy to toolkit/actors/ControllersChild.jsm
--- a/toolkit/content/browser-child.js
+++ b/toolkit/actors/ControllersChild.jsm
@@ -1,106 +1,37 @@
+/* vim: set ts=2 sw=2 sts=2 et tw=80: */
 /* 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/. */
-
-/* eslint-env mozilla/frame-script */
+"use strict";
 
-ChromeUtils.import("resource://gre/modules/BrowserUtils.jsm");
-ChromeUtils.import("resource://gre/modules/Services.jsm");
-ChromeUtils.import("resource://gre/modules/Timer.jsm");
-ChromeUtils.import("resource://gre/modules/WebNavigationChild.jsm");
-ChromeUtils.import("resource://gre/modules/WebProgressChild.jsm");
+var EXPORTED_SYMBOLS = ["ControllersChild"];
 
-this.WebProgress = new WebProgressChild(this);
-this.WebNavigation = new WebNavigationChild(this);
-
+ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
 
-var ControllerCommands = {
-  init() {
-    addMessageListener("ControllerCommands:Do", this);
-    addMessageListener("ControllerCommands:DoWithParams", this);
-    this.init = null;
-  },
-
+class ControllersChild extends ActorChild {
   receiveMessage(message) {
     switch (message.name) {
       case "ControllerCommands:Do":
-        if (docShell.isCommandEnabled(message.data))
-          docShell.doCommand(message.data);
+        if (this.docShell.isCommandEnabled(message.data))
+          this.docShell.doCommand(message.data);
         break;
 
       case "ControllerCommands:DoWithParams":
         var data = message.data;
-        if (docShell.isCommandEnabled(data.cmd)) {
+        if (this.docShell.isCommandEnabled(data.cmd)) {
           var params = Cc["@mozilla.org/embedcomp/command-params;1"].
                        createInstance(Ci.nsICommandParams);
           for (var name in data.params) {
             var value = data.params[name];
             if (value.type == "long") {
               params.setLongValue(name, parseInt(value.value));
             } else {
               throw Cr.NS_ERROR_NOT_IMPLEMENTED;
             }
           }
-          docShell.doCommandWithParams(data.cmd, params);
+          this.docShell.doCommandWithParams(data.cmd, params);
         }
         break;
     }
   }
-};
-
-ControllerCommands.init();
-
-addEventListener("DOMTitleChanged", function(aEvent) {
-  if (!aEvent.isTrusted || aEvent.target.defaultView != content)
-    return;
-  sendAsyncMessage("DOMTitleChanged", { title: content.document.title });
-}, false);
-
-addEventListener("DOMWindowClose", function(aEvent) {
-  if (!aEvent.isTrusted)
-    return;
-  sendAsyncMessage("DOMWindowClose");
-}, false);
-
-addEventListener("ImageContentLoaded", function(aEvent) {
-  if (content.document instanceof Ci.nsIImageDocument) {
-    let req = content.document.imageRequest;
-    if (!req.image)
-      return;
-    sendAsyncMessage("ImageDocumentLoaded", { width: req.image.width,
-                                              height: req.image.height });
-  }
-}, false);
-
-/**
- * Remote createAboutBlankContentViewer request handler.
- */
-addMessageListener("Browser:CreateAboutBlank", function(aMessage) {
-  if (!content.document || content.document.documentURI != "about:blank") {
-    throw new Error("Can't create a content viewer unless on about:blank");
-  }
-  let principal = aMessage.data;
-  principal = BrowserUtils.principalWithMatchingOA(principal, content.document.nodePrincipal);
-  docShell.createAboutBlankContentViewer(principal);
-});
-
-addMessageListener("InPermitUnload", msg => {
-  let inPermitUnload = docShell.contentViewer && docShell.contentViewer.inPermitUnload;
-  sendAsyncMessage("InPermitUnload", {id: msg.data.id, inPermitUnload});
-});
-
-addMessageListener("PermitUnload", msg => {
-  sendAsyncMessage("PermitUnload", {id: msg.data.id, kind: "start"});
-
-  let permitUnload = true;
-  if (docShell && docShell.contentViewer) {
-    permitUnload = docShell.contentViewer.permitUnload(msg.data.aPermitUnloadFlags);
-  }
-
-  sendAsyncMessage("PermitUnload", {id: msg.data.id, kind: "end", permitUnload});
-});
-
-// We may not get any responses to Browser:Init if the browser element
-// is torn down too quickly.
-var outerWindowID = content.windowUtils.outerWindowID;
-sendAsyncMessage("Browser:Init", {outerWindowID});
+}
--- a/toolkit/actors/moz.build
+++ b/toolkit/actors/moz.build
@@ -1,16 +1,17 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
 FINAL_TARGET_FILES.actors += [
     'AudioPlaybackChild.jsm',
+    'ControllersChild.jsm',
     'DateTimePickerChild.jsm',
     'FindBarChild.jsm',
     'PopupBlockingChild.jsm',
     'PrintingChild.jsm',
     'PurgeSessionHistoryChild.jsm',
     'SelectChild.jsm',
     'SelectionSourceChild.jsm',
     'ThumbnailsChild.jsm',
--- a/toolkit/content/browser-child.js
+++ b/toolkit/content/browser-child.js
@@ -8,53 +8,16 @@ ChromeUtils.import("resource://gre/modul
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/Timer.jsm");
 ChromeUtils.import("resource://gre/modules/WebNavigationChild.jsm");
 ChromeUtils.import("resource://gre/modules/WebProgressChild.jsm");
 
 this.WebProgress = new WebProgressChild(this);
 this.WebNavigation = new WebNavigationChild(this);
 
-
-var ControllerCommands = {
-  init() {
-    addMessageListener("ControllerCommands:Do", this);
-    addMessageListener("ControllerCommands:DoWithParams", this);
-    this.init = null;
-  },
-
-  receiveMessage(message) {
-    switch (message.name) {
-      case "ControllerCommands:Do":
-        if (docShell.isCommandEnabled(message.data))
-          docShell.doCommand(message.data);
-        break;
-
-      case "ControllerCommands:DoWithParams":
-        var data = message.data;
-        if (docShell.isCommandEnabled(data.cmd)) {
-          var params = Cc["@mozilla.org/embedcomp/command-params;1"].
-                       createInstance(Ci.nsICommandParams);
-          for (var name in data.params) {
-            var value = data.params[name];
-            if (value.type == "long") {
-              params.setLongValue(name, parseInt(value.value));
-            } else {
-              throw Cr.NS_ERROR_NOT_IMPLEMENTED;
-            }
-          }
-          docShell.doCommandWithParams(data.cmd, params);
-        }
-        break;
-    }
-  }
-};
-
-ControllerCommands.init();
-
 addEventListener("DOMTitleChanged", function(aEvent) {
   if (!aEvent.isTrusted || aEvent.target.defaultView != content)
     return;
   sendAsyncMessage("DOMTitleChanged", { title: content.document.title });
 }, false);
 
 addEventListener("DOMWindowClose", function(aEvent) {
   if (!aEvent.isTrusted)
--- a/toolkit/modules/ActorManagerParent.jsm
+++ b/toolkit/modules/ActorManagerParent.jsm
@@ -107,16 +107,26 @@ let ACTORS = {
         "AudioPlayback",
       ],
       observers: [
         "audio-playback",
       ],
     },
   },
 
+  Controllers: {
+    child: {
+      module: "resource://gre/actors/ControllersChild.jsm",
+      messages: [
+        "ControllerCommands:Do",
+        "ControllerCommands:DoWithParams",
+      ],
+    },
+  },
+
   DateTimePicker: {
     child: {
       module: "resource://gre/actors/DateTimePickerChild.jsm",
       events: {
         "MozOpenDateTimePicker": {},
       },
     },
   },