OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/shell/browser/shell_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" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 } | 57 } |
58 | 58 |
59 } // namespace | 59 } // namespace |
60 | 60 |
61 ShellURLRequestContextGetter::ShellURLRequestContextGetter( | 61 ShellURLRequestContextGetter::ShellURLRequestContextGetter( |
62 bool ignore_certificate_errors, | 62 bool ignore_certificate_errors, |
63 const base::FilePath& base_path, | 63 const base::FilePath& base_path, |
64 base::MessageLoop* io_loop, | 64 base::MessageLoop* io_loop, |
65 base::MessageLoop* file_loop, | 65 base::MessageLoop* file_loop, |
66 ProtocolHandlerMap* protocol_handlers, | 66 ProtocolHandlerMap* protocol_handlers, |
| 67 ProtocolHandlerScopedVector protocol_interceptors, |
67 net::NetLog* net_log) | 68 net::NetLog* net_log) |
68 : ignore_certificate_errors_(ignore_certificate_errors), | 69 : ignore_certificate_errors_(ignore_certificate_errors), |
69 base_path_(base_path), | 70 base_path_(base_path), |
70 io_loop_(io_loop), | 71 io_loop_(io_loop), |
71 file_loop_(file_loop), | 72 file_loop_(file_loop), |
72 net_log_(net_log) { | 73 net_log_(net_log), |
| 74 protocol_interceptors_(protocol_interceptors.Pass()) { |
73 // Must first be created on the UI thread. | 75 // Must first be created on the UI thread. |
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
75 | 77 |
76 std::swap(protocol_handlers_, *protocol_handlers); | 78 std::swap(protocol_handlers_, *protocol_handlers); |
77 | 79 |
78 // We must create the proxy config service on the UI loop on Linux because it | 80 // We must create the proxy config service on the UI loop on Linux because it |
79 // must synchronously run on the glib message loop. This will be passed to | 81 // must synchronously run on the glib message loop. This will be passed to |
80 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). | 82 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). |
81 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { | 83 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { |
82 proxy_config_service_.reset( | 84 proxy_config_service_.reset( |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 bool set_protocol = job_factory->SetProtocolHandler( | 209 bool set_protocol = job_factory->SetProtocolHandler( |
208 kDataScheme, new net::DataProtocolHandler); | 210 kDataScheme, new net::DataProtocolHandler); |
209 DCHECK(set_protocol); | 211 DCHECK(set_protocol); |
210 set_protocol = job_factory->SetProtocolHandler( | 212 set_protocol = job_factory->SetProtocolHandler( |
211 kFileScheme, | 213 kFileScheme, |
212 new net::FileProtocolHandler( | 214 new net::FileProtocolHandler( |
213 content::BrowserThread::GetBlockingPool()-> | 215 content::BrowserThread::GetBlockingPool()-> |
214 GetTaskRunnerWithShutdownBehavior( | 216 GetTaskRunnerWithShutdownBehavior( |
215 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); | 217 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); |
216 DCHECK(set_protocol); | 218 DCHECK(set_protocol); |
217 storage_->set_job_factory(job_factory.release()); | 219 |
| 220 // Set up interceptors in the reverse order. |
| 221 scoped_ptr<net::URLRequestJobFactory> top_job_factory = |
| 222 job_factory.PassAs<net::URLRequestJobFactory>(); |
| 223 for (ProtocolHandlerScopedVector::reverse_iterator i = |
| 224 protocol_interceptors_.rbegin(); |
| 225 i != protocol_interceptors_.rend(); |
| 226 ++i) { |
| 227 top_job_factory.reset(new net::ProtocolInterceptJobFactory( |
| 228 top_job_factory.Pass(), make_scoped_ptr(*i))); |
| 229 } |
| 230 protocol_interceptors_.weak_clear(); |
| 231 |
| 232 storage_->set_job_factory(top_job_factory.release()); |
218 } | 233 } |
219 | 234 |
220 return url_request_context_.get(); | 235 return url_request_context_.get(); |
221 } | 236 } |
222 | 237 |
223 scoped_refptr<base::SingleThreadTaskRunner> | 238 scoped_refptr<base::SingleThreadTaskRunner> |
224 ShellURLRequestContextGetter::GetNetworkTaskRunner() const { | 239 ShellURLRequestContextGetter::GetNetworkTaskRunner() const { |
225 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 240 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
226 } | 241 } |
227 | 242 |
228 net::HostResolver* ShellURLRequestContextGetter::host_resolver() { | 243 net::HostResolver* ShellURLRequestContextGetter::host_resolver() { |
229 return url_request_context_->host_resolver(); | 244 return url_request_context_->host_resolver(); |
230 } | 245 } |
231 | 246 |
232 } // namespace content | 247 } // namespace content |
OLD | NEW |