Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTION_API_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTION_API_H_ | |
| 7 | |
| 8 #include "base/memory/weak_ptr.h" | |
| 9 #include "chrome/browser/extensions/extension_action.h" | |
| 10 #include "chrome/browser/extensions/extension_function.h" | |
| 11 #include "chrome/browser/profiles/profile_keyed_service.h" | |
| 12 #include "content/public/browser/notification_observer.h" | |
| 13 #include "content/public/browser/notification_registrar.h" | |
| 14 | |
| 15 namespace base { | |
| 16 class DictionaryValue; | |
| 17 } | |
| 18 | |
| 19 namespace content { | |
| 20 class WebContents; | |
| 21 } | |
| 22 | |
| 23 namespace extensions { | |
| 24 class TabHelper; | |
| 25 } | |
| 26 | |
| 27 namespace extensions { | |
| 28 | |
| 29 class ExtensionActionAPI : public ProfileKeyedService { | |
| 30 public: | |
| 31 explicit ExtensionActionAPI(Profile* profile); | |
| 32 virtual ~ExtensionActionAPI(); | |
| 33 | |
| 34 // ProfileKeyedService implementation. | |
| 35 virtual void Shutdown() OVERRIDE; | |
| 36 }; | |
| 37 | |
| 38 // This class manages reading and writing browser action values from storage. | |
| 39 class ExtensionActionStorageManager | |
| 40 : public content::NotificationObserver, | |
| 41 public base::SupportsWeakPtr<ExtensionActionStorageManager> { | |
| 42 public: | |
| 43 explicit ExtensionActionStorageManager(Profile* profile); | |
| 44 virtual ~ExtensionActionStorageManager(); | |
| 45 | |
| 46 private: | |
| 47 // NotificationObserver: | |
| 48 virtual void Observe(int type, | |
| 49 const content::NotificationSource& source, | |
| 50 const content::NotificationDetails& details) OVERRIDE; | |
| 51 | |
| 52 // Reads/Writes the ExtensionAction's default values to/from storage. | |
| 53 void WriteToStorage(ExtensionAction* extension_action); | |
| 54 void ReadFromStorage( | |
| 55 const std::string& extension_id, scoped_ptr<base::Value> value); | |
| 56 | |
| 57 Profile* profile_; | |
| 58 content::NotificationRegistrar registrar_; | |
| 59 }; | |
| 60 | |
| 61 // Implementation of the browserAction, pageAction, and scriptBadge APIs. | |
| 62 // | |
| 63 // Divergent behaviour between the three is minimal (pageAction and scriptBadge | |
| 64 // have required tabIds while browserAction's are optional, they have different | |
| 65 // internal browser notification requirements, and not all functions are defined | |
| 66 // for all APIs). | |
| 67 class ExtensionActionFunction : public SyncExtensionFunction { | |
| 68 public: | |
| 69 static bool ParseCSSColorString(const std::string& color_string, | |
| 70 SkColor* result); | |
| 71 | |
| 72 protected: | |
| 73 ExtensionActionFunction(); | |
| 74 virtual ~ExtensionActionFunction(); | |
| 75 virtual bool RunImpl() OVERRIDE; | |
| 76 virtual bool RunExtensionAction() = 0; | |
| 77 | |
| 78 bool ExtractDataFromArguments(); | |
| 79 void NotifyChange(); | |
| 80 void NotifyBrowserActionChange(); | |
| 81 void NotifyLocationBarChange(); | |
| 82 void NotifySystemIndicatorChange(); | |
| 83 bool SetVisible(bool visible); | |
| 84 | |
| 85 // Extension-related information for |tab_id_|. | |
| 86 // CHECK-fails if there is no tab. | |
| 87 extensions::TabHelper& tab_helper() const; | |
| 88 | |
| 89 // All the extension action APIs take a single argument called details that | |
| 90 // is a dictionary. | |
| 91 base::DictionaryValue* details_; | |
| 92 | |
| 93 // The tab id the extension action function should apply to, if any, or | |
| 94 // kDefaultTabId if none was specified. | |
| 95 int tab_id_; | |
| 96 | |
| 97 // WebContents for |tab_id_| if one exists. | |
| 98 content::WebContents* contents_; | |
| 99 | |
| 100 // The extension action for the current extension. | |
| 101 ExtensionAction* extension_action_; | |
| 102 }; | |
| 103 | |
| 104 // | |
| 105 // Implementations of each extension action API. | |
| 106 // | |
| 107 // pageAction and browserAction bindings are created for these by extending them | |
| 108 // then declaring an EXTENSION_FUNCTION_NAME. | |
| 109 // | |
| 110 | |
| 111 // show | |
| 112 class ExtensionActionShowFunction : public ExtensionActionFunction { | |
| 113 protected: | |
| 114 virtual ~ExtensionActionShowFunction() {} | |
| 115 virtual bool RunExtensionAction() OVERRIDE; | |
| 116 }; | |
| 117 | |
| 118 // hide | |
| 119 class ExtensionActionHideFunction : public ExtensionActionFunction { | |
| 120 protected: | |
| 121 virtual ~ExtensionActionHideFunction() {} | |
| 122 virtual bool RunExtensionAction() OVERRIDE; | |
| 123 }; | |
| 124 | |
| 125 // setIcon | |
| 126 class ExtensionActionSetIconFunction : public ExtensionActionFunction { | |
| 127 protected: | |
| 128 virtual ~ExtensionActionSetIconFunction() {} | |
| 129 virtual bool RunExtensionAction() OVERRIDE; | |
| 130 }; | |
| 131 | |
| 132 // setTitle | |
| 133 class ExtensionActionSetTitleFunction : public ExtensionActionFunction { | |
| 134 protected: | |
| 135 virtual ~ExtensionActionSetTitleFunction() {} | |
| 136 virtual bool RunExtensionAction() OVERRIDE; | |
| 137 }; | |
| 138 | |
| 139 // setPopup | |
| 140 class ExtensionActionSetPopupFunction : public ExtensionActionFunction { | |
| 141 protected: | |
| 142 virtual ~ExtensionActionSetPopupFunction() {} | |
| 143 virtual bool RunExtensionAction() OVERRIDE; | |
| 144 }; | |
| 145 | |
| 146 // setBadgeText | |
| 147 class ExtensionActionSetBadgeTextFunction : public ExtensionActionFunction { | |
| 148 protected: | |
| 149 virtual ~ExtensionActionSetBadgeTextFunction() {} | |
| 150 virtual bool RunExtensionAction() OVERRIDE; | |
| 151 }; | |
| 152 | |
| 153 // setBadgeBackgroundColor | |
| 154 class ExtensionActionSetBadgeBackgroundColorFunction | |
| 155 : public ExtensionActionFunction { | |
| 156 protected: | |
| 157 virtual ~ExtensionActionSetBadgeBackgroundColorFunction() {} | |
| 158 virtual bool RunExtensionAction() OVERRIDE; | |
| 159 }; | |
| 160 | |
| 161 // getTitle | |
| 162 class ExtensionActionGetTitleFunction : public ExtensionActionFunction { | |
| 163 protected: | |
| 164 virtual ~ExtensionActionGetTitleFunction() {} | |
| 165 virtual bool RunExtensionAction() OVERRIDE; | |
| 166 }; | |
| 167 | |
| 168 // getPopup | |
| 169 class ExtensionActionGetPopupFunction : public ExtensionActionFunction { | |
| 170 protected: | |
| 171 virtual ~ExtensionActionGetPopupFunction() {} | |
| 172 virtual bool RunExtensionAction() OVERRIDE; | |
| 173 }; | |
| 174 | |
| 175 // getBadgeText | |
| 176 class ExtensionActionGetBadgeTextFunction : public ExtensionActionFunction { | |
| 177 protected: | |
| 178 virtual ~ExtensionActionGetBadgeTextFunction() {} | |
| 179 virtual bool RunExtensionAction() OVERRIDE; | |
| 180 }; | |
| 181 | |
| 182 // getBadgeBackgroundColor | |
| 183 class ExtensionActionGetBadgeBackgroundColorFunction | |
| 184 : public ExtensionActionFunction { | |
| 185 protected: | |
| 186 virtual ~ExtensionActionGetBadgeBackgroundColorFunction() {} | |
| 187 virtual bool RunExtensionAction() OVERRIDE; | |
| 188 }; | |
| 189 | |
| 190 // | |
| 191 // browserAction.* aliases for supported browserActions APIs. | |
|
Yoyo Zhou
2012/12/19 23:30:52
nit: browserAction
Devlin
2012/12/20 19:43:20
Done.
| |
| 192 // | |
| 193 | |
| 194 class BrowserActionSetIconFunction : public ExtensionActionSetIconFunction { | |
| 195 public: | |
| 196 DECLARE_EXTENSION_FUNCTION_NAME("browserAction.setIcon") | |
| 197 | |
| 198 protected: | |
| 199 virtual ~BrowserActionSetIconFunction() {} | |
| 200 }; | |
| 201 | |
| 202 class BrowserActionSetTitleFunction : public ExtensionActionSetTitleFunction { | |
| 203 public: | |
| 204 DECLARE_EXTENSION_FUNCTION_NAME("browserAction.setTitle") | |
| 205 | |
| 206 protected: | |
| 207 virtual ~BrowserActionSetTitleFunction() {} | |
| 208 }; | |
| 209 | |
| 210 class BrowserActionSetPopupFunction : public ExtensionActionSetPopupFunction { | |
| 211 public: | |
| 212 DECLARE_EXTENSION_FUNCTION_NAME("browserAction.setPopup") | |
| 213 | |
| 214 protected: | |
| 215 virtual ~BrowserActionSetPopupFunction() {} | |
| 216 }; | |
| 217 | |
| 218 class BrowserActionGetTitleFunction : public ExtensionActionGetTitleFunction { | |
| 219 public: | |
| 220 DECLARE_EXTENSION_FUNCTION_NAME("browserAction.getTitle") | |
| 221 | |
| 222 protected: | |
| 223 virtual ~BrowserActionGetTitleFunction() {} | |
| 224 }; | |
| 225 | |
| 226 class BrowserActionGetPopupFunction : public ExtensionActionGetPopupFunction { | |
| 227 public: | |
| 228 DECLARE_EXTENSION_FUNCTION_NAME("browserAction.getPopup") | |
| 229 | |
| 230 protected: | |
| 231 virtual ~BrowserActionGetPopupFunction() {} | |
| 232 }; | |
| 233 | |
| 234 class BrowserActionSetBadgeTextFunction | |
| 235 : public ExtensionActionSetBadgeTextFunction { | |
| 236 public: | |
| 237 DECLARE_EXTENSION_FUNCTION_NAME("browserAction.setBadgeText") | |
| 238 | |
| 239 protected: | |
| 240 virtual ~BrowserActionSetBadgeTextFunction() {} | |
| 241 }; | |
| 242 | |
| 243 class BrowserActionSetBadgeBackgroundColorFunction | |
| 244 : public ExtensionActionSetBadgeBackgroundColorFunction { | |
| 245 public: | |
| 246 DECLARE_EXTENSION_FUNCTION_NAME("browserAction.setBadgeBackgroundColor") | |
| 247 | |
| 248 protected: | |
| 249 virtual ~BrowserActionSetBadgeBackgroundColorFunction() {} | |
| 250 }; | |
| 251 | |
| 252 class BrowserActionGetBadgeTextFunction | |
| 253 : public ExtensionActionGetBadgeTextFunction { | |
| 254 public: | |
| 255 DECLARE_EXTENSION_FUNCTION_NAME("browserAction.getBadgeText") | |
| 256 | |
| 257 protected: | |
| 258 virtual ~BrowserActionGetBadgeTextFunction() {} | |
| 259 }; | |
| 260 | |
| 261 class BrowserActionGetBadgeBackgroundColorFunction | |
| 262 : public ExtensionActionGetBadgeBackgroundColorFunction { | |
| 263 public: | |
| 264 DECLARE_EXTENSION_FUNCTION_NAME("browserAction.getBadgeBackgroundColor") | |
| 265 | |
| 266 protected: | |
| 267 virtual ~BrowserActionGetBadgeBackgroundColorFunction() {} | |
| 268 }; | |
| 269 | |
| 270 class BrowserActionEnableFunction : public ExtensionActionShowFunction { | |
| 271 public: | |
| 272 DECLARE_EXTENSION_FUNCTION_NAME("browserAction.enable") | |
| 273 | |
| 274 protected: | |
| 275 virtual ~BrowserActionEnableFunction() {} | |
| 276 }; | |
| 277 | |
| 278 class BrowserActionDisableFunction : public ExtensionActionHideFunction { | |
| 279 public: | |
| 280 DECLARE_EXTENSION_FUNCTION_NAME("browserAction.disable") | |
| 281 | |
| 282 protected: | |
| 283 virtual ~BrowserActionDisableFunction() {} | |
| 284 }; | |
| 285 | |
| 286 // Base class for deprecated page actions APIs | |
|
Yoyo Zhou
2012/12/19 23:30:52
Put this whole block at the bottom of the file.
Devlin
2012/12/20 19:43:20
Done.
Yoyo Zhou
2013/01/02 21:56:05
The deprecated pageActions should below the non-de
Devlin
2013/01/16 21:07:31
Done.
| |
| 287 class PageActionFunction : public SyncExtensionFunction { | |
| 288 protected: | |
| 289 PageActionFunction(); | |
| 290 virtual ~PageActionFunction(); | |
| 291 bool SetPageActionEnabled(bool enable); | |
| 292 }; | |
| 293 | |
| 294 // Implement chrome.pageActions.enableForTab(). | |
| 295 class EnablePageActionFunction : public PageActionFunction { | |
| 296 public: | |
| 297 DECLARE_EXTENSION_FUNCTION_NAME("pageActions.enableForTab") | |
| 298 | |
| 299 protected: | |
| 300 virtual ~EnablePageActionFunction() {} | |
| 301 | |
| 302 // ExtensionFunction: | |
| 303 virtual bool RunImpl() OVERRIDE; | |
| 304 }; | |
| 305 | |
| 306 // Implement chrome.pageActions.disableForTab(). | |
| 307 class DisablePageActionFunction : public PageActionFunction { | |
| 308 public: | |
| 309 DECLARE_EXTENSION_FUNCTION_NAME("pageActions.disableForTab") | |
| 310 | |
| 311 protected: | |
| 312 virtual ~DisablePageActionFunction() {} | |
| 313 | |
| 314 // ExtensionFunction: | |
| 315 virtual bool RunImpl() OVERRIDE; | |
| 316 }; | |
| 317 | |
| 318 // | |
| 319 // pageAction.* aliases for supported extensionActions APIs. | |
|
Yoyo Zhou
2012/12/19 23:30:52
extensionAction -> pageAction
Devlin
2012/12/20 19:43:20
Done.
| |
| 320 // | |
| 321 | |
| 322 class PageActionShowFunction : public ExtensionActionShowFunction { | |
| 323 public: | |
| 324 DECLARE_EXTENSION_FUNCTION_NAME("pageAction.show") | |
| 325 | |
| 326 protected: | |
| 327 virtual ~PageActionShowFunction() {} | |
| 328 }; | |
| 329 | |
| 330 class PageActionHideFunction : public ExtensionActionHideFunction { | |
| 331 public: | |
| 332 DECLARE_EXTENSION_FUNCTION_NAME("pageAction.hide") | |
| 333 | |
| 334 protected: | |
| 335 virtual ~PageActionHideFunction() {} | |
| 336 }; | |
| 337 | |
| 338 class PageActionSetIconFunction : public ExtensionActionSetIconFunction { | |
| 339 public: | |
| 340 DECLARE_EXTENSION_FUNCTION_NAME("pageAction.setIcon") | |
| 341 | |
| 342 protected: | |
| 343 virtual ~PageActionSetIconFunction() {} | |
| 344 }; | |
| 345 | |
| 346 class PageActionSetTitleFunction : public ExtensionActionSetTitleFunction { | |
| 347 public: | |
| 348 DECLARE_EXTENSION_FUNCTION_NAME("pageAction.setTitle") | |
| 349 | |
| 350 protected: | |
| 351 virtual ~PageActionSetTitleFunction() {} | |
| 352 }; | |
| 353 | |
| 354 class PageActionSetPopupFunction : public ExtensionActionSetPopupFunction { | |
| 355 public: | |
| 356 DECLARE_EXTENSION_FUNCTION_NAME("pageAction.setPopup") | |
| 357 | |
| 358 protected: | |
| 359 virtual ~PageActionSetPopupFunction() {} | |
| 360 }; | |
| 361 | |
| 362 class PageActionGetTitleFunction : public ExtensionActionGetTitleFunction { | |
| 363 public: | |
| 364 DECLARE_EXTENSION_FUNCTION_NAME("pageAction.getTitle") | |
| 365 | |
| 366 protected: | |
| 367 virtual ~PageActionGetTitleFunction() {} | |
| 368 }; | |
| 369 | |
| 370 class PageActionGetPopupFunction : public ExtensionActionGetPopupFunction { | |
| 371 public: | |
| 372 DECLARE_EXTENSION_FUNCTION_NAME("pageAction.getPopup") | |
| 373 | |
| 374 protected: | |
| 375 virtual ~PageActionGetPopupFunction() {} | |
| 376 }; | |
| 377 | |
| 378 // | |
| 379 // scriptBadge.* aliases for supported scriptBadge APIs. | |
| 380 // | |
| 381 | |
| 382 class ScriptBadgeSetPopupFunction : public ExtensionActionSetPopupFunction { | |
| 383 public: | |
| 384 DECLARE_EXTENSION_FUNCTION_NAME("scriptBadge.setPopup") | |
| 385 | |
| 386 protected: | |
| 387 virtual ~ScriptBadgeSetPopupFunction() {} | |
| 388 }; | |
| 389 | |
| 390 class ScriptBadgeGetPopupFunction : public ExtensionActionGetPopupFunction { | |
| 391 public: | |
| 392 DECLARE_EXTENSION_FUNCTION_NAME("scriptBadge.getPopup") | |
| 393 | |
| 394 protected: | |
| 395 virtual ~ScriptBadgeGetPopupFunction() {} | |
| 396 }; | |
| 397 | |
| 398 // scriptBadge.getAttention(tabId) | |
| 399 class ScriptBadgeGetAttentionFunction : public ExtensionActionFunction { | |
| 400 public: | |
| 401 DECLARE_EXTENSION_FUNCTION_NAME("scriptBadge.getAttention") | |
| 402 | |
| 403 virtual bool RunExtensionAction() OVERRIDE; | |
| 404 | |
| 405 protected: | |
| 406 virtual ~ScriptBadgeGetAttentionFunction(); | |
| 407 }; | |
| 408 | |
| 409 } // namespace extensions | |
| 410 | |
| 411 #endif // CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTION_API_H _ | |
| OLD | NEW |