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

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

Issue 1431473004: Add Kerberos support to webview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ActivitylessNegoAuth
Patch Set: Rebase Created 5 years, 1 month 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 <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 "android_webview/common/pref_names.h"
17 #include "base/bind.h" 18 #include "base/bind.h"
18 #include "base/command_line.h" 19 #include "base/command_line.h"
20 #include "base/prefs/pref_service.h"
19 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
20 #include "base/threading/sequenced_worker_pool.h" 22 #include "base/threading/sequenced_worker_pool.h"
21 #include "base/threading/worker_pool.h" 23 #include "base/threading/worker_pool.h"
22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d ata.h" 24 #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" 25 #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" 26 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ est_options.h"
25 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/content_browser_client.h" 28 #include "content/public/browser/content_browser_client.h"
27 #include "content/public/browser/cookie_store_factory.h" 29 #include "content/public/browser/cookie_store_factory.h"
28 #include "content/public/common/content_client.h" 30 #include "content/public/common/content_client.h"
29 #include "content/public/common/content_switches.h" 31 #include "content/public/common/content_switches.h"
30 #include "content/public/common/url_constants.h" 32 #include "content/public/common/url_constants.h"
31 #include "net/base/cache_type.h" 33 #include "net/base/cache_type.h"
32 #include "net/cookies/cookie_store.h" 34 #include "net/cookies/cookie_store.h"
33 #include "net/dns/mapped_host_resolver.h" 35 #include "net/dns/mapped_host_resolver.h"
36 #include "net/http/http_auth_filter.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 scoped_ptr<net::MappedHostResolver> CreateCmdLineConfiguredHostResolver() {
55 net::URLRequestContextBuilder* builder) { 59 // If hostname remappings were specified on the command-line, layer these
60 // rules on top of the real host resolver. This allows forwarding all
61 // requests through a designated test server.
62 scoped_ptr<net::MappedHostResolver> host_resolver(new net::MappedHostResolver(
63 net::HostResolver::CreateDefaultResolver(NULL)));
Bernhard Bauer 2015/11/10 17:51:29 Use nullptr rather than NULL.
dgn 2015/11/11 12:26:36 Done.
64
56 const base::CommandLine& command_line = 65 const base::CommandLine& command_line =
57 *base::CommandLine::ForCurrentProcess(); 66 *base::CommandLine::ForCurrentProcess();
58 if (command_line.HasSwitch(switches::kHostResolverRules)) { 67 if (command_line.HasSwitch(switches::kHostResolverRules)) {
59 // If hostname remappings were specified on the command-line, layer these
60 // rules on top of the real host resolver. This allows forwarding all
61 // 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( 68 host_resolver->SetRulesFromString(
66 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); 69 command_line.GetSwitchValueASCII(switches::kHostResolverRules));
67 builder->set_host_resolver(host_resolver.Pass());
68 } 70 }
71
72 return host_resolver;
69 } 73 }
70 74
71 void ApplyCmdlineOverridesToNetworkSessionParams( 75 void ApplyCmdlineOverridesToNetworkSessionParams(
72 net::HttpNetworkSession::Params* params) { 76 net::HttpNetworkSession::Params* params) {
73 int value; 77 int value;
74 const base::CommandLine& command_line = 78 const base::CommandLine& command_line =
75 *base::CommandLine::ForCurrentProcess(); 79 *base::CommandLine::ForCurrentProcess();
76 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { 80 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) {
77 base::StringToInt(command_line.GetSwitchValueASCII( 81 base::StringToInt(command_line.GetSwitchValueASCII(
78 switches::kTestingFixedHttpPort), &value); 82 switches::kTestingFixedHttpPort), &value);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 job_factory.Pass(), make_scoped_ptr(*i))); 176 job_factory.Pass(), make_scoped_ptr(*i)));
173 } 177 }
174 request_interceptors.weak_clear(); 178 request_interceptors.weak_clear();
175 179
176 return job_factory.Pass(); 180 return job_factory.Pass();
177 } 181 }
178 182
179 } // namespace 183 } // namespace
180 184
181 AwURLRequestContextGetter::AwURLRequestContextGetter( 185 AwURLRequestContextGetter::AwURLRequestContextGetter(
182 const base::FilePath& cache_path, net::CookieStore* cookie_store, 186 const base::FilePath& cache_path,
183 scoped_ptr<net::ProxyConfigService> config_service) 187 net::CookieStore* cookie_store,
188 scoped_ptr<net::ProxyConfigService> config_service,
189 PrefService* user_pref_service)
184 : cache_path_(cache_path), 190 : cache_path_(cache_path),
185 net_log_(new net::NetLog()), 191 net_log_(new net::NetLog()),
186 proxy_config_service_(config_service.Pass()), 192 proxy_config_service_(config_service.Pass()),
187 cookie_store_(cookie_store), 193 cookie_store_(cookie_store),
188 http_user_agent_settings_(new AwHttpUserAgentSettings()) { 194 http_user_agent_settings_(new AwHttpUserAgentSettings()),
195 auth_android_negotiate_account_type_(user_pref_service->GetString(
196 prefs::kAuthAndroidNegotiateAccountType)),
197 auth_server_whitelist_(
198 user_pref_service->GetString(prefs::kAuthServerWhitelist)) {
189 // CreateSystemProxyConfigService for Android must be called on main thread. 199 // CreateSystemProxyConfigService for Android must be called on main thread.
190 DCHECK_CURRENTLY_ON(BrowserThread::UI); 200 DCHECK_CURRENTLY_ON(BrowserThread::UI);
191 } 201 }
192 202
193 AwURLRequestContextGetter::~AwURLRequestContextGetter() { 203 AwURLRequestContextGetter::~AwURLRequestContextGetter() {
194 } 204 }
195 205
196 void AwURLRequestContextGetter::InitializeURLRequestContext() { 206 void AwURLRequestContextGetter::InitializeURLRequestContext() {
197 DCHECK_CURRENTLY_ON(BrowserThread::IO); 207 DCHECK_CURRENTLY_ON(BrowserThread::IO);
198 DCHECK(!url_request_context_); 208 DCHECK(!url_request_context_);
199 209
200 net::URLRequestContextBuilder builder; 210 net::URLRequestContextBuilder builder;
211 scoped_ptr<net::MappedHostResolver> host_resolver(
212 CreateCmdLineConfiguredHostResolver());
201 scoped_ptr<AwNetworkDelegate> aw_network_delegate(new AwNetworkDelegate()); 213 scoped_ptr<AwNetworkDelegate> aw_network_delegate(new AwNetworkDelegate());
202 214
203 AwBrowserContext* browser_context = AwBrowserContext::GetDefault(); 215 AwBrowserContext* browser_context = AwBrowserContext::GetDefault();
204 DCHECK(browser_context); 216 DCHECK(browser_context);
205 217
206 builder.set_network_delegate( 218 builder.set_network_delegate(
207 browser_context->GetDataReductionProxyIOData() 219 browser_context->GetDataReductionProxyIOData()
208 ->CreateNetworkDelegate( 220 ->CreateNetworkDelegate(
209 aw_network_delegate.Pass(), 221 aw_network_delegate.Pass(),
210 false /* No UMA is produced to track bypasses. */) 222 false /* No UMA is produced to track bypasses. */)
211 .Pass()); 223 .Pass());
212 #if !defined(DISABLE_FTP_SUPPORT) 224 #if !defined(DISABLE_FTP_SUPPORT)
213 builder.set_ftp_enabled(false); // Android WebView does not support ftp yet. 225 builder.set_ftp_enabled(false); // Android WebView does not support ftp yet.
214 #endif 226 #endif
215 DCHECK(proxy_config_service_.get()); 227 DCHECK(proxy_config_service_.get());
216 // Android provides a local HTTP proxy that handles all the proxying. 228 // Android provides a local HTTP proxy that handles all the proxying.
217 // Create the proxy without a resolver since we rely on this local HTTP proxy. 229 // Create the proxy without a resolver since we rely on this local HTTP proxy.
218 // TODO(sgurun) is this behavior guaranteed through SDK? 230 // TODO(sgurun) is this behavior guaranteed through SDK?
219 builder.set_proxy_service(net::ProxyService::CreateWithoutProxyResolver( 231 builder.set_proxy_service(net::ProxyService::CreateWithoutProxyResolver(
220 proxy_config_service_.Pass(), net_log_.get())); 232 proxy_config_service_.Pass(), net_log_.get()));
221 builder.set_net_log(net_log_.get()); 233 builder.set_net_log(net_log_.get());
222 builder.SetCookieAndChannelIdStores(cookie_store_, NULL); 234 builder.SetCookieAndChannelIdStores(cookie_store_, NULL);
223 ApplyCmdlineOverridesToURLRequestContextBuilder(&builder); 235 builder.add_http_auth_handler_factory(
236 "negotiate",
237 CreateNegotiateAuthHandlerFactory(host_resolver.get()).release());
238 builder.set_host_resolver(host_resolver.Pass());
224 239
225 url_request_context_ = builder.Build().Pass(); 240 url_request_context_ = builder.Build().Pass();
226 // TODO(mnaganov): Fix URLRequestContextBuilder to use proper threads. 241 // TODO(mnaganov): Fix URLRequestContextBuilder to use proper threads.
227 net::HttpNetworkSession::Params network_session_params; 242 net::HttpNetworkSession::Params network_session_params;
228 243
229 PopulateNetworkSessionParams(url_request_context_.get(), 244 PopulateNetworkSessionParams(url_request_context_.get(),
230 &network_session_params); 245 &network_session_params);
231 246
232 http_network_session_.reset( 247 http_network_session_.reset(
233 new net::HttpNetworkSession(network_session_params)); 248 new net::HttpNetworkSession(network_session_params));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 net::NetLog* AwURLRequestContextGetter::GetNetLog() { 292 net::NetLog* AwURLRequestContextGetter::GetNetLog() {
278 return net_log_.get(); 293 return net_log_.get();
279 } 294 }
280 295
281 void AwURLRequestContextGetter::SetKeyOnIO(const std::string& key) { 296 void AwURLRequestContextGetter::SetKeyOnIO(const std::string& key) {
282 DCHECK(AwBrowserContext::GetDefault()->GetDataReductionProxyIOData()); 297 DCHECK(AwBrowserContext::GetDefault()->GetDataReductionProxyIOData());
283 AwBrowserContext::GetDefault()->GetDataReductionProxyIOData()-> 298 AwBrowserContext::GetDefault()->GetDataReductionProxyIOData()->
284 request_options()->SetKeyOnIO(key); 299 request_options()->SetKeyOnIO(key);
285 } 300 }
286 301
302 scoped_ptr<net::HttpAuthHandlerNegotiate::Factory>
303 AwURLRequestContextGetter::CreateNegotiateAuthHandlerFactory(
304 net::HostResolver* resolver) {
305 net::HttpAuthFilterWhitelist* auth_filter_default_credentials = nullptr;
306 if (!auth_server_whitelist_.empty()) {
307 auth_filter_default_credentials =
308 new net::HttpAuthFilterWhitelist(auth_server_whitelist_);
309 }
310
311 url_security_manager_.reset(net::URLSecurityManager::Create(
312 auth_filter_default_credentials, nullptr /*auth_filter_delegate*/));
313
314 DCHECK(resolver);
315 scoped_ptr<net::HttpAuthHandlerNegotiate::Factory> negotiate_factory(
316 new net::HttpAuthHandlerNegotiate::Factory());
317 negotiate_factory->set_library(&auth_android_negotiate_account_type_);
318 negotiate_factory->set_host_resolver(resolver);
319 negotiate_factory->set_url_security_manager(url_security_manager_.get());
320
321 return negotiate_factory;
322 }
323
287 } // namespace android_webview 324 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698