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

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: .. 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 < extension_misc::kNumExtensionIconSizes; ++i) {
1425 std::string key = base::IntToString(ExtensionIconSet::kIconSizes[i]); 1425 std::string key =
1426 base::IntToString(extension_misc::kExtensionIconSizes[i]);
1426 if (icons_value->HasKey(key)) { 1427 if (icons_value->HasKey(key)) {
1427 std::string icon_path; 1428 std::string icon_path;
1428 if (!icons_value->GetString(key, &icon_path)) { 1429 if (!icons_value->GetString(key, &icon_path)) {
1429 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( 1430 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1430 errors::kInvalidIconPath, key); 1431 errors::kInvalidIconPath, key);
1431 return false; 1432 return false;
1432 } 1433 }
1433 1434
1434 if (!icon_path.empty() && icon_path[0] == '/') 1435 if (!icon_path.empty() && icon_path[0] == '/')
1435 icon_path = icon_path.substr(1); 1436 icon_path = icon_path.substr(1);
1436 1437
1437 if (icon_path.empty()) { 1438 if (icon_path.empty()) {
1438 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( 1439 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1439 errors::kInvalidIconPath, key); 1440 errors::kInvalidIconPath, key);
1440 return false; 1441 return false;
1441 } 1442 }
1442 icons_.Add(ExtensionIconSet::kIconSizes[i], icon_path); 1443 icons_.Add(extension_misc::kExtensionIconSizes[i], icon_path);
1443 } 1444 }
1444 } 1445 }
1445 return true; 1446 return true;
1446 } 1447 }
1447 1448
1448 bool Extension::LoadCommands(string16* error) { 1449 bool Extension::LoadCommands(string16* error) {
1449 if (manifest_->HasKey(keys::kCommands)) { 1450 if (manifest_->HasKey(keys::kCommands)) {
1450 DictionaryValue* commands = NULL; 1451 DictionaryValue* commands = NULL;
1451 if (!manifest_->GetDictionary(keys::kCommands, &commands)) { 1452 if (!manifest_->GetDictionary(keys::kCommands, &commands)) {
1452 *error = ASCIIToUTF16(errors::kInvalidCommandsKey); 1453 *error = ASCIIToUTF16(errors::kInvalidCommandsKey);
(...skipping 1554 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