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 | |
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 | |
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 657 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 (unsigned int i = 0; i < remove_pref_ids.size(); ++i) { |
Peter Kasting
2012/07/21 01:55:13
Tiny nit: While you're touching this file can you
yefimt
2012/07/23 23:47:52
Done.
| |
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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 std::vector<std::string> 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( |
1192 const std::vector<std::string>& extension_ids) { | 1194 const std::vector<std::string>& extension_ids) { |
1193 ListPrefUpdate update(prefs_, kExtensionToolbar); | 1195 bool action_box_enabled = extensions::switch_utils::IsActionBoxEnabled(); |
1194 ListValue* toolbar_order = update.Get(); | 1196 SetExtensionPrefFromVector( |
1195 toolbar_order->Clear(); | 1197 action_box_enabled ? kExtensionActionBoxBar : kExtensionToolbar, |
1196 for (std::vector<std::string>::const_iterator iter = extension_ids.begin(); | 1198 extension_ids); |
1197 iter != extension_ids.end(); ++iter) { | 1199 } |
1198 toolbar_order->Append(new StringValue(*iter)); | 1200 |
1199 } | 1201 std::vector<std::string> ExtensionPrefs::GetActionBoxOrder() { |
1202 return GetExtensionPrefAsVector(kExtensionActionBox); | |
1203 } | |
1204 | |
1205 void ExtensionPrefs::SetActionBoxOrder( | |
1206 const std::vector<std::string>& extension_ids) { | |
1207 SetExtensionPrefFromVector(kExtensionActionBox, extension_ids); | |
1200 } | 1208 } |
1201 | 1209 |
1202 void ExtensionPrefs::OnExtensionInstalled( | 1210 void ExtensionPrefs::OnExtensionInstalled( |
1203 const Extension* extension, | 1211 const Extension* extension, |
1204 Extension::State initial_state, | 1212 Extension::State initial_state, |
1205 bool from_webstore, | 1213 bool from_webstore, |
1206 const StringOrdinal& page_ordinal) { | 1214 const StringOrdinal& page_ordinal) { |
1207 const std::string& id = extension->id(); | 1215 const std::string& id = extension->id(); |
1208 CHECK(Extension::IdIsValid(id)); | 1216 CHECK(Extension::IdIsValid(id)); |
1209 ScopedExtensionPrefUpdate update(prefs_, id); | 1217 ScopedExtensionPrefUpdate update(prefs_, id); |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1906 result.AddPattern(entry); | 1914 result.AddPattern(entry); |
1907 } | 1915 } |
1908 | 1916 |
1909 return result; | 1917 return result; |
1910 } | 1918 } |
1911 | 1919 |
1912 // static | 1920 // static |
1913 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { | 1921 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { |
1914 prefs->RegisterDictionaryPref(kExtensionsPref, PrefService::UNSYNCABLE_PREF); | 1922 prefs->RegisterDictionaryPref(kExtensionsPref, PrefService::UNSYNCABLE_PREF); |
1915 prefs->RegisterListPref(kExtensionToolbar, PrefService::UNSYNCABLE_PREF); | 1923 prefs->RegisterListPref(kExtensionToolbar, PrefService::UNSYNCABLE_PREF); |
1924 prefs->RegisterListPref(kExtensionActionBox, PrefService::UNSYNCABLE_PREF); | |
1925 prefs->RegisterListPref(kExtensionActionBoxBar, PrefService::UNSYNCABLE_PREF); | |
1916 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, | 1926 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, |
1917 -1, // default value | 1927 -1, // default value |
1918 PrefService::UNSYNCABLE_PREF); | 1928 PrefService::UNSYNCABLE_PREF); |
1919 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate, | 1929 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate, |
1920 PrefService::UNSYNCABLE_PREF); | 1930 PrefService::UNSYNCABLE_PREF); |
1921 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, | 1931 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, |
1922 PrefService::UNSYNCABLE_PREF); | 1932 PrefService::UNSYNCABLE_PREF); |
1923 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, | 1933 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, |
1924 PrefService::UNSYNCABLE_PREF); | 1934 PrefService::UNSYNCABLE_PREF); |
1925 prefs->RegisterListPref(prefs::kExtensionInstallForceList, | 1935 prefs->RegisterListPref(prefs::kExtensionInstallForceList, |
1926 PrefService::UNSYNCABLE_PREF); | 1936 PrefService::UNSYNCABLE_PREF); |
1927 prefs->RegisterStringPref(kWebStoreLogin, | 1937 prefs->RegisterStringPref(kWebStoreLogin, |
1928 std::string(), // default value | 1938 std::string(), // default value |
1929 PrefService::UNSYNCABLE_PREF); | 1939 PrefService::UNSYNCABLE_PREF); |
1930 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, | 1940 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, |
1931 "0", // default value | 1941 "0", // default value |
1932 PrefService::UNSYNCABLE_PREF); | 1942 PrefService::UNSYNCABLE_PREF); |
1933 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, | 1943 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, |
1934 0, // default value | 1944 0, // default value |
1935 PrefService::UNSYNCABLE_PREF); | 1945 PrefService::UNSYNCABLE_PREF); |
1936 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1946 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
1937 0, // default value | 1947 0, // default value |
1938 PrefService::UNSYNCABLE_PREF); | 1948 PrefService::UNSYNCABLE_PREF); |
1939 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, | 1949 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, |
1940 PrefService::UNSYNCABLE_PREF); | 1950 PrefService::UNSYNCABLE_PREF); |
1941 } | 1951 } |
1942 | 1952 |
1953 std::vector<std::string> ExtensionPrefs::GetExtensionPrefAsVector( | |
1954 const char* pref) { | |
1955 ExtensionIdSet extension_ids; | |
1956 const ListValue* list_of_values = prefs_->GetList(pref); | |
1957 if (!list_of_values) | |
1958 return extension_ids; | |
1959 | |
1960 for (size_t i = 0; i < list_of_values->GetSize(); ++i) { | |
1961 std::string extension_id; | |
1962 if (list_of_values->GetString(i, &extension_id)) | |
1963 extension_ids.push_back(extension_id); | |
1964 } | |
1965 return extension_ids; | |
1966 } | |
1967 | |
1968 void ExtensionPrefs::SetExtensionPrefFromVector(const char* pref, | |
1969 const std::vector<std::string>& strings) { | |
1970 ListPrefUpdate update(prefs_, pref); | |
1971 ListValue* list_of_values = update.Get(); | |
1972 list_of_values->Clear(); | |
1973 for (std::vector<std::string>::const_iterator iter = strings.begin(); | |
1974 iter != strings.end(); ++iter) | |
1975 list_of_values->Append(new StringValue(*iter)); | |
1976 } | |
1977 | |
1943 } // namespace extensions | 1978 } // namespace extensions |
OLD | NEW |