Bug 1472491: Part 5s - Add ZoomChild actor. r?felipe draft
authorKris Maglione <maglione.k@gmail.com>
Sun, 29 Jul 2018 22:18:52 -0700
changeset 825690 3a42c5aa064688e1507b0f94c698fe495466037f
parent 825689 651e043263437799311e0573fd5e15b5b4ec19cb
child 825691 4b8a5c854a588ef6effb2ce8d8e55a056db5f9f8
push id118150
push usermaglione.k@gmail.com
push dateThu, 02 Aug 2018 04:47:08 +0000
reviewersfelipe
bugs1472491
milestone63.0a1
Bug 1472491: Part 5s - Add ZoomChild actor. r?felipe MozReview-Commit-ID: 9vTa1PbTh5t
browser/base/content/test/performance/browser_startup_content.js
toolkit/content/browser-child.js
toolkit/modules/ActorManagerParent.jsm
toolkit/modules/ZoomChild.jsm
toolkit/modules/moz.build
--- a/browser/base/content/test/performance/browser_startup_content.js
+++ b/browser/base/content/test/performance/browser_startup_content.js
@@ -54,16 +54,17 @@ const whitelist = {
     "resource://gre/modules/ActorChild.jsm",
     "resource://gre/modules/ActorManagerChild.jsm",
     "resource://gre/modules/BrowserUtils.jsm",
     "resource://gre/modules/E10SUtils.jsm",
     "resource://gre/modules/PrivateBrowsingUtils.jsm",
     "resource://gre/modules/ReaderMode.jsm",
     "resource://gre/modules/WebProgressChild.jsm",
     "resource://gre/modules/WebNavigationChild.jsm",
+    "resource://gre/modules/ZoomChild.jsm",
 
     // Pocket
     "chrome://pocket/content/AboutPocket.jsm",
 
     // Telemetry
     "resource://gre/modules/TelemetryController.jsm", // bug 1470339
     "resource://gre/modules/TelemetrySession.jsm", // bug 1470339
     "resource://gre/modules/TelemetryUtils.jsm", // bug 1470339
--- a/toolkit/content/browser-child.js
+++ b/toolkit/content/browser-child.js
@@ -70,100 +70,16 @@ addEventListener("ImageContentLoaded", f
     let req = content.document.imageRequest;
     if (!req.image)
       return;
     sendAsyncMessage("ImageDocumentLoaded", { width: req.image.width,
                                               height: req.image.height });
   }
 }, false);
 
