| 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 // Interface for objects providing content setting rules. | 5 // Interface for objects providing content setting rules. |
| 6 | 6 |
| 7 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PROVIDER_H_ | 7 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PROVIDER_H_ |
| 8 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PROVIDER_H_ | 8 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PROVIDER_H_ |
| 9 #pragma once | 9 #pragma once |
| 10 | 10 |
| 11 #include <map> |
| 11 #include <string> | 12 #include <string> |
| 13 #include <utility> |
| 12 #include <vector> | 14 #include <vector> |
| 13 | 15 |
| 16 #include "base/synchronization/lock.h" |
| 14 #include "chrome/browser/content_settings/content_settings_pattern.h" | 17 #include "chrome/browser/content_settings/content_settings_pattern.h" |
| 15 #include "chrome/common/content_settings.h" | 18 #include "chrome/common/content_settings.h" |
| 16 | 19 |
| 17 class GURL; | 20 class GURL; |
| 18 | 21 |
| 19 namespace content_settings { | 22 namespace content_settings { |
| 20 | 23 |
| 21 class DefaultProviderInterface { | 24 class DefaultProviderInterface { |
| 22 public: | 25 public: |
| 23 virtual ~DefaultProviderInterface() {} | 26 virtual ~DefaultProviderInterface() {} |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // This should only be called on the UI thread. | 115 // This should only be called on the UI thread. |
| 113 virtual void ClearAllContentSettingsRules( | 116 virtual void ClearAllContentSettingsRules( |
| 114 ContentSettingsType content_type) = 0; | 117 ContentSettingsType content_type) = 0; |
| 115 | 118 |
| 116 // Resets all content settings to CONTENT_SETTINGS_DEFAULT. | 119 // Resets all content settings to CONTENT_SETTINGS_DEFAULT. |
| 117 // | 120 // |
| 118 // This should only be called on the UI thread. | 121 // This should only be called on the UI thread. |
| 119 virtual void ResetToDefaults() = 0; | 122 virtual void ResetToDefaults() = 0; |
| 120 }; | 123 }; |
| 121 | 124 |
| 125 typedef std::pair<ContentSettingsType, std::string> |
| 126 ContentSettingsTypeResourceIdentifierPair; |
| 127 typedef std::map<ContentSettingsTypeResourceIdentifierPair, ContentSetting> |
| 128 ResourceContentSettings; |
| 129 |
| 130 struct ExtendedContentSettings { |
| 131 ContentSettings content_settings; |
| 132 ResourceContentSettings content_settings_for_resources; |
| 133 }; |
| 134 |
| 135 // Map for ContentSettings. |
| 136 typedef std::map<std::string, ExtendedContentSettings> HostContentSettings; |
| 137 |
| 138 // BaseProvider is the abstract base class for all content-settings-provider |
| 139 // classes. |
| 140 class BaseProvider : public ProviderInterface { |
| 141 public: |
| 142 explicit BaseProvider(bool is_otr) |
| 143 : is_off_the_record_(is_otr) { |
| 144 } |
| 145 virtual ~BaseProvider() {} |
| 146 |
| 147 // Initializes the Provider. |
| 148 virtual void Init() = 0; |
| 149 |
| 150 // ProviderInterface Implementation |
| 151 virtual bool ContentSettingsTypeIsManaged( |
| 152 ContentSettingsType content_type) = 0; |
| 153 |
| 154 virtual ContentSetting GetContentSetting( |
| 155 const GURL& requesting_url, |
| 156 const GURL& embedding_url, |
| 157 ContentSettingsType content_type, |
| 158 const ResourceIdentifier& resource_identifier) const; |
| 159 |
| 160 virtual void SetContentSetting( |
| 161 const ContentSettingsPattern& requesting_pattern, |
| 162 const ContentSettingsPattern& embedding_pattern, |
| 163 ContentSettingsType content_type, |
| 164 const ResourceIdentifier& resource_identifier, |
| 165 ContentSetting content_setting) = 0; |
| 166 |
| 167 virtual void GetAllContentSettingsRules( |
| 168 ContentSettingsType content_type, |
| 169 const ResourceIdentifier& resource_identifier, |
| 170 Rules* content_setting_rules) const; |
| 171 |
| 172 virtual void ClearAllContentSettingsRules( |
| 173 ContentSettingsType content_type) = 0; |
| 174 |
| 175 virtual void ResetToDefaults() = 0; |
| 176 |
| 177 protected: |
| 178 // Returns true if the |content_type| requires a resource identifier. |
| 179 bool RequiresResourceIdentifier( |
| 180 ContentSettingsType content_type) const; |
| 181 |
| 182 // Returns true if the passed |settings| object contains only |
| 183 // CONTENT_SETTING_DEFAULT values. |
| 184 bool AllDefault(const ExtendedContentSettings& settings) const; |
| 185 |
| 186 // TODO(markusheintz): LEGACY method. Will be removed in a future re-factoring |
| 187 // step. |
| 188 ContentSettings GetNonDefaultContentSettings(const GURL& url) const; |
| 189 |
| 190 // Accessors |
| 191 HostContentSettings* host_content_settings() { |
| 192 return &host_content_settings_; |
| 193 } |
| 194 |
| 195 HostContentSettings* off_the_record_settings() { |
| 196 return &off_the_record_settings_; |
| 197 } |
| 198 |
| 199 base::Lock& lock() const { |
| 200 return lock_; |
| 201 } |
| 202 |
| 203 bool is_off_the_record() const { |
| 204 return is_off_the_record_; |
| 205 } |
| 206 |
| 207 private: |
| 208 // Copies of the pref data, so that we can read it on threads other than the |
| 209 // UI thread. |
| 210 HostContentSettings host_content_settings_; |
| 211 |
| 212 // Whether this settings map is for an OTR session. |
| 213 bool is_off_the_record_; |
| 214 |
| 215 // Differences to the preference-stored host content settings for |
| 216 // off-the-record settings. |
| 217 HostContentSettings off_the_record_settings_; |
| 218 |
| 219 // Used around accesses to the content_settings_ object to guarantee |
| 220 // thread safety. |
| 221 mutable base::Lock lock_; |
| 222 }; |
| 223 |
| 224 // ProviderUtil provides utility methods for content-settings-providers. |
| 225 class ProviderUtil { |
| 226 public: |
| 227 // Maps CONTENT_SETTING_ASK for the CONTENT_SETTINGS_TYPE_PLUGINS to |
| 228 // CONTENT_SETTING_BLOCK if click-to-play is not enabled. |
| 229 static ContentSetting ClickToPlayFixup(ContentSettingsType content_type, |
| 230 ContentSetting setting); |
| 231 }; |
| 232 |
| 122 } // namespace content_settings | 233 } // namespace content_settings |
| 123 | 234 |
| 124 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PROVIDER_H_ | 235 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PROVIDER_H_ |
| OLD | NEW |