Chromium Code Reviews| 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/api/alarms/alarm_manager.h" | 10 #include "chrome/browser/extensions/api/alarms/alarm_manager.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 // Indicates whether to show an install warning when the user enables. | 62 // Indicates whether to show an install warning when the user enables. |
| 63 const char kExtensionDidEscalatePermissions[] = "install_warning_on_enable"; | 63 const char kExtensionDidEscalatePermissions[] = "install_warning_on_enable"; |
| 64 | 64 |
| 65 // Indicates whether the extension was updated while it was disabled. | 65 // Indicates whether the extension was updated while it was disabled. |
| 66 const char kPrefDisableReason[] = "disable_reason"; | 66 const char kPrefDisableReason[] = "disable_reason"; |
| 67 | 67 |
| 68 // A preference that tracks browser action toolbar configuration. This is a list | 68 // A preference that tracks browser action toolbar configuration. This is a list |
| 69 // object stored in the Preferences file. The extensions are stored by ID. | 69 // object stored in the Preferences file. The extensions are stored by ID. |
| 70 const char kExtensionToolbar[] = "extensions.toolbar"; | 70 const char kExtensionToolbar[] = "extensions.toolbar"; |
| 71 | 71 |
| 72 const char kExtensionActionbox[] = "extensions.actionbox"; | |
|
Aaron Boodman
2012/06/12 05:53:44
I would recommend: extensions.action_box_order
yefimt
2012/06/13 01:24:21
Done.
| |
| 73 | |
| 74 const char kExtensionActionboxBar[] = "extensions.actionbox_bar"; | |
|
Aaron Boodman
2012/06/12 05:53:44
And: toolbar_order_for_action_box_mode
yefimt
2012/06/13 01:24:21
Changed to toolbar_order.
Assuming that old prefer
| |
| 75 | |
| 72 // The key for a serialized Time value indicating the start of the day (from the | 76 // The key for a serialized Time value indicating the start of the day (from the |
| 73 // server's perspective) an extension last included a "ping" parameter during | 77 // server's perspective) an extension last included a "ping" parameter during |
| 74 // its update check. | 78 // its update check. |
| 75 const char kLastPingDay[] = "lastpingday"; | 79 const char kLastPingDay[] = "lastpingday"; |
| 76 | 80 |
| 77 // Similar to kLastPingDay, but for "active" instead of "rollcall" pings. | 81 // Similar to kLastPingDay, but for "active" instead of "rollcall" pings. |
| 78 const char kLastActivePingDay[] = "last_active_pingday"; | 82 const char kLastActivePingDay[] = "last_active_pingday"; |
| 79 | 83 |
| 80 // A bit we use to keep track of whether we need to do an "active" ping. | 84 // A bit we use to keep track of whether we need to do an "active" ping. |
| 81 const char kActiveBit[] = "active_bit"; | 85 const char kActiveBit[] = "active_bit"; |
| (...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1174 const std::string& id) const { | 1178 const std::string& id) const { |
| 1175 return DoesExtensionHaveState(id, Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1179 return DoesExtensionHaveState(id, Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| 1176 } | 1180 } |
| 1177 | 1181 |
| 1178 bool ExtensionPrefs::IsExtensionDisabled( | 1182 bool ExtensionPrefs::IsExtensionDisabled( |
| 1179 const std::string& id) const { | 1183 const std::string& id) const { |
| 1180 return DoesExtensionHaveState(id, Extension::DISABLED); | 1184 return DoesExtensionHaveState(id, Extension::DISABLED); |
| 1181 } | 1185 } |
| 1182 | 1186 |
| 1183 std::vector<std::string> ExtensionPrefs::GetToolbarOrder() { | 1187 std::vector<std::string> ExtensionPrefs::GetToolbarOrder() { |
| 1184 ExtensionIdSet extension_ids; | 1188 bool action_box_enabled = extensions::switch_utils::IsActionBoxEnabled(); |
| 1185 const ListValue* toolbar_order = prefs_->GetList(kExtensionToolbar); | 1189 return GetExtensionsOrder(action_box_enabled ? kExtensionActionboxBar : |
| 1186 if (toolbar_order) { | 1190 kExtensionToolbar); |
| 1187 for (size_t i = 0; i < toolbar_order->GetSize(); ++i) { | |
| 1188 std::string extension_id; | |
| 1189 if (toolbar_order->GetString(i, &extension_id)) | |
| 1190 extension_ids.push_back(extension_id); | |
| 1191 } | |
| 1192 } | |
| 1193 return extension_ids; | |
| 1194 } | 1191 } |
| 1195 | 1192 |
| 1196 void ExtensionPrefs::SetToolbarOrder( | 1193 void ExtensionPrefs::SetToolbarOrder( |
| 1197 const std::vector<std::string>& extension_ids) { | 1194 const std::vector<std::string>& extension_ids) { |
| 1198 ListPrefUpdate update(prefs_, kExtensionToolbar); | 1195 bool action_box_enabled = extensions::switch_utils::IsActionBoxEnabled(); |
| 1199 ListValue* toolbar_order = update.Get(); | 1196 SetExtensionsOrder(action_box_enabled ? kExtensionActionboxBar : |
| 1200 toolbar_order->Clear(); | 1197 kExtensionToolbar, |
| 1201 for (std::vector<std::string>::const_iterator iter = extension_ids.begin(); | 1198 extension_ids); |
| 1202 iter != extension_ids.end(); ++iter) { | 1199 } |
| 1203 toolbar_order->Append(new StringValue(*iter)); | 1200 |
| 1204 } | 1201 std::vector<std::string> ExtensionPrefs::GetActionboxOrder() { |
| 1202 return GetExtensionsOrder(kExtensionActionbox); | |
| 1203 } | |
| 1204 | |
| 1205 void ExtensionPrefs::SetActionboxOrder( | |
| 1206 const std::vector<std::string>& extension_ids) { | |
| 1207 SetExtensionsOrder(kExtensionActionbox, extension_ids); | |
| 1205 } | 1208 } |
| 1206 | 1209 |
| 1207 void ExtensionPrefs::OnExtensionInstalled( | 1210 void ExtensionPrefs::OnExtensionInstalled( |
| 1208 const Extension* extension, | 1211 const Extension* extension, |
| 1209 Extension::State initial_state, | 1212 Extension::State initial_state, |
| 1210 bool from_webstore, | 1213 bool from_webstore, |
| 1211 const StringOrdinal& page_ordinal) { | 1214 const StringOrdinal& page_ordinal) { |
| 1212 const std::string& id = extension->id(); | 1215 const std::string& id = extension->id(); |
| 1213 CHECK(Extension::IdIsValid(id)); | 1216 CHECK(Extension::IdIsValid(id)); |
| 1214 ScopedExtensionPrefUpdate update(prefs_, id); | 1217 ScopedExtensionPrefUpdate update(prefs_, id); |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1901 content_settings_store_->ClearContentSettingsForExtension( | 1904 content_settings_store_->ClearContentSettingsForExtension( |
| 1902 *ext_id, | 1905 *ext_id, |
| 1903 kExtensionPrefsScopeIncognitoSessionOnly); | 1906 kExtensionPrefsScopeIncognitoSessionOnly); |
| 1904 } | 1907 } |
| 1905 } | 1908 } |
| 1906 | 1909 |
| 1907 // static | 1910 // static |
| 1908 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { | 1911 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { |
| 1909 prefs->RegisterDictionaryPref(kExtensionsPref, PrefService::UNSYNCABLE_PREF); | 1912 prefs->RegisterDictionaryPref(kExtensionsPref, PrefService::UNSYNCABLE_PREF); |
| 1910 prefs->RegisterListPref(kExtensionToolbar, PrefService::UNSYNCABLE_PREF); | 1913 prefs->RegisterListPref(kExtensionToolbar, PrefService::UNSYNCABLE_PREF); |
| 1914 prefs->RegisterListPref(kExtensionActionbox, PrefService::UNSYNCABLE_PREF); | |
| 1915 prefs->RegisterListPref(kExtensionActionboxBar, PrefService::UNSYNCABLE_PREF); | |
| 1911 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, | 1916 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, |
| 1912 -1, // default value | 1917 -1, // default value |
| 1913 PrefService::UNSYNCABLE_PREF); | 1918 PrefService::UNSYNCABLE_PREF); |
| 1914 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate, | 1919 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate, |
| 1915 PrefService::UNSYNCABLE_PREF); | 1920 PrefService::UNSYNCABLE_PREF); |
| 1916 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, | 1921 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, |
| 1917 PrefService::UNSYNCABLE_PREF); | 1922 PrefService::UNSYNCABLE_PREF); |
| 1918 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, | 1923 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, |
| 1919 PrefService::UNSYNCABLE_PREF); | 1924 PrefService::UNSYNCABLE_PREF); |
| 1920 prefs->RegisterListPref(prefs::kExtensionInstallForceList, | 1925 prefs->RegisterListPref(prefs::kExtensionInstallForceList, |
| 1921 PrefService::UNSYNCABLE_PREF); | 1926 PrefService::UNSYNCABLE_PREF); |
| 1922 prefs->RegisterStringPref(kWebStoreLogin, | 1927 prefs->RegisterStringPref(kWebStoreLogin, |
| 1923 std::string(), // default value | 1928 std::string(), // default value |
| 1924 PrefService::UNSYNCABLE_PREF); | 1929 PrefService::UNSYNCABLE_PREF); |
| 1925 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, | 1930 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, |
| 1926 "0", // default value | 1931 "0", // default value |
| 1927 PrefService::UNSYNCABLE_PREF); | 1932 PrefService::UNSYNCABLE_PREF); |
| 1928 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, | 1933 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, |
| 1929 0, // default value | 1934 0, // default value |
| 1930 PrefService::UNSYNCABLE_PREF); | 1935 PrefService::UNSYNCABLE_PREF); |
| 1931 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1936 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
| 1932 0, // default value | 1937 0, // default value |
| 1933 PrefService::UNSYNCABLE_PREF); | 1938 PrefService::UNSYNCABLE_PREF); |
| 1934 } | 1939 } |
| 1940 | |
| 1941 std::vector<std::string> ExtensionPrefs::GetExtensionsOrder(const char* pref) { | |
| 1942 ExtensionIdSet extension_ids; | |
| 1943 const ListValue* toolbar_order = prefs_->GetList(pref); | |
| 1944 if (toolbar_order) { | |
| 1945 for (size_t i = 0; i < toolbar_order->GetSize(); ++i) { | |
| 1946 std::string extension_id; | |
| 1947 if (toolbar_order->GetString(i, &extension_id)) | |
| 1948 extension_ids.push_back(extension_id); | |
| 1949 } | |
| 1950 } | |
| 1951 return extension_ids; | |
| 1952 } | |
| 1953 | |
| 1954 void ExtensionPrefs::SetExtensionsOrder(const char* pref, | |
| 1955 const std::vector<std::string>& extension_ids) { | |
| 1956 ListPrefUpdate update(prefs_, pref); | |
| 1957 ListValue* toolbar_order = update.Get(); | |
| 1958 toolbar_order->Clear(); | |
| 1959 for (std::vector<std::string>::const_iterator iter = extension_ids.begin(); | |
| 1960 iter != extension_ids.end(); ++iter) { | |
| 1961 toolbar_order->Append(new StringValue(*iter)); | |
| 1962 } | |
| 1963 } | |
| OLD | NEW |