OLD | NEW |
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_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ |
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ | 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/scoped_vector.h" |
15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
16 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "chrome/common/extensions/extension_icon_factory_delegate.h" |
| 19 #include "chrome/common/extensions/extension_icon_set.h" |
17 #include "third_party/skia/include/core/SkColor.h" | 20 #include "third_party/skia/include/core/SkColor.h" |
18 #include "ui/base/animation/linear_animation.h" | 21 #include "ui/base/animation/linear_animation.h" |
19 | 22 |
20 class GURL; | 23 class GURL; |
21 class SkBitmap; | 24 class SkBitmap; |
22 class SkDevice; | 25 class SkDevice; |
23 | 26 |
24 namespace gfx { | 27 namespace gfx { |
25 class Canvas; | 28 class Canvas; |
26 class Image; | 29 class Image; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } | 155 } |
153 | 156 |
154 // If tab |tab_id| has a set title, return it. Otherwise, return | 157 // If tab |tab_id| has a set title, return it. Otherwise, return |
155 // the default title. | 158 // the default title. |
156 std::string GetTitle(int tab_id) const { return GetValue(&title_, tab_id); } | 159 std::string GetTitle(int tab_id) const { return GetValue(&title_, tab_id); } |
157 | 160 |
158 // Icons are a bit different because the default value can be set to either a | 161 // Icons are a bit different because the default value can be set to either a |
159 // bitmap or a path. However, conceptually, there is only one default icon. | 162 // bitmap or a path. However, conceptually, there is only one default icon. |
160 // Setting the default icon using a path clears the bitmap and vice-versa. | 163 // Setting the default icon using a path clears the bitmap and vice-versa. |
161 | 164 |
162 // Since ExtensionAction, living in common/, can't interact with the browser | |
163 // to load images, the UI code needs to load the icon. Load the image there | |
164 // using an ImageLoadingTracker and call CacheIcon(image) with the result. | |
165 // | |
166 // If an image is cached redundantly, the first load will be used. | |
167 void CacheIcon(const gfx::Image& icon); | |
168 | |
169 // Set this action's icon bitmap on a specific tab. | 165 // Set this action's icon bitmap on a specific tab. |
170 void SetIcon(int tab_id, const gfx::Image& image); | 166 void SetIcon(int tab_id, const gfx::Image& image); |
171 | 167 |
172 // Get the icon for a tab, or the default if no icon was set for this tab, | 168 // Get the icon for a tab. If the default icon or pare action icon has to be |
173 // retrieving icons that have been specified by path from the previous | 169 // returned, |icon_factory| will be used to get the actual icon. |
174 // arguments to CacheIcon(). If the default icon isn't found in the cache, | 170 // |icon_factory| is used because the icon has to be loaded using |
175 // returns the puzzle piece icon. | 171 // extensions::IconImage, which cannot be done from chrome/common/. The |
176 gfx::Image GetIcon(int tab_id) const; | 172 // factory implementation should handle asynchronous icon loading. |
| 173 // If no icon is specified for the tab, returns the puzzle piece icon. |
| 174 gfx::Image GetIcon(int tab_id, |
| 175 ExtensionIconFactoryDelegate* icon_factory) const; |
177 | 176 |
178 // Gets the icon that has been set using |SetIcon| for the tab. | 177 // Gets the icon that has been set using |SetIcon| for the tab. |
179 gfx::ImageSkia GetExplicitlySetIcon(int tab_id) const; | 178 gfx::ImageSkia GetExplicitlySetIcon(int tab_id) const; |
180 | 179 |
181 // Non-tab-specific icon path. This is used to support the default_icon key of | 180 // Non-tab-specific icon path. This is used to support the default_icon key of |
182 // page and browser actions. | 181 // page and browser actions. |
183 void set_default_icon_path(const std::string& path) { | 182 void set_default_icon(scoped_ptr<ExtensionIconSet> icon_set) { |
184 default_icon_path_ = path; | 183 default_icon_ = icon_set.Pass(); |
185 } | 184 } |
186 const std::string& default_icon_path() const { | 185 |
187 return default_icon_path_; | 186 const ExtensionIconSet* default_icon() const { |
| 187 return default_icon_.get(); |
188 } | 188 } |
189 | 189 |
190 // Set this action's badge text on a specific tab. | 190 // Set this action's badge text on a specific tab. |
191 void SetBadgeText(int tab_id, const std::string& text) { | 191 void SetBadgeText(int tab_id, const std::string& text) { |
192 SetValue(&badge_text_, tab_id, text); | 192 SetValue(&badge_text_, tab_id, text); |
193 } | 193 } |
194 // Get the badge text for a tab, or the default if no badge text was set. | 194 // Get the badge text for a tab, or the default if no badge text was set. |
195 std::string GetBadgeText(int tab_id) const { | 195 std::string GetBadgeText(int tab_id) const { |
196 return GetValue(&badge_text_, tab_id); | 196 return GetValue(&badge_text_, tab_id); |
197 } | 197 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 class IconWithBadgeImageSource; | 245 class IconWithBadgeImageSource; |
246 | 246 |
247 // Runs an animation on a tab. | 247 // Runs an animation on a tab. |
248 void RunIconAnimation(int tab_id); | 248 void RunIconAnimation(int tab_id); |
249 | 249 |
250 // If the icon animation is running on tab |tab_id|, applies it to | 250 // If the icon animation is running on tab |tab_id|, applies it to |
251 // |orig| and returns the result. Otherwise, just returns |orig|. | 251 // |orig| and returns the result. Otherwise, just returns |orig|. |
252 gfx::ImageSkia ApplyIconAnimation(int tab_id, | 252 gfx::ImageSkia ApplyIconAnimation(int tab_id, |
253 const gfx::ImageSkia& orig) const; | 253 const gfx::ImageSkia& orig) const; |
254 | 254 |
| 255 // Returns width of the current icon for tab_id. |
| 256 int GetIconWidth(int tab_id) const; |
| 257 |
255 // Paints badge with specified parameters to |canvas|. | 258 // Paints badge with specified parameters to |canvas|. |
256 static void DoPaintBadge(gfx::Canvas* canvas, | 259 static void DoPaintBadge(gfx::Canvas* canvas, |
257 const gfx::Rect& bounds, | 260 const gfx::Rect& bounds, |
258 const std::string& text, | 261 const std::string& text, |
259 const SkColor& text_color_in, | 262 const SkColor& text_color_in, |
260 const SkColor& background_color_in, | 263 const SkColor& background_color_in, |
261 int icon_width); | 264 int icon_width); |
262 | 265 |
263 template <class T> | 266 template <class T> |
264 struct ValueTraits { | 267 struct ValueTraits { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 std::map<int, SkColor> badge_text_color_; | 302 std::map<int, SkColor> badge_text_color_; |
300 std::map<int, Appearance> appearance_; | 303 std::map<int, Appearance> appearance_; |
301 | 304 |
302 // IconAnimations are destroyed by a delayed task on the UI message loop so | 305 // IconAnimations are destroyed by a delayed task on the UI message loop so |
303 // that even if the Extension and ExtensionAction are destroyed on a non-UI | 306 // that even if the Extension and ExtensionAction are destroyed on a non-UI |
304 // thread, the animation will still only be touched from the UI thread. This | 307 // thread, the animation will still only be touched from the UI thread. This |
305 // causes the WeakPtr in this map to become NULL. GetIconAnimation() removes | 308 // causes the WeakPtr in this map to become NULL. GetIconAnimation() removes |
306 // NULLs to prevent the map from growing without bound. | 309 // NULLs to prevent the map from growing without bound. |
307 mutable std::map<int, base::WeakPtr<IconAnimation> > icon_animation_; | 310 mutable std::map<int, base::WeakPtr<IconAnimation> > icon_animation_; |
308 | 311 |
309 std::string default_icon_path_; | 312 // ExtensionIconSet containing paths to bitmaps from which default icon's |
| 313 // image representations will be selected. |
| 314 scoped_ptr<const ExtensionIconSet> default_icon_; |
310 | 315 |
311 // The id for the ExtensionAction, for example: "RssPageAction". This is | 316 // The id for the ExtensionAction, for example: "RssPageAction". This is |
312 // needed for compat with an older version of the page actions API. | 317 // needed for compat with an older version of the page actions API. |
313 std::string id_; | 318 std::string id_; |
314 | 319 |
315 // Saves the arguments from CacheIcon() calls. | |
316 scoped_ptr<gfx::ImageSkia> cached_icon_; | |
317 | |
318 // True if the ExtensionAction's settings have changed from what was | 320 // True if the ExtensionAction's settings have changed from what was |
319 // specified in the manifest. | 321 // specified in the manifest. |
320 bool has_changed_; | 322 bool has_changed_; |
321 | 323 |
322 DISALLOW_COPY_AND_ASSIGN(ExtensionAction); | 324 DISALLOW_COPY_AND_ASSIGN(ExtensionAction); |
323 }; | 325 }; |
324 | 326 |
325 template<> | 327 template<> |
326 struct ExtensionAction::ValueTraits<int> { | 328 struct ExtensionAction::ValueTraits<int> { |
327 static int CreateEmpty() { | 329 static int CreateEmpty() { |
328 return -1; | 330 return -1; |
329 } | 331 } |
330 }; | 332 }; |
331 | 333 |
332 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ | 334 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ |
OLD | NEW |