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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/scoped_observer.h"
10 #include "extensions/browser/extension_icon_image.h"
12 class ExtensionAction
;
13 class ExtensionIconSet
;
16 namespace extensions
{
20 // Used to get an icon to be used in the UI for an extension action.
21 // If the extension action icon is the default icon defined in the extension's
22 // manifest, it is loaded using extensions::IconImage. This icon can be loaded
23 // asynchronously. The factory observes underlying IconImage and notifies its
24 // own observer when the icon image changes.
25 class ExtensionActionIconFactory
: public extensions::IconImage::Observer
{
29 virtual ~Observer() {}
30 // Called when the underlying icon image changes.
31 virtual void OnIconUpdated() = 0;
34 // Observer should outlive this.
35 ExtensionActionIconFactory(Profile
* profile
,
36 const extensions::Extension
* extension
,
37 ExtensionAction
* action
,
39 ~ExtensionActionIconFactory() override
;
41 // extensions::IconImage override.
42 void OnExtensionIconImageChanged(extensions::IconImage
* image
) override
;
43 void OnExtensionIconImageDestroyed(extensions::IconImage
* image
) override
;
45 // Gets the extension action icon for the tab.
46 // If there is an icon set using |SetIcon|, that icon is returned.
47 // Else, if there is a default icon set for the extension action, the icon is
48 // created using IconImage. Observer is triggered wheniever the icon gets
50 // Else, extension favicon is returned.
51 // In all cases, action's attention and animation icon transformations are
52 // applied on the icon.
53 gfx::Image
GetIcon(int tab_id
);
56 const extensions::Extension
* extension_
;
57 const ExtensionAction
* action_
;
60 ScopedObserver
<extensions::IconImage
, extensions::IconImage::Observer
>
63 DISALLOW_COPY_AND_ASSIGN(ExtensionActionIconFactory
);
66 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_