Bug 832990 - Part 2 - Save and restore menu item caches via savedInstanceState. r?grisha draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 25 Jan 2018 20:47:16 +0100
changeset 749718 9aac6e905d3af0d6a4e99c35b4664b8c9f5fb12b
parent 749717 18c2a1040b50dd814c1543cef4ba03c335912a66
push id97478
push usermozilla@buttercookie.de
push dateWed, 31 Jan 2018 21:58:39 +0000
reviewersgrisha
bugs832990
milestone60.0a1
Bug 832990 - Part 2 - Save and restore menu item caches via savedInstanceState. r?grisha MozReview-Commit-ID: 6x5BDqhwabS
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
@@ -210,16 +210,18 @@ 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 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;
     public static final int ACTIVITY_RESULT_FIRST_READERVIEW_BOOKMARKS_GOTO_BOOKMARKS = 3002;
@@ -749,16 +751,24 @@ public class BrowserApp extends GeckoApp
             }
 
             @Override
             public boolean onTouch(View v, MotionEvent event) {
                 return false;
             }
         });
 
+        // 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);
+        }
+
         app.getLightweightTheme().addListener(this);
 
         mProgressView = (AnimatedProgressBar) findViewById(R.id.page_progress);
         mDynamicToolbar.setLayerView(mLayerView);
         mProgressView.setDynamicToolbar(mDynamicToolbar);
         mBrowserToolbar.setProgressBar(mProgressView);
 
         // Initialize Tab History Controller.
@@ -2484,16 +2494,25 @@ public class BrowserApp extends GeckoApp
         mMainLayoutAnimator = null;
     }
 
     @Override
     public void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
         mDynamicToolbar.onSaveInstanceState(outState);
         outState.putInt(STATE_ABOUT_HOME_TOP_PADDING, mHomeScreenContainer.getPaddingTop());
+
+        // 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);
     }
 
     /**
      * 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)}.
      *