OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/shell/shell_url_request_context_getter.h" | 5 #include "content/shell/shell_url_request_context_getter.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_split.h" | 8 #include "base/string_split.h" |
9 #include "content/browser/browser_thread.h" | 9 #include "content/browser/browser_thread.h" |
10 #include "net/base/cert_verifier.h" | 10 #include "net/base/cert_verifier.h" |
11 #include "net/base/cookie_monster.h" | 11 #include "net/base/cookie_monster.h" |
12 #include "net/base/default_origin_bound_cert_store.h" | 12 #include "net/base/default_origin_bound_cert_store.h" |
13 #include "net/base/dnsrr_resolver.h" | 13 #include "net/base/dnsrr_resolver.h" |
14 #include "net/base/host_resolver.h" | 14 #include "net/base/host_resolver.h" |
15 #include "net/http/http_auth_handler_factory.h" | 15 #include "net/http/http_auth_handler_factory.h" |
16 #include "net/http/http_server_properties_impl.h" | |
16 #include "net/http/http_cache.h" | 17 #include "net/http/http_cache.h" |
17 #include "net/base/origin_bound_cert_service.h" | 18 #include "net/base/origin_bound_cert_service.h" |
18 #include "net/base/ssl_config_service_defaults.h" | 19 #include "net/base/ssl_config_service_defaults.h" |
19 #include "net/proxy/proxy_service.h" | 20 #include "net/proxy/proxy_service.h" |
20 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
21 #include "net/url_request/url_request_context_getter.h" | 22 #include "net/url_request/url_request_context_storage.h" |
22 #include "net/url_request/url_request_job_factory.h" | 23 #include "net/url_request/url_request_job_factory.h" |
23 | 24 |
24 namespace content { | 25 namespace content { |
25 | 26 |
26 ShellURLRequestContextGetter::ShellURLRequestContextGetter( | 27 ShellURLRequestContextGetter::ShellURLRequestContextGetter( |
27 const FilePath& base_path_, | 28 const FilePath& base_path_, |
28 MessageLoop* io_loop, | 29 MessageLoop* io_loop, |
29 MessageLoop* file_loop) | 30 MessageLoop* file_loop) |
30 : io_loop_(io_loop), | 31 : io_loop_(io_loop), |
31 file_loop_(file_loop) { | 32 file_loop_(file_loop) { |
32 } | 33 } |
33 | 34 |
34 ShellURLRequestContextGetter::~ShellURLRequestContextGetter() { | 35 ShellURLRequestContextGetter::~ShellURLRequestContextGetter() { |
35 } | 36 } |
36 | 37 |
37 net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { | 38 net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { |
38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
39 | 40 |
40 if (!url_request_context_) { | 41 if (!url_request_context_) { |
42 url_request_context_ = new net::URLRequestContext(); | |
43 storage_.reset(new net::URLRequestContextStorage(url_request_context_)); | |
44 | |
45 storage_->set_cookie_store(new net::CookieMonster(NULL, NULL)); | |
46 storage_->set_origin_bound_cert_service(new net::OriginBoundCertService( | |
47 new net::DefaultOriginBoundCertStore(NULL))); | |
48 url_request_context_->set_accept_language("en-us,en"); | |
49 url_request_context_->set_accept_charset("iso-8859-1,*,utf-8"); | |
50 | |
51 scoped_ptr<net::ProxyConfigService> proxy_config_service( | |
willchan no longer on Chromium
2011/10/15 08:25:36
One too many whitespaces between the type and the
| |
52 net::ProxyService::CreateSystemProxyConfigService( | |
53 io_loop_, file_loop_)); | |
54 storage_->set_host_resolver( | |
55 net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, | |
56 net::HostResolver::kDefaultRetryAttempts, | |
57 NULL)); | |
58 storage_->set_cert_verifier(new net::CertVerifier); | |
59 // TODO(jam): use v8 if possible, look at chrome code. | |
60 storage_->set_proxy_service( | |
61 net::ProxyService::CreateUsingSystemProxyResolver( | |
62 proxy_config_service.release(), | |
63 0, | |
64 NULL)); | |
65 storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); | |
66 storage_->set_http_auth_handler_factory( | |
67 net::HttpAuthHandlerFactory::CreateDefault( | |
68 url_request_context_->host_resolver())); | |
69 storage_->set_http_server_properties(new net::HttpServerPropertiesImpl); | |
70 | |
41 FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache")); | 71 FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache")); |
42 net::HttpCache::DefaultBackend* main_backend = | 72 net::HttpCache::DefaultBackend* main_backend = |
43 new net::HttpCache::DefaultBackend( | 73 new net::HttpCache::DefaultBackend( |
44 net::DISK_CACHE, | 74 net::DISK_CACHE, |
45 cache_path, | 75 cache_path, |
46 0, | 76 0, |
47 BrowserThread::GetMessageLoopProxyForThread( | 77 BrowserThread::GetMessageLoopProxyForThread( |
48 BrowserThread::CACHE)); | 78 BrowserThread::CACHE)); |
49 | 79 |
50 net::NetLog* net_log = NULL; | 80 storage_->set_dnsrr_resolver(new net::DnsRRResolver()); |
51 host_resolver_.reset(net::CreateSystemHostResolver( | |
52 net::HostResolver::kDefaultParallelism, | |
53 net::HostResolver::kDefaultRetryAttempts, | |
54 net_log)); | |
55 | |
56 cert_verifier_.reset(new net::CertVerifier()); | |
57 | |
58 origin_bound_cert_service_.reset(new net::OriginBoundCertService( | |
59 new net::DefaultOriginBoundCertStore(NULL))); | |
60 | |
61 dnsrr_resolver_.reset(new net::DnsRRResolver()); | |
62 | |
63 net::ProxyConfigService* proxy_config_service = | |
64 net::ProxyService::CreateSystemProxyConfigService( | |
65 io_loop_, | |
66 file_loop_); | |
67 | |
68 // TODO(jam): use v8 if possible, look at chrome code. | |
69 proxy_service_.reset( | |
70 net::ProxyService::CreateUsingSystemProxyResolver( | |
71 proxy_config_service, | |
72 0, | |
73 net_log)); | |
74 | |
75 url_security_manager_.reset(net::URLSecurityManager::Create(NULL, NULL)); | |
76 | |
77 std::vector<std::string> supported_schemes; | |
78 base::SplitString("basic,digest,ntlm,negotiate", ',', &supported_schemes); | |
79 http_auth_handler_factory_.reset( | |
80 net::HttpAuthHandlerRegistryFactory::Create( | |
81 supported_schemes, | |
82 url_security_manager_.get(), | |
83 host_resolver_.get(), | |
84 std::string(), // gssapi_library_name | |
85 false, // negotiate_disable_cname_lookup | |
86 false)); // negotiate_enable_port | |
87 | 81 |
88 net::HttpCache* main_cache = new net::HttpCache( | 82 net::HttpCache* main_cache = new net::HttpCache( |
89 host_resolver_.get(), | 83 url_request_context_->host_resolver(), |
90 cert_verifier_.get(), | 84 url_request_context_->cert_verifier(), |
91 origin_bound_cert_service_.get(), | 85 url_request_context_->origin_bound_cert_service(), |
92 dnsrr_resolver_.get(), | 86 url_request_context_->dnsrr_resolver(), |
93 NULL, //dns_cert_checker | 87 NULL, //dns_cert_checker |
94 proxy_service_.get(), | 88 url_request_context_->proxy_service(), |
95 new net::SSLConfigServiceDefaults(), | 89 url_request_context_->ssl_config_service(), |
96 http_auth_handler_factory_.get(), | 90 url_request_context_->http_auth_handler_factory(), |
97 NULL, // network_delegate | 91 NULL, // network_delegate |
98 NULL, // http_server_properties | 92 url_request_context_->http_server_properties(), |
99 net_log, | 93 NULL, |
100 main_backend); | 94 main_backend); |
101 main_http_factory_.reset(main_cache); | 95 storage_->set_http_transaction_factory(main_cache); |
102 | 96 |
103 scoped_refptr<net::CookieStore> cookie_store = | 97 storage_->set_job_factory(new net::URLRequestJobFactory); |
104 new net::CookieMonster(NULL, NULL); | |
105 | |
106 url_request_context_ = new net::URLRequestContext(); | |
107 job_factory_.reset(new net::URLRequestJobFactory); | |
108 url_request_context_->set_job_factory(job_factory_.get()); | |
109 url_request_context_->set_http_transaction_factory(main_cache); | |
110 url_request_context_->set_origin_bound_cert_service( | |
111 origin_bound_cert_service_.get()); | |
112 url_request_context_->set_dnsrr_resolver(dnsrr_resolver_.get()); | |
113 url_request_context_->set_proxy_service(proxy_service_.get()); | |
114 url_request_context_->set_cookie_store(cookie_store); | |
115 } | 98 } |
116 | 99 |
117 return url_request_context_; | 100 return url_request_context_; |
118 } | 101 } |
119 | 102 |
120 net::CookieStore* ShellURLRequestContextGetter::DONTUSEME_GetCookieStore() { | 103 net::CookieStore* ShellURLRequestContextGetter::DONTUSEME_GetCookieStore() { |
121 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) | 104 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) |
122 return GetURLRequestContext()->cookie_store(); | 105 return GetURLRequestContext()->cookie_store(); |
123 NOTIMPLEMENTED(); | 106 NOTIMPLEMENTED(); |
124 return NULL; | 107 return NULL; |
125 } | 108 } |
126 | 109 |
127 scoped_refptr<base::MessageLoopProxy> | 110 scoped_refptr<base::MessageLoopProxy> |
128 ShellURLRequestContextGetter::GetIOMessageLoopProxy() const { | 111 ShellURLRequestContextGetter::GetIOMessageLoopProxy() const { |
129 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 112 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
130 } | 113 } |
131 | 114 |
115 net::HostResolver* ShellURLRequestContextGetter::host_resolver() { | |
116 return url_request_context_->host_resolver(); | |
117 } | |
118 | |
132 } // namespace content | 119 } // namespace content |
OLD | NEW |