Bug 1728669 - Simplify GeckoView:WebExtension:Connect/Message handlers r=agi
☠☠ backed out by 214cd072efe2 ☠ ☠
authorRob Wu <rob@robwu.nl>
Wed, 01 Sep 2021 21:57:20 +0000
changeset 590534 35295637d5fd1494568118ed0b61b7e0ecde5d65
parent 590533 1ae51d10e2cb32597960a6d6fca84192407d0727
child 590535 8b72575a48e67c668751bb1d59a966860170dd1c
push id149021
push userrob@robwu.nl
push dateWed, 01 Sep 2021 22:00:14 +0000
treeherderautoland@35295637d5fd [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
--- 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({