Commit 12092c50 authored by tobiasjs's avatar tobiasjs Committed by Commit bot

Save and restore state in the webview shell.

This exercises webview state save/restore, and also makes using the
shell as a testing/demonstration tool easier, because the current URL
is retained and reloaded when you switch webview providers.

BUG=
NOPRESUBMIT=true

Review-Url: https://codereview.chromium.org/2330013002
Cr-Commit-Position: refs/heads/master@{#418825}
parent 9469d572
......@@ -184,6 +184,23 @@ public class WebViewBrowserActivity extends Activity implements PopupMenu.OnMenu
String url = getUrlFromIntent(getIntent());
if (url == null) {
mWebView.restoreState(savedInstanceState);
url = mWebView.getUrl();
if (url != null) {
// If we have restored state, and that state includes
// a loaded URL, we reload. This allows us to keep the
// scroll offset, and also doesn't add an additional
// navigation history entry.
setUrlBarText(url);
// The immediately previous loadUrlFromurlbar must
// have got as far as calling loadUrl, so there is no
// URI parsing error at this point.
setUrlFail(false);
hideKeyboard(mUrlBar);
mWebView.reload();
mWebView.requestFocus();
return;
}
// Make sure to load a blank page to make it immediately inspectable with
// chrome://inspect.
url = "about:blank";
......@@ -193,6 +210,12 @@ public class WebViewBrowserActivity extends Activity implements PopupMenu.OnMenu
loadUrlFromUrlBar(mUrlBar);
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
// Deliberately don't catch TransactionTooLargeException here.
mWebView.saveState(savedInstanceState);
}
@Override
public void onBackPressed() {
if (mWebView.canGoBack()) {
......
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