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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "android_webview/browser/aw_browser_context.h" | 9 #include "android_webview/browser/aw_browser_context.h" |
10 #include "android_webview/browser/aw_content_browser_client.h" | 10 #include "android_webview/browser/aw_content_browser_client.h" |
11 #include "android_webview/browser/net/aw_http_user_agent_settings.h" | 11 #include "android_webview/browser/net/aw_http_user_agent_settings.h" |
12 #include "android_webview/browser/net/aw_network_delegate.h" | 12 #include "android_webview/browser/net/aw_network_delegate.h" |
13 #include "android_webview/browser/net/aw_request_interceptor.h" | 13 #include "android_webview/browser/net/aw_request_interceptor.h" |
14 #include "android_webview/browser/net/aw_url_request_job_factory.h" | 14 #include "android_webview/browser/net/aw_url_request_job_factory.h" |
15 #include "android_webview/browser/net/init_native_callback.h" | 15 #include "android_webview/browser/net/init_native_callback.h" |
16 #include "android_webview/common/aw_content_client.h" | 16 #include "android_webview/common/aw_content_client.h" |
17 #include "base/bind.h" | 17 #include "base/bind.h" |
18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 19 #include "base/prefs/pref_service.h" |
19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
20 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
21 #include "base/threading/worker_pool.h" | 22 #include "base/threading/worker_pool.h" |
22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d
ata.h" | 23 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d
ata.h" |
23 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw
ork_delegate.h" | 24 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw
ork_delegate.h" |
24 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ
est_options.h" | 25 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ
est_options.h" |
25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/content_browser_client.h" | 27 #include "content/public/browser/content_browser_client.h" |
27 #include "content/public/browser/cookie_store_factory.h" | 28 #include "content/public/browser/cookie_store_factory.h" |
28 #include "content/public/common/content_client.h" | 29 #include "content/public/common/content_client.h" |
29 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
30 #include "content/public/common/url_constants.h" | 31 #include "content/public/common/url_constants.h" |
31 #include "net/base/cache_type.h" | 32 #include "net/base/cache_type.h" |
32 #include "net/cookies/cookie_store.h" | 33 #include "net/cookies/cookie_store.h" |
33 #include "net/dns/mapped_host_resolver.h" | 34 #include "net/dns/mapped_host_resolver.h" |
| 35 #include "net/http/http_auth_filter.h" |
| 36 #include "net/http/http_auth_handler_factory.h" |
34 #include "net/http/http_cache.h" | 37 #include "net/http/http_cache.h" |
35 #include "net/http/http_stream_factory.h" | 38 #include "net/http/http_stream_factory.h" |
| 39 #include "net/http/url_security_manager.h" |
36 #include "net/log/net_log.h" | 40 #include "net/log/net_log.h" |
37 #include "net/proxy/proxy_service.h" | 41 #include "net/proxy/proxy_service.h" |
38 #include "net/socket/next_proto.h" | 42 #include "net/socket/next_proto.h" |
39 #include "net/ssl/channel_id_service.h" | 43 #include "net/ssl/channel_id_service.h" |
40 #include "net/url_request/data_protocol_handler.h" | 44 #include "net/url_request/data_protocol_handler.h" |
41 #include "net/url_request/file_protocol_handler.h" | 45 #include "net/url_request/file_protocol_handler.h" |
42 #include "net/url_request/url_request_context.h" | 46 #include "net/url_request/url_request_context.h" |
43 #include "net/url_request/url_request_context_builder.h" | 47 #include "net/url_request/url_request_context_builder.h" |
44 #include "net/url_request/url_request_intercepting_job_factory.h" | 48 #include "net/url_request/url_request_intercepting_job_factory.h" |
45 #include "net/url_request/url_request_interceptor.h" | 49 #include "net/url_request/url_request_interceptor.h" |
46 | 50 |
47 using content::BrowserThread; | 51 using content::BrowserThread; |
48 | 52 |
49 namespace android_webview { | 53 namespace android_webview { |
50 | 54 |
51 | 55 |
52 namespace { | 56 namespace { |
53 | 57 |
54 void ApplyCmdlineOverridesToURLRequestContextBuilder( | 58 void ApplyCmdlineOverridesToHostResolver( |
55 net::URLRequestContextBuilder* builder) { | 59 net::MappedHostResolver* host_resolver) { |
56 const base::CommandLine& command_line = | 60 const base::CommandLine& command_line = |
57 *base::CommandLine::ForCurrentProcess(); | 61 *base::CommandLine::ForCurrentProcess(); |
58 if (command_line.HasSwitch(switches::kHostResolverRules)) { | 62 if (command_line.HasSwitch(switches::kHostResolverRules)) { |
59 // If hostname remappings were specified on the command-line, layer these | 63 // If hostname remappings were specified on the command-line, layer these |
60 // rules on top of the real host resolver. This allows forwarding all | 64 // rules on top of the real host resolver. This allows forwarding all |
61 // requests through a designated test server. | 65 // requests through a designated test server. |
62 scoped_ptr<net::MappedHostResolver> host_resolver( | |
63 new net::MappedHostResolver( | |
64 net::HostResolver::CreateDefaultResolver(NULL))); | |
65 host_resolver->SetRulesFromString( | 66 host_resolver->SetRulesFromString( |
66 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); | 67 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); |
67 builder->set_host_resolver(host_resolver.Pass()); | |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 void ApplyCmdlineOverridesToNetworkSessionParams( | 71 void ApplyCmdlineOverridesToNetworkSessionParams( |
72 net::URLRequestContextBuilder::HttpNetworkSessionParams* params) { | 72 net::URLRequestContextBuilder::HttpNetworkSessionParams* params) { |
73 int value; | 73 int value; |
74 const base::CommandLine& command_line = | 74 const base::CommandLine& command_line = |
75 *base::CommandLine::ForCurrentProcess(); | 75 *base::CommandLine::ForCurrentProcess(); |
76 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { | 76 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { |
77 base::StringToInt(command_line.GetSwitchValueASCII( | 77 base::StringToInt(command_line.GetSwitchValueASCII( |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 job_factory.Pass(), make_scoped_ptr(*i))); | 152 job_factory.Pass(), make_scoped_ptr(*i))); |
153 } | 153 } |
154 request_interceptors.weak_clear(); | 154 request_interceptors.weak_clear(); |
155 | 155 |
156 return job_factory.Pass(); | 156 return job_factory.Pass(); |
157 } | 157 } |
158 | 158 |
159 } // namespace | 159 } // namespace |
160 | 160 |
161 AwURLRequestContextGetter::AwURLRequestContextGetter( | 161 AwURLRequestContextGetter::AwURLRequestContextGetter( |
162 const base::FilePath& cache_path, net::CookieStore* cookie_store, | 162 const base::FilePath& cache_path, |
163 scoped_ptr<net::ProxyConfigService> config_service) | 163 net::CookieStore* cookie_store, |
| 164 scoped_ptr<net::ProxyConfigService> config_service, |
| 165 PrefService* user_pref_service) |
164 : cache_path_(cache_path), | 166 : cache_path_(cache_path), |
165 net_log_(new net::NetLog()), | 167 net_log_(new net::NetLog()), |
166 proxy_config_service_(config_service.Pass()), | 168 proxy_config_service_(config_service.Pass()), |
167 cookie_store_(cookie_store), | 169 cookie_store_(cookie_store), |
168 http_user_agent_settings_(new AwHttpUserAgentSettings()) { | 170 http_user_agent_settings_(new AwHttpUserAgentSettings()), |
| 171 auth_android_negotiate_account_type_(user_pref_service->GetString( |
| 172 prefs::kAuthAndroidNegotiateAccountType)), |
| 173 auth_server_whitelist_( |
| 174 user_pref_service->GetString(prefs::kAuthServerWhitelist)) { |
169 // CreateSystemProxyConfigService for Android must be called on main thread. | 175 // CreateSystemProxyConfigService for Android must be called on main thread. |
170 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 176 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
171 } | 177 } |
172 | 178 |
173 AwURLRequestContextGetter::~AwURLRequestContextGetter() { | 179 AwURLRequestContextGetter::~AwURLRequestContextGetter() { |
174 } | 180 } |
175 | 181 |
176 void AwURLRequestContextGetter::InitializeURLRequestContext() { | 182 void AwURLRequestContextGetter::InitializeURLRequestContext() { |
177 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 183 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
178 DCHECK(!url_request_context_); | 184 DCHECK(!url_request_context_); |
(...skipping 29 matching lines...) Expand all Loading... |
208 cache_params.path = cache_path_; | 214 cache_params.path = cache_path_; |
209 builder.EnableHttpCache(cache_params); | 215 builder.EnableHttpCache(cache_params); |
210 builder.SetFileTaskRunner( | 216 builder.SetFileTaskRunner( |
211 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | 217 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
212 | 218 |
213 net::URLRequestContextBuilder::HttpNetworkSessionParams | 219 net::URLRequestContextBuilder::HttpNetworkSessionParams |
214 network_session_params; | 220 network_session_params; |
215 ApplyCmdlineOverridesToNetworkSessionParams(&network_session_params); | 221 ApplyCmdlineOverridesToNetworkSessionParams(&network_session_params); |
216 builder.set_http_network_session_params(network_session_params); | 222 builder.set_http_network_session_params(network_session_params); |
217 builder.SetSpdyAndQuicEnabled(true, true); | 223 builder.SetSpdyAndQuicEnabled(true, true); |
218 ApplyCmdlineOverridesToURLRequestContextBuilder(&builder); | 224 |
| 225 scoped_ptr<net::MappedHostResolver> host_resolver(new net::MappedHostResolver( |
| 226 net::HostResolver::CreateDefaultResolver(nullptr))); |
| 227 ApplyCmdlineOverridesToHostResolver(host_resolver.get()); |
| 228 builder.add_http_auth_handler_factory( |
| 229 "negotiate", |
| 230 CreateNegotiateAuthHandlerFactory(host_resolver.get()).release()); |
| 231 builder.set_host_resolver(host_resolver.Pass()); |
| 232 |
219 url_request_context_ = builder.Build().Pass(); | 233 url_request_context_ = builder.Build().Pass(); |
220 | 234 |
221 job_factory_ = CreateJobFactory(&protocol_handlers_, | 235 job_factory_ = CreateJobFactory(&protocol_handlers_, |
222 request_interceptors_.Pass()); | 236 request_interceptors_.Pass()); |
223 job_factory_.reset(new net::URLRequestInterceptingJobFactory( | 237 job_factory_.reset(new net::URLRequestInterceptingJobFactory( |
224 job_factory_.Pass(), | 238 job_factory_.Pass(), |
225 browser_context->GetDataReductionProxyIOData()->CreateInterceptor())); | 239 browser_context->GetDataReductionProxyIOData()->CreateInterceptor())); |
226 url_request_context_->set_job_factory(job_factory_.get()); | 240 url_request_context_->set_job_factory(job_factory_.get()); |
227 url_request_context_->set_http_user_agent_settings( | 241 url_request_context_->set_http_user_agent_settings( |
228 http_user_agent_settings_.get()); | 242 http_user_agent_settings_.get()); |
(...skipping 22 matching lines...) Expand all Loading... |
251 net::NetLog* AwURLRequestContextGetter::GetNetLog() { | 265 net::NetLog* AwURLRequestContextGetter::GetNetLog() { |
252 return net_log_.get(); | 266 return net_log_.get(); |
253 } | 267 } |
254 | 268 |
255 void AwURLRequestContextGetter::SetKeyOnIO(const std::string& key) { | 269 void AwURLRequestContextGetter::SetKeyOnIO(const std::string& key) { |
256 DCHECK(AwBrowserContext::GetDefault()->GetDataReductionProxyIOData()); | 270 DCHECK(AwBrowserContext::GetDefault()->GetDataReductionProxyIOData()); |
257 AwBrowserContext::GetDefault()->GetDataReductionProxyIOData()-> | 271 AwBrowserContext::GetDefault()->GetDataReductionProxyIOData()-> |
258 request_options()->SetKeyOnIO(key); | 272 request_options()->SetKeyOnIO(key); |
259 } | 273 } |
260 | 274 |
| 275 scoped_ptr<net::HttpAuthHandlerFactory> |
| 276 AwURLRequestContextGetter::CreateNegotiateAuthHandlerFactory( |
| 277 net::HostResolver* resolver) { |
| 278 DCHECK(resolver); |
| 279 |
| 280 net::HttpAuthFilterWhitelist* auth_filter_default_credentials = nullptr; |
| 281 if (!auth_server_whitelist_.empty()) { |
| 282 auth_filter_default_credentials = |
| 283 new net::HttpAuthFilterWhitelist(auth_server_whitelist_); |
| 284 } |
| 285 |
| 286 url_security_manager_.reset(net::URLSecurityManager::Create( |
| 287 auth_filter_default_credentials, nullptr /*auth_filter_delegate*/)); |
| 288 |
| 289 std::vector<std::string> supported_schemes = {"negotiate"}; |
| 290 scoped_ptr<net::HttpAuthHandlerFactory> negotiate_factory( |
| 291 net::HttpAuthHandlerRegistryFactory::Create( |
| 292 supported_schemes, |
| 293 url_security_manager_.get(), |
| 294 resolver, |
| 295 std::string() /* gssapi_library_name - not used on android */, |
| 296 auth_android_negotiate_account_type_ , |
| 297 false /* negotiate_disable_cname_lookup - unsupported policy */, |
| 298 false /* negotiate_enable_port - unsupported policy */)); |
| 299 |
| 300 return negotiate_factory; |
| 301 } |
| 302 |
261 } // namespace android_webview | 303 } // namespace android_webview |
OLD | NEW |