| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/browser/extensions/extension_icon_manager.h" | 5 #include "chrome/browser/extensions/extension_icon_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "chrome/common/extensions/extension.h" | 9 #include "chrome/common/extensions/extension.h" |
| 10 #include "chrome/common/extensions/extension_icon_set.h" | 10 #include "chrome/common/extensions/extension_icon_set.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 void ExtensionIconManager::LoadIcon(const Extension* extension) { | 48 void ExtensionIconManager::LoadIcon(const Extension* extension) { |
| 49 ExtensionResource icon_resource = extension->GetIconResource( | 49 ExtensionResource icon_resource = extension->GetIconResource( |
| 50 Extension::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_BIGGER); | 50 Extension::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_BIGGER); |
| 51 if (!icon_resource.extension_root().empty()) { | 51 if (!icon_resource.extension_root().empty()) { |
| 52 // Insert into pending_icons_ first because LoadImage can call us back | 52 // Insert into pending_icons_ first because LoadImage can call us back |
| 53 // synchronously if the image is already cached. | 53 // synchronously if the image is already cached. |
| 54 pending_icons_.insert(extension->id()); | 54 pending_icons_.insert(extension->id()); |
| 55 image_tracker_.LoadImage(extension, | 55 image_tracker_.LoadImage(extension, |
| 56 icon_resource, | 56 icon_resource, |
| 57 gfx::Size(kFavIconSize, kFavIconSize), | 57 gfx::Size(kFaviconSize, kFaviconSize), |
| 58 ImageLoadingTracker::CACHE); | 58 ImageLoadingTracker::CACHE); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 const SkBitmap& ExtensionIconManager::GetIcon(const std::string& extension_id) { | 62 const SkBitmap& ExtensionIconManager::GetIcon(const std::string& extension_id) { |
| 63 const SkBitmap* result = NULL; | 63 const SkBitmap* result = NULL; |
| 64 if (ContainsKey(icons_, extension_id)) { | 64 if (ContainsKey(icons_, extension_id)) { |
| 65 result = &icons_[extension_id]; | 65 result = &icons_[extension_id]; |
| 66 } else { | 66 } else { |
| 67 EnsureDefaultIcon(); | 67 EnsureDefaultIcon(); |
| 68 result = &default_icon_; | 68 result = &default_icon_; |
| 69 } | 69 } |
| 70 DCHECK(result); | 70 DCHECK(result); |
| 71 DCHECK_EQ(kFavIconSize + padding_.width(), result->width()); | 71 DCHECK_EQ(kFaviconSize + padding_.width(), result->width()); |
| 72 DCHECK_EQ(kFavIconSize + padding_.height(), result->height()); | 72 DCHECK_EQ(kFaviconSize + padding_.height(), result->height()); |
| 73 return *result; | 73 return *result; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void ExtensionIconManager::RemoveIcon(const std::string& extension_id) { | 76 void ExtensionIconManager::RemoveIcon(const std::string& extension_id) { |
| 77 icons_.erase(extension_id); | 77 icons_.erase(extension_id); |
| 78 pending_icons_.erase(extension_id); | 78 pending_icons_.erase(extension_id); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void ExtensionIconManager::OnImageLoaded(SkBitmap* image, | 81 void ExtensionIconManager::OnImageLoaded(SkBitmap* image, |
| 82 const ExtensionResource& resource, | 82 const ExtensionResource& resource, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 99 if (default_icon_.empty()) { | 99 if (default_icon_.empty()) { |
| 100 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 100 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 101 SkBitmap* src = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); | 101 SkBitmap* src = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); |
| 102 default_icon_ = ApplyTransforms(*src); | 102 default_icon_ = ApplyTransforms(*src); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 SkBitmap ExtensionIconManager::ApplyTransforms(const SkBitmap& source) { | 106 SkBitmap ExtensionIconManager::ApplyTransforms(const SkBitmap& source) { |
| 107 SkBitmap result = source; | 107 SkBitmap result = source; |
| 108 | 108 |
| 109 if (result.width() != kFavIconSize || result.height() != kFavIconSize) { | 109 if (result.width() != kFaviconSize || result.height() != kFaviconSize) { |
| 110 result = skia::ImageOperations::Resize( | 110 result = skia::ImageOperations::Resize( |
| 111 result, skia::ImageOperations::RESIZE_LANCZOS3, | 111 result, skia::ImageOperations::RESIZE_LANCZOS3, |
| 112 kFavIconSize, kFavIconSize); | 112 kFaviconSize, kFaviconSize); |
| 113 } | 113 } |
| 114 | 114 |
| 115 if (monochrome_) { | 115 if (monochrome_) { |
| 116 color_utils::HSL shift = {-1, 0, 0.6}; | 116 color_utils::HSL shift = {-1, 0, 0.6}; |
| 117 result = SkBitmapOperations::CreateHSLShiftedBitmap(result, shift); | 117 result = SkBitmapOperations::CreateHSLShiftedBitmap(result, shift); |
| 118 } | 118 } |
| 119 | 119 |
| 120 if (!padding_.empty()) | 120 if (!padding_.empty()) |
| 121 result = ApplyPadding(result, padding_); | 121 result = ApplyPadding(result, padding_); |
| 122 | 122 |
| 123 return result; | 123 return result; |
| 124 } | 124 } |
| OLD | NEW |