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; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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(mWebViewDelegate.getApplicati on())); |
boliu
2016/06/16 21:09:46
came here to say should add getApplicationContext
Peter Wen
2016/06/16 21:29:03
Done.
| |
122 | 122 |
123 if (isBuildDebuggable()) { | 123 if (isBuildDebuggable()) { |
124 // Suppress the StrictMode violation as this codepath is only hit on debugglable builds. | 124 // Suppress the StrictMode violation as this codepath is only hit on debuggable builds. |
125 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads( ); | 125 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads( ); |
126 CommandLine.initFromFile(COMMAND_LINE_FILE); | 126 CommandLine.initFromFile(COMMAND_LINE_FILE); |
127 StrictMode.setThreadPolicy(oldPolicy); | 127 StrictMode.setThreadPolicy(oldPolicy); |
128 } else { | 128 } else { |
129 CommandLine.init(null); | 129 CommandLine.init(null); |
130 } | 130 } |
131 | 131 |
132 ThreadUtils.setWillOverrideUiThread(); | 132 ThreadUtils.setWillOverrideUiThread(); |
133 // Load chromium library. | 133 // Load chromium library. |
134 AwBrowserProcess.loadLibrary(ContextUtils.getApplicationContext()); | 134 AwBrowserProcess.loadLibrary(); |
135 | 135 |
136 final PackageInfo packageInfo = WebViewFactory.getLoadedPackageInfo(); | 136 final PackageInfo packageInfo = WebViewFactory.getLoadedPackageInfo(); |
137 | 137 |
138 // Load glue-layer support library. | 138 // Load glue-layer support library. |
139 System.loadLibrary("webviewchromium_plat_support"); | 139 System.loadLibrary("webviewchromium_plat_support"); |
140 | 140 |
141 // Use shared preference to check for package downgrade. | 141 // Use shared preference to check for package downgrade. |
142 mWebViewPrefs = mWebViewDelegate.getApplication().getSharedPreferences( | 142 mWebViewPrefs = ContextUtils.getApplicationContext().getSharedPreference s( |
143 CHROMIUM_PREFS_NAME, Context.MODE_PRIVATE); | 143 CHROMIUM_PREFS_NAME, Context.MODE_PRIVATE); |
144 int lastVersion = mWebViewPrefs.getInt(VERSION_CODE_PREF, 0); | 144 int lastVersion = mWebViewPrefs.getInt(VERSION_CODE_PREF, 0); |
145 int currentVersion = packageInfo.versionCode; | 145 int currentVersion = packageInfo.versionCode; |
146 if (!versionCodeGE(currentVersion, lastVersion)) { | 146 if (!versionCodeGE(currentVersion, lastVersion)) { |
147 // The WebView package has been downgraded since we last ran in this application. | 147 // The WebView package has been downgraded since we last ran in this application. |
148 // Delete the WebView data directory's contents. | 148 // Delete the WebView data directory's contents. |
149 String dataDir = PathUtils.getDataDirectory(mWebViewDelegate.getAppl ication()); | 149 String dataDir = PathUtils.getDataDirectory(ContextUtils.getApplicat ionContext()); |
150 Log.i(TAG, "WebView package downgraded from " + lastVersion + " to " + currentVersion | 150 Log.i(TAG, "WebView package downgraded from " + lastVersion + " to " + currentVersion |
151 + "; deleting contents of " + dataDir); | 151 + "; deleting contents of " + dataDir); |
152 deleteContents(new File(dataDir)); | 152 deleteContents(new File(dataDir)); |
153 } | 153 } |
154 if (lastVersion != currentVersion) { | 154 if (lastVersion != currentVersion) { |
155 mWebViewPrefs.edit().putInt(VERSION_CODE_PREF, currentVersion).apply (); | 155 mWebViewPrefs.edit().putInt(VERSION_CODE_PREF, currentVersion).apply (); |
156 } | 156 } |
157 // Now safe to use WebView data directory. | 157 // Now safe to use WebView data directory. |
158 } | 158 } |
159 | 159 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 PathService.override(DIR_RESOURCE_PAKS_ANDROID, "/system/framework/webvi ew/paks"); | 279 PathService.override(DIR_RESOURCE_PAKS_ANDROID, "/system/framework/webvi ew/paks"); |
280 | 280 |
281 // Make sure that ResourceProvider is initialized before starting the br owser process. | 281 // Make sure that ResourceProvider is initialized before starting the br owser process. |
282 final String webViewPackageName = WebViewFactory.getLoadedPackageInfo(). packageName; | 282 final String webViewPackageName = WebViewFactory.getLoadedPackageInfo(). packageName; |
283 setUpResources(webViewPackageName, context); | 283 setUpResources(webViewPackageName, context); |
284 ResourceBundle.initializeLocalePaks(context, R.array.locale_paks); | 284 ResourceBundle.initializeLocalePaks(context, R.array.locale_paks); |
285 initPlatSupportLibrary(); | 285 initPlatSupportLibrary(); |
286 initNetworkChangeNotifier(context); | 286 initNetworkChangeNotifier(context); |
287 final int extraBindFlags = 0; | 287 final int extraBindFlags = 0; |
288 AwBrowserProcess.configureChildProcessLauncher(webViewPackageName, extra BindFlags); | 288 AwBrowserProcess.configureChildProcessLauncher(webViewPackageName, extra BindFlags); |
289 AwBrowserProcess.start(context); | 289 AwBrowserProcess.start(); |
290 | 290 |
291 if (isBuildDebuggable()) { | 291 if (isBuildDebuggable()) { |
292 setWebContentsDebuggingEnabled(true); | 292 setWebContentsDebuggingEnabled(true); |
293 } | 293 } |
294 | 294 |
295 TraceEvent.setATraceEnabled(mWebViewDelegate.isTraceTagEnabled()); | 295 TraceEvent.setATraceEnabled(mWebViewDelegate.isTraceTagEnabled()); |
296 mWebViewDelegate.setOnTraceEnabledChangeListener( | 296 mWebViewDelegate.setOnTraceEnabledChangeListener( |
297 new WebViewDelegate.OnTraceEnabledChangeListener() { | 297 new WebViewDelegate.OnTraceEnabledChangeListener() { |
298 @Override | 298 @Override |
299 public void onTraceEnabledChange(boolean enabled) { | 299 public void onTraceEnabledChange(boolean enabled) { |
300 TraceEvent.setATraceEnabled(enabled); | 300 TraceEvent.setATraceEnabled(enabled); |
301 } | 301 } |
302 }); | 302 }); |
303 mStarted = true; | 303 mStarted = true; |
304 | 304 |
305 for (WeakReference<WebViewChromium> wvc : mWebViewsToStart) { | 305 for (WeakReference<WebViewChromium> wvc : mWebViewsToStart) { |
306 WebViewChromium w = wvc.get(); | 306 WebViewChromium w = wvc.get(); |
307 if (w != null) { | 307 if (w != null) { |
308 w.startYourEngine(); | 308 w.startYourEngine(); |
309 } | 309 } |
310 } | 310 } |
311 mWebViewsToStart.clear(); | 311 mWebViewsToStart.clear(); |
312 mWebViewsToStart = null; | 312 mWebViewsToStart = null; |
313 | 313 |
314 // Start listening for data reduction proxy setting changes. | 314 // Start listening for data reduction proxy setting changes. |
315 mProxyManager = new AwDataReductionProxyManager(); | 315 mProxyManager = new AwDataReductionProxyManager(); |
316 mProxyManager.start(mWebViewDelegate.getApplication()); | 316 mProxyManager.start(ContextUtils.getApplicationContext()); |
317 } | 317 } |
318 | 318 |
319 boolean hasStarted() { | 319 boolean hasStarted() { |
320 return mStarted; | 320 return mStarted; |
321 } | 321 } |
322 | 322 |
323 void startYourEngines(boolean onMainThread) { | 323 void startYourEngines(boolean onMainThread) { |
324 synchronized (mLock) { | 324 synchronized (mLock) { |
325 ensureChromiumStartedLocked(onMainThread); | 325 ensureChromiumStartedLocked(onMainThread); |
326 } | 326 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 browserContext.getHttpAuthDatabase(context)); | 485 browserContext.getHttpAuthDatabase(context)); |
486 } | 486 } |
487 } | 487 } |
488 return mWebViewDatabase; | 488 return mWebViewDatabase; |
489 } | 489 } |
490 | 490 |
491 WebViewDelegate getWebViewDelegate() { | 491 WebViewDelegate getWebViewDelegate() { |
492 return mWebViewDelegate; | 492 return mWebViewDelegate; |
493 } | 493 } |
494 } | 494 } |
OLD | NEW |