| 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 <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/debug/alias.h" | 12 #include "base/debug/alias.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "chrome/browser/extensions/api/content_settings/content_settings_api_co
nstants.h" | 18 #include "chrome/browser/extensions/api/content_settings/content_settings_api_co
nstants.h" |
| 18 #include "chrome/browser/extensions/api/content_settings/content_settings_helper
s.h" | 19 #include "chrome/browser/extensions/api/content_settings/content_settings_helper
s.h" |
| 19 #include "components/content_settings/core/browser/content_settings_origin_ident
ifier_value_map.h" | 20 #include "components/content_settings/core/browser/content_settings_origin_ident
ifier_value_map.h" |
| 20 #include "components/content_settings/core/browser/content_settings_rule.h" | 21 #include "components/content_settings/core/browser/content_settings_rule.h" |
| 21 #include "components/content_settings/core/browser/content_settings_utils.h" | 22 #include "components/content_settings/core/browser/content_settings_utils.h" |
| 22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 23 | 24 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 base::STLDeleteValues(&entries_); | 56 base::STLDeleteValues(&entries_); |
| 56 } | 57 } |
| 57 | 58 |
| 58 std::unique_ptr<RuleIterator> ContentSettingsStore::GetRuleIterator( | 59 std::unique_ptr<RuleIterator> ContentSettingsStore::GetRuleIterator( |
| 59 ContentSettingsType type, | 60 ContentSettingsType type, |
| 60 const content_settings::ResourceIdentifier& identifier, | 61 const content_settings::ResourceIdentifier& identifier, |
| 61 bool incognito) const { | 62 bool incognito) const { |
| 62 std::vector<std::unique_ptr<RuleIterator>> iterators; | 63 std::vector<std::unique_ptr<RuleIterator>> iterators; |
| 63 // Iterate the extensions based on install time (last installed extensions | 64 // Iterate the extensions based on install time (last installed extensions |
| 64 // first). | 65 // first). |
| 65 ExtensionEntryMap::const_reverse_iterator entry; | 66 ExtensionEntryMap::const_reverse_iterator entry_it; |
| 66 | 67 |
| 67 // The individual |RuleIterators| shouldn't lock; pass |lock_| to the | 68 // The individual |RuleIterators| shouldn't lock; pass |lock_| to the |
| 68 // |ConcatenationIterator| in a locked state. | 69 // |ConcatenationIterator| in a locked state. |
| 69 std::unique_ptr<base::AutoLock> auto_lock(new base::AutoLock(lock_)); | 70 std::unique_ptr<base::AutoLock> auto_lock(new base::AutoLock(lock_)); |
| 70 | 71 |
| 71 for (entry = entries_.rbegin(); entry != entries_.rend(); ++entry) { | 72 for (entry_it = entries_.rbegin(); entry_it != entries_.rend(); ++entry_it) { |
| 72 if (!entry->second->enabled) | 73 auto* entry = entry_it->second; |
| 74 if (!entry->enabled) |
| 73 continue; | 75 continue; |
| 74 | 76 |
| 77 std::unique_ptr<RuleIterator> rule_it; |
| 75 if (incognito) { | 78 if (incognito) { |
| 76 iterators.push_back( | 79 rule_it = entry->incognito_session_only_settings.GetRuleIterator( |
| 77 entry->second->incognito_session_only_settings.GetRuleIterator( | 80 type, identifier, nullptr); |
| 78 type, | 81 if (rule_it) |
| 79 identifier, | 82 iterators.push_back(std::move(rule_it)); |
| 80 NULL)); | 83 rule_it = entry->incognito_persistent_settings.GetRuleIterator( |
| 81 iterators.push_back( | 84 type, identifier, nullptr); |
| 82 entry->second->incognito_persistent_settings.GetRuleIterator( | 85 if (rule_it) |
| 83 type, | 86 iterators.push_back(std::move(rule_it)); |
| 84 identifier, | |
| 85 NULL)); | |
| 86 } else { | 87 } else { |
| 87 iterators.push_back( | 88 rule_it = entry->settings.GetRuleIterator(type, identifier, nullptr); |
| 88 entry->second->settings.GetRuleIterator(type, identifier, NULL)); | 89 if (rule_it) |
| 90 iterators.push_back(std::move(rule_it)); |
| 89 } | 91 } |
| 90 } | 92 } |
| 91 return std::unique_ptr<RuleIterator>( | 93 if (iterators.empty()) |
| 92 new ConcatenationIterator(std::move(iterators), auto_lock.release())); | 94 return nullptr; |
| 95 |
| 96 return base::MakeUnique<ConcatenationIterator>(std::move(iterators), |
| 97 auto_lock.release()); |
| 93 } | 98 } |
| 94 | 99 |
| 95 void ContentSettingsStore::SetExtensionContentSetting( | 100 void ContentSettingsStore::SetExtensionContentSetting( |
| 96 const std::string& ext_id, | 101 const std::string& ext_id, |
| 97 const ContentSettingsPattern& primary_pattern, | 102 const ContentSettingsPattern& primary_pattern, |
| 98 const ContentSettingsPattern& secondary_pattern, | 103 const ContentSettingsPattern& secondary_pattern, |
| 99 ContentSettingsType type, | 104 ContentSettingsType type, |
| 100 const content_settings::ResourceIdentifier& identifier, | 105 const content_settings::ResourceIdentifier& identifier, |
| 101 ContentSetting setting, | 106 ContentSetting setting, |
| 102 ExtensionPrefsScope scope) { | 107 ExtensionPrefsScope scope) { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 NotifyOfContentSettingChanged(ext_id, scope != kExtensionPrefsScopeRegular); | 249 NotifyOfContentSettingChanged(ext_id, scope != kExtensionPrefsScopeRegular); |
| 245 } | 250 } |
| 246 } | 251 } |
| 247 | 252 |
| 248 base::ListValue* ContentSettingsStore::GetSettingsForExtension( | 253 base::ListValue* ContentSettingsStore::GetSettingsForExtension( |
| 249 const std::string& extension_id, | 254 const std::string& extension_id, |
| 250 ExtensionPrefsScope scope) const { | 255 ExtensionPrefsScope scope) const { |
| 251 base::AutoLock lock(lock_); | 256 base::AutoLock lock(lock_); |
| 252 const OriginIdentifierValueMap* map = GetValueMap(extension_id, scope); | 257 const OriginIdentifierValueMap* map = GetValueMap(extension_id, scope); |
| 253 if (!map) | 258 if (!map) |
| 254 return NULL; | 259 return nullptr; |
| 260 |
| 255 base::ListValue* settings = new base::ListValue(); | 261 base::ListValue* settings = new base::ListValue(); |
| 256 OriginIdentifierValueMap::EntryMap::const_iterator it; | 262 for (const auto& it : *map) { |
| 257 for (it = map->begin(); it != map->end(); ++it) { | 263 const auto& key = it.first; |
| 258 std::unique_ptr<RuleIterator> rule_iterator(map->GetRuleIterator( | 264 std::unique_ptr<RuleIterator> rule_iterator( |
| 259 it->first.content_type, it->first.resource_identifier, | 265 map->GetRuleIterator(key.content_type, key.resource_identifier, |
| 260 NULL)); // We already hold the lock. | 266 nullptr)); // We already hold the lock. |
| 267 if (!rule_iterator) |
| 268 continue; |
| 269 |
| 261 while (rule_iterator->HasNext()) { | 270 while (rule_iterator->HasNext()) { |
| 262 const Rule& rule = rule_iterator->Next(); | 271 const Rule& rule = rule_iterator->Next(); |
| 263 std::unique_ptr<base::DictionaryValue> setting_dict( | 272 std::unique_ptr<base::DictionaryValue> setting_dict( |
| 264 new base::DictionaryValue()); | 273 new base::DictionaryValue()); |
| 265 setting_dict->SetString(keys::kPrimaryPatternKey, | 274 setting_dict->SetString(keys::kPrimaryPatternKey, |
| 266 rule.primary_pattern.ToString()); | 275 rule.primary_pattern.ToString()); |
| 267 setting_dict->SetString(keys::kSecondaryPatternKey, | 276 setting_dict->SetString(keys::kSecondaryPatternKey, |
| 268 rule.secondary_pattern.ToString()); | 277 rule.secondary_pattern.ToString()); |
| 269 setting_dict->SetString( | 278 setting_dict->SetString( |
| 270 keys::kContentSettingsTypeKey, | 279 keys::kContentSettingsTypeKey, |
| 271 helpers::ContentSettingsTypeToString(it->first.content_type)); | 280 helpers::ContentSettingsTypeToString(key.content_type)); |
| 272 setting_dict->SetString(keys::kResourceIdentifierKey, | 281 setting_dict->SetString(keys::kResourceIdentifierKey, |
| 273 it->first.resource_identifier); | 282 key.resource_identifier); |
| 274 ContentSetting content_setting = ValueToContentSetting(rule.value.get()); | 283 ContentSetting content_setting = ValueToContentSetting(rule.value.get()); |
| 275 DCHECK_NE(CONTENT_SETTING_DEFAULT, content_setting); | 284 DCHECK_NE(CONTENT_SETTING_DEFAULT, content_setting); |
| 276 | 285 |
| 277 std::string setting_string = | 286 std::string setting_string = |
| 278 content_settings::ContentSettingToString(content_setting); | 287 content_settings::ContentSettingToString(content_setting); |
| 279 DCHECK(!setting_string.empty()); | 288 DCHECK(!setting_string.empty()); |
| 280 | 289 |
| 281 setting_dict->SetString(keys::kContentSettingKey, setting_string); | 290 setting_dict->SetString(keys::kContentSettingKey, setting_string); |
| 282 settings->Append(std::move(setting_dict)); | 291 settings->Append(std::move(setting_dict)); |
| 283 } | 292 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 ContentSettingsStore::FindEntry(const std::string& ext_id) const { | 381 ContentSettingsStore::FindEntry(const std::string& ext_id) const { |
| 373 ExtensionEntryMap::const_iterator i; | 382 ExtensionEntryMap::const_iterator i; |
| 374 for (i = entries_.begin(); i != entries_.end(); ++i) { | 383 for (i = entries_.begin(); i != entries_.end(); ++i) { |
| 375 if (i->second->id == ext_id) | 384 if (i->second->id == ext_id) |
| 376 return i; | 385 return i; |
| 377 } | 386 } |
| 378 return entries_.end(); | 387 return entries_.end(); |
| 379 } | 388 } |
| 380 | 389 |
| 381 } // namespace extensions | 390 } // namespace extensions |
| OLD | NEW |