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