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