| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.webview_shell; | 5 package org.chromium.webview_shell; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; |
| 7 import android.app.Activity; | 8 import android.app.Activity; |
| 8 import android.content.Intent; | 9 import android.content.Intent; |
| 9 import android.os.Bundle; | 10 import android.os.Bundle; |
| 10 import android.view.ViewGroup; | 11 import android.view.ViewGroup; |
| 11 import android.webkit.WebSettings; | 12 import android.webkit.WebSettings; |
| 12 import android.webkit.WebView; | 13 import android.webkit.WebView; |
| 13 import android.webkit.WebViewClient; | 14 import android.webkit.WebViewClient; |
| 14 import android.widget.RelativeLayout; | 15 import android.widget.RelativeLayout; |
| 15 | 16 |
| 16 /** | 17 /** |
| 17 * This activity always has at most one live webview. Any previously exisisting | 18 * This activity always has at most one live webview. Any previously exisisting |
| 18 * webview instance is destroyed first before creating a new one. This activity | 19 * webview instance is destroyed first before creating a new one. This activity |
| 19 * is designed for testing create/destroy webview sequence, for catching potenti
al | 20 * is designed for testing create/destroy webview sequence, for catching potenti
al |
| 20 * memory leaks and memory benchmarking. | 21 * memory leaks and memory benchmarking. |
| 21 * | 22 * |
| 22 * Note that this activity does not destroy any webviews in other activities. Fo
r | 23 * Note that this activity does not destroy any webviews in other activities. Fo
r |
| 23 * example launching TelemetryActivity followed by WebViewCreateDestroyActivity | 24 * example launching TelemetryActivity followed by WebViewCreateDestroyActivity |
| 24 * will yield two webview instances in total. | 25 * will yield two webview instances in total. |
| 25 */ | 26 */ |
| 26 public class WebViewCreateDestroyActivity extends Activity { | 27 public class WebViewCreateDestroyActivity extends Activity { |
| 28 @SuppressLint("StaticFieldLeak") |
| 27 private static WebView sWebView; | 29 private static WebView sWebView; |
| 28 | 30 |
| 29 @Override | 31 @Override |
| 30 protected void onDestroy() { | 32 protected void onDestroy() { |
| 31 destroyWebViewIfExists(); | 33 destroyWebViewIfExists(); |
| 32 super.onDestroy(); | 34 super.onDestroy(); |
| 33 } | 35 } |
| 34 | 36 |
| 35 @Override | 37 @Override |
| 36 protected void onCreate(Bundle savedInstanceState) { | 38 protected void onCreate(Bundle savedInstanceState) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 RelativeLayout layout = (RelativeLayout) findViewById(R.id.emptyview); | 79 RelativeLayout layout = (RelativeLayout) findViewById(R.id.emptyview); |
| 78 layout.removeView(sWebView); | 80 layout.removeView(sWebView); |
| 79 sWebView.destroy(); | 81 sWebView.destroy(); |
| 80 sWebView = null; | 82 sWebView = null; |
| 81 } | 83 } |
| 82 | 84 |
| 83 private static String getUrlFromIntent(Intent intent) { | 85 private static String getUrlFromIntent(Intent intent) { |
| 84 return intent != null ? intent.getDataString() : null; | 86 return intent != null ? intent.getDataString() : null; |
| 85 } | 87 } |
| 86 } | 88 } |
| OLD | NEW |