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

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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // Indicates whether to show an install warning when the user enables. 64 // Indicates whether to show an install warning when the user enables.
65 const char kExtensionDidEscalatePermissions[] = "install_warning_on_enable"; 65 const char kExtensionDidEscalatePermissions[] = "install_warning_on_enable";
66 66
67 // Indicates whether the extension was updated while it was disabled. 67 // Indicates whether the extension was updated while it was disabled.
68 const char kPrefDisableReason[] = "disable_reason"; 68 const char kPrefDisableReason[] = "disable_reason";
69 69
70 // A preference that tracks browser action toolbar configuration. This is a list 70 // A preference that tracks browser action toolbar configuration. This is a list
71 // object stored in the Preferences file. The extensions are stored by ID. 71 // object stored in the Preferences file. The extensions are stored by ID.
72 const char kExtensionToolbar[] = "extensions.toolbar"; 72 const char kExtensionToolbar[] = "extensions.toolbar";
73 73
74 // A preference that tracks the order of extensions in an action box
75 // (list of extension ids).
76 const char kExtensionActionBox[] = "extensions.action_box_order";
77
78 // A preference that tracks the order of extensions in a toolbar when
79 // action box is enabled (list of extension ids).
80 const char kExtensionActionBoxBar[] =
81 "extensions.toolbar_order_with_action_box";
82
74 // The key for a serialized Time value indicating the start of the day (from the 83 // The key for a serialized Time value indicating the start of the day (from the
75 // server's perspective) an extension last included a "ping" parameter during 84 // server's perspective) an extension last included a "ping" parameter during
76 // its update check. 85 // its update check.
77 const char kLastPingDay[] = "lastpingday"; 86 const char kLastPingDay[] = "lastpingday";
78 87
79 // Similar to kLastPingDay, but for "active" instead of "rollcall" pings. 88 // Similar to kLastPingDay, but for "active" instead of "rollcall" pings.
80 const char kLastActivePingDay[] = "last_active_pingday"; 89 const char kLastActivePingDay[] = "last_active_pingday";
81 90
82 // A bit we use to keep track of whether we need to do an "active" ping. 91 // A bit we use to keep track of whether we need to do an "active" ping.
83 const char kActiveBit[] = "active_bit"; 92 const char kActiveBit[] = "active_bit";
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 extension_id, kPrefDisableReason, 712 extension_id, kPrefDisableReason,
704 Value::CreateIntegerValue(static_cast<int>(disable_reason))); 713 Value::CreateIntegerValue(static_cast<int>(disable_reason)));
705 } 714 }
706 715
707 void ExtensionPrefs::RemoveDisableReason(const std::string& extension_id) { 716 void ExtensionPrefs::RemoveDisableReason(const std::string& extension_id) {
708 UpdateExtensionPref(extension_id, kPrefDisableReason, NULL); 717 UpdateExtensionPref(extension_id, kPrefDisableReason, NULL);
709 } 718 }
710 719
711 void ExtensionPrefs::UpdateBlacklist( 720 void ExtensionPrefs::UpdateBlacklist(
712 const std::set<std::string>& blacklist_set) { 721 const std::set<std::string>& blacklist_set) {
713 std::vector<std::string> remove_pref_ids; 722 ExtensionIdSet remove_pref_ids;
714 std::set<std::string> used_id_set; 723 std::set<std::string> used_id_set;
715 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); 724 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
716 725
717 if (extensions) { 726 if (extensions) {
718 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys(); 727 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys();
719 extension_id != extensions->end_keys(); ++extension_id) { 728 extension_id != extensions->end_keys(); ++extension_id) {
720 const DictionaryValue* ext; 729 const DictionaryValue* ext;
721 if (!extensions->GetDictionaryWithoutPathExpansion(*extension_id, &ext)) { 730 if (!extensions->GetDictionaryWithoutPathExpansion(*extension_id, &ext)) {
722 NOTREACHED() << "Invalid pref for extension " << *extension_id; 731 NOTREACHED() << "Invalid pref for extension " << *extension_id;
723 continue; 732 continue;
(...skipping 26 matching lines...) Expand all
750 } 759 }
751 760
752 // Iterate the leftovers to set blacklist in pref 761 // Iterate the leftovers to set blacklist in pref
753 std::set<std::string>::const_iterator set_itr = blacklist_set.begin(); 762 std::set<std::string>::const_iterator set_itr = blacklist_set.begin();
754 for (; set_itr != blacklist_set.end(); ++set_itr) { 763 for (; set_itr != blacklist_set.end(); ++set_itr) {
755 if (used_id_set.find(*set_itr) == used_id_set.end()) { 764 if (used_id_set.find(*set_itr) == used_id_set.end()) {
756 UpdateExtensionPref(*set_itr, kPrefBlacklist, 765 UpdateExtensionPref(*set_itr, kPrefBlacklist,
757 Value::CreateBooleanValue(true)); 766 Value::CreateBooleanValue(true));
758 } 767 }
759 } 768 }
760 for (unsigned int i = 0; i < remove_pref_ids.size(); ++i) { 769 for (size_t i = 0; i < remove_pref_ids.size(); ++i) {
761 DeleteExtensionPrefs(remove_pref_ids[i]); 770 DeleteExtensionPrefs(remove_pref_ids[i]);
762 } 771 }
763 } 772 }
764 773
765 namespace { 774 namespace {
766 775
767 // Serializes |time| as a string value mapped to |key| in |dictionary|. 776 // Serializes |time| as a string value mapped to |key| in |dictionary|.
768 void SaveTime(DictionaryValue* dictionary, 777 void SaveTime(DictionaryValue* dictionary,
769 const char* key, 778 const char* key,
770 const base::Time& time) { 779 const base::Time& time) {
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 bool ExtensionPrefs::IsExternalExtensionUninstalled( 1302 bool ExtensionPrefs::IsExternalExtensionUninstalled(
1294 const std::string& id) const { 1303 const std::string& id) const {
1295 return DoesExtensionHaveState(id, Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1304 return DoesExtensionHaveState(id, Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1296 } 1305 }
1297 1306
1298 bool ExtensionPrefs::IsExtensionDisabled( 1307 bool ExtensionPrefs::IsExtensionDisabled(
1299 const std::string& id) const { 1308 const std::string& id) const {
1300 return DoesExtensionHaveState(id, Extension::DISABLED); 1309 return DoesExtensionHaveState(id, Extension::DISABLED);
1301 } 1310 }
1302 1311
1303 std::vector<std::string> ExtensionPrefs::GetToolbarOrder() { 1312 ExtensionPrefs::ExtensionIdSet ExtensionPrefs::GetToolbarOrder() {
1304 ExtensionIdSet extension_ids; 1313 bool action_box_enabled = extensions::switch_utils::IsActionBoxEnabled();
1305 const ListValue* toolbar_order = prefs_->GetList(kExtensionToolbar); 1314 return GetExtensionPrefAsVector(
1306 if (toolbar_order) { 1315 action_box_enabled ? kExtensionActionBoxBar : kExtensionToolbar);
1307 for (size_t i = 0; i < toolbar_order->GetSize(); ++i) {
1308 std::string extension_id;
1309 if (toolbar_order->GetString(i, &extension_id))
1310 extension_ids.push_back(extension_id);
1311 }
1312 }
1313 return extension_ids;
1314 } 1316 }
1315 1317
1316 void ExtensionPrefs::SetToolbarOrder( 1318 void ExtensionPrefs::SetToolbarOrder(const ExtensionIdSet& extension_ids) {
1317 const std::vector<std::string>& extension_ids) { 1319 SetExtensionPrefFromVector(extensions::switch_utils::IsActionBoxEnabled() ?
1318 ListPrefUpdate update(prefs_, kExtensionToolbar); 1320 kExtensionActionBoxBar : kExtensionToolbar, extension_ids);
1319 ListValue* toolbar_order = update.Get(); 1321 }
1320 toolbar_order->Clear(); 1322
1321 for (std::vector<std::string>::const_iterator iter = extension_ids.begin(); 1323 ExtensionPrefs::ExtensionIdSet ExtensionPrefs::GetActionBoxOrder() {
1322 iter != extension_ids.end(); ++iter) { 1324 return GetExtensionPrefAsVector(kExtensionActionBox);
1323 toolbar_order->Append(new StringValue(*iter)); 1325 }
1324 } 1326
1327 void ExtensionPrefs::SetActionBoxOrder(const ExtensionIdSet& extension_ids) {
1328 SetExtensionPrefFromVector(kExtensionActionBox, extension_ids);
1325 } 1329 }
1326 1330
1327 void ExtensionPrefs::OnExtensionInstalled( 1331 void ExtensionPrefs::OnExtensionInstalled(
1328 const Extension* extension, 1332 const Extension* extension,
1329 Extension::State initial_state, 1333 Extension::State initial_state,
1330 bool from_webstore, 1334 bool from_webstore,
1331 const StringOrdinal& page_ordinal) { 1335 const StringOrdinal& page_ordinal) {
1332 const std::string& id = extension->id(); 1336 const std::string& id = extension->id();
1333 CHECK(Extension::IdIsValid(id)); 1337 CHECK(Extension::IdIsValid(id));
1334 ScopedExtensionPrefUpdate update(prefs_, id); 1338 ScopedExtensionPrefUpdate update(prefs_, id);
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
2031 result.AddPattern(entry); 2035 result.AddPattern(entry);
2032 } 2036 }
2033 2037
2034 return result; 2038 return result;
2035 } 2039 }
2036 2040
2037 // static 2041 // static
2038 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { 2042 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) {
2039 prefs->RegisterDictionaryPref(kExtensionsPref, PrefService::UNSYNCABLE_PREF); 2043 prefs->RegisterDictionaryPref(kExtensionsPref, PrefService::UNSYNCABLE_PREF);
2040 prefs->RegisterListPref(kExtensionToolbar, PrefService::UNSYNCABLE_PREF); 2044 prefs->RegisterListPref(kExtensionToolbar, PrefService::UNSYNCABLE_PREF);
2045 prefs->RegisterListPref(kExtensionActionBox, PrefService::UNSYNCABLE_PREF);
2046 prefs->RegisterListPref(kExtensionActionBoxBar, PrefService::UNSYNCABLE_PREF);
2041 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, 2047 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize,
2042 -1, // default value 2048 -1, // default value
2043 PrefService::UNSYNCABLE_PREF); 2049 PrefService::UNSYNCABLE_PREF);
2044 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate, 2050 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate,
2045 PrefService::UNSYNCABLE_PREF); 2051 PrefService::UNSYNCABLE_PREF);
2046 prefs->RegisterListPref(prefs::kExtensionInstallAllowList, 2052 prefs->RegisterListPref(prefs::kExtensionInstallAllowList,
2047 PrefService::UNSYNCABLE_PREF); 2053 PrefService::UNSYNCABLE_PREF);
2048 prefs->RegisterListPref(prefs::kExtensionInstallDenyList, 2054 prefs->RegisterListPref(prefs::kExtensionInstallDenyList,
2049 PrefService::UNSYNCABLE_PREF); 2055 PrefService::UNSYNCABLE_PREF);
2050 prefs->RegisterListPref(prefs::kExtensionInstallForceList, 2056 prefs->RegisterListPref(prefs::kExtensionInstallForceList,
2051 PrefService::UNSYNCABLE_PREF); 2057 PrefService::UNSYNCABLE_PREF);
2052 prefs->RegisterStringPref(kWebStoreLogin, 2058 prefs->RegisterStringPref(kWebStoreLogin,
2053 std::string(), // default value 2059 std::string(), // default value
2054 PrefService::UNSYNCABLE_PREF); 2060 PrefService::UNSYNCABLE_PREF);
2055 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, 2061 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion,
2056 "0", // default value 2062 "0", // default value
2057 PrefService::UNSYNCABLE_PREF); 2063 PrefService::UNSYNCABLE_PREF);
2058 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, 2064 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck,
2059 0, // default value 2065 0, // default value
2060 PrefService::UNSYNCABLE_PREF); 2066 PrefService::UNSYNCABLE_PREF);
2061 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, 2067 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck,
2062 0, // default value 2068 0, // default value
2063 PrefService::UNSYNCABLE_PREF); 2069 PrefService::UNSYNCABLE_PREF);
2064 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, 2070 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites,
2065 PrefService::UNSYNCABLE_PREF); 2071 PrefService::UNSYNCABLE_PREF);
2066 } 2072 }
2067 2073
2074 ExtensionPrefs::ExtensionIdSet ExtensionPrefs::GetExtensionPrefAsVector(
2075 const char* pref) {
2076 ExtensionIdSet extension_ids;
2077 const ListValue* list_of_values = prefs_->GetList(pref);
2078 if (!list_of_values)
2079 return extension_ids;
2080
2081 std::string extension_id;
2082 for (size_t i = 0; i < list_of_values->GetSize(); ++i) {
2083 if (list_of_values->GetString(i, &extension_id))
2084 extension_ids.push_back(extension_id);
2085 }
2086 return extension_ids;
2087 }
2088
2089 void ExtensionPrefs::SetExtensionPrefFromVector(const char* pref,
2090 const ExtensionIdSet& strings) {
2091 ListPrefUpdate update(prefs_, pref);
2092 ListValue* list_of_values = update.Get();
2093 list_of_values->Clear();
2094 for (ExtensionIdSet::const_iterator iter = strings.begin();
2095 iter != strings.end(); ++iter)
2096 list_of_values->Append(new StringValue(*iter));
2097 }
2098
2068 } // namespace extensions 2099 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/extension_toolbar_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698