diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-17 05:55:32 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-17 05:55:32 +0000 |
commit | c690a981436bb6a6d69ab8df959ffa5b116bf356 (patch) | |
tree | dfb4134472778bdb6409679faec3fea2e4946633 /chrome/common/extensions/extension.cc | |
parent | 5d39e314de21a384eaa226d4875b6a6e8e1bea17 (diff) | |
download | chromium_src-c690a981436bb6a6d69ab8df959ffa5b116bf356.zip chromium_src-c690a981436bb6a6d69ab8df959ffa5b116bf356.tar.gz chromium_src-c690a981436bb6a6d69ab8df959ffa5b116bf356.tar.bz2 |
Add the right-click context menu for Browser actions and Page Actions.
BUG=29538
TEST=Right-click an extension icon and make sure all the options work for both
Page and Browser actions (Options should be grayed out when there is no Options
page specified in the manifest).
Review URL: http://codereview.chromium.org/486022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34812 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/extension.cc')
-rw-r--r-- | chrome/common/extensions/extension.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 280ad98..4ed91b58 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -24,6 +24,7 @@ #include "chrome/common/extensions/user_script.h" #include "chrome/common/notification_service.h" #include "chrome/common/url_constants.h" +#include "webkit/glue/image_decoder.h" #if defined(OS_WIN) #include "base/registry.h" @@ -641,6 +642,50 @@ bool Extension::IsPrivilegeIncrease(Extension* old_extension, return false; } +// static +void Extension::DecodeIcon(Extension* extension, + Icons icon_size, + scoped_ptr<SkBitmap>* result) { + FilePath icon_path = extension->GetIconPath(icon_size).GetFilePath(); + DecodeIconFromPath(icon_path, icon_size, result); +} + +// static +void Extension::DecodeIconFromPath(const FilePath& icon_path, + Icons icon_size, + scoped_ptr<SkBitmap>* result) { + if (icon_path.empty()) + return; + + std::string file_contents; + if (!file_util::ReadFileToString(icon_path, &file_contents)) { + LOG(ERROR) << "Could not read icon file: " + << WideToUTF8(icon_path.ToWStringHack()); + return; + } + + // Decode the image using WebKit's image decoder. + const unsigned char* data = + reinterpret_cast<const unsigned char*>(file_contents.data()); + webkit_glue::ImageDecoder decoder; + scoped_ptr<SkBitmap> decoded(new SkBitmap()); + *decoded = decoder.Decode(data, file_contents.length()); + if (decoded->empty()) { + LOG(ERROR) << "Could not decode icon file: " + << WideToUTF8(icon_path.ToWStringHack()); + return; + } + + if (decoded->width() != icon_size || decoded->height() != icon_size) { + LOG(ERROR) << "Icon file has unexpected size: " + << IntToString(decoded->width()) << "x" + << IntToString(decoded->height()); + return; + } + + result->swap(decoded); +} + bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, std::string* error) { if (source.HasKey(keys::kPublicKey)) { |