Bug 1499874 - Part 2: Remove tab IDs of tabs from the previous session file in the home panel. r=esawin
authorJan Henning <jh+bugzilla@buttercookie.de>
Sun, 23 Dec 2018 15:45:26 +0100
changeset 509925 1b2727505f8719b19133cef094dc2526cbd1ca81
parent 509924 75e5aa1db2e189dcc93b0d9bd1d8e65f982d1953
child 509926 ddfc4bd7728729de8111b38c3724b6e567ec21d0
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)
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 2: Remove tab IDs of tabs from the previous session file in the home panel. r=esawin We want to remove recently closed tabs from the list that have been restored again. At the moment this only works if the tab data never leaves Gecko, because in undoCloseTab(), the session store determines the tab data to be removed from its closed tab collection by checking for equality with the tab data that was passed as an argument to undoCloseTab(). So a tab restored through the "Undo" snackbar will be removed from the "Recently closed" list, but a tab restored from the History home panel won't, because in the latter case the tab data will have been serialised and deserialised while travelling back and forth between Gecko and the Android UI. Hence we're going to switch the system to identify tabs through their tab ID instead. If automatic session restoring is turned off, the "Recently closed" home panel also displays all tabs that were open in the previous session. Those tabs aren't coming directly from the session store; instead the Android UI reads them directly from the corresponding file on disk. Therefore, when restoring such a tab we need to make sure that the session store won't attempt to find and remove that tab from its own list of recently closed tabs. To that effect, we therefore simply drop the "tabId" when parsing the "last session" file from disk. Differential Revision: https://phabricator.services.mozilla.com/D15330
--- a/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
@@ -19,16 +19,18 @@ import org.mozilla.gecko.util.ThreadUtil
 import android.content.Context;
 import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.TextView;
+import org.json.JSONObject;
 import java.util.ArrayList;
 import java.util.List;
 import static org.mozilla.gecko.home.CombinedHistoryItem.ItemType;
 import static org.mozilla.gecko.home.CombinedHistoryPanel.OnPanelLevelChangeListener.PanelLevel.CHILD_RECENT_TABS;
 public class RecentTabsAdapter extends RecyclerView.Adapter<CombinedHistoryItem>
                                implements CombinedHistoryRecyclerView.AdapterContextMenuBuilder,
@@ -162,24 +164,29 @@ public class RecentTabsAdapter extends R
                 final List<ClosedTab> parsedTabs = new ArrayList<>();
                 new SessionParser() {
                     public void onTabRead(SessionTab tab) {
                         final String url = tab.getUrl();
                         // Don't show last tabs for about:home
                         if (AboutPages.isAboutHome(url)) {
+                        final JSONObject tabObject = tab.getTabObject();
+                        // The tab ID will be used to remove recently closed tabs that have been re-
+                        // stored again. Because these tabs come from a different source that is
+                        // read-only, we therefore need to remove the stored tab ID.
+                        tabObject.remove("tabId");
                         try {
-                            parsedTabs.add(new ClosedTab(url, tab.getTitle(), tab.getTabObject().toString()));
+                            parsedTabs.add(new ClosedTab(url, tab.getTitle(), tabObject.toString()));
                         } catch (OutOfMemoryError oom) {
                             // Stringifying may fail if the tab data is too large - let's hope that
                             // this tab was an exception and that the next one will be smaller and
                             // possibly succeed.