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

Side by Side Diff: chrome/common/extensions/extension.cc

Issue 6324004: Made return types of various Value::DeepCopy() implementations more specific (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add test for covariant return types Created 9 years, 11 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 // development mode, because it keeps the ID stable across restarts and 1246 // development mode, because it keeps the ID stable across restarts and
1247 // reloading the extension. 1247 // reloading the extension.
1248 id_ = Extension::GenerateIdForPath(path()); 1248 id_ = Extension::GenerateIdForPath(path());
1249 if (id_.empty()) { 1249 if (id_.empty()) {
1250 NOTREACHED() << "Could not create ID from path."; 1250 NOTREACHED() << "Could not create ID from path.";
1251 return false; 1251 return false;
1252 } 1252 }
1253 } 1253 }
1254 1254
1255 // Make a copy of the manifest so we can store it in prefs. 1255 // Make a copy of the manifest so we can store it in prefs.
1256 manifest_value_.reset( 1256 manifest_value_.reset(source.DeepCopy());
1257 static_cast<DictionaryValue*>(source.DeepCopy()));
1258 1257
1259 // Initialize the URL. 1258 // Initialize the URL.
1260 extension_url_ = 1259 extension_url_ =
1261 Extension::GetBaseURLFromExtensionId(id()); 1260 Extension::GetBaseURLFromExtensionId(id());
1262 1261
1263 // Initialize version. 1262 // Initialize version.
1264 std::string version_str; 1263 std::string version_str;
1265 if (!source.GetString(keys::kVersion, &version_str)) { 1264 if (!source.GetString(keys::kVersion, &version_str)) {
1266 *error = errors::kInvalidVersion; 1265 *error = errors::kInvalidVersion;
1267 return false; 1266 return false;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 if (theme_value->GetDictionary(keys::kThemeImages, &images_value)) { 1418 if (theme_value->GetDictionary(keys::kThemeImages, &images_value)) {
1420 // Validate that the images are all strings 1419 // Validate that the images are all strings
1421 for (DictionaryValue::key_iterator iter = images_value->begin_keys(); 1420 for (DictionaryValue::key_iterator iter = images_value->begin_keys();
1422 iter != images_value->end_keys(); ++iter) { 1421 iter != images_value->end_keys(); ++iter) {
1423 std::string val; 1422 std::string val;
1424 if (!images_value->GetString(*iter, &val)) { 1423 if (!images_value->GetString(*iter, &val)) {
1425 *error = errors::kInvalidThemeImages; 1424 *error = errors::kInvalidThemeImages;
1426 return false; 1425 return false;
1427 } 1426 }
1428 } 1427 }
1429 theme_images_.reset( 1428 theme_images_.reset(images_value->DeepCopy());
1430 static_cast<DictionaryValue*>(images_value->DeepCopy()));
1431 } 1429 }
1432 1430
1433 DictionaryValue* colors_value; 1431 DictionaryValue* colors_value;
1434 if (theme_value->GetDictionary(keys::kThemeColors, &colors_value)) { 1432 if (theme_value->GetDictionary(keys::kThemeColors, &colors_value)) {
1435 // Validate that the colors are RGB or RGBA lists 1433 // Validate that the colors are RGB or RGBA lists
1436 for (DictionaryValue::key_iterator iter = colors_value->begin_keys(); 1434 for (DictionaryValue::key_iterator iter = colors_value->begin_keys();
1437 iter != colors_value->end_keys(); ++iter) { 1435 iter != colors_value->end_keys(); ++iter) {
1438 ListValue* color_list; 1436 ListValue* color_list;
1439 double alpha; 1437 double alpha;
1440 int alpha_int; 1438 int alpha_int;
1441 int color; 1439 int color;
1442 // The color must be a list 1440 // The color must be a list
1443 if (!colors_value->GetListWithoutPathExpansion(*iter, &color_list) || 1441 if (!colors_value->GetListWithoutPathExpansion(*iter, &color_list) ||
1444 // And either 3 items (RGB) or 4 (RGBA) 1442 // And either 3 items (RGB) or 4 (RGBA)
1445 ((color_list->GetSize() != 3) && 1443 ((color_list->GetSize() != 3) &&
1446 ((color_list->GetSize() != 4) || 1444 ((color_list->GetSize() != 4) ||
1447 // For RGBA, the fourth item must be a real or int alpha value 1445 // For RGBA, the fourth item must be a real or int alpha value
1448 (!color_list->GetReal(3, &alpha) && 1446 (!color_list->GetReal(3, &alpha) &&
1449 !color_list->GetInteger(3, &alpha_int)))) || 1447 !color_list->GetInteger(3, &alpha_int)))) ||
1450 // For both RGB and RGBA, the first three items must be ints (R,G,B) 1448 // For both RGB and RGBA, the first three items must be ints (R,G,B)
1451 !color_list->GetInteger(0, &color) || 1449 !color_list->GetInteger(0, &color) ||
1452 !color_list->GetInteger(1, &color) || 1450 !color_list->GetInteger(1, &color) ||
1453 !color_list->GetInteger(2, &color)) { 1451 !color_list->GetInteger(2, &color)) {
1454 *error = errors::kInvalidThemeColors; 1452 *error = errors::kInvalidThemeColors;
1455 return false; 1453 return false;
1456 } 1454 }
1457 } 1455 }
1458 theme_colors_.reset( 1456 theme_colors_.reset(colors_value->DeepCopy());
1459 static_cast<DictionaryValue*>(colors_value->DeepCopy()));
1460 } 1457 }
1461 1458
1462 DictionaryValue* tints_value; 1459 DictionaryValue* tints_value;
1463 if (theme_value->GetDictionary(keys::kThemeTints, &tints_value)) { 1460 if (theme_value->GetDictionary(keys::kThemeTints, &tints_value)) {
1464 // Validate that the tints are all reals. 1461 // Validate that the tints are all reals.
1465 for (DictionaryValue::key_iterator iter = tints_value->begin_keys(); 1462 for (DictionaryValue::key_iterator iter = tints_value->begin_keys();
1466 iter != tints_value->end_keys(); ++iter) { 1463 iter != tints_value->end_keys(); ++iter) {
1467 ListValue* tint_list; 1464 ListValue* tint_list;
1468 double v; 1465 double v;
1469 int vi; 1466 int vi;
1470 if (!tints_value->GetListWithoutPathExpansion(*iter, &tint_list) || 1467 if (!tints_value->GetListWithoutPathExpansion(*iter, &tint_list) ||
1471 tint_list->GetSize() != 3 || 1468 tint_list->GetSize() != 3 ||
1472 !(tint_list->GetReal(0, &v) || tint_list->GetInteger(0, &vi)) || 1469 !(tint_list->GetReal(0, &v) || tint_list->GetInteger(0, &vi)) ||
1473 !(tint_list->GetReal(1, &v) || tint_list->GetInteger(1, &vi)) || 1470 !(tint_list->GetReal(1, &v) || tint_list->GetInteger(1, &vi)) ||
1474 !(tint_list->GetReal(2, &v) || tint_list->GetInteger(2, &vi))) { 1471 !(tint_list->GetReal(2, &v) || tint_list->GetInteger(2, &vi))) {
1475 *error = errors::kInvalidThemeTints; 1472 *error = errors::kInvalidThemeTints;
1476 return false; 1473 return false;
1477 } 1474 }
1478 } 1475 }
1479 theme_tints_.reset( 1476 theme_tints_.reset(tints_value->DeepCopy());
1480 static_cast<DictionaryValue*>(tints_value->DeepCopy()));
1481 } 1477 }
1482 1478
1483 DictionaryValue* display_properties_value; 1479 DictionaryValue* display_properties_value;
1484 if (theme_value->GetDictionary(keys::kThemeDisplayProperties, 1480 if (theme_value->GetDictionary(keys::kThemeDisplayProperties,
1485 &display_properties_value)) { 1481 &display_properties_value)) {
1486 theme_display_properties_.reset( 1482 theme_display_properties_.reset(
1487 static_cast<DictionaryValue*>(display_properties_value->DeepCopy())); 1483 display_properties_value->DeepCopy());
1488 } 1484 }
1489 1485
1490 return true; 1486 return true;
1491 } 1487 }
1492 1488
1493 // Initialize plugins (optional). 1489 // Initialize plugins (optional).
1494 if (source.HasKey(keys::kPlugins)) { 1490 if (source.HasKey(keys::kPlugins)) {
1495 ListValue* list_value; 1491 ListValue* list_value;
1496 if (!source.GetList(keys::kPlugins, &list_value)) { 1492 if (!source.GetList(keys::kPlugins, &list_value)) {
1497 *error = errors::kInvalidPlugins; 1493 *error = errors::kInvalidPlugins;
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
2289 } 2285 }
2290 2286
2291 ExtensionInfo::ExtensionInfo(const DictionaryValue* manifest, 2287 ExtensionInfo::ExtensionInfo(const DictionaryValue* manifest,
2292 const std::string& id, 2288 const std::string& id,
2293 const FilePath& path, 2289 const FilePath& path,
2294 Extension::Location location) 2290 Extension::Location location)
2295 : extension_id(id), 2291 : extension_id(id),
2296 extension_path(path), 2292 extension_path(path),
2297 extension_location(location) { 2293 extension_location(location) {
2298 if (manifest) 2294 if (manifest)
2299 extension_manifest.reset( 2295 extension_manifest.reset(manifest->DeepCopy());
2300 static_cast<DictionaryValue*>(manifest->DeepCopy()));
2301 } 2296 }
2302 2297
2303 ExtensionInfo::~ExtensionInfo() {} 2298 ExtensionInfo::~ExtensionInfo() {}
2304 2299
2305 UninstalledExtensionInfo::UninstalledExtensionInfo( 2300 UninstalledExtensionInfo::UninstalledExtensionInfo(
2306 const Extension& extension) 2301 const Extension& extension)
2307 : extension_id(extension.id()), 2302 : extension_id(extension.id()),
2308 extension_api_permissions(extension.api_permissions()), 2303 extension_api_permissions(extension.api_permissions()),
2309 extension_type(extension.GetType()), 2304 extension_type(extension.GetType()),
2310 update_url(extension.update_url()) {} 2305 update_url(extension.update_url()) {}
2311 2306
2312 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} 2307 UninstalledExtensionInfo::~UninstalledExtensionInfo() {}
2313 2308
2314 2309
2315 UnloadedExtensionInfo::UnloadedExtensionInfo( 2310 UnloadedExtensionInfo::UnloadedExtensionInfo(
2316 const Extension* extension, 2311 const Extension* extension,
2317 Reason reason) 2312 Reason reason)
2318 : reason(reason), 2313 : reason(reason),
2319 already_disabled(false), 2314 already_disabled(false),
2320 extension(extension) {} 2315 extension(extension) {}
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/preference_model_associator.cc ('k') | chrome/common/extensions/extension_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698