| 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" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #include "net/url_request/url_request_intercepting_job_factory.h" | 51 #include "net/url_request/url_request_intercepting_job_factory.h" |
| 52 #include "net/url_request/url_request_interceptor.h" | 52 #include "net/url_request/url_request_interceptor.h" |
| 53 | 53 |
| 54 using content::BrowserThread; | 54 using content::BrowserThread; |
| 55 | 55 |
| 56 namespace android_webview { | 56 namespace android_webview { |
| 57 | 57 |
| 58 | 58 |
| 59 namespace { | 59 namespace { |
| 60 | 60 |
| 61 #if DCHECK_IS_ON() | |
| 62 bool g_created_url_request_context_builder = false; | |
| 63 #endif | |
| 64 // On apps targeting API level O or later, check cleartext is enforced. | |
| 65 bool g_check_cleartext_permitted = false; | |
| 66 | |
| 67 | |
| 68 const base::FilePath::CharType kChannelIDFilename[] = "Origin Bound Certs"; | 61 const base::FilePath::CharType kChannelIDFilename[] = "Origin Bound Certs"; |
| 69 const char kProxyServerSwitch[] = "proxy-server"; | 62 const char kProxyServerSwitch[] = "proxy-server"; |
| 70 | 63 |
| 71 void ApplyCmdlineOverridesToHostResolver( | 64 void ApplyCmdlineOverridesToHostResolver( |
| 72 net::MappedHostResolver* host_resolver) { | 65 net::MappedHostResolver* host_resolver) { |
| 73 const base::CommandLine& command_line = | 66 const base::CommandLine& command_line = |
| 74 *base::CommandLine::ForCurrentProcess(); | 67 *base::CommandLine::ForCurrentProcess(); |
| 75 if (command_line.HasSwitch(switches::kHostResolverRules)) { | 68 if (command_line.HasSwitch(switches::kHostResolverRules)) { |
| 76 // If hostname remappings were specified on the command-line, layer these | 69 // If hostname remappings were specified on the command-line, layer these |
| 77 // rules on top of the real host resolver. This allows forwarding all | 70 // rules on top of the real host resolver. This allows forwarding all |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 255 |
| 263 std::unique_ptr<net::MappedHostResolver> host_resolver( | 256 std::unique_ptr<net::MappedHostResolver> host_resolver( |
| 264 new net::MappedHostResolver( | 257 new net::MappedHostResolver( |
| 265 net::HostResolver::CreateDefaultResolver(nullptr))); | 258 net::HostResolver::CreateDefaultResolver(nullptr))); |
| 266 ApplyCmdlineOverridesToHostResolver(host_resolver.get()); | 259 ApplyCmdlineOverridesToHostResolver(host_resolver.get()); |
| 267 builder.SetHttpAuthHandlerFactory( | 260 builder.SetHttpAuthHandlerFactory( |
| 268 CreateAuthHandlerFactory(host_resolver.get())); | 261 CreateAuthHandlerFactory(host_resolver.get())); |
| 269 builder.set_host_resolver(std::move(host_resolver)); | 262 builder.set_host_resolver(std::move(host_resolver)); |
| 270 | 263 |
| 271 url_request_context_ = builder.Build(); | 264 url_request_context_ = builder.Build(); |
| 272 #if DCHECK_IS_ON() | |
| 273 g_created_url_request_context_builder = true; | |
| 274 #endif | |
| 275 url_request_context_->set_check_cleartext_permitted( | |
| 276 g_check_cleartext_permitted); | |
| 277 | 265 |
| 278 job_factory_ = | 266 job_factory_ = |
| 279 CreateJobFactory(&protocol_handlers_, std::move(request_interceptors_)); | 267 CreateJobFactory(&protocol_handlers_, std::move(request_interceptors_)); |
| 280 url_request_context_->set_job_factory(job_factory_.get()); | 268 url_request_context_->set_job_factory(job_factory_.get()); |
| 281 url_request_context_->set_http_user_agent_settings( | 269 url_request_context_->set_http_user_agent_settings( |
| 282 http_user_agent_settings_.get()); | 270 http_user_agent_settings_.get()); |
| 283 } | 271 } |
| 284 | 272 |
| 285 net::URLRequestContext* AwURLRequestContextGetter::GetURLRequestContext() { | 273 net::URLRequestContext* AwURLRequestContextGetter::GetURLRequestContext() { |
| 286 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 274 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 299 content::ProtocolHandlerMap* protocol_handlers, | 287 content::ProtocolHandlerMap* protocol_handlers, |
| 300 content::URLRequestInterceptorScopedVector request_interceptors) { | 288 content::URLRequestInterceptorScopedVector request_interceptors) { |
| 301 std::swap(protocol_handlers_, *protocol_handlers); | 289 std::swap(protocol_handlers_, *protocol_handlers); |
| 302 request_interceptors_.swap(request_interceptors); | 290 request_interceptors_.swap(request_interceptors); |
| 303 } | 291 } |
| 304 | 292 |
| 305 net::NetLog* AwURLRequestContextGetter::GetNetLog() { | 293 net::NetLog* AwURLRequestContextGetter::GetNetLog() { |
| 306 return net_log_.get(); | 294 return net_log_.get(); |
| 307 } | 295 } |
| 308 | 296 |
| 309 // static | |
| 310 void AwURLRequestContextGetter::set_check_cleartext_permitted(bool permitted) { | |
| 311 DCHECK(!g_created_url_request_context_builder); | |
| 312 g_check_cleartext_permitted = permitted; | |
| 313 } | |
| 314 | |
| 315 std::unique_ptr<net::HttpAuthHandlerFactory> | 297 std::unique_ptr<net::HttpAuthHandlerFactory> |
| 316 AwURLRequestContextGetter::CreateAuthHandlerFactory( | 298 AwURLRequestContextGetter::CreateAuthHandlerFactory( |
| 317 net::HostResolver* resolver) { | 299 net::HostResolver* resolver) { |
| 318 DCHECK(resolver); | 300 DCHECK(resolver); |
| 319 | 301 |
| 320 // In Chrome this is configurable via the AuthSchemes policy. For WebView | 302 // In Chrome this is configurable via the AuthSchemes policy. For WebView |
| 321 // there is no interest to have it available so far. | 303 // there is no interest to have it available so far. |
| 322 std::vector<std::string> supported_schemes = {"basic", "digest", "ntlm", | 304 std::vector<std::string> supported_schemes = {"basic", "digest", "ntlm", |
| 323 "negotiate"}; | 305 "negotiate"}; |
| 324 http_auth_preferences_.reset(new net::HttpAuthPreferences(supported_schemes)); | 306 http_auth_preferences_.reset(new net::HttpAuthPreferences(supported_schemes)); |
| 325 | 307 |
| 326 UpdateServerWhitelist(); | 308 UpdateServerWhitelist(); |
| 327 UpdateAndroidAuthNegotiateAccountType(); | 309 UpdateAndroidAuthNegotiateAccountType(); |
| 328 | 310 |
| 329 return net::HttpAuthHandlerRegistryFactory::Create( | 311 return net::HttpAuthHandlerRegistryFactory::Create( |
| 330 http_auth_preferences_.get(), resolver); | 312 http_auth_preferences_.get(), resolver); |
| 331 } | 313 } |
| 332 | 314 |
| 333 void AwURLRequestContextGetter::UpdateServerWhitelist() { | 315 void AwURLRequestContextGetter::UpdateServerWhitelist() { |
| 334 http_auth_preferences_->set_server_whitelist( | 316 http_auth_preferences_->set_server_whitelist( |
| 335 auth_server_whitelist_.GetValue()); | 317 auth_server_whitelist_.GetValue()); |
| 336 } | 318 } |
| 337 | 319 |
| 338 void AwURLRequestContextGetter::UpdateAndroidAuthNegotiateAccountType() { | 320 void AwURLRequestContextGetter::UpdateAndroidAuthNegotiateAccountType() { |
| 339 http_auth_preferences_->set_auth_android_negotiate_account_type( | 321 http_auth_preferences_->set_auth_android_negotiate_account_type( |
| 340 auth_android_negotiate_account_type_.GetValue()); | 322 auth_android_negotiate_account_type_.GetValue()); |
| 341 } | 323 } |
| 342 | 324 |
| 343 } // namespace android_webview | 325 } // namespace android_webview |
| OLD | NEW |