Bug 1414084 - Part 6 - Use only one list to store menu items added from Gecko. r?grisha draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Fri, 23 Mar 2018 19:58:18 +0100
changeset 823881 5e43f88947c297e93724613c2838e4350eed8ffb
parent 823880 98a4086d825e413a5a094538d25261ffc8804894
child 823882 a7012f02b31f1ddb0432d86998077026e83fecdc
push id117809
push usermozilla@buttercookie.de
push dateSun, 29 Jul 2018 18:19:15 +0000
reviewersgrisha
bugs1414084
milestone63.0a1
Bug 1414084 - Part 6 - Use only one list to store menu items added from Gecko. r?grisha Now that the UI code for handling both the old NativeWindow API and Web- extensions is more or less the same and both are using the same MenuItemInfo class, there's no longer any real need to keep items added through the two APIs in separate lists - in fact doing so makes it harder to preserve the ordering of menu items if the activity and its menu are destroyed and need to be re- created later on from the stored lists of MenuItemInfos. MozReview-Commit-ID: KlJdvO9WhhY
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
@@ -211,17 +211,16 @@ public class BrowserApp extends GeckoApp
     // Intent String extras used to specify custom Switchboard configurations.
     private static final String INTENT_KEY_SWITCHBOARD_SERVER = "switchboard-server";
 
     // TODO: Replace with kinto endpoint.
     private static final String SWITCHBOARD_SERVER = "https://firefox.settings.services.mozilla.com/v1/buckets/fennec/collections/experiments/records";
 
     private static final String STATE_ABOUT_HOME_TOP_PADDING = "abouthome_top_padding";
     private static final String STATE_ADDON_MENU_ITEM_CACHE = "menuitems_cache";
-    private static final String STATE_BROWSER_ACTION_ITEM_CACHE = "browseractions_cache";
     private static final String STATE_ADDON_MENU_NEXT_ID = "menuitems_nextId";
 
     private static final String BROWSER_SEARCH_TAG = "browser_search";
 
     // Request ID for startActivityForResult.
     public static final int ACTIVITY_REQUEST_PREFERENCES = 1001;
     private static final int ACTIVITY_REQUEST_TAB_QUEUE = 2001;
     public static final int ACTIVITY_REQUEST_FIRST_READERVIEW_BOOKMARK = 3001;
@@ -333,17 +332,16 @@ public class BrowserApp extends GeckoApp
 
     // The types of guest mode dialogs we show.
     public static enum GuestModeDialog {
         ENTERING,
         LEAVING
     }
 
     private ArrayList<MenuItemInfo> mAddonMenuItemsCache;
-    private ArrayList<MenuItemInfo> mBrowserActionItemsCache;
     private int mAddonMenuNextID = ADDON_MENU_OFFSET;
     private PropertyAnimator mMainLayoutAnimator;
 
     private static final Interpolator sTabsInterpolator = new Interpolator() {
         @Override
         public float getInterpolation(float t) {
             t -= 1.0f;
             return t * t * t * t * t + 1.0f;
@@ -746,17 +744,16 @@ public class BrowserApp extends GeckoApp
             }
         });
 
         // If the activity is being restored, the add-ons menu item cache only needs restoring if
         // Gecko is already running. Otherwise, we'll simply catch the corresponding events when
         // Gecko and the add-ons are starting up.
         if (savedInstanceState != null && mIsRestoringActivity) {
             mAddonMenuItemsCache = savedInstanceState.getParcelableArrayList(STATE_ADDON_MENU_ITEM_CACHE);
-            mBrowserActionItemsCache = savedInstanceState.getParcelableArrayList(STATE_BROWSER_ACTION_ITEM_CACHE);
             mAddonMenuNextID = savedInstanceState.getInt(STATE_ADDON_MENU_NEXT_ID);
         }
 
         app.getLightweightTheme().addListener(this);
 
         mProgressView = (AnimatedProgressBar) findViewById(R.id.page_progress);
         mDynamicToolbar.setLayerView(mLayerView);
         mProgressView.setDynamicToolbar(mDynamicToolbar);
