blob: 374af90f1168794a1e9b9eed40c5d70ac37c53a2 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// 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.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"
initial.commit586acc5fe2008-07-26 22:42:5215#include "net/base/cookie_policy.h"
[email protected]515838c2009-01-15 06:43:4816#include "net/ftp/ftp_auth_cache.h"
initial.commit586acc5fe2008-07-26 22:42:5217
[email protected]8ac1a752008-07-31 19:40:3718namespace net {
initial.commit586acc5fe2008-07-26 22:42:5219class CookieMonster;
[email protected]a9cea7542009-05-20 04:30:2320class ForceTLSState;
[email protected]b65ce0942009-03-16 20:13:3321class FtpTransactionFactory;
[email protected]8a00f00a2009-06-12 00:49:3822class HostResolver;
[email protected]b65ce0942009-03-16 20:13:3323class HttpTransactionFactory;
[email protected]63de95b2008-12-10 04:11:2724class ProxyService;
[email protected]8ac1a752008-07-31 19:40:3725}
[email protected]eaadd9052009-06-23 18:02:2326class Blacklist;
27class URLRequest;
initial.commit586acc5fe2008-07-26 22:42:5228
29// Subclass to provide application-specific context for URLRequest instances.
30class URLRequestContext :
31 public base::RefCountedThreadSafe<URLRequestContext> {
32 public:
[email protected]db8f44c2008-12-13 04:52:0133 URLRequestContext()
[email protected]8a00f00a2009-06-12 00:49:3834 : host_resolver_(NULL),
35 proxy_service_(NULL),
[email protected]db8f44c2008-12-13 04:52:0136 http_transaction_factory_(NULL),
[email protected]b65ce0942009-03-16 20:13:3337 ftp_transaction_factory_(NULL),
[email protected]a9cea7542009-05-20 04:30:2338 cookie_store_(NULL),
[email protected]eaadd9052009-06-23 18:02:2339 force_tls_state_(NULL),
40 blacklist_(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
initial.commit586acc5fe2008-07-26 22:42:5252 // Gets the http transaction factory for this context.
53 net::HttpTransactionFactory* http_transaction_factory() {
[email protected]db8f44c2008-12-13 04:52:0154 return http_transaction_factory_;
initial.commit586acc5fe2008-07-26 22:42:5255 }
56
[email protected]b65ce0942009-03-16 20:13:3357 // Gets the ftp transaction factory for this context.
58 net::FtpTransactionFactory* ftp_transaction_factory() {
59 return ftp_transaction_factory_;
60 }
61
initial.commit586acc5fe2008-07-26 22:42:5262 // Gets the cookie store for this context.
[email protected]db8f44c2008-12-13 04:52:0163 net::CookieMonster* cookie_store() { return cookie_store_; }
initial.commit586acc5fe2008-07-26 22:42:5264
65 // Gets the cookie policy for this context.
[email protected]8ac1a752008-07-31 19:40:3766 net::CookiePolicy* cookie_policy() { return &cookie_policy_; }
initial.commit586acc5fe2008-07-26 22:42:5267
[email protected]a9cea7542009-05-20 04:30:2368 net::ForceTLSState* force_tls_state() { return force_tls_state_; }
69
[email protected]515838c2009-01-15 06:43:4870 // Gets the FTP authentication cache for this context.
71 net::FtpAuthCache* ftp_auth_cache() { return &ftp_auth_cache_; }
initial.commit586acc5fe2008-07-26 22:42:5272
[email protected]eaadd9052009-06-23 18:02:2373 // Gets the Privacy Blacklist, if any for this context.
74 const Blacklist* blacklist() { return blacklist_; }
75
initial.commit586acc5fe2008-07-26 22:42:5276 // 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]6f681a42009-01-27 22:28:5482 // 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.commit586acc5fe2008-07-26 22:42:5288
[email protected]c9825a42009-05-01 22:51:5089 // 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]eaadd9052009-06-23 18:02:2396 // 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.commit586acc5fe2008-07-26 22:42:52109 protected:
[email protected]6f681a42009-01-27 22:28:54110 friend class base::RefCountedThreadSafe<URLRequestContext>;
111
112 virtual ~URLRequestContext() {}
113
[email protected]db8f44c2008-12-13 04:52:01114 // The following members are expected to be initialized and owned by
115 // subclasses.
[email protected]8a00f00a2009-06-12 00:49:38116 net::HostResolver* host_resolver_;
[email protected]db8f44c2008-12-13 04:52:01117 net::ProxyService* proxy_service_;
118 net::HttpTransactionFactory* http_transaction_factory_;
[email protected]b65ce0942009-03-16 20:13:33119 net::FtpTransactionFactory* ftp_transaction_factory_;
[email protected]db8f44c2008-12-13 04:52:01120 net::CookieMonster* cookie_store_;
[email protected]8ac1a752008-07-31 19:40:37121 net::CookiePolicy cookie_policy_;
[email protected]a9cea7542009-05-20 04:30:23122 net::ForceTLSState* force_tls_state_;;
[email protected]515838c2009-01-15 06:43:48123 net::FtpAuthCache ftp_auth_cache_;
[email protected]eaadd9052009-06-23 18:02:23124 const Blacklist* blacklist_;
initial.commit586acc5fe2008-07-26 22:42:52125 std::string accept_language_;
126 std::string accept_charset_;
[email protected]c9825a42009-05-01 22:51:50127 // 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.commit586acc5fe2008-07-26 22:42:52131
132 private:
[email protected]6f681a42009-01-27 22:28:54133 DISALLOW_COPY_AND_ASSIGN(URLRequestContext);
initial.commit586acc5fe2008-07-26 22:42:52134};
135
[email protected]43530b32008-08-04 22:21:34136#endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_