blob: fb2608f59db1d8786a37eab31ab65b889e524006 [file] [log] [blame]
[email protected]cb370a0632010-01-30 08:24:121// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit586acc5fe2008-07-26 22:42:524
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]43530b32008-08-04 22:21:3410#ifndef NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_
11#define NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_
initial.commit586acc5fe2008-07-26 22:42:5212
initial.commit586acc5fe2008-07-26 22:42:5213#include "base/ref_counted.h"
[email protected]6f681a42009-01-27 22:28:5414#include "base/string_util.h"
[email protected]5f450e52009-07-28 13:28:1115#include "net/base/cookie_store.h"
[email protected]94a0d3d92009-06-27 01:50:1416#include "net/base/host_resolver.h"
[email protected]db36938c2009-08-19 21:48:4217#include "net/base/ssl_config_service.h"
[email protected]326e6792009-12-11 21:04:4218#include "net/base/transport_security_state.h"
[email protected]515838c2009-01-15 06:43:4819#include "net/ftp/ftp_auth_cache.h"
[email protected]80d6524d2009-08-18 03:58:0920#include "net/proxy/proxy_service.h"
[email protected]c6f27df2009-11-13 02:30:3821#include "net/url_request/request_tracker.h"
initial.commit586acc5fe2008-07-26 22:42:5222
[email protected]8ac1a752008-07-31 19:40:3723namespace net {
[email protected]cb370a0632010-01-30 08:24:1224class CookiePolicy;
[email protected]b65ce0942009-03-16 20:13:3325class FtpTransactionFactory;
[email protected]fa55e192010-02-15 14:25:5026class HttpAuthHandlerFactory;
[email protected]b65ce0942009-03-16 20:13:3327class HttpTransactionFactory;
[email protected]c6f27df2009-11-13 02:30:3828class SocketStream;
[email protected]8ac1a752008-07-31 19:40:3729}
[email protected]eaadd9052009-06-23 18:02:2330class URLRequest;
initial.commit586acc5fe2008-07-26 22:42:5231
32// Subclass to provide application-specific context for URLRequest instances.
33class URLRequestContext :
34 public base::RefCountedThreadSafe<URLRequestContext> {
35 public:
[email protected]db8f44c2008-12-13 04:52:0136 URLRequestContext()
[email protected]80d6524d2009-08-18 03:58:0937 : http_transaction_factory_(NULL),
[email protected]b65ce0942009-03-16 20:13:3338 ftp_transaction_factory_(NULL),
[email protected]cb370a0632010-01-30 08:24:1239 cookie_policy_(NULL),
[email protected]326e6792009-12-11 21:04:4240 transport_security_state_(NULL) {
[email protected]db8f44c2008-12-13 04:52:0141 }
42
[email protected]8a00f00a2009-06-12 00:49:3843 net::HostResolver* host_resolver() const {
44 return host_resolver_;
45 }
46
[email protected]63de95b2008-12-10 04:11:2747 // Get the proxy service for this context.
48 net::ProxyService* proxy_service() const {
49 return proxy_service_;
50 }
51
[email protected]db36938c2009-08-19 21:48:4252 // Get the ssl config service for this context.
53 net::SSLConfigService* ssl_config_service() const {
54 return ssl_config_service_;
55 }
56
initial.commit586acc5fe2008-07-26 22:42:5257 // Gets the http transaction factory for this context.
[email protected]659a26022009-10-06 02:22:1058 net::HttpTransactionFactory* http_transaction_factory() const {
[email protected]db8f44c2008-12-13 04:52:0159 return http_transaction_factory_;
initial.commit586acc5fe2008-07-26 22:42:5260 }
61
[email protected]b65ce0942009-03-16 20:13:3362 // Gets the ftp transaction factory for this context.
63 net::FtpTransactionFactory* ftp_transaction_factory() {
64 return ftp_transaction_factory_;
65 }
66
[email protected]be6fca6c2010-01-30 21:48:5767 // Gets the cookie store for this context (may be null, in which case
68 // cookies are not stored).
[email protected]2bebd992009-09-05 00:17:1469 net::CookieStore* cookie_store() { return cookie_store_.get(); }
initial.commit586acc5fe2008-07-26 22:42:5270
[email protected]be6fca6c2010-01-30 21:48:5771 // Gets the cookie policy for this context (may be null, in which case
72 // cookies are allowed).
[email protected]cb370a0632010-01-30 08:24:1273 net::CookiePolicy* cookie_policy() { return cookie_policy_; }
initial.commit586acc5fe2008-07-26 22:42:5274
[email protected]326e6792009-12-11 21:04:4275 net::TransportSecurityState* transport_security_state() {
76 return transport_security_state_; }
[email protected]a9cea7542009-05-20 04:30:2377
[email protected]515838c2009-01-15 06:43:4878 // Gets the FTP authentication cache for this context.
79 net::FtpAuthCache* ftp_auth_cache() { return &ftp_auth_cache_; }
initial.commit586acc5fe2008-07-26 22:42:5280
[email protected]fa55e192010-02-15 14:25:5081 // 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.commit586acc5fe2008-07-26 22:42:5287 // 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]7bffd082009-10-22 20:06:5293 // Gets the tracker for URLRequests associated with this context.
[email protected]c6f27df2009-11-13 02:30:3894 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]7bffd082009-10-22 20:06:52102
[email protected]6f681a42009-01-27 22:28:54103 // 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.commit586acc5fe2008-07-26 22:42:52109
[email protected]c9825a42009-05-01 22:51:50110 // 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]5f9a7f92010-01-20 14:59:44117 // 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]eaadd9052009-06-23 18:02:23121 return true;
122 }
123
[email protected]5f9a7f92010-01-20 14:59:44124 // 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]eaadd9052009-06-23 18:02:23128 return true;
129 }
130
initial.commit586acc5fe2008-07-26 22:42:52131 protected:
[email protected]6f681a42009-01-27 22:28:54132 friend class base::RefCountedThreadSafe<URLRequestContext>;
133
134 virtual ~URLRequestContext() {}
135
[email protected]db8f44c2008-12-13 04:52:01136 // The following members are expected to be initialized and owned by
137 // subclasses.
[email protected]94a0d3d92009-06-27 01:50:14138 scoped_refptr<net::HostResolver> host_resolver_;
[email protected]80d6524d2009-08-18 03:58:09139 scoped_refptr<net::ProxyService> proxy_service_;
[email protected]db36938c2009-08-19 21:48:42140 scoped_refptr<net::SSLConfigService> ssl_config_service_;
[email protected]db8f44c2008-12-13 04:52:01141 net::HttpTransactionFactory* http_transaction_factory_;
[email protected]b65ce0942009-03-16 20:13:33142 net::FtpTransactionFactory* ftp_transaction_factory_;
[email protected]fa55e192010-02-15 14:25:50143 net::HttpAuthHandlerFactory* http_auth_handler_factory_;
[email protected]2bebd992009-09-05 00:17:14144 scoped_refptr<net::CookieStore> cookie_store_;
[email protected]cb370a0632010-01-30 08:24:12145 net::CookiePolicy* cookie_policy_;
[email protected]326e6792009-12-11 21:04:42146 scoped_refptr<net::TransportSecurityState> transport_security_state_;
[email protected]515838c2009-01-15 06:43:48147 net::FtpAuthCache ftp_auth_cache_;
initial.commit586acc5fe2008-07-26 22:42:52148 std::string accept_language_;
149 std::string accept_charset_;
[email protected]c9825a42009-05-01 22:51:50150 // 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.commit586acc5fe2008-07-26 22:42:52154
[email protected]7bffd082009-10-22 20:06:52155 // Tracks the requests associated with this context.
[email protected]c6f27df2009-11-13 02:30:38156 RequestTracker<URLRequest> url_request_tracker_;
157
158 // Trakcs the socket streams associated with this context.
159 RequestTracker<net::SocketStream> socket_stream_tracker_;
[email protected]7bffd082009-10-22 20:06:52160
initial.commit586acc5fe2008-07-26 22:42:52161 private:
[email protected]6f681a42009-01-27 22:28:54162 DISALLOW_COPY_AND_ASSIGN(URLRequestContext);
initial.commit586acc5fe2008-07-26 22:42:52163};
164
[email protected]43530b32008-08-04 22:21:34165#endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_