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.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.annotation.TargetApi; | 8 import android.annotation.TargetApi; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.Intent; | 10 import android.content.Intent; |
11 import android.content.pm.PackageInfo; | |
11 import android.content.res.Configuration; | 12 import android.content.res.Configuration; |
12 import android.graphics.Bitmap; | 13 import android.graphics.Bitmap; |
13 import android.graphics.Canvas; | 14 import android.graphics.Canvas; |
14 import android.graphics.Paint; | 15 import android.graphics.Paint; |
15 import android.graphics.Picture; | 16 import android.graphics.Picture; |
16 import android.graphics.Rect; | 17 import android.graphics.Rect; |
17 import android.graphics.drawable.Drawable; | 18 import android.graphics.drawable.Drawable; |
18 import android.net.Uri; | 19 import android.net.Uri; |
19 import android.net.http.SslCertificate; | 20 import android.net.http.SslCertificate; |
20 import android.os.Build; | 21 import android.os.Build; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 import org.chromium.android_webview.AwPrintDocumentAdapter; | 56 import org.chromium.android_webview.AwPrintDocumentAdapter; |
56 import org.chromium.android_webview.AwSettings; | 57 import org.chromium.android_webview.AwSettings; |
57 import org.chromium.android_webview.ResourcesContextWrapperFactory; | 58 import org.chromium.android_webview.ResourcesContextWrapperFactory; |
58 import org.chromium.base.ThreadUtils; | 59 import org.chromium.base.ThreadUtils; |
59 import org.chromium.base.annotations.SuppressFBWarnings; | 60 import org.chromium.base.annotations.SuppressFBWarnings; |
60 import org.chromium.content.browser.SmartClipProvider; | 61 import org.chromium.content.browser.SmartClipProvider; |
61 import org.chromium.content_public.browser.NavigationHistory; | 62 import org.chromium.content_public.browser.NavigationHistory; |
62 | 63 |
63 import java.io.BufferedWriter; | 64 import java.io.BufferedWriter; |
64 import java.io.File; | 65 import java.io.File; |
66 import java.lang.reflect.Field; | |
65 import java.lang.reflect.Method; | 67 import java.lang.reflect.Method; |
66 import java.util.Map; | 68 import java.util.Map; |
67 import java.util.concurrent.Callable; | 69 import java.util.concurrent.Callable; |
70 import java.util.concurrent.atomic.AtomicBoolean; | |
68 | 71 |
69 /** | 72 /** |
70 * This class is the delegate to which WebViewProxy forwards all API calls. | 73 * This class is the delegate to which WebViewProxy forwards all API calls. |
71 * | 74 * |
72 * Most of the actual functionality is implemented by AwContents (or ContentView Core within | 75 * Most of the actual functionality is implemented by AwContents (or ContentView Core within |
73 * it). This class also contains WebView-specific APIs that require the creation of other | 76 * it). This class also contains WebView-specific APIs that require the creation of other |
74 * adapters (otherwise org.chromium.content would depend on the webview.chromium package) | 77 * adapters (otherwise org.chromium.content would depend on the webview.chromium package) |
75 * and a small set of no-op deprecated APIs. | 78 * and a small set of no-op deprecated APIs. |
76 */ | 79 */ |
77 @SuppressWarnings("deprecation") | 80 @SuppressWarnings("deprecation") |
(...skipping 17 matching lines...) Expand all Loading... | |
95 private AwContents mAwContents; | 98 private AwContents mAwContents; |
96 // Non-null if this webview is using the GL accelerated draw path. | 99 // Non-null if this webview is using the GL accelerated draw path. |
97 private DrawGLFunctor mGLfunctor; | 100 private DrawGLFunctor mGLfunctor; |
98 | 101 |
99 private final WebView.HitTestResult mHitTestResult; | 102 private final WebView.HitTestResult mHitTestResult; |
100 | 103 |
101 private final int mAppTargetSdkVersion; | 104 private final int mAppTargetSdkVersion; |
102 | 105 |
103 private WebViewChromiumFactoryProvider mFactory; | 106 private WebViewChromiumFactoryProvider mFactory; |
104 | 107 |
108 private static volatile AtomicBoolean sShouldAvoidThreadCheckingForHtcMail; | |
aelias_OOO_until_Jul13
2016/08/12 07:49:57
Reading https://docs.oracle.com/javase/7/docs/api/
Changwan Ryu
2016/08/12 08:40:30
Done.
| |
109 | |
105 private static boolean sRecordWholeDocumentEnabledByApi = false; | 110 private static boolean sRecordWholeDocumentEnabledByApi = false; |
106 static void enableSlowWholeDocumentDraw() { | 111 static void enableSlowWholeDocumentDraw() { |
107 sRecordWholeDocumentEnabledByApi = true; | 112 sRecordWholeDocumentEnabledByApi = true; |
108 } | 113 } |
109 | 114 |
110 // This does not touch any global / non-threadsafe state, but note that | 115 // This does not touch any global / non-threadsafe state, but note that |
111 // init is ofter called right after and is NOT threadsafe. | 116 // init is ofter called right after and is NOT threadsafe. |
112 public WebViewChromium(WebViewChromiumFactoryProvider factory, WebView webVi ew, | 117 public WebViewChromium(WebViewChromiumFactoryProvider factory, WebView webVi ew, |
113 WebView.PrivateAccess webViewPrivate) { | 118 WebView.PrivateAccess webViewPrivate) { |
114 mWebView = webView; | 119 mWebView = webView; |
(...skipping 13 matching lines...) Expand all Loading... | |
128 } | 133 } |
129 | 134 |
130 // WebViewProvider methods ------------------------------------------------- ------------------- | 135 // WebViewProvider methods ------------------------------------------------- ------------------- |
131 | 136 |
132 @Override | 137 @Override |
133 // BUG=6790250 |javaScriptInterfaces| was only ever used by the obsolete Dum pRenderTree | 138 // BUG=6790250 |javaScriptInterfaces| was only ever used by the obsolete Dum pRenderTree |
134 // so is ignored. TODO: remove it from WebViewProvider. | 139 // so is ignored. TODO: remove it from WebViewProvider. |
135 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 140 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
136 public void init(final Map<String, Object> javaScriptInterfaces, | 141 public void init(final Map<String, Object> javaScriptInterfaces, |
137 final boolean privateBrowsing) { | 142 final boolean privateBrowsing) { |
143 avoidThreadCheckingForHtcMail(mWebView); | |
aelias_OOO_until_Jul13
2016/08/12 07:49:57
Please restructure this to look like:
sIsHtcMail.
Changwan Ryu
2016/08/12 08:40:30
Done.
| |
138 if (privateBrowsing) { | 144 if (privateBrowsing) { |
139 mFactory.startYourEngines(true); | 145 mFactory.startYourEngines(true); |
140 final String msg = "Private browsing is not supported in WebView."; | 146 final String msg = "Private browsing is not supported in WebView."; |
141 if (mAppTargetSdkVersion >= Build.VERSION_CODES.KITKAT) { | 147 if (mAppTargetSdkVersion >= Build.VERSION_CODES.KITKAT) { |
142 throw new IllegalArgumentException(msg); | 148 throw new IllegalArgumentException(msg); |
143 } else { | 149 } else { |
144 Log.w(TAG, msg); | 150 Log.w(TAG, msg); |
145 TextView warningLabel = new TextView(mContext); | 151 TextView warningLabel = new TextView(mContext); |
146 warningLabel.setText(mContext.getString( | 152 warningLabel.setText(mContext.getString( |
147 org.chromium.android_webview.R.string.private_browsing_w arning)); | 153 org.chromium.android_webview.R.string.private_browsing_w arning)); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 // Intentionally irreversibly disable the webview instance, so that private | 197 // Intentionally irreversibly disable the webview instance, so that private |
192 // user data cannot leak through misuse of a non-privateBrow ing WebView | 198 // user data cannot leak through misuse of a non-privateBrow ing WebView |
193 // instance. Can't just null out mAwContents as we never nul l-check it | 199 // instance. Can't just null out mAwContents as we never nul l-check it |
194 // before use. | 200 // before use. |
195 destroy(); | 201 destroy(); |
196 } | 202 } |
197 } | 203 } |
198 }); | 204 }); |
199 } | 205 } |
200 | 206 |
207 private boolean shouldAvoidThreadCheckingForHtcMail(View view) { | |
aelias_OOO_until_Jul13
2016/08/12 07:49:57
Please rename this to isHtcMail and delete all lin
Changwan Ryu
2016/08/12 08:40:30
Done.
| |
208 if (sShouldAvoidThreadCheckingForHtcMail != null) { | |
209 return sShouldAvoidThreadCheckingForHtcMail.get(); | |
210 } | |
211 if (mAppTargetSdkVersion > Build.VERSION_CODES.M) return false; | |
212 final String htcMailPackageId = "com.htc.android.mail"; | |
213 if (view.getClass().getName() == null | |
214 || !view.getClass().getName().startsWith(htcMailPackageId)) { | |
215 sShouldAvoidThreadCheckingForHtcMail = new AtomicBoolean(false); | |
216 return false; | |
217 } | |
218 | |
219 try { | |
220 PackageInfo packageInfo = | |
221 view.getContext().getPackageManager().getPackageInfo(htcMail PackageId, 0); | |
222 // These values are provided by HTC. | |
223 if ((mAppTargetSdkVersion < Build.VERSION_CODES.M | |
224 && packageInfo.versionCode < 864021756) | |
225 || packageInfo.versionCode < 866001861) { | |
226 sShouldAvoidThreadCheckingForHtcMail = new AtomicBoolean(true); | |
227 return true; | |
228 } | |
229 } catch (Exception e) { | |
230 e.printStackTrace(); | |
231 } | |
232 sShouldAvoidThreadCheckingForHtcMail = new AtomicBoolean(false); | |
233 return false; | |
234 } | |
235 | |
236 // This is a workaround for https://crbug.com/622151. | |
237 // In HTC's email app, InputConnection.setComposingText() will call WebView. evaluateJavaScript, | |
238 // and thread assertion will occur. We turn off WebView thread assertion for this app. | |
239 private void avoidThreadCheckingForHtcMail(View view) { | |
aelias_OOO_until_Jul13
2016/08/12 07:49:57
Please rename to disableThreadChecking and remove
Changwan Ryu
2016/08/12 08:40:30
Done.
| |
240 if (!shouldAvoidThreadCheckingForHtcMail(view)) return; | |
241 | |
242 for (Class<?> webViewClass = view.getClass(); | |
243 webViewClass != null; | |
244 webViewClass = webViewClass.getSuperclass()) { | |
245 String name = webViewClass.getName(); | |
246 if (name != null && name.contains("WebView")) { | |
247 try { | |
248 Field field = webViewClass.getDeclaredField("sEnforceThreadC hecking"); | |
249 field.setAccessible(true); | |
250 field.setBoolean(null, false); | |
251 field.setAccessible(false); | |
252 Log.w(TAG, "We are turning off thread check for this apk."); | |
aelias_OOO_until_Jul13
2016/08/12 07:49:57
This log is a bit low on detail, I'd suggest print
Changwan Ryu
2016/08/12 08:40:30
Added log in isHtcMail() and removed this one.
| |
253 } catch (NoSuchFieldException | IllegalAccessException | |
254 | IllegalArgumentException e) { | |
255 e.printStackTrace(); | |
256 } | |
257 return; | |
258 } | |
259 } | |
260 } | |
261 | |
201 private void initForReal() { | 262 private void initForReal() { |
202 AwContentsStatics.setRecordFullDocument(sRecordWholeDocumentEnabledByApi | 263 AwContentsStatics.setRecordFullDocument(sRecordWholeDocumentEnabledByApi |
203 || mAppTargetSdkVersion < Build.VERSION_CODES.LOLLIPOP); | 264 || mAppTargetSdkVersion < Build.VERSION_CODES.LOLLIPOP); |
204 | 265 |
205 mAwContents = new AwContents(mFactory.getBrowserContextOnUiThread(), mWe bView, mContext, | 266 mAwContents = new AwContents(mFactory.getBrowserContextOnUiThread(), mWe bView, mContext, |
206 new InternalAccessAdapter(), new WebViewNativeDrawGLFunctorFacto ry(), | 267 new InternalAccessAdapter(), new WebViewNativeDrawGLFunctorFacto ry(), |
207 mContentsClientAdapter, mWebSettings.getAwSettings()); | 268 mContentsClientAdapter, mWebSettings.getAwSettings()); |
208 | 269 |
209 if (mAppTargetSdkVersion >= Build.VERSION_CODES.KITKAT) { | 270 if (mAppTargetSdkVersion >= Build.VERSION_CODES.KITKAT) { |
210 // On KK and above, favicons are automatically downloaded as the met hod | 271 // On KK and above, favicons are automatically downloaded as the met hod |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 @Override | 594 @Override |
534 public void run() { | 595 public void run() { |
535 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, enc oding, historyUrl); | 596 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, enc oding, historyUrl); |
536 } | 597 } |
537 }); | 598 }); |
538 return; | 599 return; |
539 } | 600 } |
540 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, histo ryUrl); | 601 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, histo ryUrl); |
541 } | 602 } |
542 | 603 |
543 public void evaluateJavaScript(String script, ValueCallback<String> resultCa llback) { | 604 public void evaluateJavaScript( |
605 final String script, final ValueCallback<String> resultCallback) { | |
606 if (shouldAvoidThreadCheckingForHtcMail(mWebView)) { | |
aelias_OOO_until_Jul13
2016/08/12 07:49:57
Please check sIsHtcMail.get() directly here.
Changwan Ryu
2016/08/12 08:40:30
Done.
| |
607 // This is a workaround for https://crbug.com/622151. | |
608 ThreadUtils.postOnUiThread(new Runnable() { | |
609 @Override | |
610 public void run() { | |
611 evaluateJavaScriptInternal(script, resultCallback); | |
612 } | |
613 }); | |
614 } else { | |
615 evaluateJavaScriptInternal(script, resultCallback); | |
616 } | |
617 } | |
618 | |
619 private void evaluateJavaScriptInternal(String script, ValueCallback<String> resultCallback) { | |
544 checkThread(); | 620 checkThread(); |
545 mAwContents.evaluateJavaScript(script, resultCallback); | 621 mAwContents.evaluateJavaScript(script, resultCallback); |
546 } | 622 } |
547 | 623 |
548 @Override | 624 @Override |
549 public void saveWebArchive(String filename) { | 625 public void saveWebArchive(String filename) { |
550 saveWebArchive(filename, false, null); | 626 saveWebArchive(filename, false, null); |
551 } | 627 } |
552 | 628 |
553 @Override | 629 @Override |
(...skipping 1673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2227 mAwContents.extractSmartClipData(x, y, width, height); | 2303 mAwContents.extractSmartClipData(x, y, width, height); |
2228 } | 2304 } |
2229 | 2305 |
2230 // Implements SmartClipProvider | 2306 // Implements SmartClipProvider |
2231 @Override | 2307 @Override |
2232 public void setSmartClipResultHandler(final Handler resultHandler) { | 2308 public void setSmartClipResultHandler(final Handler resultHandler) { |
2233 checkThread(); | 2309 checkThread(); |
2234 mAwContents.setSmartClipResultHandler(resultHandler); | 2310 mAwContents.setSmartClipResultHandler(resultHandler); |
2235 } | 2311 } |
2236 } | 2312 } |
OLD | NEW |