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/extension_prefs.h" | 5 #include "chrome/browser/extensions/extension_prefs.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/prefs/pref_notifier.h" | 8 #include "base/prefs/pref_notifier.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
741 } else { | 741 } else { |
742 UpdateExtensionPref(extension_id, kPrefDisableReasons, | 742 UpdateExtensionPref(extension_id, kPrefDisableReasons, |
743 Value::CreateIntegerValue(new_value)); | 743 Value::CreateIntegerValue(new_value)); |
744 } | 744 } |
745 } | 745 } |
746 | 746 |
747 void ExtensionPrefs::ClearDisableReasons(const std::string& extension_id) { | 747 void ExtensionPrefs::ClearDisableReasons(const std::string& extension_id) { |
748 UpdateExtensionPref(extension_id, kPrefDisableReasons, NULL); | 748 UpdateExtensionPref(extension_id, kPrefDisableReasons, NULL); |
749 } | 749 } |
750 | 750 |
751 void ExtensionPrefs::UpdateBlacklist( | 751 std::set<std::string> ExtensionPrefs::GetBlacklistedExtensions() { |
752 const std::set<std::string>& blacklist_set) { | 752 std::set<std::string> ids; |
753 ExtensionIdList remove_pref_ids; | 753 |
754 std::set<std::string> used_id_set; | |
755 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); | 754 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); |
755 if (!extensions) | |
756 return ids; | |
756 | 757 |
757 if (extensions) { | 758 for (DictionaryValue::Iterator it(*extensions); it.HasNext(); it.Advance()) { |
758 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys(); | 759 if (!it.value().IsType(Value::TYPE_DICTIONARY)) { |
759 extension_id != extensions->end_keys(); ++extension_id) { | 760 NOTREACHED() << "Invalid pref for extension " << it.key(); |
760 const DictionaryValue* ext; | 761 continue; |
761 if (!extensions->GetDictionaryWithoutPathExpansion(*extension_id, &ext)) { | |
762 NOTREACHED() << "Invalid pref for extension " << *extension_id; | |
763 continue; | |
764 } | |
765 const std::string& id(*extension_id); | |
766 if (blacklist_set.find(id) == blacklist_set.end()) { | |
767 if (!IsBlacklistBitSet(ext)) { | |
768 // This extension is not in blacklist. And it was not blacklisted | |
769 // before. | |
770 continue; | |
771 } else { | |
772 if (ext->size() == 1) { | |
773 // We should remove the entry if the only flag here is blacklist. | |
774 remove_pref_ids.push_back(id); | |
775 } else { | |
776 // Remove the blacklist bit. | |
777 UpdateExtensionPref(id, kPrefBlacklist, NULL); | |
778 } | |
779 } | |
780 } else { | |
781 if (!IsBlacklistBitSet(ext)) { | |
782 // Only set the blacklist if it was not set. | |
783 UpdateExtensionPref(id, kPrefBlacklist, | |
784 Value::CreateBooleanValue(true)); | |
785 } | |
786 // Keep the record if this extension is already processed. | |
787 used_id_set.insert(id); | |
788 } | |
789 } | 762 } |
763 if (IsBlacklistBitSet(static_cast<const DictionaryValue*>(&it.value()))) | |
764 ids.insert(it.key()); | |
790 } | 765 } |
791 | 766 |
792 // Iterate the leftovers to set blacklist in pref | 767 return ids; |
793 std::set<std::string>::const_iterator set_itr = blacklist_set.begin(); | 768 } |
794 for (; set_itr != blacklist_set.end(); ++set_itr) { | 769 |
795 if (used_id_set.find(*set_itr) == used_id_set.end()) { | 770 void ExtensionPrefs::SetExtensionBlacklisted(const std::string& extension_id, |
796 UpdateExtensionPref(*set_itr, kPrefBlacklist, | 771 bool is_blacklisted) { |
797 Value::CreateBooleanValue(true)); | 772 if (is_blacklisted) { |
798 } | 773 UpdateExtensionPref(extension_id, |
774 kPrefBlacklist, | |
775 new base::FundamentalValue(true)); | |
asargent_no_longer_on_chrome
2012/11/30 21:44:22
optional suggestion: I personally prefer "base::Cr
not at google - send to devlin
2012/11/30 23:09:54
I don't really have a preference though I'm used t
asargent_no_longer_on_chrome
2012/11/30 23:30:25
Ah, I missed that. Ok, probably better to go with
| |
776 UpdateExtensionPref(extension_id, | |
777 kPrefBlacklistAcknowledged, | |
778 new base::FundamentalValue(true)); | |
779 return; | |
799 } | 780 } |
800 for (size_t i = 0; i < remove_pref_ids.size(); ++i) { | 781 |
801 DeleteExtensionPrefs(remove_pref_ids[i]); | 782 // If we're clearing the blacklist bit, we also want to delete the entry for |
802 } | 783 // the extension in prefs altogether if the resulting entry is empty. |
784 UpdateExtensionPref(extension_id, kPrefBlacklist, NULL); | |
785 UpdateExtensionPref(extension_id, kPrefBlacklistAcknowledged, NULL); | |
786 const DictionaryValue* dict = GetExtensionPref(extension_id); | |
787 if (dict && dict->empty()) | |
788 DeleteExtensionPrefs(extension_id); | |
803 } | 789 } |
804 | 790 |
805 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& id) const { | 791 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& id) const { |
806 const DictionaryValue* ext_prefs = GetExtensionPref(id); | 792 const DictionaryValue* ext_prefs = GetExtensionPref(id); |
807 return ext_prefs && IsBlacklistBitSet(ext_prefs); | 793 return ext_prefs && IsBlacklistBitSet(ext_prefs); |
808 } | 794 } |
809 | 795 |
810 namespace { | 796 namespace { |
811 | 797 |
812 // Serializes |time| as a string value mapped to |key| in |dictionary|. | 798 // Serializes |time| as a string value mapped to |key| in |dictionary|. |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1643 return extension; | 1629 return extension; |
1644 } | 1630 } |
1645 | 1631 |
1646 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo( | 1632 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo( |
1647 const std::string& extension_id) const { | 1633 const std::string& extension_id) const { |
1648 const DictionaryValue* ext; | 1634 const DictionaryValue* ext; |
1649 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); | 1635 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); |
1650 if (!extensions || | 1636 if (!extensions || |
1651 !extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext)) | 1637 !extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext)) |
1652 return scoped_ptr<ExtensionInfo>(); | 1638 return scoped_ptr<ExtensionInfo>(); |
1653 if (IsBlacklistBitSet(ext)) | |
1654 return scoped_ptr<ExtensionInfo>(); | |
1655 int state_value; | 1639 int state_value; |
1656 if (!ext->GetInteger(kPrefState, &state_value) || | 1640 if (!ext->GetInteger(kPrefState, &state_value) || |
1657 state_value == Extension::ENABLED_COMPONENT) { | 1641 state_value == Extension::ENABLED_COMPONENT) { |
1658 // Old preferences files may not have kPrefState for component extensions. | 1642 // Old preferences files may not have kPrefState for component extensions. |
1659 return scoped_ptr<ExtensionInfo>(); | 1643 return scoped_ptr<ExtensionInfo>(); |
1660 } | 1644 } |
1661 | 1645 |
1662 if (state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) { | 1646 if (state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) { |
1663 LOG(WARNING) << "External extension with id " << extension_id | 1647 LOG(WARNING) << "External extension with id " << extension_id |
1664 << " has been uninstalled by the user"; | 1648 << " has been uninstalled by the user"; |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2004 return result; // Empty set | 1988 return result; // Empty set |
2005 } | 1989 } |
2006 | 1990 |
2007 for (base::DictionaryValue::key_iterator it = extension_prefs->begin_keys(); | 1991 for (base::DictionaryValue::key_iterator it = extension_prefs->begin_keys(); |
2008 it != extension_prefs->end_keys(); ++it) { | 1992 it != extension_prefs->end_keys(); ++it) { |
2009 const DictionaryValue* ext; | 1993 const DictionaryValue* ext; |
2010 if (!extension_prefs->GetDictionaryWithoutPathExpansion(*it, &ext)) { | 1994 if (!extension_prefs->GetDictionaryWithoutPathExpansion(*it, &ext)) { |
2011 NOTREACHED() << "Invalid pref for extension " << *it; | 1995 NOTREACHED() << "Invalid pref for extension " << *it; |
2012 continue; | 1996 continue; |
2013 } | 1997 } |
2014 if (!IsBlacklistBitSet(ext)) | |
2015 result.push_back(*it); | |
2016 } | 1998 } |
2017 return result; | 1999 return result; |
2018 } | 2000 } |
2019 | 2001 |
2020 void ExtensionPrefs::FixMissingPrefs(const ExtensionIdList& extension_ids) { | 2002 void ExtensionPrefs::FixMissingPrefs(const ExtensionIdList& extension_ids) { |
2021 // Fix old entries that did not get an installation time entry when they | 2003 // Fix old entries that did not get an installation time entry when they |
2022 // were installed or don't have a preferences field. | 2004 // were installed or don't have a preferences field. |
2023 for (ExtensionIdList::const_iterator ext_id = extension_ids.begin(); | 2005 for (ExtensionIdList::const_iterator ext_id = extension_ids.begin(); |
2024 ext_id != extension_ids.end(); ++ext_id) { | 2006 ext_id != extension_ids.end(); ++ext_id) { |
2025 if (GetInstallTime(*ext_id) == base::Time()) { | 2007 if (GetInstallTime(*ext_id) == base::Time()) { |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2314 const ExtensionIdList& strings) { | 2296 const ExtensionIdList& strings) { |
2315 ListPrefUpdate update(prefs_, pref); | 2297 ListPrefUpdate update(prefs_, pref); |
2316 ListValue* list_of_values = update.Get(); | 2298 ListValue* list_of_values = update.Get(); |
2317 list_of_values->Clear(); | 2299 list_of_values->Clear(); |
2318 for (ExtensionIdList::const_iterator iter = strings.begin(); | 2300 for (ExtensionIdList::const_iterator iter = strings.begin(); |
2319 iter != strings.end(); ++iter) | 2301 iter != strings.end(); ++iter) |
2320 list_of_values->Append(new StringValue(*iter)); | 2302 list_of_values->Append(new StringValue(*iter)); |
2321 } | 2303 } |
2322 | 2304 |
2323 } // namespace extensions | 2305 } // namespace extensions |
OLD | NEW |