OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/prefs/pref_notifier.h" | 10 #include "chrome/browser/prefs/pref_notifier.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 const char kBrowserActionVisible[] = "browser_action_visible"; | 85 const char kBrowserActionVisible[] = "browser_action_visible"; |
86 | 86 |
87 // Preferences that hold which permissions the user has granted the extension. | 87 // Preferences that hold which permissions the user has granted the extension. |
88 // We explicitly keep track of these so that extensions can contain unknown | 88 // We explicitly keep track of these so that extensions can contain unknown |
89 // permissions, for backwards compatibility reasons, and we can still prompt | 89 // permissions, for backwards compatibility reasons, and we can still prompt |
90 // the user to accept them once recognized. | 90 // the user to accept them once recognized. |
91 const char kPrefGrantedPermissionsAPI[] = "granted_permissions.api"; | 91 const char kPrefGrantedPermissionsAPI[] = "granted_permissions.api"; |
92 const char kPrefGrantedPermissionsHost[] = "granted_permissions.host"; | 92 const char kPrefGrantedPermissionsHost[] = "granted_permissions.host"; |
93 const char kPrefGrantedPermissionsAll[] = "granted_permissions.full"; | 93 const char kPrefGrantedPermissionsAll[] = "granted_permissions.full"; |
94 | 94 |
95 // A preference that indicates when an extension was installed. | |
96 const char kPrefInstallTime[] = "install_time"; | |
97 | |
98 // A preference that contains any extension-controlled preferences. | |
99 const char kPrefPreferences[] = "preferences"; | |
100 | |
95 } // namespace | 101 } // namespace |
96 | 102 |
97 //////////////////////////////////////////////////////////////////////////////// | 103 //////////////////////////////////////////////////////////////////////////////// |
98 | 104 |
99 namespace { | 105 namespace { |
100 | 106 |
101 // TODO(asargent) - This is cleanup code for a key that was introduced into | 107 // TODO(asargent) - This is cleanup code for a key that was introduced into |
102 // the extensions.settings sub-dictionary which wasn't a valid extension | 108 // the extensions.settings sub-dictionary which wasn't a valid extension |
103 // id. We can remove this in a couple of months. (See http://crbug.com/40017 | 109 // id. We can remove this in a couple of months. (See http://crbug.com/40017 |
104 // and http://crbug.com/39745 for more details). | 110 // and http://crbug.com/39745 for more details). |
(...skipping 27 matching lines...) Expand all Loading... | |
132 result->insert(i->GetAsString()); | 138 result->insert(i->GetAsString()); |
133 } | 139 } |
134 | 140 |
135 } // namespace | 141 } // namespace |
136 | 142 |
137 ExtensionPrefs::ExtensionPrefs(PrefService* prefs, const FilePath& root_dir) | 143 ExtensionPrefs::ExtensionPrefs(PrefService* prefs, const FilePath& root_dir) |
138 : prefs_(prefs), | 144 : prefs_(prefs), |
139 install_directory_(root_dir) { | 145 install_directory_(root_dir) { |
140 // TODO(asargent) - Remove this in a couple of months. (See comment above | 146 // TODO(asargent) - Remove this in a couple of months. (See comment above |
141 // CleanupBadExtensionKeys). | 147 // CleanupBadExtensionKeys). |
142 CleanupBadExtensionKeys(prefs); | 148 CleanupBadExtensionKeys(prefs_); |
143 | 149 |
144 MakePathsRelative(); | 150 MakePathsRelative(); |
151 | |
152 InitPrefStore(); | |
145 } | 153 } |
146 | 154 |
147 ExtensionPrefs::~ExtensionPrefs() {} | 155 ExtensionPrefs::~ExtensionPrefs() {} |
148 | 156 |
149 // static | 157 // static |
150 const char ExtensionPrefs::kExtensionsPref[] = "extensions.settings"; | 158 const char ExtensionPrefs::kExtensionsPref[] = "extensions.settings"; |
151 | 159 |
152 static FilePath::StringType MakePathRelative(const FilePath& parent, | 160 static FilePath::StringType MakePathRelative(const FilePath& parent, |
153 const FilePath& child, | 161 const FilePath& child, |
154 bool *dirty) { | 162 bool *dirty) { |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
636 // Check to see if the extension has been killed. | 644 // Check to see if the extension has been killed. |
637 int state; | 645 int state; |
638 if (extension->GetInteger(kPrefState, &state) && | 646 if (extension->GetInteger(kPrefState, &state) && |
639 state == static_cast<int>(Extension::KILLBIT)) { | 647 state == static_cast<int>(Extension::KILLBIT)) { |
640 killed_ids->insert(StringToLowerASCII(key_name)); | 648 killed_ids->insert(StringToLowerASCII(key_name)); |
641 } | 649 } |
642 } | 650 } |
643 } | 651 } |
644 | 652 |
645 std::vector<std::string> ExtensionPrefs::GetToolbarOrder() { | 653 std::vector<std::string> ExtensionPrefs::GetToolbarOrder() { |
646 std::vector<std::string> extension_ids; | 654 ExtensionPrefs::ExtensionIdSet extension_ids; |
647 const ListValue* toolbar_order = prefs_->GetList(kExtensionToolbar); | 655 const ListValue* toolbar_order = prefs_->GetList(kExtensionToolbar); |
648 if (toolbar_order) { | 656 if (toolbar_order) { |
649 for (size_t i = 0; i < toolbar_order->GetSize(); ++i) { | 657 for (size_t i = 0; i < toolbar_order->GetSize(); ++i) { |
650 std::string extension_id; | 658 std::string extension_id; |
651 if (toolbar_order->GetString(i, &extension_id)) | 659 if (toolbar_order->GetString(i, &extension_id)) |
652 extension_ids.push_back(extension_id); | 660 extension_ids.push_back(extension_id); |
653 } | 661 } |
654 } | 662 } |
655 return extension_ids; | 663 return extension_ids; |
656 } | 664 } |
657 | 665 |
658 void ExtensionPrefs::SetToolbarOrder( | 666 void ExtensionPrefs::SetToolbarOrder( |
659 const std::vector<std::string>& extension_ids) { | 667 const std::vector<std::string>& extension_ids) { |
660 ListValue* toolbar_order = prefs_->GetMutableList(kExtensionToolbar); | 668 ListValue* toolbar_order = prefs_->GetMutableList(kExtensionToolbar); |
661 toolbar_order->Clear(); | 669 toolbar_order->Clear(); |
662 for (std::vector<std::string>::const_iterator iter = extension_ids.begin(); | 670 for (std::vector<std::string>::const_iterator iter = extension_ids.begin(); |
663 iter != extension_ids.end(); ++iter) { | 671 iter != extension_ids.end(); ++iter) { |
664 toolbar_order->Append(new StringValue(*iter)); | 672 toolbar_order->Append(new StringValue(*iter)); |
665 } | 673 } |
666 SavePrefsAndNotify(); | 674 SavePrefsAndNotify(); |
667 } | 675 } |
668 | 676 |
669 void ExtensionPrefs::OnExtensionInstalled( | 677 void ExtensionPrefs::OnExtensionInstalled( |
670 const Extension* extension, Extension::State initial_state, | 678 const Extension* extension, Extension::State initial_state, |
671 bool initial_incognito_enabled) { | 679 bool initial_incognito_enabled) { |
672 const std::string& id = extension->id(); | 680 const std::string& id = extension->id(); |
681 const base::Time install_time = GetCurrentTime(); | |
673 UpdateExtensionPref(id, kPrefState, | 682 UpdateExtensionPref(id, kPrefState, |
674 Value::CreateIntegerValue(initial_state)); | 683 Value::CreateIntegerValue(initial_state)); |
675 UpdateExtensionPref(id, kPrefIncognitoEnabled, | 684 UpdateExtensionPref(id, kPrefIncognitoEnabled, |
676 Value::CreateBooleanValue(initial_incognito_enabled)); | 685 Value::CreateBooleanValue(initial_incognito_enabled)); |
677 UpdateExtensionPref(id, kPrefLocation, | 686 UpdateExtensionPref(id, kPrefLocation, |
678 Value::CreateIntegerValue(extension->location())); | 687 Value::CreateIntegerValue(extension->location())); |
688 UpdateExtensionPref(id, kPrefInstallTime, | |
689 Value::CreateStringValue( | |
690 base::Int64ToString(install_time.ToInternalValue()))); | |
691 UpdateExtensionPref(id, kPrefPreferences, new DictionaryValue()); | |
692 | |
679 FilePath::StringType path = MakePathRelative(install_directory_, | 693 FilePath::StringType path = MakePathRelative(install_directory_, |
680 extension->path(), NULL); | 694 extension->path(), NULL); |
681 UpdateExtensionPref(id, kPrefPath, Value::CreateStringValue(path)); | 695 UpdateExtensionPref(id, kPrefPath, Value::CreateStringValue(path)); |
682 // We store prefs about LOAD extensions, but don't cache their manifest | 696 // We store prefs about LOAD extensions, but don't cache their manifest |
683 // since it may change on disk. | 697 // since it may change on disk. |
684 if (extension->location() != Extension::LOAD) { | 698 if (extension->location() != Extension::LOAD) { |
685 UpdateExtensionPref(id, kPrefManifest, | 699 UpdateExtensionPref(id, kPrefManifest, |
686 extension->manifest_value()->DeepCopy()); | 700 extension->manifest_value()->DeepCopy()); |
687 } | 701 } |
688 UpdateExtensionPref(id, kPrefAppLaunchIndex, | 702 UpdateExtensionPref(id, kPrefAppLaunchIndex, |
689 Value::CreateIntegerValue(GetNextAppLaunchIndex())); | 703 Value::CreateIntegerValue(GetNextAppLaunchIndex())); |
690 SavePrefsAndNotify(); | 704 SavePrefsAndNotify(); |
691 } | 705 } |
692 | 706 |
693 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, | 707 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, |
694 const Extension::Location& location, | 708 const Extension::Location& location, |
695 bool external_uninstall) { | 709 bool external_uninstall) { |
710 PrefKeySet pref_keys; | |
711 GetExtensionControlledPrefKeys(extension_id, &pref_keys); | |
712 | |
696 // For external extensions, we save a preference reminding ourself not to try | 713 // For external extensions, we save a preference reminding ourself not to try |
697 // and install the extension anymore (except when |external_uninstall| is | 714 // and install the extension anymore (except when |external_uninstall| is |
698 // true, which signifies that the registry key was deleted or the pref file | 715 // true, which signifies that the registry key was deleted or the pref file |
699 // no longer lists the extension). | 716 // no longer lists the extension). |
700 if (!external_uninstall && Extension::IsExternalLocation(location)) { | 717 if (!external_uninstall && Extension::IsExternalLocation(location)) { |
701 UpdateExtensionPref(extension_id, kPrefState, | 718 UpdateExtensionPref(extension_id, kPrefState, |
702 Value::CreateIntegerValue(Extension::KILLBIT)); | 719 Value::CreateIntegerValue(Extension::KILLBIT)); |
703 SavePrefsAndNotify(); | 720 SavePrefsAndNotify(); |
704 } else { | 721 } else { |
705 DeleteExtensionPrefs(extension_id); | 722 DeleteExtensionPrefs(extension_id); |
706 } | 723 } |
724 | |
725 UpdatePrefStore(pref_keys); | |
707 } | 726 } |
708 | 727 |
709 Extension::State ExtensionPrefs::GetExtensionState( | 728 Extension::State ExtensionPrefs::GetExtensionState( |
710 const std::string& extension_id) { | 729 const std::string& extension_id) const { |
711 DictionaryValue* extension = GetExtensionPref(extension_id); | 730 DictionaryValue* extension = GetExtensionPref(extension_id); |
712 | 731 |
713 // If the extension doesn't have a pref, it's a --load-extension. | 732 // If the extension doesn't have a pref, it's a --load-extension. |
714 if (!extension) | 733 if (!extension) |
715 return Extension::ENABLED; | 734 return Extension::ENABLED; |
716 | 735 |
717 int state = -1; | 736 int state = -1; |
718 if (!extension->GetInteger(kPrefState, &state) || | 737 if (!extension->GetInteger(kPrefState, &state) || |
719 state < 0 || state >= Extension::NUM_STATES) { | 738 state < 0 || state >= Extension::NUM_STATES) { |
720 LOG(ERROR) << "Bad or missing pref 'state' for extension '" | 739 LOG(ERROR) << "Bad or missing pref 'state' for extension '" |
721 << extension_id << "'"; | 740 << extension_id << "'"; |
722 return Extension::ENABLED; | 741 return Extension::ENABLED; |
723 } | 742 } |
724 return static_cast<Extension::State>(state); | 743 return static_cast<Extension::State>(state); |
725 } | 744 } |
726 | 745 |
727 void ExtensionPrefs::SetExtensionState(const Extension* extension, | 746 void ExtensionPrefs::SetExtensionState(const Extension* extension, |
728 Extension::State state) { | 747 Extension::State state) { |
729 UpdateExtensionPref(extension->id(), kPrefState, | 748 UpdateExtensionPref(extension->id(), kPrefState, |
730 Value::CreateIntegerValue(state)); | 749 Value::CreateIntegerValue(state)); |
750 | |
751 PrefKeySet pref_keys; | |
752 GetExtensionControlledPrefKeys(extension->id(), &pref_keys); | |
753 UpdatePrefStore(pref_keys); | |
754 | |
731 SavePrefsAndNotify(); | 755 SavePrefsAndNotify(); |
732 } | 756 } |
733 | 757 |
734 bool ExtensionPrefs::GetBrowserActionVisibility(const Extension* extension) { | 758 bool ExtensionPrefs::GetBrowserActionVisibility(const Extension* extension) { |
735 DictionaryValue* extension_prefs = GetExtensionPref(extension->id()); | 759 DictionaryValue* extension_prefs = GetExtensionPref(extension->id()); |
736 bool visible = false; | 760 bool visible = false; |
737 if (!extension_prefs->GetBoolean(kBrowserActionVisible, &visible) || visible) | 761 if (!extension_prefs->GetBoolean(kBrowserActionVisible, &visible) || visible) |
738 return true; | 762 return true; |
739 | 763 |
740 return false; | 764 return false; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
824 DictionaryValue* ExtensionPrefs::GetExtensionPref( | 848 DictionaryValue* ExtensionPrefs::GetExtensionPref( |
825 const std::string& extension_id) const { | 849 const std::string& extension_id) const { |
826 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); | 850 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); |
827 if (!dict) | 851 if (!dict) |
828 return NULL; | 852 return NULL; |
829 DictionaryValue* extension = NULL; | 853 DictionaryValue* extension = NULL; |
830 dict->GetDictionary(extension_id, &extension); | 854 dict->GetDictionary(extension_id, &extension); |
831 return extension; | 855 return extension; |
832 } | 856 } |
833 | 857 |
858 DictionaryValue* ExtensionPrefs::GetExtensionControlledPrefs( | |
859 const std::string& extension_id) const { | |
860 DictionaryValue* extension = GetExtensionPref(extension_id); | |
861 if (!extension) { | |
862 NOTREACHED(); | |
863 return NULL; | |
864 } | |
865 DictionaryValue* preferences = NULL; | |
866 extension->GetDictionary(kPrefPreferences, &preferences); | |
867 return preferences; | |
868 } | |
869 | |
834 // Helper function for GetInstalledExtensionsInfo. | 870 // Helper function for GetInstalledExtensionsInfo. |
835 static ExtensionInfo* GetInstalledExtensionInfoImpl( | 871 static ExtensionInfo* GetInstalledExtensionInfoImpl( |
836 DictionaryValue* extension_data, | 872 DictionaryValue* extension_data, |
837 DictionaryValue::key_iterator extension_id) { | 873 DictionaryValue::key_iterator extension_id) { |
838 DictionaryValue* ext; | 874 DictionaryValue* ext; |
839 if (!extension_data->GetDictionaryWithoutPathExpansion(*extension_id, &ext)) { | 875 if (!extension_data->GetDictionaryWithoutPathExpansion(*extension_id, &ext)) { |
840 LOG(WARNING) << "Invalid pref for extension " << *extension_id; | 876 LOG(WARNING) << "Invalid pref for extension " << *extension_id; |
841 NOTREACHED(); | 877 NOTREACHED(); |
842 return NULL; | 878 return NULL; |
843 } | 879 } |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1083 std::string ExtensionPrefs::GetUpdateUrlData(const std::string& extension_id) { | 1119 std::string ExtensionPrefs::GetUpdateUrlData(const std::string& extension_id) { |
1084 DictionaryValue* dictionary = GetExtensionPref(extension_id); | 1120 DictionaryValue* dictionary = GetExtensionPref(extension_id); |
1085 if (!dictionary) | 1121 if (!dictionary) |
1086 return std::string(); | 1122 return std::string(); |
1087 | 1123 |
1088 std::string data; | 1124 std::string data; |
1089 dictionary->GetString(kUpdateUrlData, &data); | 1125 dictionary->GetString(kUpdateUrlData, &data); |
1090 return data; | 1126 return data; |
1091 } | 1127 } |
1092 | 1128 |
1129 base::Time ExtensionPrefs::GetCurrentTime() const { | |
1130 return base::Time::Now(); | |
1131 } | |
1132 | |
1133 base::Time ExtensionPrefs::GetInstallTime( | |
1134 const std::string& extension_id) const { | |
1135 const DictionaryValue* extension = GetExtensionPref(extension_id); | |
1136 if (!extension) { | |
1137 NOTREACHED(); | |
Aaron Boodman
2010/12/03 20:00:44
If this really can't happen, then CHECK(extension)
battre (please use the other)
2010/12/06 10:28:50
In can happen if the programmer passed an invalid
| |
1138 return base::Time::Time(); | |
1139 } | |
1140 std::string install_time_str("0"); | |
1141 extension->GetString(kPrefInstallTime, &install_time_str); | |
1142 int64 install_time_i64 = 0; | |
1143 base::StringToInt64(install_time_str, &install_time_i64); | |
1144 LOG_IF(ERROR, install_time_i64 == 0) | |
1145 << "Error parsing installation time of an extension."; | |
1146 return base::Time::FromInternalValue(install_time_i64); | |
1147 } | |
1148 | |
1149 void ExtensionPrefs::GetEnabledExtensions(ExtensionIdSet* out) const { | |
1150 DCHECK(out); | |
Aaron Boodman
2010/12/03 20:00:44
Don't be a wuss: CHECK(out).
battre (please use the other)
2010/12/06 10:28:50
Done.
| |
1151 const DictionaryValue* extensions = | |
1152 pref_service()->GetDictionary(kExtensionsPref); | |
1153 | |
1154 for (DictionaryValue::key_iterator ext_id = extensions->begin_keys(); | |
1155 ext_id != extensions->end_keys(); ++ext_id) { | |
1156 if (GetExtensionState(*ext_id) != Extension::ENABLED) | |
1157 continue; | |
1158 out->push_back(*ext_id); | |
1159 } | |
1160 } | |
1161 | |
1162 void ExtensionPrefs::FixMissingPrefs(const ExtensionIdSet& extension_ids) { | |
1163 // Fix old entries that did not get an installation time entry when they | |
1164 // were installed or don't have a preferences field. | |
1165 bool persist_required = false; | |
1166 for (ExtensionIdSet::const_iterator ext_id = extension_ids.begin(); | |
1167 ext_id != extension_ids.end(); ++ext_id) { | |
1168 DictionaryValue* extension = GetExtensionPref(*ext_id); | |
1169 if (extension == NULL) { | |
Aaron Boodman
2010/12/03 20:00:44
CHECK(extension)
battre (please use the other)
2010/12/06 10:28:50
Done.
| |
1170 NOTREACHED(); | |
1171 continue; | |
1172 } | |
1173 | |
1174 if (GetInstallTime(*ext_id) == base::Time::Time()) { | |
1175 const base::Time install_time = GetCurrentTime(); | |
1176 extension->Set(kPrefInstallTime, | |
1177 Value::CreateStringValue( | |
1178 base::Int64ToString(install_time.ToInternalValue()))); | |
1179 persist_required = true; | |
1180 } | |
1181 } | |
1182 if (persist_required) | |
1183 SavePrefsAndNotify(); | |
1184 } | |
1185 | |
1186 void ExtensionPrefs::InitPrefStore() { | |
1187 // When this is called, the PrefService is initialized and provides access | |
1188 // to the user preferences stored in a JSON file. | |
1189 ExtensionIdSet extension_ids; | |
1190 GetEnabledExtensions(&extension_ids); | |
1191 FixMissingPrefs(extension_ids); | |
1192 | |
1193 // Collect the unique extension controlled preference keys of all extensions. | |
1194 PrefKeySet ext_controlled_prefs; | |
1195 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); | |
1196 ext_id != extension_ids.end(); ++ext_id) { | |
1197 GetExtensionControlledPrefKeys(*ext_id, &ext_controlled_prefs); | |
1198 } | |
1199 | |
1200 // Store winning preference for each extension controlled preference. | |
1201 UpdatePrefStore(ext_controlled_prefs); | |
1202 } | |
1203 | |
1204 const Value* ExtensionPrefs::GetWinningExtensionControlledPrefValue( | |
1205 const std::string& key) const { | |
1206 Value *winner = NULL; | |
1207 base::Time winners_install_time = base::Time::Time(); | |
1208 | |
1209 ExtensionIdSet extension_ids; | |
1210 GetEnabledExtensions(&extension_ids); | |
1211 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); | |
1212 ext_id != extension_ids.end(); ++ext_id) { | |
1213 base::Time extension_install_time = GetInstallTime(*ext_id); | |
1214 | |
1215 // We do not need to consider extensions that were installed before the | |
1216 // most recent extension found that provides the requested preference. | |
1217 if (extension_install_time < winners_install_time) | |
1218 continue; | |
1219 | |
1220 DictionaryValue* preferences = GetExtensionControlledPrefs(*ext_id); | |
1221 Value *value = NULL; | |
1222 if (preferences && preferences->GetWithoutPathExpansion(key, &value)) { | |
1223 // This extension is more recent than the last one providing this pref. | |
1224 winner = value; | |
1225 winners_install_time = extension_install_time; | |
1226 } | |
1227 } | |
1228 | |
1229 return winner; | |
1230 } | |
1231 | |
1232 void ExtensionPrefs::UpdatePrefStore( | |
1233 const ExtensionPrefs::PrefKeySet& pref_keys) { | |
1234 for (PrefKeySet::const_iterator i = pref_keys.begin(); | |
1235 i != pref_keys.end(); ++i) { | |
1236 UpdatePrefStore(*i); | |
1237 } | |
1238 } | |
1239 | |
1240 void ExtensionPrefs::UpdatePrefStore(const std::string& pref_key) { | |
1241 PrefStore* extension_pref_store = | |
1242 pref_service()->GetExtensionPrefStore(); | |
1243 if (extension_pref_store == NULL) | |
1244 return; // Profile is being shut down, Pref Service is already gone. | |
1245 const Value* winning_pref_value = | |
1246 GetWinningExtensionControlledPrefValue(pref_key); | |
1247 Value* old_value = NULL; | |
1248 extension_pref_store->prefs()->Get(pref_key, &old_value); | |
1249 bool changed = !Value::Equals(winning_pref_value, old_value); | |
1250 | |
1251 if (winning_pref_value) { | |
1252 extension_pref_store->prefs()->Set(pref_key, | |
1253 winning_pref_value->DeepCopy()); | |
1254 } else { | |
1255 extension_pref_store->prefs()->Remove(pref_key, NULL); | |
1256 } | |
1257 | |
1258 if (changed) { | |
1259 pref_service()->pref_notifier()->OnPreferenceSet( | |
1260 pref_key.c_str(), PrefNotifier::EXTENSION_STORE); | |
1261 } | |
1262 } | |
1263 | |
1264 void ExtensionPrefs::SetExtensionControlledPref(const std::string& extension_id, | |
1265 const std::string& pref_key, | |
1266 Value* value) { | |
1267 DCHECK(pref_service()->FindPreference(pref_key.c_str())) | |
1268 << "Extension controlled preference key " << pref_key | |
1269 << " not registered."; | |
1270 DictionaryValue* extension_preferences = | |
1271 GetExtensionControlledPrefs(extension_id); | |
1272 | |
1273 if (extension_preferences == NULL) { // May be pruned when writing to disk. | |
1274 DictionaryValue* extension = GetExtensionPref(extension_id); | |
1275 if (extension == NULL) { | |
1276 NOTREACHED() << "Extension preference undefined"; | |
1277 return; | |
1278 } | |
1279 extension_preferences = new DictionaryValue; | |
1280 extension->Set(kPrefPreferences, extension_preferences); | |
1281 } | |
1282 | |
1283 Value* oldValue = NULL; | |
1284 extension_preferences->GetWithoutPathExpansion(pref_key, &oldValue); | |
1285 bool modified = !Value::Equals(oldValue, value); | |
1286 if (!modified) | |
1287 return; | |
1288 | |
1289 if (value == NULL) | |
1290 extension_preferences->RemoveWithoutPathExpansion(pref_key, NULL); | |
1291 else | |
1292 extension_preferences->SetWithoutPathExpansion(pref_key, value); | |
1293 pref_service()->ScheduleSavePersistentPrefs(); | |
1294 | |
1295 UpdatePrefStore(pref_key); | |
1296 } | |
1297 | |
1298 void ExtensionPrefs::GetExtensionControlledPrefKeys( | |
1299 const std::string& extension_id, PrefKeySet *out) const { | |
1300 DCHECK(out != NULL); | |
1301 DictionaryValue* ext_prefs = GetExtensionControlledPrefs(extension_id); | |
1302 if (ext_prefs) { | |
1303 for (DictionaryValue::key_iterator i = ext_prefs->begin_keys(); | |
1304 i != ext_prefs->end_keys(); ++i) { | |
1305 out->insert(*i); | |
1306 } | |
1307 } | |
1308 } | |
1309 | |
1093 // static | 1310 // static |
1094 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { | 1311 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { |
1095 prefs->RegisterDictionaryPref(kExtensionsPref); | 1312 prefs->RegisterDictionaryPref(kExtensionsPref); |
1096 prefs->RegisterListPref(kExtensionToolbar); | 1313 prefs->RegisterListPref(kExtensionToolbar); |
1097 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); | 1314 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); |
1098 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); | 1315 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); |
1099 prefs->RegisterListPref(prefs::kExtensionInstallAllowList); | 1316 prefs->RegisterListPref(prefs::kExtensionInstallAllowList); |
1100 prefs->RegisterListPref(prefs::kExtensionInstallDenyList); | 1317 prefs->RegisterListPref(prefs::kExtensionInstallDenyList); |
1101 prefs->RegisterListPref(prefs::kExtensionInstallForceList); | 1318 prefs->RegisterListPref(prefs::kExtensionInstallForceList); |
1102 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); | 1319 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); |
1103 } | 1320 } |
OLD | NEW |