license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 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. |
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" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 15 | #include "net/base/cookie_policy.h" |
[email protected] | 515838c | 2009-01-15 06:43:48 | [diff] [blame] | 16 | #include "net/ftp/ftp_auth_cache.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 17 | |
[email protected] | 8ac1a75 | 2008-07-31 19:40:37 | [diff] [blame] | 18 | namespace net { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 19 | class CookieMonster; |
[email protected] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 20 | class ForceTLSState; |
[email protected] | b65ce094 | 2009-03-16 20:13:33 | [diff] [blame] | 21 | class FtpTransactionFactory; |
[email protected] | 8a00f00a | 2009-06-12 00:49:38 | [diff] [blame] | 22 | class HostResolver; |
[email protected] | b65ce094 | 2009-03-16 20:13:33 | [diff] [blame] | 23 | class HttpTransactionFactory; |
[email protected] | 63de95b | 2008-12-10 04:11:27 | [diff] [blame] | 24 | class ProxyService; |
[email protected] | 8ac1a75 | 2008-07-31 19:40:37 | [diff] [blame] | 25 | } |
[email protected] | eaadd905 | 2009-06-23 18:02:23 | [diff] [blame^] | 26 | class Blacklist; |
| 27 | class URLRequest; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 28 | |
| 29 | // Subclass to provide application-specific context for URLRequest instances. |
| 30 | class URLRequestContext : |
| 31 | public base::RefCountedThreadSafe<URLRequestContext> { |
| 32 | public: |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 33 | URLRequestContext() |
[email protected] | 8a00f00a | 2009-06-12 00:49:38 | [diff] [blame] | 34 | : host_resolver_(NULL), |
| 35 | proxy_service_(NULL), |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 36 | http_transaction_factory_(NULL), |
[email protected] | b65ce094 | 2009-03-16 20:13:33 | [diff] [blame] | 37 | ftp_transaction_factory_(NULL), |
[email protected] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 38 | cookie_store_(NULL), |
[email protected] | eaadd905 | 2009-06-23 18:02:23 | [diff] [blame^] | 39 | force_tls_state_(NULL), |
| 40 | blacklist_(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 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 52 | // Gets the http transaction factory for this context. |
| 53 | net::HttpTransactionFactory* http_transaction_factory() { |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 54 | return http_transaction_factory_; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 55 | } |
| 56 | |
[email protected] | b65ce094 | 2009-03-16 20:13:33 | [diff] [blame] | 57 | // Gets the ftp transaction factory for this context. |
| 58 | net::FtpTransactionFactory* ftp_transaction_factory() { |
| 59 | return ftp_transaction_factory_; |
| 60 | } |
| 61 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 62 | // Gets the cookie store for this context. |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 63 | net::CookieMonster* cookie_store() { return cookie_store_; } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 64 | |
| 65 | // Gets the cookie policy for this context. |
[email protected] | 8ac1a75 | 2008-07-31 19:40:37 | [diff] [blame] | 66 | net::CookiePolicy* cookie_policy() { return &cookie_policy_; } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 67 | |
[email protected] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 68 | net::ForceTLSState* force_tls_state() { return force_tls_state_; } |
| 69 | |
[email protected] | 515838c | 2009-01-15 06:43:48 | [diff] [blame] | 70 | // Gets the FTP authentication cache for this context. |
| 71 | net::FtpAuthCache* ftp_auth_cache() { return &ftp_auth_cache_; } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 72 | |
[email protected] | eaadd905 | 2009-06-23 18:02:23 | [diff] [blame^] | 73 | // Gets the Privacy Blacklist, if any for this context. |
| 74 | const Blacklist* blacklist() { return blacklist_; } |
| 75 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 76 | // Gets the value of 'Accept-Charset' header field. |
| 77 | const std::string& accept_charset() const { return accept_charset_; } |
| 78 | |
| 79 | // Gets the value of 'Accept-Language' header field. |
| 80 | const std::string& accept_language() const { return accept_language_; } |
| 81 | |
[email protected] | 6f681a4 | 2009-01-27 22:28:54 | [diff] [blame] | 82 | // Gets the UA string to use for the given URL. Pass an invalid URL (such as |
| 83 | // GURL()) to get the default UA string. Subclasses should override this |
| 84 | // method to provide a UA string. |
| 85 | virtual const std::string& GetUserAgent(const GURL& url) const { |
| 86 | return EmptyString(); |
| 87 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 88 | |
[email protected] | c9825a4 | 2009-05-01 22:51:50 | [diff] [blame] | 89 | // In general, referrer_charset is not known when URLRequestContext is |
| 90 | // constructed. So, we need a setter. |
| 91 | const std::string& referrer_charset() const { return referrer_charset_; } |
| 92 | void set_referrer_charset(const std::string& charset) { |
| 93 | referrer_charset_ = charset; |
| 94 | } |
| 95 | |
[email protected] | eaadd905 | 2009-06-23 18:02:23 | [diff] [blame^] | 96 | // Called for each cookie returning for the given request. A pointer to |
| 97 | // the cookie is passed so that it can be modified. Returns true if the |
| 98 | // cookie was not dropped (it could still be modified though). |
| 99 | virtual bool interceptCookie(const URLRequest* request, std::string* cookie) { |
| 100 | return true; |
| 101 | } |
| 102 | |
| 103 | // Called before adding cookies to sent requests. Allows overriding |
| 104 | // requests to block sending of cookies. |
| 105 | virtual bool allowSendingCookies(const URLRequest* request) const { |
| 106 | return true; |
| 107 | } |
| 108 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 109 | protected: |
[email protected] | 6f681a4 | 2009-01-27 22:28:54 | [diff] [blame] | 110 | friend class base::RefCountedThreadSafe<URLRequestContext>; |
| 111 | |
| 112 | virtual ~URLRequestContext() {} |
| 113 | |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 114 | // The following members are expected to be initialized and owned by |
| 115 | // subclasses. |
[email protected] | 8a00f00a | 2009-06-12 00:49:38 | [diff] [blame] | 116 | net::HostResolver* host_resolver_; |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 117 | net::ProxyService* proxy_service_; |
| 118 | net::HttpTransactionFactory* http_transaction_factory_; |
[email protected] | b65ce094 | 2009-03-16 20:13:33 | [diff] [blame] | 119 | net::FtpTransactionFactory* ftp_transaction_factory_; |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 120 | net::CookieMonster* cookie_store_; |
[email protected] | 8ac1a75 | 2008-07-31 19:40:37 | [diff] [blame] | 121 | net::CookiePolicy cookie_policy_; |
[email protected] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 122 | net::ForceTLSState* force_tls_state_;; |
[email protected] | 515838c | 2009-01-15 06:43:48 | [diff] [blame] | 123 | net::FtpAuthCache ftp_auth_cache_; |
[email protected] | eaadd905 | 2009-06-23 18:02:23 | [diff] [blame^] | 124 | const Blacklist* blacklist_; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 125 | std::string accept_language_; |
| 126 | std::string accept_charset_; |
[email protected] | c9825a4 | 2009-05-01 22:51:50 | [diff] [blame] | 127 | // The charset of the referrer where this request comes from. It's not |
| 128 | // used in communication with a server but is used to construct a suggested |
| 129 | // filename for file download. |
| 130 | std::string referrer_charset_; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 131 | |
| 132 | private: |
[email protected] | 6f681a4 | 2009-01-27 22:28:54 | [diff] [blame] | 133 | DISALLOW_COPY_AND_ASSIGN(URLRequestContext); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 134 | }; |
| 135 | |
[email protected] | 43530b3 | 2008-08-04 22:21:34 | [diff] [blame] | 136 | #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_ |