Bug 1472491: Part 5ζ - Add ControllersChild actor. r=mconley draft
authorKris Maglione <maglione.k@gmail.com>
Mon, 30 Jul 2018 10:52:29 -0700
changeset 828467 8da00377bc409ba83d5e6ccf05d825c6c4be7d24
parent 828466 43731b34415fe16f23b0582fc24165faa7f1aa1a
child 828468 479e16c7937b939a06dd6480bc29e2cfd39ab151
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 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
new file mode 100644
--- /dev/null
+++ b/toolkit/actors/ControllersChild.jsm
@@ -0,0 +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/. */
+"use strict";
+
+var EXPORTED_SYMBOLS = ["ControllersChild"];
+
+ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
+
+class ControllersChild extends ActorChild {
+  receiveMessage(message) {
+    switch (message.name) {
+      case "ControllerCommands:Do":
+        if (this.docShell.isCommandEnabled(message.data))
+          this.docShell.doCommand(message.data);
+        break;
+
+      case "ControllerCommands:DoWithParams":
+        var data = message.data;
+        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;
+            }
+          }
+          this.docShell.doCommandWithParams(data.cmd, params);
+        }
+        break;
+    }
+  }
+}
--- 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',
     'ExtFindChild.jsm',
     'FindBarChild.jsm',
     'PopupBlockingChild.jsm',
     'PrintingChild.jsm',
     'PurgeSessionHistoryChild.jsm',
     'SelectChild.jsm',
     'SelectionSourceChild.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
@@ -106,16 +106,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": {},
       },
     },
   },