OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "android_webview/browser/net/aw_url_request_context_getter.h" | 5 #include "android_webview/browser/net/aw_url_request_context_getter.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "android_webview/browser/aw_browser_context.h" | 10 #include "android_webview/browser/aw_browser_context.h" |
11 #include "android_webview/browser/aw_content_browser_client.h" | 11 #include "android_webview/browser/aw_content_browser_client.h" |
12 #include "android_webview/browser/net/aw_cookie_store_wrapper.h" | 12 #include "android_webview/browser/net/aw_cookie_store_wrapper.h" |
13 #include "android_webview/browser/net/aw_http_user_agent_settings.h" | 13 #include "android_webview/browser/net/aw_http_user_agent_settings.h" |
14 #include "android_webview/browser/net/aw_network_delegate.h" | 14 #include "android_webview/browser/net/aw_network_delegate.h" |
15 #include "android_webview/browser/net/aw_request_interceptor.h" | 15 #include "android_webview/browser/net/aw_request_interceptor.h" |
16 #include "android_webview/browser/net/aw_url_request_job_factory.h" | 16 #include "android_webview/browser/net/aw_url_request_job_factory.h" |
17 #include "android_webview/browser/net/init_native_callback.h" | 17 #include "android_webview/browser/net/init_native_callback.h" |
18 #include "android_webview/browser/net/token_binding_manager.h" | 18 #include "android_webview/browser/net/token_binding_manager.h" |
19 #include "android_webview/common/aw_content_client.h" | 19 #include "android_webview/common/aw_content_client.h" |
20 #include "base/bind.h" | 20 #include "base/bind.h" |
21 #include "base/command_line.h" | 21 #include "base/command_line.h" |
22 #include "base/files/file_path.h" | 22 #include "base/files/file_path.h" |
23 #include "base/memory/ptr_util.h" | 23 #include "base/memory/ptr_util.h" |
24 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
25 #include "base/threading/sequenced_worker_pool.h" | 25 #include "base/threading/sequenced_worker_pool.h" |
26 #include "base/threading/worker_pool.h" | 26 #include "base/threading/worker_pool.h" |
27 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d
ata.h" | |
28 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw
ork_delegate.h" | |
29 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ
est_options.h" | |
30 #include "components/network_session_configurator/switches.h" | 27 #include "components/network_session_configurator/switches.h" |
31 #include "components/prefs/pref_service.h" | 28 #include "components/prefs/pref_service.h" |
32 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/content_browser_client.h" | 30 #include "content/public/browser/content_browser_client.h" |
34 #include "content/public/browser/cookie_store_factory.h" | 31 #include "content/public/browser/cookie_store_factory.h" |
35 #include "content/public/common/content_client.h" | 32 #include "content/public/common/content_client.h" |
36 #include "content/public/common/content_switches.h" | 33 #include "content/public/common/content_switches.h" |
37 #include "content/public/common/url_constants.h" | 34 #include "content/public/common/url_constants.h" |
38 #include "net/base/cache_type.h" | 35 #include "net/base/cache_type.h" |
39 #include "net/cookies/cookie_store.h" | 36 #include "net/cookies/cookie_store.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 } | 195 } |
199 | 196 |
200 AwURLRequestContextGetter::~AwURLRequestContextGetter() { | 197 AwURLRequestContextGetter::~AwURLRequestContextGetter() { |
201 } | 198 } |
202 | 199 |
203 void AwURLRequestContextGetter::InitializeURLRequestContext() { | 200 void AwURLRequestContextGetter::InitializeURLRequestContext() { |
204 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 201 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
205 DCHECK(!url_request_context_); | 202 DCHECK(!url_request_context_); |
206 | 203 |
207 net::URLRequestContextBuilder builder; | 204 net::URLRequestContextBuilder builder; |
208 std::unique_ptr<AwNetworkDelegate> aw_network_delegate( | |
209 new AwNetworkDelegate()); | |
210 | 205 |
211 AwBrowserContext* browser_context = AwBrowserContext::GetDefault(); | 206 AwBrowserContext* browser_context = AwBrowserContext::GetDefault(); |
212 DCHECK(browser_context); | 207 DCHECK(browser_context); |
213 | 208 |
214 builder.set_network_delegate( | 209 builder.set_network_delegate(base::WrapUnique(new AwNetworkDelegate())); |
215 browser_context->GetDataReductionProxyIOData()->CreateNetworkDelegate( | |
216 std::move(aw_network_delegate), | |
217 false /* No UMA is produced to track bypasses. */)); | |
218 #if !defined(DISABLE_FTP_SUPPORT) | 210 #if !defined(DISABLE_FTP_SUPPORT) |
219 builder.set_ftp_enabled(false); // Android WebView does not support ftp yet. | 211 builder.set_ftp_enabled(false); // Android WebView does not support ftp yet. |
220 #endif | 212 #endif |
221 DCHECK(proxy_config_service_.get()); | 213 DCHECK(proxy_config_service_.get()); |
222 std::unique_ptr<net::ChannelIDService> channel_id_service; | 214 std::unique_ptr<net::ChannelIDService> channel_id_service; |
223 if (TokenBindingManager::GetInstance()->is_enabled()) { | 215 if (TokenBindingManager::GetInstance()->is_enabled()) { |
224 base::FilePath channel_id_path = | 216 base::FilePath channel_id_path = |
225 browser_context->GetPath().Append(kChannelIDFilename); | 217 browser_context->GetPath().Append(kChannelIDFilename); |
226 scoped_refptr<net::SQLiteChannelIDStore> channel_id_db; | 218 scoped_refptr<net::SQLiteChannelIDStore> channel_id_db; |
227 channel_id_db = new net::SQLiteChannelIDStore( | 219 channel_id_db = new net::SQLiteChannelIDStore( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 net::HostResolver::CreateDefaultResolver(nullptr))); | 256 net::HostResolver::CreateDefaultResolver(nullptr))); |
265 ApplyCmdlineOverridesToHostResolver(host_resolver.get()); | 257 ApplyCmdlineOverridesToHostResolver(host_resolver.get()); |
266 builder.SetHttpAuthHandlerFactory( | 258 builder.SetHttpAuthHandlerFactory( |
267 CreateAuthHandlerFactory(host_resolver.get())); | 259 CreateAuthHandlerFactory(host_resolver.get())); |
268 builder.set_host_resolver(std::move(host_resolver)); | 260 builder.set_host_resolver(std::move(host_resolver)); |
269 | 261 |
270 url_request_context_ = builder.Build(); | 262 url_request_context_ = builder.Build(); |
271 | 263 |
272 job_factory_ = | 264 job_factory_ = |
273 CreateJobFactory(&protocol_handlers_, std::move(request_interceptors_)); | 265 CreateJobFactory(&protocol_handlers_, std::move(request_interceptors_)); |
274 job_factory_.reset(new net::URLRequestInterceptingJobFactory( | |
275 std::move(job_factory_), | |
276 browser_context->GetDataReductionProxyIOData()->CreateInterceptor())); | |
277 url_request_context_->set_job_factory(job_factory_.get()); | 266 url_request_context_->set_job_factory(job_factory_.get()); |
278 url_request_context_->set_http_user_agent_settings( | 267 url_request_context_->set_http_user_agent_settings( |
279 http_user_agent_settings_.get()); | 268 http_user_agent_settings_.get()); |
280 } | 269 } |
281 | 270 |
282 net::URLRequestContext* AwURLRequestContextGetter::GetURLRequestContext() { | 271 net::URLRequestContext* AwURLRequestContextGetter::GetURLRequestContext() { |
283 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 272 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
284 if (!url_request_context_) | 273 if (!url_request_context_) |
285 InitializeURLRequestContext(); | 274 InitializeURLRequestContext(); |
286 | 275 |
287 return url_request_context_.get(); | 276 return url_request_context_.get(); |
288 } | 277 } |
289 | 278 |
290 scoped_refptr<base::SingleThreadTaskRunner> | 279 scoped_refptr<base::SingleThreadTaskRunner> |
291 AwURLRequestContextGetter::GetNetworkTaskRunner() const { | 280 AwURLRequestContextGetter::GetNetworkTaskRunner() const { |
292 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 281 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
293 } | 282 } |
294 | 283 |
295 void AwURLRequestContextGetter::SetHandlersAndInterceptors( | 284 void AwURLRequestContextGetter::SetHandlersAndInterceptors( |
296 content::ProtocolHandlerMap* protocol_handlers, | 285 content::ProtocolHandlerMap* protocol_handlers, |
297 content::URLRequestInterceptorScopedVector request_interceptors) { | 286 content::URLRequestInterceptorScopedVector request_interceptors) { |
298 std::swap(protocol_handlers_, *protocol_handlers); | 287 std::swap(protocol_handlers_, *protocol_handlers); |
299 request_interceptors_.swap(request_interceptors); | 288 request_interceptors_.swap(request_interceptors); |
300 } | 289 } |
301 | 290 |
302 net::NetLog* AwURLRequestContextGetter::GetNetLog() { | 291 net::NetLog* AwURLRequestContextGetter::GetNetLog() { |
303 return net_log_.get(); | 292 return net_log_.get(); |
304 } | 293 } |
305 | 294 |
306 void AwURLRequestContextGetter::SetKeyOnIO(const std::string& key) { | |
307 DCHECK(AwBrowserContext::GetDefault()->GetDataReductionProxyIOData()); | |
308 AwBrowserContext::GetDefault()->GetDataReductionProxyIOData()-> | |
309 request_options()->SetKeyOnIO(key); | |
310 } | |
311 | |
312 std::unique_ptr<net::HttpAuthHandlerFactory> | 295 std::unique_ptr<net::HttpAuthHandlerFactory> |
313 AwURLRequestContextGetter::CreateAuthHandlerFactory( | 296 AwURLRequestContextGetter::CreateAuthHandlerFactory( |
314 net::HostResolver* resolver) { | 297 net::HostResolver* resolver) { |
315 DCHECK(resolver); | 298 DCHECK(resolver); |
316 | 299 |
317 // In Chrome this is configurable via the AuthSchemes policy. For WebView | 300 // In Chrome this is configurable via the AuthSchemes policy. For WebView |
318 // there is no interest to have it available so far. | 301 // there is no interest to have it available so far. |
319 std::vector<std::string> supported_schemes = {"basic", "digest", "ntlm", | 302 std::vector<std::string> supported_schemes = {"basic", "digest", "ntlm", |
320 "negotiate"}; | 303 "negotiate"}; |
321 http_auth_preferences_.reset(new net::HttpAuthPreferences(supported_schemes)); | 304 http_auth_preferences_.reset(new net::HttpAuthPreferences(supported_schemes)); |
322 | 305 |
323 UpdateServerWhitelist(); | 306 UpdateServerWhitelist(); |
324 UpdateAndroidAuthNegotiateAccountType(); | 307 UpdateAndroidAuthNegotiateAccountType(); |
325 | 308 |
326 return net::HttpAuthHandlerRegistryFactory::Create( | 309 return net::HttpAuthHandlerRegistryFactory::Create( |
327 http_auth_preferences_.get(), resolver); | 310 http_auth_preferences_.get(), resolver); |
328 } | 311 } |
329 | 312 |
330 void AwURLRequestContextGetter::UpdateServerWhitelist() { | 313 void AwURLRequestContextGetter::UpdateServerWhitelist() { |
331 http_auth_preferences_->set_server_whitelist( | 314 http_auth_preferences_->set_server_whitelist( |
332 auth_server_whitelist_.GetValue()); | 315 auth_server_whitelist_.GetValue()); |
333 } | 316 } |
334 | 317 |
335 void AwURLRequestContextGetter::UpdateAndroidAuthNegotiateAccountType() { | 318 void AwURLRequestContextGetter::UpdateAndroidAuthNegotiateAccountType() { |
336 http_auth_preferences_->set_auth_android_negotiate_account_type( | 319 http_auth_preferences_->set_auth_android_negotiate_account_type( |
337 auth_android_negotiate_account_type_.GetValue()); | 320 auth_android_negotiate_account_type_.GetValue()); |
338 } | 321 } |
339 | 322 |
340 } // namespace android_webview | 323 } // namespace android_webview |
OLD | NEW |