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/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/admin_policy.h" | 10 #include "chrome/browser/extensions/admin_policy.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 // Indicates whether to show an install warning when the user enables. | 63 // Indicates whether to show an install warning when the user enables. |
64 const char kExtensionDidEscalatePermissions[] = "install_warning_on_enable"; | 64 const char kExtensionDidEscalatePermissions[] = "install_warning_on_enable"; |
65 | 65 |
66 // Indicates whether the extension was updated while it was disabled. | 66 // Indicates whether the extension was updated while it was disabled. |
67 const char kPrefDisableReason[] = "disable_reason"; | 67 const char kPrefDisableReason[] = "disable_reason"; |
68 | 68 |
69 // A preference that tracks browser action toolbar configuration. This is a list | 69 // A preference that tracks browser action toolbar configuration. This is a list |
70 // object stored in the Preferences file. The extensions are stored by ID. | 70 // object stored in the Preferences file. The extensions are stored by ID. |
71 const char kExtensionToolbar[] = "extensions.toolbar"; | 71 const char kExtensionToolbar[] = "extensions.toolbar"; |
72 | 72 |
73 // A preference that tracks order of extensions in an action box | |
msw
2012/07/24 23:41:55
grammar nit: "the order".
yefimt
2012/07/25 21:09:21
Done.
| |
74 // (list of extension ids). | |
75 const char kExtensionActionBox[] = "extensions.action_box_order"; | |
76 | |
77 // A preference that tracks order of extensions in an toolbar when | |
msw
2012/07/24 23:41:55
grammar nits: "the order", "a toolbar", and "is en
yefimt
2012/07/25 21:09:21
Done.
msw
2012/07/25 23:02:03
Almost, please change "an toolbar" to "a toolbar".
yefimt
2012/07/31 00:10:11
Done.
| |
78 // action box enabled (list of extension ids). | |
79 const char kExtensionActionBoxBar[] = | |
80 "extensions.toolbar_order_with_action_box"; | |
81 | |
73 // The key for a serialized Time value indicating the start of the day (from the | 82 // The key for a serialized Time value indicating the start of the day (from the |
74 // server's perspective) an extension last included a "ping" parameter during | 83 // server's perspective) an extension last included a "ping" parameter during |
75 // its update check. | 84 // its update check. |
76 const char kLastPingDay[] = "lastpingday"; | 85 const char kLastPingDay[] = "lastpingday"; |
77 | 86 |
78 // Similar to kLastPingDay, but for "active" instead of "rollcall" pings. | 87 // Similar to kLastPingDay, but for "active" instead of "rollcall" pings. |
79 const char kLastActivePingDay[] = "last_active_pingday"; | 88 const char kLastActivePingDay[] = "last_active_pingday"; |
80 | 89 |
81 // A bit we use to keep track of whether we need to do an "active" ping. | 90 // A bit we use to keep track of whether we need to do an "active" ping. |
82 const char kActiveBit[] = "active_bit"; | 91 const char kActiveBit[] = "active_bit"; |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
693 extension_id, kPrefDisableReason, | 702 extension_id, kPrefDisableReason, |
694 Value::CreateIntegerValue(static_cast<int>(disable_reason))); | 703 Value::CreateIntegerValue(static_cast<int>(disable_reason))); |
695 } | 704 } |
696 | 705 |
697 void ExtensionPrefs::RemoveDisableReason(const std::string& extension_id) { | 706 void ExtensionPrefs::RemoveDisableReason(const std::string& extension_id) { |
698 UpdateExtensionPref(extension_id, kPrefDisableReason, NULL); | 707 UpdateExtensionPref(extension_id, kPrefDisableReason, NULL); |
699 } | 708 } |
700 | 709 |
701 void ExtensionPrefs::UpdateBlacklist( | 710 void ExtensionPrefs::UpdateBlacklist( |
702 const std::set<std::string>& blacklist_set) { | 711 const std::set<std::string>& blacklist_set) { |
703 std::vector<std::string> remove_pref_ids; | 712 ExtensionIdSet remove_pref_ids; |
704 std::set<std::string> used_id_set; | 713 std::set<std::string> used_id_set; |
705 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); | 714 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); |
706 | 715 |
707 if (extensions) { | 716 if (extensions) { |
708 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys(); | 717 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys(); |
709 extension_id != extensions->end_keys(); ++extension_id) { | 718 extension_id != extensions->end_keys(); ++extension_id) { |
710 DictionaryValue* ext; | 719 DictionaryValue* ext; |
711 if (!extensions->GetDictionaryWithoutPathExpansion(*extension_id, &ext)) { | 720 if (!extensions->GetDictionaryWithoutPathExpansion(*extension_id, &ext)) { |
712 NOTREACHED() << "Invalid pref for extension " << *extension_id; | 721 NOTREACHED() << "Invalid pref for extension " << *extension_id; |
713 continue; | 722 continue; |
(...skipping 26 matching lines...) Expand all Loading... | |
740 } | 749 } |
741 | 750 |
742 // Iterate the leftovers to set blacklist in pref | 751 // Iterate the leftovers to set blacklist in pref |
743 std::set<std::string>::const_iterator set_itr = blacklist_set.begin(); | 752 std::set<std::string>::const_iterator set_itr = blacklist_set.begin(); |
744 for (; set_itr != blacklist_set.end(); ++set_itr) { | 753 for (; set_itr != blacklist_set.end(); ++set_itr) { |
745 if (used_id_set.find(*set_itr) == used_id_set.end()) { | 754 if (used_id_set.find(*set_itr) == used_id_set.end()) { |
746 UpdateExtensionPref(*set_itr, kPrefBlacklist, | 755 UpdateExtensionPref(*set_itr, kPrefBlacklist, |
747 Value::CreateBooleanValue(true)); | 756 Value::CreateBooleanValue(true)); |
748 } | 757 } |
749 } | 758 } |
750 for (unsigned int i = 0; i < remove_pref_ids.size(); ++i) { | 759 for (size_t i = 0; i < remove_pref_ids.size(); ++i) { |
751 DeleteExtensionPrefs(remove_pref_ids[i]); | 760 DeleteExtensionPrefs(remove_pref_ids[i]); |
752 } | 761 } |
753 } | 762 } |
754 | 763 |
755 namespace { | 764 namespace { |
756 | 765 |
757 // Serializes |time| as a string value mapped to |key| in |dictionary|. | 766 // Serializes |time| as a string value mapped to |key| in |dictionary|. |
758 void SaveTime(DictionaryValue* dictionary, | 767 void SaveTime(DictionaryValue* dictionary, |
759 const char* key, | 768 const char* key, |
760 const base::Time& time) { | 769 const base::Time& time) { |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1168 bool ExtensionPrefs::IsExternalExtensionUninstalled( | 1177 bool ExtensionPrefs::IsExternalExtensionUninstalled( |
1169 const std::string& id) const { | 1178 const std::string& id) const { |
1170 return DoesExtensionHaveState(id, Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1179 return DoesExtensionHaveState(id, Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
1171 } | 1180 } |
1172 | 1181 |
1173 bool ExtensionPrefs::IsExtensionDisabled( | 1182 bool ExtensionPrefs::IsExtensionDisabled( |
1174 const std::string& id) const { | 1183 const std::string& id) const { |
1175 return DoesExtensionHaveState(id, Extension::DISABLED); | 1184 return DoesExtensionHaveState(id, Extension::DISABLED); |
1176 } | 1185 } |
1177 | 1186 |
1178 std::vector<std::string> ExtensionPrefs::GetToolbarOrder() { | 1187 ExtensionPrefs::ExtensionIdSet ExtensionPrefs::GetToolbarOrder() { |
1179 ExtensionIdSet extension_ids; | 1188 bool action_box_enabled = extensions::switch_utils::IsActionBoxEnabled(); |
1180 const ListValue* toolbar_order = prefs_->GetList(kExtensionToolbar); | 1189 return GetExtensionPrefAsVector( |
1181 if (toolbar_order) { | 1190 action_box_enabled ? kExtensionActionBoxBar : kExtensionToolbar); |
1182 for (size_t i = 0; i < toolbar_order->GetSize(); ++i) { | |
1183 std::string extension_id; | |
1184 if (toolbar_order->GetString(i, &extension_id)) | |
1185 extension_ids.push_back(extension_id); | |
1186 } | |
1187 } | |
1188 return extension_ids; | |
1189 } | 1191 } |
1190 | 1192 |
1191 void ExtensionPrefs::SetToolbarOrder( | 1193 void ExtensionPrefs::SetToolbarOrder(const ExtensionIdSet& extension_ids) { |
1192 const std::vector<std::string>& extension_ids) { | 1194 bool action_box_enabled = extensions::switch_utils::IsActionBoxEnabled(); |
1193 ListPrefUpdate update(prefs_, kExtensionToolbar); | 1195 SetExtensionPrefFromVector( |
1194 ListValue* toolbar_order = update.Get(); | 1196 action_box_enabled ? kExtensionActionBoxBar : kExtensionToolbar, |
1195 toolbar_order->Clear(); | 1197 extension_ids); |
1196 for (std::vector<std::string>::const_iterator iter = extension_ids.begin(); | 1198 } |
1197 iter != extension_ids.end(); ++iter) { | 1199 |
1198 toolbar_order->Append(new StringValue(*iter)); | 1200 ExtensionPrefs::ExtensionIdSet ExtensionPrefs::GetActionBoxOrder() { |
1199 } | 1201 return GetExtensionPrefAsVector(kExtensionActionBox); |
1202 } | |
1203 | |
1204 void ExtensionPrefs::SetActionBoxOrder(const ExtensionIdSet& extension_ids) { | |
1205 SetExtensionPrefFromVector(kExtensionActionBox, extension_ids); | |
1200 } | 1206 } |
1201 | 1207 |
1202 void ExtensionPrefs::OnExtensionInstalled( | 1208 void ExtensionPrefs::OnExtensionInstalled( |
1203 const Extension* extension, | 1209 const Extension* extension, |
1204 Extension::State initial_state, | 1210 Extension::State initial_state, |
1205 bool from_webstore, | 1211 bool from_webstore, |
1206 const StringOrdinal& page_ordinal) { | 1212 const StringOrdinal& page_ordinal) { |
1207 const std::string& id = extension->id(); | 1213 const std::string& id = extension->id(); |
1208 CHECK(Extension::IdIsValid(id)); | 1214 CHECK(Extension::IdIsValid(id)); |
1209 ScopedExtensionPrefUpdate update(prefs_, id); | 1215 ScopedExtensionPrefUpdate update(prefs_, id); |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1906 result.AddPattern(entry); | 1912 result.AddPattern(entry); |
1907 } | 1913 } |
1908 | 1914 |
1909 return result; | 1915 return result; |
1910 } | 1916 } |
1911 | 1917 |
1912 // static | 1918 // static |
1913 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { | 1919 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { |
1914 prefs->RegisterDictionaryPref(kExtensionsPref, PrefService::UNSYNCABLE_PREF); | 1920 prefs->RegisterDictionaryPref(kExtensionsPref, PrefService::UNSYNCABLE_PREF); |
1915 prefs->RegisterListPref(kExtensionToolbar, PrefService::UNSYNCABLE_PREF); | 1921 prefs->RegisterListPref(kExtensionToolbar, PrefService::UNSYNCABLE_PREF); |
1922 prefs->RegisterListPref(kExtensionActionBox, PrefService::UNSYNCABLE_PREF); | |
1923 prefs->RegisterListPref(kExtensionActionBoxBar, PrefService::UNSYNCABLE_PREF); | |
1916 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, | 1924 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, |
1917 -1, // default value | 1925 -1, // default value |
1918 PrefService::UNSYNCABLE_PREF); | 1926 PrefService::UNSYNCABLE_PREF); |
1919 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate, | 1927 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate, |
1920 PrefService::UNSYNCABLE_PREF); | 1928 PrefService::UNSYNCABLE_PREF); |
1921 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, | 1929 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, |
1922 PrefService::UNSYNCABLE_PREF); | 1930 PrefService::UNSYNCABLE_PREF); |
1923 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, | 1931 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, |
1924 PrefService::UNSYNCABLE_PREF); | 1932 PrefService::UNSYNCABLE_PREF); |
1925 prefs->RegisterListPref(prefs::kExtensionInstallForceList, | 1933 prefs->RegisterListPref(prefs::kExtensionInstallForceList, |
1926 PrefService::UNSYNCABLE_PREF); | 1934 PrefService::UNSYNCABLE_PREF); |
1927 prefs->RegisterStringPref(kWebStoreLogin, | 1935 prefs->RegisterStringPref(kWebStoreLogin, |
1928 std::string(), // default value | 1936 std::string(), // default value |
1929 PrefService::UNSYNCABLE_PREF); | 1937 PrefService::UNSYNCABLE_PREF); |
1930 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, | 1938 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, |
1931 "0", // default value | 1939 "0", // default value |
1932 PrefService::UNSYNCABLE_PREF); | 1940 PrefService::UNSYNCABLE_PREF); |
1933 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, | 1941 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, |
1934 0, // default value | 1942 0, // default value |
1935 PrefService::UNSYNCABLE_PREF); | 1943 PrefService::UNSYNCABLE_PREF); |
1936 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1944 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
1937 0, // default value | 1945 0, // default value |
1938 PrefService::UNSYNCABLE_PREF); | 1946 PrefService::UNSYNCABLE_PREF); |
1939 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, | 1947 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, |
1940 PrefService::UNSYNCABLE_PREF); | 1948 PrefService::UNSYNCABLE_PREF); |
1941 } | 1949 } |
1942 | 1950 |
1951 ExtensionPrefs::ExtensionIdSet ExtensionPrefs::GetExtensionPrefAsVector( | |
1952 const char* pref) { | |
1953 ExtensionIdSet extension_ids; | |
1954 const ListValue* list_of_values = prefs_->GetList(pref); | |
1955 if (!list_of_values) | |
1956 return extension_ids; | |
1957 | |
1958 for (size_t i = 0; i < list_of_values->GetSize(); ++i) { | |
1959 std::string extension_id; | |
msw
2012/07/24 23:41:55
nit: move string decl out of loop.
yefimt
2012/07/25 21:09:21
Done.
| |
1960 if (list_of_values->GetString(i, &extension_id)) | |
1961 extension_ids.push_back(extension_id); | |
1962 } | |
1963 return extension_ids; | |
1964 } | |
1965 | |
1966 void ExtensionPrefs::SetExtensionPrefFromVector(const char* pref, | |
1967 const ExtensionIdSet& strings) { | |
1968 ListPrefUpdate update(prefs_, pref); | |
1969 ListValue* list_of_values = update.Get(); | |
1970 list_of_values->Clear(); | |
1971 for (ExtensionIdSet::const_iterator iter = strings.begin(); | |
1972 iter != strings.end(); ++iter) | |
1973 list_of_values->Append(new StringValue(*iter)); | |
1974 } | |
1975 | |
1943 } // namespace extensions | 1976 } // namespace extensions |
OLD | NEW |