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(); |
| 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 CHECK(out); |
| 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 CHECK(extension); |
| 1170 |
| 1171 if (GetInstallTime(*ext_id) == base::Time::Time()) { |
| 1172 const base::Time install_time = GetCurrentTime(); |
| 1173 extension->Set(kPrefInstallTime, |
| 1174 Value::CreateStringValue( |
| 1175 base::Int64ToString(install_time.ToInternalValue()))); |
| 1176 persist_required = true; |
| 1177 } |
| 1178 } |
| 1179 if (persist_required) |
| 1180 SavePrefsAndNotify(); |
| 1181 } |
| 1182 |
| 1183 void ExtensionPrefs::InitPrefStore() { |
| 1184 // When this is called, the PrefService is initialized and provides access |
| 1185 // to the user preferences stored in a JSON file. |
| 1186 ExtensionIdSet extension_ids; |
| 1187 GetEnabledExtensions(&extension_ids); |
| 1188 FixMissingPrefs(extension_ids); |
| 1189 |
| 1190 // Collect the unique extension controlled preference keys of all extensions. |
| 1191 PrefKeySet ext_controlled_prefs; |
| 1192 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); |
| 1193 ext_id != extension_ids.end(); ++ext_id) { |
| 1194 GetExtensionControlledPrefKeys(*ext_id, &ext_controlled_prefs); |
| 1195 } |
| 1196 |
| 1197 // Store winning preference for each extension controlled preference. |
| 1198 UpdatePrefStore(ext_controlled_prefs); |
| 1199 } |
| 1200 |
| 1201 const Value* ExtensionPrefs::GetWinningExtensionControlledPrefValue( |
| 1202 const std::string& key) const { |
| 1203 Value *winner = NULL; |
| 1204 base::Time winners_install_time = base::Time::Time(); |
| 1205 |
| 1206 ExtensionIdSet extension_ids; |
| 1207 GetEnabledExtensions(&extension_ids); |
| 1208 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); |
| 1209 ext_id != extension_ids.end(); ++ext_id) { |
| 1210 base::Time extension_install_time = GetInstallTime(*ext_id); |
| 1211 |
| 1212 // We do not need to consider extensions that were installed before the |
| 1213 // most recent extension found that provides the requested preference. |
| 1214 if (extension_install_time < winners_install_time) |
| 1215 continue; |
| 1216 |
| 1217 DictionaryValue* preferences = GetExtensionControlledPrefs(*ext_id); |
| 1218 Value *value = NULL; |
| 1219 if (preferences && preferences->GetWithoutPathExpansion(key, &value)) { |
| 1220 // This extension is more recent than the last one providing this pref. |
| 1221 winner = value; |
| 1222 winners_install_time = extension_install_time; |
| 1223 } |
| 1224 } |
| 1225 |
| 1226 return winner; |
| 1227 } |
| 1228 |
| 1229 void ExtensionPrefs::UpdatePrefStore( |
| 1230 const ExtensionPrefs::PrefKeySet& pref_keys) { |
| 1231 for (PrefKeySet::const_iterator i = pref_keys.begin(); |
| 1232 i != pref_keys.end(); ++i) { |
| 1233 UpdatePrefStore(*i); |
| 1234 } |
| 1235 } |
| 1236 |
| 1237 void ExtensionPrefs::UpdatePrefStore(const std::string& pref_key) { |
| 1238 PrefStore* extension_pref_store = |
| 1239 pref_service()->GetExtensionPrefStore(); |
| 1240 if (extension_pref_store == NULL) |
| 1241 return; // Profile is being shut down, Pref Service is already gone. |
| 1242 const Value* winning_pref_value = |
| 1243 GetWinningExtensionControlledPrefValue(pref_key); |
| 1244 Value* old_value = NULL; |
| 1245 extension_pref_store->prefs()->Get(pref_key, &old_value); |
| 1246 bool changed = !Value::Equals(winning_pref_value, old_value); |
| 1247 |
| 1248 if (winning_pref_value) { |
| 1249 extension_pref_store->prefs()->Set(pref_key, |
| 1250 winning_pref_value->DeepCopy()); |
| 1251 } else { |
| 1252 extension_pref_store->prefs()->Remove(pref_key, NULL); |
| 1253 } |
| 1254 |
| 1255 if (changed) { |
| 1256 pref_service()->pref_notifier()->OnPreferenceSet( |
| 1257 pref_key.c_str(), PrefNotifier::EXTENSION_STORE); |
| 1258 } |
| 1259 } |
| 1260 |
| 1261 void ExtensionPrefs::SetExtensionControlledPref(const std::string& extension_id, |
| 1262 const std::string& pref_key, |
| 1263 Value* value) { |
| 1264 DCHECK(pref_service()->FindPreference(pref_key.c_str())) |
| 1265 << "Extension controlled preference key " << pref_key |
| 1266 << " not registered."; |
| 1267 DictionaryValue* extension_preferences = |
| 1268 GetExtensionControlledPrefs(extension_id); |
| 1269 |
| 1270 if (extension_preferences == NULL) { // May be pruned when writing to disk. |
| 1271 DictionaryValue* extension = GetExtensionPref(extension_id); |
| 1272 if (extension == NULL) { |
| 1273 LOG(ERROR) << "Extension preference for " << extension_id << " undefined"; |
| 1274 return; |
| 1275 } |
| 1276 extension_preferences = new DictionaryValue; |
| 1277 extension->Set(kPrefPreferences, extension_preferences); |
| 1278 } |
| 1279 |
| 1280 Value* oldValue = NULL; |
| 1281 extension_preferences->GetWithoutPathExpansion(pref_key, &oldValue); |
| 1282 bool modified = !Value::Equals(oldValue, value); |
| 1283 if (!modified) |
| 1284 return; |
| 1285 |
| 1286 if (value == NULL) |
| 1287 extension_preferences->RemoveWithoutPathExpansion(pref_key, NULL); |
| 1288 else |
| 1289 extension_preferences->SetWithoutPathExpansion(pref_key, value); |
| 1290 pref_service()->ScheduleSavePersistentPrefs(); |
| 1291 |
| 1292 UpdatePrefStore(pref_key); |
| 1293 } |
| 1294 |
| 1295 void ExtensionPrefs::GetExtensionControlledPrefKeys( |
| 1296 const std::string& extension_id, PrefKeySet *out) const { |
| 1297 DCHECK(out != NULL); |
| 1298 DictionaryValue* ext_prefs = GetExtensionControlledPrefs(extension_id); |
| 1299 if (ext_prefs) { |
| 1300 for (DictionaryValue::key_iterator i = ext_prefs->begin_keys(); |
| 1301 i != ext_prefs->end_keys(); ++i) { |
| 1302 out->insert(*i); |
| 1303 } |
| 1304 } |
| 1305 } |
| 1306 |
1093 // static | 1307 // static |
1094 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { | 1308 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { |
1095 prefs->RegisterDictionaryPref(kExtensionsPref); | 1309 prefs->RegisterDictionaryPref(kExtensionsPref); |
1096 prefs->RegisterListPref(kExtensionToolbar); | 1310 prefs->RegisterListPref(kExtensionToolbar); |
1097 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); | 1311 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); |
1098 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); | 1312 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); |
1099 prefs->RegisterListPref(prefs::kExtensionInstallAllowList); | 1313 prefs->RegisterListPref(prefs::kExtensionInstallAllowList); |
1100 prefs->RegisterListPref(prefs::kExtensionInstallDenyList); | 1314 prefs->RegisterListPref(prefs::kExtensionInstallDenyList); |
1101 prefs->RegisterListPref(prefs::kExtensionInstallForceList); | 1315 prefs->RegisterListPref(prefs::kExtensionInstallForceList); |
1102 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); | 1316 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); |
1103 } | 1317 } |
OLD | NEW |