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" |
11 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" | 11 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" |
12 #include "chrome/browser/extensions/chrome_extension_function.h" | 12 #include "chrome/browser/extensions/chrome_extension_function.h" |
13 #include "chrome/browser/extensions/extension_action.h" | 13 #include "chrome/browser/extensions/extension_action.h" |
14 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class DictionaryValue; | 18 class DictionaryValue; |
19 } | 19 } |
20 | 20 |
21 namespace content { | 21 namespace content { |
| 22 class BrowserContext; |
22 class WebContents; | 23 class WebContents; |
23 } | 24 } |
24 | 25 |
25 namespace extensions { | 26 namespace extensions { |
26 class ExtensionPrefs; | 27 class ExtensionPrefs; |
27 class TabHelper; | 28 class TabHelper; |
28 | 29 |
29 class ExtensionActionAPI : public ProfileKeyedAPI { | 30 class ExtensionActionAPI : public ProfileKeyedAPI { |
30 public: | 31 public: |
31 explicit ExtensionActionAPI(Profile* profile); | 32 explicit ExtensionActionAPI(content::BrowserContext* context); |
32 virtual ~ExtensionActionAPI(); | 33 virtual ~ExtensionActionAPI(); |
33 | 34 |
34 // Convenience method to get the instance for a profile. | 35 // Convenience method to get the instance for a profile. |
35 static ExtensionActionAPI* Get(Profile* profile); | 36 static ExtensionActionAPI* Get(content::BrowserContext* context); |
36 | 37 |
37 static bool GetBrowserActionVisibility(const ExtensionPrefs* prefs, | 38 static bool GetBrowserActionVisibility(const ExtensionPrefs* prefs, |
38 const std::string& extension_id); | 39 const std::string& extension_id); |
39 static void SetBrowserActionVisibility(ExtensionPrefs* prefs, | 40 static void SetBrowserActionVisibility(ExtensionPrefs* prefs, |
40 const std::string& extension_id, | 41 const std::string& extension_id, |
41 bool visible); | 42 bool visible); |
42 | 43 |
43 // Fires the onClicked event for page_action. | 44 // Fires the onClicked event for page_action. |
44 static void PageActionExecuted(Profile* profile, | 45 static void PageActionExecuted(content::BrowserContext* context, |
45 const ExtensionAction& page_action, | 46 const ExtensionAction& page_action, |
46 int tab_id, | 47 int tab_id, |
47 const std::string& url, | 48 const std::string& url, |
48 int button); | 49 int button); |
49 | 50 |
50 // Fires the onClicked event for browser_action. | 51 // Fires the onClicked event for browser_action. |
51 static void BrowserActionExecuted(Profile* profile, | 52 static void BrowserActionExecuted(content::BrowserContext* context, |
52 const ExtensionAction& browser_action, | 53 const ExtensionAction& browser_action, |
53 content::WebContents* web_contents); | 54 content::WebContents* web_contents); |
54 | 55 |
55 // ProfileKeyedAPI implementation. | 56 // ProfileKeyedAPI implementation. |
56 static ProfileKeyedAPIFactory<ExtensionActionAPI>* GetFactoryInstance(); | 57 static ProfileKeyedAPIFactory<ExtensionActionAPI>* GetFactoryInstance(); |
57 | 58 |
58 private: | 59 private: |
59 friend class ProfileKeyedAPIFactory<ExtensionActionAPI>; | 60 friend class ProfileKeyedAPIFactory<ExtensionActionAPI>; |
60 | 61 |
61 // The DispatchEvent methods forward events to the |profile|'s event router. | 62 // The DispatchEvent methods forward events to the |profile|'s event router. |
62 static void DispatchEventToExtension(Profile* profile, | 63 static void DispatchEventToExtension(content::BrowserContext* context, |
63 const std::string& extension_id, | 64 const std::string& extension_id, |
64 const std::string& event_name, | 65 const std::string& event_name, |
65 scoped_ptr<base::ListValue> event_args); | 66 scoped_ptr<base::ListValue> event_args); |
66 | 67 |
67 // Called to dispatch a deprecated style page action click event that was | 68 // Called to dispatch a deprecated style page action click event that was |
68 // registered like: | 69 // registered like: |
69 // chrome.pageActions["name"].addListener(function(actionId, info){}) | 70 // chrome.pageActions["name"].addListener(function(actionId, info){}) |
70 static void DispatchOldPageActionEvent(Profile* profile, | 71 static void DispatchOldPageActionEvent(content::BrowserContext* context, |
71 const std::string& extension_id, | 72 const std::string& extension_id, |
72 const std::string& page_action_id, | 73 const std::string& page_action_id, |
73 int tab_id, | 74 int tab_id, |
74 const std::string& url, | 75 const std::string& url, |
75 int button); | 76 int button); |
76 | 77 |
77 // Called when either a browser or page action is executed. Figures out which | 78 // Called when either a browser or page action is executed. Figures out which |
78 // event to send based on what the extension wants. | 79 // event to send based on what the extension wants. |
79 static void ExtensionActionExecuted(Profile* profile, | 80 static void ExtensionActionExecuted(content::BrowserContext* context, |
80 const ExtensionAction& extension_action, | 81 const ExtensionAction& extension_action, |
81 content::WebContents* web_contents); | 82 content::WebContents* web_contents); |
82 | 83 |
83 // ProfileKeyedAPI implementation. | 84 // ProfileKeyedAPI implementation. |
84 static const char* service_name() { return "ExtensionActionAPI"; } | 85 static const char* service_name() { return "ExtensionActionAPI"; } |
85 | 86 |
86 DISALLOW_COPY_AND_ASSIGN(ExtensionActionAPI); | 87 DISALLOW_COPY_AND_ASSIGN(ExtensionActionAPI); |
87 }; | 88 }; |
88 | 89 |
89 // This class manages reading and writing browser action values from storage. | 90 // This class manages reading and writing browser action values from storage. |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 PAGEACTIONS_DISABLEFORTAB) | 458 PAGEACTIONS_DISABLEFORTAB) |
458 | 459 |
459 protected: | 460 protected: |
460 virtual ~DisablePageActionsFunction() {} | 461 virtual ~DisablePageActionsFunction() {} |
461 | 462 |
462 // ExtensionFunction: | 463 // ExtensionFunction: |
463 virtual bool RunImpl() OVERRIDE; | 464 virtual bool RunImpl() OVERRIDE; |
464 }; | 465 }; |
465 | 466 |
466 #endif // CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTION_API_H
_ | 467 #endif // CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTION_API_H
_ |
OLD | NEW |