Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 54 import org.chromium.base.TraceEvent; | 55 import org.chromium.base.TraceEvent; |
| 55 import org.chromium.base.annotations.SuppressFBWarnings; | 56 import org.chromium.base.annotations.SuppressFBWarnings; |
| 56 import org.chromium.base.library_loader.LibraryLoader; | 57 import org.chromium.base.library_loader.LibraryLoader; |
| 57 import org.chromium.base.library_loader.LibraryProcessType; | 58 import org.chromium.base.library_loader.LibraryProcessType; |
| 58 import org.chromium.base.library_loader.ProcessInitException; | 59 import org.chromium.base.library_loader.ProcessInitException; |
| 59 import org.chromium.content.browser.ContentViewStatics; | 60 import org.chromium.content.browser.ContentViewStatics; |
| 60 import org.chromium.net.NetworkChangeNotifier; | 61 import org.chromium.net.NetworkChangeNotifier; |
| 61 import org.chromium.ui.base.ResourceBundle; | 62 import org.chromium.ui.base.ResourceBundle; |
| 62 | 63 |
| 63 import java.io.File; | 64 import java.io.File; |
| 65 import java.lang.reflect.Field; | |
| 64 import java.util.Queue; | 66 import java.util.Queue; |
| 65 import java.util.concurrent.Callable; | 67 import java.util.concurrent.Callable; |
| 66 import java.util.concurrent.ConcurrentLinkedQueue; | 68 import java.util.concurrent.ConcurrentLinkedQueue; |
| 67 import java.util.concurrent.FutureTask; | 69 import java.util.concurrent.FutureTask; |
| 68 import java.util.concurrent.TimeUnit; | 70 import java.util.concurrent.TimeUnit; |
| 69 | 71 |
| 70 /** | 72 /** |
| 71 * Entry point to the WebView. The system framework talks to this class to get i nstances of the | 73 * Entry point to the WebView. The system framework talks to this class to get i nstances of the |
| 72 * implementation classes. | 74 * implementation classes. |
| 73 */ | 75 */ |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 101 return; | 103 return; |
| 102 } | 104 } |
| 103 | 105 |
| 104 Runnable task = mQueue.poll(); | 106 Runnable task = mQueue.poll(); |
| 105 while (task != null) { | 107 while (task != null) { |
| 106 task.run(); | 108 task.run(); |
| 107 task = mQueue.poll(); | 109 task = mQueue.poll(); |
| 108 } | 110 } |
| 109 } | 111 } |
| 110 | 112 |
| 111 private Queue<Runnable> mQueue; | 113 private final Queue<Runnable> mQueue; |
| 112 } | 114 } |
| 113 | 115 |
| 114 private final WebViewChromiumRunQueue mRunQueue = new WebViewChromiumRunQueu e(); | 116 private final WebViewChromiumRunQueue mRunQueue = new WebViewChromiumRunQueu e(); |
| 115 | 117 |
| 116 private <T> T runBlockingFuture(FutureTask<T> task) { | 118 private <T> T runBlockingFuture(FutureTask<T> task) { |
| 117 if (!hasStarted()) throw new RuntimeException("Must be started before we block!"); | 119 if (!hasStarted()) throw new RuntimeException("Must be started before we block!"); |
| 118 if (ThreadUtils.runningOnUiThread()) { | 120 if (ThreadUtils.runningOnUiThread()) { |
| 119 throw new IllegalStateException("This method should only be called o ff the UI thread"); | 121 throw new IllegalStateException("This method should only be called o ff the UI thread"); |
| 120 } | 122 } |
| 121 mRunQueue.addTask(task); | 123 mRunQueue.addTask(task); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 private WebStorageAdapter mWebStorage; | 160 private WebStorageAdapter mWebStorage; |
| 159 private WebViewDatabaseAdapter mWebViewDatabase; | 161 private WebViewDatabaseAdapter mWebViewDatabase; |
| 160 private AwDevToolsServer mDevToolsServer; | 162 private AwDevToolsServer mDevToolsServer; |
| 161 | 163 |
| 162 // Read/write protected by mLock. | 164 // Read/write protected by mLock. |
| 163 private boolean mStarted; | 165 private boolean mStarted; |
| 164 | 166 |
| 165 private SharedPreferences mWebViewPrefs; | 167 private SharedPreferences mWebViewPrefs; |
| 166 private WebViewDelegate mWebViewDelegate; | 168 private WebViewDelegate mWebViewDelegate; |
| 167 | 169 |
| 170 private boolean mShouldDisableThreadChecking; | |
| 171 | |
| 168 /** | 172 /** |
| 169 * Entry point for newer versions of Android. | 173 * Entry point for newer versions of Android. |
| 170 */ | 174 */ |
| 171 public static WebViewChromiumFactoryProvider create(android.webkit.WebViewDe legate delegate) { | 175 public static WebViewChromiumFactoryProvider create(android.webkit.WebViewDe legate delegate) { |
| 172 return new WebViewChromiumFactoryProvider(delegate); | 176 return new WebViewChromiumFactoryProvider(delegate); |
| 173 } | 177 } |
| 174 | 178 |
| 175 /** | 179 /** |
| 176 * Constructor called by the API 21 version of {@link WebViewFactory} and ea rlier. | 180 * Constructor called by the API 21 version of {@link WebViewFactory} and ea rlier. |
| 177 */ | 181 */ |
| (...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. | 226 // The WebView package has been downgraded since we last ran in this application. |
| 223 // Delete the WebView data directory's contents. | 227 // Delete the WebView data directory's contents. |
| 224 String dataDir = PathUtils.getDataDirectory(ContextUtils.getApplicat ionContext()); | 228 String dataDir = PathUtils.getDataDirectory(ContextUtils.getApplicat ionContext()); |
| 225 Log.i(TAG, "WebView package downgraded from " + lastVersion + " to " + currentVersion | 229 Log.i(TAG, "WebView package downgraded from " + lastVersion + " to " + currentVersion |
| 226 + "; deleting contents of " + dataDir); | 230 + "; deleting contents of " + dataDir); |
| 227 deleteContents(new File(dataDir)); | 231 deleteContents(new File(dataDir)); |
| 228 } | 232 } |
| 229 if (lastVersion != currentVersion) { | 233 if (lastVersion != currentVersion) { |
| 230 mWebViewPrefs.edit().putInt(VERSION_CODE_PREF, currentVersion).apply (); | 234 mWebViewPrefs.edit().putInt(VERSION_CODE_PREF, currentVersion).apply (); |
| 231 } | 235 } |
| 236 | |
| 237 mShouldDisableThreadChecking = | |
| 238 shouldDisableThreadChecking(ContextUtils.getApplicationContext() ); | |
| 232 // Now safe to use WebView data directory. | 239 // Now safe to use WebView data directory. |
| 233 } | 240 } |
| 234 | 241 |
| 235 private static boolean isBuildDebuggable() { | 242 private static boolean isBuildDebuggable() { |
| 236 return !Build.TYPE.equals("user"); | 243 return !Build.TYPE.equals("user"); |
| 237 } | 244 } |
| 238 | 245 |
| 239 /** | 246 /** |
| 240 * Both versionCodes should be from a WebView provider package implemented b y Chromium. | 247 * 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. | 248 * 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); | 482 return AwContentsClient.parseFileChooserResult(resultCod e, intent); |
| 476 } | 483 } |
| 477 }; | 484 }; |
| 478 } | 485 } |
| 479 } | 486 } |
| 480 return mStaticMethods; | 487 return mStaticMethods; |
| 481 } | 488 } |
| 482 | 489 |
| 483 @Override | 490 @Override |
| 484 public WebViewProvider createWebView(WebView webView, WebView.PrivateAccess privateAccess) { | 491 public WebViewProvider createWebView(WebView webView, WebView.PrivateAccess privateAccess) { |
| 485 return new WebViewChromium(this, webView, privateAccess); | 492 WebViewChromium webViewChromium = new WebViewChromium(this, webView, pri vateAccess, |
| 493 mShouldDisableThreadChecking); | |
| 494 // XXX: this does not get applied before WebView's sEnforceThreadCheckin g is set. | |
| 495 if (mShouldDisableThreadChecking) disableThreadChecking(); | |
| 496 return webViewChromium; | |
| 497 } | |
| 498 | |
| 499 // Check this as a workaround for https://crbug.com/622151. | |
| 500 private boolean shouldDisableThreadChecking(Context context) { | |
| 501 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) return false; | |
| 502 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
| |
| 503 if (!htcMailPackageId.equals(context.getPackageName())) return false; | |
| 504 try { | |
| 505 PackageInfo packageInfo = | |
| 506 context.getPackageManager().getPackageInfo(htcMailPackageId, 0); | |
| 507 if (packageInfo == null) return false; | |
| 508 | |
| 509 // These values are provided by HTC. | |
| 510 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M | |
| 511 && packageInfo.versionCode >= 864021756) return false; | |
| 512 if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M | |
| 513 && packageInfo.versionCode >= 866001861) return false; | |
| 514 | |
| 515 Log.w(TAG, "Disabling thread check in WebView (http://crbug.com/6221 51). " | |
| 516 + "APK name: " + htcMailPackageId + ", versionCode: " | |
| 517 + packageInfo.versionCode); | |
| 518 return true; | |
| 519 } catch (NameNotFoundException e) { | |
| 520 // Ignore this exception and return false. | |
| 521 } | |
| 522 return false; | |
| 523 } | |
| 524 | |
| 525 // This is a workaround for https://crbug.com/622151. | |
| 526 // In HTC's email app, InputConnection.setComposingText() will call WebView. evaluateJavaScript, | |
| 527 // and thread assertion will occur. We turn off WebView thread assertion for this app. | |
| 528 private void disableThreadChecking() { | |
| 529 try { | |
| 530 Class<?> webViewClass = Class.forName("android.webkit.WebView"); | |
| 531 Field field = webViewClass.getDeclaredField("sEnforceThreadChecking" ); | |
| 532 field.setAccessible(true); | |
| 533 field.setBoolean(null, false); | |
| 534 field.setAccessible(false); | |
| 535 } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessEx ception | |
| 536 | IllegalArgumentException e) { | |
| 537 Log.w(TAG, "Failed to disable thread checking."); | |
| 538 } | |
| 486 } | 539 } |
| 487 | 540 |
| 488 @Override | 541 @Override |
| 489 public GeolocationPermissions getGeolocationPermissions() { | 542 public GeolocationPermissions getGeolocationPermissions() { |
| 490 synchronized (mLock) { | 543 synchronized (mLock) { |
| 491 if (mGeolocationPermissions == null) { | 544 if (mGeolocationPermissions == null) { |
| 492 ensureChromiumStartedLocked(true); | 545 ensureChromiumStartedLocked(true); |
| 493 AwGeolocationPermissions awGelocationPermissions = ThreadUtils.r unningOnUiThread() | 546 AwGeolocationPermissions awGelocationPermissions = ThreadUtils.r unningOnUiThread() |
| 494 ? getBrowserContextOnUiThread().getGeolocationPermission s() | 547 ? getBrowserContextOnUiThread().getGeolocationPermission s() |
| 495 : runOnUiThreadBlocking(new Callable<AwGeolocationPermis sions>() { | 548 : runOnUiThreadBlocking(new Callable<AwGeolocationPermis sions>() { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 mWebViewDatabase = new WebViewDatabaseAdapter(this, awDatabase); | 614 mWebViewDatabase = new WebViewDatabaseAdapter(this, awDatabase); |
| 562 } | 615 } |
| 563 } | 616 } |
| 564 return mWebViewDatabase; | 617 return mWebViewDatabase; |
| 565 } | 618 } |
| 566 | 619 |
| 567 WebViewDelegate getWebViewDelegate() { | 620 WebViewDelegate getWebViewDelegate() { |
| 568 return mWebViewDelegate; | 621 return mWebViewDelegate; |
| 569 } | 622 } |
| 570 } | 623 } |
| OLD | NEW |