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