| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/shell_url_request_context_getter.h" | 5 #include "content/shell/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/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "net/http/http_server_properties_impl.h" | 28 #include "net/http/http_server_properties_impl.h" |
| 29 #include "net/proxy/proxy_service.h" | 29 #include "net/proxy/proxy_service.h" |
| 30 #include "net/url_request/protocol_intercept_job_factory.h" | 30 #include "net/url_request/protocol_intercept_job_factory.h" |
| 31 #include "net/url_request/static_http_user_agent_settings.h" | 31 #include "net/url_request/static_http_user_agent_settings.h" |
| 32 #include "net/url_request/url_request_context.h" | 32 #include "net/url_request/url_request_context.h" |
| 33 #include "net/url_request/url_request_context_storage.h" | 33 #include "net/url_request/url_request_context_storage.h" |
| 34 #include "net/url_request/url_request_job_factory_impl.h" | 34 #include "net/url_request/url_request_job_factory_impl.h" |
| 35 | 35 |
| 36 namespace content { | 36 namespace content { |
| 37 | 37 |
| 38 namespace { |
| 39 |
| 40 void InstallProtocolHandlers(net::URLRequestJobFactoryImpl* job_factory, |
| 41 ProtocolHandlerMap* protocol_handlers) { |
| 42 for (ProtocolHandlerMap::iterator it = |
| 43 protocol_handlers->begin(); |
| 44 it != protocol_handlers->end(); |
| 45 ++it) { |
| 46 bool set_protocol = job_factory->SetProtocolHandler( |
| 47 it->first, it->second.release()); |
| 48 DCHECK(set_protocol); |
| 49 } |
| 50 protocol_handlers->clear(); |
| 51 } |
| 52 |
| 53 } // namespace |
| 54 |
| 38 ShellURLRequestContextGetter::ShellURLRequestContextGetter( | 55 ShellURLRequestContextGetter::ShellURLRequestContextGetter( |
| 39 bool ignore_certificate_errors, | 56 bool ignore_certificate_errors, |
| 40 const base::FilePath& base_path, | 57 const base::FilePath& base_path, |
| 41 MessageLoop* io_loop, | 58 MessageLoop* io_loop, |
| 42 MessageLoop* file_loop, | 59 MessageLoop* file_loop, |
| 43 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | 60 ProtocolHandlerMap* protocol_handlers) |
| 44 blob_protocol_handler, | |
| 45 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
| 46 file_system_protocol_handler, | |
| 47 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
| 48 developer_protocol_handler, | |
| 49 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
| 50 chrome_protocol_handler, | |
| 51 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
| 52 chrome_devtools_protocol_handler) | |
| 53 : ignore_certificate_errors_(ignore_certificate_errors), | 61 : ignore_certificate_errors_(ignore_certificate_errors), |
| 54 base_path_(base_path), | 62 base_path_(base_path), |
| 55 io_loop_(io_loop), | 63 io_loop_(io_loop), |
| 56 file_loop_(file_loop), | 64 file_loop_(file_loop) { |
| 57 blob_protocol_handler_(blob_protocol_handler.Pass()), | |
| 58 file_system_protocol_handler_(file_system_protocol_handler.Pass()), | |
| 59 developer_protocol_handler_(developer_protocol_handler.Pass()), | |
| 60 chrome_protocol_handler_(chrome_protocol_handler.Pass()), | |
| 61 chrome_devtools_protocol_handler_( | |
| 62 chrome_devtools_protocol_handler.Pass()) { | |
| 63 // Must first be created on the UI thread. | 65 // Must first be created on the UI thread. |
| 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 65 | 67 |
| 68 std::swap(protocol_handlers_, *protocol_handlers); |
| 69 |
| 66 // We must create the proxy config service on the UI loop on Linux because it | 70 // We must create the proxy config service on the UI loop on Linux because it |
| 67 // must synchronously run on the glib message loop. This will be passed to | 71 // must synchronously run on the glib message loop. This will be passed to |
| 68 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). | 72 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). |
| 69 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { | 73 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { |
| 70 proxy_config_service_.reset( | 74 proxy_config_service_.reset( |
| 71 net::ProxyService::CreateSystemProxyConfigService( | 75 net::ProxyService::CreateSystemProxyConfigService( |
| 72 io_loop_->message_loop_proxy(), file_loop_)); | 76 io_loop_->message_loop_proxy(), file_loop_)); |
| 73 } | 77 } |
| 74 } | 78 } |
| 75 | 79 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 storage_->set_host_resolver(host_resolver.Pass()); | 170 storage_->set_host_resolver(host_resolver.Pass()); |
| 167 network_session_params.host_resolver = | 171 network_session_params.host_resolver = |
| 168 url_request_context_->host_resolver(); | 172 url_request_context_->host_resolver(); |
| 169 | 173 |
| 170 net::HttpCache* main_cache = new net::HttpCache( | 174 net::HttpCache* main_cache = new net::HttpCache( |
| 171 network_session_params, main_backend); | 175 network_session_params, main_backend); |
| 172 storage_->set_http_transaction_factory(main_cache); | 176 storage_->set_http_transaction_factory(main_cache); |
| 173 | 177 |
| 174 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( | 178 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( |
| 175 new net::URLRequestJobFactoryImpl()); | 179 new net::URLRequestJobFactoryImpl()); |
| 176 bool set_protocol = job_factory->SetProtocolHandler( | 180 InstallProtocolHandlers(job_factory.get(), &protocol_handlers_); |
| 177 chrome::kBlobScheme, blob_protocol_handler_.release()); | 181 storage_->set_job_factory(job_factory.release()); |
| 178 DCHECK(set_protocol); | |
| 179 set_protocol = job_factory->SetProtocolHandler( | |
| 180 chrome::kFileSystemScheme, file_system_protocol_handler_.release()); | |
| 181 DCHECK(set_protocol); | |
| 182 set_protocol = job_factory->SetProtocolHandler( | |
| 183 chrome::kChromeUIScheme, chrome_protocol_handler_.release()); | |
| 184 DCHECK(set_protocol); | |
| 185 set_protocol = job_factory->SetProtocolHandler( | |
| 186 chrome::kChromeDevToolsScheme, | |
| 187 chrome_devtools_protocol_handler_.release()); | |
| 188 DCHECK(set_protocol); | |
| 189 storage_->set_job_factory(new net::ProtocolInterceptJobFactory( | |
| 190 job_factory.PassAs<net::URLRequestJobFactory>(), | |
| 191 developer_protocol_handler_.Pass())); | |
| 192 } | 182 } |
| 193 | 183 |
| 194 return url_request_context_.get(); | 184 return url_request_context_.get(); |
| 195 } | 185 } |
| 196 | 186 |
| 197 scoped_refptr<base::SingleThreadTaskRunner> | 187 scoped_refptr<base::SingleThreadTaskRunner> |
| 198 ShellURLRequestContextGetter::GetNetworkTaskRunner() const { | 188 ShellURLRequestContextGetter::GetNetworkTaskRunner() const { |
| 199 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 189 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
| 200 } | 190 } |
| 201 | 191 |
| 202 net::HostResolver* ShellURLRequestContextGetter::host_resolver() { | 192 net::HostResolver* ShellURLRequestContextGetter::host_resolver() { |
| 203 return url_request_context_->host_resolver(); | 193 return url_request_context_->host_resolver(); |
| 204 } | 194 } |
| 205 | 195 |
| 206 } // namespace content | 196 } // namespace content |
| OLD | NEW |