blob: 72b02ecf3c61f77a441f78e7b86501124530df93 [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]5f450e52009-07-28 13:28:1116#include "net/base/cookie_store.h"
[email protected]94a0d3d92009-06-27 01:50:1417#include "net/base/host_resolver.h"
[email protected]db36938c2009-08-19 21:48:4218#include "net/base/ssl_config_service.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"
initial.commit586acc5fe2008-07-26 22:42:5221
[email protected]8ac1a752008-07-31 19:40:3722namespace net {
[email protected]a9cea7542009-05-20 04:30:2323class ForceTLSState;
[email protected]b65ce0942009-03-16 20:13:3324class FtpTransactionFactory;
25class HttpTransactionFactory;
[email protected]8ac1a752008-07-31 19:40:3726}
[email protected]eaadd9052009-06-23 18:02:2327class 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]80d6524d2009-08-18 03:58:0934 : http_transaction_factory_(NULL),
[email protected]b65ce0942009-03-16 20:13:3335 ftp_transaction_factory_(NULL),
[email protected]a9cea7542009-05-20 04:30:2336 cookie_store_(NULL),
[email protected]d0a96b62009-07-28 19:41:3637 force_tls_state_(NULL) {
[email protected]db8f44c2008-12-13 04:52:0138 }
39
[email protected]8a00f00a2009-06-12 00:49:3840 net::HostResolver* host_resolver() const {
41 return host_resolver_;
42 }
43
[email protected]63de95b2008-12-10 04:11:2744 // Get the proxy service for this context.
45 net::ProxyService* proxy_service() const {
46 return proxy_service_;
47 }
48
[email protected]db36938c2009-08-19 21:48:4249 // Get the ssl config service for this context.
50 net::SSLConfigService* ssl_config_service() const {
51 return ssl_config_service_;
52 }
53
initial.commit586acc5fe2008-07-26 22:42:5254 // Gets the http transaction factory for this context.
55 net::HttpTransactionFactory* http_transaction_factory() {
[email protected]db8f44c2008-12-13 04:52:0156 return http_transaction_factory_;
initial.commit586acc5fe2008-07-26 22:42:5257 }
58
[email protected]b65ce0942009-03-16 20:13:3359 // Gets the ftp transaction factory for this context.
60 net::FtpTransactionFactory* ftp_transaction_factory() {
61 return ftp_transaction_factory_;
62 }
63
initial.commit586acc5fe2008-07-26 22:42:5264 // Gets the cookie store for this context.
[email protected]5f450e52009-07-28 13:28:1165 net::CookieStore* cookie_store() { return cookie_store_; }
initial.commit586acc5fe2008-07-26 22:42:5266
67 // Gets the cookie policy for this context.
[email protected]8ac1a752008-07-31 19:40:3768 net::CookiePolicy* cookie_policy() { return &cookie_policy_; }
initial.commit586acc5fe2008-07-26 22:42:5269
[email protected]a9cea7542009-05-20 04:30:2370 net::ForceTLSState* force_tls_state() { return force_tls_state_; }
71
[email protected]515838c2009-01-15 06:43:4872 // Gets the FTP authentication cache for this context.
73 net::FtpAuthCache* ftp_auth_cache() { return &ftp_auth_cache_; }
initial.commit586acc5fe2008-07-26 22:42:5274
initial.commit586acc5fe2008-07-26 22:42:5275 // 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]6f681a42009-01-27 22:28:5481 // 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.commit586acc5fe2008-07-26 22:42:5287
[email protected]c9825a42009-05-01 22:51:5088 // 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]eaadd9052009-06-23 18:02:2395 // 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]5f450e52009-07-28 13:28:1198 virtual bool InterceptCookie(const URLRequest* request, std::string* cookie) {
[email protected]eaadd9052009-06-23 18:02:2399 return true;
100 }
101
102 // Called before adding cookies to sent requests. Allows overriding
103 // requests to block sending of cookies.
[email protected]5f450e52009-07-28 13:28:11104 virtual bool AllowSendingCookies(const URLRequest* request) const {
[email protected]eaadd9052009-06-23 18:02:23105 return true;
106 }
107
initial.commit586acc5fe2008-07-26 22:42:52108 protected:
[email protected]6f681a42009-01-27 22:28:54109 friend class base::RefCountedThreadSafe<URLRequestContext>;
110
111 virtual ~URLRequestContext() {}
112
[email protected]db8f44c2008-12-13 04:52:01113 // The following members are expected to be initialized and owned by
114 // subclasses.
[email protected]94a0d3d92009-06-27 01:50:14115 scoped_refptr<net::HostResolver> host_resolver_;
[email protected]80d6524d2009-08-18 03:58:09116 scoped_refptr<net::ProxyService> proxy_service_;
[email protected]db36938c2009-08-19 21:48:42117 scoped_refptr<net::SSLConfigService> ssl_config_service_;
[email protected]db8f44c2008-12-13 04:52:01118 net::HttpTransactionFactory* http_transaction_factory_;
[email protected]b65ce0942009-03-16 20:13:33119 net::FtpTransactionFactory* ftp_transaction_factory_;
[email protected]5f450e52009-07-28 13:28:11120 net::CookieStore* 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_;
initial.commit586acc5fe2008-07-26 22:42:52124 std::string accept_language_;
125 std::string accept_charset_;
[email protected]c9825a42009-05-01 22:51:50126 // 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.commit586acc5fe2008-07-26 22:42:52130
131 private:
[email protected]6f681a42009-01-27 22:28:54132 DISALLOW_COPY_AND_ASSIGN(URLRequestContext);
initial.commit586acc5fe2008-07-26 22:42:52133};
134
[email protected]43530b32008-08-04 22:21:34135#endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_