Chromium Code Reviews| Index: chrome/browser/extensions/api/extension_action/extension_action_api.h |
| diff --git a/chrome/browser/extensions/api/extension_action/extension_action_api.h b/chrome/browser/extensions/api/extension_action/extension_action_api.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..11775d83eb2ee74d1665cea18bb83b91b15a41bf |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/extension_action/extension_action_api.h |
| @@ -0,0 +1,411 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTION_API_H_ |
| +#define CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTION_API_H_ |
| + |
| +#include "base/memory/weak_ptr.h" |
| +#include "chrome/browser/extensions/extension_action.h" |
| +#include "chrome/browser/extensions/extension_function.h" |
| +#include "chrome/browser/profiles/profile_keyed_service.h" |
| +#include "content/public/browser/notification_observer.h" |
| +#include "content/public/browser/notification_registrar.h" |
| + |
| +namespace base { |
| +class DictionaryValue; |
| +} |
| + |
| +namespace content { |
| +class WebContents; |
| +} |
| + |
| +namespace extensions { |
| +class TabHelper; |
| +} |
| + |
| +namespace extensions { |
| + |
| +class ExtensionActionAPI : public ProfileKeyedService { |
| + public: |
| + explicit ExtensionActionAPI(Profile* profile); |
| + virtual ~ExtensionActionAPI(); |
| + |
| + // ProfileKeyedService implementation. |
| + virtual void Shutdown() OVERRIDE; |
| +}; |
| + |
| +// This class manages reading and writing browser action values from storage. |
| +class ExtensionActionStorageManager |
| + : public content::NotificationObserver, |
| + public base::SupportsWeakPtr<ExtensionActionStorageManager> { |
| + public: |
| + explicit ExtensionActionStorageManager(Profile* profile); |
| + virtual ~ExtensionActionStorageManager(); |
| + |
| + private: |
| + // NotificationObserver: |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE; |
| + |
| + // Reads/Writes the ExtensionAction's default values to/from storage. |
| + void WriteToStorage(ExtensionAction* extension_action); |
| + void ReadFromStorage( |
| + const std::string& extension_id, scoped_ptr<base::Value> value); |
| + |
| + Profile* profile_; |
| + content::NotificationRegistrar registrar_; |
| +}; |
| + |
| +// Implementation of the browserAction, pageAction, and scriptBadge APIs. |
| +// |
| +// Divergent behaviour between the three is minimal (pageAction and scriptBadge |
| +// have required tabIds while browserAction's are optional, they have different |
| +// internal browser notification requirements, and not all functions are defined |
| +// for all APIs). |
| +class ExtensionActionFunction : public SyncExtensionFunction { |
| + public: |
| + static bool ParseCSSColorString(const std::string& color_string, |
| + SkColor* result); |
| + |
| + protected: |
| + ExtensionActionFunction(); |
| + virtual ~ExtensionActionFunction(); |
| + virtual bool RunImpl() OVERRIDE; |
| + virtual bool RunExtensionAction() = 0; |
| + |
| + bool ExtractDataFromArguments(); |
| + void NotifyChange(); |
| + void NotifyBrowserActionChange(); |
| + void NotifyLocationBarChange(); |
| + void NotifySystemIndicatorChange(); |
| + bool SetVisible(bool visible); |
| + |
| + // Extension-related information for |tab_id_|. |
| + // CHECK-fails if there is no tab. |
| + extensions::TabHelper& tab_helper() const; |
| + |
| + // All the extension action APIs take a single argument called details that |
| + // is a dictionary. |
| + base::DictionaryValue* details_; |
| + |
| + // The tab id the extension action function should apply to, if any, or |
| + // kDefaultTabId if none was specified. |
| + int tab_id_; |
| + |
| + // WebContents for |tab_id_| if one exists. |
| + content::WebContents* contents_; |
| + |
| + // The extension action for the current extension. |
| + ExtensionAction* extension_action_; |
| +}; |
| + |
| +// |
| +// Implementations of each extension action API. |
| +// |
| +// pageAction and browserAction bindings are created for these by extending them |
| +// then declaring an EXTENSION_FUNCTION_NAME. |
| +// |
| + |
| +// show |
| +class ExtensionActionShowFunction : public ExtensionActionFunction { |
| + protected: |
| + virtual ~ExtensionActionShowFunction() {} |
| + virtual bool RunExtensionAction() OVERRIDE; |
| +}; |
| + |
| +// hide |
| +class ExtensionActionHideFunction : public ExtensionActionFunction { |
| + protected: |
| + virtual ~ExtensionActionHideFunction() {} |
| + virtual bool RunExtensionAction() OVERRIDE; |
| +}; |
| + |
| +// setIcon |
| +class ExtensionActionSetIconFunction : public ExtensionActionFunction { |
| + protected: |
| + virtual ~ExtensionActionSetIconFunction() {} |
| + virtual bool RunExtensionAction() OVERRIDE; |
| +}; |
| + |
| +// setTitle |
| +class ExtensionActionSetTitleFunction : public ExtensionActionFunction { |
| + protected: |
| + virtual ~ExtensionActionSetTitleFunction() {} |
| + virtual bool RunExtensionAction() OVERRIDE; |
| +}; |
| + |
| +// setPopup |
| +class ExtensionActionSetPopupFunction : public ExtensionActionFunction { |
| + protected: |
| + virtual ~ExtensionActionSetPopupFunction() {} |
| + virtual bool RunExtensionAction() OVERRIDE; |
| +}; |
| + |
| +// setBadgeText |
| +class ExtensionActionSetBadgeTextFunction : public ExtensionActionFunction { |
| + protected: |
| + virtual ~ExtensionActionSetBadgeTextFunction() {} |
| + virtual bool RunExtensionAction() OVERRIDE; |
| +}; |
| + |
| +// setBadgeBackgroundColor |
| +class ExtensionActionSetBadgeBackgroundColorFunction |
| + : public ExtensionActionFunction { |
| + protected: |
| + virtual ~ExtensionActionSetBadgeBackgroundColorFunction() {} |
| + virtual bool RunExtensionAction() OVERRIDE; |
| +}; |
| + |
| +// getTitle |
| +class ExtensionActionGetTitleFunction : public ExtensionActionFunction { |
| + protected: |
| + virtual ~ExtensionActionGetTitleFunction() {} |
| + virtual bool RunExtensionAction() OVERRIDE; |
| +}; |
| + |
| +// getPopup |
| +class ExtensionActionGetPopupFunction : public ExtensionActionFunction { |
| + protected: |
| + virtual ~ExtensionActionGetPopupFunction() {} |
| + virtual bool RunExtensionAction() OVERRIDE; |
| +}; |
| + |
| +// getBadgeText |
| +class ExtensionActionGetBadgeTextFunction : public ExtensionActionFunction { |
| + protected: |
| + virtual ~ExtensionActionGetBadgeTextFunction() {} |
| + virtual bool RunExtensionAction() OVERRIDE; |
| +}; |
| + |
| +// getBadgeBackgroundColor |
| +class ExtensionActionGetBadgeBackgroundColorFunction |
| + : public ExtensionActionFunction { |
| + protected: |
| + virtual ~ExtensionActionGetBadgeBackgroundColorFunction() {} |
| + virtual bool RunExtensionAction() OVERRIDE; |
| +}; |
| + |
| +// |
| +// browserAction.* aliases for supported browserActions APIs. |
|
Yoyo Zhou
2012/12/19 23:30:52
nit: browserAction
Devlin
2012/12/20 19:43:20
Done.
|
| +// |
| + |
| +class BrowserActionSetIconFunction : public ExtensionActionSetIconFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("browserAction.setIcon") |
| + |
| + protected: |
| + virtual ~BrowserActionSetIconFunction() {} |
| +}; |
| + |
| +class BrowserActionSetTitleFunction : public ExtensionActionSetTitleFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("browserAction.setTitle") |
| + |
| + protected: |
| + virtual ~BrowserActionSetTitleFunction() {} |
| +}; |
| + |
| +class BrowserActionSetPopupFunction : public ExtensionActionSetPopupFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("browserAction.setPopup") |
| + |
| + protected: |
| + virtual ~BrowserActionSetPopupFunction() {} |
| +}; |
| + |
| +class BrowserActionGetTitleFunction : public ExtensionActionGetTitleFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("browserAction.getTitle") |
| + |
| + protected: |
| + virtual ~BrowserActionGetTitleFunction() {} |
| +}; |
| + |
| +class BrowserActionGetPopupFunction : public ExtensionActionGetPopupFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("browserAction.getPopup") |
| + |
| + protected: |
| + virtual ~BrowserActionGetPopupFunction() {} |
| +}; |
| + |
| +class BrowserActionSetBadgeTextFunction |
| + : public ExtensionActionSetBadgeTextFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("browserAction.setBadgeText") |
| + |
| + protected: |
| + virtual ~BrowserActionSetBadgeTextFunction() {} |
| +}; |
| + |
| +class BrowserActionSetBadgeBackgroundColorFunction |
| + : public ExtensionActionSetBadgeBackgroundColorFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("browserAction.setBadgeBackgroundColor") |
| + |
| + protected: |
| + virtual ~BrowserActionSetBadgeBackgroundColorFunction() {} |
| +}; |
| + |
| +class BrowserActionGetBadgeTextFunction |
| + : public ExtensionActionGetBadgeTextFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("browserAction.getBadgeText") |
| + |
| + protected: |
| + virtual ~BrowserActionGetBadgeTextFunction() {} |
| +}; |
| + |
| +class BrowserActionGetBadgeBackgroundColorFunction |
| + : public ExtensionActionGetBadgeBackgroundColorFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("browserAction.getBadgeBackgroundColor") |
| + |
| + protected: |
| + virtual ~BrowserActionGetBadgeBackgroundColorFunction() {} |
| +}; |
| + |
| +class BrowserActionEnableFunction : public ExtensionActionShowFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("browserAction.enable") |
| + |
| + protected: |
| + virtual ~BrowserActionEnableFunction() {} |
| +}; |
| + |
| +class BrowserActionDisableFunction : public ExtensionActionHideFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("browserAction.disable") |
| + |
| + protected: |
| + virtual ~BrowserActionDisableFunction() {} |
| +}; |
| + |
| +// 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.
|
| +class PageActionFunction : public SyncExtensionFunction { |
| + protected: |
| + PageActionFunction(); |
| + virtual ~PageActionFunction(); |
| + bool SetPageActionEnabled(bool enable); |
| +}; |
| + |
| +// Implement chrome.pageActions.enableForTab(). |
| +class EnablePageActionFunction : public PageActionFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("pageActions.enableForTab") |
| + |
| + protected: |
| + virtual ~EnablePageActionFunction() {} |
| + |
| + // ExtensionFunction: |
| + virtual bool RunImpl() OVERRIDE; |
| +}; |
| + |
| +// Implement chrome.pageActions.disableForTab(). |
| +class DisablePageActionFunction : public PageActionFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("pageActions.disableForTab") |
| + |
| + protected: |
| + virtual ~DisablePageActionFunction() {} |
| + |
| + // ExtensionFunction: |
| + virtual bool RunImpl() OVERRIDE; |
| +}; |
| + |
| +// |
| +// pageAction.* aliases for supported extensionActions APIs. |
|
Yoyo Zhou
2012/12/19 23:30:52
extensionAction -> pageAction
Devlin
2012/12/20 19:43:20
Done.
|
| +// |
| + |
| +class PageActionShowFunction : public ExtensionActionShowFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("pageAction.show") |
| + |
| + protected: |
| + virtual ~PageActionShowFunction() {} |
| +}; |
| + |
| +class PageActionHideFunction : public ExtensionActionHideFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("pageAction.hide") |
| + |
| + protected: |
| + virtual ~PageActionHideFunction() {} |
| +}; |
| + |
| +class PageActionSetIconFunction : public ExtensionActionSetIconFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("pageAction.setIcon") |
| + |
| + protected: |
| + virtual ~PageActionSetIconFunction() {} |
| +}; |
| + |
| +class PageActionSetTitleFunction : public ExtensionActionSetTitleFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("pageAction.setTitle") |
| + |
| + protected: |
| + virtual ~PageActionSetTitleFunction() {} |
| +}; |
| + |
| +class PageActionSetPopupFunction : public ExtensionActionSetPopupFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("pageAction.setPopup") |
| + |
| + protected: |
| + virtual ~PageActionSetPopupFunction() {} |
| +}; |
| + |
| +class PageActionGetTitleFunction : public ExtensionActionGetTitleFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("pageAction.getTitle") |
| + |
| + protected: |
| + virtual ~PageActionGetTitleFunction() {} |
| +}; |
| + |
| +class PageActionGetPopupFunction : public ExtensionActionGetPopupFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("pageAction.getPopup") |
| + |
| + protected: |
| + virtual ~PageActionGetPopupFunction() {} |
| +}; |
| + |
| +// |
| +// scriptBadge.* aliases for supported scriptBadge APIs. |
| +// |
| + |
| +class ScriptBadgeSetPopupFunction : public ExtensionActionSetPopupFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("scriptBadge.setPopup") |
| + |
| + protected: |
| + virtual ~ScriptBadgeSetPopupFunction() {} |
| +}; |
| + |
| +class ScriptBadgeGetPopupFunction : public ExtensionActionGetPopupFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("scriptBadge.getPopup") |
| + |
| + protected: |
| + virtual ~ScriptBadgeGetPopupFunction() {} |
| +}; |
| + |
| +// scriptBadge.getAttention(tabId) |
| +class ScriptBadgeGetAttentionFunction : public ExtensionActionFunction { |
| + public: |
| + DECLARE_EXTENSION_FUNCTION_NAME("scriptBadge.getAttention") |
| + |
| + virtual bool RunExtensionAction() OVERRIDE; |
| + |
| + protected: |
| + virtual ~ScriptBadgeGetAttentionFunction(); |
| +}; |
| + |
| +} // namespace extensions |
| + |
| +#endif // CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTION_API_H_ |