| 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/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "chrome/browser/content_settings/content_settings_observer.h" | 22 #include "chrome/browser/content_settings/content_settings_observer.h" |
| 23 #include "chrome/browser/content_settings/content_settings_provider.h" |
| 23 #include "chrome/browser/prefs/pref_change_registrar.h" | 24 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 24 #include "chrome/common/content_settings.h" | 25 #include "chrome/common/content_settings.h" |
| 25 #include "chrome/common/content_settings_pattern.h" | 26 #include "chrome/common/content_settings_pattern.h" |
| 26 #include "content/browser/browser_thread.h" | 27 #include "content/browser/browser_thread.h" |
| 27 #include "content/common/notification_observer.h" | 28 #include "content/common/notification_observer.h" |
| 28 #include "content/common/notification_registrar.h" | 29 #include "content/common/notification_registrar.h" |
| 29 | 30 |
| 30 namespace content_settings { | 31 namespace content_settings { |
| 31 class DefaultProviderInterface; | 32 class DefaultProviderInterface; |
| 32 class ProviderInterface; | 33 class ProviderInterface; |
| 33 } // namespace content_settings | 34 } // namespace content_settings |
| 34 | 35 |
| 35 class ContentSettingsDetails; | 36 class ContentSettingsDetails; |
| 36 class ExtensionService; | 37 class ExtensionService; |
| 37 class GURL; | 38 class GURL; |
| 38 class PrefService; | 39 class PrefService; |
| 39 class Profile; | 40 class Profile; |
| 40 | 41 |
| 41 class HostContentSettingsMap | 42 class HostContentSettingsMap |
| 42 : public content_settings::Observer, | 43 : public content_settings::Observer, |
| 43 public NotificationObserver, | 44 public NotificationObserver, |
| 44 public base::RefCountedThreadSafe<HostContentSettingsMap> { | 45 public base::RefCountedThreadSafe<HostContentSettingsMap> { |
| 45 public: | 46 public: |
| 46 // 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. | |
| 48 typedef Tuple4<ContentSettingsPattern, | |
| 49 ContentSettingsPattern, | |
| 50 ContentSetting, | |
| 51 std::string> PatternSettingSourceTuple; | |
| 52 typedef std::vector<PatternSettingSourceTuple> SettingsForOneType; | |
| 53 | |
| 54 HostContentSettingsMap(PrefService* prefs, | 47 HostContentSettingsMap(PrefService* prefs, |
| 55 ExtensionService* extension_service, | 48 ExtensionService* extension_service, |
| 56 bool incognito); | 49 bool incognito); |
| 57 | 50 |
| 58 static void RegisterUserPrefs(PrefService* prefs); | 51 static void RegisterUserPrefs(PrefService* prefs); |
| 59 | 52 |
| 60 // Returns the default setting for a particular content type. | 53 // Returns the default setting for a particular content type. |
| 61 // | 54 // |
| 62 // This may be called on any thread. | 55 // This may be called on any thread. |
| 63 ContentSetting GetDefaultContentSetting( | 56 ContentSetting GetDefaultContentSetting( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // Returns all ContentSettings which apply to the given URLs. For content | 99 // Returns all ContentSettings which apply to the given URLs. For content |
| 107 // setting types that require an additional resource identifier, the default | 100 // setting types that require an additional resource identifier, the default |
| 108 // content setting is returned. | 101 // content setting is returned. |
| 109 // | 102 // |
| 110 // This may be called on any thread. | 103 // This may be called on any thread. |
| 111 ContentSettings GetContentSettings( | 104 ContentSettings GetContentSettings( |
| 112 const GURL& primary_url, | 105 const GURL& primary_url, |
| 113 const GURL& secondary_url) const; | 106 const GURL& secondary_url) const; |
| 114 | 107 |
| 115 // For a given content type, returns all patterns with a non-default setting, | 108 // For a given content type, returns all patterns with a non-default setting, |
| 116 // mapped to their actual settings, in lexicographical order. |settings| | 109 // mapped to their actual settings. Settings of each provider are sorted |
| 117 // must be a non-NULL outparam. If this map was created for the | 110 // according to |sort_function|. |settings| must be a non-NULL outparam. If |
| 118 // incognito profile, it will only return those settings differing from | 111 // this map was created for the incognito profile, it will only return those |
| 119 // the main map. For ContentSettingsTypes that require an resource identifier | 112 // settings differing from the main map. For ContentSettingsTypes that require |
| 120 // to be specified, the |resource_identifier| must be non-empty. | 113 // an resource identifier to be specified, the |resource_identifier| must be |
| 114 // non-empty. |
| 121 // | 115 // |
| 122 // This may be called on any thread. | 116 // This may be called on any thread. |
| 123 void GetSettingsForOneType(ContentSettingsType content_type, | 117 void GetSettingsForOneType( |
| 124 const std::string& resource_identifier, | 118 ContentSettingsType content_type, |
| 125 SettingsForOneType* settings) const; | 119 const std::string& resource_identifier, |
| 120 content_settings::ProviderInterface::Rule::SortFunction sort_function, |
| 121 ContentSettingsForOneType* settings) const; |
| 126 | 122 |
| 127 // Sets the default setting for a particular content type. This method must | 123 // Sets the default setting for a particular content type. This method must |
| 128 // not be invoked on an incognito map. | 124 // not be invoked on an incognito map. |
| 129 // | 125 // |
| 130 // This should only be called on the UI thread. | 126 // This should only be called on the UI thread. |
| 131 void SetDefaultContentSetting(ContentSettingsType content_type, | 127 void SetDefaultContentSetting(ContentSettingsType content_type, |
| 132 ContentSetting setting); | 128 ContentSetting setting); |
| 133 | 129 |
| 134 // Sets the content setting for the given patterns and content type. | 130 // Sets the content setting for the given patterns and content type. |
| 135 // Setting the value to CONTENT_SETTING_DEFAULT causes the default setting | 131 // Setting the value to CONTENT_SETTING_DEFAULT causes the default setting |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 mutable base::Lock lock_; | 255 mutable base::Lock lock_; |
| 260 | 256 |
| 261 // Misc global settings. | 257 // Misc global settings. |
| 262 bool block_third_party_cookies_; | 258 bool block_third_party_cookies_; |
| 263 bool is_block_third_party_cookies_managed_; | 259 bool is_block_third_party_cookies_managed_; |
| 264 | 260 |
| 265 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); | 261 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); |
| 266 }; | 262 }; |
| 267 | 263 |
| 268 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 264 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
| OLD | NEW |