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

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

Issue 10821077: Add gallery permissions to Media Galleries Preferences (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments 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 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 void ExtensionPrefs::SetLaunchType(const std::string& extension_id, 1156 void ExtensionPrefs::SetLaunchType(const std::string& extension_id,
1157 LaunchType launch_type) { 1157 LaunchType launch_type) {
1158 UpdateExtensionPref(extension_id, kPrefLaunchType, 1158 UpdateExtensionPref(extension_id, kPrefLaunchType,
1159 Value::CreateIntegerValue(static_cast<int>(launch_type))); 1159 Value::CreateIntegerValue(static_cast<int>(launch_type)));
1160 } 1160 }
1161 1161
1162 namespace { 1162 namespace {
1163 1163
1164 bool GetMediaGalleryPermissionFromDictionary( 1164 bool GetMediaGalleryPermissionFromDictionary(
1165 const DictionaryValue* dict, 1165 const DictionaryValue* dict,
1166 MediaGalleryPermission* out_permission) { 1166 chrome::MediaGalleryPermission* out_permission) {
1167 std::string string_id; 1167 std::string string_id;
1168 if (dict->GetString(kMediaGalleryIdKey, &string_id) && 1168 if (dict->GetString(kMediaGalleryIdKey, &string_id) &&
1169 base::StringToUint64(string_id, &out_permission->pref_id) && 1169 base::StringToUint64(string_id, &out_permission->pref_id) &&
1170 dict->GetBoolean(kMediaGalleryHasPermissionKey, 1170 dict->GetBoolean(kMediaGalleryHasPermissionKey,
1171 &out_permission->has_permission)) { 1171 &out_permission->has_permission)) {
1172 return true; 1172 return true;
1173 } 1173 }
1174 NOTREACHED(); 1174 NOTREACHED();
1175 return false; 1175 return false;
1176 } 1176 }
1177 1177
1178 void RemoveMediaGalleryPermissionsFromExtension(PrefService* prefs, 1178 void RemoveMediaGalleryPermissionsFromExtension(
1179 const std::string& extension_id, 1179 PrefService* prefs,
1180 MediaGalleryPrefId gallery_id) { 1180 const std::string& extension_id,
1181 chrome::MediaGalleryPrefId gallery_id) {
1181 ScopedExtensionPrefUpdate update(prefs, extension_id); 1182 ScopedExtensionPrefUpdate update(prefs, extension_id);
1182 DictionaryValue* extension_dict = update.Get(); 1183 DictionaryValue* extension_dict = update.Get();
1183 ListValue* permissions = NULL; 1184 ListValue* permissions = NULL;
1184 if (!extension_dict->GetList(kMediaGalleriesPermissions, &permissions)) 1185 if (!extension_dict->GetList(kMediaGalleriesPermissions, &permissions))
1185 return; 1186 return;
1186 1187
1187 for (ListValue::iterator it = permissions->begin(); 1188 for (ListValue::iterator it = permissions->begin();
1188 it != permissions->end(); 1189 it != permissions->end();
1189 ++it) { 1190 ++it) {
1190 const DictionaryValue* dict = NULL; 1191 const DictionaryValue* dict = NULL;
1191 if (!(*it)->GetAsDictionary(&dict)) 1192 if (!(*it)->GetAsDictionary(&dict))
1192 continue; 1193 continue;
1193 MediaGalleryPermission perm; 1194 chrome::MediaGalleryPermission perm;
1194 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm)) 1195 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm))
1195 continue; 1196 continue;
1196 if (perm.pref_id == gallery_id) { 1197 if (perm.pref_id == gallery_id) {
1197 permissions->Erase(it, NULL); 1198 permissions->Erase(it, NULL);
1198 return; 1199 return;
1199 } 1200 }
1200 } 1201 }
1201 } 1202 }
1202 1203
1203 } // namespace 1204 } // namespace
1204 1205
1205 void ExtensionPrefs::SetMediaGalleryPermission(const std::string& extension_id, 1206 void ExtensionPrefs::SetMediaGalleryPermission(
1206 MediaGalleryPrefId gallery, 1207 const std::string& extension_id,
1207 bool has_access) { 1208 chrome::MediaGalleryPrefId gallery,
1209 bool has_access) {
1208 ScopedExtensionPrefUpdate update(prefs_, extension_id); 1210 ScopedExtensionPrefUpdate update(prefs_, extension_id);
1209 DictionaryValue* extension_dict = update.Get(); 1211 DictionaryValue* extension_dict = update.Get();
1210 ListValue* permissions = NULL; 1212 ListValue* permissions = NULL;
1211 if (!extension_dict->GetList(kMediaGalleriesPermissions, &permissions)) { 1213 if (!extension_dict->GetList(kMediaGalleriesPermissions, &permissions)) {
1212 permissions = new ListValue; 1214 permissions = new ListValue;
1213 extension_dict->Set(kMediaGalleriesPermissions, permissions); 1215 extension_dict->Set(kMediaGalleriesPermissions, permissions);
1214 } else { 1216 } else {
1215 // If the gallery is already in the list, update the permission. 1217 // If the gallery is already in the list, update the permission.
1216 for (ListValue::const_iterator it = permissions->begin(); 1218 for (ListValue::const_iterator it = permissions->begin();
1217 it != permissions->end(); 1219 it != permissions->end();
1218 ++it) { 1220 ++it) {
1219 DictionaryValue* dict = NULL; 1221 DictionaryValue* dict = NULL;
1220 if (!(*it)->GetAsDictionary(&dict)) 1222 if (!(*it)->GetAsDictionary(&dict))
1221 continue; 1223 continue;
1222 MediaGalleryPermission perm; 1224 chrome::MediaGalleryPermission perm;
1223 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm)) 1225 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm))
1224 continue; 1226 continue;
1225 if (perm.pref_id == gallery) { 1227 if (perm.pref_id == gallery) {
1226 dict->SetBoolean(kMediaGalleryHasPermissionKey, has_access); 1228 dict->SetBoolean(kMediaGalleryHasPermissionKey, has_access);
1227 return; 1229 return;
1228 } 1230 }
1229 } 1231 }
1230 } 1232 }
1231 1233
1232 DictionaryValue* dict = new DictionaryValue; 1234 DictionaryValue* dict = new DictionaryValue;
1233 dict->SetString(kMediaGalleryIdKey, base::Uint64ToString(gallery)); 1235 dict->SetString(kMediaGalleryIdKey, base::Uint64ToString(gallery));
1234 dict->SetBoolean(kMediaGalleryHasPermissionKey, has_access); 1236 dict->SetBoolean(kMediaGalleryHasPermissionKey, has_access);
1235 permissions->Append(dict); 1237 permissions->Append(dict);
1236 } 1238 }
1237 1239
1238 std::vector<MediaGalleryPermission> ExtensionPrefs::GetMediaGalleryPermissions( 1240 void ExtensionPrefs::UnsetMediaGalleryPermission(
1239 const std::string& extension_id) { 1241 const std::string& extension_id,
1240 std::vector<MediaGalleryPermission> result; 1242 chrome::MediaGalleryPrefId gallery) {
1243 RemoveMediaGalleryPermissionsFromExtension(prefs_, extension_id, gallery);
1244 }
1245
1246 std::vector<chrome::MediaGalleryPermission>
1247 ExtensionPrefs::GetMediaGalleryPermissions(const std::string& extension_id) {
1248 std::vector<chrome::MediaGalleryPermission> result;
1241 const ListValue* permissions = NULL; 1249 const ListValue* permissions = NULL;
1242 if (ReadExtensionPrefList(extension_id, kMediaGalleriesPermissions, 1250 if (ReadExtensionPrefList(extension_id, kMediaGalleriesPermissions,
1243 &permissions)) { 1251 &permissions)) {
1244 for (ListValue::const_iterator it = permissions->begin(); 1252 for (ListValue::const_iterator it = permissions->begin();
1245 it != permissions->end(); 1253 it != permissions->end();
1246 ++it) { 1254 ++it) {
1247 DictionaryValue* dict = NULL; 1255 DictionaryValue* dict = NULL;
1248 if (!(*it)->GetAsDictionary(&dict)) 1256 if (!(*it)->GetAsDictionary(&dict))
1249 continue; 1257 continue;
1250 MediaGalleryPermission perm; 1258 chrome::MediaGalleryPermission perm;
1251 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm)) 1259 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm))
1252 continue; 1260 continue;
1253 result.push_back(perm); 1261 result.push_back(perm);
1254 } 1262 }
1255 } 1263 }
1256 return result; 1264 return result;
1257 } 1265 }
1258 1266
1259 void ExtensionPrefs::RemoveMediaGalleryPermissions( 1267 void ExtensionPrefs::RemoveMediaGalleryPermissions(
1260 MediaGalleryPrefId gallery_id) { 1268 chrome::MediaGalleryPrefId gallery_id) {
1261 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); 1269 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
1262 if (!extensions) 1270 if (!extensions)
1263 return; 1271 return;
1264 1272
1265 for (DictionaryValue::key_iterator it = extensions->begin_keys(); 1273 for (DictionaryValue::key_iterator it = extensions->begin_keys();
1266 it != extensions->end_keys(); 1274 it != extensions->end_keys();
1267 ++it) { 1275 ++it) {
1268 const std::string& id(*it); 1276 const std::string& id(*it);
1269 if (!Extension::IdIsValid(id)) { 1277 if (!Extension::IdIsValid(id)) {
1270 NOTREACHED(); 1278 NOTREACHED();
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 0, // default value 2066 0, // default value
2059 PrefService::UNSYNCABLE_PREF); 2067 PrefService::UNSYNCABLE_PREF);
2060 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, 2068 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck,
2061 0, // default value 2069 0, // default value
2062 PrefService::UNSYNCABLE_PREF); 2070 PrefService::UNSYNCABLE_PREF);
2063 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, 2071 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites,
2064 PrefService::UNSYNCABLE_PREF); 2072 PrefService::UNSYNCABLE_PREF);
2065 } 2073 }
2066 2074
2067 } // namespace extensions 2075 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698