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_action.h" | 5 #include "chrome/browser/extensions/extension_action.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "ui/gfx/geometry/size.h" | 31 #include "ui/gfx/geometry/size.h" |
32 #include "ui/gfx/image/image.h" | 32 #include "ui/gfx/image/image.h" |
33 #include "ui/gfx/image/image_skia.h" | 33 #include "ui/gfx/image/image_skia.h" |
34 #include "ui/gfx/image/image_skia_source.h" | 34 #include "ui/gfx/image/image_skia_source.h" |
35 #include "ui/gfx/ipc/skia/gfx_skia_param_traits.h" | 35 #include "ui/gfx/ipc/skia/gfx_skia_param_traits.h" |
36 #include "ui/gfx/skbitmap_operations.h" | 36 #include "ui/gfx/skbitmap_operations.h" |
37 #include "url/gurl.h" | 37 #include "url/gurl.h" |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 // Returns the default icon image for extensions. | |
42 gfx::Image GetDefaultIcon() { | |
43 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
44 IDR_EXTENSIONS_FAVICON); | |
45 } | |
46 | |
47 class GetAttentionImageSource : public gfx::ImageSkiaSource { | 41 class GetAttentionImageSource : public gfx::ImageSkiaSource { |
48 public: | 42 public: |
49 explicit GetAttentionImageSource(const gfx::ImageSkia& icon) | 43 explicit GetAttentionImageSource(const gfx::ImageSkia& icon) |
50 : icon_(icon) {} | 44 : icon_(icon) {} |
51 | 45 |
52 // gfx::ImageSkiaSource overrides: | 46 // gfx::ImageSkiaSource overrides: |
53 gfx::ImageSkiaRep GetImageForScale(float scale) override { | 47 gfx::ImageSkiaRep GetImageForScale(float scale) override { |
54 gfx::ImageSkiaRep icon_rep = icon_.GetRepresentation(scale); | 48 gfx::ImageSkiaRep icon_rep = icon_.GetRepresentation(scale); |
55 color_utils::HSL shift = {-1, 0, 0.5}; | 49 color_utils::HSL shift = {-1, 0, 0.5}; |
56 return gfx::ImageSkiaRep( | 50 return gfx::ImageSkiaRep( |
(...skipping 13 matching lines...) Expand all Loading... |
70 ui::ScaleFactor scale; | 64 ui::ScaleFactor scale; |
71 }; | 65 }; |
72 | 66 |
73 template <class T> | 67 template <class T> |
74 bool HasValue(const std::map<int, T>& map, int tab_id) { | 68 bool HasValue(const std::map<int, T>& map, int tab_id) { |
75 return map.find(tab_id) != map.end(); | 69 return map.find(tab_id) != map.end(); |
76 } | 70 } |
77 | 71 |
78 } // namespace | 72 } // namespace |
79 | 73 |
| 74 // static |
80 extension_misc::ExtensionIcons ExtensionAction::ActionIconSize() { | 75 extension_misc::ExtensionIcons ExtensionAction::ActionIconSize() { |
81 return extension_misc::EXTENSION_ICON_BITTY; | 76 return extension_misc::EXTENSION_ICON_BITTY; |
82 } | 77 } |
83 | 78 |
| 79 // static |
| 80 gfx::Image ExtensionAction::DefaultIcon() { |
| 81 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 82 IDR_EXTENSIONS_FAVICON); |
| 83 } |
| 84 |
84 const int ExtensionAction::kDefaultTabId = -1; | 85 const int ExtensionAction::kDefaultTabId = -1; |
85 | 86 |
86 ExtensionAction::ExtensionAction(const extensions::Extension& extension, | 87 ExtensionAction::ExtensionAction(const extensions::Extension& extension, |
87 extensions::ActionInfo::Type action_type, | 88 extensions::ActionInfo::Type action_type, |
88 const extensions::ActionInfo& manifest_data) | 89 const extensions::ActionInfo& manifest_data) |
89 : extension_id_(extension.id()), | 90 : extension_id_(extension.id()), |
90 extension_name_(extension.name()), | 91 extension_name_(extension.name()), |
91 action_type_(action_type) { | 92 action_type_(action_type) { |
92 // Page/script actions are hidden/disabled by default, and browser actions are | 93 // Page/script actions are hidden/disabled by default, and browser actions are |
93 // visible/enabled by default. | 94 // visible/enabled by default. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 badge_text_.erase(tab_id); | 218 badge_text_.erase(tab_id); |
218 badge_text_color_.erase(tab_id); | 219 badge_text_color_.erase(tab_id); |
219 badge_background_color_.erase(tab_id); | 220 badge_background_color_.erase(tab_id); |
220 is_visible_.erase(tab_id); | 221 is_visible_.erase(tab_id); |
221 // TODO(jyasskin): Erase the element from declarative_show_count_ | 222 // TODO(jyasskin): Erase the element from declarative_show_count_ |
222 // when the tab's closed. There's a race between the | 223 // when the tab's closed. There's a race between the |
223 // LocationBarController and the ContentRulesRegistry on navigation, | 224 // LocationBarController and the ContentRulesRegistry on navigation, |
224 // which prevents me from cleaning everything up now. | 225 // which prevents me from cleaning everything up now. |
225 } | 226 } |
226 | 227 |
227 extensions::IconImage* ExtensionAction::LoadDefaultIconImage( | 228 void ExtensionAction::SetDefaultIconImage( |
228 const extensions::Extension& extension, | 229 std::unique_ptr<extensions::IconImage> icon_image) { |
229 content::BrowserContext* browser_context) { | 230 default_icon_image_ = std::move(icon_image); |
230 if (default_icon_ && !default_icon_image_) { | |
231 default_icon_image_.reset(new extensions::IconImage( | |
232 browser_context, &extension, *default_icon(), ActionIconSize(), | |
233 *GetDefaultIcon().ToImageSkia(), nullptr)); | |
234 } | |
235 return default_icon_image_.get(); | |
236 } | 231 } |
237 | 232 |
238 gfx::Image ExtensionAction::GetDefaultIconImage() const { | 233 gfx::Image ExtensionAction::GetDefaultIconImage() const { |
239 // If we have a default icon, it should be loaded before trying to use it. | 234 // If we have a default icon, it should be loaded before trying to use it. |
240 DCHECK(!default_icon_image_ == !default_icon_); | 235 DCHECK(!default_icon_image_ == !default_icon_); |
241 if (default_icon_image_) | 236 if (default_icon_image_) |
242 return default_icon_image_->image(); | 237 return default_icon_image_->image(); |
243 | 238 |
244 if (placeholder_icon_image_.IsEmpty()) { | 239 if (placeholder_icon_image_.IsEmpty()) { |
245 // If the extension action redesign is enabled, we use a special placeholder | 240 // If the extension action redesign is enabled, we use a special placeholder |
246 // icon (with the first letter of the extension name) rather than the | 241 // icon (with the first letter of the extension name) rather than the |
247 // default (puzzle piece). | 242 // default (puzzle piece). |
248 if (extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) { | 243 if (extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) { |
249 placeholder_icon_image_ = | 244 placeholder_icon_image_ = |
250 extensions::ExtensionIconPlaceholder::CreateImage(ActionIconSize(), | 245 extensions::ExtensionIconPlaceholder::CreateImage(ActionIconSize(), |
251 extension_name_); | 246 extension_name_); |
252 } else { | 247 } else { |
253 placeholder_icon_image_ = GetDefaultIcon(); | 248 placeholder_icon_image_ = DefaultIcon(); |
254 } | 249 } |
255 } | 250 } |
256 | 251 |
257 return placeholder_icon_image_; | 252 return placeholder_icon_image_; |
258 } | 253 } |
259 | 254 |
260 bool ExtensionAction::HasPopupUrl(int tab_id) const { | 255 bool ExtensionAction::HasPopupUrl(int tab_id) const { |
261 return HasValue(popup_url_, tab_id); | 256 return HasValue(popup_url_, tab_id); |
262 } | 257 } |
263 | 258 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 // If there is a default icon, the icon width will be set depending on our | 316 // If there is a default icon, the icon width will be set depending on our |
322 // action type. | 317 // action type. |
323 if (default_icon_) | 318 if (default_icon_) |
324 return ActionIconSize(); | 319 return ActionIconSize(); |
325 | 320 |
326 // If no icon has been set and there is no default icon, we need favicon | 321 // If no icon has been set and there is no default icon, we need favicon |
327 // width. | 322 // width. |
328 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 323 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
329 IDR_EXTENSIONS_FAVICON).Width(); | 324 IDR_EXTENSIONS_FAVICON).Width(); |
330 } | 325 } |
OLD | NEW |