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

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: addressed torne@'s comments, simplified some code 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 | no next file » | 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..1e7c0ed8bb9a341093c8bf8690ff433c7ecee195 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
@@ -8,6 +8,7 @@ import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Canvas;
@@ -62,9 +63,11 @@ 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;
+import java.util.concurrent.atomic.AtomicBoolean;
/**
* This class is the delegate to which WebViewProxy forwards all API calls.
@@ -102,6 +105,8 @@ class WebViewChromium implements WebViewProvider, WebViewProvider.ScrollDelegate
private WebViewChromiumFactoryProvider mFactory;
+ private static volatile AtomicBoolean sIsHtcMail = new AtomicBoolean(false);
+
private static boolean sRecordWholeDocumentEnabledByApi = false;
static void enableSlowWholeDocumentDraw() {
sRecordWholeDocumentEnabledByApi = true;
@@ -135,6 +140,8 @@ class WebViewChromium implements WebViewProvider, WebViewProvider.ScrollDelegate
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void init(final Map<String, Object> javaScriptInterfaces,
final boolean privateBrowsing) {
+ sIsHtcMail.set(isHtcMail(mWebView.getContext()));
+ if (sIsHtcMail.get()) disableThreadChecking();
if (privateBrowsing) {
mFactory.startYourEngines(true);
final String msg = "Private browsing is not supported in WebView.";
@@ -198,6 +205,44 @@ class WebViewChromium implements WebViewProvider, WebViewProvider.ScrollDelegate
});
}
+ private boolean isHtcMail(Context context) {
+ 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.
+ final String htcMailPackageId = "com.htc.android.mail";
+ if (!htcMailPackageId.equals(context.getPackageName())) return false;
+
+ try {
+ PackageInfo packageInfo =
+ context.getPackageManager().getPackageInfo(htcMailPackageId, 0);
+ // These values are provided by HTC.
+ if ((mAppTargetSdkVersion < Build.VERSION_CODES.M
+ && packageInfo.versionCode < 864021756)
+ || packageInfo.versionCode < 866001861) {
+ Log.w(TAG, "Disabling thread check in WebView (http://crbug.com/622151). "
+ + "APK name: " + htcMailPackageId + ", versionCode: "
+ + packageInfo.versionCode);
+ return true;
+ }
+ } 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.
+ }
+ return false;
+ }
+
+ // 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 +585,20 @@ 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);
+ public void evaluateJavaScript(
+ final String script, final ValueCallback<String> resultCallback) {
+ if (sIsHtcMail.get()) {
+ // This is a workaround for https://crbug.com/622151.
+ 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.
+ @Override
+ public void run() {
+ mAwContents.evaluateJavaScript(script, resultCallback);
+ }
+ });
+ } else {
+ checkThread();
+ mAwContents.evaluateJavaScript(script, resultCallback);
+ }
}
@Override
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698