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