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(); | |
81 | 75 |
82 // We must create the proxy config service on the UI loop on Linux because it | 76 // We must create the proxy config service on the UI loop on Linux because it |
83 // must synchronously run on the glib message loop. This will be passed to | 77 // must synchronously run on the glib message loop. This will be passed to |
84 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). | 78 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). |
85 if (proxy_server_.IsEmpty()) | 79 if (proxy_server_.IsEmpty()) |
86 proxy_config_service_ = GetProxyConfigService(); | 80 proxy_config_service_ = GetProxyConfigService(); |
87 } | 81 } |
88 | 82 |
89 HeadlessURLRequestContextGetter::~HeadlessURLRequestContextGetter() {} | 83 HeadlessURLRequestContextGetter::~HeadlessURLRequestContextGetter() {} |
90 | 84 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 174 |
181 storage_->set_http_network_session( | 175 storage_->set_http_network_session( |
182 base::WrapUnique(new net::HttpNetworkSession(network_session_params))); | 176 base::WrapUnique(new net::HttpNetworkSession(network_session_params))); |
183 storage_->set_http_transaction_factory(base::WrapUnique(new net::HttpCache( | 177 storage_->set_http_transaction_factory(base::WrapUnique(new net::HttpCache( |
184 storage_->http_network_session(), std::move(main_backend), | 178 storage_->http_network_session(), std::move(main_backend), |
185 true /* set_up_quic_server_info */))); | 179 true /* set_up_quic_server_info */))); |
186 | 180 |
187 std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory( | 181 std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory( |
188 new net::URLRequestJobFactoryImpl()); | 182 new net::URLRequestJobFactoryImpl()); |
189 | 183 |
190 // Install handlers for default protocols which aren't handled by the | |
191 // network layer. | |
192 if (protocol_handlers_.find(url::kDataScheme) == protocol_handlers_.end()) { | |
193 protocol_handlers_[url::kDataScheme] = | |
194 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( | |
195 new net::DataProtocolHandler()); | |
196 } | |
197 if (protocol_handlers_.find(url::kFileScheme) == protocol_handlers_.end()) { | |
198 protocol_handlers_[url::kFileScheme] = | |
199 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( | |
200 new net::FileProtocolHandler( | |
201 content::BrowserThread::GetBlockingPool() | |
202 ->GetTaskRunnerWithShutdownBehavior( | |
203 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); | |
204 } | |
205 InstallProtocolHandlers(job_factory.get(), &protocol_handlers_); | 184 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); |
206 | 195 |
207 // Set up interceptors in the reverse order so that the last inceptor is at | 196 // Set up interceptors in the reverse order so that the last inceptor is at |
208 // the end of the linked list of job factories. | 197 // the end of the linked list of job factories. |
209 std::unique_ptr<net::URLRequestJobFactory> top_job_factory = | 198 std::unique_ptr<net::URLRequestJobFactory> top_job_factory = |
210 std::move(job_factory); | 199 std::move(job_factory); |
211 for (auto i = request_interceptors_.rbegin(); | 200 for (auto i = request_interceptors_.rbegin(); |
212 i != request_interceptors_.rend(); ++i) { | 201 i != request_interceptors_.rend(); ++i) { |
213 top_job_factory.reset(new net::URLRequestInterceptingJobFactory( | 202 top_job_factory.reset(new net::URLRequestInterceptingJobFactory( |
214 std::move(top_job_factory), base::WrapUnique(*i))); | 203 std::move(top_job_factory), base::WrapUnique(*i))); |
215 } | 204 } |
216 request_interceptors_.weak_clear(); | 205 request_interceptors_.weak_clear(); |
217 // Save the head of the job factory list at storage_. | 206 // Save the head of the job factory list at storage_. |
218 storage_->set_job_factory(std::move(top_job_factory)); | 207 storage_->set_job_factory(std::move(top_job_factory)); |
219 } | 208 } |
220 | 209 |
221 return url_request_context_.get(); | 210 return url_request_context_.get(); |
222 } | 211 } |
223 | 212 |
224 scoped_refptr<base::SingleThreadTaskRunner> | 213 scoped_refptr<base::SingleThreadTaskRunner> |
225 HeadlessURLRequestContextGetter::GetNetworkTaskRunner() const { | 214 HeadlessURLRequestContextGetter::GetNetworkTaskRunner() const { |
226 return content::BrowserThread::GetMessageLoopProxyForThread( | 215 return content::BrowserThread::GetMessageLoopProxyForThread( |
227 content::BrowserThread::IO); | 216 content::BrowserThread::IO); |
228 } | 217 } |
229 | 218 |
230 net::HostResolver* HeadlessURLRequestContextGetter::host_resolver() const { | 219 net::HostResolver* HeadlessURLRequestContextGetter::host_resolver() const { |
231 return url_request_context_->host_resolver(); | 220 return url_request_context_->host_resolver(); |
232 } | 221 } |
233 | 222 |
234 } // namespace headless | 223 } // namespace headless |
OLD | NEW |