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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_MANAGER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_MANAGER_H_
12 #include "base/basictypes.h"
13 #include "base/memory/weak_ptr.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "ui/gfx/geometry/insets.h"
21 namespace extensions
{
29 class ExtensionIconManager
{
31 ExtensionIconManager();
32 virtual ~ExtensionIconManager();
34 // Start loading the icon for the given extension.
35 void LoadIcon(content::BrowserContext
* context
,
36 const extensions::Extension
* extension
);
38 // This returns a bitmap of width/height kFaviconSize, loaded either from an
39 // entry specified in the extension's 'icon' section of the manifest, or a
40 // default extension icon.
41 const SkBitmap
& GetIcon(const std::string
& extension_id
);
43 // Removes the extension's icon from memory.
44 void RemoveIcon(const std::string
& extension_id
);
46 void set_monochrome(bool value
) { monochrome_
= value
; }
47 void set_padding(const gfx::Insets
& value
) { padding_
= value
; }
50 virtual void OnImageLoaded(const std::string
& extension_id
,
51 const gfx::Image
& image
);
54 // Makes sure we've done one-time initialization of the default extension icon
56 void EnsureDefaultIcon();
58 // Helper function to return a copy of |src| with the proper scaling and
60 SkBitmap
ApplyTransforms(const SkBitmap
& src
);
62 // Maps extension id to an SkBitmap with the icon for that extension.
63 std::map
<std::string
, SkBitmap
> icons_
;
65 // Set of extension IDs waiting for icons to load.
66 std::set
<std::string
> pending_icons_
;
68 // The default icon we'll use if an extension doesn't have one.
69 SkBitmap default_icon_
;
71 // If true, we will desaturate the icons to make them monochromatic.
74 // Specifies the amount of empty padding to place around the icon.
77 base::WeakPtrFactory
<ExtensionIconManager
> weak_ptr_factory_
;
79 DISALLOW_COPY_AND_ASSIGN(ExtensionIconManager
);
82 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_MANAGER_H_