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