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

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
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "chrome/browser/extensions/image_loading_tracker.h" 12 #include "chrome/browser/extensions/image_loading_tracker.h"
13 #include "chrome/common/extensions/extension_icon_set.h" 13 #include "chrome/common/extensions/extension_icon_set.h"
14 #include "content/public/browser/notification_observer.h" 14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h" 15 #include "content/public/browser/notification_registrar.h"
16 #include "ui/gfx/image/image_skia.h" 16 #include "ui/gfx/image/image_skia.h"
17 17
18 namespace extensions { 18 namespace extensions {
19 class Extension; 19 class Extension;
20 } 20 }
21 21
22 namespace gfx { 22 namespace gfx {
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 /**
Jeffrey Yasskin 2012/09/01 01:10:27 I haven't noticed this style comment elsewhere in
tbarzic 2012/09/04 21:07:09 Done.
29 // icon resource loading, screen scale factor change etc. UI code that uses 29 * A class that provides an ImageSkia for UI code to use. It handles extension
30 // extension icon should host this class and be its observer. ExtensionIconImage 30 * icon resource loading, screen scale factor change etc. UI code that uses
31 // should be outlived by the observer. In painting code, UI code paints with the 31 * extension icon should host this class and be its observer. ExtensionIconImage
32 // ImageSkia provided by this class. If required extension icon resource is not 32 * should be outlived by the observer. In painting code, UI code paints with the
33 // present, this class uses ImageLoadingTracker to load it and call on its 33 * ImageSkia provided by this class. If required extension icon resource is not
34 // observer interface when the resource is loaded. 34 * already present, this class tries to load it and calls its observer interface
35 * when the image get updated. Until the resource is loaded, the UI code will be
36 * provided with blank, transparent image.
37 * If the requesetd resource doesn't exist or can't be loaded and a default icon
Jeffrey Yasskin 2012/09/01 01:10:27 sp: requesetd
tbarzic 2012/09/04 21:07:09 Done.
38 * was supplied in the constructor, icon image will be updated with the default
39 * icon's resource.
40 * The default icon doesn't need to be supplied, but in that case, icon image
41 * representation will be left blank if the resource loading fails.
42 * If default icon is supplied, it is assumed that it contains or can
43 * syncronously create (when |GetRepresentation| is called on it)
44 * representations for all the scale factors supported by the current platform.
45 * Note that |IconImage| is not thread safe.
46 **/
35 class IconImage : public ImageLoadingTracker::Observer, 47 class IconImage : public ImageLoadingTracker::Observer,
36 public content::NotificationObserver { 48 public content::NotificationObserver {
37 public: 49 public:
38 class Observer { 50 class Observer {
39 public: 51 public:
40 // Invoked when a new image rep for an additional scale factor 52 // Invoked when a new image rep for an additional scale factor
41 // is loaded and added to |image|. 53 // is loaded and added to |image|.
42 virtual void OnExtensionIconImageChanged(IconImage* image) = 0; 54 virtual void OnExtensionIconImageChanged(IconImage* image) = 0;
43 55
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: 56 protected:
49 virtual ~Observer() {} 57 virtual ~Observer() {}
50 }; 58 };
51 59
52 IconImage(const Extension* extension, 60 IconImage(const Extension* extension,
53 const ExtensionIconSet& icon_set, 61 const ExtensionIconSet& icon_set,
54 int resource_size_in_dip, 62 int resource_size_in_dip,
63 const gfx::ImageSkia& default_icon,
55 Observer* observer); 64 Observer* observer);
56 virtual ~IconImage(); 65 virtual ~IconImage();
57 66
58 const gfx::ImageSkia& image_skia() const { return image_skia_; } 67 const gfx::ImageSkia& image_skia() const { return image_skia_; }
59 68
60 private: 69 private:
61 class Source; 70 class Source;
62 71
63 typedef std::map<int, ui::ScaleFactor> LoadMap; 72 struct LoadRequest {
73 ui::ScaleFactor scale_factor;
74 bool is_async;
75 };
64 76
65 // Loads bitmap for additional scale factor. 77 typedef std::map<int, LoadRequest> LoadMap;
66 void LoadImageForScaleFactor(ui::ScaleFactor scale_factor); 78
79 // Loads a image representation for the scale factor.
80 // If the representation gets loaded syncronously, it is returned by this
Jeffrey Yasskin 2012/09/01 01:10:27 sp: syncronously
tbarzic 2012/09/04 21:07:09 Done.
81 // method.
82 // If representation loading is asynchronous, an empty image
83 // representation is returned. When the representation gets loaded the
84 // observer's |OnExtensionIconImageLoaded| will be called.
85 gfx::ImageSkiaRep LoadImageForScaleFactor(ui::ScaleFactor scale_factor);
67 86
68 // ImageLoadingTracker::Observer overrides: 87 // ImageLoadingTracker::Observer overrides:
69 virtual void OnImageLoaded(const gfx::Image& image, 88 virtual void OnImageLoaded(const gfx::Image& image,
70 const std::string& extension_id, 89 const std::string& extension_id,
71 int index) OVERRIDE; 90 int index) OVERRIDE;
72 91
73 // content::NotificationObserver overrides: 92 // content::NotificationObserver overrides:
74 virtual void Observe(int type, 93 virtual void Observe(int type,
75 const content::NotificationSource& source, 94 const content::NotificationSource& source,
76 const content::NotificationDetails& details) OVERRIDE; 95 const content::NotificationDetails& details) OVERRIDE;
77 96
78 const Extension* extension_; 97 const Extension* extension_;
79 const ExtensionIconSet& icon_set_; 98 const ExtensionIconSet& icon_set_;
80 const int resource_size_in_dip_; 99 const int resource_size_in_dip_;
81 const gfx::Size desired_size_in_dip_;
82 100
83 Observer* observer_; 101 Observer* observer_;
84 102
85 Source* source_; // Owned by ImageSkia storage. 103 Source* source_; // Owned by ImageSkia storage.
86 gfx::ImageSkia image_skia_; 104 gfx::ImageSkia image_skia_;
105 // The icon with whose representation |image_skia_| should be updated if
106 // its own representation load fails.
107 gfx::ImageSkia default_icon_;
87 108
88 ImageLoadingTracker tracker_; 109 ImageLoadingTracker tracker_;
89 content::NotificationRegistrar registrar_; 110 content::NotificationRegistrar registrar_;
90 111
91 LoadMap load_map_; 112 LoadMap load_map_;
92 113
93 DISALLOW_COPY_AND_ASSIGN(IconImage); 114 DISALLOW_COPY_AND_ASSIGN(IconImage);
94 }; 115 };
95 116
96 } // namespace extensions 117 } // namespace extensions
97 118
98 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_IMAGE_H_ 119 #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