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

Side by Side Diff: extensions/browser/extension_url_request_context_getter.cc

Issue 615583003: Introduce NetworkDelegate's implementation in extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « extensions/browser/extension_url_request_context_getter.h ('k') | extensions/common/switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/shell_url_request_context_getter.h" 5 #include "extensions/browser/extension_url_request_context_getter.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/threading/sequenced_worker_pool.h" 12 #include "base/threading/sequenced_worker_pool.h"
13 #include "base/threading/worker_pool.h" 13 #include "base/threading/worker_pool.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/cookie_store_factory.h" 15 #include "content/public/browser/cookie_store_factory.h"
16 #include "content/public/browser/resource_request_info.h"
16 #include "content/public/common/content_switches.h" 17 #include "content/public/common/content_switches.h"
17 #include "content/shell/browser/shell_network_delegate.h" 18 #include "extensions/browser/extension_network_delegate.h"
18 #include "content/shell/common/shell_content_client.h" 19 #include "extensions/browser/info_map.h"
19 #include "content/shell/common/shell_switches.h" 20 #include "extensions/common/constants.h"
21 #include "extensions/common/switches.h"
20 #include "net/base/cache_type.h" 22 #include "net/base/cache_type.h"
21 #include "net/cert/cert_verifier.h" 23 #include "net/cert/cert_verifier.h"
22 #include "net/cookies/cookie_monster.h" 24 #include "net/cookies/cookie_monster.h"
23 #include "net/dns/host_resolver.h" 25 #include "net/dns/host_resolver.h"
24 #include "net/dns/mapped_host_resolver.h" 26 #include "net/dns/mapped_host_resolver.h"
25 #include "net/http/http_auth_handler_factory.h" 27 #include "net/http/http_auth_handler_factory.h"
26 #include "net/http/http_cache.h" 28 #include "net/http/http_cache.h"
27 #include "net/http/http_network_session.h" 29 #include "net/http/http_network_session.h"
28 #include "net/http/http_server_properties_impl.h" 30 #include "net/http/http_server_properties_impl.h"
29 #include "net/http/transport_security_state.h" 31 #include "net/http/transport_security_state.h"
30 #include "net/proxy/proxy_service.h" 32 #include "net/proxy/proxy_service.h"
31 #include "net/ssl/channel_id_service.h" 33 #include "net/ssl/channel_id_service.h"
32 #include "net/ssl/default_channel_id_store.h" 34 #include "net/ssl/default_channel_id_store.h"
33 #include "net/ssl/ssl_config_service_defaults.h" 35 #include "net/ssl/ssl_config_service_defaults.h"
34 #include "net/url_request/data_protocol_handler.h" 36 #include "net/url_request/data_protocol_handler.h"
35 #include "net/url_request/file_protocol_handler.h" 37 #include "net/url_request/file_protocol_handler.h"
36 #include "net/url_request/static_http_user_agent_settings.h" 38 #include "net/url_request/static_http_user_agent_settings.h"
37 #include "net/url_request/url_request_context.h" 39 #include "net/url_request/url_request_context.h"
38 #include "net/url_request/url_request_context_storage.h" 40 #include "net/url_request/url_request_context_storage.h"
39 #include "net/url_request/url_request_intercepting_job_factory.h" 41 #include "net/url_request/url_request_intercepting_job_factory.h"
40 #include "net/url_request/url_request_job_factory_impl.h" 42 #include "net/url_request/url_request_job_factory_impl.h"
41 #include "url/url_constants.h" 43 #include "url/url_constants.h"
42 44
43 namespace content { 45 namespace extensions {
44 46
45 namespace { 47 namespace {
46
47 void InstallProtocolHandlers(net::URLRequestJobFactoryImpl* job_factory, 48 void InstallProtocolHandlers(net::URLRequestJobFactoryImpl* job_factory,
48 ProtocolHandlerMap* protocol_handlers) { 49 content::ProtocolHandlerMap* protocol_handlers) {
49 for (ProtocolHandlerMap::iterator it = 50 for (content::ProtocolHandlerMap::iterator it =
50 protocol_handlers->begin(); 51 protocol_handlers->begin();
51 it != protocol_handlers->end(); 52 it != protocol_handlers->end();
52 ++it) { 53 ++it) {
53 bool set_protocol = job_factory->SetProtocolHandler( 54 bool set_protocol = job_factory->SetProtocolHandler(
54 it->first, it->second.release()); 55 it->first, it->second.release());
55 DCHECK(set_protocol); 56 DCHECK(set_protocol);
56 } 57 }
57 protocol_handlers->clear(); 58 protocol_handlers->clear();
58 } 59 }
59 60
60 } // namespace 61 } // namespace
61 62
62 ShellURLRequestContextGetter::ShellURLRequestContextGetter( 63 ExtensionURLRequestContextGetter::ExtensionURLRequestContextGetter(
64 void* browser_context,
63 bool ignore_certificate_errors, 65 bool ignore_certificate_errors,
64 const base::FilePath& base_path, 66 const base::FilePath& base_path,
65 base::MessageLoop* io_loop, 67 base::MessageLoop* io_loop,
66 base::MessageLoop* file_loop, 68 base::MessageLoop* file_loop,
67 ProtocolHandlerMap* protocol_handlers, 69 content::ProtocolHandlerMap* protocol_handlers,
68 URLRequestInterceptorScopedVector request_interceptors, 70 content::URLRequestInterceptorScopedVector request_interceptors,
69 net::NetLog* net_log) 71 net::NetLog* net_log,
70 : ignore_certificate_errors_(ignore_certificate_errors), 72 InfoMap* extension_info_map)
73 : browser_context_(browser_context),
74 ignore_certificate_errors_(ignore_certificate_errors),
71 base_path_(base_path), 75 base_path_(base_path),
72 io_loop_(io_loop), 76 io_loop_(io_loop),
73 file_loop_(file_loop), 77 file_loop_(file_loop),
74 net_log_(net_log), 78 net_log_(net_log),
79 extension_info_map_(extension_info_map),
75 request_interceptors_(request_interceptors.Pass()) { 80 request_interceptors_(request_interceptors.Pass()) {
76 // Must first be created on the UI thread. 81 // Must first be created on the UI thread.
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 82 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
78
79 std::swap(protocol_handlers_, *protocol_handlers); 83 std::swap(protocol_handlers_, *protocol_handlers);
80 84
81 // We must create the proxy config service on the UI loop on Linux because it 85 // We must create the proxy config service on the UI loop on Linux because it
82 // must synchronously run on the glib message loop. This will be passed to 86 // must synchronously run on the glib message loop. This will be passed to
83 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). 87 // the URLRequestContextStorage on the IO thread in GetURLRequestContext().
84 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { 88 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) {
85 proxy_config_service_.reset( 89 proxy_config_service_.reset(
86 net::ProxyService::CreateSystemProxyConfigService( 90 net::ProxyService::CreateSystemProxyConfigService(
87 io_loop_->message_loop_proxy(), file_loop_->message_loop_proxy())); 91 io_loop_->message_loop_proxy(), file_loop_->message_loop_proxy()));
88 } 92 }
89 } 93 }
90 94
91 ShellURLRequestContextGetter::~ShellURLRequestContextGetter() { 95 ExtensionURLRequestContextGetter::~ExtensionURLRequestContextGetter() {
92 } 96 }
93 97
94 net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { 98 net::URLRequestContext*
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 99 ExtensionURLRequestContextGetter::GetURLRequestContext() {
100 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
96 101
97 if (!url_request_context_) { 102 if (!url_request_context_) {
98 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 103 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
99 104
100 url_request_context_.reset(new net::URLRequestContext()); 105 url_request_context_.reset(new net::URLRequestContext());
101 url_request_context_->set_net_log(net_log_); 106 url_request_context_->set_net_log(net_log_);
102 network_delegate_.reset(new ShellNetworkDelegate); 107 network_delegate_.reset(
108 new ExtensionNetworkDelegate(browser_context_, extension_info_map_));
103 if (command_line.HasSwitch(switches::kDumpRenderTree)) 109 if (command_line.HasSwitch(switches::kDumpRenderTree))
104 ShellNetworkDelegate::SetAcceptAllCookies(false); 110 ExtensionNetworkDelegate::SetAcceptAllCookies(false);
105 url_request_context_->set_network_delegate(network_delegate_.get()); 111 url_request_context_->set_network_delegate(network_delegate_.get());
106 storage_.reset( 112 storage_.reset(
107 new net::URLRequestContextStorage(url_request_context_.get())); 113 new net::URLRequestContextStorage(url_request_context_.get()));
108 storage_->set_cookie_store(CreateCookieStore(CookieStoreConfig())); 114 storage_->set_cookie_store(CreateCookieStore(content::CookieStoreConfig()));
109 storage_->set_channel_id_service(new net::ChannelIDService( 115 storage_->set_channel_id_service(new net::ChannelIDService(
110 new net::DefaultChannelIDStore(NULL), 116 new net::DefaultChannelIDStore(NULL),
111 base::WorkerPool::GetTaskRunner(true))); 117 base::WorkerPool::GetTaskRunner(true)));
112 storage_->set_http_user_agent_settings(
113 new net::StaticHttpUserAgentSettings(
114 "en-us,en", GetShellUserAgent()));
115 118
116 scoped_ptr<net::HostResolver> host_resolver( 119 scoped_ptr<net::HostResolver> host_resolver(
117 net::HostResolver::CreateDefaultResolver( 120 net::HostResolver::CreateDefaultResolver(
118 url_request_context_->net_log())); 121 url_request_context_->net_log()));
119 122
120 storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); 123 storage_->set_cert_verifier(net::CertVerifier::CreateDefault());
121 storage_->set_transport_security_state(new net::TransportSecurityState); 124 storage_->set_transport_security_state(new net::TransportSecurityState);
122 if (command_line.HasSwitch(switches::kDumpRenderTree)) { 125 if (command_line.HasSwitch(switches::kDumpRenderTree)) {
123 storage_->set_proxy_service(net::ProxyService::CreateDirect()); 126 storage_->set_proxy_service(net::ProxyService::CreateDirect());
124 } else { 127 } else {
(...skipping 17 matching lines...) Expand all
142 net::DISK_CACHE, 145 net::DISK_CACHE,
143 #if defined(OS_ANDROID) 146 #if defined(OS_ANDROID)
144 // TODO(rdsmith): Remove when default backend for Android is 147 // TODO(rdsmith): Remove when default backend for Android is
145 // changed to simple cache. 148 // changed to simple cache.
146 net::CACHE_BACKEND_SIMPLE, 149 net::CACHE_BACKEND_SIMPLE,
147 #else 150 #else
148 net::CACHE_BACKEND_DEFAULT, 151 net::CACHE_BACKEND_DEFAULT,
149 #endif 152 #endif
150 cache_path, 153 cache_path,
151 0, 154 0,
152 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); 155 content::BrowserThread::GetMessageLoopProxyForThread(
156 content::BrowserThread::CACHE));
153 157
154 net::HttpNetworkSession::Params network_session_params; 158 net::HttpNetworkSession::Params network_session_params;
155 network_session_params.cert_verifier = 159 network_session_params.cert_verifier =
156 url_request_context_->cert_verifier(); 160 url_request_context_->cert_verifier();
157 network_session_params.transport_security_state = 161 network_session_params.transport_security_state =
158 url_request_context_->transport_security_state(); 162 url_request_context_->transport_security_state();
159 network_session_params.channel_id_service = 163 network_session_params.channel_id_service =
160 url_request_context_->channel_id_service(); 164 url_request_context_->channel_id_service();
161 network_session_params.proxy_service = 165 network_session_params.proxy_service =
162 url_request_context_->proxy_service(); 166 url_request_context_->proxy_service();
163 network_session_params.ssl_config_service = 167 network_session_params.ssl_config_service =
164 url_request_context_->ssl_config_service(); 168 url_request_context_->ssl_config_service();
165 network_session_params.http_auth_handler_factory = 169 network_session_params.http_auth_handler_factory =
166 url_request_context_->http_auth_handler_factory(); 170 url_request_context_->http_auth_handler_factory();
167 network_session_params.network_delegate = 171 network_session_params.network_delegate =
168 network_delegate_.get(); 172 network_delegate_.get();
169 network_session_params.http_server_properties = 173 network_session_params.http_server_properties =
170 url_request_context_->http_server_properties(); 174 url_request_context_->http_server_properties();
171 network_session_params.net_log = 175 network_session_params.net_log =
172 url_request_context_->net_log(); 176 url_request_context_->net_log();
173 network_session_params.ignore_certificate_errors = 177 network_session_params.ignore_certificate_errors =
174 ignore_certificate_errors_; 178 ignore_certificate_errors_;
175 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { 179 if (command_line.HasSwitch(::switches::kTestingFixedHttpPort)) {
176 int value; 180 int value;
177 base::StringToInt(command_line.GetSwitchValueASCII( 181 base::StringToInt(command_line.GetSwitchValueASCII(
178 switches::kTestingFixedHttpPort), &value); 182 ::switches::kTestingFixedHttpPort), &value);
179 network_session_params.testing_fixed_http_port = value; 183 network_session_params.testing_fixed_http_port = value;
180 } 184 }
181 if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) { 185 if (command_line.HasSwitch(::switches::kTestingFixedHttpsPort)) {
182 int value; 186 int value;
183 base::StringToInt(command_line.GetSwitchValueASCII( 187 base::StringToInt(command_line.GetSwitchValueASCII(
184 switches::kTestingFixedHttpsPort), &value); 188 ::switches::kTestingFixedHttpsPort), &value);
185 network_session_params.testing_fixed_https_port = value; 189 network_session_params.testing_fixed_https_port = value;
186 } 190 }
187 if (command_line.HasSwitch(switches::kHostResolverRules)) { 191 if (command_line.HasSwitch(::switches::kHostResolverRules)) {
188 scoped_ptr<net::MappedHostResolver> mapped_host_resolver( 192 scoped_ptr<net::MappedHostResolver> mapped_host_resolver(
189 new net::MappedHostResolver(host_resolver.Pass())); 193 new net::MappedHostResolver(host_resolver.Pass()));
190 mapped_host_resolver->SetRulesFromString( 194 mapped_host_resolver->SetRulesFromString(
191 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); 195 command_line.GetSwitchValueASCII(::switches::kHostResolverRules));
192 host_resolver = mapped_host_resolver.Pass(); 196 host_resolver = mapped_host_resolver.Pass();
193 } 197 }
194 198
195 // Give |storage_| ownership at the end in case it's |mapped_host_resolver|. 199 // Give |storage_| ownership at the end in case it's |mapped_host_resolver|.
196 storage_->set_host_resolver(host_resolver.Pass()); 200 storage_->set_host_resolver(host_resolver.Pass());
197 network_session_params.host_resolver = 201 network_session_params.host_resolver =
198 url_request_context_->host_resolver(); 202 url_request_context_->host_resolver();
199 203
200 net::HttpCache* main_cache = new net::HttpCache( 204 net::HttpCache* main_cache = new net::HttpCache(
201 network_session_params, main_backend); 205 network_session_params, main_backend);
202 storage_->set_http_transaction_factory(main_cache); 206 storage_->set_http_transaction_factory(main_cache);
203 207
204 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( 208 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
205 new net::URLRequestJobFactoryImpl()); 209 new net::URLRequestJobFactoryImpl());
206 // Keep ProtocolHandlers added in sync with 210 // Keep ProtocolHandlers added in sync with
207 // ShellContentBrowserClient::IsHandledURL(). 211 // ShellContentBrowserClient::IsHandledURL().
208 InstallProtocolHandlers(job_factory.get(), &protocol_handlers_); 212 InstallProtocolHandlers(job_factory.get(), &protocol_handlers_);
209 bool set_protocol = job_factory->SetProtocolHandler( 213 bool set_protocol = job_factory->SetProtocolHandler(
210 url::kDataScheme, new net::DataProtocolHandler); 214 url::kDataScheme, new net::DataProtocolHandler);
211 DCHECK(set_protocol); 215 DCHECK(set_protocol);
212 #if !defined(DISABLE_FILE_SUPPORT) 216 #if !defined(DISABLE_FILE_SUPPORT)
213 set_protocol = job_factory->SetProtocolHandler( 217 set_protocol = job_factory->SetProtocolHandler(
214 url::kFileScheme, 218 url::kFileScheme,
215 new net::FileProtocolHandler( 219 new net::FileProtocolHandler(
216 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( 220 content::BrowserThread::GetBlockingPool()->
217 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); 221 GetTaskRunnerWithShutdownBehavior(
222 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
218 DCHECK(set_protocol); 223 DCHECK(set_protocol);
219 #endif 224 #endif
220 225
221 // Set up interceptors in the reverse order. 226 // Set up interceptors in the reverse order.
222 scoped_ptr<net::URLRequestJobFactory> top_job_factory = 227 scoped_ptr<net::URLRequestJobFactory> top_job_factory =
223 job_factory.PassAs<net::URLRequestJobFactory>(); 228 job_factory.PassAs<net::URLRequestJobFactory>();
224 for (URLRequestInterceptorScopedVector::reverse_iterator i = 229 for (content::URLRequestInterceptorScopedVector::reverse_iterator i =
225 request_interceptors_.rbegin(); 230 request_interceptors_.rbegin();
226 i != request_interceptors_.rend(); 231 i != request_interceptors_.rend();
227 ++i) { 232 ++i) {
228 top_job_factory.reset(new net::URLRequestInterceptingJobFactory( 233 top_job_factory.reset(new net::URLRequestInterceptingJobFactory(
229 top_job_factory.Pass(), make_scoped_ptr(*i))); 234 top_job_factory.Pass(), make_scoped_ptr(*i)));
230 } 235 }
231 request_interceptors_.weak_clear(); 236 request_interceptors_.weak_clear();
232 237
233 storage_->set_job_factory(top_job_factory.release()); 238 storage_->set_job_factory(top_job_factory.release());
234 } 239 }
235 240
236 return url_request_context_.get(); 241 return url_request_context_.get();
237 } 242 }
238 243
239 scoped_refptr<base::SingleThreadTaskRunner> 244 scoped_refptr<base::SingleThreadTaskRunner>
240 ShellURLRequestContextGetter::GetNetworkTaskRunner() const { 245 ExtensionURLRequestContextGetter::GetNetworkTaskRunner() const {
241 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); 246 return content::BrowserThread::GetMessageLoopProxyForThread(
247 content::BrowserThread::IO);
242 } 248 }
243 249
244 net::HostResolver* ShellURLRequestContextGetter::host_resolver() { 250 } // namespace extensions
245 return url_request_context_->host_resolver();
246 }
247
248 } // namespace content
OLDNEW
« no previous file with comments | « extensions/browser/extension_url_request_context_getter.h ('k') | extensions/common/switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698