Chromium Code Reviews| Index: android_webview/browser/net/aw_url_request_context_getter.cc |
| diff --git a/android_webview/browser/net/aw_url_request_context_getter.cc b/android_webview/browser/net/aw_url_request_context_getter.cc |
| index 4de5a3317aba6a0953a9c827aba21c61b60811e4..ad3890d5a657cc9546c09a8d2a205d875724a904 100644 |
| --- a/android_webview/browser/net/aw_url_request_context_getter.cc |
| +++ b/android_webview/browser/net/aw_url_request_context_getter.cc |
| @@ -14,8 +14,10 @@ |
| #include "android_webview/browser/net/aw_url_request_job_factory.h" |
| #include "android_webview/browser/net/init_native_callback.h" |
| #include "android_webview/common/aw_content_client.h" |
| +#include "android_webview/common/pref_names.h" |
| #include "base/bind.h" |
| #include "base/command_line.h" |
| +#include "base/prefs/pref_service.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/threading/sequenced_worker_pool.h" |
| #include "base/threading/worker_pool.h" |
| @@ -31,8 +33,10 @@ |
| #include "net/base/cache_type.h" |
| #include "net/cookies/cookie_store.h" |
| #include "net/dns/mapped_host_resolver.h" |
| +#include "net/http/http_auth_filter.h" |
| #include "net/http/http_cache.h" |
| #include "net/http/http_stream_factory.h" |
| +#include "net/http/url_security_manager.h" |
| #include "net/log/net_log.h" |
| #include "net/proxy/proxy_service.h" |
| #include "net/socket/next_proto.h" |
| @@ -51,21 +55,21 @@ namespace android_webview { |
| namespace { |
| -void ApplyCmdlineOverridesToURLRequestContextBuilder( |
| - net::URLRequestContextBuilder* builder) { |
| +scoped_ptr<net::MappedHostResolver> CreateCmdLineConfiguredHostResolver() { |
| + // If hostname remappings were specified on the command-line, layer these |
| + // rules on top of the real host resolver. This allows forwarding all |
| + // requests through a designated test server. |
| + scoped_ptr<net::MappedHostResolver> host_resolver(new net::MappedHostResolver( |
| + net::HostResolver::CreateDefaultResolver(nullptr))); |
| + |
| const base::CommandLine& command_line = |
| *base::CommandLine::ForCurrentProcess(); |
| if (command_line.HasSwitch(switches::kHostResolverRules)) { |
| - // If hostname remappings were specified on the command-line, layer these |
| - // rules on top of the real host resolver. This allows forwarding all |
| - // requests through a designated test server. |
| - scoped_ptr<net::MappedHostResolver> host_resolver( |
| - new net::MappedHostResolver( |
| - net::HostResolver::CreateDefaultResolver(NULL))); |
| host_resolver->SetRulesFromString( |
| command_line.GetSwitchValueASCII(switches::kHostResolverRules)); |
| - builder->set_host_resolver(host_resolver.Pass()); |
| } |
| + |
| + return host_resolver; |
| } |
| void ApplyCmdlineOverridesToNetworkSessionParams( |
| @@ -179,13 +183,19 @@ scoped_ptr<net::URLRequestJobFactory> CreateJobFactory( |
| } // namespace |
| AwURLRequestContextGetter::AwURLRequestContextGetter( |
| - const base::FilePath& cache_path, net::CookieStore* cookie_store, |
| - scoped_ptr<net::ProxyConfigService> config_service) |
| + const base::FilePath& cache_path, |
| + net::CookieStore* cookie_store, |
| + scoped_ptr<net::ProxyConfigService> config_service, |
| + PrefService* user_pref_service) |
| : cache_path_(cache_path), |
| net_log_(new net::NetLog()), |
| proxy_config_service_(config_service.Pass()), |
| cookie_store_(cookie_store), |
| - http_user_agent_settings_(new AwHttpUserAgentSettings()) { |
| + http_user_agent_settings_(new AwHttpUserAgentSettings()), |
| + auth_android_negotiate_account_type_(user_pref_service->GetString( |
| + prefs::kAuthAndroidNegotiateAccountType)), |
| + auth_server_whitelist_( |
| + user_pref_service->GetString(prefs::kAuthServerWhitelist)) { |
| // CreateSystemProxyConfigService for Android must be called on main thread. |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| } |
| @@ -198,6 +208,8 @@ void AwURLRequestContextGetter::InitializeURLRequestContext() { |
| DCHECK(!url_request_context_); |
| net::URLRequestContextBuilder builder; |
| + scoped_ptr<net::MappedHostResolver> host_resolver( |
| + CreateCmdLineConfiguredHostResolver()); |
|
sgurun-gerrit only
2015/11/13 08:43:51
move creation below, right before where it is used
dgn
2015/11/25 00:27:15
Done.
|
| scoped_ptr<AwNetworkDelegate> aw_network_delegate(new AwNetworkDelegate()); |
| AwBrowserContext* browser_context = AwBrowserContext::GetDefault(); |
| @@ -220,7 +232,10 @@ void AwURLRequestContextGetter::InitializeURLRequestContext() { |
| proxy_config_service_.Pass(), net_log_.get())); |
| builder.set_net_log(net_log_.get()); |
| builder.SetCookieAndChannelIdStores(cookie_store_, NULL); |
| - ApplyCmdlineOverridesToURLRequestContextBuilder(&builder); |
| + builder.add_http_auth_handler_factory( |
|
sgurun-gerrit only
2015/11/13 08:43:51
the documentation for add_http_auth_handler_factor
dgn
2015/11/13 12:37:07
We do call Build(), line 240. The comment is right
sgurun-gerrit only
2015/11/18 02:23:28
sure, builder.build() needs to be called for any u
|
| + "negotiate", |
| + CreateNegotiateAuthHandlerFactory(host_resolver.get()).release()); |
| + builder.set_host_resolver(host_resolver.Pass()); |
| url_request_context_ = builder.Build().Pass(); |
| // TODO(mnaganov): Fix URLRequestContextBuilder to use proper threads. |
| @@ -284,4 +299,26 @@ void AwURLRequestContextGetter::SetKeyOnIO(const std::string& key) { |
| request_options()->SetKeyOnIO(key); |
| } |
| +scoped_ptr<net::HttpAuthHandlerNegotiate::Factory> |
| +AwURLRequestContextGetter::CreateNegotiateAuthHandlerFactory( |
| + net::HostResolver* resolver) { |
| + net::HttpAuthFilterWhitelist* auth_filter_default_credentials = nullptr; |
| + if (!auth_server_whitelist_.empty()) { |
| + auth_filter_default_credentials = |
| + new net::HttpAuthFilterWhitelist(auth_server_whitelist_); |
| + } |
| + |
| + url_security_manager_.reset(net::URLSecurityManager::Create( |
| + auth_filter_default_credentials, nullptr /*auth_filter_delegate*/)); |
| + |
| + DCHECK(resolver); |
|
sgurun-gerrit only
2015/11/13 08:43:51
looks like this check is in a weird place. Either
dgn
2015/11/25 00:27:14
Done.
|
| + scoped_ptr<net::HttpAuthHandlerNegotiate::Factory> negotiate_factory( |
| + new net::HttpAuthHandlerNegotiate::Factory()); |
| + negotiate_factory->set_library(&auth_android_negotiate_account_type_); |
| + negotiate_factory->set_host_resolver(resolver); |
| + negotiate_factory->set_url_security_manager(url_security_manager_.get()); |
| + |
| + return negotiate_factory; |
| +} |
| + |
| } // namespace android_webview |