OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/extensions/extension_action_icon_factory.h" | |
6 | |
7 #include "chrome/common/extensions/extension.h" | |
8 #include "chrome/common/extensions/extension_action.h" | |
9 #include "chrome/common/extensions/extension_icon_set.h" | |
10 #include "grit/theme_resources.h" | |
11 #include "ui/base/resource/resource_bundle.h" | |
12 #include "ui/gfx/image/image_skia.h" | |
13 | |
14 using extensions::Extension; | |
15 using extensions::IconImage; | |
16 | |
17 namespace { | |
18 | |
19 int GetIconSizeForType(ExtensionAction::Type type) { | |
20 switch (type) { | |
21 case ExtensionAction::TYPE_BROWSER: | |
22 case ExtensionAction::TYPE_PAGE: | |
23 return extension_misc::EXTENSION_ICON_ACTION; | |
24 case ExtensionAction::TYPE_SCRIPT_BADGE: | |
25 return extension_misc::EXTENSION_ICON_BITTY; | |
26 default: | |
27 NOTREACHED(); | |
28 return 0; | |
29 } | |
30 } | |
31 | |
32 gfx::ImageSkia GetDefaultIcon() { | |
33 return *ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
34 IDR_EXTENSIONS_FAVICON).ToImageSkia(); | |
35 } | |
36 | |
37 } // namespace | |
38 | |
39 ExtensionActionIconFactory::ExtensionActionIconFactory( | |
40 const Extension* extension, Observer* observer) | |
41 : extension_(extension), | |
42 observer_(observer) { | |
43 } | |
44 | |
45 ExtensionActionIconFactory::~ExtensionActionIconFactory() {} | |
46 | |
47 // extensions::IconImage::Observer overrides. | |
48 void ExtensionActionIconFactory::OnExtensionIconImageChanged(IconImage* image) { | |
49 if (observer_) | |
50 observer_->OnIconUpdated(); | |
51 } | |
52 | |
53 gfx::Image ExtensionActionIconFactory::GetIcon( | |
54 const ExtensionAction* action, | |
55 int tab_id) { | |
56 gfx::ImageSkia base_icon = GetBaseIconFromAction(action, tab_id); | |
57 return action->ApplyAttentionAndAnimation(base_icon, tab_id); | |
58 } | |
59 | |
60 gfx::ImageSkia ExtensionActionIconFactory::GetBaseIconFromAction( | |
61 const ExtensionAction* action, | |
62 int tab_id) { | |
63 gfx::ImageSkia icon = action->GetExplicitlySetIcon(tab_id); | |
64 if (!icon.isNull()) | |
65 return icon; | |
66 if (action->default_icon()) { | |
67 // If icon set hasn't changed, return the present icon. | |
Jeffrey Yasskin
2012/09/14 23:47:12
If GetIcon() is called with two different Extensio
tbarzic
2012/09/15 00:29:10
Done.
| |
68 if (icon_.get()) { | |
69 return icon_->image_skia(); | |
70 } | |
71 | |
72 icon_.reset(new IconImage(extension_, | |
Jeffrey Yasskin
2012/09/14 23:47:12
I see a path from the observer callback through Br
tbarzic
2012/09/15 00:29:10
if I get your comment correctly, you're afraid tha
| |
73 *action->default_icon(), | |
74 GetIconSizeForType(action->action_type()), | |
75 GetDefaultIcon(), | |
76 this)); | |
77 return icon_->image_skia(); | |
78 } | |
79 | |
80 return GetDefaultIcon(); | |
81 } | |
82 | |
OLD | NEW |