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

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

Issue 2628863004: [Android WebView] Ensure we have user consent before uploading minidumps (Closed)
Patch Set: Check user consent before copying minidumps, delete minidumps in app dir if no consent, add unit te… Created 3 years, 11 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;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 import org.chromium.android_webview.AwCookieManager; 42 import org.chromium.android_webview.AwCookieManager;
43 import org.chromium.android_webview.AwDevToolsServer; 43 import org.chromium.android_webview.AwDevToolsServer;
44 import org.chromium.android_webview.AwMetricsServiceClient; 44 import org.chromium.android_webview.AwMetricsServiceClient;
45 import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy; 45 import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy;
46 import org.chromium.android_webview.AwQuotaManagerBridge; 46 import org.chromium.android_webview.AwQuotaManagerBridge;
47 import org.chromium.android_webview.AwResource; 47 import org.chromium.android_webview.AwResource;
48 import org.chromium.android_webview.AwSettings; 48 import org.chromium.android_webview.AwSettings;
49 import org.chromium.android_webview.HttpAuthDatabase; 49 import org.chromium.android_webview.HttpAuthDatabase;
50 import org.chromium.android_webview.PlatformServiceBridge; 50 import org.chromium.android_webview.PlatformServiceBridge;
51 import org.chromium.android_webview.ResourcesContextWrapperFactory; 51 import org.chromium.android_webview.ResourcesContextWrapperFactory;
52 import org.chromium.android_webview.command_line.CommandLineUtil;
52 import org.chromium.base.BuildConfig; 53 import org.chromium.base.BuildConfig;
53 import org.chromium.base.CommandLine; 54 import org.chromium.base.CommandLine;
54 import org.chromium.base.ContextUtils; 55 import org.chromium.base.ContextUtils;
55 import org.chromium.base.MemoryPressureListener; 56 import org.chromium.base.MemoryPressureListener;
56 import org.chromium.base.PackageUtils; 57 import org.chromium.base.PackageUtils;
57 import org.chromium.base.PathService; 58 import org.chromium.base.PathService;
58 import org.chromium.base.PathUtils; 59 import org.chromium.base.PathUtils;
59 import org.chromium.base.ThreadUtils; 60 import org.chromium.base.ThreadUtils;
60 import org.chromium.base.TraceEvent; 61 import org.chromium.base.TraceEvent;
61 import org.chromium.base.annotations.SuppressFBWarnings; 62 import org.chromium.base.annotations.SuppressFBWarnings;
(...skipping 14 matching lines...) Expand all
76 /** 77 /**
77 * 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
78 * implementation classes. 79 * implementation classes.
79 */ 80 */
80 @SuppressWarnings("deprecation") 81 @SuppressWarnings("deprecation")
81 public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { 82 public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider {
82 private static final String TAG = "WebViewChromiumFactoryProvider"; 83 private static final String TAG = "WebViewChromiumFactoryProvider";
83 84
84 private static final String CHROMIUM_PREFS_NAME = "WebViewChromiumPrefs"; 85 private static final String CHROMIUM_PREFS_NAME = "WebViewChromiumPrefs";
85 private static final String VERSION_CODE_PREF = "lastVersionCodeUsed"; 86 private static final String VERSION_CODE_PREF = "lastVersionCodeUsed";
86 private static final String COMMAND_LINE_FILE = "/data/local/tmp/webview-com mand-line";
87 private static final String HTTP_AUTH_DATABASE_FILE = "http_auth.db"; 87 private static final String HTTP_AUTH_DATABASE_FILE = "http_auth.db";
88 88
89 private class WebViewChromiumRunQueue { 89 private class WebViewChromiumRunQueue {
90 public WebViewChromiumRunQueue() { 90 public WebViewChromiumRunQueue() {
91 mQueue = new ConcurrentLinkedQueue<Runnable>(); 91 mQueue = new ConcurrentLinkedQueue<Runnable>();
92 } 92 }
93 93
94 public void addTask(Runnable task) { 94 public void addTask(Runnable task) {
95 mQueue.add(task); 95 mQueue.add(task);
96 if (WebViewChromiumFactoryProvider.this.hasStarted()) { 96 if (WebViewChromiumFactoryProvider.this.hasStarted()) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } catch (IllegalArgumentException e) { 208 } catch (IllegalArgumentException e) {
209 if (!ctx.getSystemService(UserManager.class).isUserUnlocked()) { 209 if (!ctx.getSystemService(UserManager.class).isUserUnlocked()) {
210 throw e; 210 throw e;
211 } 211 }
212 ctx = ctx.createCredentialProtectedStorageContext(); 212 ctx = ctx.createCredentialProtectedStorageContext();
213 } 213 }
214 214
215 // WebView needs to make sure to always use the wrapped application cont ext. 215 // WebView needs to make sure to always use the wrapped application cont ext.
216 ContextUtils.initApplicationContext(ResourcesContextWrapperFactory.get(c tx)); 216 ContextUtils.initApplicationContext(ResourcesContextWrapperFactory.get(c tx));
217 217
218 if (isBuildDebuggable()) { 218 if (CommandLineUtil.isBuildDebuggable()) {
219 // Suppress the StrictMode violation as this codepath is only hit on debuggable builds. 219 // Suppress the StrictMode violation as this codepath is only hit on debuggable builds.
220 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads( ); 220 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads( );
221 CommandLine.initFromFile(COMMAND_LINE_FILE); 221 CommandLine.initFromFile(CommandLineUtil.WEBVIEW_COMMAND_LINE_FILE);
222 StrictMode.setThreadPolicy(oldPolicy); 222 StrictMode.setThreadPolicy(oldPolicy);
223 } else { 223 } else {
224 CommandLine.init(null); 224 CommandLine.init(null);
225 } 225 }
226 226
227 if (Settings.Global.getInt(ContextUtils.getApplicationContext().getConte ntResolver(), 227 if (Settings.Global.getInt(ContextUtils.getApplicationContext().getConte ntResolver(),
228 Settings.Global.WEBVIEW_MULTIPROCESS, 0) 228 Settings.Global.WEBVIEW_MULTIPROCESS, 0)
229 == 1) { 229 == 1) {
230 CommandLine cl = CommandLine.getInstance(); 230 CommandLine cl = CommandLine.getInstance();
231 cl.appendSwitch("webview-sandboxed-renderer"); 231 cl.appendSwitch("webview-sandboxed-renderer");
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 } 263 }
264 264
265 static void checkStorageIsNotDeviceProtected(Context context) { 265 static void checkStorageIsNotDeviceProtected(Context context) {
266 if ((Build.VERSION.CODENAME.equals("N") || Build.VERSION.SDK_INT > Build .VERSION_CODES.M) 266 if ((Build.VERSION.CODENAME.equals("N") || Build.VERSION.SDK_INT > Build .VERSION_CODES.M)
267 && context.isDeviceProtectedStorage()) { 267 && context.isDeviceProtectedStorage()) {
268 throw new IllegalArgumentException( 268 throw new IllegalArgumentException(
269 "WebView cannot be used with device protected storage"); 269 "WebView cannot be used with device protected storage");
270 } 270 }
271 } 271 }
272 272
273 private static boolean isBuildDebuggable() {
274 return !Build.TYPE.equals("user");
275 }
276
277 /** 273 /**
278 * Both versionCodes should be from a WebView provider package implemented b y Chromium. 274 * Both versionCodes should be from a WebView provider package implemented b y Chromium.
279 * VersionCodes from other kinds of packages won't make any sense in this me thod. 275 * VersionCodes from other kinds of packages won't make any sense in this me thod.
280 * 276 *
281 * An introduction to Chromium versionCode scheme: 277 * An introduction to Chromium versionCode scheme:
282 * "BBBBPPPAX" 278 * "BBBBPPPAX"
283 * BBBB: 4 digit branch number. It monotonically increases over time. 279 * BBBB: 4 digit branch number. It monotonically increases over time.
284 * PPP: patch number in the branch. It is padded with zeroes to the left. Th ese three digits may 280 * PPP: patch number in the branch. It is padded with zeroes to the left. Th ese three digits may
285 * change their meaning in the future. 281 * change their meaning in the future.
286 * A: architecture digit. 282 * A: architecture digit.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 395
400 // Make sure that ResourceProvider is initialized before starting the br owser process. 396 // Make sure that ResourceProvider is initialized before starting the br owser process.
401 final String webViewPackageName = WebViewFactory.getLoadedPackageInfo(). packageName; 397 final String webViewPackageName = WebViewFactory.getLoadedPackageInfo(). packageName;
402 final Context context = ContextUtils.getApplicationContext(); 398 final Context context = ContextUtils.getApplicationContext();
403 setUpResources(webViewPackageName, context); 399 setUpResources(webViewPackageName, context);
404 initPlatSupportLibrary(); 400 initPlatSupportLibrary();
405 initNetworkChangeNotifier(context); 401 initNetworkChangeNotifier(context);
406 final boolean isExternalService = true; 402 final boolean isExternalService = true;
407 AwBrowserProcess.configureChildProcessLauncher(webViewPackageName, isExt ernalService); 403 AwBrowserProcess.configureChildProcessLauncher(webViewPackageName, isExt ernalService);
408 AwBrowserProcess.start(); 404 AwBrowserProcess.start();
409 AwBrowserProcess.handleMinidumps(webViewPackageName); 405
406 boolean enableMinidumpUploadingForTesting = CommandLine.getInstance().ha sSwitch(
407 CommandLineUtil.CRASH_UPLOADS_ENABLED_FOR_TESTING_SWITCH);
sgurun-gerrit only 2017/01/24 08:58:49 Is this only for convenience, to ease the manual t
gsennton 2017/01/24 10:41:47 It's also useful for devices that do not have the
sgurun-gerrit only 2017/01/24 18:55:27 I think we should be a little bit stingy while add
gsennton 2017/01/25 10:35:13 Which flag are we talking about here now? Are you
408 if (enableMinidumpUploadingForTesting) {
409 AwBrowserProcess.handleMinidumps(webViewPackageName, true /* enabled */);
410 } else {
411 // Copy minidumps if Android Checkbox is toggled on.
gsennton 2017/01/23 18:33:53 TODO merge this with the queryMetricsSetting call
sgurun-gerrit only 2017/01/24 08:58:49 +1
gsennton 2017/01/24 10:41:47 Why aren't we checking canUseGms() in the call bel
sgurun-gerrit only 2017/01/24 18:55:27 you need to check for canUseGms() only if you don'
gsennton 2017/01/25 10:35:13 Done.
412 PlatformServiceBridge platformServiceBridge =
413 PlatformServiceBridge.getInstance(context);
414 if (platformServiceBridge.canUseGms()) {
415 platformServiceBridge.queryMetricsSetting(new ValueCallback<Bool ean>() {
416 @Override
417 public void onReceiveValue(Boolean enabled) {
418 AwBrowserProcess.handleMinidumps(webViewPackageName, ena bled);
419 }
420 });
421 } else {
422 // Gms is not available - don't copy minidumps.
423 AwBrowserProcess.handleMinidumps(webViewPackageName, false /* en abled */);
424 }
425 }
410 426
411 PlatformServiceBridge.getInstance(context) 427 PlatformServiceBridge.getInstance(context)
412 .queryMetricsSetting(new ValueCallback<Boolean>() { 428 .queryMetricsSetting(new ValueCallback<Boolean>() {
413 public void onReceiveValue(Boolean enabled) { 429 public void onReceiveValue(Boolean enabled) {
414 ThreadUtils.assertOnUiThread(); 430 ThreadUtils.assertOnUiThread();
415 AwMetricsServiceClient.setConsentSetting(context, enable d); 431 AwMetricsServiceClient.setConsentSetting(context, enable d);
416 } 432 }
417 }); 433 });
418 434
419 if (isBuildDebuggable()) { 435 if (CommandLineUtil.isBuildDebuggable()) {
420 setWebContentsDebuggingEnabled(true); 436 setWebContentsDebuggingEnabled(true);
421 } 437 }
422 438
423 TraceEvent.setATraceEnabled(mWebViewDelegate.isTraceTagEnabled()); 439 TraceEvent.setATraceEnabled(mWebViewDelegate.isTraceTagEnabled());
424 mWebViewDelegate.setOnTraceEnabledChangeListener( 440 mWebViewDelegate.setOnTraceEnabledChangeListener(
425 new WebViewDelegate.OnTraceEnabledChangeListener() { 441 new WebViewDelegate.OnTraceEnabledChangeListener() {
426 @Override 442 @Override
427 public void onTraceEnabledChange(boolean enabled) { 443 public void onTraceEnabledChange(boolean enabled) {
428 TraceEvent.setATraceEnabled(enabled); 444 TraceEvent.setATraceEnabled(enabled);
429 } 445 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 } 521 }
506 522
507 @Override 523 @Override
508 public String getDefaultUserAgent(Context context) { 524 public String getDefaultUserAgent(Context context) {
509 return AwSettings.getDefaultUserAgent(); 525 return AwSettings.getDefaultUserAgent();
510 } 526 }
511 527
512 @Override 528 @Override
513 public void setWebContentsDebuggingEnabled(boolean enable) { 529 public void setWebContentsDebuggingEnabled(boolean enable) {
514 // Web Contents debugging is always enabled on debug bui lds. 530 // Web Contents debugging is always enabled on debug bui lds.
515 if (!isBuildDebuggable()) { 531 if (!CommandLineUtil.isBuildDebuggable()) {
516 WebViewChromiumFactoryProvider.this.setWebContentsDe buggingEnabled( 532 WebViewChromiumFactoryProvider.this.setWebContentsDe buggingEnabled(
517 enable); 533 enable);
518 } 534 }
519 } 535 }
520 536
521 @Override 537 @Override
522 public void clearClientCertPreferences(Runnable onCleared) { 538 public void clearClientCertPreferences(Runnable onCleared) {
523 AwContentsStatics.clearClientCertPreferences(onCleared); 539 AwContentsStatics.clearClientCertPreferences(onCleared);
524 } 540 }
525 541
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 WebViewDelegate getWebViewDelegate() { 685 WebViewDelegate getWebViewDelegate() {
670 return mWebViewDelegate; 686 return mWebViewDelegate;
671 } 687 }
672 688
673 // The method to support unreleased Android. 689 // The method to support unreleased Android.
674 WebViewContentsClientAdapter createWebViewContentsClientAdapter(WebView webV iew, 690 WebViewContentsClientAdapter createWebViewContentsClientAdapter(WebView webV iew,
675 Context context) { 691 Context context) {
676 return new WebViewContentsClientAdapter(webView, context, mWebViewDelega te); 692 return new WebViewContentsClientAdapter(webView, context, mWebViewDelega te);
677 } 693 }
678 } 694 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698