Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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. | |
| 4 | |
| 5 // Maps hostnames to cookie settings. Written on the UI thread and read on any | |
| 6 // thread. One instance per profile. | |
| 7 | |
| 8 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ | |
| 9 #define CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ | |
| 10 #pragma once | |
| 11 | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/synchronization/lock.h" | |
| 14 #include "chrome/browser/content_settings/host_content_settings_map.h" | |
| 15 #include "chrome/browser/prefs/pref_change_registrar.h" | |
| 16 #include "chrome/common/content_settings.h" | |
| 17 #include "content/common/notification_observer.h" | |
| 18 | |
| 19 class ContentSettingsPattern; | |
| 20 class GURL; | |
| 21 class Profile; | |
| 22 | |
| 23 // A frontend to the cookie-specific settings of HostContentSettingsMap. Handles | |
| 24 // cookie-specific logic such as blocking third-party cookies. | |
| 25 class CookieSettings | |
| 26 : public NotificationObserver, | |
| 27 public base::RefCountedThreadSafe<CookieSettings> { | |
| 28 public: | |
| 29 CookieSettings( | |
| 30 HostContentSettingsMap* host_content_settings_map, | |
| 31 PrefService* prefs); | |
| 32 | |
| 33 virtual ~CookieSettings(); | |
| 34 | |
| 35 // Returns the CookieSettings associated with the profile. | |
| 36 // | |
| 37 // This should only be called on the UI thread. | |
| 38 static CookieSettings* GetForProfile(Profile* profile); | |
| 39 | |
| 40 // Returns the default content setting (CONTENT_SETTING_ALLOW, | |
| 41 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. | |
| 42 // | |
| 43 // This may be called on any thread. | |
| 44 ContentSetting GetDefaultCookieSetting() const; | |
| 45 | |
| 46 // Returns true if the page identified by (url, first_party_url) is allowed to | |
| 47 // read cookies. | |
| 48 // | |
| 49 // This may be called on any thread. | |
| 50 bool IsReadingCookieAllowed(const GURL& url, | |
| 51 const GURL& first_party_url) const; | |
| 52 | |
| 53 // Returns true if the page identified by (url, first_party_url) is allowed to | |
| 54 // set a cookie (permanent or session only). | |
| 55 // | |
| 56 // This may be called on any thread. | |
| 57 bool IsSettingCookieAllowed(const GURL& url, | |
| 58 const GURL& first_party_url) const; | |
| 59 | |
| 60 // Returns true if the cookie set by a page identified by url should be | |
| 61 // session only. Querying this only makes sense if IsSettingCookieAllowed has | |
| 62 // returned true. | |
| 63 // | |
| 64 // This may be called on any thread. | |
| 65 bool IsCookieSessionOnly(const GURL& url) const; | |
| 66 | |
| 67 // For returns all patterns with a non-default cookie setting, mapped to their | |
| 68 // actual settings, in lexicographical order. |settings| must be a non-NULL | |
| 69 // outparam. If this CookieSettings was created for the incognito profile, it | |
| 70 // will only return those settings differing from the main | |
| 71 // CookieSettings. Returns false if the cookie settings are in an inconsistent | |
| 72 // state between setting the two content setting types, true otherwise. | |
| 73 // | |
| 74 // This may be called on any thread. | |
| 75 void GetCookieSettings( | |
| 76 HostContentSettingsMap::SettingsForOneType* settings) const; | |
| 77 | |
| 78 // Sets the default content setting (CONTENT_SETTING_ALLOW, | |
| 79 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. | |
| 80 // | |
| 81 // This should only be called on the UI thread. | |
| 82 void SetDefaultCookieSetting(ContentSetting setting); | |
| 83 | |
| 84 // Sets the cookie setting to CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK or | |
| 85 // CONTENT_SETTING_SESSION_ONLY for (url, first_party_url) pairs where url | |
| 86 // matches primary_pattern. | |
| 87 // | |
| 88 // This should only be called on the UI thread. | |
| 89 void SetCookieSetting(const ContentSettingsPattern& primary_pattern, | |
| 90 ContentSetting setting); | |
| 91 | |
| 92 // Resets the cookie setting for (url, first_party_url) pais where url matches | |
| 93 // primary_pattern. | |
| 94 // | |
| 95 // This should only be called on the UI thread. | |
| 96 void ResetCookieSetting(const ContentSettingsPattern& primary_pattern); | |
| 97 | |
| 98 // NotificationObserver implementation. | |
| 99 virtual void Observe(int type, | |
| 100 const NotificationSource& source, | |
| 101 const NotificationDetails& details); | |
|
Bernhard Bauer
2011/09/14 16:01:36
Could you add OVERRIDE here?
| |
| 102 | |
| 103 // Detaches the CookieSettings from all Profile-related objects like | |
| 104 // PrefService. This methods needs to be called before destroying the Profile. | |
| 105 // Afterwards, none of the methods above that should only be called on the UI | |
| 106 // thread should be called anymore. | |
| 107 void ShutdownOnUIThread(); | |
| 108 | |
| 109 private: | |
| 110 class Factory; | |
| 111 | |
| 112 // A helper for retrieving data for CONTENT_TYPE_COOKIES and | |
| 113 // CONTENT_TYPE_COOKIES_SESSION_ONLY. | |
| 114 ContentSetting GetCookieContentSetting(const GURL& url, | |
| 115 const GURL& first_party_url, | |
| 116 ContentSettingsType content_type, | |
| 117 bool setting_cookie) const; | |
| 118 | |
| 119 // This setting trumps any host-specific settings. | |
| 120 // | |
| 121 // This method may be called on any thread. | |
| 122 bool ShouldBlockThirdPartyCookies() const; | |
| 123 | |
| 124 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; | |
| 125 PrefChangeRegistrar pref_change_registrar_; | |
| 126 | |
| 127 // Used around accesses to block_third_party_cookies_ to guarantee thread | |
| 128 // safety. | |
| 129 mutable base::Lock lock_; | |
| 130 | |
| 131 bool block_third_party_cookies_; | |
| 132 }; | |
| 133 | |
| 134 #endif // CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ | |
| OLD | NEW |