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

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: Minor cleanups + comment fixes. 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;
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.CommandLine; 53 import org.chromium.base.CommandLine;
54 import org.chromium.base.ContextUtils; 54 import org.chromium.base.ContextUtils;
55 import org.chromium.base.MemoryPressureListener; 55 import org.chromium.base.MemoryPressureListener;
56 import org.chromium.base.PackageUtils; 56 import org.chromium.base.PackageUtils;
57 import org.chromium.base.PathService; 57 import org.chromium.base.PathService;
58 import org.chromium.base.PathUtils; 58 import org.chromium.base.PathUtils;
59 import org.chromium.base.ThreadUtils; 59 import org.chromium.base.ThreadUtils;
60 import org.chromium.base.TraceEvent; 60 import org.chromium.base.TraceEvent;
61 import org.chromium.base.annotations.SuppressFBWarnings;
62 import org.chromium.base.library_loader.LibraryLoader; 61 import org.chromium.base.library_loader.LibraryLoader;
63 import org.chromium.base.library_loader.LibraryProcessType; 62 import org.chromium.base.library_loader.LibraryProcessType;
64 import org.chromium.base.library_loader.NativeLibraries; 63 import org.chromium.base.library_loader.NativeLibraries;
65 import org.chromium.base.library_loader.ProcessInitException; 64 import org.chromium.base.library_loader.ProcessInitException;
66 import org.chromium.content.browser.ContentViewStatics; 65 import org.chromium.content.browser.ContentViewStatics;
67 import org.chromium.net.NetworkChangeNotifier; 66 import org.chromium.net.NetworkChangeNotifier;
68 67
69 import java.io.File; 68 import java.io.File;
70 import java.util.Queue; 69 import java.util.Queue;
71 import java.util.concurrent.Callable; 70 import java.util.concurrent.Callable;
72 import java.util.concurrent.ConcurrentLinkedQueue; 71 import java.util.concurrent.ConcurrentLinkedQueue;
73 import java.util.concurrent.FutureTask; 72 import java.util.concurrent.FutureTask;
74 import java.util.concurrent.TimeUnit; 73 import java.util.concurrent.TimeUnit;
75 74
76 /** 75 /**
77 * Entry point to the WebView. The system framework talks to this class to get i nstances of the 76 * Entry point to the WebView. The system framework talks to this class to get i nstances of the
78 * implementation classes. 77 * implementation classes.
79 */ 78 */
80 @SuppressWarnings("deprecation") 79 @SuppressWarnings("deprecation")
81 public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { 80 public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider {
82 private static final String TAG = "WebViewChromiumFactoryProvider"; 81 private static final String TAG = "WebViewChromiumFactoryProvider";
83 82
84 private static final String CHROMIUM_PREFS_NAME = "WebViewChromiumPrefs"; 83 private static final String CHROMIUM_PREFS_NAME = "WebViewChromiumPrefs";
85 private static final String VERSION_CODE_PREF = "lastVersionCodeUsed"; 84 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"; 85 private static final String HTTP_AUTH_DATABASE_FILE = "http_auth.db";
88 86
89 private class WebViewChromiumRunQueue { 87 private class WebViewChromiumRunQueue {
90 public WebViewChromiumRunQueue() { 88 public WebViewChromiumRunQueue() {
91 mQueue = new ConcurrentLinkedQueue<Runnable>(); 89 mQueue = new ConcurrentLinkedQueue<Runnable>();
92 } 90 }
93 91
94 public void addTask(Runnable task) { 92 public void addTask(Runnable task) {
95 mQueue.add(task); 93 mQueue.add(task);
96 if (WebViewChromiumFactoryProvider.this.hasStarted()) { 94 if (WebViewChromiumFactoryProvider.this.hasStarted()) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 initialize(WebViewDelegateFactory.createApi21CompatibilityDelegate()); 188 initialize(WebViewDelegateFactory.createApi21CompatibilityDelegate());
191 } 189 }
192 190
193 /** 191 /**
194 * Constructor called by the API 22 version of {@link WebViewFactory} and la ter. 192 * Constructor called by the API 22 version of {@link WebViewFactory} and la ter.
195 */ 193 */
196 public WebViewChromiumFactoryProvider(android.webkit.WebViewDelegate delegat e) { 194 public WebViewChromiumFactoryProvider(android.webkit.WebViewDelegate delegat e) {
197 initialize(WebViewDelegateFactory.createProxyDelegate(delegate)); 195 initialize(WebViewDelegateFactory.createProxyDelegate(delegate));
198 } 196 }
199 197
200 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
201 private void initialize(WebViewDelegate webViewDelegate) { 198 private void initialize(WebViewDelegate webViewDelegate) {
202 mWebViewDelegate = webViewDelegate; 199 mWebViewDelegate = webViewDelegate;
203 Context ctx = mWebViewDelegate.getApplication().getApplicationContext(); 200 Context ctx = mWebViewDelegate.getApplication().getApplicationContext();
204 201
205 // If the application context is DE, but we have credentials, use a CE c ontext instead 202 // If the application context is DE, but we have credentials, use a CE c ontext instead
206 try { 203 try {
207 checkStorageIsNotDeviceProtected(mWebViewDelegate.getApplication()); 204 checkStorageIsNotDeviceProtected(mWebViewDelegate.getApplication());
208 } catch (IllegalArgumentException e) { 205 } catch (IllegalArgumentException e) {
209 if (!ctx.getSystemService(UserManager.class).isUserUnlocked()) { 206 if (!ctx.getSystemService(UserManager.class).isUserUnlocked()) {
210 throw e; 207 throw e;
211 } 208 }
212 ctx = ctx.createCredentialProtectedStorageContext(); 209 ctx = ctx.createCredentialProtectedStorageContext();
213 } 210 }
214 211
215 // WebView needs to make sure to always use the wrapped application cont ext. 212 // WebView needs to make sure to always use the wrapped application cont ext.
216 ContextUtils.initApplicationContext(ResourcesContextWrapperFactory.get(c tx)); 213 ContextUtils.initApplicationContext(ResourcesContextWrapperFactory.get(c tx));
217 214
218 if (isBuildDebuggable()) { 215 CommandLineUtil.initCommandLine();
219 // Suppress the StrictMode violation as this codepath is only hit on debuggable builds.
220 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads( );
221 CommandLine.initFromFile(COMMAND_LINE_FILE);
222 StrictMode.setThreadPolicy(oldPolicy);
223 } else {
224 CommandLine.init(null);
225 }
226 216
227 if (Settings.Global.getInt(ContextUtils.getApplicationContext().getConte ntResolver(), 217 if (Settings.Global.getInt(ContextUtils.getApplicationContext().getConte ntResolver(),
228 Settings.Global.WEBVIEW_MULTIPROCESS, 0) 218 Settings.Global.WEBVIEW_MULTIPROCESS, 0)
229 == 1) { 219 == 1) {
230 CommandLine cl = CommandLine.getInstance(); 220 CommandLine cl = CommandLine.getInstance();
231 cl.appendSwitch("webview-sandboxed-renderer"); 221 cl.appendSwitch("webview-sandboxed-renderer");
232 } 222 }
233 223
234 ThreadUtils.setWillOverrideUiThread(); 224 ThreadUtils.setWillOverrideUiThread();
235 // Load chromium library. 225 // Load chromium library.
(...skipping 27 matching lines...) Expand all
263 } 253 }
264 254
265 static void checkStorageIsNotDeviceProtected(Context context) { 255 static void checkStorageIsNotDeviceProtected(Context context) {
266 if ((Build.VERSION.CODENAME.equals("N") || Build.VERSION.SDK_INT > Build .VERSION_CODES.M) 256 if ((Build.VERSION.CODENAME.equals("N") || Build.VERSION.SDK_INT > Build .VERSION_CODES.M)
267 && context.isDeviceProtectedStorage()) { 257 && context.isDeviceProtectedStorage()) {
268 throw new IllegalArgumentException( 258 throw new IllegalArgumentException(
269 "WebView cannot be used with device protected storage"); 259 "WebView cannot be used with device protected storage");
270 } 260 }
271 } 261 }
272 262
273 private static boolean isBuildDebuggable() {
274 return !Build.TYPE.equals("user");
275 }
276
277 /** 263 /**
278 * Both versionCodes should be from a WebView provider package implemented b y Chromium. 264 * 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. 265 * VersionCodes from other kinds of packages won't make any sense in this me thod.
280 * 266 *
281 * An introduction to Chromium versionCode scheme: 267 * An introduction to Chromium versionCode scheme:
282 * "BBBBPPPAX" 268 * "BBBBPPPAX"
283 * BBBB: 4 digit branch number. It monotonically increases over time. 269 * 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 270 * 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. 271 * change their meaning in the future.
286 * A: architecture digit. 272 * A: architecture digit.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 385
400 // Make sure that ResourceProvider is initialized before starting the br owser process. 386 // Make sure that ResourceProvider is initialized before starting the br owser process.
401 final String webViewPackageName = WebViewFactory.getLoadedPackageInfo(). packageName; 387 final String webViewPackageName = WebViewFactory.getLoadedPackageInfo(). packageName;
402 final Context context = ContextUtils.getApplicationContext(); 388 final Context context = ContextUtils.getApplicationContext();
403 setUpResources(webViewPackageName, context); 389 setUpResources(webViewPackageName, context);
404 initPlatSupportLibrary(); 390 initPlatSupportLibrary();
405 initNetworkChangeNotifier(context); 391 initNetworkChangeNotifier(context);
406 final boolean isExternalService = true; 392 final boolean isExternalService = true;
407 AwBrowserProcess.configureChildProcessLauncher(webViewPackageName, isExt ernalService); 393 AwBrowserProcess.configureChildProcessLauncher(webViewPackageName, isExt ernalService);
408 AwBrowserProcess.start(); 394 AwBrowserProcess.start();
409 AwBrowserProcess.handleMinidumps(webViewPackageName);
410 395
396 final boolean enableMinidumpUploadingForTesting = CommandLine.getInstanc e().hasSwitch(
sgurun-gerrit only 2017/01/25 19:42:06 you can inline this to if
397 CommandLineUtil.CRASH_UPLOADS_ENABLED_FOR_TESTING_SWITCH);
398 if (enableMinidumpUploadingForTesting) {
399 AwBrowserProcess.handleMinidumps(webViewPackageName, true /* enabled */);
400 }
401
402 // Actions conditioned on whether the Android Checkbox is toggled on
411 PlatformServiceBridge.getInstance(context) 403 PlatformServiceBridge.getInstance(context)
sgurun-gerrit only 2017/01/25 19:42:06 move to else as no need to do this if command line
paulmiller 2017/01/25 21:46:31 This is still needed for AwMetricsServiceClient.se
gsennton 2017/01/26 10:24:50 I'm doing all of this because we wanted to merge t
412 .queryMetricsSetting(new ValueCallback<Boolean>() { 404 .queryMetricsSetting(new ValueCallback<Boolean>() {
413 public void onReceiveValue(Boolean enabled) { 405 public void onReceiveValue(Boolean enabled) {
414 ThreadUtils.assertOnUiThread(); 406 ThreadUtils.assertOnUiThread();
415 AwMetricsServiceClient.setConsentSetting(context, enable d); 407 AwMetricsServiceClient.setConsentSetting(context, enable d);
408
409 if (!enableMinidumpUploadingForTesting) {
sgurun-gerrit only 2017/01/25 19:42:06 after moving to else, remove that.
410 AwBrowserProcess.handleMinidumps(webViewPackageName, enabled);
411 }
416 } 412 }
417 }); 413 });
418 414
419 if (isBuildDebuggable()) { 415 if (CommandLineUtil.isBuildDebuggable()) {
420 setWebContentsDebuggingEnabled(true); 416 setWebContentsDebuggingEnabled(true);
421 } 417 }
422 418
423 TraceEvent.setATraceEnabled(mWebViewDelegate.isTraceTagEnabled()); 419 TraceEvent.setATraceEnabled(mWebViewDelegate.isTraceTagEnabled());
424 mWebViewDelegate.setOnTraceEnabledChangeListener( 420 mWebViewDelegate.setOnTraceEnabledChangeListener(
425 new WebViewDelegate.OnTraceEnabledChangeListener() { 421 new WebViewDelegate.OnTraceEnabledChangeListener() {
426 @Override 422 @Override
427 public void onTraceEnabledChange(boolean enabled) { 423 public void onTraceEnabledChange(boolean enabled) {
428 TraceEvent.setATraceEnabled(enabled); 424 TraceEvent.setATraceEnabled(enabled);
429 } 425 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 } 501 }
506 502
507 @Override 503 @Override
508 public String getDefaultUserAgent(Context context) { 504 public String getDefaultUserAgent(Context context) {
509 return AwSettings.getDefaultUserAgent(); 505 return AwSettings.getDefaultUserAgent();
510 } 506 }
511 507
512 @Override 508 @Override
513 public void setWebContentsDebuggingEnabled(boolean enable) { 509 public void setWebContentsDebuggingEnabled(boolean enable) {
514 // Web Contents debugging is always enabled on debug bui lds. 510 // Web Contents debugging is always enabled on debug bui lds.
515 if (!isBuildDebuggable()) { 511 if (!CommandLineUtil.isBuildDebuggable()) {
516 WebViewChromiumFactoryProvider.this.setWebContentsDe buggingEnabled( 512 WebViewChromiumFactoryProvider.this.setWebContentsDe buggingEnabled(
517 enable); 513 enable);
518 } 514 }
519 } 515 }
520 516
521 @Override 517 @Override
522 public void clearClientCertPreferences(Runnable onCleared) { 518 public void clearClientCertPreferences(Runnable onCleared) {
523 AwContentsStatics.clearClientCertPreferences(onCleared); 519 AwContentsStatics.clearClientCertPreferences(onCleared);
524 } 520 }
525 521
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 WebViewDelegate getWebViewDelegate() { 665 WebViewDelegate getWebViewDelegate() {
670 return mWebViewDelegate; 666 return mWebViewDelegate;
671 } 667 }
672 668
673 // The method to support unreleased Android. 669 // The method to support unreleased Android.
674 WebViewContentsClientAdapter createWebViewContentsClientAdapter(WebView webV iew, 670 WebViewContentsClientAdapter createWebViewContentsClientAdapter(WebView webV iew,
675 Context context) { 671 Context context) {
676 return new WebViewContentsClientAdapter(webView, context, mWebViewDelega te); 672 return new WebViewContentsClientAdapter(webView, context, mWebViewDelega te);
677 } 673 }
678 } 674 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698