[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | c5f1e33 | 2011-09-27 01:08:03 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "content/shell/shell_url_request_context_getter.h" |
| 6 | |
| 7 | #include "base/logging.h" |
| 8 | #include "base/string_split.h" |
[email protected] | 5bab49ec | 2012-05-04 21:13:19 | [diff] [blame^] | 9 | #include "base/threading/worker_pool.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 10 | #include "content/public/browser/browser_thread.h" |
[email protected] | 33bc283 | 2012-03-29 08:18:17 | [diff] [blame] | 11 | #include "content/shell/shell_network_delegate.h" |
[email protected] | c5f1e33 | 2011-09-27 01:08:03 | [diff] [blame] | 12 | #include "net/base/cert_verifier.h" |
[email protected] | 32cb7fb | 2012-03-22 22:41:11 | [diff] [blame] | 13 | #include "net/base/default_server_bound_cert_store.h" |
[email protected] | c5f1e33 | 2011-09-27 01:08:03 | [diff] [blame] | 14 | #include "net/base/host_resolver.h" |
[email protected] | 32cb7fb | 2012-03-22 22:41:11 | [diff] [blame] | 15 | #include "net/base/server_bound_cert_service.h" |
[email protected] | c5f1e33 | 2011-09-27 01:08:03 | [diff] [blame] | 16 | #include "net/base/ssl_config_service_defaults.h" |
[email protected] | 48839bfc | 2012-03-16 18:19:11 | [diff] [blame] | 17 | #include "net/cookies/cookie_monster.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 18 | #include "net/http/http_auth_handler_factory.h" |
| 19 | #include "net/http/http_cache.h" |
| 20 | #include "net/http/http_server_properties_impl.h" |
[email protected] | c5f1e33 | 2011-09-27 01:08:03 | [diff] [blame] | 21 | #include "net/proxy/proxy_service.h" |
| 22 | #include "net/url_request/url_request_context.h" |
[email protected] | 98cce3ae | 2011-10-15 16:19:41 | [diff] [blame] | 23 | #include "net/url_request/url_request_context_storage.h" |
[email protected] | c5f1e33 | 2011-09-27 01:08:03 | [diff] [blame] | 24 | #include "net/url_request/url_request_job_factory.h" |
| 25 | |
| 26 | namespace content { |
| 27 | |
| 28 | ShellURLRequestContextGetter::ShellURLRequestContextGetter( |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 29 | const FilePath& base_path, |
[email protected] | c5f1e33 | 2011-09-27 01:08:03 | [diff] [blame] | 30 | MessageLoop* io_loop, |
| 31 | MessageLoop* file_loop) |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 32 | : base_path_(base_path), |
| 33 | io_loop_(io_loop), |
[email protected] | c5f1e33 | 2011-09-27 01:08:03 | [diff] [blame] | 34 | file_loop_(file_loop) { |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 35 | // Must first be created on the UI thread. |
| 36 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 37 | |
| 38 | // We must create the proxy config service on the UI loop on Linux because it |
| 39 | // must synchronously run on the glib message loop. This will be passed to |
| 40 | // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). |
| 41 | proxy_config_service_.reset( |
| 42 | net::ProxyService::CreateSystemProxyConfigService( |
| 43 | io_loop_, file_loop_)); |
[email protected] | c5f1e33 | 2011-09-27 01:08:03 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | ShellURLRequestContextGetter::~ShellURLRequestContextGetter() { |
| 47 | } |
| 48 | |
| 49 | net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { |
| 50 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 51 | |
| 52 | if (!url_request_context_) { |
[email protected] | 98cce3ae | 2011-10-15 16:19:41 | [diff] [blame] | 53 | url_request_context_ = new net::URLRequestContext(); |
[email protected] | 33bc283 | 2012-03-29 08:18:17 | [diff] [blame] | 54 | network_delegate_.reset(new ShellNetworkDelegate); |
| 55 | url_request_context_->set_network_delegate(network_delegate_.get()); |
[email protected] | 98cce3ae | 2011-10-15 16:19:41 | [diff] [blame] | 56 | storage_.reset(new net::URLRequestContextStorage(url_request_context_)); |
[email protected] | 98cce3ae | 2011-10-15 16:19:41 | [diff] [blame] | 57 | storage_->set_cookie_store(new net::CookieMonster(NULL, NULL)); |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 58 | storage_->set_server_bound_cert_service(new net::ServerBoundCertService( |
[email protected] | 5bab49ec | 2012-05-04 21:13:19 | [diff] [blame^] | 59 | new net::DefaultServerBoundCertStore(NULL), |
| 60 | base::WorkerPool::GetTaskRunner(true))); |
[email protected] | 98cce3ae | 2011-10-15 16:19:41 | [diff] [blame] | 61 | url_request_context_->set_accept_language("en-us,en"); |
| 62 | url_request_context_->set_accept_charset("iso-8859-1,*,utf-8"); |
| 63 | |
[email protected] | 98cce3ae | 2011-10-15 16:19:41 | [diff] [blame] | 64 | storage_->set_host_resolver( |
| 65 | net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, |
| 66 | net::HostResolver::kDefaultRetryAttempts, |
| 67 | NULL)); |
[email protected] | 9f59fac | 2012-03-21 23:18:11 | [diff] [blame] | 68 | storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); |
[email protected] | 98cce3ae | 2011-10-15 16:19:41 | [diff] [blame] | 69 | // TODO(jam): use v8 if possible, look at chrome code. |
| 70 | storage_->set_proxy_service( |
| 71 | net::ProxyService::CreateUsingSystemProxyResolver( |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 72 | proxy_config_service_.release(), |
[email protected] | 98cce3ae | 2011-10-15 16:19:41 | [diff] [blame] | 73 | 0, |
| 74 | NULL)); |
| 75 | storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); |
| 76 | storage_->set_http_auth_handler_factory( |
| 77 | net::HttpAuthHandlerFactory::CreateDefault( |
| 78 | url_request_context_->host_resolver())); |
| 79 | storage_->set_http_server_properties(new net::HttpServerPropertiesImpl); |
| 80 | |
[email protected] | c5f1e33 | 2011-09-27 01:08:03 | [diff] [blame] | 81 | FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache")); |
| 82 | net::HttpCache::DefaultBackend* main_backend = |
| 83 | new net::HttpCache::DefaultBackend( |
| 84 | net::DISK_CACHE, |
| 85 | cache_path, |
| 86 | 0, |
| 87 | BrowserThread::GetMessageLoopProxyForThread( |
| 88 | BrowserThread::CACHE)); |
| 89 | |
[email protected] | c5f1e33 | 2011-09-27 01:08:03 | [diff] [blame] | 90 | net::HttpCache* main_cache = new net::HttpCache( |
[email protected] | 98cce3ae | 2011-10-15 16:19:41 | [diff] [blame] | 91 | url_request_context_->host_resolver(), |
| 92 | url_request_context_->cert_verifier(), |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 93 | url_request_context_->server_bound_cert_service(), |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 94 | NULL, /* transport_security_state */ |
[email protected] | 98cce3ae | 2011-10-15 16:19:41 | [diff] [blame] | 95 | url_request_context_->proxy_service(), |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 96 | "", /* ssl_session_cache_shard */ |
[email protected] | 98cce3ae | 2011-10-15 16:19:41 | [diff] [blame] | 97 | url_request_context_->ssl_config_service(), |
| 98 | url_request_context_->http_auth_handler_factory(), |
[email protected] | 33bc283 | 2012-03-29 08:18:17 | [diff] [blame] | 99 | url_request_context_->network_delegate(), |
[email protected] | 98cce3ae | 2011-10-15 16:19:41 | [diff] [blame] | 100 | url_request_context_->http_server_properties(), |
| 101 | NULL, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 102 | main_backend, |
| 103 | "" /* trusted_spdy_proxy */ ); |
[email protected] | 98cce3ae | 2011-10-15 16:19:41 | [diff] [blame] | 104 | storage_->set_http_transaction_factory(main_cache); |
[email protected] | c5f1e33 | 2011-09-27 01:08:03 | [diff] [blame] | 105 | |
[email protected] | 98cce3ae | 2011-10-15 16:19:41 | [diff] [blame] | 106 | storage_->set_job_factory(new net::URLRequestJobFactory); |
[email protected] | c5f1e33 | 2011-09-27 01:08:03 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | return url_request_context_; |
| 110 | } |
| 111 | |
[email protected] | c5f1e33 | 2011-09-27 01:08:03 | [diff] [blame] | 112 | scoped_refptr<base::MessageLoopProxy> |
| 113 | ShellURLRequestContextGetter::GetIOMessageLoopProxy() const { |
| 114 | return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
| 115 | } |
| 116 | |
[email protected] | 98cce3ae | 2011-10-15 16:19:41 | [diff] [blame] | 117 | net::HostResolver* ShellURLRequestContextGetter::host_resolver() { |
| 118 | return url_request_context_->host_resolver(); |
| 119 | } |
| 120 | |
[email protected] | c5f1e33 | 2011-09-27 01:08:03 | [diff] [blame] | 121 | } // namespace content |