| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/api/content_settings/content_settings_store.
h" | 5 #include "chrome/browser/extensions/api/content_settings/content_settings_store.
h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/debug/alias.h" | 9 #include "base/debug/alias.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/content_settings/content_settings_origin_identifier_val
ue_map.h" | 16 #include "chrome/browser/content_settings/content_settings_origin_identifier_val
ue_map.h" |
| 17 #include "chrome/browser/content_settings/content_settings_rule.h" | 17 #include "chrome/browser/content_settings/content_settings_rule.h" |
| 18 #include "chrome/browser/content_settings/content_settings_utils.h" | 18 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 19 #include "chrome/browser/extensions/api/content_settings/content_settings_api_co
nstants.h" | 19 #include "chrome/browser/extensions/api/content_settings/content_settings_api_co
nstants.h" |
| 20 #include "chrome/browser/extensions/api/content_settings/content_settings_helper
s.h" | 20 #include "chrome/browser/extensions/api/content_settings/content_settings_helper
s.h" |
| 21 #include "chrome/common/chrome_content_settings_client.h" |
| 21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 22 | 23 |
| 23 using content::BrowserThread; | 24 using content::BrowserThread; |
| 24 using content_settings::ConcatenationIterator; | 25 using content_settings::ConcatenationIterator; |
| 25 using content_settings::Rule; | 26 using content_settings::Rule; |
| 26 using content_settings::RuleIterator; | 27 using content_settings::RuleIterator; |
| 27 using content_settings::OriginIdentifierValueMap; | 28 using content_settings::OriginIdentifierValueMap; |
| 28 using content_settings::ResourceIdentifier; | 29 using content_settings::ResourceIdentifier; |
| 29 using content_settings::ValueToContentSetting; | 30 using content_settings::ValueToContentSetting; |
| 30 | 31 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 base::ListValue* settings = new base::ListValue(); | 254 base::ListValue* settings = new base::ListValue(); |
| 254 OriginIdentifierValueMap::EntryMap::const_iterator it; | 255 OriginIdentifierValueMap::EntryMap::const_iterator it; |
| 255 for (it = map->begin(); it != map->end(); ++it) { | 256 for (it = map->begin(); it != map->end(); ++it) { |
| 256 scoped_ptr<RuleIterator> rule_iterator( | 257 scoped_ptr<RuleIterator> rule_iterator( |
| 257 map->GetRuleIterator(it->first.content_type, | 258 map->GetRuleIterator(it->first.content_type, |
| 258 it->first.resource_identifier, | 259 it->first.resource_identifier, |
| 259 NULL)); // We already hold the lock. | 260 NULL)); // We already hold the lock. |
| 260 while (rule_iterator->HasNext()) { | 261 while (rule_iterator->HasNext()) { |
| 261 const Rule& rule = rule_iterator->Next(); | 262 const Rule& rule = rule_iterator->Next(); |
| 262 base::DictionaryValue* setting_dict = new base::DictionaryValue(); | 263 base::DictionaryValue* setting_dict = new base::DictionaryValue(); |
| 264 content_settings::ChromeContentSettingsClient client; |
| 263 setting_dict->SetString(keys::kPrimaryPatternKey, | 265 setting_dict->SetString(keys::kPrimaryPatternKey, |
| 264 rule.primary_pattern.ToString()); | 266 rule.primary_pattern.ToString(&client)); |
| 265 setting_dict->SetString(keys::kSecondaryPatternKey, | 267 setting_dict->SetString(keys::kSecondaryPatternKey, |
| 266 rule.secondary_pattern.ToString()); | 268 rule.secondary_pattern.ToString(&client)); |
| 267 setting_dict->SetString( | 269 setting_dict->SetString( |
| 268 keys::kContentSettingsTypeKey, | 270 keys::kContentSettingsTypeKey, |
| 269 helpers::ContentSettingsTypeToString(it->first.content_type)); | 271 helpers::ContentSettingsTypeToString(it->first.content_type)); |
| 270 setting_dict->SetString(keys::kResourceIdentifierKey, | 272 setting_dict->SetString(keys::kResourceIdentifierKey, |
| 271 it->first.resource_identifier); | 273 it->first.resource_identifier); |
| 272 ContentSetting content_setting = ValueToContentSetting(rule.value.get()); | 274 ContentSetting content_setting = ValueToContentSetting(rule.value.get()); |
| 273 DCHECK_NE(CONTENT_SETTING_DEFAULT, content_setting); | 275 DCHECK_NE(CONTENT_SETTING_DEFAULT, content_setting); |
| 274 setting_dict->SetString( | 276 setting_dict->SetString( |
| 275 keys::kContentSettingKey, | 277 keys::kContentSettingKey, |
| 276 helpers::ContentSettingToString(content_setting)); | 278 helpers::ContentSettingToString(content_setting)); |
| 277 settings->Append(setting_dict); | 279 settings->Append(setting_dict); |
| 278 } | 280 } |
| 279 } | 281 } |
| 280 return settings; | 282 return settings; |
| 281 } | 283 } |
| 282 | 284 |
| 283 void ContentSettingsStore::SetExtensionContentSettingFromList( | 285 void ContentSettingsStore::SetExtensionContentSettingFromList( |
| 284 const std::string& extension_id, | 286 const std::string& extension_id, |
| 285 const base::ListValue* list, | 287 const base::ListValue* list, |
| 286 ExtensionPrefsScope scope) { | 288 ExtensionPrefsScope scope) { |
| 287 for (base::ListValue::const_iterator it = list->begin(); | 289 for (base::ListValue::const_iterator it = list->begin(); |
| 288 it != list->end(); ++it) { | 290 it != list->end(); ++it) { |
| 289 if ((*it)->GetType() != base::Value::TYPE_DICTIONARY) { | 291 if ((*it)->GetType() != base::Value::TYPE_DICTIONARY) { |
| 290 NOTREACHED(); | 292 NOTREACHED(); |
| 291 continue; | 293 continue; |
| 292 } | 294 } |
| 293 base::DictionaryValue* dict = static_cast<base::DictionaryValue*>(*it); | 295 base::DictionaryValue* dict = static_cast<base::DictionaryValue*>(*it); |
| 294 std::string primary_pattern_str; | 296 std::string primary_pattern_str; |
| 295 dict->GetString(keys::kPrimaryPatternKey, &primary_pattern_str); | 297 dict->GetString(keys::kPrimaryPatternKey, &primary_pattern_str); |
| 298 content_settings::ChromeContentSettingsClient client; |
| 296 ContentSettingsPattern primary_pattern = | 299 ContentSettingsPattern primary_pattern = |
| 297 ContentSettingsPattern::FromString(primary_pattern_str); | 300 ContentSettingsPattern::FromString(&client, primary_pattern_str); |
| 298 DCHECK(primary_pattern.IsValid()); | 301 DCHECK(primary_pattern.IsValid()); |
| 299 | 302 |
| 300 std::string secondary_pattern_str; | 303 std::string secondary_pattern_str; |
| 301 dict->GetString(keys::kSecondaryPatternKey, &secondary_pattern_str); | 304 dict->GetString(keys::kSecondaryPatternKey, &secondary_pattern_str); |
| 302 ContentSettingsPattern secondary_pattern = | 305 ContentSettingsPattern secondary_pattern = |
| 303 ContentSettingsPattern::FromString(secondary_pattern_str); | 306 ContentSettingsPattern::FromString(&client, secondary_pattern_str); |
| 304 DCHECK(secondary_pattern.IsValid()); | 307 DCHECK(secondary_pattern.IsValid()); |
| 305 | 308 |
| 306 std::string content_settings_type_str; | 309 std::string content_settings_type_str; |
| 307 dict->GetString(keys::kContentSettingsTypeKey, &content_settings_type_str); | 310 dict->GetString(keys::kContentSettingsTypeKey, &content_settings_type_str); |
| 308 ContentSettingsType content_settings_type = | 311 ContentSettingsType content_settings_type = |
| 309 helpers::StringToContentSettingsType(content_settings_type_str); | 312 helpers::StringToContentSettingsType(content_settings_type_str); |
| 310 DCHECK_NE(CONTENT_SETTINGS_TYPE_DEFAULT, content_settings_type); | 313 DCHECK_NE(CONTENT_SETTINGS_TYPE_DEFAULT, content_settings_type); |
| 311 | 314 |
| 312 std::string resource_identifier; | 315 std::string resource_identifier; |
| 313 dict->GetString(keys::kResourceIdentifierKey, &resource_identifier); | 316 dict->GetString(keys::kResourceIdentifierKey, &resource_identifier); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 ContentSettingsStore::FindEntry(const std::string& ext_id) const { | 371 ContentSettingsStore::FindEntry(const std::string& ext_id) const { |
| 369 ExtensionEntryMap::const_iterator i; | 372 ExtensionEntryMap::const_iterator i; |
| 370 for (i = entries_.begin(); i != entries_.end(); ++i) { | 373 for (i = entries_.begin(); i != entries_.end(); ++i) { |
| 371 if (i->second->id == ext_id) | 374 if (i->second->id == ext_id) |
| 372 return i; | 375 return i; |
| 373 } | 376 } |
| 374 return entries_.end(); | 377 return entries_.end(); |
| 375 } | 378 } |
| 376 | 379 |
| 377 } // namespace extensions | 380 } // namespace extensions |
| OLD | NEW |