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

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

Issue 2076623002: 🍳 Fix and clean up application context in webview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Wrap context. Created 4 years, 6 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
« no previous file with comments | « no previous file | android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 public WebViewChromiumFactoryProvider(android.webkit.WebViewDelegate delegat e) { 111 public WebViewChromiumFactoryProvider(android.webkit.WebViewDelegate delegat e) {
112 initialize(WebViewDelegateFactory.createProxyDelegate(delegate)); 112 initialize(WebViewDelegateFactory.createProxyDelegate(delegate));
113 } 113 }
114 114
115 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") 115 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
116 private void initialize(WebViewDelegate webViewDelegate) { 116 private void initialize(WebViewDelegate webViewDelegate) {
117 mWebViewDelegate = webViewDelegate; 117 mWebViewDelegate = webViewDelegate;
118 118
119 // WebView needs to make sure to always use the wrapped application cont ext. 119 // WebView needs to make sure to always use the wrapped application cont ext.
120 ContextUtils.initApplicationContext( 120 ContextUtils.initApplicationContext(
121 ResourcesContextWrapperFactory.get(mWebViewDelegate.getApplicati on())); 121 ResourcesContextWrapperFactory.get(
122 mWebViewDelegate.getApplication().getApplicationContext( )));
122 123
123 if (isBuildDebuggable()) { 124 if (isBuildDebuggable()) {
124 // Suppress the StrictMode violation as this codepath is only hit on debugglable builds. 125 // Suppress the StrictMode violation as this codepath is only hit on debuggable builds.
125 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads( ); 126 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads( );
126 CommandLine.initFromFile(COMMAND_LINE_FILE); 127 CommandLine.initFromFile(COMMAND_LINE_FILE);
127 StrictMode.setThreadPolicy(oldPolicy); 128 StrictMode.setThreadPolicy(oldPolicy);
128 } else { 129 } else {
129 CommandLine.init(null); 130 CommandLine.init(null);
130 } 131 }
131 132
132 ThreadUtils.setWillOverrideUiThread(); 133 ThreadUtils.setWillOverrideUiThread();
133 // Load chromium library. 134 // Load chromium library.
134 AwBrowserProcess.loadLibrary(ContextUtils.getApplicationContext()); 135 AwBrowserProcess.loadLibrary();
135 136
136 final PackageInfo packageInfo = WebViewFactory.getLoadedPackageInfo(); 137 final PackageInfo packageInfo = WebViewFactory.getLoadedPackageInfo();
137 138
138 // Load glue-layer support library. 139 // Load glue-layer support library.
139 System.loadLibrary("webviewchromium_plat_support"); 140 System.loadLibrary("webviewchromium_plat_support");
140 141
141 // Use shared preference to check for package downgrade. 142 // Use shared preference to check for package downgrade.
142 mWebViewPrefs = mWebViewDelegate.getApplication().getSharedPreferences( 143 mWebViewPrefs = ContextUtils.getApplicationContext().getSharedPreference s(
143 CHROMIUM_PREFS_NAME, Context.MODE_PRIVATE); 144 CHROMIUM_PREFS_NAME, Context.MODE_PRIVATE);
144 int lastVersion = mWebViewPrefs.getInt(VERSION_CODE_PREF, 0); 145 int lastVersion = mWebViewPrefs.getInt(VERSION_CODE_PREF, 0);
145 int currentVersion = packageInfo.versionCode; 146 int currentVersion = packageInfo.versionCode;
146 if (!versionCodeGE(currentVersion, lastVersion)) { 147 if (!versionCodeGE(currentVersion, lastVersion)) {
147 // The WebView package has been downgraded since we last ran in this application. 148 // The WebView package has been downgraded since we last ran in this application.
148 // Delete the WebView data directory's contents. 149 // Delete the WebView data directory's contents.
149 String dataDir = PathUtils.getDataDirectory(mWebViewDelegate.getAppl ication()); 150 String dataDir = PathUtils.getDataDirectory(ContextUtils.getApplicat ionContext());
150 Log.i(TAG, "WebView package downgraded from " + lastVersion + " to " + currentVersion 151 Log.i(TAG, "WebView package downgraded from " + lastVersion + " to " + currentVersion
151 + "; deleting contents of " + dataDir); 152 + "; deleting contents of " + dataDir);
152 deleteContents(new File(dataDir)); 153 deleteContents(new File(dataDir));
153 } 154 }
154 if (lastVersion != currentVersion) { 155 if (lastVersion != currentVersion) {
155 mWebViewPrefs.edit().putInt(VERSION_CODE_PREF, currentVersion).apply (); 156 mWebViewPrefs.edit().putInt(VERSION_CODE_PREF, currentVersion).apply ();
156 } 157 }
157 // Now safe to use WebView data directory. 158 // Now safe to use WebView data directory.
158 } 159 }
159 160
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 PathService.override(DIR_RESOURCE_PAKS_ANDROID, "/system/framework/webvi ew/paks"); 280 PathService.override(DIR_RESOURCE_PAKS_ANDROID, "/system/framework/webvi ew/paks");
280 281
281 // Make sure that ResourceProvider is initialized before starting the br owser process. 282 // Make sure that ResourceProvider is initialized before starting the br owser process.
282 final String webViewPackageName = WebViewFactory.getLoadedPackageInfo(). packageName; 283 final String webViewPackageName = WebViewFactory.getLoadedPackageInfo(). packageName;
283 setUpResources(webViewPackageName, context); 284 setUpResources(webViewPackageName, context);
284 ResourceBundle.initializeLocalePaks(context, R.array.locale_paks); 285 ResourceBundle.initializeLocalePaks(context, R.array.locale_paks);
285 initPlatSupportLibrary(); 286 initPlatSupportLibrary();
286 initNetworkChangeNotifier(context); 287 initNetworkChangeNotifier(context);
287 final int extraBindFlags = 0; 288 final int extraBindFlags = 0;
288 AwBrowserProcess.configureChildProcessLauncher(webViewPackageName, extra BindFlags); 289 AwBrowserProcess.configureChildProcessLauncher(webViewPackageName, extra BindFlags);
289 AwBrowserProcess.start(context); 290 AwBrowserProcess.start();
290 291
291 if (isBuildDebuggable()) { 292 if (isBuildDebuggable()) {
292 setWebContentsDebuggingEnabled(true); 293 setWebContentsDebuggingEnabled(true);
293 } 294 }
294 295
295 TraceEvent.setATraceEnabled(mWebViewDelegate.isTraceTagEnabled()); 296 TraceEvent.setATraceEnabled(mWebViewDelegate.isTraceTagEnabled());
296 mWebViewDelegate.setOnTraceEnabledChangeListener( 297 mWebViewDelegate.setOnTraceEnabledChangeListener(
297 new WebViewDelegate.OnTraceEnabledChangeListener() { 298 new WebViewDelegate.OnTraceEnabledChangeListener() {
298 @Override 299 @Override
299 public void onTraceEnabledChange(boolean enabled) { 300 public void onTraceEnabledChange(boolean enabled) {
300 TraceEvent.setATraceEnabled(enabled); 301 TraceEvent.setATraceEnabled(enabled);
301 } 302 }
302 }); 303 });
303 mStarted = true; 304 mStarted = true;
304 305
305 for (WeakReference<WebViewChromium> wvc : mWebViewsToStart) { 306 for (WeakReference<WebViewChromium> wvc : mWebViewsToStart) {
306 WebViewChromium w = wvc.get(); 307 WebViewChromium w = wvc.get();
307 if (w != null) { 308 if (w != null) {
308 w.startYourEngine(); 309 w.startYourEngine();
309 } 310 }
310 } 311 }
311 mWebViewsToStart.clear(); 312 mWebViewsToStart.clear();
312 mWebViewsToStart = null; 313 mWebViewsToStart = null;
313 314
314 // Start listening for data reduction proxy setting changes. 315 // Start listening for data reduction proxy setting changes.
315 mProxyManager = new AwDataReductionProxyManager(); 316 mProxyManager = new AwDataReductionProxyManager();
316 mProxyManager.start(mWebViewDelegate.getApplication()); 317 mProxyManager.start(ContextUtils.getApplicationContext());
317 } 318 }
318 319
319 boolean hasStarted() { 320 boolean hasStarted() {
320 return mStarted; 321 return mStarted;
321 } 322 }
322 323
323 void startYourEngines(boolean onMainThread) { 324 void startYourEngines(boolean onMainThread) {
324 synchronized (mLock) { 325 synchronized (mLock) {
325 ensureChromiumStartedLocked(onMainThread); 326 ensureChromiumStartedLocked(onMainThread);
326 } 327 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 browserContext.getHttpAuthDatabase(context)); 486 browserContext.getHttpAuthDatabase(context));
486 } 487 }
487 } 488 }
488 return mWebViewDatabase; 489 return mWebViewDatabase;
489 } 490 }
490 491
491 WebViewDelegate getWebViewDelegate() { 492 WebViewDelegate getWebViewDelegate() {
492 return mWebViewDelegate; 493 return mWebViewDelegate;
493 } 494 }
494 } 495 }
OLDNEW
« no previous file with comments | « no previous file | android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698