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 EXTENSIONS_BROWSER_API_MANAGEMENT_MANAGEMENT_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_ | 6 #define EXTENSIONS_BROWSER_API_MANAGEMENT_MANAGEMENT_API_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/scoped_observer.h" | 9 #include "base/scoped_observer.h" |
10 #include "base/task/cancelable_task_tracker.h" | |
11 #include "chrome/browser/extensions/bookmark_app_helper.h" | |
12 #include "chrome/browser/extensions/chrome_extension_function.h" | |
13 #include "chrome/browser/extensions/extension_install_prompt.h" | |
14 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | |
15 #include "chrome/common/web_application_info.h" | |
16 #include "components/favicon_base/favicon_types.h" | |
17 #include "components/keyed_service/core/keyed_service.h" | 10 #include "components/keyed_service/core/keyed_service.h" |
| 11 #include "extensions/browser/api/management/management_api_delegate.h" |
18 #include "extensions/browser/browser_context_keyed_api_factory.h" | 12 #include "extensions/browser/browser_context_keyed_api_factory.h" |
19 #include "extensions/browser/event_router.h" | 13 #include "extensions/browser/event_router.h" |
| 14 #include "extensions/browser/extension_function.h" |
20 #include "extensions/browser/extension_registry_observer.h" | 15 #include "extensions/browser/extension_registry_observer.h" |
21 | 16 |
22 class ExtensionService; | 17 class ExtensionRegistry; |
23 class ExtensionUninstallDialog; | 18 class ExtensionUninstallDialog; |
| 19 struct WebApplicationInfo; |
24 | 20 |
25 namespace extensions { | 21 namespace extensions { |
26 class ExtensionRegistry; | 22 class ExtensionRegistry; |
27 | 23 |
28 class ManagementFunction : public ChromeSyncExtensionFunction { | 24 class ManagementFunction : public SyncExtensionFunction { |
29 protected: | 25 protected: |
30 ~ManagementFunction() override {} | 26 ~ManagementFunction() override {} |
31 | |
32 ExtensionService* service(); | |
33 }; | 27 }; |
34 | 28 |
35 class AsyncManagementFunction : public ChromeAsyncExtensionFunction { | 29 class AsyncManagementFunction : public AsyncExtensionFunction { |
36 protected: | 30 protected: |
37 ~AsyncManagementFunction() override {} | 31 ~AsyncManagementFunction() override {} |
38 | |
39 ExtensionService* service(); | |
40 }; | 32 }; |
41 | 33 |
42 class ManagementGetAllFunction : public ManagementFunction { | 34 class ManagementGetAllFunction : public ManagementFunction { |
43 public: | 35 public: |
44 DECLARE_EXTENSION_FUNCTION("management.getAll", MANAGEMENT_GETALL) | 36 DECLARE_EXTENSION_FUNCTION("management.getAll", MANAGEMENT_GETALL) |
45 | 37 |
46 protected: | 38 protected: |
47 ~ManagementGetAllFunction() override {} | 39 ~ManagementGetAllFunction() override {} |
48 | 40 |
49 // ExtensionFunction: | 41 // ExtensionFunction: |
(...skipping 28 matching lines...) Expand all Loading... |
78 MANAGEMENT_GETPERMISSIONWARNINGSBYID) | 70 MANAGEMENT_GETPERMISSIONWARNINGSBYID) |
79 | 71 |
80 protected: | 72 protected: |
81 ~ManagementGetPermissionWarningsByIdFunction() override {} | 73 ~ManagementGetPermissionWarningsByIdFunction() override {} |
82 | 74 |
83 // ExtensionFunction: | 75 // ExtensionFunction: |
84 bool RunSync() override; | 76 bool RunSync() override; |
85 }; | 77 }; |
86 | 78 |
87 class ManagementGetPermissionWarningsByManifestFunction | 79 class ManagementGetPermissionWarningsByManifestFunction |
88 : public ChromeAsyncExtensionFunction { | 80 : public AsyncExtensionFunction { |
89 public: | 81 public: |
90 DECLARE_EXTENSION_FUNCTION( | 82 DECLARE_EXTENSION_FUNCTION("management.getPermissionWarningsByManifest", |
91 "management.getPermissionWarningsByManifest", | 83 MANAGEMENT_GETPERMISSIONWARNINGSBYMANIFEST); |
92 MANAGEMENT_GETPERMISSIONWARNINGSBYMANIFEST); | |
93 | 84 |
94 // Called when utility process finishes. | 85 // Called when utility process finishes. |
95 void OnParseSuccess(scoped_ptr<base::DictionaryValue> parsed_manifest); | 86 void OnParseSuccess(scoped_ptr<base::DictionaryValue> parsed_manifest); |
96 void OnParseFailure(const std::string& error); | 87 void OnParseFailure(const std::string& error); |
97 | 88 |
98 protected: | 89 protected: |
99 ~ManagementGetPermissionWarningsByManifestFunction() override {} | 90 ~ManagementGetPermissionWarningsByManifestFunction() override {} |
100 | 91 |
101 // ExtensionFunction: | 92 // ExtensionFunction: |
102 bool RunAsync() override; | 93 bool RunAsync() override; |
103 }; | 94 }; |
104 | 95 |
105 class ManagementLaunchAppFunction : public ManagementFunction { | 96 class ManagementLaunchAppFunction : public ManagementFunction { |
106 public: | 97 public: |
107 DECLARE_EXTENSION_FUNCTION("management.launchApp", MANAGEMENT_LAUNCHAPP) | 98 DECLARE_EXTENSION_FUNCTION("management.launchApp", MANAGEMENT_LAUNCHAPP) |
108 | 99 |
109 protected: | 100 protected: |
110 ~ManagementLaunchAppFunction() override {} | 101 ~ManagementLaunchAppFunction() override {} |
111 | 102 |
112 // ExtensionFunction: | 103 // ExtensionFunction: |
113 bool RunSync() override; | 104 bool RunSync() override; |
114 }; | 105 }; |
115 | 106 |
116 class ManagementSetEnabledFunction : public AsyncManagementFunction, | 107 class ManagementSetEnabledFunction : public AsyncManagementFunction { |
117 public ExtensionInstallPrompt::Delegate { | |
118 public: | 108 public: |
119 DECLARE_EXTENSION_FUNCTION("management.setEnabled", MANAGEMENT_SETENABLED) | 109 DECLARE_EXTENSION_FUNCTION("management.setEnabled", MANAGEMENT_SETENABLED) |
120 | 110 |
121 ManagementSetEnabledFunction(); | 111 ManagementSetEnabledFunction(); |
122 | 112 |
| 113 void InstallUIProceed(); |
| 114 void InstallUIAbort(bool user_initiated); |
| 115 |
123 protected: | 116 protected: |
124 ~ManagementSetEnabledFunction() override; | 117 ~ManagementSetEnabledFunction() override; |
125 | 118 |
126 // ExtensionFunction: | 119 // ExtensionFunction: |
127 bool RunAsync() override; | 120 bool RunAsync() override; |
128 | 121 |
129 // ExtensionInstallPrompt::Delegate. | |
130 void InstallUIProceed() override; | |
131 void InstallUIAbort(bool user_initiated) override; | |
132 | |
133 private: | 122 private: |
134 std::string extension_id_; | 123 std::string extension_id_; |
135 | 124 |
136 // Used for prompting to re-enable items with permissions escalation updates. | 125 scoped_ptr<InstallPromptDelegate> install_prompt_; |
137 scoped_ptr<ExtensionInstallPrompt> install_prompt_; | |
138 }; | 126 }; |
139 | 127 |
140 class ManagementUninstallFunctionBase : public AsyncManagementFunction, | 128 class ManagementUninstallFunctionBase : public AsyncManagementFunction { |
141 public ExtensionUninstallDialog::Delegate { | |
142 public: | 129 public: |
143 ManagementUninstallFunctionBase(); | 130 ManagementUninstallFunctionBase(); |
144 | 131 |
145 static void SetAutoConfirmForTest(bool should_proceed); | 132 static void SetAutoConfirmForTest(bool should_proceed); |
146 | 133 |
147 // ExtensionUninstallDialog::Delegate implementation. | 134 void ExtensionUninstallAccepted(); |
148 void ExtensionUninstallAccepted() override; | 135 void ExtensionUninstallCanceled(); |
149 void ExtensionUninstallCanceled() override; | |
150 | 136 |
151 protected: | 137 protected: |
152 ~ManagementUninstallFunctionBase() override; | 138 ~ManagementUninstallFunctionBase() override; |
153 | 139 |
154 bool Uninstall(const std::string& extension_id, bool show_confirm_dialog); | 140 bool Uninstall(const std::string& extension_id, bool show_confirm_dialog); |
| 141 |
155 private: | 142 private: |
156 | |
157 // If should_uninstall is true, this method does the actual uninstall. | 143 // If should_uninstall is true, this method does the actual uninstall. |
158 // If |show_uninstall_dialog|, then this function will be called by one of the | 144 // If |show_uninstall_dialog|, then this function will be called by one of the |
159 // Accepted/Canceled callbacks. Otherwise, it's called directly from RunAsync. | 145 // Accepted/Canceled callbacks. Otherwise, it's called directly from RunAsync. |
160 void Finish(bool should_uninstall); | 146 void Finish(bool should_uninstall); |
161 | 147 |
162 std::string extension_id_; | 148 std::string extension_id_; |
163 scoped_ptr<ExtensionUninstallDialog> extension_uninstall_dialog_; | 149 |
| 150 scoped_ptr<UninstallDialogDelegate> uninstall_dialog_; |
164 }; | 151 }; |
165 | 152 |
166 class ManagementUninstallFunction : public ManagementUninstallFunctionBase { | 153 class ManagementUninstallFunction : public ManagementUninstallFunctionBase { |
167 public: | 154 public: |
168 DECLARE_EXTENSION_FUNCTION("management.uninstall", MANAGEMENT_UNINSTALL) | 155 DECLARE_EXTENSION_FUNCTION("management.uninstall", MANAGEMENT_UNINSTALL) |
169 | 156 |
170 ManagementUninstallFunction(); | 157 ManagementUninstallFunction(); |
171 | 158 |
172 private: | 159 private: |
173 ~ManagementUninstallFunction() override; | 160 ~ManagementUninstallFunction() override; |
174 | 161 |
175 bool RunAsync() override; | 162 bool RunAsync() override; |
176 }; | 163 }; |
177 | 164 |
178 class ManagementUninstallSelfFunction : public ManagementUninstallFunctionBase { | 165 class ManagementUninstallSelfFunction : public ManagementUninstallFunctionBase { |
179 public: | 166 public: |
180 DECLARE_EXTENSION_FUNCTION("management.uninstallSelf", | 167 DECLARE_EXTENSION_FUNCTION("management.uninstallSelf", |
181 MANAGEMENT_UNINSTALLSELF); | 168 MANAGEMENT_UNINSTALLSELF); |
182 | 169 |
183 ManagementUninstallSelfFunction(); | 170 ManagementUninstallSelfFunction(); |
184 | 171 |
185 private: | 172 private: |
186 ~ManagementUninstallSelfFunction() override; | 173 ~ManagementUninstallSelfFunction() override; |
187 | 174 |
188 bool RunAsync() override; | 175 bool RunAsync() override; |
189 }; | 176 }; |
190 | 177 |
191 class ManagementCreateAppShortcutFunction : public AsyncManagementFunction { | 178 class ManagementCreateAppShortcutFunction : public AsyncManagementFunction { |
192 public: | 179 public: |
193 DECLARE_EXTENSION_FUNCTION("management.createAppShortcut", | 180 DECLARE_EXTENSION_FUNCTION("management.createAppShortcut", |
194 MANAGEMENT_CREATEAPPSHORTCUT); | 181 MANAGEMENT_CREATEAPPSHORTCUT); |
195 | 182 |
196 ManagementCreateAppShortcutFunction(); | 183 ManagementCreateAppShortcutFunction(); |
197 | 184 |
198 void OnCloseShortcutPrompt(bool created); | 185 void OnCloseShortcutPrompt(bool created); |
199 | 186 |
200 static void SetAutoConfirmForTest(bool should_proceed); | 187 static void SetAutoConfirmForTest(bool should_proceed); |
201 | 188 |
202 protected: | 189 protected: |
203 ~ManagementCreateAppShortcutFunction() override; | 190 ~ManagementCreateAppShortcutFunction() override; |
204 | 191 |
205 bool RunAsync() override; | 192 bool RunAsync() override; |
206 }; | 193 }; |
207 | 194 |
208 class ManagementSetLaunchTypeFunction : public ManagementFunction { | 195 class ManagementSetLaunchTypeFunction : public ManagementFunction { |
209 public: | 196 public: |
210 DECLARE_EXTENSION_FUNCTION("management.setLaunchType", | 197 DECLARE_EXTENSION_FUNCTION("management.setLaunchType", |
211 MANAGEMENT_SETLAUNCHTYPE); | 198 MANAGEMENT_SETLAUNCHTYPE); |
212 | 199 |
213 protected: | 200 protected: |
214 ~ManagementSetLaunchTypeFunction() override {} | 201 ~ManagementSetLaunchTypeFunction() override {} |
215 | 202 |
216 bool RunSync() override; | 203 bool RunSync() override; |
217 }; | 204 }; |
218 | 205 |
219 class ManagementGenerateAppForLinkFunction : public AsyncManagementFunction { | 206 class ManagementGenerateAppForLinkFunction : public AsyncManagementFunction { |
220 public: | 207 public: |
221 DECLARE_EXTENSION_FUNCTION("management.generateAppForLink", | 208 DECLARE_EXTENSION_FUNCTION("management.generateAppForLink", |
222 MANAGEMENT_GENERATEAPPFORLINK); | 209 MANAGEMENT_GENERATEAPPFORLINK); |
223 | 210 |
224 ManagementGenerateAppForLinkFunction(); | 211 ManagementGenerateAppForLinkFunction(); |
225 | 212 |
| 213 void FinishCreateBookmarkApp(const Extension* extension, |
| 214 const WebApplicationInfo& web_app_info); |
| 215 |
226 protected: | 216 protected: |
227 ~ManagementGenerateAppForLinkFunction() override; | 217 ~ManagementGenerateAppForLinkFunction() override; |
228 | 218 |
229 bool RunAsync() override; | 219 bool RunAsync() override; |
230 | 220 |
231 private: | 221 private: |
232 void OnFaviconForApp(const favicon_base::FaviconImageResult& image_result); | 222 scoped_ptr<AppForLinkDelegate> app_for_link_delegate_; |
233 void FinishCreateBookmarkApp(const Extension* extension, | |
234 const WebApplicationInfo& web_app_info); | |
235 | |
236 std::string title_; | |
237 GURL launch_url_; | |
238 | |
239 scoped_ptr<BookmarkAppHelper> bookmark_app_helper_; | |
240 | |
241 // Used for favicon loading tasks. | |
242 base::CancelableTaskTracker cancelable_task_tracker_; | |
243 }; | 223 }; |
244 | 224 |
245 class ManagementEventRouter : public ExtensionRegistryObserver { | 225 class ManagementEventRouter : public ExtensionRegistryObserver { |
246 public: | 226 public: |
247 explicit ManagementEventRouter(content::BrowserContext* context); | 227 explicit ManagementEventRouter(content::BrowserContext* context); |
248 ~ManagementEventRouter() override; | 228 ~ManagementEventRouter() override; |
249 | 229 |
250 private: | 230 private: |
251 // ExtensionRegistryObserver implementation. | 231 // ExtensionRegistryObserver implementation. |
252 void OnExtensionLoaded(content::BrowserContext* browser_context, | 232 void OnExtensionLoaded(content::BrowserContext* browser_context, |
(...skipping 27 matching lines...) Expand all Loading... |
280 | 260 |
281 // KeyedService implementation. | 261 // KeyedService implementation. |
282 void Shutdown() override; | 262 void Shutdown() override; |
283 | 263 |
284 // BrowserContextKeyedAPI implementation. | 264 // BrowserContextKeyedAPI implementation. |
285 static BrowserContextKeyedAPIFactory<ManagementAPI>* GetFactoryInstance(); | 265 static BrowserContextKeyedAPIFactory<ManagementAPI>* GetFactoryInstance(); |
286 | 266 |
287 // EventRouter::Observer implementation. | 267 // EventRouter::Observer implementation. |
288 void OnListenerAdded(const EventListenerInfo& details) override; | 268 void OnListenerAdded(const EventListenerInfo& details) override; |
289 | 269 |
| 270 // Returns the ManagementAPI delegate. |
| 271 const ManagementAPIDelegate* GetDelegate() const { return delegate_.get(); } |
| 272 |
290 private: | 273 private: |
291 friend class BrowserContextKeyedAPIFactory<ManagementAPI>; | 274 friend class BrowserContextKeyedAPIFactory<ManagementAPI>; |
292 | 275 |
293 content::BrowserContext* browser_context_; | 276 content::BrowserContext* browser_context_; |
294 | 277 |
295 // BrowserContextKeyedAPI implementation. | 278 // BrowserContextKeyedAPI implementation. |
296 static const char* service_name() { | 279 static const char* service_name() { return "ManagementAPI"; } |
297 return "ManagementAPI"; | |
298 } | |
299 static const bool kServiceIsNULLWhileTesting = true; | 280 static const bool kServiceIsNULLWhileTesting = true; |
300 | 281 |
301 // Created lazily upon OnListenerAdded. | 282 // Created lazily upon OnListenerAdded. |
302 scoped_ptr<ManagementEventRouter> management_event_router_; | 283 scoped_ptr<ManagementEventRouter> management_event_router_; |
303 | 284 |
| 285 scoped_ptr<ManagementAPIDelegate> delegate_; |
| 286 |
304 DISALLOW_COPY_AND_ASSIGN(ManagementAPI); | 287 DISALLOW_COPY_AND_ASSIGN(ManagementAPI); |
305 }; | 288 }; |
306 | 289 |
307 } // namespace extensions | 290 } // namespace extensions |
308 | 291 |
309 #endif // CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_ | 292 #endif // EXTENSIONS_BROWSER_API_MANAGEMENT_MANAGEMENT_API_H_ |
OLD | NEW |