Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/browser/extensions/extension_icon_manager.h" | 5 #include "chrome/browser/extensions/extension_icon_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "extensions/browser/image_loader.h" | 10 #include "extensions/browser/image_loader.h" |
| 11 #include "extensions/common/constants.h" | 11 #include "extensions/common/constants.h" |
| 12 #include "extensions/common/extension.h" | 12 #include "extensions/common/extension.h" |
| 13 #include "extensions/common/extension_icon_set.h" | 13 #include "extensions/common/extension_icon_set.h" |
| 14 #include "extensions/common/extension_resource.h" | 14 #include "extensions/common/extension_resource.h" |
| 15 #include "extensions/common/manifest_handlers/icons_handler.h" | 15 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 17 #include "skia/ext/image_operations.h" | 17 #include "skia/ext/image_operations.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
| 20 #include "ui/gfx/color_utils.h" | 20 #include "ui/gfx/color_utils.h" |
| 21 #include "ui/gfx/favicon_size.h" | 21 #include "ui/gfx/favicon_size.h" |
| 22 #include "ui/gfx/geometry/size.h" | 22 #include "ui/gfx/geometry/size.h" |
| 23 #include "ui/gfx/image/image.h" | 23 #include "ui/gfx/image/image.h" |
| 24 #include "ui/gfx/paint_vector_icon.h" | |
| 24 #include "ui/gfx/skbitmap_operations.h" | 25 #include "ui/gfx/skbitmap_operations.h" |
| 26 #include "ui/gfx/vector_icons_public2.h" | |
| 27 #include "ui/native_theme/common_theme.h" | |
| 28 #include "ui/native_theme/native_theme.h" | |
| 25 | 29 |
| 26 namespace { | 30 namespace { |
| 27 | 31 |
| 28 // Helper function to create a new bitmap with |padding| amount of empty space | 32 // Helper function to create a new bitmap with |padding| amount of empty space |
| 29 // around the original bitmap. | 33 // around the original bitmap. |
| 30 static SkBitmap ApplyPadding(const SkBitmap& source, | 34 static SkBitmap ApplyPadding(const SkBitmap& source, |
| 31 const gfx::Insets& padding) { | 35 const gfx::Insets& padding) { |
| 32 scoped_ptr<gfx::Canvas> result( | 36 scoped_ptr<gfx::Canvas> result( |
| 33 new gfx::Canvas(gfx::Size(source.width() + padding.width(), | 37 new gfx::Canvas(gfx::Size(source.width() + padding.width(), |
| 34 source.height() + padding.height()), | 38 source.height() + padding.height()), |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 // do nothing. | 105 // do nothing. |
| 102 if (!ContainsKey(pending_icons_, extension_id)) | 106 if (!ContainsKey(pending_icons_, extension_id)) |
| 103 return; | 107 return; |
| 104 | 108 |
| 105 pending_icons_.erase(extension_id); | 109 pending_icons_.erase(extension_id); |
| 106 icons_[extension_id] = ApplyTransforms(*image.ToSkBitmap()); | 110 icons_[extension_id] = ApplyTransforms(*image.ToSkBitmap()); |
| 107 } | 111 } |
| 108 | 112 |
| 109 void ExtensionIconManager::EnsureDefaultIcon() { | 113 void ExtensionIconManager::EnsureDefaultIcon() { |
| 110 if (default_icon_.empty()) { | 114 if (default_icon_.empty()) { |
| 111 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 115 SkColor icon_color; |
| 112 SkBitmap src = rb.GetImageNamed(IDR_EXTENSIONS_SECTION).AsBitmap(); | 116 ui::CommonThemeGetSystemColor(ui::NativeTheme::kColorId_ChromeIconGrey, |
| 113 default_icon_ = ApplyTransforms(src); | 117 &icon_color); |
| 118 // TODO(estade): use correct scale factor instead of 1x. | |
|
Evan Stade
2015/07/27 23:34:21
(note this didn't work correctly before this CL ei
| |
| 119 default_icon_ = | |
| 120 ApplyPadding(*gfx::CreateVectorIcon(gfx::VectorIconId::EXTENSION, | |
| 121 gfx::kFaviconSize, icon_color) | |
| 122 .bitmap(), | |
| 123 padding_); | |
| 114 } | 124 } |
| 115 } | 125 } |
| 116 | 126 |
| 117 SkBitmap ExtensionIconManager::ApplyTransforms(const SkBitmap& source) { | 127 SkBitmap ExtensionIconManager::ApplyTransforms(const SkBitmap& source) { |
| 118 SkBitmap result = source; | 128 SkBitmap result = source; |
| 119 | 129 |
| 120 if (result.width() != gfx::kFaviconSize || | 130 if (result.width() != gfx::kFaviconSize || |
| 121 result.height() != gfx::kFaviconSize) { | 131 result.height() != gfx::kFaviconSize) { |
| 122 result = skia::ImageOperations::Resize( | 132 result = skia::ImageOperations::Resize( |
| 123 result, skia::ImageOperations::RESIZE_LANCZOS3, | 133 result, skia::ImageOperations::RESIZE_LANCZOS3, |
| 124 gfx::kFaviconSize, gfx::kFaviconSize); | 134 gfx::kFaviconSize, gfx::kFaviconSize); |
| 125 } | 135 } |
| 126 | 136 |
| 127 if (monochrome_) { | 137 if (monochrome_) { |
| 128 color_utils::HSL shift = {-1, 0, 0.6}; | 138 color_utils::HSL shift = {-1, 0, 0.6}; |
| 129 result = SkBitmapOperations::CreateHSLShiftedBitmap(result, shift); | 139 result = SkBitmapOperations::CreateHSLShiftedBitmap(result, shift); |
| 130 } | 140 } |
| 131 | 141 |
| 132 if (!padding_.empty()) | 142 if (!padding_.empty()) |
| 133 result = ApplyPadding(result, padding_); | 143 result = ApplyPadding(result, padding_); |
| 134 | 144 |
| 135 return result; | 145 return result; |
| 136 } | 146 } |
| OLD | NEW |