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

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: Compiles 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 std::vector<chrome::MediaGalleryPermission>
1239 const std::string& extension_id) { 1241 ExtensionPrefs::GetMediaGalleryPermissions(const std::string& extension_id) {
1240 std::vector<MediaGalleryPermission> result; 1242 std::vector<chrome::MediaGalleryPermission> result;
1241 const ListValue* permissions = NULL; 1243 const ListValue* permissions = NULL;
1242 if (ReadExtensionPrefList(extension_id, kMediaGalleriesPermissions, 1244 if (ReadExtensionPrefList(extension_id, kMediaGalleriesPermissions,
1243 &permissions)) { 1245 &permissions)) {
1244 for (ListValue::const_iterator it = permissions->begin(); 1246 for (ListValue::const_iterator it = permissions->begin();
1245 it != permissions->end(); 1247 it != permissions->end();
1246 it++) { 1248 it++) {
1247 DictionaryValue* dict = NULL; 1249 DictionaryValue* dict = NULL;
1248 if (!(*it)->GetAsDictionary(&dict)) 1250 if (!(*it)->GetAsDictionary(&dict))
1249 continue; 1251 continue;
1250 MediaGalleryPermission perm; 1252 chrome::MediaGalleryPermission perm;
1251 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm)) 1253 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm))
1252 continue; 1254 continue;
1253 result.push_back(perm); 1255 result.push_back(perm);
1254 } 1256 }
1255 } 1257 }
1256 return result; 1258 return result;
1257 } 1259 }
1258 1260
1259 void ExtensionPrefs::RemoveMediaGalleryPermissions( 1261 void ExtensionPrefs::RemoveMediaGalleryPermissions(
1260 MediaGalleryPrefId gallery_id) { 1262 chrome::MediaGalleryPrefId gallery_id) {
1261 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); 1263 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
1262 if (!extensions) 1264 if (!extensions)
1263 return; 1265 return;
1264 1266
1265 for (DictionaryValue::key_iterator iter = extensions->begin_keys(); 1267 for (DictionaryValue::key_iterator iter = extensions->begin_keys();
1266 iter != extensions->end_keys(); ++iter) { 1268 iter != extensions->end_keys(); ++iter) {
1267 const std::string& id(*iter); 1269 const std::string& id(*iter);
1268 if (!Extension::IdIsValid(id)) { 1270 if (!Extension::IdIsValid(id)) {
1269 NOTREACHED(); 1271 NOTREACHED();
1270 continue; 1272 continue;
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 0, // default value 2059 0, // default value
2058 PrefService::UNSYNCABLE_PREF); 2060 PrefService::UNSYNCABLE_PREF);
2059 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, 2061 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck,
2060 0, // default value 2062 0, // default value
2061 PrefService::UNSYNCABLE_PREF); 2063 PrefService::UNSYNCABLE_PREF);
2062 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, 2064 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites,
2063 PrefService::UNSYNCABLE_PREF); 2065 PrefService::UNSYNCABLE_PREF);
2064 } 2066 }
2065 2067
2066 } // namespace extensions 2068 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698