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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 net_log_(net_log), | 74 net_log_(net_log), |
75 request_interceptors_(request_interceptors.Pass()) { | 75 request_interceptors_(request_interceptors.Pass()) { |
76 // Must first be created on the UI thread. | 76 // Must first be created on the UI thread. |
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
78 | 78 |
79 std::swap(protocol_handlers_, *protocol_handlers); | 79 std::swap(protocol_handlers_, *protocol_handlers); |
80 | 80 |
81 // We must create the proxy config service on the UI loop on Linux because it | 81 // 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 | 82 // must synchronously run on the glib message loop. This will be passed to |
83 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). | 83 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). |
84 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { | 84 proxy_config_service_.reset(GetProxyConfigService()); |
85 proxy_config_service_.reset( | |
86 net::ProxyService::CreateSystemProxyConfigService( | |
87 io_loop_->message_loop_proxy(), file_loop_->message_loop_proxy())); | |
88 } | |
89 } | 85 } |
90 | 86 |
91 ShellURLRequestContextGetter::~ShellURLRequestContextGetter() { | 87 ShellURLRequestContextGetter::~ShellURLRequestContextGetter() { |
92 } | 88 } |
93 | 89 |
94 net::NetworkDelegate* ShellURLRequestContextGetter::CreateNetworkDelegate() { | 90 net::NetworkDelegate* ShellURLRequestContextGetter::CreateNetworkDelegate() { |
95 return new ShellNetworkDelegate; | 91 return new ShellNetworkDelegate; |
96 } | 92 } |
97 | 93 |
| 94 net::ProxyConfigService* ShellURLRequestContextGetter::GetProxyConfigService() { |
| 95 return net::ProxyService::CreateSystemProxyConfigService( |
| 96 io_loop_->message_loop_proxy(), file_loop_->message_loop_proxy()); |
| 97 } |
| 98 |
| 99 net::ProxyService* ShellURLRequestContextGetter::GetProxyService() { |
| 100 // TODO(jam): use v8 if possible, look at chrome code. |
| 101 return net::ProxyService::CreateUsingSystemProxyResolver( |
| 102 proxy_config_service_.release(), 0, url_request_context_->net_log()); |
| 103 } |
| 104 |
98 net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { | 105 net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { |
99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
100 | 107 |
101 if (!url_request_context_) { | 108 if (!url_request_context_) { |
102 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 109 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
103 | 110 |
104 url_request_context_.reset(new net::URLRequestContext()); | 111 url_request_context_.reset(new net::URLRequestContext()); |
105 url_request_context_->set_net_log(net_log_); | 112 url_request_context_->set_net_log(net_log_); |
106 network_delegate_.reset(CreateNetworkDelegate()); | 113 network_delegate_.reset(CreateNetworkDelegate()); |
107 if (command_line.HasSwitch(switches::kDumpRenderTree)) | |
108 ShellNetworkDelegate::SetAcceptAllCookies(false); | |
109 url_request_context_->set_network_delegate(network_delegate_.get()); | 114 url_request_context_->set_network_delegate(network_delegate_.get()); |
110 storage_.reset( | 115 storage_.reset( |
111 new net::URLRequestContextStorage(url_request_context_.get())); | 116 new net::URLRequestContextStorage(url_request_context_.get())); |
112 storage_->set_cookie_store(CreateCookieStore(CookieStoreConfig())); | 117 storage_->set_cookie_store(CreateCookieStore(CookieStoreConfig())); |
113 storage_->set_channel_id_service(new net::ChannelIDService( | 118 storage_->set_channel_id_service(new net::ChannelIDService( |
114 new net::DefaultChannelIDStore(NULL), | 119 new net::DefaultChannelIDStore(NULL), |
115 base::WorkerPool::GetTaskRunner(true))); | 120 base::WorkerPool::GetTaskRunner(true))); |
116 storage_->set_http_user_agent_settings( | 121 storage_->set_http_user_agent_settings( |
117 new net::StaticHttpUserAgentSettings( | 122 new net::StaticHttpUserAgentSettings( |
118 "en-us,en", GetShellUserAgent())); | 123 "en-us,en", GetShellUserAgent())); |
119 | 124 |
120 scoped_ptr<net::HostResolver> host_resolver( | 125 scoped_ptr<net::HostResolver> host_resolver( |
121 net::HostResolver::CreateDefaultResolver( | 126 net::HostResolver::CreateDefaultResolver( |
122 url_request_context_->net_log())); | 127 url_request_context_->net_log())); |
123 | 128 |
124 storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); | 129 storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); |
125 storage_->set_transport_security_state(new net::TransportSecurityState); | 130 storage_->set_transport_security_state(new net::TransportSecurityState); |
126 if (command_line.HasSwitch(switches::kDumpRenderTree)) { | 131 storage_->set_proxy_service(GetProxyService()); |
127 storage_->set_proxy_service(net::ProxyService::CreateDirect()); | |
128 } else { | |
129 // TODO(jam): use v8 if possible, look at chrome code. | |
130 storage_->set_proxy_service( | |
131 net::ProxyService::CreateUsingSystemProxyResolver( | |
132 proxy_config_service_.release(), | |
133 0, | |
134 url_request_context_->net_log())); | |
135 } | |
136 storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); | 132 storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); |
137 storage_->set_http_auth_handler_factory( | 133 storage_->set_http_auth_handler_factory( |
138 net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); | 134 net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); |
139 storage_->set_http_server_properties( | 135 storage_->set_http_server_properties( |
140 scoped_ptr<net::HttpServerProperties>( | 136 scoped_ptr<net::HttpServerProperties>( |
141 new net::HttpServerPropertiesImpl())); | 137 new net::HttpServerPropertiesImpl())); |
142 | 138 |
143 base::FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache")); | 139 base::FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache")); |
144 net::HttpCache::DefaultBackend* main_backend = | 140 net::HttpCache::DefaultBackend* main_backend = |
145 new net::HttpCache::DefaultBackend( | 141 new net::HttpCache::DefaultBackend( |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 scoped_refptr<base::SingleThreadTaskRunner> | 239 scoped_refptr<base::SingleThreadTaskRunner> |
244 ShellURLRequestContextGetter::GetNetworkTaskRunner() const { | 240 ShellURLRequestContextGetter::GetNetworkTaskRunner() const { |
245 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 241 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
246 } | 242 } |
247 | 243 |
248 net::HostResolver* ShellURLRequestContextGetter::host_resolver() { | 244 net::HostResolver* ShellURLRequestContextGetter::host_resolver() { |
249 return url_request_context_->host_resolver(); | 245 return url_request_context_->host_resolver(); |
250 } | 246 } |
251 | 247 |
252 } // namespace content | 248 } // namespace content |
OLD | NEW |