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_icon_factory.h" | 5 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
6 | 6 |
7 #include "chrome/browser/extensions/extension_action.h" | 7 #include "chrome/browser/extensions/extension_action.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "ui/gfx/image/image.h" | 9 #include "ui/gfx/image/image.h" |
10 #include "ui/gfx/image/image_skia.h" | 10 #include "ui/gfx/image/image_skia.h" |
11 | 11 |
12 using extensions::Extension; | 12 using extensions::Extension; |
13 using extensions::IconImage; | 13 using extensions::IconImage; |
14 | 14 |
15 ExtensionActionIconFactory::ExtensionActionIconFactory( | 15 ExtensionActionIconFactory::ExtensionActionIconFactory( |
16 Profile* profile, | 16 Profile* profile, |
17 const Extension* extension, | 17 const Extension* extension, |
18 ExtensionAction* action, | 18 ExtensionAction* action, |
19 Observer* observer) | 19 Observer* observer) |
20 : action_(action), observer_(observer), icon_image_observer_(this) { | 20 : action_(action), observer_(observer), icon_image_observer_(this) { |
21 extensions::IconImage* default_icon_image = | 21 if (action->default_icon_image()) |
22 action->LoadDefaultIconImage(*extension, profile); | 22 icon_image_observer_.Add(action->default_icon_image()); |
23 if (default_icon_image) | |
24 icon_image_observer_.Add(default_icon_image); | |
25 } | 23 } |
26 | 24 |
27 ExtensionActionIconFactory::~ExtensionActionIconFactory() {} | 25 ExtensionActionIconFactory::~ExtensionActionIconFactory() {} |
28 | 26 |
29 // extensions::IconImage::Observer overrides. | 27 // extensions::IconImage::Observer overrides. |
30 void ExtensionActionIconFactory::OnExtensionIconImageChanged(IconImage* image) { | 28 void ExtensionActionIconFactory::OnExtensionIconImageChanged(IconImage* image) { |
31 if (observer_) | 29 if (observer_) |
32 observer_->OnIconUpdated(); | 30 observer_->OnIconUpdated(); |
33 } | 31 } |
34 | 32 |
35 void ExtensionActionIconFactory::OnExtensionIconImageDestroyed( | 33 void ExtensionActionIconFactory::OnExtensionIconImageDestroyed( |
36 IconImage* image) { | 34 IconImage* image) { |
37 icon_image_observer_.RemoveAll(); | 35 icon_image_observer_.RemoveAll(); |
38 } | 36 } |
39 | 37 |
40 gfx::Image ExtensionActionIconFactory::GetIcon(int tab_id) { | 38 gfx::Image ExtensionActionIconFactory::GetIcon(int tab_id) { |
41 gfx::Image icon = action_->GetExplicitlySetIcon(tab_id); | 39 gfx::Image icon = action_->GetExplicitlySetIcon(tab_id); |
42 if (!icon.IsEmpty()) | 40 if (!icon.IsEmpty()) |
43 return icon; | 41 return icon; |
44 | 42 |
45 icon = action_->GetDeclarativeIcon(tab_id); | 43 icon = action_->GetDeclarativeIcon(tab_id); |
46 if (!icon.IsEmpty()) | 44 if (!icon.IsEmpty()) |
47 return icon; | 45 return icon; |
48 | 46 |
49 return action_->GetDefaultIconImage(); | 47 return action_->GetDefaultIconImage(); |
50 } | 48 } |
OLD | NEW |