| 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_API_EXTENSION_ACTION_EXTENSION_ACTION_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTION_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTION_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTION_API_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 133 |
| 134 DISALLOW_COPY_AND_ASSIGN(ExtensionActionAPI); | 134 DISALLOW_COPY_AND_ASSIGN(ExtensionActionAPI); |
| 135 }; | 135 }; |
| 136 | 136 |
| 137 // Implementation of the browserAction and pageAction APIs. | 137 // Implementation of the browserAction and pageAction APIs. |
| 138 // | 138 // |
| 139 // Divergent behaviour between the two is minimal (pageAction has required | 139 // Divergent behaviour between the two is minimal (pageAction has required |
| 140 // tabIds while browserAction's are optional, they have different internal | 140 // tabIds while browserAction's are optional, they have different internal |
| 141 // browser notification requirements, and not all functions are defined for all | 141 // browser notification requirements, and not all functions are defined for all |
| 142 // APIs). | 142 // APIs). |
| 143 class ExtensionActionFunction : public ChromeSyncExtensionFunction { | 143 class ExtensionActionFunction : public UIThreadExtensionFunction { |
| 144 public: | 144 public: |
| 145 static bool ParseCSSColorString(const std::string& color_string, | 145 static bool ParseCSSColorString(const std::string& color_string, |
| 146 SkColor* result); | 146 SkColor* result); |
| 147 | 147 |
| 148 protected: | 148 protected: |
| 149 ExtensionActionFunction(); | 149 ExtensionActionFunction(); |
| 150 ~ExtensionActionFunction() override; | 150 ~ExtensionActionFunction() override; |
| 151 bool RunSync() override; | 151 ResponseAction Run() override; |
| 152 virtual bool RunExtensionAction() = 0; | 152 |
| 153 virtual ResponseAction RunExtensionAction() = 0; |
| 153 | 154 |
| 154 bool ExtractDataFromArguments(); | 155 bool ExtractDataFromArguments(); |
| 155 void NotifyChange(); | 156 void NotifyChange(); |
| 156 bool SetVisible(bool visible); | 157 void SetVisible(bool visible); |
| 157 | 158 |
| 158 // All the extension action APIs take a single argument called details that | 159 // All the extension action APIs take a single argument called details that |
| 159 // is a dictionary. | 160 // is a dictionary. |
| 160 base::DictionaryValue* details_; | 161 base::DictionaryValue* details_; |
| 161 | 162 |
| 162 // The tab id the extension action function should apply to, if any, or | 163 // The tab id the extension action function should apply to, if any, or |
| 163 // kDefaultTabId if none was specified. | 164 // kDefaultTabId if none was specified. |
| 164 int tab_id_; | 165 int tab_id_; |
| 165 | 166 |
| 166 // WebContents for |tab_id_| if one exists. | 167 // WebContents for |tab_id_| if one exists. |
| 167 content::WebContents* contents_; | 168 content::WebContents* contents_; |
| 168 | 169 |
| 169 // The extension action for the current extension. | 170 // The extension action for the current extension. |
| 170 ExtensionAction* extension_action_; | 171 ExtensionAction* extension_action_; |
| 171 }; | 172 }; |
| 172 | 173 |
| 173 // | 174 // |
| 174 // Implementations of each extension action API. | 175 // Implementations of each extension action API. |
| 175 // | 176 // |
| 176 // pageAction and browserAction bindings are created for these by extending them | 177 // pageAction and browserAction bindings are created for these by extending them |
| 177 // then declaring an EXTENSION_FUNCTION_NAME. | 178 // then declaring an EXTENSION_FUNCTION_NAME. |
| 178 // | 179 // |
| 179 | 180 |
| 180 // show | 181 // show |
| 181 class ExtensionActionShowFunction : public ExtensionActionFunction { | 182 class ExtensionActionShowFunction : public ExtensionActionFunction { |
| 182 protected: | 183 protected: |
| 183 ~ExtensionActionShowFunction() override {} | 184 ~ExtensionActionShowFunction() override {} |
| 184 bool RunExtensionAction() override; | 185 ResponseAction RunExtensionAction() override; |
| 185 }; | 186 }; |
| 186 | 187 |
| 187 // hide | 188 // hide |
| 188 class ExtensionActionHideFunction : public ExtensionActionFunction { | 189 class ExtensionActionHideFunction : public ExtensionActionFunction { |
| 189 protected: | 190 protected: |
| 190 ~ExtensionActionHideFunction() override {} | 191 ~ExtensionActionHideFunction() override {} |
| 191 bool RunExtensionAction() override; | 192 ResponseAction RunExtensionAction() override; |
| 192 }; | 193 }; |
| 193 | 194 |
| 194 // setIcon | 195 // setIcon |
| 195 class ExtensionActionSetIconFunction : public ExtensionActionFunction { | 196 class ExtensionActionSetIconFunction : public ExtensionActionFunction { |
| 196 protected: | 197 protected: |
| 197 ~ExtensionActionSetIconFunction() override {} | 198 ~ExtensionActionSetIconFunction() override {} |
| 198 bool RunExtensionAction() override; | 199 ResponseAction RunExtensionAction() override; |
| 199 }; | 200 }; |
| 200 | 201 |
| 201 // setTitle | 202 // setTitle |
| 202 class ExtensionActionSetTitleFunction : public ExtensionActionFunction { | 203 class ExtensionActionSetTitleFunction : public ExtensionActionFunction { |
| 203 protected: | 204 protected: |
| 204 ~ExtensionActionSetTitleFunction() override {} | 205 ~ExtensionActionSetTitleFunction() override {} |
| 205 bool RunExtensionAction() override; | 206 ResponseAction RunExtensionAction() override; |
| 206 }; | 207 }; |
| 207 | 208 |
| 208 // setPopup | 209 // setPopup |
| 209 class ExtensionActionSetPopupFunction : public ExtensionActionFunction { | 210 class ExtensionActionSetPopupFunction : public ExtensionActionFunction { |
| 210 protected: | 211 protected: |
| 211 ~ExtensionActionSetPopupFunction() override {} | 212 ~ExtensionActionSetPopupFunction() override {} |
| 212 bool RunExtensionAction() override; | 213 ResponseAction RunExtensionAction() override; |
| 213 }; | 214 }; |
| 214 | 215 |
| 215 // setBadgeText | 216 // setBadgeText |
| 216 class ExtensionActionSetBadgeTextFunction : public ExtensionActionFunction { | 217 class ExtensionActionSetBadgeTextFunction : public ExtensionActionFunction { |
| 217 protected: | 218 protected: |
| 218 ~ExtensionActionSetBadgeTextFunction() override {} | 219 ~ExtensionActionSetBadgeTextFunction() override {} |
| 219 bool RunExtensionAction() override; | 220 ResponseAction RunExtensionAction() override; |
| 220 }; | 221 }; |
| 221 | 222 |
| 222 // setBadgeBackgroundColor | 223 // setBadgeBackgroundColor |
| 223 class ExtensionActionSetBadgeBackgroundColorFunction | 224 class ExtensionActionSetBadgeBackgroundColorFunction |
| 224 : public ExtensionActionFunction { | 225 : public ExtensionActionFunction { |
| 225 protected: | 226 protected: |
| 226 ~ExtensionActionSetBadgeBackgroundColorFunction() override {} | 227 ~ExtensionActionSetBadgeBackgroundColorFunction() override {} |
| 227 bool RunExtensionAction() override; | 228 ResponseAction RunExtensionAction() override; |
| 228 }; | 229 }; |
| 229 | 230 |
| 230 // getTitle | 231 // getTitle |
| 231 class ExtensionActionGetTitleFunction : public ExtensionActionFunction { | 232 class ExtensionActionGetTitleFunction : public ExtensionActionFunction { |
| 232 protected: | 233 protected: |
| 233 ~ExtensionActionGetTitleFunction() override {} | 234 ~ExtensionActionGetTitleFunction() override {} |
| 234 bool RunExtensionAction() override; | 235 ResponseAction RunExtensionAction() override; |
| 235 }; | 236 }; |
| 236 | 237 |
| 237 // getPopup | 238 // getPopup |
| 238 class ExtensionActionGetPopupFunction : public ExtensionActionFunction { | 239 class ExtensionActionGetPopupFunction : public ExtensionActionFunction { |
| 239 protected: | 240 protected: |
| 240 ~ExtensionActionGetPopupFunction() override {} | 241 ~ExtensionActionGetPopupFunction() override {} |
| 241 bool RunExtensionAction() override; | 242 ResponseAction RunExtensionAction() override; |
| 242 }; | 243 }; |
| 243 | 244 |
| 244 // getBadgeText | 245 // getBadgeText |
| 245 class ExtensionActionGetBadgeTextFunction : public ExtensionActionFunction { | 246 class ExtensionActionGetBadgeTextFunction : public ExtensionActionFunction { |
| 246 protected: | 247 protected: |
| 247 ~ExtensionActionGetBadgeTextFunction() override {} | 248 ~ExtensionActionGetBadgeTextFunction() override {} |
| 248 bool RunExtensionAction() override; | 249 ResponseAction RunExtensionAction() override; |
| 249 }; | 250 }; |
| 250 | 251 |
| 251 // getBadgeBackgroundColor | 252 // getBadgeBackgroundColor |
| 252 class ExtensionActionGetBadgeBackgroundColorFunction | 253 class ExtensionActionGetBadgeBackgroundColorFunction |
| 253 : public ExtensionActionFunction { | 254 : public ExtensionActionFunction { |
| 254 protected: | 255 protected: |
| 255 ~ExtensionActionGetBadgeBackgroundColorFunction() override {} | 256 ~ExtensionActionGetBadgeBackgroundColorFunction() override {} |
| 256 bool RunExtensionAction() override; | 257 ResponseAction RunExtensionAction() override; |
| 257 }; | 258 }; |
| 258 | 259 |
| 259 // | 260 // |
| 260 // browserAction.* aliases for supported browserAction APIs. | 261 // browserAction.* aliases for supported browserAction APIs. |
| 261 // | 262 // |
| 262 | 263 |
| 263 class BrowserActionSetIconFunction : public ExtensionActionSetIconFunction { | 264 class BrowserActionSetIconFunction : public ExtensionActionSetIconFunction { |
| 264 public: | 265 public: |
| 265 DECLARE_EXTENSION_FUNCTION("browserAction.setIcon", BROWSERACTION_SETICON) | 266 DECLARE_EXTENSION_FUNCTION("browserAction.setIcon", BROWSERACTION_SETICON) |
| 266 | 267 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 class PageActionGetPopupFunction | 442 class PageActionGetPopupFunction |
| 442 : public extensions::ExtensionActionGetPopupFunction { | 443 : public extensions::ExtensionActionGetPopupFunction { |
| 443 public: | 444 public: |
| 444 DECLARE_EXTENSION_FUNCTION("pageAction.getPopup", PAGEACTION_GETPOPUP) | 445 DECLARE_EXTENSION_FUNCTION("pageAction.getPopup", PAGEACTION_GETPOPUP) |
| 445 | 446 |
| 446 protected: | 447 protected: |
| 447 ~PageActionGetPopupFunction() override {} | 448 ~PageActionGetPopupFunction() override {} |
| 448 }; | 449 }; |
| 449 | 450 |
| 450 #endif // CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTION_API_H
_ | 451 #endif // CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTION_API_H
_ |
| OLD | NEW |