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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 // extension id | 129 // extension id |
127 const std::string& extension_id() const { return extension_id_; } | 130 const std::string& extension_id() const { return extension_id_; } |
128 | 131 |
129 // What kind of action is this? | 132 // What kind of action is this? |
130 Type action_type() const { return action_type_; } | 133 Type action_type() const { return action_type_; } |
131 | 134 |
132 // action id -- only used with legacy page actions API | 135 // action id -- only used with legacy page actions API |
133 std::string id() const { return id_; } | 136 std::string id() const { return id_; } |
134 void set_id(const std::string& id) { id_ = id; } | 137 void set_id(const std::string& id) { id_ = id; } |
135 | 138 |
136 // static icon paths from manifest -- only used with legacy page actions API. | 139 const std::vector<const ExtensionIconSet*>& page_action_icons() const { |
Jeffrey Yasskin
2012/09/13 00:23:36
I think mpcomplete is removing the icon_paths() AP
tbarzic
2012/09/13 17:57:54
fwiw, this change removes page action icons loadin
| |
137 std::vector<std::string>* icon_paths() { return &icon_paths_; } | 140 return page_action_icons_.get(); |
138 const std::vector<std::string>* icon_paths() const { return &icon_paths_; } | 141 } |
142 | |
143 // Adds an IconSet for a new page action icon. | |
144 void AddPageActionIcon(scoped_ptr<ExtensionIconSet> icon_set); | |
145 | |
146 // Checks if specified icon index is valid. | |
147 bool IsValidIconIndex(int index) const; | |
139 | 148 |
140 bool has_changed() const { return has_changed_; } | 149 bool has_changed() const { return has_changed_; } |
141 void set_has_changed(bool value) { has_changed_ = value; } | 150 void set_has_changed(bool value) { has_changed_ = value; } |
142 | 151 |
143 // Set the url which the popup will load when the user clicks this action's | 152 // Set the url which the popup will load when the user clicks this action's |
144 // icon. Setting an empty URL will disable the popup for a given tab. | 153 // icon. Setting an empty URL will disable the popup for a given tab. |
145 void SetPopupUrl(int tab_id, const GURL& url); | 154 void SetPopupUrl(int tab_id, const GURL& url); |
146 | 155 |
147 // Use HasPopup() to see if a popup should be displayed. | 156 // Use HasPopup() to see if a popup should be displayed. |
148 bool HasPopup(int tab_id) const; | 157 bool HasPopup(int tab_id) const; |
149 | 158 |
150 // Get the URL to display in a popup. | 159 // Get the URL to display in a popup. |
151 GURL GetPopupUrl(int tab_id) const; | 160 GURL GetPopupUrl(int tab_id) const; |
152 | 161 |
153 // Set this action's title on a specific tab. | 162 // Set this action's title on a specific tab. |
154 void SetTitle(int tab_id, const std::string& title) { | 163 void SetTitle(int tab_id, const std::string& title) { |
155 SetValue(&title_, tab_id, title); | 164 SetValue(&title_, tab_id, title); |
156 } | 165 } |
157 | 166 |
158 // If tab |tab_id| has a set title, return it. Otherwise, return | 167 // If tab |tab_id| has a set title, return it. Otherwise, return |
159 // the default title. | 168 // the default title. |
160 std::string GetTitle(int tab_id) const { return GetValue(&title_, tab_id); } | 169 std::string GetTitle(int tab_id) const { return GetValue(&title_, tab_id); } |
161 | 170 |
162 // Icons are a bit different because the default value can be set to either a | 171 // Icons are a bit different because the default value can be set to either a |
163 // bitmap or a path. However, conceptually, there is only one default icon. | 172 // bitmap or a path. However, conceptually, there is only one default icon. |
164 // Setting the default icon using a path clears the bitmap and vice-versa. | 173 // Setting the default icon using a path clears the bitmap and vice-versa. |
165 | 174 |
166 // Since ExtensionAction, living in common/, can't interact with the browser | |
167 // to load images, the UI code needs to load the images for each path. For | |
168 // each path in default_icon_path() and icon_paths(), load the image there | |
169 // using an ImageLoadingTracker and call CacheIcon(path, image) with the | |
170 // result. | |
171 // | |
172 // If an image is cached redundantly, the first load will be used. | |
173 void CacheIcon(const std::string& path, const gfx::Image& icon); | |
174 | |
175 // Set this action's icon bitmap on a specific tab. | 175 // Set this action's icon bitmap on a specific tab. |
176 void SetIcon(int tab_id, const gfx::Image& image); | 176 void SetIcon(int tab_id, const gfx::Image& image); |
177 | 177 |
178 // Get the icon for a tab, or the default if no icon was set for this tab, | 178 // Get the icon for a tab. If the default icon or pare action icon has to be |
179 // retrieving icons that have been specified by path from the previous | 179 // returned, |icon_factory| will be used to get the actual icon. |
180 // arguments to CacheIcon(). If the default icon isn't found in the cache, | 180 // |icon_factory| is used because the icon has to be loaded using |
181 // returns the puzzle piece icon. | 181 // extensions::IconImage, which cannot be done from chrome/common/. The |
182 gfx::Image GetIcon(int tab_id) const; | 182 // factory implementation should handle asynchronous icon loading. |
183 // If no icon is specified for the tab, returns the puzzle piece icon. | |
184 gfx::Image GetIcon(int tab_id, | |
185 ExtensionIconFactoryDelegate* icon_factory) const; | |
183 | 186 |
184 // Gets the icon that has been set using |SetIcon| for the tab. | 187 // Gets the icon that has been set using |SetIcon| for the tab. |
185 gfx::ImageSkia GetExplicitlySetIcon(int tab_id) const; | 188 gfx::ImageSkia GetExplicitlySetIcon(int tab_id) const; |
186 | 189 |
187 // Set this action's icon index for a specific tab. For use with | 190 // Set this action's icon index for a specific tab. For use with |
188 // icon_paths(), only used in page actions. | 191 // icon_paths(), only used in page actions. |
189 void SetIconIndex(int tab_id, int index); | 192 void SetIconIndex(int tab_id, int index); |
190 | 193 |
191 // Get this action's icon index for a tab, or the default if no icon index | 194 // Get this action's icon index for a tab, or the default if no icon index |
192 // was set. | 195 // was set. |
193 int GetIconIndex(int tab_id) const { | 196 int GetIconIndex(int tab_id) const { |
194 return GetValue(&icon_index_, tab_id); | 197 return GetValue(&icon_index_, tab_id); |
195 } | 198 } |
196 | 199 |
197 // Non-tab-specific icon path. This is used to support the default_icon key of | 200 // Non-tab-specific icon path. This is used to support the default_icon key of |
198 // page and browser actions. | 201 // page and browser actions. |
199 void set_default_icon_path(const std::string& path) { | 202 void set_default_icon(scoped_ptr<ExtensionIconSet> icon_set) { |
200 default_icon_path_ = path; | 203 default_icon_ = icon_set.Pass(); |
201 } | 204 } |
202 const std::string& default_icon_path() const { | 205 |
203 return default_icon_path_; | 206 const ExtensionIconSet* default_icon() const { |
207 return default_icon_.get(); | |
204 } | 208 } |
205 | 209 |
206 // Set this action's badge text on a specific tab. | 210 // Set this action's badge text on a specific tab. |
207 void SetBadgeText(int tab_id, const std::string& text) { | 211 void SetBadgeText(int tab_id, const std::string& text) { |
208 SetValue(&badge_text_, tab_id, text); | 212 SetValue(&badge_text_, tab_id, text); |
209 } | 213 } |
210 // Get the badge text for a tab, or the default if no badge text was set. | 214 // Get the badge text for a tab, or the default if no badge text was set. |
211 std::string GetBadgeText(int tab_id) const { | 215 std::string GetBadgeText(int tab_id) const { |
212 return GetValue(&badge_text_, tab_id); | 216 return GetValue(&badge_text_, tab_id); |
213 } | 217 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 class IconWithBadgeImageSource; | 265 class IconWithBadgeImageSource; |
262 | 266 |
263 // Runs an animation on a tab. | 267 // Runs an animation on a tab. |
264 void RunIconAnimation(int tab_id); | 268 void RunIconAnimation(int tab_id); |
265 | 269 |
266 // If the icon animation is running on tab |tab_id|, applies it to | 270 // If the icon animation is running on tab |tab_id|, applies it to |
267 // |orig| and returns the result. Otherwise, just returns |orig|. | 271 // |orig| and returns the result. Otherwise, just returns |orig|. |
268 gfx::ImageSkia ApplyIconAnimation(int tab_id, | 272 gfx::ImageSkia ApplyIconAnimation(int tab_id, |
269 const gfx::ImageSkia& orig) const; | 273 const gfx::ImageSkia& orig) const; |
270 | 274 |
275 // Returns width of the current icon for tab_id. | |
276 int GetIconWidth(int tab_id) const; | |
277 | |
271 // Paints badge with specified parameters to |canvas|. | 278 // Paints badge with specified parameters to |canvas|. |
272 static void DoPaintBadge(gfx::Canvas* canvas, | 279 static void DoPaintBadge(gfx::Canvas* canvas, |
273 const gfx::Rect& bounds, | 280 const gfx::Rect& bounds, |
274 const std::string& text, | 281 const std::string& text, |
275 const SkColor& text_color_in, | 282 const SkColor& text_color_in, |
276 const SkColor& background_color_in, | 283 const SkColor& background_color_in, |
277 int icon_width); | 284 int icon_width); |
278 | 285 |
279 template <class T> | 286 template <class T> |
280 struct ValueTraits { | 287 struct ValueTraits { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 std::map<int, SkColor> badge_text_color_; | 323 std::map<int, SkColor> badge_text_color_; |
317 std::map<int, Appearance> appearance_; | 324 std::map<int, Appearance> appearance_; |
318 | 325 |
319 // IconAnimations are destroyed by a delayed task on the UI message loop so | 326 // IconAnimations are destroyed by a delayed task on the UI message loop so |
320 // that even if the Extension and ExtensionAction are destroyed on a non-UI | 327 // that even if the Extension and ExtensionAction are destroyed on a non-UI |
321 // thread, the animation will still only be touched from the UI thread. This | 328 // thread, the animation will still only be touched from the UI thread. This |
322 // causes the WeakPtr in this map to become NULL. GetIconAnimation() removes | 329 // causes the WeakPtr in this map to become NULL. GetIconAnimation() removes |
323 // NULLs to prevent the map from growing without bound. | 330 // NULLs to prevent the map from growing without bound. |
324 mutable std::map<int, base::WeakPtr<IconAnimation> > icon_animation_; | 331 mutable std::map<int, base::WeakPtr<IconAnimation> > icon_animation_; |
325 | 332 |
326 std::string default_icon_path_; | 333 // ExtensionIconSet with icon image representations for default icon. |
Jeffrey Yasskin
2012/09/13 00:23:36
ExtensionIconSet doesn't hold icon image represent
tbarzic
2012/09/13 02:01:01
I look at ExtensionIconSet as not aware of scale f
| |
334 scoped_ptr<const ExtensionIconSet> default_icon_; | |
335 | |
336 // ExtensionIconSets with icon image representations for deprecated page | |
337 // action icons. | |
338 ScopedVector<const ExtensionIconSet> page_action_icons_; | |
327 | 339 |
328 // The id for the ExtensionAction, for example: "RssPageAction". This is | 340 // The id for the ExtensionAction, for example: "RssPageAction". This is |
329 // needed for compat with an older version of the page actions API. | 341 // needed for compat with an older version of the page actions API. |
330 std::string id_; | 342 std::string id_; |
331 | 343 |
332 // A list of paths to icons this action might show. This is needed to support | |
333 // the legacy setIcon({iconIndex:...} method of the page actions API. | |
334 std::vector<std::string> icon_paths_; | |
335 | |
336 // Saves the arguments from CacheIcon() calls. | |
337 std::map<std::string, gfx::ImageSkia> path_to_icon_cache_; | |
338 | |
339 // True if the ExtensionAction's settings have changed from what was | 344 // True if the ExtensionAction's settings have changed from what was |
340 // specified in the manifest. | 345 // specified in the manifest. |
341 bool has_changed_; | 346 bool has_changed_; |
342 | 347 |
343 DISALLOW_COPY_AND_ASSIGN(ExtensionAction); | 348 DISALLOW_COPY_AND_ASSIGN(ExtensionAction); |
344 }; | 349 }; |
345 | 350 |
346 template<> | 351 template<> |
347 struct ExtensionAction::ValueTraits<int> { | 352 struct ExtensionAction::ValueTraits<int> { |
348 static int CreateEmpty() { | 353 static int CreateEmpty() { |
349 return -1; | 354 return -1; |
350 } | 355 } |
351 }; | 356 }; |
352 | 357 |
353 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ | 358 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ |
OLD | NEW |