| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_COOKIE_SETTINGS_H_ | 5 #ifndef COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_COOKIE_SETTINGS_H_ |
| 6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_COOKIE_SETTINGS_H_ | 6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_COOKIE_SETTINGS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 public: | 30 public: |
| 31 // Creates a new CookieSettings instance. | 31 // Creates a new CookieSettings instance. |
| 32 // The caller is responsible for ensuring that |extension_scheme| is valid for | 32 // The caller is responsible for ensuring that |extension_scheme| is valid for |
| 33 // the whole lifetime of this instance. | 33 // the whole lifetime of this instance. |
| 34 CookieSettings(HostContentSettingsMap* host_content_settings_map, | 34 CookieSettings(HostContentSettingsMap* host_content_settings_map, |
| 35 PrefService* prefs, | 35 PrefService* prefs, |
| 36 const char* extension_scheme); | 36 const char* extension_scheme); |
| 37 | 37 |
| 38 // Returns the default content setting (CONTENT_SETTING_ALLOW, | 38 // Returns the default content setting (CONTENT_SETTING_ALLOW, |
| 39 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. If | 39 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. If |
| 40 // |provider_id| is not NULL, the id of the provider which provided the | 40 // |provider_id| is not nullptr, the id of the provider which provided the |
| 41 // default setting is assigned to it. | 41 // default setting is assigned to it. |
| 42 // | 42 // |
| 43 // This may be called on any thread. | 43 // This may be called on any thread. |
| 44 ContentSetting GetDefaultCookieSetting(std::string* provider_id) const; | 44 ContentSetting GetDefaultCookieSetting(std::string* provider_id) const; |
| 45 | 45 |
| 46 // Returns true if the page identified by (|url|, |first_party_url|) is | 46 // Returns true if the page identified by (|url|, |first_party_url|) is |
| 47 // allowed to read cookies. | 47 // allowed to read cookies. |
| 48 // | 48 // |
| 49 // This may be called on any thread. | 49 // This may be called on any thread. |
| 50 bool IsReadingCookieAllowed(const GURL& url, | 50 bool IsReadingCookieAllowed(const GURL& url, |
| 51 const GURL& first_party_url) const; | 51 const GURL& first_party_url) const; |
| 52 | 52 |
| 53 // Returns true if the page identified by (|url|, |first_party_url|) is | 53 // Returns true if the page identified by (|url|, |first_party_url|) is |
| 54 // allowed to set cookies (permanent or session only). | 54 // allowed to set cookies (permanent or session only). |
| 55 // | 55 // |
| 56 // This may be called on any thread. | 56 // This may be called on any thread. |
| 57 bool IsSettingCookieAllowed(const GURL& url, | 57 bool IsSettingCookieAllowed(const GURL& url, |
| 58 const GURL& first_party_url) const; | 58 const GURL& first_party_url) const; |
| 59 | 59 |
| 60 // Gets the results from IsReadingCookieAllowed and IsSettingCookieAllowed in |
| 61 // a performance efficient way. |
| 62 // |
| 63 // This may be called on any thread. |
| 64 void GetReadingAndSettingCookieAllowed(const GURL& url, |
| 65 const GURL& first_party_url, |
| 66 bool* reading_cookie_allowed, |
| 67 bool* setting_cookie_allowed) const; |
| 68 |
| 60 // Returns true if the cookie set by a page identified by |url| should be | 69 // Returns true if the cookie set by a page identified by |url| should be |
| 61 // session only. Querying this only makes sense if |IsSettingCookieAllowed| | 70 // session only. Querying this only makes sense if |IsSettingCookieAllowed| |
| 62 // has returned true. | 71 // has returned true. |
| 63 // | 72 // |
| 64 // This may be called on any thread. | 73 // This may be called on any thread. |
| 65 bool IsCookieSessionOnly(const GURL& url) const; | 74 bool IsCookieSessionOnly(const GURL& url) const; |
| 66 | 75 |
| 67 // Returns all patterns with a non-default cookie setting, mapped to their | 76 // Returns all patterns with a non-default cookie setting, mapped to their |
| 68 // actual settings, in the precedence order of the setting rules. |settings| | 77 // actual settings, in the precedence order of the setting rules. |settings| |
| 69 // must be a non-NULL outparam. | 78 // must be a non-nullptr outparam. |
| 70 // | 79 // |
| 71 // This may be called on any thread. | 80 // This may be called on any thread. |
| 72 void GetCookieSettings(ContentSettingsForOneType* settings) const; | 81 void GetCookieSettings(ContentSettingsForOneType* settings) const; |
| 73 | 82 |
| 74 // Sets the default content setting (CONTENT_SETTING_ALLOW, | 83 // Sets the default content setting (CONTENT_SETTING_ALLOW, |
| 75 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. | 84 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. |
| 76 // | 85 // |
| 77 // This should only be called on the UI thread. | 86 // This should only be called on the UI thread. |
| 78 void SetDefaultCookieSetting(ContentSetting setting); | 87 void SetDefaultCookieSetting(ContentSetting setting); |
| 79 | 88 |
| 80 // Sets the cookie setting for the given url. | 89 // Sets the cookie setting for the given url. |
| 81 // | 90 // |
| 82 // This should only be called on the UI thread. | 91 // This should only be called on the UI thread. |
| 83 void SetCookieSetting(const GURL& primary_url, ContentSetting setting); | 92 void SetCookieSetting(const GURL& primary_url, ContentSetting setting); |
| 84 | 93 |
| 85 // Resets the cookie setting for the given url. | 94 // Resets the cookie setting for the given url. |
| 86 // | 95 // |
| 87 // This should only be called on the UI thread. | 96 // This should only be called on the UI thread. |
| 88 void ResetCookieSetting(const GURL& primary_url); | 97 void ResetCookieSetting(const GURL& primary_url); |
| 89 | 98 |
| 90 bool IsStorageDurable(const GURL& origin) const; | 99 bool IsStorageDurable(const GURL& origin) const; |
| 91 | 100 |
| 92 // Detaches the |CookieSettings| from |PrefService|. This methods needs to be | 101 // Detaches the |CookieSettings| from |PrefService|. This methods needs to be |
| 93 // called before destroying the service. Afterwards, only const methods can be | 102 // called before destroying the service. Afterwards, only const methods can be |
| 94 // called. | 103 // called. |
| 95 void ShutdownOnUIThread() override; | 104 void ShutdownOnUIThread() override; |
| 96 | 105 |
| 97 // A helper for applying third party cookie blocking rules. | 106 // A helper for applying third party cookie blocking rules. |
| 98 ContentSetting GetCookieSetting( | 107 void GetCookieSetting(const GURL& url, |
| 99 const GURL& url, | 108 const GURL& first_party_url, |
| 100 const GURL& first_party_url, | 109 content_settings::SettingSource* source, |
| 101 bool setting_cookie, | 110 ContentSetting* reading_cookie, |
| 102 content_settings::SettingSource* source) const; | 111 ContentSetting* setting_cookie) const; |
| 103 | 112 |
| 104 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 113 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 105 | 114 |
| 106 private: | 115 private: |
| 107 ~CookieSettings() override; | 116 ~CookieSettings() override; |
| 108 | 117 |
| 109 void OnBlockThirdPartyCookiesChanged(); | 118 void OnBlockThirdPartyCookiesChanged(); |
| 110 | 119 |
| 111 // Returns true if the "block third party cookies" preference is set. | 120 // Returns true if the "block third party cookies" preference is set. |
| 112 // | 121 // |
| (...skipping 10 matching lines...) Expand all Loading... |
| 123 mutable base::Lock lock_; | 132 mutable base::Lock lock_; |
| 124 | 133 |
| 125 bool block_third_party_cookies_; | 134 bool block_third_party_cookies_; |
| 126 | 135 |
| 127 DISALLOW_COPY_AND_ASSIGN(CookieSettings); | 136 DISALLOW_COPY_AND_ASSIGN(CookieSettings); |
| 128 }; | 137 }; |
| 129 | 138 |
| 130 } // namespace content_settings | 139 } // namespace content_settings |
| 131 | 140 |
| 132 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_COOKIE_SETTINGS_H_ | 141 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_COOKIE_SETTINGS_H_ |
| OLD | NEW |