Chromium Code Reviews| 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 21 matching lines...) Expand all Loading... | |
| 32 } // namespace content_settings | 32 } // namespace content_settings |
| 33 | 33 |
| 34 class ContentSettingsDetails; | 34 class ContentSettingsDetails; |
| 35 class ExtensionService; | 35 class ExtensionService; |
| 36 class GURL; | 36 class GURL; |
| 37 class PrefService; | 37 class PrefService; |
| 38 class Profile; | 38 class Profile; |
| 39 | 39 |
| 40 class HostContentSettingsMap | 40 class HostContentSettingsMap |
| 41 : public content_settings::Observer, | 41 : public content_settings::Observer, |
| 42 public NotificationObserver, | |
| 43 public base::RefCountedThreadSafe<HostContentSettingsMap> { | 42 public base::RefCountedThreadSafe<HostContentSettingsMap> { |
| 44 public: | 43 public: |
| 45 typedef Tuple4<ContentSettingsPattern, | 44 typedef Tuple4<ContentSettingsPattern, |
| 46 ContentSettingsPattern, | 45 ContentSettingsPattern, |
| 47 ContentSetting, | 46 ContentSetting, |
| 48 std::string> PatternSettingSourceTuple; | 47 std::string> PatternSettingSourceTuple; |
| 49 typedef std::vector<PatternSettingSourceTuple> SettingsForOneType; | 48 typedef std::vector<PatternSettingSourceTuple> SettingsForOneType; |
| 50 | 49 |
| 51 HostContentSettingsMap(PrefService* prefs, | 50 HostContentSettingsMap(PrefService* prefs, |
| 52 ExtensionService* extension_service, | 51 ExtensionService* extension_service, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 70 // require an resource identifier to be specified, the |resource_identifier| | 69 // require an resource identifier to be specified, the |resource_identifier| |
| 71 // must be non-empty. | 70 // must be non-empty. |
| 72 // | 71 // |
| 73 // This may be called on any thread. | 72 // This may be called on any thread. |
| 74 ContentSetting GetContentSetting( | 73 ContentSetting GetContentSetting( |
| 75 const GURL& primary_url, | 74 const GURL& primary_url, |
| 76 const GURL& secondary_url, | 75 const GURL& secondary_url, |
| 77 ContentSettingsType content_type, | 76 ContentSettingsType content_type, |
| 78 const std::string& resource_identifier) const; | 77 const std::string& resource_identifier) const; |
| 79 | 78 |
| 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 | 79 // Returns a single ContentSetting which applies to the given URLs or |
| 91 // CONTENT_SETTING_DEFAULT, if no exception applies. Note that certain | 80 // CONTENT_SETTING_DEFAULT, if no exception applies. Note that certain |
| 92 // internal schemes are whitelisted. For ContentSettingsTypes that require an | 81 // internal schemes are whitelisted. For ContentSettingsTypes that require an |
| 93 // resource identifier to be specified, the |resource_identifier| must be | 82 // resource identifier to be specified, the |resource_identifier| must be |
| 94 // non-empty. | 83 // non-empty. |
| 95 // | 84 // |
| 96 // This may be called on any thread. | 85 // This may be called on any thread. |
| 97 ContentSetting GetNonDefaultContentSetting( | 86 ContentSetting GetNonDefaultContentSetting( |
| 98 const GURL& primary_url, | 87 const GURL& primary_url, |
| 99 const GURL& secondary_url, | 88 const GURL& secondary_url, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 ContentSetting setting); | 154 ContentSetting setting); |
| 166 | 155 |
| 167 // Clears all host-specific settings for one content type. | 156 // Clears all host-specific settings for one content type. |
| 168 // | 157 // |
| 169 // This should only be called on the UI thread. | 158 // This should only be called on the UI thread. |
| 170 void ClearSettingsForOneType(ContentSettingsType content_type); | 159 void ClearSettingsForOneType(ContentSettingsType content_type); |
| 171 | 160 |
| 172 static bool IsSettingAllowedForType(ContentSetting setting, | 161 static bool IsSettingAllowedForType(ContentSetting setting, |
| 173 ContentSettingsType content_type); | 162 ContentSettingsType content_type); |
| 174 | 163 |
| 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. | 164 // Returns true if the default setting for the |content_type| is managed. |
| 188 bool IsDefaultContentSettingManaged(ContentSettingsType content_type) const; | 165 bool IsDefaultContentSettingManaged(ContentSettingsType content_type) const; |
| 189 | 166 |
| 190 // Detaches the HostContentSettingsMap from all Profile-related objects like | 167 // Detaches the HostContentSettingsMap from all Profile-related objects like |
| 191 // PrefService. This methods needs to be called before destroying the Profile. | 168 // 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 | 169 // Afterwards, none of the methods above that should only be called on the UI |
| 193 // thread should be called anymore. | 170 // thread should be called anymore. |
| 194 void ShutdownOnUIThread(); | 171 void ShutdownOnUIThread(); |
| 195 | 172 |
| 196 // content_settings::Observer implementation. | 173 // content_settings::Observer implementation. |
| 197 virtual void OnContentSettingChanged( | 174 virtual void OnContentSettingChanged( |
| 198 ContentSettingsPattern primary_pattern, | 175 ContentSettingsPattern primary_pattern, |
| 199 ContentSettingsPattern secondary_pattern, | 176 ContentSettingsPattern secondary_pattern, |
| 200 ContentSettingsType content_type, | 177 ContentSettingsType content_type, |
| 201 std::string resource_identifier); | 178 std::string resource_identifier); |
| 202 | 179 |
| 203 // NotificationObserver implementation. | |
| 204 virtual void Observe(int type, | |
| 205 const NotificationSource& source, | |
| 206 const NotificationDetails& details); | |
| 207 | |
| 208 private: | 180 private: |
| 209 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; | 181 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; |
| 210 | 182 |
| 211 virtual ~HostContentSettingsMap(); | 183 virtual ~HostContentSettingsMap(); |
| 212 | 184 |
| 213 ContentSetting GetContentSettingInternal( | 185 ContentSetting GetContentSettingInternal( |
| 214 const GURL& primary_url, | 186 const GURL& primary_url, |
| 215 const GURL& secondary_url, | 187 const GURL& secondary_url, |
| 216 ContentSettingsType content_type, | 188 ContentSettingsType content_type, |
| 217 const std::string& resource_identifier) const; | 189 const std::string& resource_identifier) const; |
| 218 | 190 |
| 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. | 191 // Weak; owned by the Profile. |
| 224 PrefService* prefs_; | 192 PrefService* prefs_; |
| 225 | 193 |
| 226 PrefChangeRegistrar pref_change_registrar_; | |
| 227 | |
| 228 // Whether this settings map is for an OTR session. | 194 // Whether this settings map is for an OTR session. |
| 229 bool is_off_the_record_; | 195 bool is_off_the_record_; |
| 230 | 196 |
| 231 // Whether we are currently updating preferences, this is used to ignore | 197 // Whether we are currently updating preferences, this is used to ignore |
| 232 // notifications from the preferences service that we triggered ourself. | 198 // notifications from the preferences service that we triggered ourself. |
| 233 bool updating_preferences_; | 199 bool updating_preferences_; |
| 234 | 200 |
| 235 // Default content setting providers. | 201 // Default content setting providers. |
| 236 std::vector<linked_ptr<content_settings::DefaultProviderInterface> > | 202 std::vector<linked_ptr<content_settings::DefaultProviderInterface> > |
| 237 default_content_settings_providers_; | 203 default_content_settings_providers_; |
| 238 | 204 |
| 239 // Content setting providers. | 205 // Content setting providers. |
| 240 std::vector<linked_ptr<content_settings::ProviderInterface> > | 206 std::vector<linked_ptr<content_settings::ProviderInterface> > |
| 241 content_settings_providers_; | 207 content_settings_providers_; |
| 242 | 208 |
| 209 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); | |
| 210 }; | |
| 211 | |
| 212 // FIXME(marja): This should be moved into a separate file. | |
|
markusheintz_
2011/08/24 12:29:40
Please move to a new file: cookie_settings.h
marja
2011/08/25 13:56:11
Done.
| |
| 213 class CookieContentSettings | |
|
markusheintz_
2011/08/24 12:29:40
Maybe we could just call it 'CookieSettings' since
marja
2011/08/25 13:56:11
Done.
| |
| 214 : public NotificationObserver, | |
| 215 public base::RefCountedThreadSafe<CookieContentSettings>{ | |
| 216 public: | |
| 217 CookieContentSettings( | |
| 218 HostContentSettingsMap* host_content_settings_map, | |
| 219 PrefService* prefs, | |
| 220 bool incognito); | |
| 221 | |
| 222 bool Allow(const GURL& url, | |
|
markusheintz_
2011/08/24 12:29:40
I guess you should add a comment here that describ
markusheintz_
2011/08/24 12:29:40
I just wonder whether this method should be called
marja
2011/08/25 13:56:11
Done.
marja
2011/08/25 13:56:11
Done.
| |
| 223 const GURL& first_party_url, | |
| 224 bool setting_cookie) const; | |
| 225 | |
| 226 bool EnforceSessionOnly(const GURL& url) const; | |
|
markusheintz_
2011/08/24 12:29:40
Add a comment please.
markusheintz_
2011/08/24 12:29:40
Analog to the proposed name of the method above th
marja
2011/08/25 13:56:11
Done.
marja
2011/08/25 13:56:11
Done.
| |
| 227 | |
| 228 // This setting trumps any host-specific settings. | |
| 229 bool BlockThirdPartyCookies() const { return block_third_party_cookies_; } | |
| 230 bool IsBlockThirdPartyCookiesManaged() const { | |
| 231 return is_block_third_party_cookies_managed_; | |
| 232 } | |
| 233 | |
| 234 // Sets whether we block all third-party cookies. This method must not be | |
| 235 // invoked on an incognito map. | |
| 236 // | |
| 237 // This should only be called on the UI thread. | |
| 238 void SetBlockThirdPartyCookies(bool block); | |
| 239 | |
| 240 // NotificationObserver implementation. | |
| 241 virtual void Observe(int type, | |
| 242 const NotificationSource& source, | |
| 243 const NotificationDetails& details); | |
| 244 | |
| 245 // Detaches the HostContentSettingsMap from all Profile-related objects like | |
|
markusheintz_
2011/08/24 12:29:40
Please update the comment. s/HostContentSettingsMa
marja
2011/08/25 13:56:11
Done.
| |
| 246 // PrefService. This methods needs to be called before destroying the Profile. | |
| 247 // Afterwards, none of the methods above that should only be called on the UI | |
| 248 // thread should be called anymore. | |
| 249 void ShutdownOnUIThread(); | |
| 250 | |
| 251 private: | |
| 252 // Various migration methods (old cookie, popup and per-host data gets | |
| 253 // migrated to the new format). | |
| 254 void MigrateObsoleteCookiePref(); | |
|
markusheintz_
2011/08/24 12:29:40
This method is around for quite a while. I guess w
marja
2011/09/01 11:03:19
Should I also remove const char kCookieBehavior[]
| |
| 255 | |
| 256 ContentSetting GetCookieContentSetting(const GURL& url, | |
| 257 const GURL& first_party_url, | |
| 258 bool setting_cookie) const; | |
| 259 | |
| 260 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; | |
| 261 | |
| 262 // Weak; owned by the profile. | |
| 263 PrefService* prefs_; | |
| 264 PrefChangeRegistrar pref_change_registrar_; | |
| 265 | |
| 266 bool is_off_the_record_; | |
| 267 | |
| 243 // Used around accesses to the following objects to guarantee thread safety. | 268 // Used around accesses to the following objects to guarantee thread safety. |
| 244 mutable base::Lock lock_; | 269 mutable base::Lock lock_; |
| 245 | 270 |
| 246 // Misc global settings. | 271 // Misc global settings. |
| 247 bool block_third_party_cookies_; | 272 bool block_third_party_cookies_; |
| 248 bool is_block_third_party_cookies_managed_; | 273 bool is_block_third_party_cookies_managed_; |
| 249 | |
| 250 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); | |
| 251 }; | 274 }; |
| 252 | 275 |
| 253 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 276 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
| OLD | NEW |