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_BROWSER_EXTENSIONS_EXTENSION_ACTION_H_ |
Aaron Boodman
2012/09/16 01:42:50
Wow, neat that you can literally just move the fil
| |
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ | 6 #define CHROME_BROWSER_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/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "chrome/common/extensions/extension.h" | |
17 #include "third_party/skia/include/core/SkColor.h" | 18 #include "third_party/skia/include/core/SkColor.h" |
18 #include "ui/base/animation/linear_animation.h" | 19 #include "ui/base/animation/linear_animation.h" |
19 | 20 |
20 class GURL; | 21 class GURL; |
22 class Profile; | |
21 class SkBitmap; | 23 class SkBitmap; |
22 class SkDevice; | 24 class SkDevice; |
23 | 25 |
24 namespace gfx { | 26 namespace gfx { |
25 class Canvas; | 27 class Canvas; |
26 class Image; | 28 class Image; |
27 class ImageSkia; | 29 class ImageSkia; |
28 class Rect; | 30 class Rect; |
29 class Size; | 31 class Size; |
30 } | 32 } |
31 | 33 |
32 // ExtensionAction encapsulates the state of a browser action, page action, or | 34 // ExtensionAction encapsulates the state of a browser action, page action, or |
33 // script badge. | 35 // script badge. |
34 // Instances can have both global and per-tab state. If a property does not have | 36 // Instances can have both global and per-tab state. If a property does not have |
35 // a per-tab value, the global value is used instead. | 37 // a per-tab value, the global value is used instead. |
36 class ExtensionAction { | 38 class ExtensionAction { |
37 public: | 39 public: |
38 // Use this ID to indicate the default state for properties that take a tab_id | 40 // Use this ID to indicate the default state for properties that take a tab_id |
39 // parameter. | 41 // parameter. |
40 static const int kDefaultTabId; | 42 static const int kDefaultTabId; |
41 | 43 |
42 // The types of extension actions. | |
43 enum Type { | |
44 TYPE_BROWSER, | |
45 TYPE_PAGE, | |
46 TYPE_SCRIPT_BADGE, | |
47 }; | |
48 | |
49 enum Appearance { | 44 enum Appearance { |
50 // The action icon is hidden. | 45 // The action icon is hidden. |
51 INVISIBLE, | 46 INVISIBLE, |
52 // The action is trying to get the user's attention but isn't yet | 47 // The action is trying to get the user's attention but isn't yet |
53 // running on the page. Currently only used for script badges. | 48 // running on the page. Currently only used for script badges. |
54 WANTS_ATTENTION, | 49 WANTS_ATTENTION, |
55 // The action icon is visible with its normal appearance. | 50 // The action icon is visible with its normal appearance. |
56 ACTIVE, | 51 ACTIVE, |
57 }; | 52 }; |
58 | 53 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 // Device we use to paint icons to. | 104 // Device we use to paint icons to. |
110 mutable scoped_ptr<SkDevice> device_; | 105 mutable scoped_ptr<SkDevice> device_; |
111 | 106 |
112 ObserverList<Observer> observers_; | 107 ObserverList<Observer> observers_; |
113 | 108 |
114 base::WeakPtrFactory<IconAnimation> weak_ptr_factory_; | 109 base::WeakPtrFactory<IconAnimation> weak_ptr_factory_; |
115 | 110 |
116 DISALLOW_COPY_AND_ASSIGN(IconAnimation); | 111 DISALLOW_COPY_AND_ASSIGN(IconAnimation); |
117 }; | 112 }; |
118 | 113 |
119 ExtensionAction(const std::string& extension_id, Type action_type); | 114 ExtensionAction(const std::string& extension_id, |
115 const extensions::Extension::ActionInfo& manifest_info); | |
120 ~ExtensionAction(); | 116 ~ExtensionAction(); |
121 | 117 |
122 // Gets a copy of this, ownership passed to caller. | 118 // Gets a copy of this, ownership passed to caller. |
123 // It doesn't make sense to copy of an ExtensionAction except in tests. | 119 // It doesn't make sense to copy of an ExtensionAction except in tests. |
124 scoped_ptr<ExtensionAction> CopyForTest() const; | 120 scoped_ptr<ExtensionAction> CopyForTest() const; |
125 | 121 |
126 // extension id | 122 // extension id |
127 const std::string& extension_id() const { return extension_id_; } | 123 const std::string& extension_id() const { return extension_id_; } |
128 | 124 |
129 // What kind of action is this? | 125 // What kind of action is this? |
130 Type action_type() const { return action_type_; } | 126 extensions::Extension::ActionInfo::Type action_type() const { |
127 return action_type_; | |
128 } | |
131 | 129 |
132 // action id -- only used with legacy page actions API | 130 // action id -- only used with legacy page actions API |
133 std::string id() const { return id_; } | 131 std::string id() const { return id_; } |
134 void set_id(const std::string& id) { id_ = id; } | 132 void set_id(const std::string& id) { id_ = id; } |
135 | 133 |
136 // static icon paths from manifest -- only used with legacy page actions API. | 134 // static icon paths from manifest -- only used with legacy page actions API. |
137 std::vector<std::string>* icon_paths() { return &icon_paths_; } | 135 std::vector<std::string>* icon_paths() { return &icon_paths_; } |
138 const std::vector<std::string>* icon_paths() const { return &icon_paths_; } | 136 const std::vector<std::string>* icon_paths() const { return &icon_paths_; } |
139 | 137 |
140 bool has_changed() const { return has_changed_; } | 138 bool has_changed() const { return has_changed_; } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 } else { | 294 } else { |
297 iter = map->find(kDefaultTabId); | 295 iter = map->find(kDefaultTabId); |
298 return iter != map->end() ? iter->second : ValueTraits<T>::CreateEmpty(); | 296 return iter != map->end() ? iter->second : ValueTraits<T>::CreateEmpty(); |
299 } | 297 } |
300 } | 298 } |
301 | 299 |
302 // The id for the extension this action belongs to (as defined in the | 300 // The id for the extension this action belongs to (as defined in the |
303 // extension manifest). | 301 // extension manifest). |
304 const std::string extension_id_; | 302 const std::string extension_id_; |
305 | 303 |
306 const Type action_type_; | 304 const extensions::Extension::ActionInfo::Type action_type_; |
307 | 305 |
308 // Each of these data items can have both a global state (stored with the key | 306 // Each of these data items can have both a global state (stored with the key |
309 // kDefaultTabId), or tab-specific state (stored with the tab_id as the key). | 307 // kDefaultTabId), or tab-specific state (stored with the tab_id as the key). |
310 std::map<int, GURL> popup_url_; | 308 std::map<int, GURL> popup_url_; |
311 std::map<int, std::string> title_; | 309 std::map<int, std::string> title_; |
312 std::map<int, gfx::ImageSkia> icon_; | 310 std::map<int, gfx::ImageSkia> icon_; |
313 std::map<int, int> icon_index_; // index into icon_paths_ | 311 std::map<int, int> icon_index_; // index into icon_paths_ |
314 std::map<int, std::string> badge_text_; | 312 std::map<int, std::string> badge_text_; |
315 std::map<int, SkColor> badge_background_color_; | 313 std::map<int, SkColor> badge_background_color_; |
316 std::map<int, SkColor> badge_text_color_; | 314 std::map<int, SkColor> badge_text_color_; |
(...skipping 26 matching lines...) Expand all Loading... | |
343 DISALLOW_COPY_AND_ASSIGN(ExtensionAction); | 341 DISALLOW_COPY_AND_ASSIGN(ExtensionAction); |
344 }; | 342 }; |
345 | 343 |
346 template<> | 344 template<> |
347 struct ExtensionAction::ValueTraits<int> { | 345 struct ExtensionAction::ValueTraits<int> { |
348 static int CreateEmpty() { | 346 static int CreateEmpty() { |
349 return -1; | 347 return -1; |
350 } | 348 } |
351 }; | 349 }; |
352 | 350 |
353 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ | 351 namespace extensions { |
352 ExtensionAction* GetBrowserAction(Profile* profile, const Extension& extension); | |
Jeffrey Yasskin
2012/09/14 19:18:33
Functions along these lines are important to short
Aaron Boodman
2012/09/16 01:42:50
namespace: yes, keep 'Extension' prefix: yes
Aaron Boodman
2012/09/16 01:42:50
The downside of free functions like this is that i
not at google - send to devlin
2012/09/27 00:46:10
I also do not like free/utility functions like thi
| |
353 ExtensionAction* GetPageAction(Profile* profile, const Extension& extension); | |
354 ExtensionAction* GetScriptBadge(Profile* profile, const Extension& extension); | |
355 } | |
356 | |
357 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_H_ | |
OLD | NEW |