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" |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "chrome/browser/extensions/extension_event_names.h" | 14 #include "chrome/browser/extensions/extension_event_names.h" |
15 #include "chrome/browser/extensions/extension_event_router.h" | 15 #include "chrome/browser/extensions/extension_event_router.h" |
16 #include "chrome/browser/extensions/extensions_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
17 #include "chrome/browser/extensions/extension_updater.h" | 17 #include "chrome/browser/extensions/extension_updater.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/common/extensions/extension_constants.h" | 20 #include "chrome/common/extensions/extension_constants.h" |
21 #include "chrome/common/extensions/extension_error_utils.h" | 21 #include "chrome/common/extensions/extension_error_utils.h" |
22 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
23 #include "chrome/common/extensions/extension_icon_set.h" | 23 #include "chrome/common/extensions/extension_icon_set.h" |
24 #include "chrome/common/extensions/url_pattern.h" | 24 #include "chrome/common/extensions/url_pattern.h" |
25 #include "chrome/common/notification_service.h" | 25 #include "chrome/common/notification_service.h" |
26 #include "chrome/common/notification_type.h" | 26 #include "chrome/common/notification_type.h" |
(...skipping 13 matching lines...) Expand all Loading... |
40 const char kOptionsUrlKey[] = "optionsUrl"; | 40 const char kOptionsUrlKey[] = "optionsUrl"; |
41 const char kPermissionsKey[] = "permissions"; | 41 const char kPermissionsKey[] = "permissions"; |
42 const char kSizeKey[] = "size"; | 42 const char kSizeKey[] = "size"; |
43 const char kUrlKey[] = "url"; | 43 const char kUrlKey[] = "url"; |
44 const char kVersionKey[] = "version"; | 44 const char kVersionKey[] = "version"; |
45 | 45 |
46 const char kNoExtensionError[] = "No extension with id *"; | 46 const char kNoExtensionError[] = "No extension with id *"; |
47 const char kNotAnAppError[] = "Extension * is not an App"; | 47 const char kNotAnAppError[] = "Extension * is not an App"; |
48 } | 48 } |
49 | 49 |
50 ExtensionsService* ExtensionManagementFunction::service() { | 50 ExtensionService* ExtensionManagementFunction::service() { |
51 return profile()->GetExtensionsService(); | 51 return profile()->GetExtensionService(); |
52 } | 52 } |
53 | 53 |
54 static DictionaryValue* CreateExtensionInfo(const Extension& extension, | 54 static DictionaryValue* CreateExtensionInfo(const Extension& extension, |
55 bool enabled) { | 55 bool enabled) { |
56 DictionaryValue* info = new DictionaryValue(); | 56 DictionaryValue* info = new DictionaryValue(); |
57 info->SetString(kIdKey, extension.id()); | 57 info->SetString(kIdKey, extension.id()); |
58 info->SetBoolean(kIsAppKey, extension.is_app()); | 58 info->SetBoolean(kIsAppKey, extension.is_app()); |
59 info->SetString(kNameKey, extension.name()); | 59 info->SetString(kNameKey, extension.name()); |
60 info->SetBoolean(kEnabledKey, enabled); | 60 info->SetBoolean(kEnabledKey, enabled); |
61 info->SetString(kVersionKey, extension.VersionString()); | 61 info->SetString(kVersionKey, extension.VersionString()); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 CHECK(profile); | 262 CHECK(profile); |
263 | 263 |
264 ListValue args; | 264 ListValue args; |
265 if (event_name == events::kOnExtensionUninstalled) { | 265 if (event_name == events::kOnExtensionUninstalled) { |
266 const std::string& extension_id = | 266 const std::string& extension_id = |
267 Details<UninstalledExtensionInfo>(details).ptr()->extension_id; | 267 Details<UninstalledExtensionInfo>(details).ptr()->extension_id; |
268 args.Append(Value::CreateStringValue(extension_id)); | 268 args.Append(Value::CreateStringValue(extension_id)); |
269 } else { | 269 } else { |
270 const Extension* extension = Details<const Extension>(details).ptr(); | 270 const Extension* extension = Details<const Extension>(details).ptr(); |
271 CHECK(extension); | 271 CHECK(extension); |
272 ExtensionsService* service = profile->GetExtensionsService(); | 272 ExtensionService* service = profile->GetExtensionService(); |
273 bool enabled = service->GetExtensionById(extension->id(), false) != NULL; | 273 bool enabled = service->GetExtensionById(extension->id(), false) != NULL; |
274 args.Append(CreateExtensionInfo(*extension, enabled)); | 274 args.Append(CreateExtensionInfo(*extension, enabled)); |
275 } | 275 } |
276 | 276 |
277 std::string args_json; | 277 std::string args_json; |
278 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); | 278 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); |
279 | 279 |
280 profile->GetExtensionEventRouter()->DispatchEventToRenderers( | 280 profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
281 event_name, args_json, NULL, GURL()); | 281 event_name, args_json, NULL, GURL()); |
282 } | 282 } |
OLD | NEW |