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

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

Issue 10843014: Generalize ExtensionIconSet to store icon paths for custom size sets (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits 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/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 1403 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 1414
1415 bool Extension::LoadIcons(string16* error) { 1415 bool Extension::LoadIcons(string16* error) {
1416 if (!manifest_->HasKey(keys::kIcons)) 1416 if (!manifest_->HasKey(keys::kIcons))
1417 return true; 1417 return true;
1418 DictionaryValue* icons_value = NULL; 1418 DictionaryValue* icons_value = NULL;
1419 if (!manifest_->GetDictionary(keys::kIcons, &icons_value)) { 1419 if (!manifest_->GetDictionary(keys::kIcons, &icons_value)) {
1420 *error = ASCIIToUTF16(errors::kInvalidIcons); 1420 *error = ASCIIToUTF16(errors::kInvalidIcons);
1421 return false; 1421 return false;
1422 } 1422 }
1423 1423
1424 for (size_t i = 0; i < ExtensionIconSet::kNumIconSizes; ++i) { 1424 for (size_t i = 0; i < icons_.num_allowed_sizes(); ++i) {
1425 std::string key = base::IntToString(ExtensionIconSet::kIconSizes[i]); 1425 std::string key = base::IntToString(icons_.allowed_sizes()[i]);
1426 if (icons_value->HasKey(key)) { 1426 if (icons_value->HasKey(key)) {
1427 std::string icon_path; 1427 std::string icon_path;
1428 if (!icons_value->GetString(key, &icon_path)) { 1428 if (!icons_value->GetString(key, &icon_path)) {
1429 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( 1429 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1430 errors::kInvalidIconPath, key); 1430 errors::kInvalidIconPath, key);
1431 return false; 1431 return false;
1432 } 1432 }
1433 1433
1434 if (!icon_path.empty() && icon_path[0] == '/') 1434 if (!icon_path.empty() && icon_path[0] == '/')
1435 icon_path = icon_path.substr(1); 1435 icon_path = icon_path.substr(1);
1436 1436
1437 if (icon_path.empty()) { 1437 if (icon_path.empty()) {
1438 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( 1438 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1439 errors::kInvalidIconPath, key); 1439 errors::kInvalidIconPath, key);
1440 return false; 1440 return false;
1441 } 1441 }
1442 icons_.Add(ExtensionIconSet::kIconSizes[i], icon_path); 1442 icons_.Add(icons_.allowed_sizes()[i], icon_path);
1443 } 1443 }
1444 } 1444 }
1445 return true; 1445 return true;
1446 } 1446 }
1447 1447
1448 bool Extension::LoadCommands(string16* error) { 1448 bool Extension::LoadCommands(string16* error) {
1449 if (manifest_->HasKey(keys::kCommands)) { 1449 if (manifest_->HasKey(keys::kCommands)) {
1450 DictionaryValue* commands = NULL; 1450 DictionaryValue* commands = NULL;
1451 if (!manifest_->GetDictionary(keys::kCommands, &commands)) { 1451 if (!manifest_->GetDictionary(keys::kCommands, &commands)) {
1452 *error = ASCIIToUTF16(errors::kInvalidCommandsKey); 1452 *error = ASCIIToUTF16(errors::kInvalidCommandsKey);
(...skipping 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after
2890 bool Extension::IsTrustedId(const std::string& id) { 2890 bool Extension::IsTrustedId(const std::string& id) {
2891 // See http://b/4946060 for more details. 2891 // See http://b/4946060 for more details.
2892 return id == std::string("nckgahadagoaajjgafhacjanaoiihapd"); 2892 return id == std::string("nckgahadagoaajjgafhacjanaoiihapd");
2893 } 2893 }
2894 2894
2895 Extension::Extension(const FilePath& path, 2895 Extension::Extension(const FilePath& path,
2896 scoped_ptr<extensions::Manifest> manifest) 2896 scoped_ptr<extensions::Manifest> manifest)
2897 : manifest_version_(0), 2897 : manifest_version_(0),
2898 incognito_split_mode_(false), 2898 incognito_split_mode_(false),
2899 offline_enabled_(false), 2899 offline_enabled_(false),
2900 icons_(ExtensionIconSet::ICON_SET_MANIFEST_ICONS),
2900 converted_from_user_script_(false), 2901 converted_from_user_script_(false),
2901 background_page_is_persistent_(true), 2902 background_page_is_persistent_(true),
2902 allow_background_js_access_(true), 2903 allow_background_js_access_(true),
2903 manifest_(manifest.release()), 2904 manifest_(manifest.release()),
2904 is_storage_isolated_(false), 2905 is_storage_isolated_(false),
2905 launch_container_(extension_misc::LAUNCH_TAB), 2906 launch_container_(extension_misc::LAUNCH_TAB),
2906 launch_width_(0), 2907 launch_width_(0),
2907 launch_height_(0), 2908 launch_height_(0),
2908 wants_file_access_(false), 2909 wants_file_access_(false),
2909 creation_flags_(0) { 2910 creation_flags_(0) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
3007 output->append(is_public ? kPublic : kPrivate); 3008 output->append(is_public ? kPublic : kPrivate);
3008 output->append(" "); 3009 output->append(" ");
3009 output->append(kKeyInfoEndMarker); 3010 output->append(kKeyInfoEndMarker);
3010 output->append("\n"); 3011 output->append("\n");
3011 3012
3012 return true; 3013 return true;
3013 } 3014 }
3014 3015
3015 // static 3016 // static
3016 void Extension::DecodeIcon(const Extension* extension, 3017 void Extension::DecodeIcon(const Extension* extension,
3017 ExtensionIconSet::Icons preferred_icon_size, 3018 int preferred_icon_size,
3018 ExtensionIconSet::MatchType match_type, 3019 ExtensionIconSet::MatchType match_type,
3019 scoped_ptr<SkBitmap>* result) { 3020 scoped_ptr<SkBitmap>* result) {
3020 std::string path = extension->icons().Get(preferred_icon_size, match_type); 3021 std::string path = extension->icons().Get(preferred_icon_size, match_type);
3021 ExtensionIconSet::Icons size = extension->icons().GetIconSizeFromPath(path); 3022 int size = extension->icons().GetIconSizeFromPath(path);
3022 ExtensionResource icon_resource = extension->GetResource(path); 3023 ExtensionResource icon_resource = extension->GetResource(path);
3023 DecodeIconFromPath(icon_resource.GetFilePath(), size, result); 3024 DecodeIconFromPath(icon_resource.GetFilePath(), size, result);
3024 } 3025 }
3025 3026
3026 // static 3027 // static
3027 void Extension::DecodeIcon(const Extension* extension, 3028 void Extension::DecodeIcon(const Extension* extension,
3028 ExtensionIconSet::Icons icon_size, 3029 int icon_size,
3029 scoped_ptr<SkBitmap>* result) { 3030 scoped_ptr<SkBitmap>* result) {
3030 DecodeIcon(extension, icon_size, ExtensionIconSet::MATCH_EXACTLY, result); 3031 DecodeIcon(extension, icon_size, ExtensionIconSet::MATCH_EXACTLY, result);
3031 } 3032 }
3032 3033
3033 // static 3034 // static
3034 void Extension::DecodeIconFromPath(const FilePath& icon_path, 3035 void Extension::DecodeIconFromPath(const FilePath& icon_path,
3035 ExtensionIconSet::Icons icon_size, 3036 int icon_size,
3036 scoped_ptr<SkBitmap>* result) { 3037 scoped_ptr<SkBitmap>* result) {
3037 if (icon_path.empty()) 3038 if (icon_path.empty())
3038 return; 3039 return;
3039 3040
3040 std::string file_contents; 3041 std::string file_contents;
3041 if (!file_util::ReadFileToString(icon_path, &file_contents)) { 3042 if (!file_util::ReadFileToString(icon_path, &file_contents)) {
3042 DLOG(ERROR) << "Could not read icon file: " << icon_path.LossyDisplayName(); 3043 DLOG(ERROR) << "Could not read icon file: " << icon_path.LossyDisplayName();
3043 return; 3044 return;
3044 } 3045 }
3045 3046
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
3901 3902
3902 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3903 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3903 const Extension* extension, 3904 const Extension* extension,
3904 const PermissionSet* permissions, 3905 const PermissionSet* permissions,
3905 Reason reason) 3906 Reason reason)
3906 : reason(reason), 3907 : reason(reason),
3907 extension(extension), 3908 extension(extension),
3908 permissions(permissions) {} 3909 permissions(permissions) {}
3909 3910
3910 } // namespace extensions 3911 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698