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

Side by Side Diff: chrome/browser/host_content_settings_map.h

Issue 2878075: Introduce a resource identifier for content settings. (Closed)
Patch Set: updates Created 10 years, 4 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_HOST_CONTENT_SETTINGS_MAP_H_ 8 #ifndef CHROME_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_
9 #define CHROME_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ 9 #define CHROME_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_
10 #pragma once 10 #pragma once
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 std::string pattern_; 66 std::string pattern_;
67 }; 67 };
68 68
69 // Details for the CONTENT_SETTINGS_CHANGED notification. This is sent when 69 // Details for the CONTENT_SETTINGS_CHANGED notification. This is sent when
70 // content settings change for at least one host. If settings change for more 70 // content settings change for at least one host. If settings change for more
71 // than one pattern in one user interaction, this will usually send a single 71 // than one pattern in one user interaction, this will usually send a single
72 // notification with update_all() returning true instead of one notification 72 // notification with update_all() returning true instead of one notification
73 // for each pattern. 73 // for each pattern.
74 class ContentSettingsDetails { 74 class ContentSettingsDetails {
75 public: 75 public:
76 // Update the setting that matches this pattern/content type. 76 // Update the setting that matches this pattern/content type/resource.
77 ContentSettingsDetails(const Pattern& pattern, ContentSettingsType type) 77 ContentSettingsDetails(const Pattern& pattern,
78 : pattern_(pattern), type_(type) {} 78 ContentSettingsType type,
79 79 const std::string& resource_identifier)
80 // No pattern is specified. Update all settings for this content type. 80 : pattern_(pattern),
81 explicit ContentSettingsDetails(ContentSettingsType type) : type_(type) {} 81 type_(type),
82 82 resource_identifier_(resource_identifier) {}
83 // No content type or pattern is specified. Update all settings.
84 ContentSettingsDetails() : type_(CONTENT_SETTINGS_TYPE_DEFAULT) {}
85 83
86 // The pattern whose settings have changed. 84 // The pattern whose settings have changed.
87 const Pattern& pattern() const { return pattern_; } 85 const Pattern& pattern() const { return pattern_; }
88 86
89 // True if all settings should be updated for the given type. 87 // True if all settings should be updated for the given type.
90 bool update_all() const { return pattern_.AsString().empty(); } 88 bool update_all() const { return pattern_.AsString().empty(); }
91 89
92 // The type of the pattern whose settings have changed. 90 // The type of the pattern whose settings have changed.
93 ContentSettingsType type() const { return type_; } 91 ContentSettingsType type() const { return type_; }
94 92
93 // The resource identifier for the settings type that has changed.
94 const std::string& resource_identifier() const {
95 return resource_identifier_;
96 }
97
95 // True if all types should be updated. If update_all() is false, this will 98 // True if all types should be updated. If update_all() is false, this will
96 // be false as well (although the reverse does not hold true). 99 // be false as well (although the reverse does not hold true).
97 bool update_all_types() const { 100 bool update_all_types() const {
98 return CONTENT_SETTINGS_TYPE_DEFAULT == type_; 101 return CONTENT_SETTINGS_TYPE_DEFAULT == type_;
99 } 102 }
100 103
101 private: 104 private:
102 Pattern pattern_; 105 Pattern pattern_;
103 ContentSettingsType type_; 106 ContentSettingsType type_;
107 std::string resource_identifier_;
104 }; 108 };
105 109
106 110
107 typedef std::pair<Pattern, ContentSetting> PatternSettingPair; 111 typedef std::pair<Pattern, ContentSetting> PatternSettingPair;
108 typedef std::vector<PatternSettingPair> SettingsForOneType; 112 typedef std::vector<PatternSettingPair> SettingsForOneType;
109 113
110 explicit HostContentSettingsMap(Profile* profile); 114 explicit HostContentSettingsMap(Profile* profile);
111 ~HostContentSettingsMap(); 115 ~HostContentSettingsMap();
112 116
113 static void RegisterUserPrefs(PrefService* prefs); 117 static void RegisterUserPrefs(PrefService* prefs);
114 118
115 // Returns the default setting for a particular content type. 119 // Returns the default setting for a particular content type.
116 // 120 //
117 // This may be called on any thread. 121 // This may be called on any thread.
118 ContentSetting GetDefaultContentSetting( 122 ContentSetting GetDefaultContentSetting(
119 ContentSettingsType content_type) const; 123 ContentSettingsType content_type) const;
120 124
121 // Returns a single ContentSetting which applies to a given URL. Note that 125 // Returns a single ContentSetting which applies to a given URL. Note that
122 // certain internal schemes are whitelisted. 126 // certain internal schemes are whitelisted. For ContentSettingsTypes that
127 // require an resource identifier to be specified, the |resource_identifier|
128 // must be non-empty.
123 // 129 //
124 // This may be called on any thread. 130 // This may be called on any thread.
125 ContentSetting GetContentSetting(const GURL& url, 131 ContentSetting GetContentSetting(
126 ContentSettingsType content_type) const; 132 const GURL& url,
133 ContentSettingsType content_type,
134 const std::string& resource_identifier) const;
127 135
128 // Returns all ContentSettings which apply to a given URL. 136 // Returns a single ContentSetting which applies to a given URL or
137 // CONTENT_SETTING_DEFAULT, if no exception applies. Note that certain
138 // internal schemes are whitelisted. For ContentSettingsTypes that require an
139 // resource identifier to be specified, the |resource_identifier| must be
140 // non-empty.
141 //
142 // This may be called on any thread.
143 ContentSetting GetNonDefaultContentSetting(
144 const GURL& url,
145 ContentSettingsType content_type,
146 const std::string& resource_identifier) const;
147
148 // Returns all ContentSettings which apply to a given URL. For content
149 // setting types that require an additional resource identifier, the default
150 // content setting is returned.
129 // 151 //
130 // This may be called on any thread. 152 // This may be called on any thread.
131 ContentSettings GetContentSettings(const GURL& url) const; 153 ContentSettings GetContentSettings(const GURL& url) const;
132 154
155 // Returns all non-default ContentSettings which apply to a given URL. For
156 // content setting types that require an additional resource identifier,
157 // CONTENT_SETTING_DEFAULT is returned.
158 //
159 // This may be called on any thread.
160 ContentSettings GetNonDefaultContentSettings(const GURL& url) const;
161
133 // For a given content type, returns all patterns with a non-default setting, 162 // For a given content type, returns all patterns with a non-default setting,
134 // mapped to their actual settings, in lexicographical order. |settings| 163 // mapped to their actual settings, in lexicographical order. |settings|
135 // must be a non-NULL outparam. If this map was created for the 164 // must be a non-NULL outparam. If this map was created for the
136 // off-the-record profile, it will only return those settings differing from 165 // off-the-record profile, it will only return those settings differing from
137 // the main map. 166 // the main map. For ContentSettingsTypes that require an resource identifier
167 // to be specified, the |resource_identifier| must be non-empty.
138 // 168 //
139 // This may be called on any thread. 169 // This may be called on any thread.
140 void GetSettingsForOneType(ContentSettingsType content_type, 170 void GetSettingsForOneType(ContentSettingsType content_type,
171 const std::string& resource_identifier,
141 SettingsForOneType* settings) const; 172 SettingsForOneType* settings) const;
142 173
143 // Sets the default setting for a particular content type. This method must 174 // Sets the default setting for a particular content type. This method must
144 // not be invoked on an off-the-record map. 175 // not be invoked on an off-the-record map.
145 // 176 //
146 // This should only be called on the UI thread. 177 // This should only be called on the UI thread.
147 void SetDefaultContentSetting(ContentSettingsType content_type, 178 void SetDefaultContentSetting(ContentSettingsType content_type,
148 ContentSetting setting); 179 ContentSetting setting);
149 180
150 // Sets the blocking setting for a particular pattern and content type. 181 // Sets the blocking setting for a particular pattern and content type.
151 // Setting the value to CONTENT_SETTING_DEFAULT causes the default setting for 182 // Setting the value to CONTENT_SETTING_DEFAULT causes the default setting
152 // that type to be used when loading pages matching this pattern. 183 // for that type to be used when loading pages matching this pattern. For
184 // ContentSettingsTypes that require an resource identifier to be specified,
185 // the |resource_identifier| must be non-empty.
153 // 186 //
154 // This should only be called on the UI thread. 187 // This should only be called on the UI thread.
155 void SetContentSetting(const Pattern& pattern, 188 void SetContentSetting(const Pattern& pattern,
156 ContentSettingsType content_type, 189 ContentSettingsType content_type,
190 const std::string& resource_identifier,
157 ContentSetting setting); 191 ContentSetting setting);
158 192
159 // Convenience method to add a content setting for a given URL, making sure 193 // Convenience method to add a content setting for a given URL, making sure
160 // that there is no setting overriding it. 194 // that there is no setting overriding it. For ContentSettingsTypes that
195 // require an resource identifier to be specified, the |resource_identifier|
196 // must be non-empty.
197 //
161 // This should only be called on the UI thread. 198 // This should only be called on the UI thread.
162 void AddExceptionForURL(const GURL& url, 199 void AddExceptionForURL(const GURL& url,
163 ContentSettingsType content_type, 200 ContentSettingsType content_type,
201 const std::string& resource_identifier,
164 ContentSetting setting); 202 ContentSetting setting);
165 203
166 // Clears all host-specific settings for one content type. 204 // Clears all host-specific settings for one content type.
167 // 205 //
168 // This should only be called on the UI thread. 206 // This should only be called on the UI thread.
169 void ClearSettingsForOneType(ContentSettingsType content_type); 207 void ClearSettingsForOneType(ContentSettingsType content_type);
170 208
209 // Whether the |content_type| requires an additional resource identifier for
210 // accessing content settings.
211 bool RequiresResourceIdentifier(ContentSettingsType content_type) const;
212
171 // This setting trumps any host-specific settings. 213 // This setting trumps any host-specific settings.
172 bool BlockThirdPartyCookies() const { return block_third_party_cookies_; } 214 bool BlockThirdPartyCookies() const { return block_third_party_cookies_; }
173 215
174 // Sets whether we block all third-party cookies. This method must not be 216 // Sets whether we block all third-party cookies. This method must not be
175 // invoked on an off-the-record map. 217 // invoked on an off-the-record map.
176 // 218 //
177 // This should only be called on the UI thread. 219 // This should only be called on the UI thread.
178 void SetBlockThirdPartyCookies(bool block); 220 void SetBlockThirdPartyCookies(bool block);
179 221
180 // Resets all settings levels. 222 // Resets all settings levels.
181 // 223 //
182 // This should only be called on the UI thread. 224 // This should only be called on the UI thread.
183 void ResetToDefaults(); 225 void ResetToDefaults();
184 226
185 // Whether this settings map is associated with an OTR session. 227 // Whether this settings map is associated with an OTR session.
186 bool IsOffTheRecord(); 228 bool IsOffTheRecord();
187 229
188 // NotificationObserver implementation. 230 // NotificationObserver implementation.
189 virtual void Observe(NotificationType type, 231 virtual void Observe(NotificationType type,
190 const NotificationSource& source, 232 const NotificationSource& source,
191 const NotificationDetails& details); 233 const NotificationDetails& details);
192 234
193 private: 235 private:
194 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; 236 friend class base::RefCountedThreadSafe<HostContentSettingsMap>;
195 237
196 typedef std::map<std::string, ContentSettings> HostContentSettings; 238 typedef std::pair<ContentSettingsType, std::string>
239 ContentSettingsTypeResourceIdentifierPair;
240 typedef std::map<ContentSettingsTypeResourceIdentifierPair, ContentSetting>
241 ResourceContentSettings;
197 242
198 // The names of the ContentSettingsType values, for use with dictionary prefs. 243 struct ExtendedContentSettings {
199 static const wchar_t* kTypeNames[CONTENT_SETTINGS_NUM_TYPES]; 244 ContentSettings content_settings;
245 ResourceContentSettings content_settings_for_resources;
246 };
200 247
201 // The default setting for each content type. 248 typedef std::map<std::string, ExtendedContentSettings> HostContentSettings;
202 static const ContentSetting kDefaultSettings[CONTENT_SETTINGS_NUM_TYPES];
203
204 // Returns true if we should allow all content types for this URL. This is
205 // true for various internal objects like chrome:// URLs, so UI and other
206 // things users think of as "not webpages" don't break.
207 static bool ShouldAllowAllContent(const GURL& url);
208 249
209 // Sets the fields of |settings| based on the values in |dictionary|. 250 // Sets the fields of |settings| based on the values in |dictionary|.
210 void GetSettingsFromDictionary(const DictionaryValue* dictionary, 251 void GetSettingsFromDictionary(const DictionaryValue* dictionary,
211 ContentSettings* settings); 252 ContentSettings* settings);
212 253
254 // Populates |settings| based on the values in |dictionary|.
255 void GetResourceSettingsFromDictionary(const DictionaryValue* dictionary,
256 ResourceContentSettings* settings);
257
213 // Forces the default settings to be explicitly set instead of themselves 258 // Forces the default settings to be explicitly set instead of themselves
214 // being CONTENT_SETTING_DEFAULT. 259 // being CONTENT_SETTING_DEFAULT.
215 void ForceDefaultsToBeExplicit(); 260 void ForceDefaultsToBeExplicit();
216 261
217 // Returns true if |settings| consists entirely of CONTENT_SETTING_DEFAULT. 262 // Returns true if |settings| consists entirely of CONTENT_SETTING_DEFAULT.
218 bool AllDefault(const ContentSettings& settings) const; 263 bool AllDefault(const ExtendedContentSettings& settings) const;
219 264
220 // Reads the default settings from the prefereces service. If |overwrite| is 265 // Reads the default settings from the prefereces service. If |overwrite| is
221 // true and the preference is missing, the local copy will be cleared as well. 266 // true and the preference is missing, the local copy will be cleared as well.
222 void ReadDefaultSettings(bool overwrite); 267 void ReadDefaultSettings(bool overwrite);
223 268
224 // Reads the host exceptions from the prefereces service. If |overwrite| is 269 // Reads the host exceptions from the prefereces service. If |overwrite| is
225 // true and the preference is missing, the local copy will be cleared as well. 270 // true and the preference is missing, the local copy will be cleared as well.
226 void ReadExceptions(bool overwrite); 271 void ReadExceptions(bool overwrite);
227 272
228 // Informs observers that content settings have changed. Make sure that 273 // Informs observers that content settings have changed. Make sure that
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 }; 308 };
264 309
265 // Stream operator so HostContentSettingsMap::Pattern can be used in 310 // Stream operator so HostContentSettingsMap::Pattern can be used in
266 // assertion statements. 311 // assertion statements.
267 inline std::ostream& operator<<( 312 inline std::ostream& operator<<(
268 std::ostream& out, const HostContentSettingsMap::Pattern& pattern) { 313 std::ostream& out, const HostContentSettingsMap::Pattern& pattern) {
269 return out << pattern.AsString(); 314 return out << pattern.AsString();
270 } 315 }
271 316
272 #endif // CHROME_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ 317 #endif // CHROME_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_
OLDNEW
« no previous file with comments | « chrome/browser/gtk/options/content_exceptions_window_gtk_unittest.cc ('k') | chrome/browser/host_content_settings_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698