From 96d703076ccf0da697a1f77df41d05845bc4e886 Mon Sep 17 00:00:00 2001 From: Agi Sferro Date: Tue, 13 Oct 2020 17:59:41 +0000 Subject: [PATCH] Bug 1648155 - Migrate GeckoViewScrollChild to Actor. r=snorp Differential Revision: https://phabricator.services.mozilla.com/D93017 --- mobile/android/actors/ScrollDelegateChild.jsm | 46 +++++++++++++++++++ mobile/android/actors/moz.build | 1 + .../chrome/geckoview/GeckoViewScrollChild.js | 44 ------------------ mobile/android/chrome/geckoview/geckoview.js | 11 ++++- mobile/android/chrome/geckoview/jar.mn | 1 - 5 files changed, 57 insertions(+), 46 deletions(-) create mode 100644 mobile/android/actors/ScrollDelegateChild.jsm delete mode 100644 mobile/android/chrome/geckoview/GeckoViewScrollChild.js diff --git a/mobile/android/actors/ScrollDelegateChild.jsm b/mobile/android/actors/ScrollDelegateChild.jsm new file mode 100644 index 000000000000..d7f185b30d3c --- /dev/null +++ b/mobile/android/actors/ScrollDelegateChild.jsm @@ -0,0 +1,46 @@ +/* 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 { GeckoViewActorChild } = ChromeUtils.import( + "resource://gre/modules/GeckoViewActorChild.jsm" +); + +const { XPCOMUtils } = ChromeUtils.import( + "resource://gre/modules/XPCOMUtils.jsm" +); + +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); + +const EXPORTED_SYMBOLS = ["ScrollDelegateChild"]; + +class ScrollDelegateChild extends GeckoViewActorChild { + // eslint-disable-next-line complexity + handleEvent(aEvent) { + if (!this.isContentWindow) { + // This not a GeckoView-controlled window + return; + } + + if (aEvent.originalTarget.ownerGlobal != this.contentWindow) { + return; + } + + debug`handleEvent: ${aEvent.type}`; + + switch (aEvent.type) { + case "mozvisualscroll": + const x = {}; + const y = {}; + this.contentWindow.windowUtils.getVisualViewportOffset(x, y); + this.eventDispatcher.sendRequest({ + type: "GeckoView:ScrollChanged", + scrollX: x.value, + scrollY: y.value, + }); + break; + } + } +} + +const { debug, warn } = ScrollDelegateChild.initLogging("ScrollDelegate"); diff --git a/mobile/android/actors/moz.build b/mobile/android/actors/moz.build index 6f574720f954..b79d56e3646c 100644 --- a/mobile/android/actors/moz.build +++ b/mobile/android/actors/moz.build @@ -15,5 +15,6 @@ FINAL_TARGET_FILES.actors += [ 'LoadURIDelegateChild.jsm', 'ProgressDelegateChild.jsm', 'ProgressDelegateParent.jsm', + 'ScrollDelegateChild.jsm', 'WebBrowserChromeChild.jsm', ] diff --git a/mobile/android/chrome/geckoview/GeckoViewScrollChild.js b/mobile/android/chrome/geckoview/GeckoViewScrollChild.js deleted file mode 100644 index e7a05c982266..000000000000 --- a/mobile/android/chrome/geckoview/GeckoViewScrollChild.js +++ /dev/null @@ -1,44 +0,0 @@ -/* -*- 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" -); - -class GeckoViewScrollChild extends GeckoViewChildModule { - onEnable() { - debug`onEnable`; - addEventListener("mozvisualscroll", this, { mozSystemGroup: true }); - } - - onDisable() { - debug`onDisable`; - removeEventListener("mozvisualscroll", { mozSystemGroup: true }); - } - - handleEvent(aEvent) { - if (aEvent.originalTarget.ownerGlobal != content) { - return; - } - - debug`handleEvent: ${aEvent.type}`; - - switch (aEvent.type) { - case "mozvisualscroll": - const x = {}, - y = {}; - content.windowUtils.getVisualViewportOffset(x, y); - this.eventDispatcher.sendRequest({ - type: "GeckoView:ScrollChanged", - scrollX: x.value, - scrollY: y.value, - }); - break; - } - } -} - -const { debug, warn } = GeckoViewScrollChild.initLogging("GeckoViewScroll"); -const module = GeckoViewScrollChild.create(this); diff --git a/mobile/android/chrome/geckoview/geckoview.js b/mobile/android/chrome/geckoview/geckoview.js index 733f7a358b63..ac39418a013b 100644 --- a/mobile/android/chrome/geckoview/geckoview.js +++ b/mobile/android/chrome/geckoview/geckoview.js @@ -651,7 +651,16 @@ function startup() { { name: "GeckoViewScroll", onEnable: { - frameScript: "chrome://geckoview/content/GeckoViewScrollChild.js", + actors: { + ScrollDelegate: { + child: { + moduleURI: "resource:///actors/ScrollDelegateChild.jsm", + events: { + mozvisualscroll: { mozSystemGroup: true }, + }, + }, + }, + }, }, }, { diff --git a/mobile/android/chrome/geckoview/jar.mn b/mobile/android/chrome/geckoview/jar.mn index ddee4dcf6b7c..435d92fccdbf 100644 --- a/mobile/android/chrome/geckoview/jar.mn +++ b/mobile/android/chrome/geckoview/jar.mn @@ -16,7 +16,6 @@ geckoview.jar: content/GeckoViewMediaChild.js content/GeckoViewMediaControlChild.js content/GeckoViewPromptChild.js - content/GeckoViewScrollChild.js content/GeckoViewSelectionActionChild.js content/SessionStateAggregator.js