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 sIsHtcMail = new AtomicBoolean(false); | |
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 sIsHtcMail.set(isHtcMail(mWebView.getContext())); | |
144 if (sIsHtcMail.get()) disableThreadChecking(); | |
138 if (privateBrowsing) { | 145 if (privateBrowsing) { |
139 mFactory.startYourEngines(true); | 146 mFactory.startYourEngines(true); |
140 final String msg = "Private browsing is not supported in WebView."; | 147 final String msg = "Private browsing is not supported in WebView."; |
141 if (mAppTargetSdkVersion >= Build.VERSION_CODES.KITKAT) { | 148 if (mAppTargetSdkVersion >= Build.VERSION_CODES.KITKAT) { |
142 throw new IllegalArgumentException(msg); | 149 throw new IllegalArgumentException(msg); |
143 } else { | 150 } else { |
144 Log.w(TAG, msg); | 151 Log.w(TAG, msg); |
145 TextView warningLabel = new TextView(mContext); | 152 TextView warningLabel = new TextView(mContext); |
146 warningLabel.setText(mContext.getString( | 153 warningLabel.setText(mContext.getString( |
147 org.chromium.android_webview.R.string.private_browsing_w arning)); | 154 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 | 198 // Intentionally irreversibly disable the webview instance, so that private |
192 // user data cannot leak through misuse of a non-privateBrow ing WebView | 199 // 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 | 200 // instance. Can't just null out mAwContents as we never nul l-check it |
194 // before use. | 201 // before use. |
195 destroy(); | 202 destroy(); |
196 } | 203 } |
197 } | 204 } |
198 }); | 205 }); |
199 } | 206 } |
200 | 207 |
208 private boolean isHtcMail(Context context) { | |
209 if (mAppTargetSdkVersion > Build.VERSION_CODES.M) return false; | |
Torne
2016/08/12 13:25:41
I'm not sure that checking the target SDK version
Changwan Ryu
2016/08/16 10:30:24
You're right. Fixed now.
| |
210 final String htcMailPackageId = "com.htc.android.mail"; | |
211 if (!htcMailPackageId.equals(context.getPackageName())) return false; | |
212 | |
213 try { | |
214 PackageInfo packageInfo = | |
215 context.getPackageManager().getPackageInfo(htcMailPackageId, 0); | |
216 // These values are provided by HTC. | |
217 if ((mAppTargetSdkVersion < Build.VERSION_CODES.M | |
218 && packageInfo.versionCode < 864021756) | |
219 || packageInfo.versionCode < 866001861) { | |
220 Log.w(TAG, "Disabling thread check in WebView (http://crbug.com/ 622151). " | |
221 + "APK name: " + htcMailPackageId + ", versionCode: " | |
222 + packageInfo.versionCode); | |
223 return true; | |
224 } | |
225 } catch (Exception e) { | |
Torne
2016/08/12 13:25:41
Comment or something here to note that we are inte
Changwan Ryu
2016/08/16 10:30:24
Done.
| |
226 } | |
227 return false; | |
228 } | |
229 | |
230 // This is a workaround for https://crbug.com/622151. | |
231 // In HTC's email app, InputConnection.setComposingText() will call WebView. evaluateJavaScript, | |
232 // and thread assertion will occur. We turn off WebView thread assertion for this app. | |
233 private void disableThreadChecking() { | |
234 try { | |
235 Class webViewClass = Class.forName("android.webkit.WebView"); | |
236 Field field = webViewClass.getDeclaredField("sEnforceThreadChecking" ); | |
237 field.setAccessible(true); | |
238 field.setBoolean(null, false); | |
239 field.setAccessible(false); | |
240 } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessEx ception | |
241 | IllegalArgumentException e) { | |
242 Log.w(TAG, "Failed to disable thread checking."); | |
243 } | |
244 } | |
245 | |
201 private void initForReal() { | 246 private void initForReal() { |
202 AwContentsStatics.setRecordFullDocument(sRecordWholeDocumentEnabledByApi | 247 AwContentsStatics.setRecordFullDocument(sRecordWholeDocumentEnabledByApi |
203 || mAppTargetSdkVersion < Build.VERSION_CODES.LOLLIPOP); | 248 || mAppTargetSdkVersion < Build.VERSION_CODES.LOLLIPOP); |
204 | 249 |
205 mAwContents = new AwContents(mFactory.getBrowserContextOnUiThread(), mWe bView, mContext, | 250 mAwContents = new AwContents(mFactory.getBrowserContextOnUiThread(), mWe bView, mContext, |
206 new InternalAccessAdapter(), new WebViewNativeDrawGLFunctorFacto ry(), | 251 new InternalAccessAdapter(), new WebViewNativeDrawGLFunctorFacto ry(), |
207 mContentsClientAdapter, mWebSettings.getAwSettings()); | 252 mContentsClientAdapter, mWebSettings.getAwSettings()); |
208 | 253 |
209 if (mAppTargetSdkVersion >= Build.VERSION_CODES.KITKAT) { | 254 if (mAppTargetSdkVersion >= Build.VERSION_CODES.KITKAT) { |
210 // On KK and above, favicons are automatically downloaded as the met hod | 255 // 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 | 578 @Override |
534 public void run() { | 579 public void run() { |
535 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, enc oding, historyUrl); | 580 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, enc oding, historyUrl); |
536 } | 581 } |
537 }); | 582 }); |
538 return; | 583 return; |
539 } | 584 } |
540 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, histo ryUrl); | 585 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, histo ryUrl); |
541 } | 586 } |
542 | 587 |
543 public void evaluateJavaScript(String script, ValueCallback<String> resultCa llback) { | 588 public void evaluateJavaScript( |
544 checkThread(); | 589 final String script, final ValueCallback<String> resultCallback) { |
545 mAwContents.evaluateJavaScript(script, resultCallback); | 590 if (sIsHtcMail.get()) { |
591 // This is a workaround for https://crbug.com/622151. | |
592 ThreadUtils.runOnUiThread(new Runnable() { | |
Torne
2016/08/12 13:25:41
Every other function here uses checkNeedsPost and
Changwan Ryu
2016/08/16 10:30:24
Done.
| |
593 @Override | |
594 public void run() { | |
595 mAwContents.evaluateJavaScript(script, resultCallback); | |
596 } | |
597 }); | |
598 } else { | |
599 checkThread(); | |
600 mAwContents.evaluateJavaScript(script, resultCallback); | |
601 } | |
546 } | 602 } |
547 | 603 |
548 @Override | 604 @Override |
549 public void saveWebArchive(String filename) { | 605 public void saveWebArchive(String filename) { |
550 saveWebArchive(filename, false, null); | 606 saveWebArchive(filename, false, null); |
551 } | 607 } |
552 | 608 |
553 @Override | 609 @Override |
554 public void saveWebArchive(final String basename, final boolean autoname, | 610 public void saveWebArchive(final String basename, final boolean autoname, |
555 final ValueCallback<String> callback) { | 611 final ValueCallback<String> callback) { |
(...skipping 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2227 mAwContents.extractSmartClipData(x, y, width, height); | 2283 mAwContents.extractSmartClipData(x, y, width, height); |
2228 } | 2284 } |
2229 | 2285 |
2230 // Implements SmartClipProvider | 2286 // Implements SmartClipProvider |
2231 @Override | 2287 @Override |
2232 public void setSmartClipResultHandler(final Handler resultHandler) { | 2288 public void setSmartClipResultHandler(final Handler resultHandler) { |
2233 checkThread(); | 2289 checkThread(); |
2234 mAwContents.setSmartClipResultHandler(resultHandler); | 2290 mAwContents.setSmartClipResultHandler(resultHandler); |
2235 } | 2291 } |
2236 } | 2292 } |
OLD | NEW |