Bug 1591462 - [1.1] Move autofill mechanics into a dedicated child module. r=snorp
authorEugen Sawin <esawin@me73.com>
Mon, 11 Nov 2019 17:22:18 +0000
changeset 501494 2a31fae3744051ac321dcfb371596b5a4004521c
parent 501493 0c672cce8019ad294204a0a2efb16cd7035dbde3
child 501495 4617ad7f36d478391771b06aa5164a9c9f2042ae
push id114170
push usermalexandru@mozilla.com
push dateTue, 12 Nov 2019 21:58:32 +0000
treeherdermozilla-inbound@9e3f44e87a1a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1591462
milestone72.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 1591462 - [1.1] Move autofill mechanics into a dedicated child module. r=snorp Differential Revision: https://phabricator.services.mozilla.com/D50630
mobile/android/chrome/geckoview/GeckoViewAutofillChild.js
mobile/android/chrome/geckoview/GeckoViewContentChild.js
mobile/android/chrome/geckoview/geckoview.js
mobile/android/chrome/geckoview/jar.mn
new file mode 100644
--- /dev/null
+++ b/mobile/android/chrome/geckoview/GeckoViewAutofillChild.js
@@ -0,0 +1,97 @@
+/* -*- 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/. */
+
+const { GeckoViewChildModule } = ChromeUtils.import(
+  "resource://gre/modules/GeckoViewChildModule.jsm"
+);
+var { XPCOMUtils } = ChromeUtils.import(
+  "resource://gre/modules/XPCOMUtils.jsm"
+);
+var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
+
+XPCOMUtils.defineLazyModuleGetters(this, {
+  FormLikeFactory: "resource://gre/modules/FormLikeFactory.jsm",
+  GeckoViewAutofill: "resource://gre/modules/GeckoViewAutofill.jsm",
+});
+
+class GeckoViewAutofillChild extends GeckoViewChildModule {
+  onInit() {
+    debug`onInit`;
+
+    const options = {
+      mozSystemGroup: true,
+      capture: false,
+    };
+
+    addEventListener("DOMFormHasPassword", this, options);
+    addEventListener("DOMInputPasswordAdded", this, options);
+    addEventListener("pagehide", this, options);
+    addEventListener("pageshow", this, options);
+    addEventListener("focusin", this, options);
+    addEventListener("focusout", this, options);
+
+    XPCOMUtils.defineLazyGetter(
+      this,
+      "_autofill",
+      () => new GeckoViewAutofill(this.eventDispatcher)
+    );
+  }
+
+  onEnable() {
+    debug`onEnable`;
+  }
+
+  onDisable() {
+    debug`onDisable`;
+  }
+
+  // eslint-disable-next-line complexity
+  handleEvent(aEvent) {
+    debug`handleEvent: ${aEvent.type}`;
+
+    switch (aEvent.type) {
+      case "DOMFormHasPassword": {
+        this._autofill.addElement(
+          FormLikeFactory.createFromForm(aEvent.composedTarget)
+        );
+        break;
+      }
+      case "DOMInputPasswordAdded": {
+        const input = aEvent.composedTarget;
+        if (!input.form) {
+          this._autofill.addElement(FormLikeFactory.createFromField(input));
+        }
+        break;
+      }
+      case "focusin": {
+        if (aEvent.composedTarget instanceof content.HTMLInputElement) {
+          this._autofill.onFocus(aEvent.composedTarget);
+        }
+        break;
+      }
+      case "focusout": {
+        if (aEvent.composedTarget instanceof content.HTMLInputElement) {
+          this._autofill.onFocus(null);
+        }
+        break;
+      }
+      case "pagehide": {
+        if (aEvent.target === content.document) {
+          this._autofill.clearElements();
+        }
+        break;
+      }
+      case "pageshow": {
+        if (aEvent.target === content.document && aEvent.persisted) {
+          this._autofill.scanDocument(aEvent.target);
+        }
+        break;
+      }
+    }
+  }
+}
+
+const { debug, warn } = GeckoViewAutofillChild.initLogging("GeckoViewAutofill"); // eslint-disable-line no-unused-vars
+const module = GeckoViewAutofillChild.create(this);
--- a/mobile/android/chrome/geckoview/GeckoViewContentChild.js
+++ b/mobile/android/chrome/geckoview/GeckoViewContentChild.js
@@ -18,18 +18,16 @@ const SCREEN_LENGTH_TYPE_VIEWPORT_HEIGHT
 const SCREEN_LENGTH_DOCUMENT_WIDTH = 3;
 const SCREEN_LENGTH_DOCUMENT_HEIGHT = 4;
 
 // This need to match PanZoomController.java
 const SCROLL_BEHAVIOR_SMOOTH = 0;
 const SCROLL_BEHAVIOR_AUTO = 1;
 
 XPCOMUtils.defineLazyModuleGetters(this, {
-  FormLikeFactory: "resource://gre/modules/FormLikeFactory.jsm",
-  GeckoViewAutofill: "resource://gre/modules/GeckoViewAutofill.jsm",
   ManifestObtainer: "resource://gre/modules/ManifestObtainer.jsm",
   PrivacyFilter: "resource://gre/modules/sessionstore/PrivacyFilter.jsm",
   SessionHistory: "resource://gre/modules/sessionstore/SessionHistory.jsm",
 });
 
 class GeckoViewContentChild extends GeckoViewChildModule {
   onInit() {
     debug`onInit`;
@@ -56,30 +54,18 @@ class GeckoViewContentChild extends Geck
     this.messageManager.addMessageListener("GeckoView:ZoomToInput", this);
     this.messageManager.addMessageListener("GeckoView:ScrollBy", this);
     this.messageManager.addMessageListener("GeckoView:ScrollTo", this);
 
     const options = {
       mozSystemGroup: true,
       capture: false,
     };
-    addEventListener("DOMFormHasPassword", this, options);
-    addEventListener("DOMInputPasswordAdded", this, options);
-    addEventListener("pagehide", this, options);
-    addEventListener("pageshow", this, options);
-    addEventListener("focusin", this, options);
-    addEventListener("focusout", this, options);
     addEventListener("mozcaretstatechanged", this, options);
 
-    XPCOMUtils.defineLazyGetter(
-      this,
-      "_autoFill",
-      () => new GeckoViewAutofill(this.eventDispatcher)
-    );
-
     // Notify WebExtension process script that this tab is ready for extension content to load.
     Services.obs.notifyObservers(
       this.messageManager,
       "tab-content-frameloader-created"
     );
   }
 
   onEnable() {
@@ -372,28 +358,16 @@ class GeckoViewContentChild extends Geck
             elementType,
             elementSrc: elementSrc || null,
           };
 
           this.eventDispatcher.sendRequest(msg);
           aEvent.preventDefault();
         }
         break;
