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