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

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

Issue 10941003: Reset registered events and dispatch runtime.onInstalled to all extensions when (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ? Created 8 years, 3 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/command_line.h"
7 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
8 #include "base/string_util.h" 9 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "base/version.h"
10 #include "chrome/browser/extensions/admin_policy.h" 12 #include "chrome/browser/extensions/admin_policy.h"
11 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" 13 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
12 #include "chrome/browser/extensions/extension_pref_store.h" 14 #include "chrome/browser/extensions/extension_pref_store.h"
13 #include "chrome/browser/extensions/extension_sorting.h" 15 #include "chrome/browser/extensions/extension_sorting.h"
14 #include "chrome/browser/prefs/pref_notifier.h" 16 #include "chrome/browser/prefs/pref_notifier.h"
15 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/browser/prefs/scoped_user_pref_update.h" 18 #include "chrome/browser/prefs/scoped_user_pref_update.h"
17 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/chrome_version_info.h"
18 #include "chrome/common/extensions/extension_switch_utils.h" 22 #include "chrome/common/extensions/extension_switch_utils.h"
19 #include "chrome/common/extensions/manifest.h" 23 #include "chrome/common/extensions/manifest.h"
20 #include "chrome/common/extensions/permissions/permission_set.h" 24 #include "chrome/common/extensions/permissions/permission_set.h"
21 #include "chrome/common/extensions/permissions/permissions_info.h" 25 #include "chrome/common/extensions/permissions/permissions_info.h"
22 #include "chrome/common/extensions/url_pattern.h" 26 #include "chrome/common/extensions/url_pattern.h"
23 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
24 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
25 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
26 #include "grit/generated_resources.h" 30 #include "grit/generated_resources.h"
27 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 202
199 // List of media gallery permissions. 203 // List of media gallery permissions.
200 const char kMediaGalleriesPermissions[] = "media_galleries_permissions"; 204 const char kMediaGalleriesPermissions[] = "media_galleries_permissions";
201 205
202 // Key for Media Gallery ID. 206 // Key for Media Gallery ID.
203 const char kMediaGalleryIdKey[] = "id"; 207 const char kMediaGalleryIdKey[] = "id";
204 208
205 // Key for Media Gallery Permission Value. 209 // Key for Media Gallery Permission Value.
206 const char kMediaGalleryHasPermissionKey[] = "has_permission"; 210 const char kMediaGalleryHasPermissionKey[] = "has_permission";
207 211
212 // Key for what version chrome was last time the extension prefs were loaded.
213 const char kExtensionsLastChromeVersion[] = "extensions.last_chrome_version";
214
208 // Provider of write access to a dictionary storing extension prefs. 215 // Provider of write access to a dictionary storing extension prefs.
209 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { 216 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate {
210 public: 217 public:
211 ScopedExtensionPrefUpdate(PrefService* service, 218 ScopedExtensionPrefUpdate(PrefService* service,
212 const std::string& extension_id) : 219 const std::string& extension_id) :
213 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref), 220 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref),
214 extension_id_(extension_id) {} 221 extension_id_(extension_id) {}
215 222
216 virtual ~ScopedExtensionPrefUpdate() { 223 virtual ~ScopedExtensionPrefUpdate() {
217 } 224 }
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 } 960 }
954 961
955 UpdateExtensionPref(*ext_id, kPrefDisableReasons, 962 UpdateExtensionPref(*ext_id, kPrefDisableReasons,
956 Value::CreateIntegerValue(new_value)); 963 Value::CreateIntegerValue(new_value));
957 // Remove the old disable reason. 964 // Remove the old disable reason.
958 UpdateExtensionPref(*ext_id, kDeprecatedPrefDisableReason, NULL); 965 UpdateExtensionPref(*ext_id, kDeprecatedPrefDisableReason, NULL);
959 } 966 }
960 } 967 }
961 } 968 }
962 969
970 void ExtensionPrefs::ClearRegisteredEvents() {
971 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
972 if (!extensions)
973 return;
974
975 for (DictionaryValue::key_iterator it = extensions->begin_keys();
976 it != extensions->end_keys(); ++it) {
977 UpdateExtensionPref(*it, kRegisteredEvents, NULL);
978 }
979 }
980
963 PermissionSet* ExtensionPrefs::GetGrantedPermissions( 981 PermissionSet* ExtensionPrefs::GetGrantedPermissions(
964 const std::string& extension_id) { 982 const std::string& extension_id) {
965 CHECK(Extension::IdIsValid(extension_id)); 983 CHECK(Extension::IdIsValid(extension_id));
966 return ReadExtensionPrefPermissionSet(extension_id, kPrefGrantedPermissions); 984 return ReadExtensionPrefPermissionSet(extension_id, kPrefGrantedPermissions);
967 } 985 }
968 986
969 void ExtensionPrefs::AddGrantedPermissions( 987 void ExtensionPrefs::AddGrantedPermissions(
970 const std::string& extension_id, 988 const std::string& extension_id,
971 const PermissionSet* permissions) { 989 const PermissionSet* permissions) {
972 CHECK(Extension::IdIsValid(extension_id)); 990 CHECK(Extension::IdIsValid(extension_id));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 return ReadExtensionPrefPermissionSet(extension_id, kPrefActivePermissions); 1026 return ReadExtensionPrefPermissionSet(extension_id, kPrefActivePermissions);
1009 } 1027 }
1010 1028
1011 void ExtensionPrefs::SetActivePermissions( 1029 void ExtensionPrefs::SetActivePermissions(
1012 const std::string& extension_id, 1030 const std::string& extension_id,
1013 const PermissionSet* permissions) { 1031 const PermissionSet* permissions) {
1014 SetExtensionPrefPermissionSet( 1032 SetExtensionPrefPermissionSet(
1015 extension_id, kPrefActivePermissions, permissions); 1033 extension_id, kPrefActivePermissions, permissions);
1016 } 1034 }
1017 1035
1036 bool ExtensionPrefs::CheckRegisteredEventsUpToDate() {
1037 // If we're running inside a test, then assume prefs are all up-to-date.
1038 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType))
Matt Perry 2012/09/19 23:32:46 I had to add this bit to fix the chromeos tests. C
1039 return true;
1040
1041 Version version;
1042 if (prefs_->HasPrefPath(kExtensionsLastChromeVersion)) {
1043 std::string version_str = prefs_->GetString(kExtensionsLastChromeVersion);
1044 version = Version(version_str);
1045 }
1046
1047 chrome::VersionInfo current_version_info;
1048 std::string current_version = current_version_info.Version();
1049 prefs_->SetString(kExtensionsLastChromeVersion, current_version);
1050
1051 // If there was no version string in prefs, assume we're out of date.
1052 if (!version.IsValid() || version.IsOlderThan(current_version)) {
1053 ClearRegisteredEvents();
1054 return false;
1055 }
1056
1057 return true;
1058 }
1059
1018 std::set<std::string> ExtensionPrefs::GetRegisteredEvents( 1060 std::set<std::string> ExtensionPrefs::GetRegisteredEvents(
1019 const std::string& extension_id) { 1061 const std::string& extension_id) {
1020 std::set<std::string> events; 1062 std::set<std::string> events;
1021 const DictionaryValue* extension = GetExtensionPref(extension_id); 1063 const DictionaryValue* extension = GetExtensionPref(extension_id);
1022 if (!extension) 1064 if (!extension)
1023 return events; 1065 return events;
1024 1066
1025 const ListValue* value = NULL; 1067 const ListValue* value = NULL;
1026 if (!extension->GetList(kRegisteredEvents, &value)) 1068 if (!extension->GetList(kRegisteredEvents, &value))
1027 return events; 1069 return events;
(...skipping 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after
2133 "0", // default value 2175 "0", // default value
2134 PrefService::UNSYNCABLE_PREF); 2176 PrefService::UNSYNCABLE_PREF);
2135 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, 2177 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck,
2136 0, // default value 2178 0, // default value
2137 PrefService::UNSYNCABLE_PREF); 2179 PrefService::UNSYNCABLE_PREF);
2138 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, 2180 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck,
2139 0, // default value 2181 0, // default value
2140 PrefService::UNSYNCABLE_PREF); 2182 PrefService::UNSYNCABLE_PREF);
2141 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, 2183 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites,
2142 PrefService::UNSYNCABLE_PREF); 2184 PrefService::UNSYNCABLE_PREF);
2185 prefs->RegisterStringPref(kExtensionsLastChromeVersion,
2186 std::string(), // default value
2187 PrefService::UNSYNCABLE_PREF);
2143 } 2188 }
2144 2189
2145 ExtensionPrefs::ExtensionIds ExtensionPrefs::GetExtensionPrefAsVector( 2190 ExtensionPrefs::ExtensionIds ExtensionPrefs::GetExtensionPrefAsVector(
2146 const char* pref) { 2191 const char* pref) {
2147 ExtensionIds extension_ids; 2192 ExtensionIds extension_ids;
2148 const ListValue* list_of_values = prefs_->GetList(pref); 2193 const ListValue* list_of_values = prefs_->GetList(pref);
2149 if (!list_of_values) 2194 if (!list_of_values)
2150 return extension_ids; 2195 return extension_ids;
2151 2196
2152 std::string extension_id; 2197 std::string extension_id;
2153 for (size_t i = 0; i < list_of_values->GetSize(); ++i) { 2198 for (size_t i = 0; i < list_of_values->GetSize(); ++i) {
2154 if (list_of_values->GetString(i, &extension_id)) 2199 if (list_of_values->GetString(i, &extension_id))
2155 extension_ids.push_back(extension_id); 2200 extension_ids.push_back(extension_id);
2156 } 2201 }
2157 return extension_ids; 2202 return extension_ids;
2158 } 2203 }
2159 2204
2160 void ExtensionPrefs::SetExtensionPrefFromVector(const char* pref, 2205 void ExtensionPrefs::SetExtensionPrefFromVector(const char* pref,
2161 const ExtensionIds& strings) { 2206 const ExtensionIds& strings) {
2162 ListPrefUpdate update(prefs_, pref); 2207 ListPrefUpdate update(prefs_, pref);
2163 ListValue* list_of_values = update.Get(); 2208 ListValue* list_of_values = update.Get();
2164 list_of_values->Clear(); 2209 list_of_values->Clear();
2165 for (ExtensionIds::const_iterator iter = strings.begin(); 2210 for (ExtensionIds::const_iterator iter = strings.begin();
2166 iter != strings.end(); ++iter) 2211 iter != strings.end(); ++iter)
2167 list_of_values->Append(new StringValue(*iter)); 2212 list_of_values->Append(new StringValue(*iter));
2168 } 2213 }
2169 2214
2170 } // namespace extensions 2215 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/extension_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698