Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: chrome/browser/extensions/extension_prefs.cc

Issue 10533086: Action box menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Action box menu Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 the 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 the order of extensions in a toolbar when
78 // action box is 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
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
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
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 SetExtensionPrefFromVector(extensions::switch_utils::IsActionBoxEnabled() ?
1193 ListPrefUpdate update(prefs_, kExtensionToolbar); 1195 kExtensionActionBoxBar : kExtensionToolbar, extension_ids);
1194 ListValue* toolbar_order = update.Get(); 1196 }
1195 toolbar_order->Clear(); 1197
1196 for (std::vector<std::string>::const_iterator iter = extension_ids.begin(); 1198 ExtensionPrefs::ExtensionIdSet ExtensionPrefs::GetActionBoxOrder() {
1197 iter != extension_ids.end(); ++iter) { 1199 return GetExtensionPrefAsVector(kExtensionActionBox);
1198 toolbar_order->Append(new StringValue(*iter)); 1200 }
1199 } 1201
1202 void ExtensionPrefs::SetActionBoxOrder(const ExtensionIdSet& extension_ids) {
1203 SetExtensionPrefFromVector(kExtensionActionBox, extension_ids);
1200 } 1204 }
1201 1205
1202 void ExtensionPrefs::OnExtensionInstalled( 1206 void ExtensionPrefs::OnExtensionInstalled(
1203 const Extension* extension, 1207 const Extension* extension,
1204 Extension::State initial_state, 1208 Extension::State initial_state,
1205 bool from_webstore, 1209 bool from_webstore,
1206 const StringOrdinal& page_ordinal) { 1210 const StringOrdinal& page_ordinal) {
1207 const std::string& id = extension->id(); 1211 const std::string& id = extension->id();
1208 CHECK(Extension::IdIsValid(id)); 1212 CHECK(Extension::IdIsValid(id));
1209 ScopedExtensionPrefUpdate update(prefs_, id); 1213 ScopedExtensionPrefUpdate update(prefs_, id);
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 result.AddPattern(entry); 1910 result.AddPattern(entry);
1907 } 1911 }
1908 1912
1909 return result; 1913 return result;
1910 } 1914 }
1911 1915
1912 // static 1916 // static
1913 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { 1917 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) {
1914 prefs->RegisterDictionaryPref(kExtensionsPref, PrefService::UNSYNCABLE_PREF); 1918 prefs->RegisterDictionaryPref(kExtensionsPref, PrefService::UNSYNCABLE_PREF);
1915 prefs->RegisterListPref(kExtensionToolbar, PrefService::UNSYNCABLE_PREF); 1919 prefs->RegisterListPref(kExtensionToolbar, PrefService::UNSYNCABLE_PREF);
1920 prefs->RegisterListPref(kExtensionActionBox, PrefService::UNSYNCABLE_PREF);
1921 prefs->RegisterListPref(kExtensionActionBoxBar, PrefService::UNSYNCABLE_PREF);
1916 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, 1922 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize,
1917 -1, // default value 1923 -1, // default value
1918 PrefService::UNSYNCABLE_PREF); 1924 PrefService::UNSYNCABLE_PREF);
1919 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate, 1925 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate,
1920 PrefService::UNSYNCABLE_PREF); 1926 PrefService::UNSYNCABLE_PREF);
1921 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, 1927 prefs->RegisterListPref(prefs::kExtensionInstallAllowList,
1922 PrefService::UNSYNCABLE_PREF); 1928 PrefService::UNSYNCABLE_PREF);
1923 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, 1929 prefs->RegisterListPref(prefs::kExtensionInstallDenyList,
1924 PrefService::UNSYNCABLE_PREF); 1930 PrefService::UNSYNCABLE_PREF);
1925 prefs->RegisterListPref(prefs::kExtensionInstallForceList, 1931 prefs->RegisterListPref(prefs::kExtensionInstallForceList,
1926 PrefService::UNSYNCABLE_PREF); 1932 PrefService::UNSYNCABLE_PREF);
1927 prefs->RegisterStringPref(kWebStoreLogin, 1933 prefs->RegisterStringPref(kWebStoreLogin,
1928 std::string(), // default value 1934 std::string(), // default value
1929 PrefService::UNSYNCABLE_PREF); 1935 PrefService::UNSYNCABLE_PREF);
1930 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, 1936 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion,
1931 "0", // default value 1937 "0", // default value
1932 PrefService::UNSYNCABLE_PREF); 1938 PrefService::UNSYNCABLE_PREF);
1933 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, 1939 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck,
1934 0, // default value 1940 0, // default value
1935 PrefService::UNSYNCABLE_PREF); 1941 PrefService::UNSYNCABLE_PREF);
1936 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, 1942 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck,
1937 0, // default value 1943 0, // default value
1938 PrefService::UNSYNCABLE_PREF); 1944 PrefService::UNSYNCABLE_PREF);
1939 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, 1945 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites,
1940 PrefService::UNSYNCABLE_PREF); 1946 PrefService::UNSYNCABLE_PREF);
1941 } 1947 }
1942 1948
1949 ExtensionPrefs::ExtensionIdSet ExtensionPrefs::GetExtensionPrefAsVector(
1950 const char* pref) {
1951 ExtensionIdSet extension_ids;
1952 const ListValue* list_of_values = prefs_->GetList(pref);
1953 if (!list_of_values)
1954 return extension_ids;
1955
1956 std::string extension_id;
1957 for (size_t i = 0; i < list_of_values->GetSize(); ++i) {
1958 if (list_of_values->GetString(i, &extension_id))
1959 extension_ids.push_back(extension_id);
1960 }
1961 return extension_ids;
1962 }
1963
1964 void ExtensionPrefs::SetExtensionPrefFromVector(const char* pref,
1965 const ExtensionIdSet& strings) {
1966 ListPrefUpdate update(prefs_, pref);
1967 ListValue* list_of_values = update.Get();
1968 list_of_values->Clear();
1969 for (ExtensionIdSet::const_iterator iter = strings.begin();
1970 iter != strings.end(); ++iter)
1971 list_of_values->Append(new StringValue(*iter));
1972 }
1973
1943 } // namespace extensions 1974 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698