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

Side by Side Diff: android_webview/glue/java/src/com/android/webview/chromium/WebViewChromium.java

Issue 2243753002: Prevent thread assertion for HTC mail apk (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: check in factory provider initialization 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 unified diff | Download patch
OLDNEW
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
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
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
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 // This is called here because otherwise compiler optimization may call
Torne 2016/08/17 10:43:07 I'm really suspicious of this comment. What do you
Changwan Ryu 2016/08/17 14:07:41 As opposed to do it inside WebViewChromiumFactoryP
Torne 2016/08/17 14:14:34 I'm still confused about what this means, though.
Changwan Ryu 2016/08/18 09:31:02 Hmm.. I had to look up a bit. https://docs.oracle.
204 // disableThreadChecking before setting WebView#sEnforceThreadChecking.
205 if (mShouldDisableThreadChecking) disableThreadChecking();
206 }
207
208 // This is a workaround for https://crbug.com/622151.
209 // In HTC's email app, InputConnection.setComposingText() will call WebView. evaluateJavaScript,
210 // and thread assertion will occur. We turn off WebView thread assertion for this app.
211 private void disableThreadChecking() {
212 try {
213 Class<?> webViewClass = Class.forName("android.webkit.WebView");
214 Field field = webViewClass.getDeclaredField("sEnforceThreadChecking" );
215 field.setAccessible(true);
216 field.setBoolean(null, false);
217 field.setAccessible(false);
218 } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessEx ception
219 | IllegalArgumentException e) {
220 Log.w(TAG, "Failed to disable thread checking.");
221 }
199 } 222 }
200 223
201 private void initForReal() { 224 private void initForReal() {
202 AwContentsStatics.setRecordFullDocument(sRecordWholeDocumentEnabledByApi 225 AwContentsStatics.setRecordFullDocument(sRecordWholeDocumentEnabledByApi
203 || mAppTargetSdkVersion < Build.VERSION_CODES.LOLLIPOP); 226 || mAppTargetSdkVersion < Build.VERSION_CODES.LOLLIPOP);
204 227
205 mAwContents = new AwContents(mFactory.getBrowserContextOnUiThread(), mWe bView, mContext, 228 mAwContents = new AwContents(mFactory.getBrowserContextOnUiThread(), mWe bView, mContext,
206 new InternalAccessAdapter(), new WebViewNativeDrawGLFunctorFacto ry(), 229 new InternalAccessAdapter(), new WebViewNativeDrawGLFunctorFacto ry(),
207 mContentsClientAdapter, mWebSettings.getAwSettings()); 230 mContentsClientAdapter, mWebSettings.getAwSettings());
208 231
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 @Override 556 @Override
534 public void run() { 557 public void run() {
535 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, enc oding, historyUrl); 558 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, enc oding, historyUrl);
536 } 559 }
537 }); 560 });
538 return; 561 return;
539 } 562 }
540 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, histo ryUrl); 563 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, histo ryUrl);
541 } 564 }
542 565
543 public void evaluateJavaScript(String script, ValueCallback<String> resultCa llback) { 566 @Override
544 checkThread(); 567 public void evaluateJavaScript(
545 mAwContents.evaluateJavaScript(script, resultCallback); 568 final String script, final ValueCallback<String> resultCallback) {
569 if (mShouldDisableThreadChecking) {
570 // This is a workaround for https://crbug.com/622151.
571 if (checkNeedsPost()) {
Torne 2016/08/17 10:43:07 You need to combine this into the previous if cond
Changwan Ryu 2016/08/17 14:07:41 Good catch! Done.
572 mFactory.addTask(new Runnable() {
573 @Override
574 public void run() {
575 mAwContents.evaluateJavaScript(script, resultCallback);
576 }
577 });
578 return;
579 }
580 } else {
581 checkThread();
582 mAwContents.evaluateJavaScript(script, resultCallback);
583 }
546 } 584 }
547 585
548 @Override 586 @Override
549 public void saveWebArchive(String filename) { 587 public void saveWebArchive(String filename) {
550 saveWebArchive(filename, false, null); 588 saveWebArchive(filename, false, null);
551 } 589 }
552 590
553 @Override 591 @Override
554 public void saveWebArchive(final String basename, final boolean autoname, 592 public void saveWebArchive(final String basename, final boolean autoname,
555 final ValueCallback<String> callback) { 593 final ValueCallback<String> callback) {
(...skipping 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after
2227 mAwContents.extractSmartClipData(x, y, width, height); 2265 mAwContents.extractSmartClipData(x, y, width, height);
2228 } 2266 }
2229 2267
2230 // Implements SmartClipProvider 2268 // Implements SmartClipProvider
2231 @Override 2269 @Override
2232 public void setSmartClipResultHandler(final Handler resultHandler) { 2270 public void setSmartClipResultHandler(final Handler resultHandler) {
2233 checkThread(); 2271 checkThread();
2234 mAwContents.setSmartClipResultHandler(resultHandler); 2272 mAwContents.setSmartClipResultHandler(resultHandler);
2235 } 2273 }
2236 } 2274 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698