| 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/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 // Convenience method to get the instance for a profile. | 60 // Convenience method to get the instance for a profile. |
| 61 static ExtensionActionAPI* Get(content::BrowserContext* context); | 61 static ExtensionActionAPI* Get(content::BrowserContext* context); |
| 62 | 62 |
| 63 static bool GetBrowserActionVisibility(const ExtensionPrefs* prefs, | 63 static bool GetBrowserActionVisibility(const ExtensionPrefs* prefs, |
| 64 const std::string& extension_id); | 64 const std::string& extension_id); |
| 65 static void SetBrowserActionVisibility(ExtensionPrefs* prefs, | 65 static void SetBrowserActionVisibility(ExtensionPrefs* prefs, |
| 66 const std::string& extension_id, | 66 const std::string& extension_id, |
| 67 bool visible); | 67 bool visible); |
| 68 | 68 |
| 69 // Fires the onClicked event for page_action. | |
| 70 static void PageActionExecuted(content::BrowserContext* context, | |
| 71 const ExtensionAction& page_action, | |
| 72 int tab_id, | |
| 73 const std::string& url, | |
| 74 int button); | |
| 75 | |
| 76 // Fires the onClicked event for browser_action. | |
| 77 static void BrowserActionExecuted(content::BrowserContext* context, | |
| 78 const ExtensionAction& browser_action, | |
| 79 content::WebContents* web_contents); | |
| 80 | |
| 81 // BrowserContextKeyedAPI implementation. | 69 // BrowserContextKeyedAPI implementation. |
| 82 static BrowserContextKeyedAPIFactory<ExtensionActionAPI>* | 70 static BrowserContextKeyedAPIFactory<ExtensionActionAPI>* |
| 83 GetFactoryInstance(); | 71 GetFactoryInstance(); |
| 84 | 72 |
| 85 // Add or remove observers. | 73 // Add or remove observers. |
| 86 void AddObserver(Observer* observer); | 74 void AddObserver(Observer* observer); |
| 87 void RemoveObserver(Observer* observer); | 75 void RemoveObserver(Observer* observer); |
| 88 | 76 |
| 77 // Executes the action of the given |extension| on the |browser|'s active |
| 78 // web contents. If |grant_tab_permissions| is true, this will also grant |
| 79 // activeTab to the extension (so this should only be done if this is through |
| 80 // a direct user action). Returns the action that should be taken. |
| 81 ExtensionAction::ShowAction ExecuteExtensionAction( |
| 82 const Extension* extension, |
| 83 Browser* browser, |
| 84 bool grant_active_tab_permissions); |
| 85 |
| 89 void NotifyChange(ExtensionAction* extension_action, | 86 void NotifyChange(ExtensionAction* extension_action, |
| 90 content::WebContents* web_contents, | 87 content::WebContents* web_contents, |
| 91 content::BrowserContext* browser_context); | 88 content::BrowserContext* browser_context); |
| 92 | 89 |
| 93 // Clears the values for all ExtensionActions for the tab associated with the | 90 // Clears the values for all ExtensionActions for the tab associated with the |
| 94 // given |web_contents|. | 91 // given |web_contents|. |
| 95 void ClearAllValuesForTab(content::WebContents* web_contents); | 92 void ClearAllValuesForTab(content::WebContents* web_contents); |
| 96 | 93 |
| 97 private: | 94 private: |
| 98 friend class BrowserContextKeyedAPIFactory<ExtensionActionAPI>; | 95 friend class BrowserContextKeyedAPIFactory<ExtensionActionAPI>; |
| 99 | 96 |
| 100 // The DispatchEvent methods forward events to the |profile|'s event router. | 97 // The DispatchEvent methods forward events to the |context|'s event router. |
| 101 static void DispatchEventToExtension(content::BrowserContext* context, | 98 void DispatchEventToExtension(content::BrowserContext* context, |
| 102 const std::string& extension_id, | 99 const std::string& extension_id, |
| 103 const std::string& event_name, | 100 const std::string& event_name, |
| 104 scoped_ptr<base::ListValue> event_args); | 101 scoped_ptr<base::ListValue> event_args); |
| 105 | 102 |
| 106 // Called when either a browser or page action is executed. Figures out which | 103 // Called when either a browser or page action is executed. Figures out which |
| 107 // event to send based on what the extension wants. | 104 // event to send based on what the extension wants. |
| 108 static void ExtensionActionExecuted(content::BrowserContext* context, | 105 void ExtensionActionExecuted(const ExtensionAction& extension_action, |
| 109 const ExtensionAction& extension_action, | 106 content::WebContents* web_contents); |
| 110 content::WebContents* web_contents); | |
| 111 | 107 |
| 112 // BrowserContextKeyedAPI implementation. | 108 // BrowserContextKeyedAPI implementation. |
| 113 virtual void Shutdown() OVERRIDE; | 109 virtual void Shutdown() OVERRIDE; |
| 114 static const char* service_name() { return "ExtensionActionAPI"; } | 110 static const char* service_name() { return "ExtensionActionAPI"; } |
| 115 static const bool kServiceRedirectedInIncognito = true; | 111 static const bool kServiceRedirectedInIncognito = true; |
| 116 | 112 |
| 117 ObserverList<Observer> observers_; | 113 ObserverList<Observer> observers_; |
| 118 | 114 |
| 119 content::BrowserContext* browser_context_; | 115 content::BrowserContext* browser_context_; |
| 120 | 116 |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 class PageActionGetPopupFunction | 464 class PageActionGetPopupFunction |
| 469 : public extensions::ExtensionActionGetPopupFunction { | 465 : public extensions::ExtensionActionGetPopupFunction { |
| 470 public: | 466 public: |
| 471 DECLARE_EXTENSION_FUNCTION("pageAction.getPopup", PAGEACTION_GETPOPUP) | 467 DECLARE_EXTENSION_FUNCTION("pageAction.getPopup", PAGEACTION_GETPOPUP) |
| 472 | 468 |
| 473 protected: | 469 protected: |
| 474 virtual ~PageActionGetPopupFunction() {} | 470 virtual ~PageActionGetPopupFunction() {} |
| 475 }; | 471 }; |
| 476 | 472 |
| 477 #endif // CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTION_API_H
_ | 473 #endif // CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTION_API_H
_ |
| OLD | NEW |