Chromium Code Reviews| Index: android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java |
| diff --git a/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java b/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java |
| index e78808be92430272ef31be2051599c25764e14b8..c8ee1c378a669ef86eaa63c6b19e24a70dd097eb 100644 |
| --- a/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java |
| +++ b/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java |
| @@ -12,6 +12,7 @@ import android.content.Intent; |
| import android.content.SharedPreferences; |
| import android.content.pm.PackageInfo; |
| import android.content.pm.PackageManager; |
| +import android.content.pm.PackageManager.NameNotFoundException; |
| import android.net.Uri; |
| import android.os.Build; |
| import android.os.Looper; |
| @@ -61,6 +62,7 @@ import org.chromium.net.NetworkChangeNotifier; |
| import org.chromium.ui.base.ResourceBundle; |
| import java.io.File; |
| +import java.lang.reflect.Field; |
| import java.util.Queue; |
| import java.util.concurrent.Callable; |
| import java.util.concurrent.ConcurrentLinkedQueue; |
| @@ -108,7 +110,7 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { |
| } |
| } |
| - private Queue<Runnable> mQueue; |
| + private final Queue<Runnable> mQueue; |
| } |
| private final WebViewChromiumRunQueue mRunQueue = new WebViewChromiumRunQueue(); |
| @@ -165,6 +167,8 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { |
| private SharedPreferences mWebViewPrefs; |
| private WebViewDelegate mWebViewDelegate; |
| + private boolean mShouldDisableThreadChecking; |
| + |
| /** |
| * Entry point for newer versions of Android. |
| */ |
| @@ -229,6 +233,9 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { |
| if (lastVersion != currentVersion) { |
| mWebViewPrefs.edit().putInt(VERSION_CODE_PREF, currentVersion).apply(); |
| } |
| + |
| + mShouldDisableThreadChecking = |
| + shouldDisableThreadChecking(ContextUtils.getApplicationContext()); |
| // Now safe to use WebView data directory. |
| } |
| @@ -482,7 +489,53 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { |
| @Override |
| public WebViewProvider createWebView(WebView webView, WebView.PrivateAccess privateAccess) { |
| - return new WebViewChromium(this, webView, privateAccess); |
| + WebViewChromium webViewChromium = new WebViewChromium(this, webView, privateAccess, |
| + mShouldDisableThreadChecking); |
| + // XXX: this does not get applied before WebView's sEnforceThreadChecking is set. |
| + if (mShouldDisableThreadChecking) disableThreadChecking(); |
| + return webViewChromium; |
| + } |
| + |
| + // Check this as a workaround for https://crbug.com/622151. |
| + private boolean shouldDisableThreadChecking(Context context) { |
| + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) return false; |
| + final String htcMailPackageId = "com.htc.android.mail"; |
|
sgurun-gerrit only
2016/08/25 23:41:02
Sorry but I don't think we should create a precede
|
| + if (!htcMailPackageId.equals(context.getPackageName())) return false; |
| + try { |
| + PackageInfo packageInfo = |
| + context.getPackageManager().getPackageInfo(htcMailPackageId, 0); |
| + if (packageInfo == null) return false; |
| + |
| + // These values are provided by HTC. |
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M |
| + && packageInfo.versionCode >= 864021756) return false; |
| + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M |
| + && packageInfo.versionCode >= 866001861) return false; |
| + |
| + Log.w(TAG, "Disabling thread check in WebView (http://crbug.com/622151). " |
| + + "APK name: " + htcMailPackageId + ", versionCode: " |
| + + packageInfo.versionCode); |
| + return true; |
| + } catch (NameNotFoundException e) { |
| + // Ignore this exception and return false. |
| + } |
| + 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."); |
| + } |
| } |
| @Override |