Bug 1728669 - Simplify GeckoView:WebExtension:Connect/Message handlers r=agi
authorRob Wu <rob@robwu.nl>
Thu, 02 Sep 2021 19:55:13 +0000
changeset 590856 452f3a79c1b24819926765ca930a3e2eb5533a4b
parent 590855 b647ffc0d5dfbc28a8403543bec89a5d27936837
child 590857 6c6500b08fad53f895b6aa4650ad21106e3dbc14
push id38757
push usermalexandru@mozilla.com
push dateFri, 03 Sep 2021 03:51:58 +0000
treeherdermozilla-central@3634785345fe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersagi
bugs1728669
milestone93.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 1728669 - Simplify GeckoView:WebExtension:Connect/Message handlers r=agi Differential Revision: https://phabricator.services.mozilla.com/D124260
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/WebExtensionController.java
mobile/android/modules/geckoview/GeckoViewWebExtension.jsm
mobile/android/modules/test/AppUiTestDelegate.jsm
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/WebExtensionController.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/WebExtensionController.java
@@ -719,25 +719,17 @@ public class WebExtensionController {
             return;
         } else if ("GeckoView:WebExtension:DebuggerListUpdated".equals(event)) {
             if (mDebuggerDelegate != null) {
                 mDebuggerDelegate.onExtensionListUpdated();
             }
             return;
         }
 
-        final GeckoBundle senderBundle;
-        if ("GeckoView:WebExtension:Connect".equals(event) ||
-                "GeckoView:WebExtension:Message".equals(event)) {
-            senderBundle = bundle.getBundle("sender");
-        } else {
-            senderBundle = bundle;
-        }
-
-        extensionFromBundle(senderBundle).accept(extension -> {
+        extensionFromBundle(bundle).accept(extension -> {
             if ("GeckoView:WebExtension:NewTab".equals(event)) {
                 newTab(message, extension);
                 return;
             } else if ("GeckoView:WebExtension:UpdateTab".equals(event)) {
                 updateTab(message, extension);
                 return;
             } else if ("GeckoView:WebExtension:CloseTab".equals(event)) {
                 closeTab(message, extension);
@@ -762,25 +754,29 @@ public class WebExtensionController {
                 return;
             } else if ("GeckoView:BrowsingData:Clear".equals(event)) {
                 browsingDataClear(message, extension);
                 return;
             } else if ("GeckoView:WebExtension:Download".equals(event)) {
                 download(message, extension);
                 return;
             }
+
+            // GeckoView:WebExtension:Connect and GeckoView:WebExtension:Message
+            // are handled below.
             final String nativeApp = bundle.getString("nativeApp");
             if (nativeApp == null) {
                 if (BuildConfig.DEBUG) {
                     throw new RuntimeException("Missing required nativeApp message parameter.");
                 }
                 callback.sendError("Missing nativeApp parameter.");
                 return;
             }
 
+            final GeckoBundle senderBundle = bundle.getBundle("sender");
             final WebExtension.MessageSender sender = fromBundle(extension, senderBundle, session);
             if (sender == null) {
                 if (callback != null) {
                     if (BuildConfig.DEBUG) {
                         try {
                             Log.e(LOGTAG, "Could not find recipient for message: " + bundle.toJSONObject());
                         } catch (final JSONException ex) {
                         }
--- a/mobile/android/modules/geckoview/GeckoViewWebExtension.jsm
+++ b/mobile/android/modules/geckoview/GeckoViewWebExtension.jsm
@@ -216,18 +216,16 @@ class EmbedderPort {
       }
     }
   }
 }
 
 class GeckoViewConnection {
   constructor(sender, target, nativeApp, allowContentMessaging) {
     this.sender = sender;
-    // Map from the extension MessageSender to the android GeckoBundle format.
-    sender.extensionId = sender.id;
     this.target = target;
     this.nativeApp = nativeApp;
     this.allowContentMessaging = allowContentMessaging;
 
     if (!allowContentMessaging && sender.envType !== "addon_child") {
       throw new Error(`Unexpected messaging sender: ${JSON.stringify(sender)}`);
     }
   }
@@ -260,16 +258,17 @@ class GeckoViewConnection {
   }
 
   _sendMessage({ type, portId, data }) {
     const message = {
       type,
       sender: this.sender,
       data,
       portId,
+      extensionId: this.sender.id,
       nativeApp: this.nativeApp,
     };
 
     return this.dispatcher.sendRequestForResult(message);
   }
 
   sendMessage(data) {
     return this._sendMessage({
--- a/mobile/android/modules/test/AppUiTestDelegate.jsm
+++ b/mobile/android/modules/test/AppUiTestDelegate.jsm
@@ -21,19 +21,19 @@ const TEST_SUPPORT_EXTENSION_ID = "test-
 
 class Delegate {
   _sendMessageToApp(data) {
     const message = {
       type: "GeckoView:WebExtension:Message",
       sender: {
         envType: "addon_child",
         url: "test-runner-support:///",
-        extensionId: TEST_SUPPORT_EXTENSION_ID,
       },
       data,
+      extensionId: TEST_SUPPORT_EXTENSION_ID,
       nativeApp: "test-runner-support",
     };
 
     return EventDispatcher.instance.sendRequestForResult(message);
   }
 
   clickPageAction(window, extensionId) {
     return this._sendMessageToApp({ type: "clickPageAction", extensionId });