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

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

Issue 2102153002: [WebViewShell] Add activity for opening urls while creating/destroying webviews. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no-find-copies Created 4 years, 6 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 | « android_webview/tools/system_webview_shell/apk/res/values/strings.xml ('k') | 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/WebViewCreateDestroyActivity.java
diff --git a/android_webview/tools/system_webview_shell/apk/src/org/chromium/webview_shell/WebViewCreateDestroyActivity.java b/android_webview/tools/system_webview_shell/apk/src/org/chromium/webview_shell/WebViewCreateDestroyActivity.java
new file mode 100644
index 0000000000000000000000000000000000000000..6727bbc5051ec12d00ae996e709e19c0791a53c0
--- /dev/null
+++ b/android_webview/tools/system_webview_shell/apk/src/org/chromium/webview_shell/WebViewCreateDestroyActivity.java
@@ -0,0 +1,85 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.webview_shell;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.ViewGroup;
+import android.webkit.WebSettings;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+import android.widget.RelativeLayout;
+
+/**
+ * This activity always has at most one live webview. Any previously exisisting
+ * webview instance is destroyed first before creating a new one. This activity
+ * is designed for testing create/destroy webview sequence, for catching potential
+ * memory leaks and memory benchmarking.
+ *
+ * Note that this activity does not destroy any webviews in other activities. For
+ * example launching TelemetryActivity followed by WebViewCreateDestroyActivity
+ * will yield two webview instances in total.
+ */
+public class WebViewCreateDestroyActivity extends Activity {
+ private static WebView sWebView;
+
+ @Override
+ protected void onDestroy() {
+ destroyWebViewIfExists();
+ super.onDestroy();
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_empty);
+ getWindow().setTitle(
+ getResources().getString(R.string.title_activity_create_destroy));
+ onNewIntent(getIntent());
+ }
+
+ @Override
+ protected void onNewIntent(Intent intent) {
+ destroyWebViewIfExists();
+ openUsingNewWebView(intent);
+ }
+
+ private void openUsingNewWebView(Intent intent) {
+ sWebView = new WebView(this);
+ sWebView.setLayoutParams(
+ new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT));
+ RelativeLayout layout = (RelativeLayout) findViewById(R.id.emptyview);
+ layout.addView(sWebView);
+
+ WebSettings webSettings = sWebView.getSettings();
+ webSettings.setJavaScriptEnabled(true);
+ webSettings.setUseWideViewPort(true);
+ webSettings.setLoadWithOverviewMode(true);
+
+ sWebView.setWebViewClient(new WebViewClient() {
+ @Override
+ public boolean shouldOverrideUrlLoading(WebView view, String url) {
+ return false;
+ }
+ });
+
+ String url = getUrlFromIntent(intent);
+ sWebView.loadUrl(url == null ? "about:blank" : url);
+ }
+
+ private void destroyWebViewIfExists() {
+ if (sWebView == null) return;
+ RelativeLayout layout = (RelativeLayout) findViewById(R.id.emptyview);
+ layout.removeView(sWebView);
+ sWebView.destroy();
+ sWebView = null;
+ }
+
+ private static String getUrlFromIntent(Intent intent) {
+ return intent != null ? intent.getDataString() : null;
+ }
+}
« no previous file with comments | « android_webview/tools/system_webview_shell/apk/res/values/strings.xml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698