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 "base/scoped_observer.h" | 9 #include "base/scoped_observer.h" |
10 #include "base/task/cancelable_task_tracker.h" | 10 #include "base/task/cancelable_task_tracker.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 }; | 40 }; |
41 | 41 |
42 class ManagementGetAllFunction : public ManagementFunction { | 42 class ManagementGetAllFunction : public ManagementFunction { |
43 public: | 43 public: |
44 DECLARE_EXTENSION_FUNCTION("management.getAll", MANAGEMENT_GETALL) | 44 DECLARE_EXTENSION_FUNCTION("management.getAll", MANAGEMENT_GETALL) |
45 | 45 |
46 protected: | 46 protected: |
47 virtual ~ManagementGetAllFunction() {} | 47 virtual ~ManagementGetAllFunction() {} |
48 | 48 |
49 // ExtensionFunction: | 49 // ExtensionFunction: |
50 virtual bool RunSync() OVERRIDE; | 50 virtual bool RunSync() override; |
51 }; | 51 }; |
52 | 52 |
53 class ManagementGetFunction : public ManagementFunction { | 53 class ManagementGetFunction : public ManagementFunction { |
54 public: | 54 public: |
55 DECLARE_EXTENSION_FUNCTION("management.get", MANAGEMENT_GET) | 55 DECLARE_EXTENSION_FUNCTION("management.get", MANAGEMENT_GET) |
56 | 56 |
57 protected: | 57 protected: |
58 virtual ~ManagementGetFunction() {} | 58 virtual ~ManagementGetFunction() {} |
59 | 59 |
60 // ExtensionFunction: | 60 // ExtensionFunction: |
61 virtual bool RunSync() OVERRIDE; | 61 virtual bool RunSync() override; |
62 }; | 62 }; |
63 | 63 |
64 class ManagementGetSelfFunction : public ManagementFunction { | 64 class ManagementGetSelfFunction : public ManagementFunction { |
65 public: | 65 public: |
66 DECLARE_EXTENSION_FUNCTION("management.getSelf", MANAGEMENT_GETSELF) | 66 DECLARE_EXTENSION_FUNCTION("management.getSelf", MANAGEMENT_GETSELF) |
67 | 67 |
68 protected: | 68 protected: |
69 virtual ~ManagementGetSelfFunction() {} | 69 virtual ~ManagementGetSelfFunction() {} |
70 | 70 |
71 // ExtensionFunction: | 71 // ExtensionFunction: |
72 virtual bool RunSync() OVERRIDE; | 72 virtual bool RunSync() override; |
73 }; | 73 }; |
74 | 74 |
75 class ManagementGetPermissionWarningsByIdFunction : public ManagementFunction { | 75 class ManagementGetPermissionWarningsByIdFunction : public ManagementFunction { |
76 public: | 76 public: |
77 DECLARE_EXTENSION_FUNCTION("management.getPermissionWarningsById", | 77 DECLARE_EXTENSION_FUNCTION("management.getPermissionWarningsById", |
78 MANAGEMENT_GETPERMISSIONWARNINGSBYID) | 78 MANAGEMENT_GETPERMISSIONWARNINGSBYID) |
79 | 79 |
80 protected: | 80 protected: |
81 virtual ~ManagementGetPermissionWarningsByIdFunction() {} | 81 virtual ~ManagementGetPermissionWarningsByIdFunction() {} |
82 | 82 |
83 // ExtensionFunction: | 83 // ExtensionFunction: |
84 virtual bool RunSync() OVERRIDE; | 84 virtual bool RunSync() override; |
85 }; | 85 }; |
86 | 86 |
87 class ManagementGetPermissionWarningsByManifestFunction | 87 class ManagementGetPermissionWarningsByManifestFunction |
88 : public ChromeAsyncExtensionFunction { | 88 : public ChromeAsyncExtensionFunction { |
89 public: | 89 public: |
90 DECLARE_EXTENSION_FUNCTION( | 90 DECLARE_EXTENSION_FUNCTION( |
91 "management.getPermissionWarningsByManifest", | 91 "management.getPermissionWarningsByManifest", |
92 MANAGEMENT_GETPERMISSIONWARNINGSBYMANIFEST); | 92 MANAGEMENT_GETPERMISSIONWARNINGSBYMANIFEST); |
93 | 93 |
94 // Called when utility process finishes. | 94 // Called when utility process finishes. |
95 void OnParseSuccess(scoped_ptr<base::DictionaryValue> parsed_manifest); | 95 void OnParseSuccess(scoped_ptr<base::DictionaryValue> parsed_manifest); |
96 void OnParseFailure(const std::string& error); | 96 void OnParseFailure(const std::string& error); |
97 | 97 |
98 protected: | 98 protected: |
99 virtual ~ManagementGetPermissionWarningsByManifestFunction() {} | 99 virtual ~ManagementGetPermissionWarningsByManifestFunction() {} |
100 | 100 |
101 // ExtensionFunction: | 101 // ExtensionFunction: |
102 virtual bool RunAsync() OVERRIDE; | 102 virtual bool RunAsync() override; |
103 }; | 103 }; |
104 | 104 |
105 class ManagementLaunchAppFunction : public ManagementFunction { | 105 class ManagementLaunchAppFunction : public ManagementFunction { |
106 public: | 106 public: |
107 DECLARE_EXTENSION_FUNCTION("management.launchApp", MANAGEMENT_LAUNCHAPP) | 107 DECLARE_EXTENSION_FUNCTION("management.launchApp", MANAGEMENT_LAUNCHAPP) |
108 | 108 |
109 protected: | 109 protected: |
110 virtual ~ManagementLaunchAppFunction() {} | 110 virtual ~ManagementLaunchAppFunction() {} |
111 | 111 |
112 // ExtensionFunction: | 112 // ExtensionFunction: |
113 virtual bool RunSync() OVERRIDE; | 113 virtual bool RunSync() override; |
114 }; | 114 }; |
115 | 115 |
116 class ManagementSetEnabledFunction : public AsyncManagementFunction, | 116 class ManagementSetEnabledFunction : public AsyncManagementFunction, |
117 public ExtensionInstallPrompt::Delegate { | 117 public ExtensionInstallPrompt::Delegate { |
118 public: | 118 public: |
119 DECLARE_EXTENSION_FUNCTION("management.setEnabled", MANAGEMENT_SETENABLED) | 119 DECLARE_EXTENSION_FUNCTION("management.setEnabled", MANAGEMENT_SETENABLED) |
120 | 120 |
121 ManagementSetEnabledFunction(); | 121 ManagementSetEnabledFunction(); |
122 | 122 |
123 protected: | 123 protected: |
124 virtual ~ManagementSetEnabledFunction(); | 124 virtual ~ManagementSetEnabledFunction(); |
125 | 125 |
126 // ExtensionFunction: | 126 // ExtensionFunction: |
127 virtual bool RunAsync() OVERRIDE; | 127 virtual bool RunAsync() override; |
128 | 128 |
129 // ExtensionInstallPrompt::Delegate. | 129 // ExtensionInstallPrompt::Delegate. |
130 virtual void InstallUIProceed() OVERRIDE; | 130 virtual void InstallUIProceed() override; |
131 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; | 131 virtual void InstallUIAbort(bool user_initiated) override; |
132 | 132 |
133 private: | 133 private: |
134 std::string extension_id_; | 134 std::string extension_id_; |
135 | 135 |
136 // Used for prompting to re-enable items with permissions escalation updates. | 136 // Used for prompting to re-enable items with permissions escalation updates. |
137 scoped_ptr<ExtensionInstallPrompt> install_prompt_; | 137 scoped_ptr<ExtensionInstallPrompt> install_prompt_; |
138 }; | 138 }; |
139 | 139 |
140 class ManagementUninstallFunctionBase : public AsyncManagementFunction, | 140 class ManagementUninstallFunctionBase : public AsyncManagementFunction, |
141 public ExtensionUninstallDialog::Delegate { | 141 public ExtensionUninstallDialog::Delegate { |
142 public: | 142 public: |
143 ManagementUninstallFunctionBase(); | 143 ManagementUninstallFunctionBase(); |
144 | 144 |
145 static void SetAutoConfirmForTest(bool should_proceed); | 145 static void SetAutoConfirmForTest(bool should_proceed); |
146 | 146 |
147 // ExtensionUninstallDialog::Delegate implementation. | 147 // ExtensionUninstallDialog::Delegate implementation. |
148 virtual void ExtensionUninstallAccepted() OVERRIDE; | 148 virtual void ExtensionUninstallAccepted() override; |
149 virtual void ExtensionUninstallCanceled() OVERRIDE; | 149 virtual void ExtensionUninstallCanceled() override; |
150 | 150 |
151 protected: | 151 protected: |
152 virtual ~ManagementUninstallFunctionBase(); | 152 virtual ~ManagementUninstallFunctionBase(); |
153 | 153 |
154 bool Uninstall(const std::string& extension_id, bool show_confirm_dialog); | 154 bool Uninstall(const std::string& extension_id, bool show_confirm_dialog); |
155 private: | 155 private: |
156 | 156 |
157 // If should_uninstall is true, this method does the actual uninstall. | 157 // 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 | 158 // 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. | 159 // Accepted/Canceled callbacks. Otherwise, it's called directly from RunAsync. |
160 void Finish(bool should_uninstall); | 160 void Finish(bool should_uninstall); |
161 | 161 |
162 std::string extension_id_; | 162 std::string extension_id_; |
163 scoped_ptr<ExtensionUninstallDialog> extension_uninstall_dialog_; | 163 scoped_ptr<ExtensionUninstallDialog> extension_uninstall_dialog_; |
164 }; | 164 }; |
165 | 165 |
166 class ManagementUninstallFunction : public ManagementUninstallFunctionBase { | 166 class ManagementUninstallFunction : public ManagementUninstallFunctionBase { |
167 public: | 167 public: |
168 DECLARE_EXTENSION_FUNCTION("management.uninstall", MANAGEMENT_UNINSTALL) | 168 DECLARE_EXTENSION_FUNCTION("management.uninstall", MANAGEMENT_UNINSTALL) |
169 | 169 |
170 ManagementUninstallFunction(); | 170 ManagementUninstallFunction(); |
171 | 171 |
172 private: | 172 private: |
173 virtual ~ManagementUninstallFunction(); | 173 virtual ~ManagementUninstallFunction(); |
174 | 174 |
175 virtual bool RunAsync() OVERRIDE; | 175 virtual bool RunAsync() override; |
176 }; | 176 }; |
177 | 177 |
178 class ManagementUninstallSelfFunction : public ManagementUninstallFunctionBase { | 178 class ManagementUninstallSelfFunction : public ManagementUninstallFunctionBase { |
179 public: | 179 public: |
180 DECLARE_EXTENSION_FUNCTION("management.uninstallSelf", | 180 DECLARE_EXTENSION_FUNCTION("management.uninstallSelf", |
181 MANAGEMENT_UNINSTALLSELF); | 181 MANAGEMENT_UNINSTALLSELF); |
182 | 182 |
183 ManagementUninstallSelfFunction(); | 183 ManagementUninstallSelfFunction(); |
184 | 184 |
185 private: | 185 private: |
186 virtual ~ManagementUninstallSelfFunction(); | 186 virtual ~ManagementUninstallSelfFunction(); |
187 | 187 |
188 virtual bool RunAsync() OVERRIDE; | 188 virtual bool RunAsync() override; |
189 }; | 189 }; |
190 | 190 |
191 class ManagementCreateAppShortcutFunction : public AsyncManagementFunction { | 191 class ManagementCreateAppShortcutFunction : public AsyncManagementFunction { |
192 public: | 192 public: |
193 DECLARE_EXTENSION_FUNCTION("management.createAppShortcut", | 193 DECLARE_EXTENSION_FUNCTION("management.createAppShortcut", |
194 MANAGEMENT_CREATEAPPSHORTCUT); | 194 MANAGEMENT_CREATEAPPSHORTCUT); |
195 | 195 |
196 ManagementCreateAppShortcutFunction(); | 196 ManagementCreateAppShortcutFunction(); |
197 | 197 |
198 void OnCloseShortcutPrompt(bool created); | 198 void OnCloseShortcutPrompt(bool created); |
199 | 199 |
200 static void SetAutoConfirmForTest(bool should_proceed); | 200 static void SetAutoConfirmForTest(bool should_proceed); |
201 | 201 |
202 protected: | 202 protected: |
203 virtual ~ManagementCreateAppShortcutFunction(); | 203 virtual ~ManagementCreateAppShortcutFunction(); |
204 | 204 |
205 virtual bool RunAsync() OVERRIDE; | 205 virtual bool RunAsync() override; |
206 }; | 206 }; |
207 | 207 |
208 class ManagementSetLaunchTypeFunction : public ManagementFunction { | 208 class ManagementSetLaunchTypeFunction : public ManagementFunction { |
209 public: | 209 public: |
210 DECLARE_EXTENSION_FUNCTION("management.setLaunchType", | 210 DECLARE_EXTENSION_FUNCTION("management.setLaunchType", |
211 MANAGEMENT_SETLAUNCHTYPE); | 211 MANAGEMENT_SETLAUNCHTYPE); |
212 | 212 |
213 protected: | 213 protected: |
214 virtual ~ManagementSetLaunchTypeFunction() {} | 214 virtual ~ManagementSetLaunchTypeFunction() {} |
215 | 215 |
216 virtual bool RunSync() OVERRIDE; | 216 virtual bool RunSync() override; |
217 }; | 217 }; |
218 | 218 |
219 class ManagementGenerateAppForLinkFunction : public AsyncManagementFunction { | 219 class ManagementGenerateAppForLinkFunction : public AsyncManagementFunction { |
220 public: | 220 public: |
221 DECLARE_EXTENSION_FUNCTION("management.generateAppForLink", | 221 DECLARE_EXTENSION_FUNCTION("management.generateAppForLink", |
222 MANAGEMENT_GENERATEAPPFORLINK); | 222 MANAGEMENT_GENERATEAPPFORLINK); |
223 | 223 |
224 ManagementGenerateAppForLinkFunction(); | 224 ManagementGenerateAppForLinkFunction(); |
225 | 225 |
226 protected: | 226 protected: |
227 virtual ~ManagementGenerateAppForLinkFunction(); | 227 virtual ~ManagementGenerateAppForLinkFunction(); |
228 | 228 |
229 virtual bool RunAsync() OVERRIDE; | 229 virtual bool RunAsync() override; |
230 | 230 |
231 private: | 231 private: |
232 void OnFaviconForApp(const favicon_base::FaviconImageResult& image_result); | 232 void OnFaviconForApp(const favicon_base::FaviconImageResult& image_result); |
233 void FinishCreateBookmarkApp(const Extension* extension, | 233 void FinishCreateBookmarkApp(const Extension* extension, |
234 const WebApplicationInfo& web_app_info); | 234 const WebApplicationInfo& web_app_info); |
235 | 235 |
236 std::string title_; | 236 std::string title_; |
237 GURL launch_url_; | 237 GURL launch_url_; |
238 | 238 |
239 scoped_ptr<BookmarkAppHelper> bookmark_app_helper_; | 239 scoped_ptr<BookmarkAppHelper> bookmark_app_helper_; |
240 | 240 |
241 // Used for favicon loading tasks. | 241 // Used for favicon loading tasks. |
242 base::CancelableTaskTracker cancelable_task_tracker_; | 242 base::CancelableTaskTracker cancelable_task_tracker_; |
243 }; | 243 }; |
244 | 244 |
245 class ManagementEventRouter : public ExtensionRegistryObserver { | 245 class ManagementEventRouter : public ExtensionRegistryObserver { |
246 public: | 246 public: |
247 explicit ManagementEventRouter(content::BrowserContext* context); | 247 explicit ManagementEventRouter(content::BrowserContext* context); |
248 virtual ~ManagementEventRouter(); | 248 virtual ~ManagementEventRouter(); |
249 | 249 |
250 private: | 250 private: |
251 // ExtensionRegistryObserver implementation. | 251 // ExtensionRegistryObserver implementation. |
252 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, | 252 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, |
253 const Extension* extension) OVERRIDE; | 253 const Extension* extension) override; |
254 virtual void OnExtensionUnloaded( | 254 virtual void OnExtensionUnloaded( |
255 content::BrowserContext* browser_context, | 255 content::BrowserContext* browser_context, |
256 const Extension* extension, | 256 const Extension* extension, |
257 UnloadedExtensionInfo::Reason reason) OVERRIDE; | 257 UnloadedExtensionInfo::Reason reason) override; |
258 virtual void OnExtensionInstalled(content::BrowserContext* browser_context, | 258 virtual void OnExtensionInstalled(content::BrowserContext* browser_context, |
259 const Extension* extension, | 259 const Extension* extension, |
260 bool is_update) OVERRIDE; | 260 bool is_update) override; |
261 virtual void OnExtensionUninstalled( | 261 virtual void OnExtensionUninstalled( |
262 content::BrowserContext* browser_context, | 262 content::BrowserContext* browser_context, |
263 const Extension* extension, | 263 const Extension* extension, |
264 extensions::UninstallReason reason) OVERRIDE; | 264 extensions::UninstallReason reason) override; |
265 | 265 |
266 // Dispatches management api events to listening extensions. | 266 // Dispatches management api events to listening extensions. |
267 void BroadcastEvent(const Extension* extension, const char* event_name); | 267 void BroadcastEvent(const Extension* extension, const char* event_name); |
268 | 268 |
269 content::BrowserContext* browser_context_; | 269 content::BrowserContext* browser_context_; |
270 | 270 |
271 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 271 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
272 extension_registry_observer_; | 272 extension_registry_observer_; |
273 | 273 |
274 DISALLOW_COPY_AND_ASSIGN(ManagementEventRouter); | 274 DISALLOW_COPY_AND_ASSIGN(ManagementEventRouter); |
275 }; | 275 }; |
276 | 276 |
277 class ManagementAPI : public BrowserContextKeyedAPI, | 277 class ManagementAPI : public BrowserContextKeyedAPI, |
278 public EventRouter::Observer { | 278 public EventRouter::Observer { |
279 public: | 279 public: |
280 explicit ManagementAPI(content::BrowserContext* context); | 280 explicit ManagementAPI(content::BrowserContext* context); |
281 virtual ~ManagementAPI(); | 281 virtual ~ManagementAPI(); |
282 | 282 |
283 // KeyedService implementation. | 283 // KeyedService implementation. |
284 virtual void Shutdown() OVERRIDE; | 284 virtual void Shutdown() override; |
285 | 285 |
286 // BrowserContextKeyedAPI implementation. | 286 // BrowserContextKeyedAPI implementation. |
287 static BrowserContextKeyedAPIFactory<ManagementAPI>* GetFactoryInstance(); | 287 static BrowserContextKeyedAPIFactory<ManagementAPI>* GetFactoryInstance(); |
288 | 288 |
289 // EventRouter::Observer implementation. | 289 // EventRouter::Observer implementation. |
290 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; | 290 virtual void OnListenerAdded(const EventListenerInfo& details) override; |
291 | 291 |
292 private: | 292 private: |
293 friend class BrowserContextKeyedAPIFactory<ManagementAPI>; | 293 friend class BrowserContextKeyedAPIFactory<ManagementAPI>; |
294 | 294 |
295 content::BrowserContext* browser_context_; | 295 content::BrowserContext* browser_context_; |
296 | 296 |
297 // BrowserContextKeyedAPI implementation. | 297 // BrowserContextKeyedAPI implementation. |
298 static const char* service_name() { | 298 static const char* service_name() { |
299 return "ManagementAPI"; | 299 return "ManagementAPI"; |
300 } | 300 } |
301 static const bool kServiceIsNULLWhileTesting = true; | 301 static const bool kServiceIsNULLWhileTesting = true; |
302 | 302 |
303 // Created lazily upon OnListenerAdded. | 303 // Created lazily upon OnListenerAdded. |
304 scoped_ptr<ManagementEventRouter> management_event_router_; | 304 scoped_ptr<ManagementEventRouter> management_event_router_; |
305 | 305 |
306 DISALLOW_COPY_AND_ASSIGN(ManagementAPI); | 306 DISALLOW_COPY_AND_ASSIGN(ManagementAPI); |
307 }; | 307 }; |
308 | 308 |
309 } // namespace extensions | 309 } // namespace extensions |
310 | 310 |
311 #endif // CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_ | 311 #endif // CHROME_BROWSER_EXTENSIONS_API_MANAGEMENT_MANAGEMENT_API_H_ |
OLD | NEW |