| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 GetFactoryInstance(); | 71 GetFactoryInstance(); |
| 72 | 72 |
| 73 // Add or remove observers. | 73 // Add or remove observers. |
| 74 void AddObserver(Observer* observer); | 74 void AddObserver(Observer* observer); |
| 75 void RemoveObserver(Observer* observer); | 75 void RemoveObserver(Observer* observer); |
| 76 | 76 |
| 77 bool GetBrowserActionVisibility(const std::string& extension_id); | 77 bool GetBrowserActionVisibility(const std::string& extension_id); |
| 78 void SetBrowserActionVisibility(const std::string& extension_id, | 78 void SetBrowserActionVisibility(const std::string& extension_id, |
| 79 bool visible); | 79 bool visible); |
| 80 | 80 |
| 81 // Executes the action of the given |extension| on the |browser|'s active | |
| 82 // web contents. If |grant_tab_permissions| is true, this will also grant | |
| 83 // activeTab to the extension (so this should only be done if this is through | |
| 84 // a direct user action). Returns the action that should be taken. | |
| 85 ExtensionAction::ShowAction ExecuteExtensionAction( | |
| 86 const Extension* extension, | |
| 87 Browser* browser, | |
| 88 bool grant_active_tab_permissions); | |
| 89 | |
| 90 // Opens the popup for the given |extension| in the given |browser|'s window. | 81 // Opens the popup for the given |extension| in the given |browser|'s window. |
| 91 // If |grant_active_tab_permissions| is true, this grants the extension | 82 // If |grant_active_tab_permissions| is true, this grants the extension |
| 92 // activeTab (so this should only be done if this is through a direct user | 83 // activeTab (so this should only be done if this is through a direct user |
| 93 // action). | 84 // action). |
| 94 bool ShowExtensionActionPopup(const Extension* extension, | 85 bool ShowExtensionActionPopup(const Extension* extension, |
| 95 Browser* browser, | 86 Browser* browser, |
| 96 bool grant_active_tab_permissions); | 87 bool grant_active_tab_permissions); |
| 97 | 88 |
| 98 // Returns true if the |extension| has a visible page action on the given | |
| 99 // |web_contents|. | |
| 100 bool PageActionWantsToRun(const Extension* extension, | |
| 101 content::WebContents* web_contents); | |
| 102 | |
| 103 // Returns true if the |extension| has a blocked script that wants to inject | |
| 104 // on the given |web_contents|. | |
| 105 bool HasBeenBlocked(const Extension* extension, | |
| 106 content::WebContents* web_contents); | |
| 107 | |
| 108 // Notifies that there has been a change in the given |extension_action|. | 89 // Notifies that there has been a change in the given |extension_action|. |
| 109 void NotifyChange(ExtensionAction* extension_action, | 90 void NotifyChange(ExtensionAction* extension_action, |
| 110 content::WebContents* web_contents, | 91 content::WebContents* web_contents, |
| 111 content::BrowserContext* browser_context); | 92 content::BrowserContext* browser_context); |
| 112 | 93 |
| 94 // Dispatches the onClicked event for extension that owns the given action. |
| 95 void DispatchExtensionActionClicked(const ExtensionAction& extension_action, |
| 96 content::WebContents* web_contents); |
| 97 |
| 113 // Clears the values for all ExtensionActions for the tab associated with the | 98 // Clears the values for all ExtensionActions for the tab associated with the |
| 114 // given |web_contents| (and signals that page actions changed). | 99 // given |web_contents| (and signals that page actions changed). |
| 115 void ClearAllValuesForTab(content::WebContents* web_contents); | 100 void ClearAllValuesForTab(content::WebContents* web_contents); |
| 116 | 101 |
| 117 // Notifies that the current set of page actions for |web_contents| has | 102 // Notifies that the current set of page actions for |web_contents| has |
| 118 // changed, and signals the browser to update. | 103 // changed, and signals the browser to update. |
| 119 void NotifyPageActionsChanged(content::WebContents* web_contents); | 104 void NotifyPageActionsChanged(content::WebContents* web_contents); |
| 120 | 105 |
| 121 void set_prefs_for_testing(ExtensionPrefs* prefs) { | 106 void set_prefs_for_testing(ExtensionPrefs* prefs) { |
| 122 extension_prefs_ = prefs; | 107 extension_prefs_ = prefs; |
| 123 } | 108 } |
| 124 | 109 |
| 125 private: | 110 private: |
| 126 friend class BrowserContextKeyedAPIFactory<ExtensionActionAPI>; | 111 friend class BrowserContextKeyedAPIFactory<ExtensionActionAPI>; |
| 127 | 112 |
| 128 // Returns the associated extension prefs. | 113 // Returns the associated extension prefs. |
| 129 ExtensionPrefs* GetExtensionPrefs(); | 114 ExtensionPrefs* GetExtensionPrefs(); |
| 130 | 115 |
| 131 // The DispatchEvent methods forward events to the |context|'s event router. | 116 // The DispatchEvent methods forward events to the |context|'s event router. |
| 132 void DispatchEventToExtension(content::BrowserContext* context, | 117 void DispatchEventToExtension(content::BrowserContext* context, |
| 133 const std::string& extension_id, | 118 const std::string& extension_id, |
| 134 events::HistogramValue histogram_value, | 119 events::HistogramValue histogram_value, |
| 135 const std::string& event_name, | 120 const std::string& event_name, |
| 136 scoped_ptr<base::ListValue> event_args); | 121 scoped_ptr<base::ListValue> event_args); |
| 137 | 122 |
| 138 // Called when either a browser or page action is executed. Figures out which | |
| 139 // event to send based on what the extension wants. | |
| 140 void ExtensionActionExecuted(const ExtensionAction& extension_action, | |
| 141 content::WebContents* web_contents); | |
| 142 | |
| 143 // BrowserContextKeyedAPI implementation. | 123 // BrowserContextKeyedAPI implementation. |
| 144 void Shutdown() override; | 124 void Shutdown() override; |
| 145 static const char* service_name() { return "ExtensionActionAPI"; } | 125 static const char* service_name() { return "ExtensionActionAPI"; } |
| 146 static const bool kServiceRedirectedInIncognito = true; | 126 static const bool kServiceRedirectedInIncognito = true; |
| 147 | 127 |
| 148 base::ObserverList<Observer> observers_; | 128 base::ObserverList<Observer> observers_; |
| 149 | 129 |
| 150 content::BrowserContext* browser_context_; | 130 content::BrowserContext* browser_context_; |
| 151 | 131 |
| 152 ExtensionPrefs* extension_prefs_; | 132 ExtensionPrefs* extension_prefs_; |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 class PageActionGetPopupFunction | 441 class PageActionGetPopupFunction |
| 462 : public extensions::ExtensionActionGetPopupFunction { | 442 : public extensions::ExtensionActionGetPopupFunction { |
| 463 public: | 443 public: |
| 464 DECLARE_EXTENSION_FUNCTION("pageAction.getPopup", PAGEACTION_GETPOPUP) | 444 DECLARE_EXTENSION_FUNCTION("pageAction.getPopup", PAGEACTION_GETPOPUP) |
| 465 | 445 |
| 466 protected: | 446 protected: |
| 467 ~PageActionGetPopupFunction() override {} | 447 ~PageActionGetPopupFunction() override {} |
| 468 }; | 448 }; |
| 469 | 449 |
| 470 #endif // CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTION_API_H
_ | 450 #endif // CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTION_API_H
_ |
| OLD | NEW |