| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 // Maps hostnames to custom content settings. Written on the UI thread and read | 5 // Maps hostnames to custom content settings. Written on the UI thread and read |
| 6 // on any thread. One instance per profile. | 6 // on any thread. One instance per profile. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 8 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
| 9 #define CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 9 #define CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
| 10 #pragma once | 10 #pragma once |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "content/browser/browser_thread.h" | 25 #include "content/browser/browser_thread.h" |
| 26 #include "content/common/notification_observer.h" | 26 #include "content/common/notification_observer.h" |
| 27 #include "content/common/notification_registrar.h" | 27 #include "content/common/notification_registrar.h" |
| 28 | 28 |
| 29 namespace content_settings { | 29 namespace content_settings { |
| 30 class DefaultProviderInterface; | 30 class DefaultProviderInterface; |
| 31 class ProviderInterface; | 31 class ProviderInterface; |
| 32 } // namespace content_settings | 32 } // namespace content_settings |
| 33 | 33 |
| 34 class ContentSettingsDetails; | 34 class ContentSettingsDetails; |
| 35 class CookieSettings; |
| 35 class ExtensionService; | 36 class ExtensionService; |
| 36 class GURL; | 37 class GURL; |
| 37 class PrefService; | 38 class PrefService; |
| 38 class Profile; | 39 class Profile; |
| 39 | 40 |
| 40 class HostContentSettingsMap | 41 class HostContentSettingsMap |
| 41 : public content_settings::Observer, | 42 : public content_settings::Observer, |
| 42 public NotificationObserver, | |
| 43 public base::RefCountedThreadSafe<HostContentSettingsMap> { | 43 public base::RefCountedThreadSafe<HostContentSettingsMap> { |
| 44 public: | 44 public: |
| 45 typedef Tuple4<ContentSettingsPattern, | 45 typedef Tuple4<ContentSettingsPattern, |
| 46 ContentSettingsPattern, | 46 ContentSettingsPattern, |
| 47 ContentSetting, | 47 ContentSetting, |
| 48 std::string> PatternSettingSourceTuple; | 48 std::string> PatternSettingSourceTuple; |
| 49 typedef std::vector<PatternSettingSourceTuple> SettingsForOneType; | 49 typedef std::vector<PatternSettingSourceTuple> SettingsForOneType; |
| 50 | 50 |
| 51 HostContentSettingsMap(PrefService* prefs, | 51 HostContentSettingsMap(PrefService* prefs, |
| 52 ExtensionService* extension_service, | 52 ExtensionService* extension_service, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 70 // require an resource identifier to be specified, the |resource_identifier| | 70 // require an resource identifier to be specified, the |resource_identifier| |
| 71 // must be non-empty. | 71 // must be non-empty. |
| 72 // | 72 // |
| 73 // This may be called on any thread. | 73 // This may be called on any thread. |
| 74 ContentSetting GetContentSetting( | 74 ContentSetting GetContentSetting( |
| 75 const GURL& primary_url, | 75 const GURL& primary_url, |
| 76 const GURL& secondary_url, | 76 const GURL& secondary_url, |
| 77 ContentSettingsType content_type, | 77 ContentSettingsType content_type, |
| 78 const std::string& resource_identifier) const; | 78 const std::string& resource_identifier) const; |
| 79 | 79 |
| 80 // Gets the content setting for cookies. This takes the third party cookie | |
| 81 // flag into account, and therefore needs to know whether we read or write a | |
| 82 // cookie. | |
| 83 // | |
| 84 // This may be called on any thread. | |
| 85 ContentSetting GetCookieContentSetting( | |
| 86 const GURL& url, | |
| 87 const GURL& first_party_url, | |
| 88 bool setting_cookie) const; | |
| 89 | |
| 90 // Returns a single ContentSetting which applies to the given URLs or | 80 // Returns a single ContentSetting which applies to the given URLs or |
| 91 // CONTENT_SETTING_DEFAULT, if no exception applies. Note that certain | 81 // CONTENT_SETTING_DEFAULT, if no exception applies. Note that certain |
| 92 // internal schemes are whitelisted. For ContentSettingsTypes that require an | 82 // internal schemes are whitelisted. For ContentSettingsTypes that require an |
| 93 // resource identifier to be specified, the |resource_identifier| must be | 83 // resource identifier to be specified, the |resource_identifier| must be |
| 94 // non-empty. | 84 // non-empty. |
| 95 // | 85 // |
| 96 // This may be called on any thread. | 86 // This may be called on any thread. |
| 97 ContentSetting GetNonDefaultContentSetting( | 87 ContentSetting GetNonDefaultContentSetting( |
| 98 const GURL& primary_url, | 88 const GURL& primary_url, |
| 99 const GURL& secondary_url, | 89 const GURL& secondary_url, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 124 // must be a non-NULL outparam. If this map was created for the | 114 // must be a non-NULL outparam. If this map was created for the |
| 125 // incognito profile, it will only return those settings differing from | 115 // incognito profile, it will only return those settings differing from |
| 126 // the main map. For ContentSettingsTypes that require an resource identifier | 116 // the main map. For ContentSettingsTypes that require an resource identifier |
| 127 // to be specified, the |resource_identifier| must be non-empty. | 117 // to be specified, the |resource_identifier| must be non-empty. |
| 128 // | 118 // |
| 129 // This may be called on any thread. | 119 // This may be called on any thread. |
| 130 void GetSettingsForOneType(ContentSettingsType content_type, | 120 void GetSettingsForOneType(ContentSettingsType content_type, |
| 131 const std::string& resource_identifier, | 121 const std::string& resource_identifier, |
| 132 SettingsForOneType* settings) const; | 122 SettingsForOneType* settings) const; |
| 133 | 123 |
| 124 // Returns a CookieSettings instance which can be used for reading and writing |
| 125 // cookie-related content settings. |
| 126 CookieSettings* GetCookieSettings(); |
| 127 |
| 134 // Sets the default setting for a particular content type. This method must | 128 // Sets the default setting for a particular content type. This method must |
| 135 // not be invoked on an incognito map. | 129 // not be invoked on an incognito map. |
| 136 // | 130 // |
| 137 // This should only be called on the UI thread. | 131 // This should only be called on the UI thread. |
| 138 void SetDefaultContentSetting(ContentSettingsType content_type, | 132 void SetDefaultContentSetting(ContentSettingsType content_type, |
| 139 ContentSetting setting); | 133 ContentSetting setting); |
| 140 | 134 |
| 141 // Sets the content setting for the given patterns and content type. | 135 // Sets the content setting for the given patterns and content type. |
| 142 // Setting the value to CONTENT_SETTING_DEFAULT causes the default setting | 136 // Setting the value to CONTENT_SETTING_DEFAULT causes the default setting |
| 143 // for that type to be used when loading pages matching this pattern. For | 137 // for that type to be used when loading pages matching this pattern. For |
| (...skipping 21 matching lines...) Expand all Loading... |
| 165 ContentSetting setting); | 159 ContentSetting setting); |
| 166 | 160 |
| 167 // Clears all host-specific settings for one content type. | 161 // Clears all host-specific settings for one content type. |
| 168 // | 162 // |
| 169 // This should only be called on the UI thread. | 163 // This should only be called on the UI thread. |
| 170 void ClearSettingsForOneType(ContentSettingsType content_type); | 164 void ClearSettingsForOneType(ContentSettingsType content_type); |
| 171 | 165 |
| 172 static bool IsSettingAllowedForType(ContentSetting setting, | 166 static bool IsSettingAllowedForType(ContentSetting setting, |
| 173 ContentSettingsType content_type); | 167 ContentSettingsType content_type); |
| 174 | 168 |
| 175 // This setting trumps any host-specific settings. | |
| 176 bool BlockThirdPartyCookies() const { return block_third_party_cookies_; } | |
| 177 bool IsBlockThirdPartyCookiesManaged() const { | |
| 178 return is_block_third_party_cookies_managed_; | |
| 179 } | |
| 180 | |
| 181 // Sets whether we block all third-party cookies. This method must not be | |
| 182 // invoked on an incognito map. | |
| 183 // | |
| 184 // This should only be called on the UI thread. | |
| 185 void SetBlockThirdPartyCookies(bool block); | |
| 186 | |
| 187 // Returns true if the default setting for the |content_type| is managed. | 169 // Returns true if the default setting for the |content_type| is managed. |
| 188 bool IsDefaultContentSettingManaged(ContentSettingsType content_type) const; | 170 bool IsDefaultContentSettingManaged(ContentSettingsType content_type) const; |
| 189 | 171 |
| 190 // Detaches the HostContentSettingsMap from all Profile-related objects like | 172 // Detaches the HostContentSettingsMap from all Profile-related objects like |
| 191 // PrefService. This methods needs to be called before destroying the Profile. | 173 // PrefService. This methods needs to be called before destroying the Profile. |
| 192 // Afterwards, none of the methods above that should only be called on the UI | 174 // Afterwards, none of the methods above that should only be called on the UI |
| 193 // thread should be called anymore. | 175 // thread should be called anymore. |
| 194 void ShutdownOnUIThread(); | 176 void ShutdownOnUIThread(); |
| 195 | 177 |
| 196 // content_settings::Observer implementation. | 178 // content_settings::Observer implementation. |
| 197 virtual void OnContentSettingChanged( | 179 virtual void OnContentSettingChanged( |
| 198 ContentSettingsPattern primary_pattern, | 180 ContentSettingsPattern primary_pattern, |
| 199 ContentSettingsPattern secondary_pattern, | 181 ContentSettingsPattern secondary_pattern, |
| 200 ContentSettingsType content_type, | 182 ContentSettingsType content_type, |
| 201 std::string resource_identifier); | 183 std::string resource_identifier); |
| 202 | 184 |
| 203 // NotificationObserver implementation. | 185 static bool ShouldAllowAllContent(const GURL& url); |
| 204 virtual void Observe(int type, | |
| 205 const NotificationSource& source, | |
| 206 const NotificationDetails& details); | |
| 207 | 186 |
| 208 private: | 187 private: |
| 209 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; | 188 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; |
| 210 | 189 |
| 211 virtual ~HostContentSettingsMap(); | 190 virtual ~HostContentSettingsMap(); |
| 212 | 191 |
| 213 ContentSetting GetContentSettingInternal( | 192 ContentSetting GetContentSettingInternal( |
| 214 const GURL& primary_url, | 193 const GURL& primary_url, |
| 215 const GURL& secondary_url, | 194 const GURL& secondary_url, |
| 216 ContentSettingsType content_type, | 195 ContentSettingsType content_type, |
| 217 const std::string& resource_identifier) const; | 196 const std::string& resource_identifier) const; |
| 218 | 197 |
| 219 // Various migration methods (old cookie, popup and per-host data gets | |
| 220 // migrated to the new format). | |
| 221 void MigrateObsoleteCookiePref(); | |
| 222 | |
| 223 // Weak; owned by the Profile. | 198 // Weak; owned by the Profile. |
| 224 PrefService* prefs_; | 199 PrefService* prefs_; |
| 225 | 200 |
| 226 PrefChangeRegistrar pref_change_registrar_; | |
| 227 | |
| 228 // Whether this settings map is for an OTR session. | 201 // Whether this settings map is for an OTR session. |
| 229 bool is_off_the_record_; | 202 bool is_off_the_record_; |
| 230 | 203 |
| 231 // Whether we are currently updating preferences, this is used to ignore | 204 // Whether we are currently updating preferences, this is used to ignore |
| 232 // notifications from the preferences service that we triggered ourself. | 205 // notifications from the preferences service that we triggered ourself. |
| 233 bool updating_preferences_; | 206 bool updating_preferences_; |
| 234 | 207 |
| 235 // Default content setting providers. | 208 // Default content setting providers. |
| 236 std::vector<linked_ptr<content_settings::DefaultProviderInterface> > | 209 std::vector<linked_ptr<content_settings::DefaultProviderInterface> > |
| 237 default_content_settings_providers_; | 210 default_content_settings_providers_; |
| 238 | 211 |
| 239 // Content setting providers. | 212 // Content setting providers. |
| 240 std::vector<linked_ptr<content_settings::ProviderInterface> > | 213 std::vector<linked_ptr<content_settings::ProviderInterface> > |
| 241 content_settings_providers_; | 214 content_settings_providers_; |
| 242 | 215 |
| 243 // Used around accesses to the following objects to guarantee thread safety. | 216 scoped_refptr<CookieSettings> cookie_settings_; |
| 244 mutable base::Lock lock_; | |
| 245 | |
| 246 // Misc global settings. | |
| 247 bool block_third_party_cookies_; | |
| 248 bool is_block_third_party_cookies_managed_; | |
| 249 | 217 |
| 250 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); | 218 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); |
| 251 }; | 219 }; |
| 252 | 220 |
| 253 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 221 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
| OLD | NEW |