Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2167)

Unified Diff: android_webview/tools/system_webview_shell/apk/src/org/chromium/webview_shell/WebViewBrowserActivity.java

Issue 2663413002: [WebView shell] Discard very long WebView states (Closed)
Patch Set: Added the actual legth to the toast message Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/tools/system_webview_shell/apk/src/org/chromium/webview_shell/WebViewBrowserActivity.java
diff --git a/android_webview/tools/system_webview_shell/apk/src/org/chromium/webview_shell/WebViewBrowserActivity.java b/android_webview/tools/system_webview_shell/apk/src/org/chromium/webview_shell/WebViewBrowserActivity.java
index c8b3ae75e7903f68545beb872fadb7dad0d1a847..802a2f9bb82c102c82886c0d129903e962aca93a 100644
--- a/android_webview/tools/system_webview_shell/apk/src/org/chromium/webview_shell/WebViewBrowserActivity.java
+++ b/android_webview/tools/system_webview_shell/apk/src/org/chromium/webview_shell/WebViewBrowserActivity.java
@@ -44,6 +44,7 @@ import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.PopupMenu;
import android.widget.TextView;
+import android.widget.Toast;
import org.chromium.base.Log;
@@ -56,6 +57,7 @@ import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -74,6 +76,12 @@ public class WebViewBrowserActivity extends Activity implements PopupMenu.OnMenu
// WebKit permissions with no corresponding Android permission can always be granted
private static final String NO_ANDROID_PERMISSION = "NO_ANDROID_PERMISSION";
+ // TODO(timav): Remove these variables after http://crbug.com/626202 is fixed.
+ // The Bundle key for WebView serialized state
+ private static final String SAVE_RESTORE_STATE_KEY = "WEBVIEW_CHROMIUM_STATE";
+ // Maximal size of this state.
+ private static final int MAX_STATE_LENGTH = 300 * 1024;
+
// Map from WebKit permissions to Android permissions
private static final HashMap<String, String> sPermissions;
static {
@@ -214,6 +222,17 @@ public class WebViewBrowserActivity extends Activity implements PopupMenu.OnMenu
public void onSaveInstanceState(Bundle savedInstanceState) {
// Deliberately don't catch TransactionTooLargeException here.
mWebView.saveState(savedInstanceState);
+
+ // TODO(timav): Remove this hack after http://crbug.com/626202 is fixed.
+ // Drop the saved state of it is too long since Android N and above
+ // can't handle large states without a crash.
+ byte[] webViewState = savedInstanceState.getByteArray(SAVE_RESTORE_STATE_KEY);
+ if (webViewState != null && webViewState.length > MAX_STATE_LENGTH) {
+ savedInstanceState.remove(SAVE_RESTORE_STATE_KEY);
+ String message = String.format(
+ Locale.US, "Can't save state: %dkb is too long", webViewState.length / 1024);
+ Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
+ }
}
@Override
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698