Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: chrome/browser/content_settings/content_settings_provider.h

Issue 6484035: Add a content_settings::BaseProvider for code that is shared by all content settings providers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 PolicyProvider classes.
Bernhard Bauer 2011/02/14 16:58:36 Nit: and also for PrefProviders?
markusheintz_ 2011/02/14 18:25:28 Done.
139 class BaseProvider : public ProviderInterface {
Bernhard Bauer 2011/02/14 16:58:36 With this class and ProviderUtil below, this file
markusheintz_ 2011/02/14 18:25:28 You are right this file grew into a real beast now
140 public:
141 explicit BaseProvider(bool is_otr)
142 : is_off_the_record_(is_otr) {
143 }
144 virtual ~BaseProvider() {}
145
146 // Initializes the Provider.
147 virtual void Init() = 0;
148
149 // ProviderInterface Implementation
150 virtual bool ContentSettingsTypeIsManaged(
151 ContentSettingsType content_type) = 0;
152
153 virtual ContentSetting GetContentSetting(
154 const GURL& requesting_url,
155 const GURL& embedding_url,
156 ContentSettingsType content_type,
157 const ResourceIdentifier& resource_identifier) const;
158
159 virtual void SetContentSetting(
160 const ContentSettingsPattern& requesting_pattern,
161 const ContentSettingsPattern& embedding_pattern,
162 ContentSettingsType content_type,
163 const ResourceIdentifier& resource_identifier,
164 ContentSetting content_setting) = 0;
165
166 virtual void GetAllContentSettingsRules(
167 ContentSettingsType content_type,
168 const ResourceIdentifier& resource_identifier,
169 Rules* content_setting_rules) const;
170
171 virtual void ClearAllContentSettingsRules(
172 ContentSettingsType content_type) = 0;
173
174 virtual void ResetToDefaults() = 0;
175
176 protected:
177 // Returns true if the |content_type| requires a resource identifier.
178 bool RequiresResourceIdentifier(
179 ContentSettingsType content_type) const;
180
181 // Returns true if the passed |settings| object contains only
182 // CONTENT_SETTING_DEFAULT values.
183 bool AllDefault(const ExtendedContentSettings& settings) const;
184
185 // TODO(markusheintz): LEGACY method. Will be removed in a futur re-factoring
Bernhard Bauer 2011/02/14 16:58:36 Nit: "future"
markusheintz_ 2011/02/14 18:25:28 Done.
186 // step.
187 ContentSettings GetNonDefaultContentSettings(const GURL& url) const;
188
189 // Accessors
190 HostContentSettings* host_content_settings() {
191 return &host_content_settings_;
192 }
193
194 HostContentSettings* off_the_record_settings() {
195 return &off_the_record_settings_;
196 }
197
198 base::Lock& lock() const {
199 return lock_;
200 }
201
202 bool is_off_the_record() const {
203 return is_off_the_record_;
204 }
205
206 private:
207 // Copies of the pref data, so that we can read it on threads other than the
208 // UI thread.
209 HostContentSettings host_content_settings_;
210
211 // Whether this settings map is for an OTR session.
212 bool is_off_the_record_;
213
214 // Differences to the preference-stored host content settings for
215 // off-the-record settings.
216 HostContentSettings off_the_record_settings_;
217
218 // Used around accesses to the content_settings_ object to guarantee
219 // thread safety.
220 mutable base::Lock lock_;
221 };
222
223 // ProviderUtil provides utility methods for content-settings-providers.
224 class ProviderUtil {
225 public:
226 // Maps CONTENT_SETTING_ASK for the CONTENT_SETTINGS_TYPE_PLUGINS to
227 // CONTENT_SETTING_BLOCK if click-to-play is not enabled.
228 static ContentSetting ClickToPlayFixup(ContentSettingsType content_type,
229 ContentSetting setting);
230 };
231
122 } // namespace content_settings 232 } // namespace content_settings
123 233
124 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PROVIDER_H_ 234 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698