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