| 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_BROWSER_EXTENSIONS_EXTENSION_ACTION_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "chrome/common/extensions/api/extension_action/action_info.h" | 15 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 16 #include "extensions/common/constants.h" | 16 #include "extensions/common/constants.h" |
| 17 #include "third_party/skia/include/core/SkColor.h" | 17 #include "third_party/skia/include/core/SkColor.h" |
| 18 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
| 19 | 19 |
| 20 class GURL; | 20 class GURL; |
| 21 | 21 |
| 22 namespace content { | |
| 23 class BrowserContext; | |
| 24 } | |
| 25 | |
| 26 namespace extensions { | 22 namespace extensions { |
| 27 class Extension; | 23 class Extension; |
| 28 class IconImage; | 24 class IconImage; |
| 29 } | 25 } |
| 30 | 26 |
| 31 namespace gfx { | 27 namespace gfx { |
| 32 class Canvas; | 28 class Canvas; |
| 33 class Image; | 29 class Image; |
| 34 class ImageSkia; | 30 class ImageSkia; |
| 35 class Rect; | 31 class Rect; |
| 36 class Size; | 32 class Size; |
| 37 } | 33 } |
| 38 | 34 |
| 39 // ExtensionAction encapsulates the state of a browser action or page action. | 35 // ExtensionAction encapsulates the state of a browser action or page action. |
| 40 // 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 |
| 41 // a per-tab value, the global value is used instead. | 37 // a per-tab value, the global value is used instead. |
| 42 class ExtensionAction { | 38 class ExtensionAction { |
| 43 public: | 39 public: |
| 44 // The action that the UI should take after the ExtensionAction is clicked. | 40 // The action that the UI should take after the ExtensionAction is clicked. |
| 45 enum ShowAction { | 41 enum ShowAction { |
| 46 ACTION_NONE, | 42 ACTION_NONE, |
| 47 ACTION_SHOW_POPUP, | 43 ACTION_SHOW_POPUP, |
| 48 // We don't need a SHOW_CONTEXT_MENU because that's handled separately in | 44 // We don't need a SHOW_CONTEXT_MENU because that's handled separately in |
| 49 // the UI. | 45 // the UI. |
| 50 }; | 46 }; |
| 51 | 47 |
| 52 static extension_misc::ExtensionIcons ActionIconSize(); | 48 static extension_misc::ExtensionIcons ActionIconSize(); |
| 53 | 49 |
| 50 // Returns the default icon to use when no other is available (the puzzle |
| 51 // piece). |
| 52 static gfx::Image FallbackIcon(); |
| 53 |
| 54 // Use this ID to indicate the default state for properties that take a tab_id | 54 // Use this ID to indicate the default state for properties that take a tab_id |
| 55 // parameter. | 55 // parameter. |
| 56 static const int kDefaultTabId; | 56 static const int kDefaultTabId; |
| 57 | 57 |
| 58 ExtensionAction(const extensions::Extension& extension, | 58 ExtensionAction(const extensions::Extension& extension, |
| 59 extensions::ActionInfo::Type action_type, | 59 extensions::ActionInfo::Type action_type, |
| 60 const extensions::ActionInfo& manifest_data); | 60 const extensions::ActionInfo& manifest_data); |
| 61 ~ExtensionAction(); | 61 ~ExtensionAction(); |
| 62 | 62 |
| 63 // extension id | 63 // extension id |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 if (const bool* default_is_visible = | 174 if (const bool* default_is_visible = |
| 175 FindOrNull(&is_visible_, kDefaultTabId)) | 175 FindOrNull(&is_visible_, kDefaultTabId)) |
| 176 return *default_is_visible; | 176 return *default_is_visible; |
| 177 | 177 |
| 178 return false; | 178 return false; |
| 179 } | 179 } |
| 180 | 180 |
| 181 // Remove all tab-specific state. | 181 // Remove all tab-specific state. |
| 182 void ClearAllValuesForTab(int tab_id); | 182 void ClearAllValuesForTab(int tab_id); |
| 183 | 183 |
| 184 // Lazily loads and returns the default icon image, if one exists for the | 184 // Sets the default IconImage for this action. |
| 185 // action. | 185 void SetDefaultIconImage(std::unique_ptr<extensions::IconImage> icon_image); |
| 186 extensions::IconImage* LoadDefaultIconImage( | |
| 187 const extensions::Extension& extension, | |
| 188 content::BrowserContext* browser_context); | |
| 189 | 186 |
| 190 // Returns the image to use as the default icon for the action. Can only be | 187 // Returns the image to use as the default icon for the action. Can only be |
| 191 // called after LoadDefaultIconImage(). | 188 // called after SetDefaultIconImage(). |
| 192 gfx::Image GetDefaultIconImage() const; | 189 gfx::Image GetDefaultIconImage() const; |
| 193 | 190 |
| 194 // Determine whether or not the ExtensionAction has a value set for the given | 191 // Determine whether or not the ExtensionAction has a value set for the given |
| 195 // |tab_id| for each property. | 192 // |tab_id| for each property. |
| 196 bool HasPopupUrl(int tab_id) const; | 193 bool HasPopupUrl(int tab_id) const; |
| 197 bool HasTitle(int tab_id) const; | 194 bool HasTitle(int tab_id) const; |
| 198 bool HasBadgeText(int tab_id) const; | 195 bool HasBadgeText(int tab_id) const; |
| 199 bool HasBadgeBackgroundColor(int tab_id) const; | 196 bool HasBadgeBackgroundColor(int tab_id) const; |
| 200 bool HasBadgeTextColor(int tab_id) const; | 197 bool HasBadgeTextColor(int tab_id) const; |
| 201 bool HasIsVisible(int tab_id) const; | 198 bool HasIsVisible(int tab_id) const; |
| 202 bool HasIcon(int tab_id) const; | 199 bool HasIcon(int tab_id) const; |
| 203 | 200 |
| 201 extensions::IconImage* default_icon_image() { |
| 202 return default_icon_image_.get(); |
| 203 } |
| 204 |
| 204 void SetDefaultIconForTest(std::unique_ptr<ExtensionIconSet> default_icon); | 205 void SetDefaultIconForTest(std::unique_ptr<ExtensionIconSet> default_icon); |
| 205 | 206 |
| 206 private: | 207 private: |
| 207 // Populates the action from the |extension| and |manifest_data|, filling in | 208 // Populates the action from the |extension| and |manifest_data|, filling in |
| 208 // any missing values (like title or icons) as possible. | 209 // any missing values (like title or icons) as possible. |
| 209 void Populate(const extensions::Extension& extension, | 210 void Populate(const extensions::Extension& extension, |
| 210 const extensions::ActionInfo& manifest_data); | 211 const extensions::ActionInfo& manifest_data); |
| 211 | 212 |
| 212 // Returns width of the current icon for tab_id. | 213 // Returns width of the current icon for tab_id. |
| 213 // TODO(tbarzic): The icon selection is done in ExtensionActionIconFactory. | 214 // TODO(tbarzic): The icon selection is done in ExtensionActionIconFactory. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 std::map<int, int> declarative_show_count_; | 279 std::map<int, int> declarative_show_count_; |
| 279 | 280 |
| 280 // declarative_icon_[tab_id][declarative_rule_priority] is a vector of icon | 281 // declarative_icon_[tab_id][declarative_rule_priority] is a vector of icon |
| 281 // images that are currently in effect | 282 // images that are currently in effect |
| 282 std::map<int, std::map<int, std::vector<gfx::Image> > > declarative_icon_; | 283 std::map<int, std::map<int, std::vector<gfx::Image> > > declarative_icon_; |
| 283 | 284 |
| 284 // ExtensionIconSet containing paths to bitmaps from which default icon's | 285 // ExtensionIconSet containing paths to bitmaps from which default icon's |
| 285 // image representations will be selected. | 286 // image representations will be selected. |
| 286 std::unique_ptr<ExtensionIconSet> default_icon_; | 287 std::unique_ptr<ExtensionIconSet> default_icon_; |
| 287 | 288 |
| 288 // The default icon image, if |default_icon_| exists. | 289 // The default icon image, if |default_icon_| exists. Set via |
| 289 // Lazily initialized via LoadDefaultIconImage(). | 290 // SetDefaultIconImage(). Since IconImages depend upon BrowserContexts, we |
| 291 // don't have the ExtensionAction load it directly to keep this class's |
| 292 // knowledge limited. |
| 290 std::unique_ptr<extensions::IconImage> default_icon_image_; | 293 std::unique_ptr<extensions::IconImage> default_icon_image_; |
| 291 | 294 |
| 292 // The lazily-initialized image for a placeholder icon, in the event that the | 295 // The lazily-initialized image for a placeholder icon, in the event that the |
| 293 // extension doesn't have its own icon. (Mutable to allow lazy init in | 296 // extension doesn't have its own icon. (Mutable to allow lazy init in |
| 294 // GetDefaultIconImage().) | 297 // GetDefaultIconImage().) |
| 295 mutable gfx::Image placeholder_icon_image_; | 298 mutable gfx::Image placeholder_icon_image_; |
| 296 | 299 |
| 297 // The id for the ExtensionAction, for example: "RssPageAction". This is | 300 // The id for the ExtensionAction, for example: "RssPageAction". This is |
| 298 // needed for compat with an older version of the page actions API. | 301 // needed for compat with an older version of the page actions API. |
| 299 std::string id_; | 302 std::string id_; |
| 300 | 303 |
| 301 DISALLOW_COPY_AND_ASSIGN(ExtensionAction); | 304 DISALLOW_COPY_AND_ASSIGN(ExtensionAction); |
| 302 }; | 305 }; |
| 303 | 306 |
| 304 template<> | 307 template<> |
| 305 struct ExtensionAction::ValueTraits<int> { | 308 struct ExtensionAction::ValueTraits<int> { |
| 306 static int CreateEmpty() { | 309 static int CreateEmpty() { |
| 307 return -1; | 310 return -1; |
| 308 } | 311 } |
| 309 }; | 312 }; |
| 310 | 313 |
| 311 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_H_ | 314 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_H_ |
| OLD | NEW |