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

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: rebase 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
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
2364 InstallWarning(InstallWarning::FORMAT_TEXT, 2365 InstallWarning(InstallWarning::FORMAT_TEXT,
2365 errors::kScriptBadgeTitleIgnored)); 2366 errors::kScriptBadgeTitleIgnored));
2366 } 2367 }
2367 script_badge_->SetTitle(ExtensionAction::kDefaultTabId, name()); 2368 script_badge_->SetTitle(ExtensionAction::kDefaultTabId, name());
2368 2369
2369 if (!script_badge_->default_icon_path().empty()) { 2370 if (!script_badge_->default_icon_path().empty()) {
2370 install_warnings_.push_back( 2371 install_warnings_.push_back(
2371 InstallWarning(InstallWarning::FORMAT_TEXT, 2372 InstallWarning(InstallWarning::FORMAT_TEXT,
2372 errors::kScriptBadgeIconIgnored)); 2373 errors::kScriptBadgeIconIgnored));
2373 } 2374 }
2374 std::string icon16_path = icons().Get(ExtensionIconSet::EXTENSION_ICON_BITTY, 2375 std::string icon16_path = icons().Get(extension_misc::EXTENSION_ICON_BITTY,
2375 ExtensionIconSet::MATCH_EXACTLY); 2376 ExtensionIconSet::MATCH_EXACTLY);
2376 if (!icon16_path.empty()) { 2377 if (!icon16_path.empty()) {
2377 script_badge_->set_default_icon_path(icon16_path); 2378 script_badge_->set_default_icon_path(icon16_path);
2378 } else { 2379 } else {
2379 script_badge_->SetIcon( 2380 script_badge_->SetIcon(
2380 ExtensionAction::kDefaultTabId, 2381 ExtensionAction::kDefaultTabId,
2381 ui::ResourceBundle::GetSharedInstance().GetImageNamed( 2382 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
2382 IDR_EXTENSIONS_FAVICON)); 2383 IDR_EXTENSIONS_FAVICON));
2383 } 2384 }
2384 2385
(...skipping 622 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 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
3925 3926
3926 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3927 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3927 const Extension* extension, 3928 const Extension* extension,
3928 const PermissionSet* permissions, 3929 const PermissionSet* permissions,
3929 Reason reason) 3930 Reason reason)
3930 : reason(reason), 3931 : reason(reason),
3931 extension(extension), 3932 extension(extension),
3932 permissions(permissions) {} 3933 permissions(permissions) {}
3933 3934
3934 } // namespace extensions 3935 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698