OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/extensions/extension_management_api.h" | 5 #include "chrome/browser/extensions/extension_management_api.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 namespace events = extension_event_names; | 30 namespace events = extension_event_names; |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 const char kAppLaunchUrlKey[] = "appLaunchUrl"; | 34 const char kAppLaunchUrlKey[] = "appLaunchUrl"; |
35 const char kDescriptionKey[] = "description"; | 35 const char kDescriptionKey[] = "description"; |
36 const char kEnabledKey[] = "enabled"; | 36 const char kEnabledKey[] = "enabled"; |
37 const char kIconsKey[] = "icons"; | 37 const char kIconsKey[] = "icons"; |
38 const char kIdKey[] = "id"; | 38 const char kIdKey[] = "id"; |
39 const char kIsAppKey[] = "isApp"; | 39 const char kIsAppKey[] = "isApp"; |
| 40 const char kIsThemeKey[] = "isTheme"; |
40 const char kNameKey[] = "name"; | 41 const char kNameKey[] = "name"; |
41 const char kOptionsUrlKey[] = "optionsUrl"; | 42 const char kOptionsUrlKey[] = "optionsUrl"; |
42 const char kPermissionsKey[] = "permissions"; | 43 const char kPermissionsKey[] = "permissions"; |
43 const char kSizeKey[] = "size"; | 44 const char kSizeKey[] = "size"; |
44 const char kUrlKey[] = "url"; | 45 const char kUrlKey[] = "url"; |
45 const char kVersionKey[] = "version"; | 46 const char kVersionKey[] = "version"; |
46 | 47 |
47 const char kNoExtensionError[] = "No extension with id *"; | 48 const char kNoExtensionError[] = "No extension with id *"; |
48 const char kNotAnAppError[] = "Extension * is not an App"; | 49 const char kNotAnAppError[] = "Extension * is not an App"; |
49 } | 50 } |
50 | 51 |
51 ExtensionService* ExtensionManagementFunction::service() { | 52 ExtensionService* ExtensionManagementFunction::service() { |
52 return profile()->GetExtensionService(); | 53 return profile()->GetExtensionService(); |
53 } | 54 } |
54 | 55 |
55 static DictionaryValue* CreateExtensionInfo(const Extension& extension, | 56 static DictionaryValue* CreateExtensionInfo(const Extension& extension, |
56 bool enabled) { | 57 bool enabled) { |
57 DictionaryValue* info = new DictionaryValue(); | 58 DictionaryValue* info = new DictionaryValue(); |
58 info->SetString(kIdKey, extension.id()); | 59 info->SetString(kIdKey, extension.id()); |
59 info->SetBoolean(kIsAppKey, extension.is_app()); | 60 info->SetBoolean(kIsAppKey, extension.is_app()); |
| 61 info->SetBoolean(kIsThemeKey, extension.is_theme()); |
60 info->SetString(kNameKey, extension.name()); | 62 info->SetString(kNameKey, extension.name()); |
61 info->SetBoolean(kEnabledKey, enabled); | 63 info->SetBoolean(kEnabledKey, enabled); |
62 info->SetString(kVersionKey, extension.VersionString()); | 64 info->SetString(kVersionKey, extension.VersionString()); |
63 info->SetString(kDescriptionKey, extension.description()); | 65 info->SetString(kDescriptionKey, extension.description()); |
64 info->SetString(kOptionsUrlKey, | 66 info->SetString(kOptionsUrlKey, |
65 extension.options_url().possibly_invalid_spec()); | 67 extension.options_url().possibly_invalid_spec()); |
66 if (extension.is_app()) | 68 if (extension.is_app()) |
67 info->SetString(kAppLaunchUrlKey, | 69 info->SetString(kAppLaunchUrlKey, |
68 extension.GetFullLaunchURL().possibly_invalid_spec()); | 70 extension.GetFullLaunchURL().possibly_invalid_spec()); |
69 | 71 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 if (!service()->GetExtensionById(extension_id, true)) { | 215 if (!service()->GetExtensionById(extension_id, true)) { |
214 error_ = ExtensionErrorUtils::FormatErrorMessage( | 216 error_ = ExtensionErrorUtils::FormatErrorMessage( |
215 kNoExtensionError, extension_id); | 217 kNoExtensionError, extension_id); |
216 return false; | 218 return false; |
217 } | 219 } |
218 | 220 |
219 service()->UninstallExtension(extension_id, false /* external_uninstall */); | 221 service()->UninstallExtension(extension_id, false /* external_uninstall */); |
220 return true; | 222 return true; |
221 } | 223 } |
222 | 224 |
223 // static | |
224 ExtensionManagementEventRouter* ExtensionManagementEventRouter::GetInstance() { | |
225 return Singleton<ExtensionManagementEventRouter>::get(); | |
226 } | |
227 | |
228 ExtensionManagementEventRouter::ExtensionManagementEventRouter() {} | 225 ExtensionManagementEventRouter::ExtensionManagementEventRouter() {} |
229 | 226 |
230 ExtensionManagementEventRouter::~ExtensionManagementEventRouter() {} | 227 ExtensionManagementEventRouter::~ExtensionManagementEventRouter() {} |
231 | 228 |
232 void ExtensionManagementEventRouter::Init() { | 229 void ExtensionManagementEventRouter::Init() { |
233 NotificationType::Type types[] = { | 230 NotificationType::Type types[] = { |
234 NotificationType::EXTENSION_INSTALLED, | 231 NotificationType::EXTENSION_INSTALLED, |
235 NotificationType::EXTENSION_UNINSTALLED, | 232 NotificationType::EXTENSION_UNINSTALLED, |
236 NotificationType::EXTENSION_LOADED, | 233 NotificationType::EXTENSION_LOADED, |
237 NotificationType::EXTENSION_UNLOADED | 234 NotificationType::EXTENSION_UNLOADED |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 CHECK(profile); | 268 CHECK(profile); |
272 | 269 |
273 ListValue args; | 270 ListValue args; |
274 if (event_name == events::kOnExtensionUninstalled) { | 271 if (event_name == events::kOnExtensionUninstalled) { |
275 const std::string& extension_id = | 272 const std::string& extension_id = |
276 Details<UninstalledExtensionInfo>(details).ptr()->extension_id; | 273 Details<UninstalledExtensionInfo>(details).ptr()->extension_id; |
277 args.Append(Value::CreateStringValue(extension_id)); | 274 args.Append(Value::CreateStringValue(extension_id)); |
278 } else { | 275 } else { |
279 const Extension* extension = NULL; | 276 const Extension* extension = NULL; |
280 if (event_name == events::kOnExtensionDisabled) { | 277 if (event_name == events::kOnExtensionDisabled) { |
281 extension = Details<UnloadedExtensionInfo>(details)->extension; | 278 UnloadedExtensionInfo* info = |
| 279 Details<UnloadedExtensionInfo>(details).ptr(); |
| 280 // If the extension was already disabled, we don't want to send another |
| 281 // notification about it. |
| 282 if (info->already_disabled) |
| 283 return; |
| 284 |
| 285 extension = info->extension; |
282 } else { | 286 } else { |
283 extension = Details<const Extension>(details).ptr(); | 287 extension = Details<const Extension>(details).ptr(); |
284 } | 288 } |
285 CHECK(extension); | 289 CHECK(extension); |
286 ExtensionService* service = profile->GetExtensionService(); | 290 ExtensionService* service = profile->GetExtensionService(); |
287 bool enabled = service->GetExtensionById(extension->id(), false) != NULL; | 291 bool enabled = service->GetExtensionById(extension->id(), false) != NULL; |
288 args.Append(CreateExtensionInfo(*extension, enabled)); | 292 args.Append(CreateExtensionInfo(*extension, enabled)); |
289 } | 293 } |
290 | 294 |
291 std::string args_json; | 295 std::string args_json; |
292 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); | 296 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); |
293 | 297 |
294 profile->GetExtensionEventRouter()->DispatchEventToRenderers( | 298 profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
295 event_name, args_json, NULL, GURL()); | 299 event_name, args_json, NULL, GURL()); |
296 } | 300 } |
OLD | NEW |