@@ -2440,17 +2437,16 @@ public class BrowserApp extends GeckoApp
 
         // The various add-on UI item caches and event listeners should really live somewhere based
         // on the Application, so that their lifetime more closely matches that of Gecko itself, as
         // GeckoView-based activities can start Gecko (and therefore add-ons) while BrowserApp isn't
         // even running.
         // For now we'll only guard against the case where BrowserApp is destroyed and later re-
         // created while Gecko keeps running throughout, and leave the full solution to bug 1414084.
         outState.putParcelableArrayList(STATE_ADDON_MENU_ITEM_CACHE, mAddonMenuItemsCache);
-        outState.putParcelableArrayList(STATE_BROWSER_ACTION_ITEM_CACHE, mBrowserActionItemsCache);
         outState.putInt(STATE_ADDON_MENU_NEXT_ID, mAddonMenuNextID);
     }
 
     /**
      * Attempts to switch to an open tab with the given URL.
      * <p>
      * If the tab exists, this method cancels any in-progress editing as well as
      * calling {@link Tabs#selectTab(int)}.
@@ -3359,42 +3355,42 @@ public class BrowserApp extends GeckoApp
         item.setEnabled(info.enabled);
         item.setVisible(info.visible);
     }
 
     /**
      * Adds a WebExtension browser action to the menu.
      */
     private void addBrowserActionMenuItem(final MenuItemInfo info) {
-        if (mBrowserActionItemsCache == null) {
-            mBrowserActionItemsCache = new ArrayList<>();
+        if (mAddonMenuItemsCache == null) {
+            mAddonMenuItemsCache = new ArrayList<>();
         }
 
         // Always cache so we can rebuild after a locale switch.
-        mBrowserActionItemsCache.add(info);
+        mAddonMenuItemsCache.add(info);
 
         if (mMenu == null) {
             return;
         }
 
         addBrowserActionMenuItemToMenu(mMenu, info);
     }
 
     /**
      * Removes a WebExtension browser action from the menu by its UUID.
      */
     private void removeBrowserActionMenuItem(String uuid) {
         int id = -1;
 
         // Remove browser action menu item from cache, if available.
-        if (mBrowserActionItemsCache != null && !mBrowserActionItemsCache.isEmpty()) {
-            for (MenuItemInfo item : mBrowserActionItemsCache) {
+        if (mAddonMenuItemsCache != null && !mAddonMenuItemsCache.isEmpty()) {
+            for (MenuItemInfo item : mAddonMenuItemsCache) {
                 if (item.uuid.equals(uuid)) {
                     id = item.id;
-                    mBrowserActionItemsCache.remove(item);
+                    mAddonMenuItemsCache.remove(item);
                     break;
                 }
             }
         }
 
         if (mMenu == null || id == -1) {
             return;
         }
@@ -3407,18 +3403,18 @@ public class BrowserApp extends GeckoApp
 
     /**
      * 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 (MenuItemInfo item : mBrowserActionItemsCache) {
+        if (mAddonMenuItemsCache != null && !mAddonMenuItemsCache.isEmpty()) {
+            for (MenuItemInfo item : mAddonMenuItemsCache) {
                 if (item.uuid.equals(uuid)) {
                     id = item.id;
                     item.label = options.getString("name", item.label);
                     break;
                 }
             }
         }
 
@@ -3441,23 +3437,16 @@ public class BrowserApp extends GeckoApp
         if (menu instanceof GeckoMenu &&
             HardwareUtils.isTablet()) {
             ((GeckoMenu) menu).setActionItemBarPresenter(mBrowserToolbar);
         }
 
         MenuInflater inflater = getMenuInflater();
         inflater.inflate(R.menu.browser_app_menu, mMenu);
 
-        // Add browser action menu items, if any exist.
-        if (mBrowserActionItemsCache != null && !mBrowserActionItemsCache.isEmpty()) {
-            for (MenuItemInfo item : mBrowserActionItemsCache) {
-                addBrowserActionMenuItemToMenu(mMenu, item);
-            }
-        }
-
         // Add add-on menu items, if any exist.
         if (mAddonMenuItemsCache != null && !mAddonMenuItemsCache.isEmpty()) {
             for (MenuItemInfo item : mAddonMenuItemsCache) {
                 addAddonMenuItemToMenu(mMenu, item);
             }
         }
 
         // Action providers are available only ICS+.