OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_MANAGER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_MANAGER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "third_party/skia/include/core/SkBitmap.h" | 14 #include "ui/gfx/image/image.h" |
15 #include "ui/gfx/geometry/insets.h" | |
16 | 15 |
17 namespace content { | 16 namespace content { |
18 class BrowserContext; | 17 class BrowserContext; |
19 } | 18 } |
20 | 19 |
21 namespace extensions { | 20 namespace extensions { |
22 class Extension; | 21 class Extension; |
23 } | 22 } |
24 | 23 |
25 namespace gfx { | 24 namespace gfx { |
26 class Image; | 25 class Image; |
27 } | 26 } |
28 | 27 |
29 class ExtensionIconManager { | 28 class ExtensionIconManager { |
30 public: | 29 public: |
31 ExtensionIconManager(); | 30 ExtensionIconManager(); |
32 virtual ~ExtensionIconManager(); | 31 virtual ~ExtensionIconManager(); |
33 | 32 |
34 // Start loading the icon for the given extension. | 33 // Start loading the icon for the given extension. |
35 void LoadIcon(content::BrowserContext* context, | 34 void LoadIcon(content::BrowserContext* context, |
36 const extensions::Extension* extension); | 35 const extensions::Extension* extension); |
37 | 36 |
38 // This returns a bitmap of width/height kFaviconSize, loaded either from an | 37 // This returns an image of width/height kFaviconSize, loaded either from an |
39 // entry specified in the extension's 'icon' section of the manifest, or a | 38 // entry specified in the extension's 'icon' section of the manifest, or a |
40 // default extension icon. | 39 // default extension icon. |
41 const SkBitmap& GetIcon(const std::string& extension_id); | 40 gfx::Image GetIcon(const std::string& extension_id); |
42 | 41 |
43 // Removes the extension's icon from memory. | 42 // Removes the extension's icon from memory. |
44 void RemoveIcon(const std::string& extension_id); | 43 void RemoveIcon(const std::string& extension_id); |
45 | 44 |
46 void set_monochrome(bool value) { monochrome_ = value; } | 45 void set_monochrome(bool value) { monochrome_ = value; } |
47 void set_padding(const gfx::Insets& value) { padding_ = value; } | |
48 | 46 |
49 protected: | 47 protected: |
50 virtual void OnImageLoaded(const std::string& extension_id, | 48 virtual void OnImageLoaded(const std::string& extension_id, |
51 const gfx::Image& image); | 49 const gfx::Image& image); |
52 | 50 |
53 private: | 51 private: |
54 // Makes sure we've done one-time initialization of the default extension icon | 52 // Makes sure we've done one-time initialization of the default extension icon |
55 // default_icon_. | 53 // default_icon_. |
56 void EnsureDefaultIcon(); | 54 void EnsureDefaultIcon(); |
57 | 55 |
58 // Helper function to return a copy of |src| with the proper scaling and | 56 // Maps extension id to the icon for that extension. |
59 // coloring. | 57 std::map<std::string, gfx::Image> icons_; |
60 SkBitmap ApplyTransforms(const SkBitmap& src); | |
61 | |
62 // Maps extension id to an SkBitmap with the icon for that extension. | |
63 std::map<std::string, SkBitmap> icons_; | |
64 | 58 |
65 // Set of extension IDs waiting for icons to load. | 59 // Set of extension IDs waiting for icons to load. |
66 std::set<std::string> pending_icons_; | 60 std::set<std::string> pending_icons_; |
67 | 61 |
68 // The default icon we'll use if an extension doesn't have one. | 62 // The default icon we'll use if an extension doesn't have one. |
69 SkBitmap default_icon_; | 63 gfx::Image default_icon_; |
70 | 64 |
71 // If true, we will desaturate the icons to make them monochromatic. | 65 // If true, we will desaturate the icons to make them monochromatic. |
72 bool monochrome_; | 66 bool monochrome_; |
73 | 67 |
74 // Specifies the amount of empty padding to place around the icon. | |
75 gfx::Insets padding_; | |
76 | |
77 base::WeakPtrFactory<ExtensionIconManager> weak_ptr_factory_; | 68 base::WeakPtrFactory<ExtensionIconManager> weak_ptr_factory_; |
78 | 69 |
79 DISALLOW_COPY_AND_ASSIGN(ExtensionIconManager); | 70 DISALLOW_COPY_AND_ASSIGN(ExtensionIconManager); |
80 }; | 71 }; |
81 | 72 |
82 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_MANAGER_H_ | 73 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_MANAGER_H_ |
OLD | NEW |