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 #include "chrome/browser/content_settings/host_content_settings_map.h" | 5 #include "chrome/browser/content_settings/host_content_settings_map.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 HostContentSettingsMap::NUM_PROVIDER_TYPES, | 61 HostContentSettingsMap::NUM_PROVIDER_TYPES, |
62 kProviderSourceMap_has_incorrect_size); | 62 kProviderSourceMap_has_incorrect_size); |
63 | 63 |
64 bool ContentTypeHasCompoundValue(ContentSettingsType type) { | 64 bool ContentTypeHasCompoundValue(ContentSettingsType type) { |
65 // Values for content type CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE are | 65 // Values for content type CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE are |
66 // of type dictionary/map. Compound types like dictionaries can't be mapped to | 66 // of type dictionary/map. Compound types like dictionaries can't be mapped to |
67 // the type |ContentSetting|. | 67 // the type |ContentSetting|. |
68 return type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE; | 68 return type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE; |
69 } | 69 } |
70 | 70 |
71 ContentSetting GetDefaultSetting( | 71 // Returns true if the |content_type| supports a resource identifier. |
72 content_settings::RuleIterator* rule_iterator) { | 72 // Resource identifiers are supported (but not required) for plug-ins. |
73 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); | 73 bool SupportsResourceIdentifier(ContentSettingsType content_type) { |
74 while (rule_iterator->HasNext()) { | 74 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; |
75 content_settings::Rule rule = rule_iterator->Next(); | |
76 if (rule.primary_pattern == wildcard && | |
77 rule.secondary_pattern == wildcard) { | |
78 return content_settings::ValueToContentSetting(rule.value.get()); | |
79 } | |
80 } | |
81 return CONTENT_SETTING_DEFAULT; | |
82 } | 75 } |
83 | 76 |
84 } // namespace | 77 } // namespace |
85 | 78 |
86 HostContentSettingsMap::HostContentSettingsMap( | 79 HostContentSettingsMap::HostContentSettingsMap( |
87 PrefService* prefs, | 80 PrefService* prefs, |
88 ExtensionService* extension_service, | 81 ExtensionService* extension_service, |
89 bool incognito) | 82 bool incognito) |
90 : prefs_(prefs), | 83 : prefs_(prefs), |
91 is_off_the_record_(incognito) { | 84 is_off_the_record_(incognito) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 content_settings::DefaultProvider::RegisterUserPrefs(prefs); | 118 content_settings::DefaultProvider::RegisterUserPrefs(prefs); |
126 content_settings::PrefProvider::RegisterUserPrefs(prefs); | 119 content_settings::PrefProvider::RegisterUserPrefs(prefs); |
127 content_settings::PolicyProvider::RegisterUserPrefs(prefs); | 120 content_settings::PolicyProvider::RegisterUserPrefs(prefs); |
128 } | 121 } |
129 | 122 |
130 ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider( | 123 ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider( |
131 ContentSettingsType content_type, | 124 ContentSettingsType content_type, |
132 content_settings::ProviderInterface* provider) const { | 125 content_settings::ProviderInterface* provider) const { |
133 scoped_ptr<content_settings::RuleIterator> rule_iterator( | 126 scoped_ptr<content_settings::RuleIterator> rule_iterator( |
134 provider->GetRuleIterator(content_type, "", false)); | 127 provider->GetRuleIterator(content_type, "", false)); |
135 return GetDefaultSetting(rule_iterator.get()); | 128 |
| 129 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); |
| 130 while (rule_iterator->HasNext()) { |
| 131 content_settings::Rule rule = rule_iterator->Next(); |
| 132 if (rule.primary_pattern == wildcard && |
| 133 rule.secondary_pattern == wildcard) { |
| 134 return content_settings::ValueToContentSetting(rule.value.get()); |
| 135 } |
| 136 } |
| 137 return CONTENT_SETTING_DEFAULT; |
136 } | 138 } |
137 | 139 |
138 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( | 140 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( |
139 ContentSettingsType content_type, | 141 ContentSettingsType content_type, |
140 std::string* provider_id) const { | 142 std::string* provider_id) const { |
141 DCHECK(!ContentTypeHasCompoundValue(content_type)); | 143 DCHECK(!ContentTypeHasCompoundValue(content_type)); |
142 | 144 |
143 // Iterate through the list of providers and return the first non-NULL value | 145 // Iterate through the list of providers and return the first non-NULL value |
144 // that matches |primary_url| and |secondary_url|. | 146 // that matches |primary_url| and |secondary_url|. |
145 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 147 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
(...skipping 15 matching lines...) Expand all Loading... |
161 // DefaultProvider to always provide a value. | 163 // DefaultProvider to always provide a value. |
162 NOTREACHED(); | 164 NOTREACHED(); |
163 return CONTENT_SETTING_DEFAULT; | 165 return CONTENT_SETTING_DEFAULT; |
164 } | 166 } |
165 | 167 |
166 ContentSetting HostContentSettingsMap::GetContentSetting( | 168 ContentSetting HostContentSettingsMap::GetContentSetting( |
167 const GURL& primary_url, | 169 const GURL& primary_url, |
168 const GURL& secondary_url, | 170 const GURL& secondary_url, |
169 ContentSettingsType content_type, | 171 ContentSettingsType content_type, |
170 const std::string& resource_identifier) const { | 172 const std::string& resource_identifier) const { |
| 173 DCHECK(!ContentTypeHasCompoundValue(content_type)); |
171 scoped_ptr<base::Value> value(GetWebsiteSetting( | 174 scoped_ptr<base::Value> value(GetWebsiteSetting( |
172 primary_url, secondary_url, content_type, resource_identifier, NULL)); | 175 primary_url, secondary_url, content_type, resource_identifier, NULL)); |
173 return content_settings::ValueToContentSetting(value.get()); | 176 return content_settings::ValueToContentSetting(value.get()); |
174 } | 177 } |
175 | 178 |
176 void HostContentSettingsMap::GetSettingsForOneType( | 179 void HostContentSettingsMap::GetSettingsForOneType( |
177 ContentSettingsType content_type, | 180 ContentSettingsType content_type, |
178 const std::string& resource_identifier, | 181 const std::string& resource_identifier, |
179 ContentSettingsForOneType* settings) const { | 182 ContentSettingsForOneType* settings) const { |
180 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || | 183 DCHECK(SupportsResourceIdentifier(content_type) || |
181 resource_identifier.empty()); | 184 resource_identifier.empty()); |
182 DCHECK(settings); | 185 DCHECK(settings); |
183 | 186 |
184 settings->clear(); | 187 settings->clear(); |
185 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 188 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
186 provider != content_settings_providers_.end(); | 189 provider != content_settings_providers_.end(); |
187 ++provider) { | 190 ++provider) { |
188 // For each provider, iterate first the incognito-specific rules, then the | 191 // For each provider, iterate first the incognito-specific rules, then the |
189 // normal rules. | 192 // normal rules. |
190 if (is_off_the_record_) { | 193 if (is_off_the_record_) { |
191 AddSettingsForOneType(provider->second, | 194 AddSettingsForOneType(provider->second, |
192 provider->first, | 195 provider->first, |
193 content_type, | 196 content_type, |
194 resource_identifier, | 197 resource_identifier, |
195 settings, | 198 settings, |
196 true); | 199 true); |
197 } | 200 } |
198 AddSettingsForOneType(provider->second, | 201 AddSettingsForOneType(provider->second, |
199 provider->first, | 202 provider->first, |
200 content_type, | 203 content_type, |
201 resource_identifier, | 204 resource_identifier, |
202 settings, | 205 settings, |
203 false); | 206 false); |
204 } | 207 } |
205 } | 208 } |
206 | 209 |
207 void HostContentSettingsMap::SetDefaultContentSetting( | 210 void HostContentSettingsMap::SetDefaultContentSetting( |
208 ContentSettingsType content_type, | 211 ContentSettingsType content_type, |
209 ContentSetting setting) { | 212 ContentSetting setting) { |
210 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); | 213 DCHECK(!ContentTypeHasCompoundValue(content_type)); |
211 DCHECK(IsSettingAllowedForType(setting, content_type)); | 214 DCHECK(IsSettingAllowedForType(setting, content_type)); |
212 | 215 |
213 base::Value* value = NULL; | 216 base::Value* value = NULL; |
214 if (setting != CONTENT_SETTING_DEFAULT) | 217 if (setting != CONTENT_SETTING_DEFAULT) |
215 value = Value::CreateIntegerValue(setting); | 218 value = Value::CreateIntegerValue(setting); |
216 SetWebsiteSetting( | 219 SetWebsiteSetting( |
217 ContentSettingsPattern::Wildcard(), | 220 ContentSettingsPattern::Wildcard(), |
218 ContentSettingsPattern::Wildcard(), | 221 ContentSettingsPattern::Wildcard(), |
219 content_type, | 222 content_type, |
220 std::string(), | 223 std::string(), |
221 value); | 224 value); |
222 } | 225 } |
223 | 226 |
224 void HostContentSettingsMap::SetWebsiteSetting( | 227 void HostContentSettingsMap::SetWebsiteSetting( |
225 const ContentSettingsPattern& primary_pattern, | 228 const ContentSettingsPattern& primary_pattern, |
226 const ContentSettingsPattern& secondary_pattern, | 229 const ContentSettingsPattern& secondary_pattern, |
227 ContentSettingsType content_type, | 230 ContentSettingsType content_type, |
228 const std::string& resource_identifier, | 231 const std::string& resource_identifier, |
229 base::Value* value) { | 232 base::Value* value) { |
230 DCHECK(IsValueAllowedForType(value, content_type)); | 233 DCHECK(IsValueAllowedForType(value, content_type)); |
231 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || | 234 DCHECK(SupportsResourceIdentifier(content_type) || |
232 resource_identifier.empty()); | 235 resource_identifier.empty()); |
233 for (ProviderIterator provider = content_settings_providers_.begin(); | 236 for (ProviderIterator provider = content_settings_providers_.begin(); |
234 provider != content_settings_providers_.end(); | 237 provider != content_settings_providers_.end(); |
235 ++provider) { | 238 ++provider) { |
236 if (provider->second->SetWebsiteSetting(primary_pattern, | 239 if (provider->second->SetWebsiteSetting(primary_pattern, |
237 secondary_pattern, | 240 secondary_pattern, |
238 content_type, | 241 content_type, |
239 resource_identifier, | 242 resource_identifier, |
240 value)) { | 243 value)) { |
241 return; | 244 return; |
242 } | 245 } |
243 } | 246 } |
244 NOTREACHED(); | 247 NOTREACHED(); |
245 } | 248 } |
246 | 249 |
247 void HostContentSettingsMap::SetContentSetting( | 250 void HostContentSettingsMap::SetContentSetting( |
248 const ContentSettingsPattern& primary_pattern, | 251 const ContentSettingsPattern& primary_pattern, |
249 const ContentSettingsPattern& secondary_pattern, | 252 const ContentSettingsPattern& secondary_pattern, |
250 ContentSettingsType content_type, | 253 ContentSettingsType content_type, |
251 const std::string& resource_identifier, | 254 const std::string& resource_identifier, |
252 ContentSetting setting) { | 255 ContentSetting setting) { |
253 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); | 256 DCHECK(!ContentTypeHasCompoundValue(content_type)); |
254 base::Value* value = NULL; | 257 base::Value* value = NULL; |
255 if (setting != CONTENT_SETTING_DEFAULT) | 258 if (setting != CONTENT_SETTING_DEFAULT) |
256 value = Value::CreateIntegerValue(setting); | 259 value = Value::CreateIntegerValue(setting); |
257 SetWebsiteSetting(primary_pattern, | 260 SetWebsiteSetting(primary_pattern, |
258 secondary_pattern, | 261 secondary_pattern, |
259 content_type, | 262 content_type, |
260 resource_identifier, | 263 resource_identifier, |
261 value); | 264 value); |
262 } | 265 } |
263 | 266 |
264 void HostContentSettingsMap::AddExceptionForURL( | 267 void HostContentSettingsMap::AddExceptionForURL( |
265 const GURL& primary_url, | 268 const GURL& primary_url, |
266 const GURL& secondary_url, | 269 const GURL& secondary_url, |
267 ContentSettingsType content_type, | 270 ContentSettingsType content_type, |
268 const std::string& resource_identifier, | 271 const std::string& resource_identifier, |
269 ContentSetting setting) { | 272 ContentSetting setting) { |
270 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must | 273 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must |
271 // match. | 274 // match. |
272 DCHECK(primary_url == secondary_url); | 275 DCHECK(primary_url == secondary_url); |
| 276 DCHECK(!ContentTypeHasCompoundValue(content_type)); |
273 | 277 |
274 // Make sure there is no entry that would override the pattern we are about | 278 // Make sure there is no entry that would override the pattern we are about |
275 // to insert for exactly this URL. | 279 // to insert for exactly this URL. |
276 SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(primary_url), | 280 SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(primary_url), |
277 ContentSettingsPattern::Wildcard(), | 281 ContentSettingsPattern::Wildcard(), |
278 content_type, | 282 content_type, |
279 resource_identifier, | 283 resource_identifier, |
280 CONTENT_SETTING_DEFAULT); | 284 CONTENT_SETTING_DEFAULT); |
281 | 285 |
282 SetContentSetting(ContentSettingsPattern::FromURL(primary_url), | 286 SetContentSetting(ContentSettingsPattern::FromURL(primary_url), |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 primary_url.SchemeIs(chrome::kChromeInternalScheme) || | 412 primary_url.SchemeIs(chrome::kChromeInternalScheme) || |
409 primary_url.SchemeIs(chrome::kChromeUIScheme); | 413 primary_url.SchemeIs(chrome::kChromeUIScheme); |
410 } | 414 } |
411 | 415 |
412 base::Value* HostContentSettingsMap::GetWebsiteSetting( | 416 base::Value* HostContentSettingsMap::GetWebsiteSetting( |
413 const GURL& primary_url, | 417 const GURL& primary_url, |
414 const GURL& secondary_url, | 418 const GURL& secondary_url, |
415 ContentSettingsType content_type, | 419 ContentSettingsType content_type, |
416 const std::string& resource_identifier, | 420 const std::string& resource_identifier, |
417 content_settings::SettingInfo* info) const { | 421 content_settings::SettingInfo* info) const { |
418 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || | 422 DCHECK(SupportsResourceIdentifier(content_type) || |
419 resource_identifier.empty()); | 423 resource_identifier.empty()); |
420 | 424 |
421 // Check if the scheme of the requesting url is whitelisted. | 425 // Check if the scheme of the requesting url is whitelisted. |
422 if (ShouldAllowAllContent(primary_url, secondary_url, content_type)) { | 426 if (ShouldAllowAllContent(primary_url, secondary_url, content_type)) { |
423 if (info) { | 427 if (info) { |
424 info->source = content_settings::SETTING_SOURCE_WHITELIST; | 428 info->source = content_settings::SETTING_SOURCE_WHITELIST; |
425 info->primary_pattern = ContentSettingsPattern::Wildcard(); | 429 info->primary_pattern = ContentSettingsPattern::Wildcard(); |
426 info->secondary_pattern = ContentSettingsPattern::Wildcard(); | 430 info->secondary_pattern = ContentSettingsPattern::Wildcard(); |
427 } | 431 } |
428 return Value::CreateIntegerValue(CONTENT_SETTING_ALLOW); | 432 return Value::CreateIntegerValue(CONTENT_SETTING_ALLOW); |
(...skipping 22 matching lines...) Expand all Loading... |
451 } | 455 } |
452 } | 456 } |
453 | 457 |
454 if (info) { | 458 if (info) { |
455 info->source = content_settings::SETTING_SOURCE_NONE; | 459 info->source = content_settings::SETTING_SOURCE_NONE; |
456 info->primary_pattern = ContentSettingsPattern(); | 460 info->primary_pattern = ContentSettingsPattern(); |
457 info->secondary_pattern = ContentSettingsPattern(); | 461 info->secondary_pattern = ContentSettingsPattern(); |
458 } | 462 } |
459 return NULL; | 463 return NULL; |
460 } | 464 } |
OLD | NEW |