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

Side by Side Diff: android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java

Issue 2655023008: [Android WebView] Ensure Android Checkbox is on when uploading minidumps (Closed)
Patch Set: Rebase Created 3 years, 10 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.net.Uri; 15 import android.net.Uri;
16 import android.os.Build; 16 import android.os.Build;
17 import android.os.Looper; 17 import android.os.Looper;
18 import android.os.Process; 18 import android.os.Process;
19 import android.os.StrictMode;
20 import android.os.UserManager; 19 import android.os.UserManager;
21 import android.provider.Settings; 20 import android.provider.Settings;
22 import android.util.Log; 21 import android.util.Log;
23 import android.webkit.CookieManager; 22 import android.webkit.CookieManager;
24 import android.webkit.GeolocationPermissions; 23 import android.webkit.GeolocationPermissions;
25 import android.webkit.ServiceWorkerController; 24 import android.webkit.ServiceWorkerController;
26 import android.webkit.TokenBindingService; 25 import android.webkit.TokenBindingService;
27 import android.webkit.ValueCallback; 26 import android.webkit.ValueCallback;
28 import android.webkit.WebStorage; 27 import android.webkit.WebStorage;
29 import android.webkit.WebView; 28 import android.webkit.WebView;
(...skipping 12 matching lines...) Expand all
42 import org.chromium.android_webview.AwCookieManager; 41 import org.chromium.android_webview.AwCookieManager;
43 import org.chromium.android_webview.AwDevToolsServer; 42 import org.chromium.android_webview.AwDevToolsServer;
44 import org.chromium.android_webview.AwMetricsServiceClient; 43 import org.chromium.android_webview.AwMetricsServiceClient;
45 import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy; 44 import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy;
46 import org.chromium.android_webview.AwQuotaManagerBridge; 45 import org.chromium.android_webview.AwQuotaManagerBridge;
47 import org.chromium.android_webview.AwResource; 46 import org.chromium.android_webview.AwResource;
48 import org.chromium.android_webview.AwSettings; 47 import org.chromium.android_webview.AwSettings;
49 import org.chromium.android_webview.HttpAuthDatabase; 48 import org.chromium.android_webview.HttpAuthDatabase;
50 import org.chromium.android_webview.PlatformServiceBridge; 49 import org.chromium.android_webview.PlatformServiceBridge;
51 import org.chromium.android_webview.ResourcesContextWrapperFactory; 50 import org.chromium.android_webview.ResourcesContextWrapperFactory;
51 import org.chromium.android_webview.command_line.CommandLineUtil;
52 import org.chromium.base.BuildConfig; 52 import org.chromium.base.BuildConfig;
53 import org.chromium.base.BuildInfo; 53 import org.chromium.base.BuildInfo;
54 import org.chromium.base.CommandLine; 54 import org.chromium.base.CommandLine;
55 import org.chromium.base.ContextUtils; 55 import org.chromium.base.ContextUtils;
56 import org.chromium.base.MemoryPressureListener; 56 import org.chromium.base.MemoryPressureListener;
57 import org.chromium.base.PackageUtils; 57 import org.chromium.base.PackageUtils;
58 import org.chromium.base.PathService; 58 import org.chromium.base.PathService;
59 import org.chromium.base.PathUtils; 59 import org.chromium.base.PathUtils;
60 import org.chromium.base.ThreadUtils; 60 import org.chromium.base.ThreadUtils;
61 import org.chromium.base.TraceEvent; 61 import org.chromium.base.TraceEvent;
62 import org.chromium.base.annotations.SuppressFBWarnings;
63 import org.chromium.base.library_loader.LibraryLoader; 62 import org.chromium.base.library_loader.LibraryLoader;
64 import org.chromium.base.library_loader.LibraryProcessType; 63 import org.chromium.base.library_loader.LibraryProcessType;
65 import org.chromium.base.library_loader.NativeLibraries; 64 import org.chromium.base.library_loader.NativeLibraries;
66 import org.chromium.base.library_loader.ProcessInitException; 65 import org.chromium.base.library_loader.ProcessInitException;
67 import org.chromium.content.browser.ContentViewStatics; 66 import org.chromium.content.browser.ContentViewStatics;
68 import org.chromium.content.browser.input.LGEmailActionModeWorkaround; 67 import org.chromium.content.browser.input.LGEmailActionModeWorkaround;
69 import org.chromium.net.NetworkChangeNotifier; 68 import org.chromium.net.NetworkChangeNotifier;
70 69
71 import java.io.File; 70 import java.io.File;
72 import java.util.Queue; 71 import java.util.Queue;
73 import java.util.concurrent.Callable; 72 import java.util.concurrent.Callable;
74 import java.util.concurrent.ConcurrentLinkedQueue; 73 import java.util.concurrent.ConcurrentLinkedQueue;
75 import java.util.concurrent.FutureTask; 74 import java.util.concurrent.FutureTask;
76 import java.util.concurrent.TimeUnit; 75 import java.util.concurrent.TimeUnit;
77 76
78 /** 77 /**
79 * Entry point to the WebView. The system framework talks to this class to get i nstances of the 78 * Entry point to the WebView. The system framework talks to this class to get i nstances of the
80 * implementation classes. 79 * implementation classes.
81 */ 80 */
82 @SuppressWarnings("deprecation") 81 @SuppressWarnings("deprecation")
83 public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { 82 public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider {
84 private static final String TAG = "WebViewChromiumFactoryProvider"; 83 private static final String TAG = "WebViewChromiumFactoryProvider";
85 84
86 private static final String CHROMIUM_PREFS_NAME = "WebViewChromiumPrefs"; 85 private static final String CHROMIUM_PREFS_NAME = "WebViewChromiumPrefs";
87 private static final String VERSION_CODE_PREF = "lastVersionCodeUsed"; 86 private static final String VERSION_CODE_PREF = "lastVersionCodeUsed";
88 private static final String COMMAND_LINE_FILE = "/data/local/tmp/webview-com mand-line";
89 private static final String HTTP_AUTH_DATABASE_FILE = "http_auth.db"; 87 private static final String HTTP_AUTH_DATABASE_FILE = "http_auth.db";
90 // same switch as kEnableCrashReporterForTesting in //base/base_switches.h
91 public static final String CRASH_UPLOADS_ENABLED_FOR_TESTING_SWITCH =
92 "enable-crash-reporter-for-testing";
93 88
94 private class WebViewChromiumRunQueue { 89 private class WebViewChromiumRunQueue {
95 public WebViewChromiumRunQueue() { 90 public WebViewChromiumRunQueue() {
96 mQueue = new ConcurrentLinkedQueue<Runnable>(); 91 mQueue = new ConcurrentLinkedQueue<Runnable>();
97 } 92 }
98 93
99 public void addTask(Runnable task) { 94 public void addTask(Runnable task) {
100 mQueue.add(task); 95 mQueue.add(task);
101 if (WebViewChromiumFactoryProvider.this.hasStarted()) { 96 if (WebViewChromiumFactoryProvider.this.hasStarted()) {
102 ThreadUtils.runOnUiThread(new Runnable() { 97 ThreadUtils.runOnUiThread(new Runnable() {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 initialize(WebViewDelegateFactory.createProxyDelegate(delegate)); 197 initialize(WebViewDelegateFactory.createProxyDelegate(delegate));
203 } 198 }
204 199
205 /** 200 /**
206 * Constructor for internal use when a proxy delegate has already been creat ed. 201 * Constructor for internal use when a proxy delegate has already been creat ed.
207 */ 202 */
208 WebViewChromiumFactoryProvider(WebViewDelegate delegate) { 203 WebViewChromiumFactoryProvider(WebViewDelegate delegate) {
209 initialize(delegate); 204 initialize(delegate);
210 } 205 }
211 206
212 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
213 private void initialize(WebViewDelegate webViewDelegate) { 207 private void initialize(WebViewDelegate webViewDelegate) {
214 mWebViewDelegate = webViewDelegate; 208 mWebViewDelegate = webViewDelegate;
215 Context ctx = mWebViewDelegate.getApplication().getApplicationContext(); 209 Context ctx = mWebViewDelegate.getApplication().getApplicationContext();
216 210
217 // If the application context is DE, but we have credentials, use a CE c ontext instead 211 // If the application context is DE, but we have credentials, use a CE c ontext instead
218 try { 212 try {
219 checkStorageIsNotDeviceProtected(mWebViewDelegate.getApplication()); 213 checkStorageIsNotDeviceProtected(mWebViewDelegate.getApplication());
220 } catch (IllegalArgumentException e) { 214 } catch (IllegalArgumentException e) {
221 if (!ctx.getSystemService(UserManager.class).isUserUnlocked()) { 215 if (!ctx.getSystemService(UserManager.class).isUserUnlocked()) {
222 throw e; 216 throw e;
223 } 217 }
224 ctx = ctx.createCredentialProtectedStorageContext(); 218 ctx = ctx.createCredentialProtectedStorageContext();
225 } 219 }
226 220
227 // WebView needs to make sure to always use the wrapped application cont ext. 221 // WebView needs to make sure to always use the wrapped application cont ext.
228 ContextUtils.initApplicationContext(ResourcesContextWrapperFactory.get(c tx)); 222 ContextUtils.initApplicationContext(ResourcesContextWrapperFactory.get(c tx));
229 223
230 if (isBuildDebuggable()) { 224 CommandLineUtil.initCommandLine();
231 // Suppress the StrictMode violation as this codepath is only hit on debuggable builds.
232 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads( );
233 CommandLine.initFromFile(COMMAND_LINE_FILE);
234 StrictMode.setThreadPolicy(oldPolicy);
235 } else {
236 CommandLine.init(null);
237 }
238 225
239 boolean multiProcess = false; 226 boolean multiProcess = false;
240 if (BuildInfo.isAtLeastO()) { 227 if (BuildInfo.isAtLeastO()) {
241 // Ask the system if multiprocess should be enabled on O+. 228 // Ask the system if multiprocess should be enabled on O+.
242 multiProcess = mWebViewDelegate.isMultiProcessEnabled(); 229 multiProcess = mWebViewDelegate.isMultiProcessEnabled();
243 } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 230 } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
244 // Check the multiprocess developer setting directly on N. 231 // Check the multiprocess developer setting directly on N.
245 multiProcess = Settings.Global.getInt( 232 multiProcess = Settings.Global.getInt(
246 ContextUtils.getApplicationContext().getContentResolver(), 233 ContextUtils.getApplicationContext().getContentResolver(),
247 Settings.Global.WEBVIEW_MULTIPROCESS, 0) == 1; 234 Settings.Global.WEBVIEW_MULTIPROCESS, 0) == 1;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 } 270 }
284 271
285 static void checkStorageIsNotDeviceProtected(Context context) { 272 static void checkStorageIsNotDeviceProtected(Context context) {
286 if ((Build.VERSION.CODENAME.equals("N") || Build.VERSION.SDK_INT > Build .VERSION_CODES.M) 273 if ((Build.VERSION.CODENAME.equals("N") || Build.VERSION.SDK_INT > Build .VERSION_CODES.M)
287 && context.isDeviceProtectedStorage()) { 274 && context.isDeviceProtectedStorage()) {
288 throw new IllegalArgumentException( 275 throw new IllegalArgumentException(
289 "WebView cannot be used with device protected storage"); 276 "WebView cannot be used with device protected storage");
290 } 277 }
291 } 278 }
292 279
293 private static boolean isBuildDebuggable() {
294 return !Build.TYPE.equals("user");
295 }
296
297 /** 280 /**
298 * Both versionCodes should be from a WebView provider package implemented b y Chromium. 281 * Both versionCodes should be from a WebView provider package implemented b y Chromium.
299 * VersionCodes from other kinds of packages won't make any sense in this me thod. 282 * VersionCodes from other kinds of packages won't make any sense in this me thod.
300 * 283 *
301 * An introduction to Chromium versionCode scheme: 284 * An introduction to Chromium versionCode scheme:
302 * "BBBBPPPAX" 285 * "BBBBPPPAX"
303 * BBBB: 4 digit branch number. It monotonically increases over time. 286 * BBBB: 4 digit branch number. It monotonically increases over time.
304 * PPP: patch number in the branch. It is padded with zeroes to the left. Th ese three digits may 287 * PPP: patch number in the branch. It is padded with zeroes to the left. Th ese three digits may
305 * change their meaning in the future. 288 * change their meaning in the future.
306 * A: architecture digit. 289 * A: architecture digit.
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 final String webViewPackageName = WebViewFactory.getLoadedPackageInfo(). packageName; 409 final String webViewPackageName = WebViewFactory.getLoadedPackageInfo(). packageName;
427 final Context context = ContextUtils.getApplicationContext(); 410 final Context context = ContextUtils.getApplicationContext();
428 setUpResources(webViewPackageName, context); 411 setUpResources(webViewPackageName, context);
429 initPlatSupportLibrary(); 412 initPlatSupportLibrary();
430 doNetworkInitializations(context); 413 doNetworkInitializations(context);
431 final boolean isExternalService = true; 414 final boolean isExternalService = true;
432 AwBrowserProcess.configureChildProcessLauncher(webViewPackageName, isExt ernalService); 415 AwBrowserProcess.configureChildProcessLauncher(webViewPackageName, isExt ernalService);
433 AwBrowserProcess.start(); 416 AwBrowserProcess.start();
434 417
435 final boolean enableMinidumpUploadingForTesting = CommandLine.getInstanc e().hasSwitch( 418 final boolean enableMinidumpUploadingForTesting = CommandLine.getInstanc e().hasSwitch(
436 CRASH_UPLOADS_ENABLED_FOR_TESTING_SWITCH); 419 CommandLineUtil.CRASH_UPLOADS_ENABLED_FOR_TESTING_SWITCH);
437 if (enableMinidumpUploadingForTesting) { 420 if (enableMinidumpUploadingForTesting) {
438 AwBrowserProcess.handleMinidumps(webViewPackageName, true /* enabled */); 421 AwBrowserProcess.handleMinidumps(webViewPackageName, true /* enabled */);
439 } 422 }
440 423
441 // Actions conditioned on whether the Android Checkbox is toggled on 424 // Actions conditioned on whether the Android Checkbox is toggled on
442 PlatformServiceBridge.getInstance(context) 425 PlatformServiceBridge.getInstance(context)
443 .queryMetricsSetting(new ValueCallback<Boolean>() { 426 .queryMetricsSetting(new ValueCallback<Boolean>() {
444 public void onReceiveValue(Boolean enabled) { 427 public void onReceiveValue(Boolean enabled) {
445 ThreadUtils.assertOnUiThread(); 428 ThreadUtils.assertOnUiThread();
446 AwMetricsServiceClient.setConsentSetting(context, enable d); 429 AwMetricsServiceClient.setConsentSetting(context, enable d);
447 430
448 if (!enableMinidumpUploadingForTesting) { 431 if (!enableMinidumpUploadingForTesting) {
449 AwBrowserProcess.handleMinidumps(webViewPackageName, enabled); 432 AwBrowserProcess.handleMinidumps(webViewPackageName, enabled);
450 } 433 }
451 } 434 }
452 }); 435 });
453 436
454 if (isBuildDebuggable()) { 437 if (CommandLineUtil.isBuildDebuggable()) {
455 setWebContentsDebuggingEnabled(true); 438 setWebContentsDebuggingEnabled(true);
456 } 439 }
457 440
458 TraceEvent.setATraceEnabled(mWebViewDelegate.isTraceTagEnabled()); 441 TraceEvent.setATraceEnabled(mWebViewDelegate.isTraceTagEnabled());
459 mWebViewDelegate.setOnTraceEnabledChangeListener( 442 mWebViewDelegate.setOnTraceEnabledChangeListener(
460 new WebViewDelegate.OnTraceEnabledChangeListener() { 443 new WebViewDelegate.OnTraceEnabledChangeListener() {
461 @Override 444 @Override
462 public void onTraceEnabledChange(boolean enabled) { 445 public void onTraceEnabledChange(boolean enabled) {
463 TraceEvent.setATraceEnabled(enabled); 446 TraceEvent.setATraceEnabled(enabled);
464 } 447 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 } 523 }
541 524
542 @Override 525 @Override
543 public String getDefaultUserAgent(Context context) { 526 public String getDefaultUserAgent(Context context) {
544 return AwSettings.getDefaultUserAgent(); 527 return AwSettings.getDefaultUserAgent();
545 } 528 }
546 529
547 @Override 530 @Override
548 public void setWebContentsDebuggingEnabled(boolean enable) { 531 public void setWebContentsDebuggingEnabled(boolean enable) {
549 // Web Contents debugging is always enabled on debug bui lds. 532 // Web Contents debugging is always enabled on debug bui lds.
550 if (!isBuildDebuggable()) { 533 if (!CommandLineUtil.isBuildDebuggable()) {
551 WebViewChromiumFactoryProvider.this.setWebContentsDe buggingEnabled( 534 WebViewChromiumFactoryProvider.this.setWebContentsDe buggingEnabled(
552 enable); 535 enable);
553 } 536 }
554 } 537 }
555 538
556 @Override 539 @Override
557 public void clearClientCertPreferences(Runnable onCleared) { 540 public void clearClientCertPreferences(Runnable onCleared) {
558 AwContentsStatics.clearClientCertPreferences(onCleared); 541 AwContentsStatics.clearClientCertPreferences(onCleared);
559 } 542 }
560 543
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 WebViewDelegate getWebViewDelegate() { 688 WebViewDelegate getWebViewDelegate() {
706 return mWebViewDelegate; 689 return mWebViewDelegate;
707 } 690 }
708 691
709 // The method to support unreleased Android. 692 // The method to support unreleased Android.
710 WebViewContentsClientAdapter createWebViewContentsClientAdapter(WebView webV iew, 693 WebViewContentsClientAdapter createWebViewContentsClientAdapter(WebView webV iew,
711 Context context) { 694 Context context) {
712 return new WebViewContentsClientAdapter(webView, context, mWebViewDelega te); 695 return new WebViewContentsClientAdapter(webView, context, mWebViewDelega te);
713 } 696 }
714 } 697 }
OLDNEW
« no previous file with comments | « android_webview/glue/glue.gni ('k') | android_webview/java/src/org/chromium/android_webview/command_line/CommandLineUtil.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698