| 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 |
| 11 | 11 |
| 12 #include <map> | 12 #include <map> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
| 18 #include "base/memory/linked_ptr.h" | 18 #include "base/memory/linked_ptr.h" |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
| 22 #include "chrome/browser/content_settings/content_settings_pattern.h" | 22 #include "chrome/browser/content_settings/content_settings_pattern.h" |
| 23 #include "chrome/browser/content_settings/content_settings_observer.h" | 23 #include "chrome/browser/content_settings/content_settings_observer.h" |
| 24 #include "chrome/browser/prefs/pref_change_registrar.h" | |
| 25 #include "chrome/common/content_settings.h" | 24 #include "chrome/common/content_settings.h" |
| 26 #include "content/browser/browser_thread.h" | 25 #include "content/browser/browser_thread.h" |
| 27 #include "content/common/notification_observer.h" | 26 #include "content/common/notification_observer.h" |
| 28 #include "content/common/notification_registrar.h" | 27 #include "content/common/notification_registrar.h" |
| 29 | 28 |
| 30 namespace content_settings { | 29 namespace content_settings { |
| 31 class DefaultProviderInterface; | 30 class DefaultProviderInterface; |
| 32 class ProviderInterface; | 31 class ProviderInterface; |
| 33 } // namespace content_settings | 32 } // namespace content_settings |
| 34 | 33 |
| 35 class ContentSettingsDetails; | 34 class ContentSettingsDetails; |
| 36 class ExtensionService; | 35 class ExtensionService; |
| 37 class GURL; | 36 class GURL; |
| 38 class PrefService; | 37 class PrefService; |
| 39 class Profile; | 38 class Profile; |
| 40 | 39 |
| 41 class HostContentSettingsMap | 40 class HostContentSettingsMap |
| 42 : public content_settings::Observer, | 41 : public content_settings::Observer, |
| 43 public NotificationObserver, | |
| 44 public base::RefCountedThreadSafe<HostContentSettingsMap> { | 42 public base::RefCountedThreadSafe<HostContentSettingsMap> { |
| 45 public: | 43 public: |
| 46 // TODO(markusheintz): I sold my soul to the devil on order to add this tuple. | 44 // TODO(markusheintz): I sold my soul to the devil on order to add this tuple. |
| 47 // I really want my soul back, so I really will change this ASAP. | 45 // I really want my soul back, so I really will change this ASAP. |
| 48 typedef Tuple4<ContentSettingsPattern, | 46 typedef Tuple4<ContentSettingsPattern, |
| 49 ContentSettingsPattern, | 47 ContentSettingsPattern, |
| 50 ContentSetting, | 48 ContentSetting, |
| 51 std::string> PatternSettingSourceTuple; | 49 std::string> PatternSettingSourceTuple; |
| 52 typedef std::vector<PatternSettingSourceTuple> SettingsForOneType; | 50 typedef std::vector<PatternSettingSourceTuple> SettingsForOneType; |
| 53 | 51 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // |resource_identifier| must be non-empty. Ownership of the returned |Value| | 84 // |resource_identifier| must be non-empty. Ownership of the returned |Value| |
| 87 // is transfered to the caller. | 85 // is transfered to the caller. |
| 88 // | 86 // |
| 89 // This may be called on any thread. | 87 // This may be called on any thread. |
| 90 Value* GetContentSettingValue( | 88 Value* GetContentSettingValue( |
| 91 const GURL& primary_url, | 89 const GURL& primary_url, |
| 92 const GURL& secondary_url, | 90 const GURL& secondary_url, |
| 93 ContentSettingsType content_type, | 91 ContentSettingsType content_type, |
| 94 const std::string& resource_identifier) const; | 92 const std::string& resource_identifier) const; |
| 95 | 93 |
| 96 // Gets the content setting for cookies. This takes the third party cookie | |
| 97 // flag into account, and therefore needs to know whether we read or write a | |
| 98 // cookie. | |
| 99 // | |
| 100 // This may be called on any thread. | |
| 101 ContentSetting GetCookieContentSetting( | |
| 102 const GURL& url, | |
| 103 const GURL& first_party_url, | |
| 104 bool setting_cookie) const; | |
| 105 | |
| 106 // Returns all ContentSettings which apply to the given URLs. For content | 94 // Returns all ContentSettings which apply to the given URLs. For content |
| 107 // setting types that require an additional resource identifier, the default | 95 // setting types that require an additional resource identifier, the default |
| 108 // content setting is returned. | 96 // content setting is returned. |
| 109 // | 97 // |
| 110 // This may be called on any thread. | 98 // This may be called on any thread. |
| 111 ContentSettings GetContentSettings( | 99 ContentSettings GetContentSettings( |
| 112 const GURL& primary_url, | 100 const GURL& primary_url, |
| 113 const GURL& secondary_url) const; | 101 const GURL& secondary_url) const; |
| 114 | 102 |
| 115 // For a given content type, returns all patterns with a non-default setting, | 103 // For a given content type, returns all patterns with a non-default setting, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 ContentSetting setting); | 145 ContentSetting setting); |
| 158 | 146 |
| 159 // Clears all host-specific settings for one content type. | 147 // Clears all host-specific settings for one content type. |
| 160 // | 148 // |
| 161 // This should only be called on the UI thread. | 149 // This should only be called on the UI thread. |
| 162 void ClearSettingsForOneType(ContentSettingsType content_type); | 150 void ClearSettingsForOneType(ContentSettingsType content_type); |
| 163 | 151 |
| 164 static bool IsSettingAllowedForType(ContentSetting setting, | 152 static bool IsSettingAllowedForType(ContentSetting setting, |
| 165 ContentSettingsType content_type); | 153 ContentSettingsType content_type); |
| 166 | 154 |
| 167 // This setting trumps any host-specific settings. | |
| 168 bool BlockThirdPartyCookies() const { return block_third_party_cookies_; } | |
| 169 bool IsBlockThirdPartyCookiesManaged() const { | |
| 170 return is_block_third_party_cookies_managed_; | |
| 171 } | |
| 172 | |
| 173 // Sets whether we block all third-party cookies. This method must not be | |
| 174 // invoked on an incognito map. | |
| 175 // | |
| 176 // This should only be called on the UI thread. | |
| 177 void SetBlockThirdPartyCookies(bool block); | |
| 178 | |
| 179 // Returns true if the default setting for the |content_type| is managed. | 155 // Returns true if the default setting for the |content_type| is managed. |
| 180 bool IsDefaultContentSettingManaged(ContentSettingsType content_type) const; | 156 bool IsDefaultContentSettingManaged(ContentSettingsType content_type) const; |
| 181 | 157 |
| 182 // Detaches the HostContentSettingsMap from all Profile-related objects like | 158 // Detaches the HostContentSettingsMap from all Profile-related objects like |
| 183 // PrefService. This methods needs to be called before destroying the Profile. | 159 // PrefService. This methods needs to be called before destroying the Profile. |
| 184 // Afterwards, none of the methods above that should only be called on the UI | 160 // Afterwards, none of the methods above that should only be called on the UI |
| 185 // thread should be called anymore. | 161 // thread should be called anymore. |
| 186 void ShutdownOnUIThread(); | 162 void ShutdownOnUIThread(); |
| 187 | 163 |
| 188 // content_settings::Observer implementation. | 164 // content_settings::Observer implementation. |
| 189 virtual void OnContentSettingChanged( | 165 virtual void OnContentSettingChanged( |
| 190 ContentSettingsPattern primary_pattern, | 166 ContentSettingsPattern primary_pattern, |
| 191 ContentSettingsPattern secondary_pattern, | 167 ContentSettingsPattern secondary_pattern, |
| 192 ContentSettingsType content_type, | 168 ContentSettingsType content_type, |
| 193 std::string resource_identifier); | 169 std::string resource_identifier); |
| 194 | 170 |
| 195 // NotificationObserver implementation. | 171 static bool ShouldAllowAllContent(const GURL& url, |
| 196 virtual void Observe(int type, | 172 ContentSettingsType content_type); |
| 197 const NotificationSource& source, | |
| 198 const NotificationDetails& details); | |
| 199 | 173 |
| 200 private: | 174 private: |
| 201 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; | 175 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; |
| 176 friend class CookieSettings; |
| 202 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; | 177 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; |
| 203 | 178 |
| 204 virtual ~HostContentSettingsMap(); | 179 virtual ~HostContentSettingsMap(); |
| 205 | 180 |
| 206 // Returns all non-default ContentSettings which apply to the given URLs. For | 181 // Returns all non-default ContentSettings which apply to the given URLs. For |
| 207 // content setting types that require an additional resource identifier, | 182 // content setting types that require an additional resource identifier, |
| 208 // CONTENT_SETTING_DEFAULT is returned. | 183 // CONTENT_SETTING_DEFAULT is returned. |
| 209 // | 184 // |
| 210 // This may be called on any thread. | 185 // This may be called on any thread. |
| 211 ContentSettings GetNonDefaultContentSettings( | 186 ContentSettings GetNonDefaultContentSettings( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 224 const GURL& secondary_url, | 199 const GURL& secondary_url, |
| 225 ContentSettingsType content_type, | 200 ContentSettingsType content_type, |
| 226 const std::string& resource_identifier) const; | 201 const std::string& resource_identifier) const; |
| 227 | 202 |
| 228 ContentSetting GetContentSettingInternal( | 203 ContentSetting GetContentSettingInternal( |
| 229 const GURL& primary_url, | 204 const GURL& primary_url, |
| 230 const GURL& secondary_url, | 205 const GURL& secondary_url, |
| 231 ContentSettingsType content_type, | 206 ContentSettingsType content_type, |
| 232 const std::string& resource_identifier) const; | 207 const std::string& resource_identifier) const; |
| 233 | 208 |
| 234 // Various migration methods (old cookie, popup and per-host data gets | |
| 235 // migrated to the new format). | |
| 236 void MigrateObsoleteCookiePref(); | |
| 237 | |
| 238 // Weak; owned by the Profile. | 209 // Weak; owned by the Profile. |
| 239 PrefService* prefs_; | 210 PrefService* prefs_; |
| 240 | 211 |
| 241 PrefChangeRegistrar pref_change_registrar_; | |
| 242 | |
| 243 // Whether this settings map is for an OTR session. | 212 // Whether this settings map is for an OTR session. |
| 244 bool is_off_the_record_; | 213 bool is_off_the_record_; |
| 245 | 214 |
| 246 // Whether we are currently updating preferences, this is used to ignore | 215 // Whether we are currently updating preferences, this is used to ignore |
| 247 // notifications from the preferences service that we triggered ourself. | 216 // notifications from the preferences service that we triggered ourself. |
| 248 bool updating_preferences_; | 217 bool updating_preferences_; |
| 249 | 218 |
| 250 // Default content setting providers. | 219 // Default content setting providers. |
| 251 std::vector<linked_ptr<content_settings::DefaultProviderInterface> > | 220 std::vector<linked_ptr<content_settings::DefaultProviderInterface> > |
| 252 default_content_settings_providers_; | 221 default_content_settings_providers_; |
| 253 | 222 |
| 254 // Content setting providers. | 223 // Content setting providers. |
| 255 std::vector<linked_ptr<content_settings::ProviderInterface> > | 224 std::vector<linked_ptr<content_settings::ProviderInterface> > |
| 256 content_settings_providers_; | 225 content_settings_providers_; |
| 257 | 226 |
| 258 // Used around accesses to the following objects to guarantee thread safety. | |
| 259 mutable base::Lock lock_; | |
| 260 | |
| 261 // Misc global settings. | |
| 262 bool block_third_party_cookies_; | |
| 263 bool is_block_third_party_cookies_managed_; | |
| 264 | |
| 265 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); | 227 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); |
| 266 }; | 228 }; |
| 267 | 229 |
| 268 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 230 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
| OLD | NEW |