Bug 1414084 - Part 8 - Unify menu item EventDispatcher messages. r?grisha draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sun, 18 Mar 2018 16:42:57 +0100
changeset 823883 747887186a05d2d3ef3feedf957a104328d2f829
parent 823882 a7012f02b31f1ddb0432d86998077026e83fecdc
child 823884 f87beb9188f46e8336daf7d9b607c3bcf0e8c766
push id117809
push usermozilla@buttercookie.de
push dateSun, 29 Jul 2018 18:19:15 +0000
reviewersgrisha
bugs1414084
milestone63.0a1
Bug 1414084 - Part 8 - Unify menu item EventDispatcher messages. r?grisha As a final step, these can be merged as well. The same reasoning as in the previous patch applies with regards to additional functionality that isn't (yet) used by webextensions. MozReview-Commit-ID: Ezx2mQY0s85
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/modules/BrowserActions.jsm
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -851,19 +851,16 @@ public class BrowserApp extends GeckoApp
             null);
 
         EventDispatcher.getInstance().registerUiThreadListener(this,
             "GeckoView:AccessibilityEnabled",
             "Menu:Open",
             "Menu:Update",
             "Menu:Add",
             "Menu:Remove",
-            "Menu:AddBrowserAction",
-            "Menu:RemoveBrowserAction",
-            "Menu:UpdateBrowserAction",
             "LightweightTheme:Update",
             "Tab:Added",
             "Video:Play",
             "CharEncoding:Data",
             "CharEncoding:State",
             "Settings:Show",
             "Updater:Launch",
             "Sanitize:Finished",
@@ -1590,19 +1587,16 @@ public class BrowserApp extends GeckoApp
             null);
 
         EventDispatcher.getInstance().unregisterUiThreadListener(this,
             "GeckoView:AccessibilityEnabled",
             "Menu:Open",
             "Menu:Update",
             "Menu:Add",
             "Menu:Remove",
-            "Menu:AddBrowserAction",
-            "Menu:RemoveBrowserAction",
-            "Menu:UpdateBrowserAction",
             "LightweightTheme:Update",
             "Tab:Added",
             "Video:Play",
             "CharEncoding:Data",
             "CharEncoding:State",
             "Settings:Show",
             "Updater:Launch",
             "Sanitize:Finished",
@@ -1854,17 +1848,17 @@ public class BrowserApp extends GeckoApp
                     mBrowserToolbar.cancelEdit();
                 }
                 openOptionsMenu();
                 break;
 
             case "Menu:Add":
                 final MenuItemInfo info = new MenuItemInfo();
                 info.label = message.getString("name");
-                if (info.label == null) {
+                if (TextUtils.isEmpty(info.label)) {
                     Log.e(LOGTAG, "Invalid menu item name");
                     return;
                 }
                 info.id = mAddonMenuNextID++;
                 info.uuid = message.getString("uuid");
                 info.checked = message.getBoolean("checked", false);
                 info.enabled = message.getBoolean("enabled", true);
                 info.visible = message.getBoolean("visible", true);
@@ -1887,37 +1881,16 @@ public class BrowserApp extends GeckoApp
                 removeAddonMenuItem(message.getString("uuid"));
                 break;
 
             case "Menu:Update":
                 updateAddonMenuItem(message.getString("uuid"),
                                     message.getBundle("options"));
                 break;
 
-            case "Menu:AddBrowserAction":
-                final MenuItemInfo browserAction = new MenuItemInfo();
-                browserAction.label = message.getString("name");
-                if (TextUtils.isEmpty(browserAction.label)) {
-                    Log.e(LOGTAG, "Invalid browser action name");
-                    return;
-                }
-                browserAction.id = mAddonMenuNextID++;
-                browserAction.uuid = message.getString("uuid");
-                addAddonMenuItem(browserAction);
-                break;
-
-            case "Menu:RemoveBrowserAction":
-                removeAddonMenuItem(message.getString("uuid"));
-                break;
-
-            case "Menu:UpdateBrowserAction":
-                updateAddonMenuItem(message.getString("uuid"),
-                                    message.getBundle("options"));
-                break;
-
             case "LightweightTheme:Update":
                 mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
                 break;
 
             case "Search:Keyword":
                 storeSearchQuery(message.getString("query"));
                 recordSearch(GeckoSharedPrefs.forProfile(this), message.getString("identifier"),
                         TelemetryContract.Method.ACTIONBAR);
--- a/mobile/android/modules/BrowserActions.jsm
+++ b/mobile/android/modules/BrowserActions.jsm
@@ -60,17 +60,17 @@ var BrowserActions = {
   },
 
   /**
    * Registers a new browser action.
    * @param {Object} browserAction The browser action to add.
    */
   register(browserAction) {
     EventDispatcher.instance.sendRequest({
-      type: "Menu:AddBrowserAction",
+      type: "Menu:Add",
       uuid: browserAction.uuid,
       name: browserAction.defaults.name,
     });
 
     this._browserActions[browserAction.uuid] = browserAction;
     this._browserActionTitles[browserAction.uuid] = browserAction.defaults.name;
 
     this._maybeRegisterListeners();
@@ -79,17 +79,17 @@ var BrowserActions = {
   /**
    * Updates the browser action with the specified UUID.
    * @param {string} uuid The UUID of the browser action.
    * @param {Object} options The properties to update.
    */
   update(uuid, options) {
     if (options.name) {
       EventDispatcher.instance.sendRequest({
-        type: "Menu:UpdateBrowserAction",
+        type: "Menu:Update",
         uuid,
         options,
       });
 
       this._browserActionTitles[uuid] = options.name;
     }
   },
 
@@ -129,16 +129,16 @@ var BrowserActions = {
    * @param {string} uuid The UUID of the browser action.
    */
   unregister(uuid) {
     let browserAction = this._browserActions[uuid];
     if (!browserAction) {
       throw new Error(`No BrowserAction with UUID ${uuid} was found`);
     }
     EventDispatcher.instance.sendRequest({
-      type: "Menu:RemoveBrowserAction",
+      type: "Menu:Remove",
       uuid,
     });
     delete this._browserActions[uuid];
     delete this._browserActionTitles[uuid];
     this._maybeUnregisterListeners();
   }
 };