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" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
12 #include "net/dns/mapped_host_resolver.h" | 12 #include "net/dns/mapped_host_resolver.h" |
13 #include "net/proxy/proxy_service.h" | 13 #include "net/proxy/proxy_service.h" |
14 #include "net/url_request/url_request_context.h" | 14 #include "net/url_request/url_request_context.h" |
15 #include "net/url_request/url_request_context_builder.h" | 15 #include "net/url_request/url_request_context_builder.h" |
16 | 16 |
17 namespace headless { | 17 namespace headless { |
18 | 18 |
19 HeadlessURLRequestContextGetter::HeadlessURLRequestContextGetter( | 19 HeadlessURLRequestContextGetter::HeadlessURLRequestContextGetter( |
20 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 20 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
21 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, | 21 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, |
22 content::ProtocolHandlerMap* protocol_handlers, | 22 content::ProtocolHandlerMap* protocol_handlers, |
| 23 ProtocolHandlerMap context_protocol_handlers, |
23 content::URLRequestInterceptorScopedVector request_interceptors, | 24 content::URLRequestInterceptorScopedVector request_interceptors, |
24 HeadlessBrowser::Options* options) | 25 HeadlessBrowser::Options* options) |
25 : io_task_runner_(std::move(io_task_runner)), | 26 : io_task_runner_(std::move(io_task_runner)), |
26 file_task_runner_(std::move(file_task_runner)), | 27 file_task_runner_(std::move(file_task_runner)), |
27 user_agent_(options->user_agent), | 28 user_agent_(options->user_agent), |
28 host_resolver_rules_(options->host_resolver_rules), | 29 host_resolver_rules_(options->host_resolver_rules), |
29 proxy_server_(options->proxy_server), | 30 proxy_server_(options->proxy_server), |
30 request_interceptors_(std::move(request_interceptors)) { | 31 request_interceptors_(std::move(request_interceptors)) { |
31 // Must first be created on the UI thread. | 32 // Must first be created on the UI thread. |
32 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 33 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
33 | 34 |
34 std::swap(protocol_handlers_, *protocol_handlers); | 35 std::swap(protocol_handlers_, *protocol_handlers); |
35 for (auto& pair : options->protocol_handlers) { | 36 for (auto& pair : options->protocol_handlers) { |
36 protocol_handlers_[pair.first] = | 37 protocol_handlers_[pair.first] = |
37 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( | 38 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( |
38 pair.second.release()); | 39 pair.second.release()); |
39 } | 40 } |
40 options->protocol_handlers.clear(); | 41 options->protocol_handlers.clear(); |
| 42 for (auto& pair : context_protocol_handlers) { |
| 43 protocol_handlers_[pair.first] = |
| 44 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( |
| 45 pair.second.release()); |
| 46 } |
| 47 context_protocol_handlers.clear(); |
41 | 48 |
42 // We must create the proxy config service on the UI loop on Linux because it | 49 // We must create the proxy config service on the UI loop on Linux because it |
43 // must synchronously run on the glib message loop. This will be passed to | 50 // must synchronously run on the glib message loop. This will be passed to |
44 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). | 51 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). |
45 if (proxy_server_.IsEmpty()) { | 52 if (proxy_server_.IsEmpty()) { |
46 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( | 53 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( |
47 io_task_runner_, file_task_runner_); | 54 io_task_runner_, file_task_runner_); |
48 } | 55 } |
49 } | 56 } |
50 | 57 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 HeadlessURLRequestContextGetter::GetNetworkTaskRunner() const { | 110 HeadlessURLRequestContextGetter::GetNetworkTaskRunner() const { |
104 return content::BrowserThread::GetMessageLoopProxyForThread( | 111 return content::BrowserThread::GetMessageLoopProxyForThread( |
105 content::BrowserThread::IO); | 112 content::BrowserThread::IO); |
106 } | 113 } |
107 | 114 |
108 net::HostResolver* HeadlessURLRequestContextGetter::host_resolver() const { | 115 net::HostResolver* HeadlessURLRequestContextGetter::host_resolver() const { |
109 return url_request_context_->host_resolver(); | 116 return url_request_context_->host_resolver(); |
110 } | 117 } |
111 | 118 |
112 } // namespace headless | 119 } // namespace headless |
OLD | NEW |