Bug 1499874 - Part 3: Renumber recently closed tabs from the previous session when automatically restoring. r=esawin
authorJan Henning <jh+bugzilla@buttercookie.de>
Sun, 23 Dec 2018 17:23:21 +0100
changeset 509926 ddfc4bd7728729de8111b38c3724b6e567ec21d0
parent 509925 1b2727505f8719b19133cef094dc2526cbd1ca81
child 509927 95343ed265a38b4cc4de4f12189e97948bfea845
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1499874
milestone66.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 1499874 - Part 3: Renumber recently closed tabs from the previous session when automatically restoring. r=esawin We want to remove recently closed tabs from the session store when they get re- stored again, and for that we need something to uniquely identify them. As tab IDs are unique per session only, this means that the tab IDs of recently closed tabs resurrected from the previous session could conflict with tabs that have been freshly opened in the current session. E.g. tab 2 has been closed in a previous session and is now part of the session store's closed tab list. In the current session, a number of tabs are opened again and then what is now the *current* tab 2 is closed as well. The result would be that the session store now has two closed tabs with a tab ID of 2. To avoid that scenario, all recently closed tabs are renumbered with an ID in the negative range at the start of the session. Therefore all tabs originally opened in the current session will have a tab ID >= 0, while all recently closed tabs coming directly from a previous session will have a negative tab ID, < -1. (-1 itself remains the sentinel value for an invalid tab ID). Differential Revision: https://phabricator.services.mozilla.com/D15331
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -289,16 +289,25 @@ public abstract class GeckoApp extends G
             } catch (JSONException e) {
                 Log.e(LOGTAG, "JSON error", e);
             }
             tabs.put(tabObject);
         }
 
         @Override
         public void onClosedTabsRead(final JSONArray closedTabData) throws JSONException {
+            // All tabs opened in the current session (including those that will be restored through
+            // the session store) will be numbered with a tab ID ≥ 0.
+            // To avoid duplicate IDs with closed tabs read from the previous session, we therefore
+            // renumber the latter with IDs in the negative range.
+            int closedTabId = Tabs.INVALID_TAB_ID;
+            for (int i = 0; i < closedTabData.length(); i++) {
+                final JSONObject closedTab = closedTabData.getJSONObject(i);
+                closedTab.put("tabId", --closedTabId);
+            }
             windowObject.put("closedTabs", closedTabData);
         }
 
         /**
          * Updates stored parent tab IDs in the session store data to match the new tab IDs
          * that have been allocated during startup session restore.
          *
          * @param tabData A JSONArray containg stored session store tabs.