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

Side by Side Diff: android_webview/browser/net/aw_url_request_context_getter.cc

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

Powered by Google App Engine
This is Rietveld 408576698