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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 if (rule.primary_pattern == wildcard && | 76 if (rule.primary_pattern == wildcard && |
77 rule.secondary_pattern == wildcard) { | 77 rule.secondary_pattern == wildcard) { |
78 return content_settings::ValueToContentSetting(rule.value.get()); | 78 return content_settings::ValueToContentSetting(rule.value.get()); |
79 } | 79 } |
80 } | 80 } |
81 return CONTENT_SETTING_DEFAULT; | 81 return CONTENT_SETTING_DEFAULT; |
82 } | 82 } |
83 | 83 |
84 } // namespace | 84 } // namespace |
85 | 85 |
86 namespace base { | |
87 class Value; | |
Bernhard Bauer
2011/11/11 14:00:40
Here's a hint: You never need to forward-declare a
markusheintz_
2011/11/14 11:15:10
Another change in the matrix.
| |
88 } | |
89 | |
86 HostContentSettingsMap::HostContentSettingsMap( | 90 HostContentSettingsMap::HostContentSettingsMap( |
87 PrefService* prefs, | 91 PrefService* prefs, |
88 ExtensionService* extension_service, | 92 ExtensionService* extension_service, |
89 bool incognito) | 93 bool incognito) |
90 : prefs_(prefs), | 94 : prefs_(prefs), |
91 is_off_the_record_(incognito) { | 95 is_off_the_record_(incognito) { |
92 content_settings::ObservableProvider* policy_provider = | 96 content_settings::ObservableProvider* policy_provider = |
93 new content_settings::PolicyProvider(prefs_); | 97 new content_settings::PolicyProvider(prefs_); |
94 policy_provider->AddObserver(this); | 98 policy_provider->AddObserver(this); |
95 content_settings_providers_[POLICY_PROVIDER] = policy_provider; | 99 content_settings_providers_[POLICY_PROVIDER] = policy_provider; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 false); | 234 false); |
231 } | 235 } |
232 } | 236 } |
233 | 237 |
234 void HostContentSettingsMap::SetDefaultContentSetting( | 238 void HostContentSettingsMap::SetDefaultContentSetting( |
235 ContentSettingsType content_type, | 239 ContentSettingsType content_type, |
236 ContentSetting setting) { | 240 ContentSetting setting) { |
237 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); | 241 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); |
238 DCHECK(IsSettingAllowedForType(setting, content_type)); | 242 DCHECK(IsSettingAllowedForType(setting, content_type)); |
239 | 243 |
240 content_settings_providers_[DEFAULT_PROVIDER]->SetContentSetting( | 244 scoped_ptr<base::Value> value(Value::CreateIntegerValue(setting)); |
245 content_settings_providers_[DEFAULT_PROVIDER]->SetWebsiteSetting( | |
241 ContentSettingsPattern::Wildcard(), | 246 ContentSettingsPattern::Wildcard(), |
242 ContentSettingsPattern::Wildcard(), | 247 ContentSettingsPattern::Wildcard(), |
243 content_type, | 248 content_type, |
244 std::string(), | 249 std::string(), |
245 setting); | 250 value.get()); |
251 } | |
252 | |
253 void HostContentSettingsMap::SetWebsiteSetting( | |
254 const ContentSettingsPattern& primary_pattern, | |
255 const ContentSettingsPattern& secondary_pattern, | |
256 ContentSettingsType content_type, | |
257 const std::string& resource_identifier, | |
258 base::Value* in_value) { | |
259 // The HostContentSettingsMap takes ownership of the passed value but the | |
260 // PrefProviders don't. PrefProvider make a copy of passed values. Therefor | |
261 // we put the passed |value| in a scoped pointer to clean it up. | |
262 scoped_ptr<base::Value> value(in_value); | |
Bernhard Bauer
2011/11/11 14:00:40
So... maybe the PrefProviders should take ownershi
markusheintz_
2011/11/14 11:15:10
Done.
| |
263 | |
264 DCHECK(IsValueAllowedForType(value.get(), content_type)); | |
265 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || | |
266 resource_identifier.empty()); | |
267 for (ProviderIterator provider = content_settings_providers_.begin(); | |
268 provider != content_settings_providers_.end(); | |
269 ++provider) { | |
270 provider->second->SetWebsiteSetting( | |
271 primary_pattern, | |
272 secondary_pattern, | |
273 content_type, | |
274 resource_identifier, | |
275 value.get()); | |
276 } | |
246 } | 277 } |
247 | 278 |
248 void HostContentSettingsMap::SetContentSetting( | 279 void HostContentSettingsMap::SetContentSetting( |
249 const ContentSettingsPattern& primary_pattern, | 280 const ContentSettingsPattern& primary_pattern, |
250 const ContentSettingsPattern& secondary_pattern, | 281 const ContentSettingsPattern& secondary_pattern, |
251 ContentSettingsType content_type, | 282 ContentSettingsType content_type, |
252 const std::string& resource_identifier, | 283 const std::string& resource_identifier, |
253 ContentSetting setting) { | 284 ContentSetting setting) { |
254 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); | 285 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); |
255 DCHECK(IsSettingAllowedForType(setting, content_type)); | 286 scoped_ptr<base::Value> value; |
Bernhard Bauer
2011/11/11 14:00:40
You don't need a scoped_ptr if you're releasing it
markusheintz_
2011/11/14 11:15:10
Yeah. I saw this somewhere else and though it migh
| |
256 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || | 287 if (setting != CONTENT_SETTING_DEFAULT) |
257 resource_identifier.empty()); | 288 value.reset(Value::CreateIntegerValue(setting)); |
258 for (ProviderIterator provider = content_settings_providers_.begin(); | 289 SetWebsiteSetting(primary_pattern, |
259 provider != content_settings_providers_.end(); | 290 secondary_pattern, |
260 ++provider) { | 291 content_type, |
261 provider->second->SetContentSetting( | 292 resource_identifier, |
262 primary_pattern, | 293 value.release()); |
263 secondary_pattern, | |
264 content_type, | |
265 resource_identifier, | |
266 setting); | |
267 } | |
268 } | 294 } |
269 | 295 |
270 void HostContentSettingsMap::AddExceptionForURL( | 296 void HostContentSettingsMap::AddExceptionForURL( |
271 const GURL& primary_url, | 297 const GURL& primary_url, |
272 const GURL& secondary_url, | 298 const GURL& secondary_url, |
273 ContentSettingsType content_type, | 299 ContentSettingsType content_type, |
274 const std::string& resource_identifier, | 300 const std::string& resource_identifier, |
275 ContentSetting setting) { | 301 ContentSetting setting) { |
276 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must | 302 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must |
277 // match. | 303 // match. |
(...skipping 16 matching lines...) Expand all Loading... | |
294 | 320 |
295 void HostContentSettingsMap::ClearSettingsForOneType( | 321 void HostContentSettingsMap::ClearSettingsForOneType( |
296 ContentSettingsType content_type) { | 322 ContentSettingsType content_type) { |
297 for (ProviderIterator provider = content_settings_providers_.begin(); | 323 for (ProviderIterator provider = content_settings_providers_.begin(); |
298 provider != content_settings_providers_.end(); | 324 provider != content_settings_providers_.end(); |
299 ++provider) { | 325 ++provider) { |
300 provider->second->ClearAllContentSettingsRules(content_type); | 326 provider->second->ClearAllContentSettingsRules(content_type); |
301 } | 327 } |
302 } | 328 } |
303 | 329 |
330 bool HostContentSettingsMap::IsValueAllowedForType( | |
331 const base::Value* value, ContentSettingsType type) { | |
332 return IsSettingAllowedForType( | |
333 content_settings::ValueToContentSetting(value), type); | |
334 } | |
335 | |
304 // static | 336 // static |
305 bool HostContentSettingsMap::IsSettingAllowedForType( | 337 bool HostContentSettingsMap::IsSettingAllowedForType( |
306 ContentSetting setting, ContentSettingsType content_type) { | 338 ContentSetting setting, ContentSettingsType content_type) { |
307 // Intents content settings are hidden behind a switch for now. | 339 // Intents content settings are hidden behind a switch for now. |
308 if (content_type == CONTENT_SETTINGS_TYPE_INTENTS && | 340 if (content_type == CONTENT_SETTINGS_TYPE_INTENTS && |
309 !CommandLine::ForCurrentProcess()->HasSwitch( | 341 !CommandLine::ForCurrentProcess()->HasSwitch( |
310 switches::kEnableWebIntents)) | 342 switches::kEnableWebIntents)) |
311 return false; | 343 return false; |
312 | 344 |
313 // DEFAULT, ALLOW and BLOCK are always allowed. | 345 // DEFAULT, ALLOW and BLOCK are always allowed. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 } | 476 } |
445 } | 477 } |
446 | 478 |
447 if (info) { | 479 if (info) { |
448 info->source = content_settings::SETTING_SOURCE_NONE; | 480 info->source = content_settings::SETTING_SOURCE_NONE; |
449 info->primary_pattern = ContentSettingsPattern(); | 481 info->primary_pattern = ContentSettingsPattern(); |
450 info->secondary_pattern = ContentSettingsPattern(); | 482 info->secondary_pattern = ContentSettingsPattern(); |
451 } | 483 } |
452 return NULL; | 484 return NULL; |
453 } | 485 } |
OLD | NEW |