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

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

Issue 2867008: Show extension icons next to their top-level context menu items.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_resource.h » ('j') | 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 50770)
+++ chrome/common/extensions/extension.cc (working copy)
@@ -760,11 +760,11 @@
#elif defined(OS_WIN)
FilePath relative_file_path(UTF8ToWide(relative_path));
#endif
- return ExtensionResource(path(), relative_file_path);
+ return ExtensionResource(id(), path(), relative_file_path);
}
ExtensionResource Extension::GetResource(const FilePath& relative_file_path) {
- return ExtensionResource(path(), relative_file_path);
+ return ExtensionResource(id(), path(), relative_file_path);
}
// TODO(rafaelw): Move ParsePEMKeyBytes, ProducePEM & FormatPEMForOutput to a
@@ -1584,28 +1584,63 @@
NotificationService::NoDetails());
}
+static std::string SizeToString(const gfx::Size& max_size) {
+ return IntToString(max_size.width()) + "x" + IntToString(max_size.height());
+}
+
void Extension::SetCachedImage(const ExtensionResource& source,
- const SkBitmap& image) {
+ const SkBitmap& image,
+ const gfx::Size& original_size) {
DCHECK(source.extension_root() == path()); // The resource must come from
// this extension.
- image_cache_[source.relative_path()] = image;
+ const FilePath& path = source.relative_path();
+ gfx::Size actual_size(image.width(), image.height());
+ if (actual_size == original_size) {
+ image_cache_[ImageCacheKey(path, std::string())] = image;
+ } else {
+ image_cache_[ImageCacheKey(path, SizeToString(actual_size))] = image;
+ }
}
-bool Extension::HasCachedImage(const ExtensionResource& source) {
+bool Extension::HasCachedImage(const ExtensionResource& source,
+ const gfx::Size& max_size) {
DCHECK(source.extension_root() == path()); // The resource must come from
// this extension.
- return image_cache_.find(source.relative_path()) != image_cache_.end();
+ return GetCachedImageImpl(source, max_size) != NULL;
}
-SkBitmap Extension::GetCachedImage(const ExtensionResource& source) {
+SkBitmap Extension::GetCachedImage(const ExtensionResource& source,
+ const gfx::Size& max_size) {
DCHECK(source.extension_root() == path()); // The resource must come from
// this extension.
- ImageCache::iterator i = image_cache_.find(source.relative_path());
- if (i == image_cache_.end())
- return SkBitmap();
- return i->second;
+ SkBitmap* image = GetCachedImageImpl(source, max_size);
+ return image ? *image : SkBitmap();
}
+SkBitmap* Extension::GetCachedImageImpl(const ExtensionResource& source,
+ const gfx::Size& max_size) {
+ const FilePath& path = source.relative_path();
+
+ // Look for exact size match.
+ ImageCache::iterator i = image_cache_.find(
+ ImageCacheKey(path, SizeToString(max_size)));
+ if (i != image_cache_.end())
+ return &(i->second);
+
+ // If we have the original size version cached, return that if it's small
+ // enough.
+ i = image_cache_.find(ImageCacheKey(path, std::string()));
+ if (i != image_cache_.end()) {
+ SkBitmap& image = i->second;
+ if (image.width() <= max_size.width() &&
+ image.height() <= max_size.height())
+ return &(i->second);
+ }
+
+ return NULL;
+}
+
+
ExtensionResource Extension::GetIconPath(Icons icon) {
std::map<int, std::string>::const_iterator iter = icons_.find(icon);
if (iter == icons_.end())
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698