[WebLayer] Persist previous tab GUIDs in Shell app
The |mPreviousTabList| is used to set the active tab once the current one closes. This must be preserved across device reconfigurations as we might crash during rotations of the device otherwise. Bug: 1233023 Change-Id: I40859de7e4f4e9347524c3e4ba02e3f860e95515 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3053854 Reviewed-by: Clark DuVall <cduvall@chromium.org> Commit-Queue: Richard Knoll <knollr@chromium.org> Cr-Commit-Position: refs/heads/master@{#905270}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
b73040c6f2
commit
088ac310ed
@ -95,6 +95,7 @@ public class WebLayerShellActivity extends AppCompatActivity {
|
||||
|
||||
private static final String NON_INCOGNITO_PROFILE_NAME = "DefaultProfile";
|
||||
private static final String EXTRA_START_IN_INCOGNITO = "EXTRA_START_IN_INCOGNITO";
|
||||
private static final String KEY_PREVIOUS_TAB_GUIDS = "previousTabGuids";
|
||||
|
||||
private static class ContextMenuCreator
|
||||
implements View.OnCreateContextMenuListener, MenuItem.OnMenuItemClickListener {
|
||||
@ -312,6 +313,19 @@ public class WebLayerShellActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
||||
// Store the stack of previous tab GUIDs that are used to set the next active tab when a tab
|
||||
// closes. Also used to setup various callbacks again on restore.
|
||||
String[] previousTabGuids = new String[mPreviousTabList.size()];
|
||||
for (int i = 0; i < mPreviousTabList.size(); ++i) {
|
||||
previousTabGuids[i] = mPreviousTabList.get(i).getGuid();
|
||||
}
|
||||
outState.putStringArray(KEY_PREVIOUS_TAB_GUIDS, previousTabGuids);
|
||||
}
|
||||
|
||||
private void onAppMenuButtonClicked(View appMenuButtonView) {
|
||||
PopupMenu popup = new PopupMenu(WebLayerShellActivity.this, appMenuButtonView);
|
||||
popup.getMenuInflater().inflate(R.menu.app_menu, popup.getMenu());
|
||||
@ -597,6 +611,8 @@ public class WebLayerShellActivity extends AppCompatActivity {
|
||||
|
||||
createTabCallbacks();
|
||||
|
||||
restorePreviousTabList(savedInstanceState);
|
||||
|
||||
registerTabCallbacks(mBrowser.getActiveTab());
|
||||
|
||||
updateTopView();
|
||||
@ -704,6 +720,24 @@ public class WebLayerShellActivity extends AppCompatActivity {
|
||||
};
|
||||
}
|
||||
|
||||
private void restorePreviousTabList(Bundle savedInstanceState) {
|
||||
if (savedInstanceState == null) return;
|
||||
String[] previousTabGuids = savedInstanceState.getStringArray(KEY_PREVIOUS_TAB_GUIDS);
|
||||
if (previousTabGuids == null) return;
|
||||
|
||||
Map<String, Tab> currentTabMap = new HashMap<String, Tab>();
|
||||
for (Tab tab : mBrowser.getTabs()) {
|
||||
currentTabMap.put(tab.getGuid(), tab);
|
||||
}
|
||||
|
||||
for (String tabGuid : previousTabGuids) {
|
||||
Tab tab = currentTabMap.get(tabGuid);
|
||||
if (tab == null) continue;
|
||||
mPreviousTabList.add(tab);
|
||||
registerTabCallbacks(tab);
|
||||
}
|
||||
}
|
||||
|
||||
private void onTabAddedImpl(Tab newTab) {
|
||||
registerTabCallbacks(newTab);
|
||||
mPreviousTabList.add(mBrowser.getActiveTab());
|
||||
|
Reference in New Issue
Block a user