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

Unified Diff: chrome/common/extensions/extension.cc

Issue 501136: Merge 34812 - Add the rightclick context menu for Browser actions and Page... (Closed) Base URL: svn://chrome-svn/chrome/branches/249/src/
Patch Set: Created 11 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/extension.cc
===================================================================
--- chrome/common/extensions/extension.cc (revision 35008)
+++ chrome/common/extensions/extension.cc (working copy)
@@ -24,6 +24,7 @@
#include "chrome/common/notification_service.h"
#include "chrome/common/url_constants.h"
#include "net/base/base64.h"
+#include "webkit/glue/image_decoder.h"
#if defined(OS_WIN)
#include "base/registry.h"
@@ -641,6 +642,50 @@
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)) {
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698