-const ZoomManager = {
-  get fullZoom() {
-    return this._cache.fullZoom;
-  },
-
-  get textZoom() {
-    return this._cache.textZoom;
-  },
-
-  set fullZoom(value) {
-    this._cache.fullZoom = value;
-    this._markupViewer.fullZoom = value;
-  },
-
-  set textZoom(value) {
-    this._cache.textZoom = value;
-    this._markupViewer.textZoom = value;
-  },
-
-  refreshFullZoom() {
-    return this._refreshZoomValue("fullZoom");
-  },
-
-  refreshTextZoom() {
-    return this._refreshZoomValue("textZoom");
-  },
-
-  /**
-   * Retrieves specified zoom property value from markupViewer and refreshes
-   * cache if needed.
-   * @param valueName Either 'fullZoom' or 'textZoom'.
-   * @returns Returns true if cached value was actually refreshed.
-   * @private
-   */
-  _refreshZoomValue(valueName) {
-    let actualZoomValue = this._markupViewer[valueName];
-    // Round to remove any floating-point error.
-    actualZoomValue = Number(actualZoomValue.toFixed(2));
-    if (actualZoomValue != this._cache[valueName]) {
-      this._cache[valueName] = actualZoomValue;
-      return true;
-    }
-    return false;
-  },
-
-  get _markupViewer() {
-    return docShell.contentViewer;
-  },
-
-  _cache: {
-    fullZoom: NaN,
-    textZoom: NaN
-  }
-};
-
-addMessageListener("FullZoom", function(aMessage) {
-  ZoomManager.fullZoom = aMessage.data.value;
-});
-
-addMessageListener("TextZoom", function(aMessage) {
-  ZoomManager.textZoom = aMessage.data.value;
-});
-
-addEventListener("FullZoomChange", function() {
-  if (ZoomManager.refreshFullZoom()) {
-    sendAsyncMessage("FullZoomChange", { value: ZoomManager.fullZoom });
-  }
-}, false);
-
-addEventListener("TextZoomChange", function(aEvent) {
-  if (ZoomManager.refreshTextZoom()) {
-    sendAsyncMessage("TextZoomChange", { value: ZoomManager.textZoom });
-  }
-}, false);
-
-addEventListener("ZoomChangeUsingMouseWheel", function() {
-  sendAsyncMessage("ZoomChangeUsingMouseWheel", {});
-}, false);
-
-addMessageListener("UpdateCharacterSet", function(aMessage) {
-  docShell.charset = aMessage.data.value;
-  docShell.gatherCharsetMenuTelemetry();
-});
-
 /**
  * Remote thumbnail request handler for PageThumbs thumbnails.
  */
 addMessageListener("Browser:Thumbnail:Request", function(aMessage) {
   let snapshot;
   let args = aMessage.data.additionalArgs;
   let fullScale = args ? args.fullScale : false;
   if (fullScale) {
--- a/toolkit/modules/ActorManagerParent.jsm
+++ b/toolkit/modules/ActorManagerParent.jsm
@@ -152,16 +152,31 @@ let ACTORS = {
     module: "resource://gre/modules/Select",
     child: {
       events: {
         "mozshowdropdown": {},
         "mozshowdropdown-sourcetouch": {},
       },
     },
   },
+
+  Zoom: {
+    module: "resource://gre/modules/Zoom",
+    child: {
+      events: {
+        "FullZoomChange": {},
+        "TextZoomChange": {},
+        "ZoomChangeUsingMouseWheel": {},
+      },
+      messages: [
+        "FullZoom",
+        "TextZoom",
+      ],
+    },
+  },
 };
 
 class ActorSet {
   constructor(group, process) {
     this.group = group;
     this.process = process;
 
     this.actors = new Map();
new file mode 100644
--- /dev/null
+++ b/toolkit/modules/ZoomChild.jsm
@@ -0,0 +1,89 @@
+/* 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 = ["ZoomChild"];
+
+ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
+
+class ZoomChild extends ActorChild {
+  constructor(mm) {
+    super(mm);
+    this._cache = {
+      fullZoom: NaN,
+      textZoom: NaN,
+    };
+  }
+
+  get fullZoom() {
+    return this._cache.fullZoom;
+  }
+
+  get textZoom() {
+    return this._cache.textZoom;
+  }
+
+  set fullZoom(value) {
+    this._cache.fullZoom = value;
+    this._markupViewer.fullZoom = value;
+  }
+
+  set textZoom(value) {
+    this._cache.textZoom = value;
+    this._markupViewer.textZoom = value;
+  }
+
+  refreshFullZoom() {
+    return this._refreshZoomValue("fullZoom");
+  }
+
+  refreshTextZoom() {
+    return this._refreshZoomValue("textZoom");
+  }
+
+  /**
+   * Retrieves specified zoom property value from markupViewer and refreshes
+   * cache if needed.
+   * @param valueName Either 'fullZoom' or 'textZoom'.
+   * @returns Returns true if cached value was actually refreshed.
+   * @private
+   */
+  _refreshZoomValue(valueName) {
+    let actualZoomValue = this._markupViewer[valueName];
+    // Round to remove any floating-point error.
+    actualZoomValue = Number(actualZoomValue.toFixed(2));
+    if (actualZoomValue != this._cache[valueName]) {
+      this._cache[valueName] = actualZoomValue;
+      return true;
+    }
+    return false;
+  }
+
+  get _markupViewer() {
+    return this.docShell.contentViewer;
+  }
+
+  receiveMessage(message) {
+    if (message.name == "FullZoom") {
+      this.fullZoom = message.data.value;
+    } else if (message.name == "TextZoom") {
+      this.textZoom = message.data.value;
+    }
+  }
+
+  handleEvent(event) {
+    if (event.type == "FullZoomChange") {
+      if (this.refreshFullZoom()) {
+        this.mm.sendAsyncMessage("FullZoomChange", { value: this.fullZoom });
+      }
+    } else if (event.type == "TextZoomChange") {
+      if (this.refreshTextZoom()) {
+        this.mm.sendAsyncMessage("TextZoomChange", { value: this.textZoom });
+      }
+    } else if (event.type == "ZoomChangeUsingMouseWheel") {
+      this.mm.sendAsyncMessage("ZoomChangeUsingMouseWheel", {});
+    }
+  }
+}
--- a/toolkit/modules/moz.build
+++ b/toolkit/modules/moz.build
@@ -259,16 +259,17 @@ EXTRA_JS_MODULES += [
     'Troubleshoot.jsm',
     'UpdateUtils.jsm',
     'WebChannel.jsm',
     'WebChannelContent.jsm',
     'WebNavigationChild.jsm',
     'WebProgressChild.jsm',
     'WindowDraggingUtils.jsm',
     'ZipUtils.jsm',
+    'ZoomChild.jsm',
 ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     EXTRA_JS_MODULES += [
         'PropertyListUtils.jsm',
     ]
 
 EXTRA_JS_MODULES.third_party.jsesc += ['third_party/jsesc/jsesc.js']