Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 com.android.webview.chromium; | 5 package com.android.webview.chromium; |
| 6 | 6 |
| 7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
| 10 import android.graphics.BitmapFactory; | 10 import android.graphics.BitmapFactory; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 private WebViewDelegate mWebViewDelegate; | 103 private WebViewDelegate mWebViewDelegate; |
| 104 | 104 |
| 105 private DownloadListener mDownloadListener; | 105 private DownloadListener mDownloadListener; |
| 106 | 106 |
| 107 private Handler mUiThreadHandler; | 107 private Handler mUiThreadHandler; |
| 108 | 108 |
| 109 private static final int NEW_WEBVIEW_CREATED = 100; | 109 private static final int NEW_WEBVIEW_CREATED = 100; |
| 110 | 110 |
| 111 private WeakHashMap<AwPermissionRequest, WeakReference<PermissionRequestAdap ter>> | 111 private WeakHashMap<AwPermissionRequest, WeakReference<PermissionRequestAdap ter>> |
| 112 mOngoingPermissionRequests; | 112 mOngoingPermissionRequests; |
| 113 | |
| 114 private static class UiThreadHandler extends Handler { | |
| 115 private final WeakReference<WebView> mWeakWebView; | |
|
boliu
2016/08/24 00:36:04
I... don't think this is safe. It's actually conce
| |
| 116 | |
| 117 public UiThreadHandler(WebView webView) { | |
| 118 mWeakWebView = new WeakReference<WebView>(webView); | |
| 119 } | |
| 120 | |
| 121 @Override | |
| 122 public void handleMessage(Message msg) { | |
| 123 switch (msg.what) { | |
| 124 case NEW_WEBVIEW_CREATED: | |
| 125 if (mWeakWebView.get() == null) { | |
|
boliu
2016/08/24 00:36:04
this is not c++ WeakPtr, gc can run at any time, a
| |
| 126 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
| |
| 127 } | |
| 128 WebView.WebViewTransport t = (WebView.WebViewTransport) msg. obj; | |
| 129 WebView newWebView = t.getWebView(); | |
| 130 if (newWebView == mWeakWebView.get()) { | |
| 131 throw new IllegalArgumentException( | |
| 132 "Parent WebView cannot host it's own popup windo w. Please " | |
| 133 + "use WebSettings.setSupportMultipleWindows(fal se)"); | |
| 134 } | |
| 135 | |
| 136 if (newWebView != null && newWebView.copyBackForwardList().g etSize() != 0) { | |
| 137 throw new IllegalArgumentException( | |
| 138 "New WebView for popup window must not have been previously " | |
| 139 + "navigated."); | |
| 140 } | |
| 141 | |
| 142 WebViewChromium.completeWindowCreation(mWeakWebView.get(), n ewWebView); | |
| 143 break; | |
| 144 default: | |
| 145 throw new IllegalStateException(); | |
| 146 } | |
| 147 } | |
| 148 } | |
| 149 | |
| 113 /** | 150 /** |
| 114 * Adapter constructor. | 151 * Adapter constructor. |
| 115 * | 152 * |
| 116 * @param webView the {@link WebView} instance that this adapter is serving. | 153 * @param webView the {@link WebView} instance that this adapter is serving. |
| 117 */ | 154 */ |
| 118 WebViewContentsClientAdapter(WebView webView, Context context, | 155 WebViewContentsClientAdapter(WebView webView, Context context, |
| 119 WebViewDelegate webViewDelegate) { | 156 WebViewDelegate webViewDelegate) { |
| 120 if (webView == null || webViewDelegate == null) { | 157 if (webView == null || webViewDelegate == null) { |
| 121 throw new IllegalArgumentException("webView or delegate can't be nul l."); | 158 throw new IllegalArgumentException("webView or delegate can't be nul l."); |
| 122 } | 159 } |
| 123 | 160 |
| 124 if (context == null) { | 161 if (context == null) { |
| 125 throw new IllegalArgumentException("context can't be null."); | 162 throw new IllegalArgumentException("context can't be null."); |
| 126 } | 163 } |
| 127 | 164 |
| 128 mContext = context; | 165 mContext = context; |
| 129 mWebView = webView; | 166 mWebView = webView; |
| 130 mWebViewDelegate = webViewDelegate; | 167 mWebViewDelegate = webViewDelegate; |
| 131 setWebViewClient(null); | 168 setWebViewClient(null); |
| 132 | 169 |
| 133 mUiThreadHandler = new Handler() { | 170 mUiThreadHandler = new UiThreadHandler(mWebView); |
| 134 @Override | |
| 135 public void handleMessage(Message msg) { | |
| 136 switch (msg.what) { | |
| 137 case NEW_WEBVIEW_CREATED: | |
| 138 WebView.WebViewTransport t = (WebView.WebViewTransport) msg.obj; | |
| 139 WebView newWebView = t.getWebView(); | |
| 140 if (newWebView == mWebView) { | |
| 141 throw new IllegalArgumentException( | |
| 142 "Parent WebView cannot host it's own popup w indow. Please " | |
| 143 + "use WebSettings.setSupportMultipleWindows (false)"); | |
| 144 } | |
| 145 | |
| 146 if (newWebView != null && newWebView.copyBackForwardList ().getSize() != 0) { | |
| 147 throw new IllegalArgumentException( | |
| 148 "New WebView for popup window must not have been previously " | |
| 149 + "navigated."); | |
| 150 } | |
| 151 | |
| 152 WebViewChromium.completeWindowCreation(mWebView, newWebV iew); | |
| 153 break; | |
| 154 default: | |
| 155 throw new IllegalStateException(); | |
| 156 } | |
| 157 } | |
| 158 }; | |
| 159 } | 171 } |
| 160 | 172 |
| 161 void setWebViewClient(WebViewClient client) { | 173 void setWebViewClient(WebViewClient client) { |
| 162 if (client != null) { | 174 if (client != null) { |
| 163 mWebViewClient = client; | 175 mWebViewClient = client; |
| 164 } else { | 176 } else { |
| 165 mWebViewClient = sNullWebViewClient; | 177 mWebViewClient = sNullWebViewClient; |
| 166 } | 178 } |
| 167 } | 179 } |
| 168 | 180 |
| (...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1282 mAwPermissionRequest.deny(); | 1294 mAwPermissionRequest.deny(); |
| 1283 } | 1295 } |
| 1284 } | 1296 } |
| 1285 | 1297 |
| 1286 @Override | 1298 @Override |
| 1287 public void deny() { | 1299 public void deny() { |
| 1288 mAwPermissionRequest.deny(); | 1300 mAwPermissionRequest.deny(); |
| 1289 } | 1301 } |
| 1290 } | 1302 } |
| 1291 } | 1303 } |
| OLD | NEW |