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

Unified Diff: android_webview/glue/java/src/com/android/webview/chromium/WebViewContentsClientAdapter.java

Issue 2268233004: Fix HandlerLeak lint warning (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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/glue/java/src/com/android/webview/chromium/WebViewContentsClientAdapter.java
diff --git a/android_webview/glue/java/src/com/android/webview/chromium/WebViewContentsClientAdapter.java b/android_webview/glue/java/src/com/android/webview/chromium/WebViewContentsClientAdapter.java
index 1d28526a597de73ef6dfc7c835b0da7b1f81f555..a92a0cf7febd404552202440c397002ca3bc780e 100644
--- a/android_webview/glue/java/src/com/android/webview/chromium/WebViewContentsClientAdapter.java
+++ b/android_webview/glue/java/src/com/android/webview/chromium/WebViewContentsClientAdapter.java
@@ -110,6 +110,43 @@ public class WebViewContentsClientAdapter extends AwContentsClient {
private WeakHashMap<AwPermissionRequest, WeakReference<PermissionRequestAdapter>>
mOngoingPermissionRequests;
+
+ private static class UiThreadHandler extends Handler {
+ private final WeakReference<WebView> mWeakWebView;
boliu 2016/08/24 00:36:04 I... don't think this is safe. It's actually conce
+
+ public UiThreadHandler(WebView webView) {
+ mWeakWebView = new WeakReference<WebView>(webView);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case NEW_WEBVIEW_CREATED:
+ if (mWeakWebView.get() == null) {
boliu 2016/08/24 00:36:04 this is not c++ WeakPtr, gc can run at any time, a
+ return;
Torne 2016/08/24 15:31:36 Just returning here would mean that even though th
boliu 2016/08/24 16:08:59 It is. Have the native AwContents of the pop up be
+ }
+ WebView.WebViewTransport t = (WebView.WebViewTransport) msg.obj;
+ WebView newWebView = t.getWebView();
+ if (newWebView == mWeakWebView.get()) {
+ throw new IllegalArgumentException(
+ "Parent WebView cannot host it's own popup window. Please "
+ + "use WebSettings.setSupportMultipleWindows(false)");
+ }
+
+ if (newWebView != null && newWebView.copyBackForwardList().getSize() != 0) {
+ throw new IllegalArgumentException(
+ "New WebView for popup window must not have been previously "
+ + "navigated.");
+ }
+
+ WebViewChromium.completeWindowCreation(mWeakWebView.get(), newWebView);
+ break;
+ default:
+ throw new IllegalStateException();
+ }
+ }
+ }
+
/**
* Adapter constructor.
*
@@ -130,32 +167,7 @@ public class WebViewContentsClientAdapter extends AwContentsClient {
mWebViewDelegate = webViewDelegate;
setWebViewClient(null);
- mUiThreadHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case NEW_WEBVIEW_CREATED:
- WebView.WebViewTransport t = (WebView.WebViewTransport) msg.obj;
- WebView newWebView = t.getWebView();
- if (newWebView == mWebView) {
- throw new IllegalArgumentException(
- "Parent WebView cannot host it's own popup window. Please "
- + "use WebSettings.setSupportMultipleWindows(false)");
- }
-
- if (newWebView != null && newWebView.copyBackForwardList().getSize() != 0) {
- throw new IllegalArgumentException(
- "New WebView for popup window must not have been previously "
- + "navigated.");
- }
-
- WebViewChromium.completeWindowCreation(mWebView, newWebView);
- break;
- default:
- throw new IllegalStateException();
- }
- }
- };
+ mUiThreadHandler = new UiThreadHandler(mWebView);
}
void setWebViewClient(WebViewClient client) {
« 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