[email protected] | cb370a063 | 2010-01-30 08:24:12 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
| 5 | // This class represents contextual information (cookies, cache, etc.) |
| 6 | // that's useful when processing resource requests. |
| 7 | // The class is reference-counted so that it can be cleaned up after any |
| 8 | // requests that are using it have been completed. |
| 9 | |
[email protected] | 43530b3 | 2008-08-04 22:21:34 | [diff] [blame] | 10 | #ifndef NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_ |
| 11 | #define NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_ |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 12 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 13 | #include "base/ref_counted.h" |
[email protected] | 6f681a4 | 2009-01-27 22:28:54 | [diff] [blame] | 14 | #include "base/string_util.h" |
[email protected] | 5f450e5 | 2009-07-28 13:28:11 | [diff] [blame] | 15 | #include "net/base/cookie_store.h" |
[email protected] | 94a0d3d9 | 2009-06-27 01:50:14 | [diff] [blame] | 16 | #include "net/base/host_resolver.h" |
[email protected] | db36938c | 2009-08-19 21:48:42 | [diff] [blame] | 17 | #include "net/base/ssl_config_service.h" |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 18 | #include "net/base/transport_security_state.h" |
[email protected] | 515838c | 2009-01-15 06:43:48 | [diff] [blame] | 19 | #include "net/ftp/ftp_auth_cache.h" |
[email protected] | 80d6524d | 2009-08-18 03:58:09 | [diff] [blame] | 20 | #include "net/proxy/proxy_service.h" |
[email protected] | c6f27df | 2009-11-13 02:30:38 | [diff] [blame] | 21 | #include "net/url_request/request_tracker.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 22 | |
[email protected] | 8ac1a75 | 2008-07-31 19:40:37 | [diff] [blame] | 23 | namespace net { |
[email protected] | cb370a063 | 2010-01-30 08:24:12 | [diff] [blame] | 24 | class CookiePolicy; |
[email protected] | b65ce094 | 2009-03-16 20:13:33 | [diff] [blame] | 25 | class FtpTransactionFactory; |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame^] | 26 | class HttpAuthHandlerFactory; |
[email protected] | b65ce094 | 2009-03-16 20:13:33 | [diff] [blame] | 27 | class HttpTransactionFactory; |
[email protected] | c6f27df | 2009-11-13 02:30:38 | [diff] [blame] | 28 | class SocketStream; |
[email protected] | 8ac1a75 | 2008-07-31 19:40:37 | [diff] [blame] | 29 | } |
[email protected] | eaadd905 | 2009-06-23 18:02:23 | [diff] [blame] | 30 | class URLRequest; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 31 | |
| 32 | // Subclass to provide application-specific context for URLRequest instances. |
| 33 | class URLRequestContext : |
| 34 | public base::RefCountedThreadSafe<URLRequestContext> { |
| 35 | public: |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 36 | URLRequestContext() |
[email protected] | 80d6524d | 2009-08-18 03:58:09 | [diff] [blame] | 37 | : http_transaction_factory_(NULL), |
[email protected] | b65ce094 | 2009-03-16 20:13:33 | [diff] [blame] | 38 | ftp_transaction_factory_(NULL), |
[email protected] | cb370a063 | 2010-01-30 08:24:12 | [diff] [blame] | 39 | cookie_policy_(NULL), |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 40 | transport_security_state_(NULL) { |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 41 | } |
| 42 | |
[email protected] | 8a00f00a | 2009-06-12 00:49:38 | [diff] [blame] | 43 | net::HostResolver* host_resolver() const { |
| 44 | return host_resolver_; |
| 45 | } |
| 46 | |
[email protected] | 63de95b | 2008-12-10 04:11:27 | [diff] [blame] | 47 | // Get the proxy service for this context. |
| 48 | net::ProxyService* proxy_service() const { |
| 49 | return proxy_service_; |
| 50 | } |
| 51 | |
[email protected] | db36938c | 2009-08-19 21:48:42 | [diff] [blame] | 52 | // Get the ssl config service for this context. |
| 53 | net::SSLConfigService* ssl_config_service() const { |
| 54 | return ssl_config_service_; |
| 55 | } |
| 56 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 57 | // Gets the http transaction factory for this context. |
[email protected] | 659a2602 | 2009-10-06 02:22:10 | [diff] [blame] | 58 | net::HttpTransactionFactory* http_transaction_factory() const { |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 59 | return http_transaction_factory_; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 60 | } |
| 61 | |
[email protected] | b65ce094 | 2009-03-16 20:13:33 | [diff] [blame] | 62 | // Gets the ftp transaction factory for this context. |
| 63 | net::FtpTransactionFactory* ftp_transaction_factory() { |
| 64 | return ftp_transaction_factory_; |
| 65 | } |
| 66 | |
[email protected] | be6fca6c | 2010-01-30 21:48:57 | [diff] [blame] | 67 | // Gets the cookie store for this context (may be null, in which case |
| 68 | // cookies are not stored). |
[email protected] | 2bebd99 | 2009-09-05 00:17:14 | [diff] [blame] | 69 | net::CookieStore* cookie_store() { return cookie_store_.get(); } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 70 | |
[email protected] | be6fca6c | 2010-01-30 21:48:57 | [diff] [blame] | 71 | // Gets the cookie policy for this context (may be null, in which case |
| 72 | // cookies are allowed). |
[email protected] | cb370a063 | 2010-01-30 08:24:12 | [diff] [blame] | 73 | net::CookiePolicy* cookie_policy() { return cookie_policy_; } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 74 | |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 75 | net::TransportSecurityState* transport_security_state() { |
| 76 | return transport_security_state_; } |
[email protected] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 77 | |
[email protected] | 515838c | 2009-01-15 06:43:48 | [diff] [blame] | 78 | // Gets the FTP authentication cache for this context. |
| 79 | net::FtpAuthCache* ftp_auth_cache() { return &ftp_auth_cache_; } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 80 | |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame^] | 81 | // Gets the HTTP Authentication Handler Factory for this context. |
| 82 | // The factory is only valid for the lifetime of this URLRequestContext |
| 83 | net::HttpAuthHandlerFactory* http_auth_handler_factory() { |
| 84 | return http_auth_handler_factory_; |
| 85 | } |
| 86 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 87 | // Gets the value of 'Accept-Charset' header field. |
| 88 | const std::string& accept_charset() const { return accept_charset_; } |
| 89 | |
| 90 | // Gets the value of 'Accept-Language' header field. |
| 91 | const std::string& accept_language() const { return accept_language_; } |
| 92 | |
[email protected] | 7bffd08 | 2009-10-22 20:06:52 | [diff] [blame] | 93 | // Gets the tracker for URLRequests associated with this context. |
[email protected] | c6f27df | 2009-11-13 02:30:38 | [diff] [blame] | 94 | RequestTracker<URLRequest>* url_request_tracker() { |
| 95 | return &url_request_tracker_; |
| 96 | } |
| 97 | |
| 98 | // Gets the tracker for SocketStreams associated with this context. |
| 99 | RequestTracker<net::SocketStream>* socket_stream_tracker() { |
| 100 | return &socket_stream_tracker_; |
| 101 | } |
[email protected] | 7bffd08 | 2009-10-22 20:06:52 | [diff] [blame] | 102 | |
[email protected] | 6f681a4 | 2009-01-27 22:28:54 | [diff] [blame] | 103 | // Gets the UA string to use for the given URL. Pass an invalid URL (such as |
| 104 | // GURL()) to get the default UA string. Subclasses should override this |
| 105 | // method to provide a UA string. |
| 106 | virtual const std::string& GetUserAgent(const GURL& url) const { |
| 107 | return EmptyString(); |
| 108 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 109 | |
[email protected] | c9825a4 | 2009-05-01 22:51:50 | [diff] [blame] | 110 | // In general, referrer_charset is not known when URLRequestContext is |
| 111 | // constructed. So, we need a setter. |
| 112 | const std::string& referrer_charset() const { return referrer_charset_; } |
| 113 | void set_referrer_charset(const std::string& charset) { |
| 114 | referrer_charset_ = charset; |
| 115 | } |
| 116 | |
[email protected] | 5f9a7f9 | 2010-01-20 14:59:44 | [diff] [blame] | 117 | // Called before adding cookies to requests. Returns true if cookie can |
| 118 | // be added to the request. The cookie might still be modified though. |
| 119 | virtual bool InterceptRequestCookies(const URLRequest* request, |
| 120 | const std::string& cookies) const { |
[email protected] | eaadd905 | 2009-06-23 18:02:23 | [diff] [blame] | 121 | return true; |
| 122 | } |
| 123 | |
[email protected] | 5f9a7f9 | 2010-01-20 14:59:44 | [diff] [blame] | 124 | // Called before adding cookies from respones to the cookie monster. Returns |
| 125 | // true if the cookie can be added. The cookie might still be modified though. |
| 126 | virtual bool InterceptResponseCookie(const URLRequest* request, |
| 127 | const std::string& cookie) const { |
[email protected] | eaadd905 | 2009-06-23 18:02:23 | [diff] [blame] | 128 | return true; |
| 129 | } |
| 130 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 131 | protected: |
[email protected] | 6f681a4 | 2009-01-27 22:28:54 | [diff] [blame] | 132 | friend class base::RefCountedThreadSafe<URLRequestContext>; |
| 133 | |
| 134 | virtual ~URLRequestContext() {} |
| 135 | |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 136 | // The following members are expected to be initialized and owned by |
| 137 | // subclasses. |
[email protected] | 94a0d3d9 | 2009-06-27 01:50:14 | [diff] [blame] | 138 | scoped_refptr<net::HostResolver> host_resolver_; |
[email protected] | 80d6524d | 2009-08-18 03:58:09 | [diff] [blame] | 139 | scoped_refptr<net::ProxyService> proxy_service_; |
[email protected] | db36938c | 2009-08-19 21:48:42 | [diff] [blame] | 140 | scoped_refptr<net::SSLConfigService> ssl_config_service_; |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 141 | net::HttpTransactionFactory* http_transaction_factory_; |
[email protected] | b65ce094 | 2009-03-16 20:13:33 | [diff] [blame] | 142 | net::FtpTransactionFactory* ftp_transaction_factory_; |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame^] | 143 | net::HttpAuthHandlerFactory* http_auth_handler_factory_; |
[email protected] | 2bebd99 | 2009-09-05 00:17:14 | [diff] [blame] | 144 | scoped_refptr<net::CookieStore> cookie_store_; |
[email protected] | cb370a063 | 2010-01-30 08:24:12 | [diff] [blame] | 145 | net::CookiePolicy* cookie_policy_; |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 146 | scoped_refptr<net::TransportSecurityState> transport_security_state_; |
[email protected] | 515838c | 2009-01-15 06:43:48 | [diff] [blame] | 147 | net::FtpAuthCache ftp_auth_cache_; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 148 | std::string accept_language_; |
| 149 | std::string accept_charset_; |
[email protected] | c9825a4 | 2009-05-01 22:51:50 | [diff] [blame] | 150 | // The charset of the referrer where this request comes from. It's not |
| 151 | // used in communication with a server but is used to construct a suggested |
| 152 | // filename for file download. |
| 153 | std::string referrer_charset_; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 154 | |
[email protected] | 7bffd08 | 2009-10-22 20:06:52 | [diff] [blame] | 155 | // Tracks the requests associated with this context. |
[email protected] | c6f27df | 2009-11-13 02:30:38 | [diff] [blame] | 156 | RequestTracker<URLRequest> url_request_tracker_; |
| 157 | |
| 158 | // Trakcs the socket streams associated with this context. |
| 159 | RequestTracker<net::SocketStream> socket_stream_tracker_; |
[email protected] | 7bffd08 | 2009-10-22 20:06:52 | [diff] [blame] | 160 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 161 | private: |
[email protected] | 6f681a4 | 2009-01-27 22:28:54 | [diff] [blame] | 162 | DISALLOW_COPY_AND_ASSIGN(URLRequestContext); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 163 | }; |
| 164 | |
[email protected] | 43530b3 | 2008-08-04 22:21:34 | [diff] [blame] | 165 | #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_ |