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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 // Indicates whether to show an install warning when the user enables. | 70 // Indicates whether to show an install warning when the user enables. |
71 const char kExtensionDidEscalatePermissions[] = "install_warning_on_enable"; | 71 const char kExtensionDidEscalatePermissions[] = "install_warning_on_enable"; |
72 | 72 |
73 // Indicates whether the extension was updated while it was disabled. | 73 // Indicates whether the extension was updated while it was disabled. |
74 const char kPrefDisableReason[] = "disable_reason"; | 74 const char kPrefDisableReason[] = "disable_reason"; |
75 | 75 |
76 // A preference that tracks browser action toolbar configuration. This is a list | 76 // A preference that tracks browser action toolbar configuration. This is a list |
77 // object stored in the Preferences file. The extensions are stored by ID. | 77 // object stored in the Preferences file. The extensions are stored by ID. |
78 const char kExtensionToolbar[] = "extensions.toolbar"; | 78 const char kExtensionToolbar[] = "extensions.toolbar"; |
79 | 79 |
80 const char kExtensionActionBox[] = "extensions.action_box_order"; | |
Aaron Boodman
2012/07/02 22:41:34
Comment these.
yefimt
2012/07/11 22:34:34
Done.
| |
81 | |
82 const char kExtensionActionBoxBar[] = "extensions.toolbar_order"; | |
Aaron Boodman
2012/07/02 22:41:34
I still think this should be toolbar_order_with_ac
yefimt
2012/07/11 22:34:34
Done.
| |
83 | |
80 // The key for a serialized Time value indicating the start of the day (from the | 84 // The key for a serialized Time value indicating the start of the day (from the |
81 // server's perspective) an extension last included a "ping" parameter during | 85 // server's perspective) an extension last included a "ping" parameter during |
82 // its update check. | 86 // its update check. |
83 const char kLastPingDay[] = "lastpingday"; | 87 const char kLastPingDay[] = "lastpingday"; |
84 | 88 |
85 // Similar to kLastPingDay, but for "active" instead of "rollcall" pings. | 89 // Similar to kLastPingDay, but for "active" instead of "rollcall" pings. |
86 const char kLastActivePingDay[] = "last_active_pingday"; | 90 const char kLastActivePingDay[] = "last_active_pingday"; |
87 | 91 |
88 // A bit we use to keep track of whether we need to do an "active" ping. | 92 // A bit we use to keep track of whether we need to do an "active" ping. |
89 const char kActiveBit[] = "active_bit"; | 93 const char kActiveBit[] = "active_bit"; |
(...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1145 const std::string& id) const { | 1149 const std::string& id) const { |
1146 return DoesExtensionHaveState(id, Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1150 return DoesExtensionHaveState(id, Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
1147 } | 1151 } |
1148 | 1152 |
1149 bool ExtensionPrefs::IsExtensionDisabled( | 1153 bool ExtensionPrefs::IsExtensionDisabled( |
1150 const std::string& id) const { | 1154 const std::string& id) const { |
1151 return DoesExtensionHaveState(id, Extension::DISABLED); | 1155 return DoesExtensionHaveState(id, Extension::DISABLED); |
1152 } | 1156 } |
1153 | 1157 |
1154 std::vector<std::string> ExtensionPrefs::GetToolbarOrder() { | 1158 std::vector<std::string> ExtensionPrefs::GetToolbarOrder() { |
1155 ExtensionIdSet extension_ids; | 1159 bool action_box_enabled = extensions::switch_utils::IsActionBoxEnabled(); |
1156 const ListValue* toolbar_order = prefs_->GetList(kExtensionToolbar); | 1160 return GetExtensionsOrder(action_box_enabled ? kExtensionActionBoxBar : |
1157 if (toolbar_order) { | 1161 kExtensionToolbar); |
1158 for (size_t i = 0; i < toolbar_order->GetSize(); ++i) { | |
1159 std::string extension_id; | |
1160 if (toolbar_order->GetString(i, &extension_id)) | |
1161 extension_ids.push_back(extension_id); | |
1162 } | |
1163 } | |
1164 return extension_ids; | |
1165 } | 1162 } |
1166 | 1163 |
1167 void ExtensionPrefs::SetToolbarOrder( | 1164 void ExtensionPrefs::SetToolbarOrder( |
1168 const std::vector<std::string>& extension_ids) { | 1165 const std::vector<std::string>& extension_ids) { |
1169 ListPrefUpdate update(prefs_, kExtensionToolbar); | 1166 bool action_box_enabled = extensions::switch_utils::IsActionBoxEnabled(); |
1170 ListValue* toolbar_order = update.Get(); | 1167 SetExtensionsOrder(action_box_enabled ? kExtensionActionBoxBar : |
1171 toolbar_order->Clear(); | 1168 kExtensionToolbar, |
1172 for (std::vector<std::string>::const_iterator iter = extension_ids.begin(); | 1169 extension_ids); |
1173 iter != extension_ids.end(); ++iter) { | 1170 } |
1174 toolbar_order->Append(new StringValue(*iter)); | 1171 |
1175 } | 1172 std::vector<std::string> ExtensionPrefs::GetActionBoxOrder() { |
1173 return GetExtensionsOrder(kExtensionActionBox); | |
1174 } | |
1175 | |
1176 void ExtensionPrefs::SetActionBoxOrder( | |
1177 const std::vector<std::string>& extension_ids) { | |
1178 SetExtensionsOrder(kExtensionActionBox, extension_ids); | |
1176 } | 1179 } |
1177 | 1180 |
1178 void ExtensionPrefs::OnExtensionInstalled( | 1181 void ExtensionPrefs::OnExtensionInstalled( |
1179 const Extension* extension, | 1182 const Extension* extension, |
1180 Extension::State initial_state, | 1183 Extension::State initial_state, |
1181 bool from_webstore, | 1184 bool from_webstore, |
1182 const StringOrdinal& page_ordinal) { | 1185 const StringOrdinal& page_ordinal) { |
1183 const std::string& id = extension->id(); | 1186 const std::string& id = extension->id(); |
1184 CHECK(Extension::IdIsValid(id)); | 1187 CHECK(Extension::IdIsValid(id)); |
1185 ScopedExtensionPrefUpdate update(prefs_, id); | 1188 ScopedExtensionPrefUpdate update(prefs_, id); |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1882 result.AddPattern(entry); | 1885 result.AddPattern(entry); |
1883 } | 1886 } |
1884 | 1887 |
1885 return result; | 1888 return result; |
1886 } | 1889 } |
1887 | 1890 |
1888 // static | 1891 // static |
1889 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { | 1892 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { |
1890 prefs->RegisterDictionaryPref(kExtensionsPref, PrefService::UNSYNCABLE_PREF); | 1893 prefs->RegisterDictionaryPref(kExtensionsPref, PrefService::UNSYNCABLE_PREF); |
1891 prefs->RegisterListPref(kExtensionToolbar, PrefService::UNSYNCABLE_PREF); | 1894 prefs->RegisterListPref(kExtensionToolbar, PrefService::UNSYNCABLE_PREF); |
1895 prefs->RegisterListPref(kExtensionActionBox, PrefService::UNSYNCABLE_PREF); | |
1896 prefs->RegisterListPref(kExtensionActionBoxBar, PrefService::UNSYNCABLE_PREF); | |
1892 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, | 1897 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, |
1893 -1, // default value | 1898 -1, // default value |
1894 PrefService::UNSYNCABLE_PREF); | 1899 PrefService::UNSYNCABLE_PREF); |
1895 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate, | 1900 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate, |
1896 PrefService::UNSYNCABLE_PREF); | 1901 PrefService::UNSYNCABLE_PREF); |
1897 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, | 1902 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, |
1898 PrefService::UNSYNCABLE_PREF); | 1903 PrefService::UNSYNCABLE_PREF); |
1899 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, | 1904 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, |
1900 PrefService::UNSYNCABLE_PREF); | 1905 PrefService::UNSYNCABLE_PREF); |
1901 prefs->RegisterListPref(prefs::kExtensionInstallForceList, | 1906 prefs->RegisterListPref(prefs::kExtensionInstallForceList, |
1902 PrefService::UNSYNCABLE_PREF); | 1907 PrefService::UNSYNCABLE_PREF); |
1903 prefs->RegisterStringPref(kWebStoreLogin, | 1908 prefs->RegisterStringPref(kWebStoreLogin, |
1904 std::string(), // default value | 1909 std::string(), // default value |
1905 PrefService::UNSYNCABLE_PREF); | 1910 PrefService::UNSYNCABLE_PREF); |
1906 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, | 1911 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, |
1907 "0", // default value | 1912 "0", // default value |
1908 PrefService::UNSYNCABLE_PREF); | 1913 PrefService::UNSYNCABLE_PREF); |
1909 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, | 1914 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, |
1910 0, // default value | 1915 0, // default value |
1911 PrefService::UNSYNCABLE_PREF); | 1916 PrefService::UNSYNCABLE_PREF); |
1912 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1917 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
1913 0, // default value | 1918 0, // default value |
1914 PrefService::UNSYNCABLE_PREF); | 1919 PrefService::UNSYNCABLE_PREF); |
1915 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, | 1920 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, |
1916 PrefService::UNSYNCABLE_PREF); | 1921 PrefService::UNSYNCABLE_PREF); |
1917 } | 1922 } |
1923 | |
1924 std::vector<std::string> ExtensionPrefs::GetExtensionsOrder(const char* pref) { | |
1925 ExtensionIdSet extension_ids; | |
1926 const ListValue* list_of_values = prefs_->GetList(pref); | |
1927 if (list_of_values) { | |
Aaron Boodman
2012/07/02 22:41:34
Reverse check and return early.
yefimt
2012/07/11 22:34:34
Done.
| |
1928 for (size_t i = 0; i < list_of_values->GetSize(); ++i) { | |
1929 std::string extension_id; | |
1930 if (list_of_values->GetString(i, &extension_id)) | |
1931 extension_ids.push_back(extension_id); | |
1932 } | |
1933 } | |
1934 return extension_ids; | |
1935 } | |
1936 | |
1937 void ExtensionPrefs::SetExtensionsOrder(const char* pref, | |
1938 const std::vector<std::string>& strings) { | |
1939 ListPrefUpdate update(prefs_, pref); | |
1940 ListValue* list_of_values = update.Get(); | |
1941 list_of_values->Clear(); | |
1942 for (std::vector<std::string>::const_iterator iter = strings.begin(); | |
1943 iter != strings.end(); ++iter) { | |
1944 list_of_values->Append(new StringValue(*iter)); | |
1945 } | |
1946 } | |
OLD | NEW |