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; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 import org.chromium.android_webview.AwPrintDocumentAdapter; | 55 import org.chromium.android_webview.AwPrintDocumentAdapter; |
56 import org.chromium.android_webview.AwSettings; | 56 import org.chromium.android_webview.AwSettings; |
57 import org.chromium.android_webview.ResourcesContextWrapperFactory; | 57 import org.chromium.android_webview.ResourcesContextWrapperFactory; |
58 import org.chromium.base.ThreadUtils; | 58 import org.chromium.base.ThreadUtils; |
59 import org.chromium.base.annotations.SuppressFBWarnings; | 59 import org.chromium.base.annotations.SuppressFBWarnings; |
60 import org.chromium.content.browser.SmartClipProvider; | 60 import org.chromium.content.browser.SmartClipProvider; |
61 import org.chromium.content_public.browser.NavigationHistory; | 61 import org.chromium.content_public.browser.NavigationHistory; |
62 | 62 |
63 import java.io.BufferedWriter; | 63 import java.io.BufferedWriter; |
64 import java.io.File; | 64 import java.io.File; |
65 import java.lang.reflect.Field; | |
65 import java.lang.reflect.Method; | 66 import java.lang.reflect.Method; |
66 import java.util.Map; | 67 import java.util.Map; |
67 import java.util.concurrent.Callable; | 68 import java.util.concurrent.Callable; |
68 | 69 |
69 /** | 70 /** |
70 * This class is the delegate to which WebViewProxy forwards all API calls. | 71 * This class is the delegate to which WebViewProxy forwards all API calls. |
71 * | 72 * |
72 * Most of the actual functionality is implemented by AwContents (or ContentView Core within | 73 * 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 | 74 * 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) | 75 * adapters (otherwise org.chromium.content would depend on the webview.chromium package) |
(...skipping 20 matching lines...) Expand all Loading... | |
95 private AwContents mAwContents; | 96 private AwContents mAwContents; |
96 // Non-null if this webview is using the GL accelerated draw path. | 97 // Non-null if this webview is using the GL accelerated draw path. |
97 private DrawGLFunctor mGLfunctor; | 98 private DrawGLFunctor mGLfunctor; |
98 | 99 |
99 private final WebView.HitTestResult mHitTestResult; | 100 private final WebView.HitTestResult mHitTestResult; |
100 | 101 |
101 private final int mAppTargetSdkVersion; | 102 private final int mAppTargetSdkVersion; |
102 | 103 |
103 private WebViewChromiumFactoryProvider mFactory; | 104 private WebViewChromiumFactoryProvider mFactory; |
104 | 105 |
106 private final boolean mShouldDisableThreadChecking; | |
107 | |
105 private static boolean sRecordWholeDocumentEnabledByApi = false; | 108 private static boolean sRecordWholeDocumentEnabledByApi = false; |
106 static void enableSlowWholeDocumentDraw() { | 109 static void enableSlowWholeDocumentDraw() { |
107 sRecordWholeDocumentEnabledByApi = true; | 110 sRecordWholeDocumentEnabledByApi = true; |
108 } | 111 } |
109 | 112 |
110 // This does not touch any global / non-threadsafe state, but note that | 113 // This does not touch any global / non-threadsafe state, but note that |
111 // init is ofter called right after and is NOT threadsafe. | 114 // init is ofter called right after and is NOT threadsafe. |
112 public WebViewChromium(WebViewChromiumFactoryProvider factory, WebView webVi ew, | 115 public WebViewChromium(WebViewChromiumFactoryProvider factory, WebView webVi ew, |
113 WebView.PrivateAccess webViewPrivate) { | 116 WebView.PrivateAccess webViewPrivate, boolean shouldDisableThreadChe cking) { |
114 mWebView = webView; | 117 mWebView = webView; |
115 mWebViewPrivate = webViewPrivate; | 118 mWebViewPrivate = webViewPrivate; |
116 mHitTestResult = new WebView.HitTestResult(); | 119 mHitTestResult = new WebView.HitTestResult(); |
117 mContext = ResourcesContextWrapperFactory.get(mWebView.getContext()); | 120 mContext = ResourcesContextWrapperFactory.get(mWebView.getContext()); |
118 mAppTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; | 121 mAppTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
119 mFactory = factory; | 122 mFactory = factory; |
123 mShouldDisableThreadChecking = shouldDisableThreadChecking; | |
120 factory.getWebViewDelegate().addWebViewAssetPath(mWebView.getContext()); | 124 factory.getWebViewDelegate().addWebViewAssetPath(mWebView.getContext()); |
121 } | 125 } |
122 | 126 |
123 static void completeWindowCreation(WebView parent, WebView child) { | 127 static void completeWindowCreation(WebView parent, WebView child) { |
124 AwContents parentContents = ((WebViewChromium) parent.getWebViewProvider ()).mAwContents; | 128 AwContents parentContents = ((WebViewChromium) parent.getWebViewProvider ()).mAwContents; |
125 AwContents childContents = | 129 AwContents childContents = |
126 child == null ? null : ((WebViewChromium) child.getWebViewProvid er()).mAwContents; | 130 child == null ? null : ((WebViewChromium) child.getWebViewProvid er()).mAwContents; |
127 parentContents.supplyContentsForPopup(childContents); | 131 parentContents.supplyContentsForPopup(childContents); |
128 } | 132 } |
129 | 133 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 initForReal(); | 193 initForReal(); |
190 if (privateBrowsing) { | 194 if (privateBrowsing) { |
191 // Intentionally irreversibly disable the webview instance, so that private | 195 // Intentionally irreversibly disable the webview instance, so that private |
192 // user data cannot leak through misuse of a non-privateBrow ing WebView | 196 // 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 | 197 // instance. Can't just null out mAwContents as we never nul l-check it |
194 // before use. | 198 // before use. |
195 destroy(); | 199 destroy(); |
196 } | 200 } |
197 } | 201 } |
198 }); | 202 }); |
203 | |
204 if (mShouldDisableThreadChecking) disableThreadChecking(); | |
Torne
2016/08/26 11:25:01
Can you do this *before* posting the task to the o
Changwan Ryu
2016/08/26 11:36:30
Done.
| |
205 } | |
206 | |
207 // This is a workaround for https://crbug.com/622151. | |
208 // In HTC's email app, InputConnection.setComposingText() will call WebView. evaluateJavaScript, | |
209 // and thread assertion will occur. We turn off WebView thread assertion for this app. | |
210 private void disableThreadChecking() { | |
211 try { | |
212 Class<?> webViewClass = Class.forName("android.webkit.WebView"); | |
213 Field field = webViewClass.getDeclaredField("sEnforceThreadChecking" ); | |
214 field.setAccessible(true); | |
215 field.setBoolean(null, false); | |
216 field.setAccessible(false); | |
217 } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessEx ception | |
218 | IllegalArgumentException e) { | |
219 Log.w(TAG, "Failed to disable thread checking."); | |
220 } | |
199 } | 221 } |
200 | 222 |
201 private void initForReal() { | 223 private void initForReal() { |
202 AwContentsStatics.setRecordFullDocument(sRecordWholeDocumentEnabledByApi | 224 AwContentsStatics.setRecordFullDocument(sRecordWholeDocumentEnabledByApi |
203 || mAppTargetSdkVersion < Build.VERSION_CODES.LOLLIPOP); | 225 || mAppTargetSdkVersion < Build.VERSION_CODES.LOLLIPOP); |
204 | 226 |
205 mAwContents = new AwContents(mFactory.getBrowserContextOnUiThread(), mWe bView, mContext, | 227 mAwContents = new AwContents(mFactory.getBrowserContextOnUiThread(), mWe bView, mContext, |
206 new InternalAccessAdapter(), new WebViewNativeDrawGLFunctorFacto ry(), | 228 new InternalAccessAdapter(), new WebViewNativeDrawGLFunctorFacto ry(), |
207 mContentsClientAdapter, mWebSettings.getAwSettings()); | 229 mContentsClientAdapter, mWebSettings.getAwSettings()); |
208 | 230 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 @Override | 555 @Override |
534 public void run() { | 556 public void run() { |
535 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, enc oding, historyUrl); | 557 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, enc oding, historyUrl); |
536 } | 558 } |
537 }); | 559 }); |
538 return; | 560 return; |
539 } | 561 } |
540 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, histo ryUrl); | 562 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, histo ryUrl); |
541 } | 563 } |
542 | 564 |
543 public void evaluateJavaScript(String script, ValueCallback<String> resultCa llback) { | 565 @Override |
544 checkThread(); | 566 public void evaluateJavaScript( |
545 mAwContents.evaluateJavaScript(script, resultCallback); | 567 final String script, final ValueCallback<String> resultCallback) { |
568 if (mShouldDisableThreadChecking && checkNeedsPost()) { | |
569 // This is a workaround for https://crbug.com/622151. | |
570 mFactory.addTask(new Runnable() { | |
571 @Override | |
572 public void run() { | |
573 mAwContents.evaluateJavaScript(script, resultCallback); | |
574 } | |
575 }); | |
576 } else { | |
577 checkThread(); | |
578 mAwContents.evaluateJavaScript(script, resultCallback); | |
579 } | |
546 } | 580 } |
547 | 581 |
548 @Override | 582 @Override |
549 public void saveWebArchive(String filename) { | 583 public void saveWebArchive(String filename) { |
550 saveWebArchive(filename, false, null); | 584 saveWebArchive(filename, false, null); |
551 } | 585 } |
552 | 586 |
553 @Override | 587 @Override |
554 public void saveWebArchive(final String basename, final boolean autoname, | 588 public void saveWebArchive(final String basename, final boolean autoname, |
555 final ValueCallback<String> callback) { | 589 final ValueCallback<String> callback) { |
(...skipping 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2227 mAwContents.extractSmartClipData(x, y, width, height); | 2261 mAwContents.extractSmartClipData(x, y, width, height); |
2228 } | 2262 } |
2229 | 2263 |
2230 // Implements SmartClipProvider | 2264 // Implements SmartClipProvider |
2231 @Override | 2265 @Override |
2232 public void setSmartClipResultHandler(final Handler resultHandler) { | 2266 public void setSmartClipResultHandler(final Handler resultHandler) { |
2233 checkThread(); | 2267 checkThread(); |
2234 mAwContents.setSmartClipResultHandler(resultHandler); | 2268 mAwContents.setSmartClipResultHandler(resultHandler); |
2235 } | 2269 } |
2236 } | 2270 } |
OLD | NEW |