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

Side by Side Diff: android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.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.Manifest; 7 import android.Manifest;
8 import android.app.ActivityManager; 8 import android.app.ActivityManager;
9 import android.content.ComponentCallbacks2; 9 import android.content.ComponentCallbacks2;
10 import android.content.Context; 10 import android.content.Context;
11 import android.content.Intent; 11 import android.content.Intent;
12 import android.content.SharedPreferences; 12 import android.content.SharedPreferences;
13 import android.content.pm.PackageInfo; 13 import android.content.pm.PackageInfo;
14 import android.content.pm.PackageManager; 14 import android.content.pm.PackageManager;
15 import android.content.pm.PackageManager.NameNotFoundException;
15 import android.net.Uri; 16 import android.net.Uri;
16 import android.os.Build; 17 import android.os.Build;
17 import android.os.Looper; 18 import android.os.Looper;
18 import android.os.Process; 19 import android.os.Process;
19 import android.os.StrictMode; 20 import android.os.StrictMode;
20 import android.util.Log; 21 import android.util.Log;
21 import android.webkit.CookieManager; 22 import android.webkit.CookieManager;
22 import android.webkit.GeolocationPermissions; 23 import android.webkit.GeolocationPermissions;
23 import android.webkit.WebStorage; 24 import android.webkit.WebStorage;
24 import android.webkit.WebView; 25 import android.webkit.WebView;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 return; 102 return;
102 } 103 }
103 104
104 Runnable task = mQueue.poll(); 105 Runnable task = mQueue.poll();
105 while (task != null) { 106 while (task != null) {
106 task.run(); 107 task.run();
107 task = mQueue.poll(); 108 task = mQueue.poll();
108 } 109 }
109 } 110 }
110 111
111 private Queue<Runnable> mQueue; 112 private final Queue<Runnable> mQueue;
112 } 113 }
113 114
114 private final WebViewChromiumRunQueue mRunQueue = new WebViewChromiumRunQueu e(); 115 private final WebViewChromiumRunQueue mRunQueue = new WebViewChromiumRunQueu e();
115 116
116 private <T> T runBlockingFuture(FutureTask<T> task) { 117 private <T> T runBlockingFuture(FutureTask<T> task) {
117 if (!hasStarted()) throw new RuntimeException("Must be started before we block!"); 118 if (!hasStarted()) throw new RuntimeException("Must be started before we block!");
118 if (ThreadUtils.runningOnUiThread()) { 119 if (ThreadUtils.runningOnUiThread()) {
119 throw new IllegalStateException("This method should only be called o ff the UI thread"); 120 throw new IllegalStateException("This method should only be called o ff the UI thread");
120 } 121 }
121 mRunQueue.addTask(task); 122 mRunQueue.addTask(task);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 private WebStorageAdapter mWebStorage; 159 private WebStorageAdapter mWebStorage;
159 private WebViewDatabaseAdapter mWebViewDatabase; 160 private WebViewDatabaseAdapter mWebViewDatabase;
160 private AwDevToolsServer mDevToolsServer; 161 private AwDevToolsServer mDevToolsServer;
161 162
162 // Read/write protected by mLock. 163 // Read/write protected by mLock.
163 private boolean mStarted; 164 private boolean mStarted;
164 165
165 private SharedPreferences mWebViewPrefs; 166 private SharedPreferences mWebViewPrefs;
166 private WebViewDelegate mWebViewDelegate; 167 private WebViewDelegate mWebViewDelegate;
167 168
169 private boolean mShouldDisableThreadChecking;
170
168 /** 171 /**
169 * Entry point for newer versions of Android. 172 * Entry point for newer versions of Android.
170 */ 173 */
171 public static WebViewChromiumFactoryProvider create(android.webkit.WebViewDe legate delegate) { 174 public static WebViewChromiumFactoryProvider create(android.webkit.WebViewDe legate delegate) {
172 return new WebViewChromiumFactoryProvider(delegate); 175 return new WebViewChromiumFactoryProvider(delegate);
173 } 176 }
174 177
175 /** 178 /**
176 * Constructor called by the API 21 version of {@link WebViewFactory} and ea rlier. 179 * Constructor called by the API 21 version of {@link WebViewFactory} and ea rlier.
177 */ 180 */
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 // The WebView package has been downgraded since we last ran in this application. 225 // The WebView package has been downgraded since we last ran in this application.
223 // Delete the WebView data directory's contents. 226 // Delete the WebView data directory's contents.
224 String dataDir = PathUtils.getDataDirectory(ContextUtils.getApplicat ionContext()); 227 String dataDir = PathUtils.getDataDirectory(ContextUtils.getApplicat ionContext());
225 Log.i(TAG, "WebView package downgraded from " + lastVersion + " to " + currentVersion 228 Log.i(TAG, "WebView package downgraded from " + lastVersion + " to " + currentVersion
226 + "; deleting contents of " + dataDir); 229 + "; deleting contents of " + dataDir);
227 deleteContents(new File(dataDir)); 230 deleteContents(new File(dataDir));
228 } 231 }
229 if (lastVersion != currentVersion) { 232 if (lastVersion != currentVersion) {
230 mWebViewPrefs.edit().putInt(VERSION_CODE_PREF, currentVersion).apply (); 233 mWebViewPrefs.edit().putInt(VERSION_CODE_PREF, currentVersion).apply ();
231 } 234 }
235
236 mShouldDisableThreadChecking =
237 shouldDisableThreadChecking(ContextUtils.getApplicationContext() );
232 // Now safe to use WebView data directory. 238 // Now safe to use WebView data directory.
233 } 239 }
234 240
235 private static boolean isBuildDebuggable() { 241 private static boolean isBuildDebuggable() {
236 return !Build.TYPE.equals("user"); 242 return !Build.TYPE.equals("user");
237 } 243 }
238 244
239 /** 245 /**
240 * Both versionCodes should be from a WebView provider package implemented b y Chromium. 246 * Both versionCodes should be from a WebView provider package implemented b y Chromium.
241 * VersionCodes from other kinds of packages won't make any sense in this me thod. 247 * VersionCodes from other kinds of packages won't make any sense in this me thod.
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 return AwContentsClient.parseFileChooserResult(resultCod e, intent); 481 return AwContentsClient.parseFileChooserResult(resultCod e, intent);
476 } 482 }
477 }; 483 };
478 } 484 }
479 } 485 }
480 return mStaticMethods; 486 return mStaticMethods;
481 } 487 }
482 488
483 @Override 489 @Override
484 public WebViewProvider createWebView(WebView webView, WebView.PrivateAccess privateAccess) { 490 public WebViewProvider createWebView(WebView webView, WebView.PrivateAccess privateAccess) {
485 return new WebViewChromium(this, webView, privateAccess); 491 return new WebViewChromium(this, webView, privateAccess, mShouldDisableT hreadChecking);
492 }
493
494 // Check this as a workaround for https://crbug.com/622151.
495 private boolean shouldDisableThreadChecking(Context context) {
496 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) return false;
497 final String htcMailPackageId = "com.htc.android.mail";
498 if (!htcMailPackageId.equals(context.getPackageName())) return false;
499 try {
500 PackageInfo packageInfo =
501 context.getPackageManager().getPackageInfo(htcMailPackageId, 0);
502 if (packageInfo == null) return false;
503 // These values are provided by HTC.
504 if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.M
505 && packageInfo.versionCode < 864021756)
506 || packageInfo.versionCode < 866001861) {
Torne 2016/08/17 10:43:07 This condition doesn't work as intended; it will a
Changwan Ryu 2016/08/17 14:07:41 Good catch! Fixed now.
507 Log.w(TAG, "Disabling thread check in WebView (http://crbug.com/ 622151). "
508 + "APK name: " + htcMailPackageId + ", versionCode: "
509 + packageInfo.versionCode);
510 return true;
511 }
512 } catch (NameNotFoundException e) {
513 // Ignore this exception and return false.
514 }
515 return false;
486 } 516 }
487 517
488 @Override 518 @Override
489 public GeolocationPermissions getGeolocationPermissions() { 519 public GeolocationPermissions getGeolocationPermissions() {
490 synchronized (mLock) { 520 synchronized (mLock) {
491 if (mGeolocationPermissions == null) { 521 if (mGeolocationPermissions == null) {
492 ensureChromiumStartedLocked(true); 522 ensureChromiumStartedLocked(true);
493 AwGeolocationPermissions awGelocationPermissions = ThreadUtils.r unningOnUiThread() 523 AwGeolocationPermissions awGelocationPermissions = ThreadUtils.r unningOnUiThread()
494 ? getBrowserContextOnUiThread().getGeolocationPermission s() 524 ? getBrowserContextOnUiThread().getGeolocationPermission s()
495 : runOnUiThreadBlocking(new Callable<AwGeolocationPermis sions>() { 525 : runOnUiThreadBlocking(new Callable<AwGeolocationPermis sions>() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 mWebViewDatabase = new WebViewDatabaseAdapter(this, awDatabase); 591 mWebViewDatabase = new WebViewDatabaseAdapter(this, awDatabase);
562 } 592 }
563 } 593 }
564 return mWebViewDatabase; 594 return mWebViewDatabase;
565 } 595 }
566 596
567 WebViewDelegate getWebViewDelegate() { 597 WebViewDelegate getWebViewDelegate() {
568 return mWebViewDelegate; 598 return mWebViewDelegate;
569 } 599 }
570 } 600 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698