Bug 1472491: Part 5p - Add ExtFindChild actor. r?felipe draft
authorKris Maglione <maglione.k@gmail.com>
Sun, 29 Jul 2018 21:44:48 -0700
changeset 825195 af9cb28a1d68e3dd8624f6275267911e74f8fa68
parent 825194 e4571e8e6dd869056335fd61a81b5d2e6c5bca87
child 825196 12837aba553e89c20b452c011446a5bdfba61c10
push id118036
push usermaglione.k@gmail.com
push dateWed, 01 Aug 2018 02:23:07 +0000
reviewersfelipe
bugs1472491
milestone63.0a1
Bug 1472491: Part 5p - Add ExtFindChild actor. r?felipe MozReview-Commit-ID: 3zL8iYeYAPx
browser/components/extensions/test/browser/browser_ext_find.js
toolkit/content/browser-content.js
toolkit/modules/ActorManagerParent.jsm
toolkit/modules/ExtFindChild.jsm
toolkit/modules/moz.build
--- a/browser/components/extensions/test/browser/browser_ext_find.js
+++ b/browser/components/extensions/test/browser/browser_ext_find.js
@@ -35,30 +35,30 @@ function waitForMessage(messageManager, 
       messageManager.removeMessageListener(topic, messageListener);
       resolve(message);
     });
   });
 }
 
 add_task(async function testDuplicatePinnedTab() {
   async function background() {
-    function awaitLoad(tabId) {
+    function awaitLoad(tabId, url) {
       return new Promise(resolve => {
         browser.tabs.onUpdated.addListener(function listener(tabId_, changed, tab) {
-          if (tabId == tabId_ && changed.status == "complete") {
+          if (tabId == tabId_ && changed.status == "complete" && tab.url == url) {
             browser.tabs.onUpdated.removeListener(listener);
             resolve();
           }
         });
       });
     }
 
     let url = "http://example.com/browser/browser/components/extensions/test/browser/file_find_frames.html";
     let tab = await browser.tabs.update({url});
-    await awaitLoad(tab.id);
+    await awaitLoad(tab.id, url);
 
     let data = await browser.find.find("banana", {includeRangeData: true});
     let rangeData = data.rangeData;
 
     browser.test.log("Test that `data.count` is the expected value.");
     browser.test.assertEq(6, data.count, "The value returned from `data.count`");
 
     browser.test.log("Test that `rangeData` has the proper number of values.");
--- a/toolkit/content/browser-content.js
+++ b/toolkit/content/browser-content.js
@@ -14,18 +14,16 @@ ChromeUtils.import("resource://gre/modul
 ActorManagerChild.attach(this);
 
 ChromeUtils.defineModuleGetter(this, "AutoCompletePopup",
   "resource://gre/modules/AutoCompletePopupContent.jsm");
 ChromeUtils.defineModuleGetter(this, "AutoScrollController",
   "resource://gre/modules/AutoScrollController.jsm");
 ChromeUtils.defineModuleGetter(this, "SelectContentHelper",
   "resource://gre/modules/SelectContentHelper.jsm");
-ChromeUtils.defineModuleGetter(this, "FindContent",
-  "resource://gre/modules/FindContent.jsm");
 ChromeUtils.defineModuleGetter(this, "PrintingContent",
   "resource://gre/modules/PrintingContent.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "formFill",
                                    "@mozilla.org/satchel/form-fill-controller;1",
                                    "nsIFormFillController");
 
 var global = this;
@@ -213,46 +211,11 @@ addEventListener("mozshowdropdown-source
   if (!event.isTrusted)
     return;
 
   if (!SelectContentHelper.open) {
     new SelectContentHelper(event.target, {isOpenedViaTouch: true}, this);
   }
 });
 
-let ExtFind = {
-  init() {
-    addMessageListener("ext-Finder:CollectResults", this);
-    addMessageListener("ext-Finder:HighlightResults", this);
-    addMessageListener("ext-Finder:clearHighlighting", this);
-    this.init = null;
-  },
-
-  _findContent: null,
-
-  async receiveMessage(message) {
-    if (!this._findContent) {
-      this._findContent = new FindContent(docShell);
-    }
-
-    let data;
-    switch (message.name) {
-      case "ext-Finder:CollectResults":
-        this.finderInited = true;
-        data = await this._findContent.findRanges(message.data);
-        sendAsyncMessage("ext-Finder:CollectResultsFinished", data);
-        break;
-      case "ext-Finder:HighlightResults":
-        data = this._findContent.highlightResults(message.data);
-        sendAsyncMessage("ext-Finder:HighlightResultsFinished", data);
-        break;
-      case "ext-Finder:clearHighlighting":
-        this._findContent.highlighter.highlight(false);
-        break;
-    }
-  },
-};
-
-ExtFind.init();
-
 addEventListener("ShieldPageEvent", ShieldFrameListener, false, true);
 
 addEventListener("mozUITour", UITourListener, false, true);
--- a/toolkit/modules/ActorManagerParent.jsm
+++ b/toolkit/modules/ActorManagerParent.jsm
@@ -106,16 +106,27 @@ let ACTORS = {
         "AudioPlayback",
       ],
       observers: [
         "audio-playback",
       ],
     },
   },
 
+  ExtFind: {
+    module: "resource://gre/modules/ExtFind",
+    child: {
+      messages: [
+        "ext-Finder:CollectResults",
+        "ext-Finder:HighlightResults",
+        "ext-Finder:clearHighlighting",
+      ]
+    },
+  },
+
   FindBar: {
     module: "resource://gre/modules/FindBar",
     child: {
       events: {
         "keypress": {mozSystemGroup: true},
       },
     },
   },
new file mode 100644
--- /dev/null
+++ b/toolkit/modules/ExtFindChild.jsm
@@ -0,0 +1,36 @@
+/* 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 = ["ExtFindChild"];
+
+ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
+
+ChromeUtils.defineModuleGetter(this, "FindContent",
+                               "resource://gre/modules/FindContent.jsm");
+
+class ExtFindChild extends ActorChild {
+  async receiveMessage(message) {
+    if (!this._findContent) {
+      this._findContent = new FindContent(this.mm.docShell);
+    }
+
+    let data;
+    switch (message.name) {
+      case "ext-Finder:CollectResults":
+        this.finderInited = true;
+        data = await this._findContent.findRanges(message.data);
+        this.mm.sendAsyncMessage("ext-Finder:CollectResultsFinished", data);
+        break;
+      case "ext-Finder:HighlightResults":
+        data = this._findContent.highlightResults(message.data);
+        this.mm.sendAsyncMessage("ext-Finder:HighlightResultsFinished", data);
+        break;
+      case "ext-Finder:clearHighlighting":
+        this._findContent.highlighter.highlight(false);
+        break;
+    }
+  }
+}
--- a/toolkit/modules/moz.build
+++ b/toolkit/modules/moz.build
@@ -198,16 +198,17 @@ EXTRA_JS_MODULES += [
     'CreditCard.jsm',
     'css-selector.js',
     'DateTimePickerContent.jsm',
     'DateTimePickerParent.jsm',
     'DeferredTask.jsm',
     'Deprecated.jsm',
     'E10SUtils.jsm',
     'EventEmitter.jsm',
+    'ExtFindChild.jsm',
     'FileUtils.jsm',
     'FindBarChild.jsm',
     'FindBarContent.jsm',
     'Finder.jsm',
     'FinderHighlighter.jsm',
     'FinderIterator.jsm',
     'FormLikeFactory.jsm',
     'Geometry.jsm',