Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: chrome/browser/extensions/extension_icon_image.h

Issue 10861034: Supply default icon to extension icon image. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: .. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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_IMAGE_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_IMAGE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_IMAGE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_IMAGE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
(...skipping 12 matching lines...) Expand all
23 class Size; 23 class Size;
24 } 24 }
25 25
26 namespace extensions { 26 namespace extensions {
27 27
28 // A class that provides an ImageSkia for UI code to use. It handles extension 28 // A class that provides an ImageSkia for UI code to use. It handles extension
29 // icon resource loading, screen scale factor change etc. UI code that uses 29 // icon resource loading, screen scale factor change etc. UI code that uses
30 // extension icon should host this class and be its observer. ExtensionIconImage 30 // extension icon should host this class and be its observer. ExtensionIconImage
31 // should be outlived by the observer. In painting code, UI code paints with the 31 // should be outlived by the observer. In painting code, UI code paints with the
32 // ImageSkia provided by this class. If required extension icon resource is not 32 // ImageSkia provided by this class. If required extension icon resource is not
33 // present, this class uses ImageLoadingTracker to load it and call on its 33 // already present, this class tries to load it and calls its observer interface
34 // observer interface when the resource is loaded. 34 // when the image get updated. Until the resource is loaded, the UI code will be
35 // provided with blank, transparent image.
36 // If the requeseted resource doesn't exist or can't be loaded and a default
Jeffrey Yasskin 2012/09/05 23:14:49 "requeseted" is still misspelled, along with some
tbarzic 2012/09/06 00:39:53 yep, I usually go through the comments once more b
37 // icon was supplied in the constructor, icon image will be updated with the
38 // default icon's resource.
39 // The default icon doesn't need to be supplied, but in that case, icon image
40 // representation will be left blank if the resource loading fails.
41 // If default icon is supplied, it is assumed that it contains or can
42 // syncronously create (when |GetRepresentation| is called on it)
43 // representations for all the scale factors supported by the current platform.
44 // Note that |IconImage| is not thread safe.
35 class IconImage : public ImageLoadingTracker::Observer, 45 class IconImage : public ImageLoadingTracker::Observer,
36 public content::NotificationObserver { 46 public content::NotificationObserver {
37 public: 47 public:
38 class Observer { 48 class Observer {
39 public: 49 public:
40 // Invoked when a new image rep for an additional scale factor 50 // Invoked when a new image rep for an additional scale factor
41 // is loaded and added to |image|. 51 // is loaded and added to |image|.
42 virtual void OnExtensionIconImageChanged(IconImage* image) = 0; 52 virtual void OnExtensionIconImageChanged(IconImage* image) = 0;
43 53
44 // Invoked when the icon image couldn't be loaded.
45 virtual void OnIconImageLoadFailed(IconImage* image,
46 ui::ScaleFactor scale_factor) = 0;
47
48 protected: 54 protected:
49 virtual ~Observer() {} 55 virtual ~Observer() {}
50 }; 56 };
51 57
52 IconImage(const Extension* extension, 58 IconImage(const Extension* extension,
53 const ExtensionIconSet& icon_set, 59 const ExtensionIconSet& icon_set,
54 int resource_size_in_dip, 60 int resource_size_in_dip,
61 const gfx::ImageSkia& default_icon,
55 Observer* observer); 62 Observer* observer);
56 virtual ~IconImage(); 63 virtual ~IconImage();
57 64
58 const gfx::ImageSkia& image_skia() const { return image_skia_; } 65 const gfx::ImageSkia& image_skia() const { return image_skia_; }
59 66
60 private: 67 private:
61 class Source; 68 class Source;
62 69
63 typedef std::map<int, ui::ScaleFactor> LoadMap; 70 struct LoadRequest {
71 ui::ScaleFactor scale_factor;
72 bool is_async;
73 };
64 74
65 // Loads bitmap for additional scale factor. 75 typedef std::map<int, LoadRequest> LoadMap;
66 void LoadImageForScaleFactor(ui::ScaleFactor scale_factor); 76
77 // Loads a image representation for the scale factor.
78 // If the representation gets loaded synchronously, it is returned by this
79 // method.
80 // If representation loading is asynchronous, an empty image
81 // representation is returned. When the representation gets loaded the
82 // observer's |OnExtensionIconImageLoaded| will be called.
83 gfx::ImageSkiaRep LoadImageForScaleFactor(ui::ScaleFactor scale_factor);
67 84
68 // ImageLoadingTracker::Observer overrides: 85 // ImageLoadingTracker::Observer overrides:
69 virtual void OnImageLoaded(const gfx::Image& image, 86 virtual void OnImageLoaded(const gfx::Image& image,
70 const std::string& extension_id, 87 const std::string& extension_id,
71 int index) OVERRIDE; 88 int index) OVERRIDE;
72 89
73 // content::NotificationObserver overrides: 90 // content::NotificationObserver overrides:
74 virtual void Observe(int type, 91 virtual void Observe(int type,
75 const content::NotificationSource& source, 92 const content::NotificationSource& source,
76 const content::NotificationDetails& details) OVERRIDE; 93 const content::NotificationDetails& details) OVERRIDE;
77 94
78 const Extension* extension_; 95 const Extension* extension_;
79 const ExtensionIconSet& icon_set_; 96 const ExtensionIconSet& icon_set_;
80 const int resource_size_in_dip_; 97 const int resource_size_in_dip_;
81 const gfx::Size desired_size_in_dip_;
82 98
83 Observer* observer_; 99 Observer* observer_;
84 100
85 Source* source_; // Owned by ImageSkia storage. 101 Source* source_; // Owned by ImageSkia storage.
86 gfx::ImageSkia image_skia_; 102 gfx::ImageSkia image_skia_;
103 // The icon with whose representation |image_skia_| should be updated if
104 // its own representation load fails.
105 gfx::ImageSkia default_icon_;
87 106
88 ImageLoadingTracker tracker_; 107 ImageLoadingTracker tracker_;
89 content::NotificationRegistrar registrar_; 108 content::NotificationRegistrar registrar_;
90 109
91 LoadMap load_map_; 110 LoadMap load_map_;
92 111
93 DISALLOW_COPY_AND_ASSIGN(IconImage); 112 DISALLOW_COPY_AND_ASSIGN(IconImage);
94 }; 113 };
95 114
96 } // namespace extensions 115 } // namespace extensions
97 116
98 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_IMAGE_H_ 117 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_IMAGE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_icon_image.cc » ('j') | chrome/browser/extensions/extension_icon_image.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698