Bug 1472491: Part 5x - Add SelectionSourceChild actor. r=mconley draft
authorKris Maglione <maglione.k@gmail.com>
Sun, 29 Jul 2018 23:28:10 -0700
changeset 828459 b5361531f26d4cbc51489d867e8e34a1c97fb6f9
parent 828458 861d15a74541ce6dcc7542554fca946c18b89116
child 828460 90d2c9ae0dfd529e91490e25e5e17f9ea3ee9ecc
push id118680
push usermaglione.k@gmail.com
push dateFri, 10 Aug 2018 23:04:22 +0000
reviewersmconley
bugs1472491
milestone63.0a1
Bug 1472491: Part 5x - Add SelectionSourceChild actor. r=mconley MozReview-Commit-ID: 6RioXbevgRO
toolkit/actors/SelectionSourceChild.jsm
toolkit/actors/moz.build
toolkit/content/browser-content.js
toolkit/modules/ActorManagerParent.jsm
toolkit/modules/SelectionSourceContent.jsm
toolkit/modules/moz.build
rename from toolkit/modules/SelectionSourceContent.jsm
rename to toolkit/actors/SelectionSourceChild.jsm
--- a/toolkit/modules/SelectionSourceContent.jsm
+++ b/toolkit/actors/SelectionSourceChild.jsm
@@ -1,30 +1,31 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* 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 = ["SelectionSourceContent"];
+var EXPORTED_SYMBOLS = ["SelectionSourceChild"];
 
+ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
-var SelectionSourceContent = {
+class SelectionSourceChild extends ActorChild {
   receiveMessage(message) {
     const global = message.target;
 
     if (message.name == "ViewSource:GetSelection") {
       let selectionDetails;
       try {
         selectionDetails = this.getSelection(global);
       } finally {
         global.sendAsyncMessage("ViewSource:GetSelectionDone", selectionDetails);
       }
     }
-  },
+  }
 
   /**
    * A helper to get a path like FIXptr, but with an array instead of the
    * "tumbler" notation.
    * See FIXptr: http://lists.w3.org/Archives/Public/www-xml-linking-comments/2001AprJun/att-0074/01-NOTE-FIXptr-20010425.htm
    */
   getPath(ancestor, node) {
     var n = node;
@@ -40,17 +41,17 @@ var SelectionSourceContent = {
           path.push(i);
           break;
         }
       }
       n = p;
       p = n.parentNode;
     } while (n != ancestor && p);
     return path;
-  },
+  }
 
   getSelection(global) {
     const {content} = global;
 
     // These are markers used to delimit the selection during processing. They
     // are removed from the final rendering.
     // We use noncharacter Unicode codepoints to minimize the risk of clashing
     // with anything that might legitimately be present in the document.
@@ -172,14 +173,14 @@ var SelectionSourceContent = {
     tmpNode = dataDoc.createElementNS("http://www.w3.org/1999/xhtml", "div");
     tmpNode.appendChild(ancestorContainer);
 
     return { uri: (isHTML ? "view-source:data:text/html;charset=utf-8," :
                             "view-source:data:application/xml;charset=utf-8,")
                   + encodeURIComponent(tmpNode.innerHTML),
              drawSelection: canDrawSelection,
              baseURI: doc.baseURI };
-  },
+  }
 
   get wrapLongLines() {
     return Services.prefs.getBoolPref("view_source.wrap_long_lines");
-  },
-};
+  }
+}
--- a/toolkit/actors/moz.build
+++ b/toolkit/actors/moz.build
@@ -5,11 +5,12 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 FINAL_TARGET_FILES.actors += [
     'AudioPlaybackChild.jsm',
     'ExtFindChild.jsm',
     'FindBarChild.jsm',
     'PrintingChild.jsm',
     'SelectChild.jsm',
+    'SelectionSourceChild.jsm',
     'ThumbnailsChild.jsm',
     'ZoomChild.jsm',
 ]
--- a/toolkit/content/browser-content.js
+++ b/toolkit/content/browser-content.js
@@ -37,19 +37,16 @@ XPCOMUtils.defineLazyProxy(this, "Shield
 });
 
 XPCOMUtils.defineLazyProxy(this, "UITourListener", () => {
   let tmp = {};
   ChromeUtils.import("resource:///modules/ContentUITour.jsm", tmp);
   return new tmp.UITourListener(global);
 });
 
-XPCOMUtils.defineLazyProxy(this, "SelectionSourceContent",
-  "resource://gre/modules/SelectionSourceContent.jsm");
-
 XPCOMUtils.defineLazyProxy(this, "WebChannelContent",
   "resource://gre/modules/WebChannelContent.jsm");
 
 XPCOMUtils.defineLazyProxy(this, "DateTimePickerContent", () => {
   let tmp = {};
   ChromeUtils.import("resource://gre/modules/DateTimePickerContent.jsm", tmp);
   return new tmp.DateTimePickerContent(this);
 });
@@ -131,18 +128,16 @@ addMessageListener("Browser:PurgeSession
     --purge; // Don't remove the page the user's staring at from shistory
   }
 
   if (purge > 0) {
     sessionHistory.legacySHistory.PurgeHistory(purge);
   }
 });
 
-addMessageListener("ViewSource:GetSelection", SelectionSourceContent);
-
 let AutoComplete = {
   _connected: false,
 
   init() {
     addEventListener("unload", this, {once: true});
     addEventListener("DOMContentLoaded", this, {once: true});
     // WebExtension browserAction is preloaded and does not receive DCL, wait
     // on pageshow so we can hookup the formfill controller.
--- a/toolkit/modules/ActorManagerParent.jsm
+++ b/toolkit/modules/ActorManagerParent.jsm
@@ -153,16 +153,25 @@ let ACTORS = {
       module: "resource://gre/actors/SelectChild.jsm",
       events: {
         "mozshowdropdown": {},
         "mozshowdropdown-sourcetouch": {},
       },
     },
   },
 
+  SelectionSource: {
+    child: {
+      module: "resource://gre/actors/SelectionSourceChild.jsm",
+      messages: [
+        "ViewSource:GetSelection",
+      ],
+    },
+  },
+
   Thumbnails: {
     child: {
       module: "resource://gre/actors/ThumbnailsChild.jsm",
       messages: [
         "Browser:Thumbnail:Request",
         "Browser:Thumbnail:CheckState",
         "Browser:Thumbnail:GetOriginalURL",
       ],
--- a/toolkit/modules/moz.build
+++ b/toolkit/modules/moz.build
@@ -236,17 +236,16 @@ EXTRA_JS_MODULES += [
     'PromiseMessage.jsm',
     'PromiseUtils.jsm',
     'RemoteController.js',
     'RemoteFinder.jsm',
     'RemoteSecurityUI.jsm',
     'RemoteWebProgress.jsm',
     'ResetProfile.jsm',
     'ResponsivenessMonitor.jsm',
-    'SelectionSourceContent.jsm',
     'SelectParentHelper.jsm',
     'ServiceRequest.jsm',
     'Services.jsm',
     'sessionstore/FormData.jsm',
     'sessionstore/ScrollPosition.jsm',
     'ShortcutUtils.jsm',
     'Sqlite.jsm',
     'Task.jsm',