OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "headless/lib/browser/headless_url_request_context_getter.h" | 5 #include "headless/lib/browser/headless_url_request_context_getter.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 file_task_runner_(std::move(file_task_runner)), | 65 file_task_runner_(std::move(file_task_runner)), |
66 net_log_(net_log), | 66 net_log_(net_log), |
67 user_agent_(options->user_agent), | 67 user_agent_(options->user_agent), |
68 host_resolver_rules_(options->host_resolver_rules), | 68 host_resolver_rules_(options->host_resolver_rules), |
69 proxy_server_(options->proxy_server), | 69 proxy_server_(options->proxy_server), |
70 request_interceptors_(std::move(request_interceptors)) { | 70 request_interceptors_(std::move(request_interceptors)) { |
71 // Must first be created on the UI thread. | 71 // Must first be created on the UI thread. |
72 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 72 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
73 | 73 |
74 std::swap(protocol_handlers_, *protocol_handlers); | 74 std::swap(protocol_handlers_, *protocol_handlers); |
75 for (auto& pair : options->protocol_handlers) { | |
76 protocol_handlers_[pair.first] = | |
77 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( | |
78 pair.second.release()); | |
79 } | |
80 options->protocol_handlers.clear(); | |
75 | 81 |
76 // We must create the proxy config service on the UI loop on Linux because it | 82 // We must create the proxy config service on the UI loop on Linux because it |
77 // must synchronously run on the glib message loop. This will be passed to | 83 // must synchronously run on the glib message loop. This will be passed to |
78 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). | 84 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). |
79 if (proxy_server_.IsEmpty()) | 85 if (proxy_server_.IsEmpty()) |
80 proxy_config_service_ = GetProxyConfigService(); | 86 proxy_config_service_ = GetProxyConfigService(); |
81 } | 87 } |
82 | 88 |
83 HeadlessURLRequestContextGetter::~HeadlessURLRequestContextGetter() {} | 89 HeadlessURLRequestContextGetter::~HeadlessURLRequestContextGetter() {} |
84 | 90 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 | 180 |
175 storage_->set_http_network_session( | 181 storage_->set_http_network_session( |
176 base::WrapUnique(new net::HttpNetworkSession(network_session_params))); | 182 base::WrapUnique(new net::HttpNetworkSession(network_session_params))); |
177 storage_->set_http_transaction_factory(base::WrapUnique(new net::HttpCache( | 183 storage_->set_http_transaction_factory(base::WrapUnique(new net::HttpCache( |
178 storage_->http_network_session(), std::move(main_backend), | 184 storage_->http_network_session(), std::move(main_backend), |
179 true /* set_up_quic_server_info */))); | 185 true /* set_up_quic_server_info */))); |
180 | 186 |
181 std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory( | 187 std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory( |
182 new net::URLRequestJobFactoryImpl()); | 188 new net::URLRequestJobFactoryImpl()); |
183 | 189 |
190 if (protocol_handlers_.find(url::kDataScheme) == protocol_handlers_.end()) { | |
alex clarke (OOO till 29th)
2016/05/31 16:55:50
Maybe add a comment explaining why we need to add
Sami
2016/05/31 18:01:38
Done.
| |
191 protocol_handlers_[url::kDataScheme] = | |
192 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( | |
193 new net::DataProtocolHandler()); | |
194 } | |
195 if (protocol_handlers_.find(url::kFileScheme) == protocol_handlers_.end()) { | |
196 protocol_handlers_[url::kFileScheme] = | |
197 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( | |
198 new net::FileProtocolHandler( | |
199 content::BrowserThread::GetBlockingPool() | |
200 ->GetTaskRunnerWithShutdownBehavior( | |
201 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); | |
202 } | |
184 InstallProtocolHandlers(job_factory.get(), &protocol_handlers_); | 203 InstallProtocolHandlers(job_factory.get(), &protocol_handlers_); |
185 bool set_protocol = job_factory->SetProtocolHandler( | |
186 url::kDataScheme, base::WrapUnique(new net::DataProtocolHandler)); | |
187 DCHECK(set_protocol); | |
188 set_protocol = job_factory->SetProtocolHandler( | |
189 url::kFileScheme, | |
190 base::WrapUnique(new net::FileProtocolHandler( | |
191 content::BrowserThread::GetBlockingPool() | |
192 ->GetTaskRunnerWithShutdownBehavior( | |
193 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)))); | |
194 DCHECK(set_protocol); | |
195 | 204 |
196 // Set up interceptors in the reverse order so that the last inceptor is at | 205 // Set up interceptors in the reverse order so that the last inceptor is at |
197 // the end of the linked list of job factories. | 206 // the end of the linked list of job factories. |
198 std::unique_ptr<net::URLRequestJobFactory> top_job_factory = | 207 std::unique_ptr<net::URLRequestJobFactory> top_job_factory = |
199 std::move(job_factory); | 208 std::move(job_factory); |
200 for (auto i = request_interceptors_.rbegin(); | 209 for (auto i = request_interceptors_.rbegin(); |
201 i != request_interceptors_.rend(); ++i) { | 210 i != request_interceptors_.rend(); ++i) { |
202 top_job_factory.reset(new net::URLRequestInterceptingJobFactory( | 211 top_job_factory.reset(new net::URLRequestInterceptingJobFactory( |
203 std::move(top_job_factory), base::WrapUnique(*i))); | 212 std::move(top_job_factory), base::WrapUnique(*i))); |
204 } | 213 } |
205 request_interceptors_.weak_clear(); | 214 request_interceptors_.weak_clear(); |
206 // Save the head of the job factory list at storage_. | 215 // Save the head of the job factory list at storage_. |
207 storage_->set_job_factory(std::move(top_job_factory)); | 216 storage_->set_job_factory(std::move(top_job_factory)); |
208 } | 217 } |
209 | 218 |
210 return url_request_context_.get(); | 219 return url_request_context_.get(); |
211 } | 220 } |
212 | 221 |
213 scoped_refptr<base::SingleThreadTaskRunner> | 222 scoped_refptr<base::SingleThreadTaskRunner> |
214 HeadlessURLRequestContextGetter::GetNetworkTaskRunner() const { | 223 HeadlessURLRequestContextGetter::GetNetworkTaskRunner() const { |
215 return content::BrowserThread::GetMessageLoopProxyForThread( | 224 return content::BrowserThread::GetMessageLoopProxyForThread( |
216 content::BrowserThread::IO); | 225 content::BrowserThread::IO); |
217 } | 226 } |
218 | 227 |
219 net::HostResolver* HeadlessURLRequestContextGetter::host_resolver() const { | 228 net::HostResolver* HeadlessURLRequestContextGetter::host_resolver() const { |
220 return url_request_context_->host_resolver(); | 229 return url_request_context_->host_resolver(); |
221 } | 230 } |
222 | 231 |
223 } // namespace headless | 232 } // namespace headless |
OLD | NEW |