-      case "DOMFormHasPassword":
-        this._autoFill.addElement(
-          FormLikeFactory.createFromForm(aEvent.composedTarget)
-        );
-        break;
-      case "DOMInputPasswordAdded": {
-        const input = aEvent.composedTarget;
-        if (!input.form) {
-          this._autoFill.addElement(FormLikeFactory.createFromField(input));
-        }
-        break;
-      }
       case "MozDOMFullscreen:Request":
         sendAsyncMessage("GeckoView:DOMFullscreenRequest");
         break;
       case "MozDOMFullscreen:Entered":
       case "MozDOMFullscreen:Exited":
         // Content may change fullscreen state by itself, and we should ensure
         // that the parent always exits fullscreen when content has left
         // full screen mode.
@@ -415,36 +389,16 @@ class GeckoViewContentChild extends Geck
           return;
         }
 
         aEvent.preventDefault();
         this.eventDispatcher.sendRequest({
           type: "GeckoView:DOMWindowClose",
         });
         break;
-      case "focusin":
-        if (aEvent.composedTarget instanceof content.HTMLInputElement) {
-          this._autoFill.onFocus(aEvent.composedTarget);
-        }
-        break;
-      case "focusout":
-        if (aEvent.composedTarget instanceof content.HTMLInputElement) {
-          this._autoFill.onFocus(null);
-        }
-        break;
-      case "pagehide":
-        if (aEvent.target === content.document) {
-          this._autoFill.clearElements();
-        }
-        break;
-      case "pageshow":
-        if (aEvent.target === content.document && aEvent.persisted) {
-          this._autoFill.scanDocument(aEvent.target);
-        }
-        break;
       case "mozcaretstatechanged":
         if (
           aEvent.reason === "presscaret" ||
           aEvent.reason === "releasecaret"
         ) {
           this.eventDispatcher.sendRequest({
             type: "GeckoView:PinOnScreen",
             pinned: aEvent.reason === "presscaret",
--- a/mobile/android/chrome/geckoview/geckoview.js
+++ b/mobile/android/chrome/geckoview/geckoview.js
@@ -522,16 +522,22 @@ function startup() {
       },
     },
     {
       name: "SessionStateAggregator",
       onInit: {
         frameScript: "chrome://geckoview/content/SessionStateAggregator.js",
       },
     },
+    {
+      name: "GeckoViewAutofill",
+      onInit: {
+        frameScript: "chrome://geckoview/content/GeckoViewAutofillChild.js",
+      },
+    },
   ]);
 
   Services.tm.dispatchToMainThread(() => {
     // This should always be the first thing we do here - any additional delayed
     // initialisation tasks should be added between "browser-delayed-startup-finished"
     // and "browser-idle-startup-tasks-finished".
 
     // Bug 1496684: Various bits of platform stuff depend on this notification
--- a/mobile/android/chrome/geckoview/jar.mn
+++ b/mobile/android/chrome/geckoview/jar.mn
@@ -7,16 +7,17 @@ geckoview.jar:
 
   content/config.xhtml
   content/config.js
 % override chrome://global/content/config.xul chrome://geckoview/content/config.xhtml
 
   content/ErrorPageEventHandler.js
   content/geckoview.xul
   content/geckoview.js
+  content/GeckoViewAutofillChild.js
   content/GeckoViewContentBlockingChild.js
   content/GeckoViewContentChild.js
   content/GeckoViewMediaChild.js
   content/GeckoViewProgressChild.js
   content/GeckoViewPromptChild.js
   content/GeckoViewScrollChild.js
   content/GeckoViewSettingsChild.js
   content/GeckoViewSelectionActionChild.js