Prevent chrome://net-internals/#export from flickering
[chromium-blink-merge.git] / chrome / browser / extensions / extension_action_icon_factory.h
blobb65adabb923acbf5df1eb225c3063d5cc4b91f05
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;
14 class Profile;
16 namespace extensions {
17 class Extension;
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 {
26 public:
27 class Observer {
28 public:
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,
38 Observer* observer);
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
49 // updated.
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);
55 private:
56 const extensions::Extension* extension_;
57 const ExtensionAction* action_;
58 Observer* observer_;
60 ScopedObserver<extensions::IconImage, extensions::IconImage::Observer>
61 icon_image_observer_;
63 DISALLOW_COPY_AND_ASSIGN(ExtensionActionIconFactory);
66 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_