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

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: move disableThreadChecking before addTask 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
« no previous file with comments | « no previous file | android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..cb1ef7218adc8d31e81e0c9b1da9e70eca894251 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());
}
@@ -183,6 +187,8 @@ class WebViewChromium implements WebViewProvider, WebViewProvider.ScrollDelegate
mWebSettings.getAwSettings().setZeroLayoutHeightDisablesViewportQuirk(true);
}
+ if (mShouldDisableThreadChecking) disableThreadChecking();
+
mFactory.addTask(new Runnable() {
@Override
public void run() {
@@ -198,6 +204,22 @@ class WebViewChromium implements WebViewProvider, WebViewProvider.ScrollDelegate
});
}
+ // 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() {
AwContentsStatics.setRecordFullDocument(sRecordWholeDocumentEnabledByApi
|| mAppTargetSdkVersion < Build.VERSION_CODES.LOLLIPOP);
@@ -540,9 +562,21 @@ 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 && checkNeedsPost()) {
+ // This is a workaround for https://crbug.com/622151.
+ mFactory.addTask(new Runnable() {
+ @Override
+ public void run() {
+ mAwContents.evaluateJavaScript(script, resultCallback);
+ }
+ });
+ } else {
+ checkThread();
+ mAwContents.evaluateJavaScript(script, resultCallback);
+ }
}
@Override
« no previous file with comments | « no previous file | android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698