Bug 1351111 - Add support for updating existing browser actions r?sebastian draft
authorMatthew Wein <mwein@mozilla.com>
Thu, 25 May 2017 17:11:56 -0400
changeset 586782 b6d0d9fa05265912d5f556683496507dc06c4f2c
parent 586775 9a5c710587f9e64bf044602d5e988b152ef4f40c
child 586783 885095dd7c55b9607f0d85a1e24396e73b249a85
push id61521
push usermwein@mozilla.com
push dateWed, 31 May 2017 03:08:36 +0000
reviewerssebastian
bugs1351111
milestone55.0a1
Bug 1351111 - Add support for updating existing browser actions r?sebastian MozReview-Commit-ID: 7fuDRmR75WD
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -764,16 +764,17 @@ public class BrowserApp extends GeckoApp
         EventDispatcher.getInstance().registerUiThreadListener(this,
             "Accessibility:Enabled",
             "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",
@@ -1573,16 +1574,17 @@ public class BrowserApp extends GeckoApp
         EventDispatcher.getInstance().unregisterUiThreadListener(this,
             "Accessibility:Enabled",
             "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",
@@ -1894,16 +1896,21 @@ public class BrowserApp extends GeckoApp
                 browserAction.uuid = message.getString("uuid");
                 addBrowserActionMenuItem(browserAction);
                 break;
 
             case "Menu:RemoveBrowserAction":
                 removeBrowserActionMenuItem(message.getString("uuid"));
                 break;
 
+            case "Menu:UpdateBrowserAction":
+                updateBrowserActionMenuItem(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);
@@ -3333,16 +3340,43 @@ public class BrowserApp extends GeckoApp
         }
 
         final MenuItem menuItem = mMenu.findItem(id);
         if (menuItem != null) {
             mMenu.removeItem(id);
         }
     }
 
+    /**
+     * Updates the WebExtension browser action with the specified UUID.
+     */
+    private void updateBrowserActionMenuItem(String uuid, final GeckoBundle options) {
+        int id = -1;
+
+        // Set attribute for the menu item in cache, if available
+        if (mBrowserActionItemsCache != null && !mBrowserActionItemsCache.isEmpty()) {
+            for (BrowserActionItemInfo item : mBrowserActionItemsCache) {
+                if (item.uuid.equals(uuid)) {
+                    id = item.id;
+                    item.label = options.getString("name", item.label);
+                    break;
+                }
+            }
+        }
+
+        if (mMenu == null || id == -1) {
+            return;
+        }
+
+        final MenuItem menuItem = mMenu.findItem(id);
+        if (menuItem != null) {
+            menuItem.setTitle(options.getString("name", menuItem.getTitle().toString()));
+        }
+    }
+
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
         // Sets mMenu = menu.
         super.onCreateOptionsMenu(menu);
 
         // Inform the menu about the action-items bar.
         if (menu instanceof GeckoMenu &&
             HardwareUtils.isTablet()) {