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_MANAGEMENT_MANAGEMENT_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" |
9 #include "chrome/browser/extensions/event_router.h" | 10 #include "chrome/browser/extensions/event_router.h" |
10 #include "chrome/browser/extensions/extension_function.h" | 11 #include "chrome/browser/extensions/extension_function.h" |
11 #include "chrome/browser/extensions/extension_install_prompt.h" | 12 #include "chrome/browser/extensions/extension_install_prompt.h" |
12 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | 13 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
13 #include "chrome/browser/profiles/profile_keyed_service.h" | 14 #include "chrome/browser/profiles/profile_keyed_service.h" |
14 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
16 | 17 |
17 class ExtensionService; | 18 class ExtensionService; |
18 class ExtensionUninstallDialog; | 19 class ExtensionUninstallDialog; |
19 | 20 |
20 class ExtensionManagementFunction : public SyncExtensionFunction { | 21 namespace extensions { |
| 22 |
| 23 class ManagementFunction : public SyncExtensionFunction { |
21 protected: | 24 protected: |
22 virtual ~ExtensionManagementFunction() {} | 25 virtual ~ManagementFunction() {} |
23 | 26 |
24 ExtensionService* service(); | 27 ExtensionService* service(); |
25 }; | 28 }; |
26 | 29 |
27 class AsyncExtensionManagementFunction : public AsyncExtensionFunction { | 30 class AsyncManagementFunction : public AsyncExtensionFunction { |
28 protected: | 31 protected: |
29 virtual ~AsyncExtensionManagementFunction() {} | 32 virtual ~AsyncManagementFunction() {} |
30 | 33 |
31 ExtensionService* service(); | 34 ExtensionService* service(); |
32 }; | 35 }; |
33 | 36 |
34 class GetAllExtensionsFunction : public ExtensionManagementFunction { | 37 class GetAllExtensionsFunction : public ManagementFunction { |
35 public: | 38 public: |
36 DECLARE_EXTENSION_FUNCTION_NAME("management.getAll"); | 39 DECLARE_EXTENSION_FUNCTION_NAME("management.getAll"); |
37 | 40 |
38 protected: | 41 protected: |
39 virtual ~GetAllExtensionsFunction() {} | 42 virtual ~GetAllExtensionsFunction() {} |
40 | 43 |
41 // ExtensionFunction: | 44 // ExtensionFunction: |
42 virtual bool RunImpl() OVERRIDE; | 45 virtual bool RunImpl() OVERRIDE; |
43 }; | 46 }; |
44 | 47 |
45 class GetExtensionByIdFunction : public ExtensionManagementFunction { | 48 class GetExtensionByIdFunction : public ManagementFunction { |
46 public: | 49 public: |
47 DECLARE_EXTENSION_FUNCTION_NAME("management.get"); | 50 DECLARE_EXTENSION_FUNCTION_NAME("management.get"); |
48 | 51 |
49 protected: | 52 protected: |
50 virtual ~GetExtensionByIdFunction() {} | 53 virtual ~GetExtensionByIdFunction() {} |
51 | 54 |
52 // ExtensionFunction: | 55 // ExtensionFunction: |
53 virtual bool RunImpl() OVERRIDE; | 56 virtual bool RunImpl() OVERRIDE; |
54 }; | 57 }; |
55 | 58 |
56 class GetPermissionWarningsByIdFunction : public ExtensionManagementFunction { | 59 class GetPermissionWarningsByIdFunction : public ManagementFunction { |
57 public: | 60 public: |
58 DECLARE_EXTENSION_FUNCTION_NAME("management.getPermissionWarningsById"); | 61 DECLARE_EXTENSION_FUNCTION_NAME("management.getPermissionWarningsById"); |
59 | 62 |
60 protected: | 63 protected: |
61 virtual ~GetPermissionWarningsByIdFunction() {} | 64 virtual ~GetPermissionWarningsByIdFunction() {} |
62 | 65 |
63 // ExtensionFunction: | 66 // ExtensionFunction: |
64 virtual bool RunImpl() OVERRIDE; | 67 virtual bool RunImpl() OVERRIDE; |
65 }; | 68 }; |
66 | 69 |
67 class GetPermissionWarningsByManifestFunction : public AsyncExtensionFunction { | 70 class GetPermissionWarningsByManifestFunction : public AsyncExtensionFunction { |
68 public: | 71 public: |
69 DECLARE_EXTENSION_FUNCTION_NAME( | 72 DECLARE_EXTENSION_FUNCTION_NAME( |
70 "management.getPermissionWarningsByManifest"); | 73 "management.getPermissionWarningsByManifest"); |
71 | 74 |
72 // Called when utility process finishes. | 75 // Called when utility process finishes. |
73 void OnParseSuccess(base::DictionaryValue* parsed_manifest); | 76 void OnParseSuccess(base::DictionaryValue* parsed_manifest); |
74 void OnParseFailure(const std::string& error); | 77 void OnParseFailure(const std::string& error); |
75 | 78 |
76 protected: | 79 protected: |
77 virtual ~GetPermissionWarningsByManifestFunction() {} | 80 virtual ~GetPermissionWarningsByManifestFunction() {} |
78 | 81 |
79 // ExtensionFunction: | 82 // ExtensionFunction: |
80 virtual bool RunImpl() OVERRIDE; | 83 virtual bool RunImpl() OVERRIDE; |
81 }; | 84 }; |
82 | 85 |
83 class LaunchAppFunction : public ExtensionManagementFunction { | 86 class LaunchAppFunction : public ManagementFunction { |
84 public: | 87 public: |
85 DECLARE_EXTENSION_FUNCTION_NAME("management.launchApp"); | 88 DECLARE_EXTENSION_FUNCTION_NAME("management.launchApp"); |
86 | 89 |
87 protected: | 90 protected: |
88 virtual ~LaunchAppFunction() {} | 91 virtual ~LaunchAppFunction() {} |
89 | 92 |
90 // ExtensionFunction: | 93 // ExtensionFunction: |
91 virtual bool RunImpl() OVERRIDE; | 94 virtual bool RunImpl() OVERRIDE; |
92 }; | 95 }; |
93 | 96 |
94 class SetEnabledFunction : public AsyncExtensionManagementFunction, | 97 class SetEnabledFunction : public AsyncManagementFunction, |
95 public ExtensionInstallPrompt::Delegate { | 98 public ExtensionInstallPrompt::Delegate { |
96 public: | 99 public: |
97 DECLARE_EXTENSION_FUNCTION_NAME("management.setEnabled"); | 100 DECLARE_EXTENSION_FUNCTION_NAME("management.setEnabled"); |
98 | 101 |
99 SetEnabledFunction(); | 102 SetEnabledFunction(); |
100 | 103 |
101 protected: | 104 protected: |
102 virtual ~SetEnabledFunction(); | 105 virtual ~SetEnabledFunction(); |
103 | 106 |
104 // ExtensionFunction: | 107 // ExtensionFunction: |
105 virtual bool RunImpl() OVERRIDE; | 108 virtual bool RunImpl() OVERRIDE; |
106 | 109 |
107 // ExtensionInstallPrompt::Delegate. | 110 // ExtensionInstallPrompt::Delegate. |
108 virtual void InstallUIProceed() OVERRIDE; | 111 virtual void InstallUIProceed() OVERRIDE; |
109 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; | 112 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; |
110 | 113 |
111 private: | 114 private: |
112 std::string extension_id_; | 115 std::string extension_id_; |
113 | 116 |
114 // Used for prompting to re-enable items with permissions escalation updates. | 117 // Used for prompting to re-enable items with permissions escalation updates. |
115 scoped_ptr<ExtensionInstallPrompt> install_prompt_; | 118 scoped_ptr<ExtensionInstallPrompt> install_prompt_; |
116 }; | 119 }; |
117 | 120 |
118 class UninstallFunction : public AsyncExtensionManagementFunction, | 121 class UninstallFunction : public AsyncManagementFunction, |
119 public ExtensionUninstallDialog::Delegate { | 122 public ExtensionUninstallDialog::Delegate { |
120 public: | 123 public: |
121 DECLARE_EXTENSION_FUNCTION_NAME("management.uninstall"); | 124 DECLARE_EXTENSION_FUNCTION_NAME("management.uninstall"); |
122 | 125 |
123 UninstallFunction(); | 126 UninstallFunction(); |
124 static void SetAutoConfirmForTest(bool should_proceed); | 127 static void SetAutoConfirmForTest(bool should_proceed); |
125 | 128 |
126 // ExtensionUninstallDialog::Delegate implementation. | 129 // ExtensionUninstallDialog::Delegate implementation. |
127 virtual void ExtensionUninstallAccepted() OVERRIDE; | 130 virtual void ExtensionUninstallAccepted() OVERRIDE; |
128 virtual void ExtensionUninstallCanceled() OVERRIDE; | 131 virtual void ExtensionUninstallCanceled() OVERRIDE; |
129 | 132 |
130 private: | 133 private: |
131 virtual ~UninstallFunction(); | 134 virtual ~UninstallFunction(); |
132 | 135 |
133 virtual bool RunImpl() OVERRIDE; | 136 virtual bool RunImpl() OVERRIDE; |
134 | 137 |
135 // If should_uninstall is true, this method does the actual uninstall. | 138 // If should_uninstall is true, this method does the actual uninstall. |
136 // If |show_uninstall_dialog|, then this function will be called by one of the | 139 // If |show_uninstall_dialog|, then this function will be called by one of the |
137 // Accepted/Canceled callbacks. Otherwise, it's called directly from RunImpl. | 140 // Accepted/Canceled callbacks. Otherwise, it's called directly from RunImpl. |
138 void Finish(bool should_uninstall); | 141 void Finish(bool should_uninstall); |
139 | 142 |
140 std::string extension_id_; | 143 std::string extension_id_; |
141 scoped_ptr<ExtensionUninstallDialog> extension_uninstall_dialog_; | 144 scoped_ptr<ExtensionUninstallDialog> extension_uninstall_dialog_; |
142 }; | 145 }; |
143 | 146 |
144 class ExtensionManagementEventRouter : public content::NotificationObserver { | 147 class ManagementEventRouter : public content::NotificationObserver { |
145 public: | 148 public: |
146 explicit ExtensionManagementEventRouter(Profile* profile); | 149 explicit ManagementEventRouter(Profile* profile); |
147 virtual ~ExtensionManagementEventRouter(); | 150 virtual ~ManagementEventRouter(); |
148 | 151 |
149 private: | 152 private: |
150 // content::NotificationObserver implementation. | 153 // content::NotificationObserver implementation. |
151 virtual void Observe(int type, | 154 virtual void Observe(int type, |
152 const content::NotificationSource& source, | 155 const content::NotificationSource& source, |
153 const content::NotificationDetails& details) OVERRIDE; | 156 const content::NotificationDetails& details) OVERRIDE; |
154 | 157 |
155 content::NotificationRegistrar registrar_; | 158 content::NotificationRegistrar registrar_; |
156 | 159 |
157 Profile* profile_; | 160 Profile* profile_; |
158 | 161 |
159 DISALLOW_COPY_AND_ASSIGN(ExtensionManagementEventRouter); | 162 DISALLOW_COPY_AND_ASSIGN(ManagementEventRouter); |
160 }; | 163 }; |
161 | 164 |
162 class ExtensionManagementAPI : public ProfileKeyedService, | 165 class ManagementAPI : public ProfileKeyedAPI, |
163 public extensions::EventRouter::Observer { | 166 public extensions::EventRouter::Observer { |
164 public: | 167 public: |
165 explicit ExtensionManagementAPI(Profile* profile); | 168 explicit ManagementAPI(Profile* profile); |
166 virtual ~ExtensionManagementAPI(); | 169 virtual ~ManagementAPI(); |
167 | 170 |
168 // ProfileKeyedService implementation. | 171 // ProfileKeyedService implementation. |
169 virtual void Shutdown() OVERRIDE; | 172 virtual void Shutdown() OVERRIDE; |
170 | 173 |
| 174 // ProfileKeyedAPI implementation. |
| 175 static ProfileKeyedAPIFactory<ManagementAPI>* GetFactoryInstance(); |
| 176 |
171 // EventRouter::Observer implementation. | 177 // EventRouter::Observer implementation. |
172 virtual void OnListenerAdded(const extensions::EventListenerInfo& details) | 178 virtual void OnListenerAdded(const extensions::EventListenerInfo& details) |
173 OVERRIDE; | 179 OVERRIDE; |
174 | 180 |
175 private: | 181 private: |
| 182 friend class ProfileKeyedAPIFactory<ManagementAPI>; |
| 183 |
176 Profile* profile_; | 184 Profile* profile_; |
177 | 185 |
| 186 // ProfileKeyedAPI implementation. |
| 187 static const char* service_name() { |
| 188 return "ManagementAPI"; |
| 189 } |
| 190 static const bool kServiceIsNULLWhileTesting = true; |
| 191 |
178 // Created lazily upon OnListenerAdded. | 192 // Created lazily upon OnListenerAdded. |
179 scoped_ptr<ExtensionManagementEventRouter> management_event_router_; | 193 scoped_ptr<ManagementEventRouter> management_event_router_; |
| 194 |
| 195 DISALLOW_COPY_AND_ASSIGN(ManagementAPI); |
180 }; | 196 }; |
181 | 197 |
| 198 } // namespace extensions |
| 199 |
182 #endif // CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_ | 200 #endif // CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_ |
OLD | NEW |