Commit 0a7b468e authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Fix crash when tab state can't be saved.

If the native WebContentsState returns null for some reason, we
shouldn't consider there to be a saved tab that we try to restore.

Bug: 982356
Change-Id: Ic7960faec2a90b534714ff4ba91b60cf89a01336
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1693601Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676593}
parent 45d5d4bd
...@@ -460,9 +460,10 @@ public class TabState { ...@@ -460,9 +460,10 @@ public class TabState {
* thread. * thread.
* @param bundle Bundle to write the tab's state to. * @param bundle Bundle to write the tab's state to.
* @param state State object obtained from from {@link Tab#getState()}. * @param state State object obtained from from {@link Tab#getState()}.
* @return Whether the tab state was successfully saved.
*/ */
public static void saveState(Bundle bundle, TabState state) { public static boolean saveState(Bundle bundle, TabState state) {
if (state == null || state.contentsState == null) return; if (state == null || state.contentsState == null) return false;
byte[] contentsStateBytes = getContentStateByteArray(state.contentsState.buffer()); byte[] contentsStateBytes = getContentStateByteArray(state.contentsState.buffer());
...@@ -479,6 +480,7 @@ public class TabState { ...@@ -479,6 +480,7 @@ public class TabState {
bundle.putInt(VERSION, state.contentsState.version()); bundle.putInt(VERSION, state.contentsState.version());
bundle.putInt(THEME_COLOR, state.themeColor); bundle.putInt(THEME_COLOR, state.themeColor);
bundle.putBoolean(IS_INCOGNITO, state.isIncognito()); bundle.putBoolean(IS_INCOGNITO, state.isIncognito());
return true;
} }
/** /**
......
...@@ -241,8 +241,9 @@ public class NoTouchActivity extends SingleTabActivity { ...@@ -241,8 +241,9 @@ public class NoTouchActivity extends SingleTabActivity {
Tab tab = getActivityTab(); Tab tab = getActivityTab();
if (tab == null || tab.getUrl() == null || tab.getUrl().isEmpty()) return; if (tab == null || tab.getUrl() == null || tab.getUrl().isEmpty()) return;
long time = SystemClock.elapsedRealtime(); long time = SystemClock.elapsedRealtime();
outState.putInt(BUNDLE_TAB_ID, tab.getId()); if (TabState.saveState(outState, TabState.from(tab))) {
TabState.saveState(outState, TabState.from(tab)); outState.putInt(BUNDLE_TAB_ID, tab.getId());
}
RecordHistogram.recordTimesHistogram("Android.StrictMode.NoTouchActivitySaveState", RecordHistogram.recordTimesHistogram("Android.StrictMode.NoTouchActivitySaveState",
SystemClock.elapsedRealtime() - time); SystemClock.elapsedRealtime() - time);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment