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