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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: android_webview/glue/java/src/com/android/webview/chromium/WebViewChromium.java
diff --git a/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromium.java b/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromium.java
index 0f8ca85b46b4b6dc8b195baf1c92a20f3a56962e..f24fb049cfcdf1a7d22e0806091ea786e50a26da 100644
--- a/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromium.java
+++ b/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromium.java
@@ -62,6 +62,7 @@ import org.chromium.content_public.browser.NavigationHistory;
import java.io.BufferedWriter;
import java.io.File;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.Callable;
@@ -102,6 +103,8 @@ class WebViewChromium implements WebViewProvider, WebViewProvider.ScrollDelegate
private WebViewChromiumFactoryProvider mFactory;
+ private final boolean mShouldDisableThreadChecking;
+
private static boolean sRecordWholeDocumentEnabledByApi = false;
static void enableSlowWholeDocumentDraw() {
sRecordWholeDocumentEnabledByApi = true;
@@ -110,13 +113,14 @@ class WebViewChromium implements WebViewProvider, WebViewProvider.ScrollDelegate
// This does not touch any global / non-threadsafe state, but note that
// init is ofter called right after and is NOT threadsafe.
public WebViewChromium(WebViewChromiumFactoryProvider factory, WebView webView,
- WebView.PrivateAccess webViewPrivate) {
+ WebView.PrivateAccess webViewPrivate, boolean shouldDisableThreadChecking) {
mWebView = webView;
mWebViewPrivate = webViewPrivate;
mHitTestResult = new WebView.HitTestResult();
mContext = ResourcesContextWrapperFactory.get(mWebView.getContext());
mAppTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion;
mFactory = factory;
+ mShouldDisableThreadChecking = shouldDisableThreadChecking;
factory.getWebViewDelegate().addWebViewAssetPath(mWebView.getContext());
}
@@ -196,6 +200,25 @@ class WebViewChromium implements WebViewProvider, WebViewProvider.ScrollDelegate
}
}
});
+ // 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.
+ // disableThreadChecking before setting WebView#sEnforceThreadChecking.
+ if (mShouldDisableThreadChecking) disableThreadChecking();
+ }
+
+ // This is a workaround for https://crbug.com/622151.
+ // In HTC's email app, InputConnection.setComposingText() will call WebView.evaluateJavaScript,
+ // and thread assertion will occur. We turn off WebView thread assertion for this app.
+ private void disableThreadChecking() {
+ try {
+ Class<?> webViewClass = Class.forName("android.webkit.WebView");
+ Field field = webViewClass.getDeclaredField("sEnforceThreadChecking");
+ field.setAccessible(true);
+ field.setBoolean(null, false);
+ field.setAccessible(false);
+ } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException
+ | IllegalArgumentException e) {
+ Log.w(TAG, "Failed to disable thread checking.");
+ }
}
private void initForReal() {
@@ -540,9 +563,24 @@ class WebViewChromium implements WebViewProvider, WebViewProvider.ScrollDelegate
mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
}
- public void evaluateJavaScript(String script, ValueCallback<String> resultCallback) {
- checkThread();
- mAwContents.evaluateJavaScript(script, resultCallback);
+ @Override
+ public void evaluateJavaScript(
+ final String script, final ValueCallback<String> resultCallback) {
+ if (mShouldDisableThreadChecking) {
+ // This is a workaround for https://crbug.com/622151.
+ 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.
+ mFactory.addTask(new Runnable() {
+ @Override
+ public void run() {
+ mAwContents.evaluateJavaScript(script, resultCallback);
+ }
+ });
+ return;
+ }
+ } else {
+ checkThread();
+ mAwContents.evaluateJavaScript(script, resultCallback);
+ }
}
@Override

Powered by Google App Engine
This is Rietveld 408576698