OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_ | 5 #ifndef CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_ |
6 #define CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_ | 6 #define CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_ |
7 | 7 |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/linked_ptr.h" | 9 #include "base/linked_ptr.h" |
| 10 #include "net/base/cookie_policy.h" |
10 #include "chrome/browser/host_content_settings_map.h" | 11 #include "chrome/browser/host_content_settings_map.h" |
11 #include "chrome/browser/host_zoom_map.h" | 12 #include "chrome/browser/host_zoom_map.h" |
12 #include "chrome/browser/privacy_blacklist/blacklist.h" | 13 #include "chrome/browser/privacy_blacklist/blacklist.h" |
13 #include "chrome/browser/net/url_request_context_getter.h" | 14 #include "chrome/browser/net/url_request_context_getter.h" |
14 #include "chrome/common/appcache/chrome_appcache_service.h" | 15 #include "chrome/common/appcache/chrome_appcache_service.h" |
15 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
16 #include "chrome/common/notification_registrar.h" | 17 #include "chrome/common/notification_registrar.h" |
17 #include "chrome/common/pref_service.h" | 18 #include "chrome/common/pref_service.h" |
18 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
19 | 20 |
20 class CommandLine; | 21 class CommandLine; |
21 class Profile; | 22 class Profile; |
22 | 23 |
23 namespace net { | 24 namespace net { |
24 class ProxyConfig; | 25 class ProxyConfig; |
25 } | 26 } |
26 | 27 |
27 class ChromeURLRequestContext; | 28 class ChromeURLRequestContext; |
28 class ChromeURLRequestContextFactory; | 29 class ChromeURLRequestContextFactory; |
29 class IOThread; | 30 class IOThread; |
30 | 31 |
31 // Subclass of URLRequestContext which can be used to store extra information | 32 // Subclass of URLRequestContext which can be used to store extra information |
32 // for requests. | 33 // for requests. |
33 // | 34 // |
34 // All methods of this class must be called from the IO thread, | 35 // All methods of this class must be called from the IO thread, |
35 // including the constructor and destructor. | 36 // including the constructor and destructor. |
36 class ChromeURLRequestContext : public URLRequestContext { | 37 class ChromeURLRequestContext : public URLRequestContext, |
| 38 public net::CookiePolicy { |
37 public: | 39 public: |
38 // Maintains some extension-related state we need on the IO thread. | 40 // Maintains some extension-related state we need on the IO thread. |
39 // TODO(aa): It would be cool if the Extension objects in ExtensionsService | 41 // TODO(aa): It would be cool if the Extension objects in ExtensionsService |
40 // could be immutable and ref-counted so that we could use them directly from | 42 // could be immutable and ref-counted so that we could use them directly from |
41 // both threads. There is only a small amount of mutable state in Extension. | 43 // both threads. There is only a small amount of mutable state in Extension. |
42 struct ExtensionInfo { | 44 struct ExtensionInfo { |
43 ExtensionInfo(const FilePath& path, const std::string& default_locale, | 45 ExtensionInfo(const FilePath& path, const std::string& default_locale, |
44 const Extension::URLPatternList& extent, | 46 const Extension::URLPatternList& extent, |
45 const std::vector<std::string>& api_permissions) | 47 const std::vector<std::string>& api_permissions) |
46 : path(path), default_locale(default_locale), | 48 : path(path), default_locale(default_locale), |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 return host_content_settings_map_; | 106 return host_content_settings_map_; |
105 } | 107 } |
106 | 108 |
107 const HostZoomMap* host_zoom_map() const { return host_zoom_map_; } | 109 const HostZoomMap* host_zoom_map() const { return host_zoom_map_; } |
108 | 110 |
109 // Gets the Privacy Blacklist, if any for this context. | 111 // Gets the Privacy Blacklist, if any for this context. |
110 const Blacklist* GetPrivacyBlacklist() const; | 112 const Blacklist* GetPrivacyBlacklist() const; |
111 | 113 |
112 // Callback for when new extensions are loaded. Takes ownership of | 114 // Callback for when new extensions are loaded. Takes ownership of |
113 // |extension_info|. | 115 // |extension_info|. |
114 void OnNewExtensions( | 116 void OnNewExtensions(const std::string& id, ExtensionInfo* extension_info); |
115 const std::string& id, | |
116 ChromeURLRequestContext::ExtensionInfo* extension_info); | |
117 | 117 |
118 // Callback for when an extension is unloaded. | 118 // Callback for when an extension is unloaded. |
119 void OnUnloadedExtension(const std::string& id); | 119 void OnUnloadedExtension(const std::string& id); |
120 | 120 |
| 121 // False only if cookies are globally blocked without exception. |
| 122 bool AreCookiesEnabled() const; |
| 123 |
| 124 // CookiePolicy methods: |
| 125 virtual bool CanGetCookies(const GURL& url, const GURL& first_party); |
| 126 virtual bool CanSetCookie(const GURL& url, const GURL& first_party); |
| 127 |
121 protected: | 128 protected: |
122 // Copies the dependencies from |other| into |this|. If you use this | 129 // Copies the dependencies from |other| into |this|. If you use this |
123 // constructor, then you should hold a reference to |other|, as we | 130 // constructor, then you should hold a reference to |other|, as we |
124 // depend on |other| being alive. | 131 // depend on |other| being alive. |
125 explicit ChromeURLRequestContext(ChromeURLRequestContext* other); | 132 explicit ChromeURLRequestContext(ChromeURLRequestContext* other); |
126 virtual ~ChromeURLRequestContext(); | 133 virtual ~ChromeURLRequestContext(); |
127 | 134 |
128 public: | 135 public: |
129 // Setters to simplify initializing from factory objects. | 136 // Setters to simplify initializing from factory objects. |
130 | 137 |
131 void set_accept_language(const std::string& accept_language) { | 138 void set_accept_language(const std::string& accept_language) { |
132 accept_language_ = accept_language; | 139 accept_language_ = accept_language; |
133 } | 140 } |
134 void set_accept_charset(const std::string& accept_charset) { | 141 void set_accept_charset(const std::string& accept_charset) { |
135 accept_charset_ = accept_charset; | 142 accept_charset_ = accept_charset; |
136 } | 143 } |
137 void set_referrer_charset(const std::string& referrer_charset) { | 144 void set_referrer_charset(const std::string& referrer_charset) { |
138 referrer_charset_ = referrer_charset; | 145 referrer_charset_ = referrer_charset; |
139 } | 146 } |
140 void set_cookie_policy_type(net::CookiePolicy::Type type) { | |
141 cookie_policy_.set_type(type); | |
142 } | |
143 void set_extension_info( | 147 void set_extension_info( |
144 const ChromeURLRequestContext::ExtensionInfoMap& info) { | 148 const ChromeURLRequestContext::ExtensionInfoMap& info) { |
145 extension_info_ = info; | 149 extension_info_ = info; |
146 } | 150 } |
147 void set_transport_security_state( | 151 void set_transport_security_state( |
148 net::TransportSecurityState* state) { | 152 net::TransportSecurityState* state) { |
149 transport_security_state_ = state; | 153 transport_security_state_ = state; |
150 } | 154 } |
151 void set_ssl_config_service(net::SSLConfigService* service) { | 155 void set_ssl_config_service(net::SSLConfigService* service) { |
152 ssl_config_service_ = service; | 156 ssl_config_service_ = service; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 void set_privacy_blacklist(Blacklist* privacy_blacklist) { | 189 void set_privacy_blacklist(Blacklist* privacy_blacklist) { |
186 privacy_blacklist_ = privacy_blacklist; | 190 privacy_blacklist_ = privacy_blacklist; |
187 } | 191 } |
188 void set_appcache_service(ChromeAppCacheService* service) { | 192 void set_appcache_service(ChromeAppCacheService* service) { |
189 appcache_service_ = service; | 193 appcache_service_ = service; |
190 } | 194 } |
191 | 195 |
192 // Callback for when the accept language changes. | 196 // Callback for when the accept language changes. |
193 void OnAcceptLanguageChange(const std::string& accept_language); | 197 void OnAcceptLanguageChange(const std::string& accept_language); |
194 | 198 |
195 // Callback for when the cookie policy changes. | |
196 void OnCookiePolicyChange(net::CookiePolicy::Type type); | |
197 | |
198 // Callback for when the default charset changes. | 199 // Callback for when the default charset changes. |
199 void OnDefaultCharsetChange(const std::string& default_charset); | 200 void OnDefaultCharsetChange(const std::string& default_charset); |
200 | 201 |
201 protected: | 202 protected: |
202 ExtensionInfoMap extension_info_; | 203 ExtensionInfoMap extension_info_; |
203 | 204 |
204 // Path to the directory user scripts are stored in. | 205 // Path to the directory user scripts are stored in. |
205 FilePath user_script_dir_path_; | 206 FilePath user_script_dir_path_; |
206 | 207 |
207 scoped_refptr<ChromeAppCacheService> appcache_service_; | 208 scoped_refptr<ChromeAppCacheService> appcache_service_; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 // Creates a request context for media resources from a regular request | 310 // Creates a request context for media resources from a regular request |
310 // context. This helper method is called from CreateOriginalForMedia and | 311 // context. This helper method is called from CreateOriginalForMedia and |
311 // CreateOffTheRecordForMedia. | 312 // CreateOffTheRecordForMedia. |
312 static ChromeURLRequestContextGetter* CreateRequestContextForMedia( | 313 static ChromeURLRequestContextGetter* CreateRequestContextForMedia( |
313 Profile* profile, const FilePath& disk_cache_path, int cache_size, | 314 Profile* profile, const FilePath& disk_cache_path, int cache_size, |
314 bool off_the_record); | 315 bool off_the_record); |
315 | 316 |
316 // These methods simply forward to the corresponding method on | 317 // These methods simply forward to the corresponding method on |
317 // ChromeURLRequestContext. | 318 // ChromeURLRequestContext. |
318 void OnAcceptLanguageChange(const std::string& accept_language); | 319 void OnAcceptLanguageChange(const std::string& accept_language); |
319 void OnCookiePolicyChange(net::CookiePolicy::Type type); | |
320 void OnDefaultCharsetChange(const std::string& default_charset); | 320 void OnDefaultCharsetChange(const std::string& default_charset); |
321 | 321 |
322 // Saves the cookie store to |result| and signals |completion|. | 322 // Saves the cookie store to |result| and signals |completion|. |
323 void GetCookieStoreAsyncHelper(base::WaitableEvent* completion, | 323 void GetCookieStoreAsyncHelper(base::WaitableEvent* completion, |
324 net::CookieStore** result); | 324 net::CookieStore** result); |
325 | 325 |
326 // Access only from the UI thread. | 326 // Access only from the UI thread. |
327 PrefService* prefs_; | 327 PrefService* prefs_; |
328 | 328 |
329 // Deferred logic for creating a ChromeURLRequestContext. | 329 // Deferred logic for creating a ChromeURLRequestContext. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 | 363 |
364 // Values extracted from the Profile. | 364 // Values extracted from the Profile. |
365 // | 365 // |
366 // NOTE: If you add any parameters here, keep it in sync with | 366 // NOTE: If you add any parameters here, keep it in sync with |
367 // ApplyProfileParametersToContext(). | 367 // ApplyProfileParametersToContext(). |
368 bool is_media_; | 368 bool is_media_; |
369 bool is_off_the_record_; | 369 bool is_off_the_record_; |
370 std::string accept_language_; | 370 std::string accept_language_; |
371 std::string accept_charset_; | 371 std::string accept_charset_; |
372 std::string referrer_charset_; | 372 std::string referrer_charset_; |
373 net::CookiePolicy::Type cookie_policy_type_; | |
374 ChromeURLRequestContext::ExtensionInfoMap extension_info_; | 373 ChromeURLRequestContext::ExtensionInfoMap extension_info_; |
375 // TODO(aa): I think this can go away now as we no longer support standalone | 374 // TODO(aa): I think this can go away now as we no longer support standalone |
376 // user scripts. | 375 // user scripts. |
377 FilePath user_script_dir_path_; | 376 FilePath user_script_dir_path_; |
378 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; | 377 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; |
379 scoped_refptr<HostZoomMap> host_zoom_map_; | 378 scoped_refptr<HostZoomMap> host_zoom_map_; |
380 scoped_refptr<Blacklist> privacy_blacklist_; | 379 scoped_refptr<Blacklist> privacy_blacklist_; |
381 net::TransportSecurityState* transport_security_state_; | 380 net::TransportSecurityState* transport_security_state_; |
382 scoped_refptr<net::SSLConfigService> ssl_config_service_; | 381 scoped_refptr<net::SSLConfigService> ssl_config_service_; |
383 | 382 |
384 FilePath profile_dir_path_; | 383 FilePath profile_dir_path_; |
385 | 384 |
386 private: | 385 private: |
387 IOThread* const io_thread_; | 386 IOThread* const io_thread_; |
388 | 387 |
389 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextFactory); | 388 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextFactory); |
390 }; | 389 }; |
391 | 390 |
392 // Creates a proxy configuration using the overrides specified on the command | 391 // Creates a proxy configuration using the overrides specified on the command |
393 // line. Returns NULL if the system defaults should be used instead. | 392 // line. Returns NULL if the system defaults should be used instead. |
394 net::ProxyConfig* CreateProxyConfig(const CommandLine& command_line); | 393 net::ProxyConfig* CreateProxyConfig(const CommandLine& command_line); |
395 | 394 |
396 #endif // CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_ | 395 #endif // CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_ |
OLD | NEW |