| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 |
| 504 // These values are provided by HTC. |
| 505 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M |
| 506 && packageInfo.versionCode >= 864021756) return false; |
| 507 if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M |
| 508 && packageInfo.versionCode >= 866001861) return false; |
| 509 |
| 510 Log.w(TAG, "Disabling thread check in WebView (http://crbug.com/6221
51). " |
| 511 + "APK name: " + htcMailPackageId + ", versionCode: " |
| 512 + packageInfo.versionCode); |
| 513 return true; |
| 514 } catch (NameNotFoundException e) { |
| 515 // Ignore this exception and return false. |
| 516 } |
| 517 return false; |
| 486 } | 518 } |
| 487 | 519 |
| 488 @Override | 520 @Override |
| 489 public GeolocationPermissions getGeolocationPermissions() { | 521 public GeolocationPermissions getGeolocationPermissions() { |
| 490 synchronized (mLock) { | 522 synchronized (mLock) { |
| 491 if (mGeolocationPermissions == null) { | 523 if (mGeolocationPermissions == null) { |
| 492 ensureChromiumStartedLocked(true); | 524 ensureChromiumStartedLocked(true); |
| 493 AwGeolocationPermissions awGelocationPermissions = ThreadUtils.r
unningOnUiThread() | 525 AwGeolocationPermissions awGelocationPermissions = ThreadUtils.r
unningOnUiThread() |
| 494 ? getBrowserContextOnUiThread().getGeolocationPermission
s() | 526 ? getBrowserContextOnUiThread().getGeolocationPermission
s() |
| 495 : runOnUiThreadBlocking(new Callable<AwGeolocationPermis
sions>() { | 527 : runOnUiThreadBlocking(new Callable<AwGeolocationPermis
sions>() { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 mWebViewDatabase = new WebViewDatabaseAdapter(this, awDatabase); | 593 mWebViewDatabase = new WebViewDatabaseAdapter(this, awDatabase); |
| 562 } | 594 } |
| 563 } | 595 } |
| 564 return mWebViewDatabase; | 596 return mWebViewDatabase; |
| 565 } | 597 } |
| 566 | 598 |
| 567 WebViewDelegate getWebViewDelegate() { | 599 WebViewDelegate getWebViewDelegate() { |
| 568 return mWebViewDelegate; | 600 return mWebViewDelegate; |
| 569 } | 601 } |
| 570 } | 602 } |
| OLD | NEW |