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 20 matching lines...) Expand all Loading... |
31 | 31 |
32 const char kAppLaunchUrlKey[] = "appLaunchUrl"; | 32 const char kAppLaunchUrlKey[] = "appLaunchUrl"; |
33 const char kEnabledKey[] = "enabled"; | 33 const char kEnabledKey[] = "enabled"; |
34 const char kIconsKey[] = "icons"; | 34 const char kIconsKey[] = "icons"; |
35 const char kIdKey[] = "id"; | 35 const char kIdKey[] = "id"; |
36 const char kIsAppKey[] = "isApp"; | 36 const char kIsAppKey[] = "isApp"; |
37 const char kNameKey[] = "name"; | 37 const char kNameKey[] = "name"; |
38 const char kOptionsUrlKey[] = "optionsUrl"; | 38 const char kOptionsUrlKey[] = "optionsUrl"; |
39 const char kSizeKey[] = "size"; | 39 const char kSizeKey[] = "size"; |
40 const char kUrlKey[] = "url"; | 40 const char kUrlKey[] = "url"; |
| 41 const char kVersionKey[] = "version"; |
41 | 42 |
42 const char kNoExtensionError[] = "No extension with id *"; | 43 const char kNoExtensionError[] = "No extension with id *"; |
43 | 44 const char kNotAnAppError[] = "Extension * is not an App"; |
44 } | 45 } |
45 | 46 |
46 ExtensionsService* ExtensionManagementFunction::service() { | 47 ExtensionsService* ExtensionManagementFunction::service() { |
47 return profile()->GetExtensionsService(); | 48 return profile()->GetExtensionsService(); |
48 } | 49 } |
49 | 50 |
50 static DictionaryValue* CreateExtensionInfo(const Extension& extension, | 51 static DictionaryValue* CreateExtensionInfo(const Extension& extension, |
51 bool enabled) { | 52 bool enabled) { |
52 DictionaryValue* info = new DictionaryValue(); | 53 DictionaryValue* info = new DictionaryValue(); |
53 info->SetString(kIdKey, extension.id()); | 54 info->SetString(kIdKey, extension.id()); |
54 info->SetBoolean(kIsAppKey, extension.is_app()); | 55 info->SetBoolean(kIsAppKey, extension.is_app()); |
55 info->SetString(kNameKey, extension.name()); | 56 info->SetString(kNameKey, extension.name()); |
56 info->SetBoolean(kEnabledKey, enabled); | 57 info->SetBoolean(kEnabledKey, enabled); |
| 58 info->SetString(kVersionKey, extension.VersionString()); |
57 if (!extension.options_url().is_empty()) | 59 if (!extension.options_url().is_empty()) |
58 info->SetString(kOptionsUrlKey, | 60 info->SetString(kOptionsUrlKey, |
59 extension.options_url().possibly_invalid_spec()); | 61 extension.options_url().possibly_invalid_spec()); |
60 if (extension.is_app()) | 62 if (extension.is_app()) |
61 info->SetString(kAppLaunchUrlKey, | 63 info->SetString(kAppLaunchUrlKey, |
62 extension.GetFullLaunchURL().possibly_invalid_spec()); | 64 extension.GetFullLaunchURL().possibly_invalid_spec()); |
63 | 65 |
64 const ExtensionIconSet::IconMap& icons = extension.icons().map(); | 66 const ExtensionIconSet::IconMap& icons = extension.icons().map(); |
65 if (!icons.empty()) { | 67 if (!icons.empty()) { |
66 ListValue* icon_list = new ListValue(); | 68 ListValue* icon_list = new ListValue(); |
(...skipping 28 matching lines...) Expand all Loading... |
95 bool GetAllExtensionsFunction::RunImpl() { | 97 bool GetAllExtensionsFunction::RunImpl() { |
96 ListValue* result = new ListValue(); | 98 ListValue* result = new ListValue(); |
97 result_.reset(result); | 99 result_.reset(result); |
98 | 100 |
99 AddExtensionInfo(result, *service()->extensions(), true); | 101 AddExtensionInfo(result, *service()->extensions(), true); |
100 AddExtensionInfo(result, *service()->disabled_extensions(), false); | 102 AddExtensionInfo(result, *service()->disabled_extensions(), false); |
101 | 103 |
102 return true; | 104 return true; |
103 } | 105 } |
104 | 106 |
| 107 bool LaunchAppFunction::RunImpl() { |
| 108 std::string extension_id; |
| 109 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id)); |
| 110 Extension* extension = service()->GetExtensionById(extension_id, true); |
| 111 if (!extension) { |
| 112 error_ = ExtensionErrorUtils::FormatErrorMessage(kNoExtensionError, |
| 113 extension_id); |
| 114 return false; |
| 115 } |
| 116 if (!extension->is_app()) { |
| 117 error_ = ExtensionErrorUtils::FormatErrorMessage(kNotAnAppError, |
| 118 extension_id); |
| 119 return false; |
| 120 } |
| 121 |
| 122 extension_misc::LaunchContainer container = extension->launch_container(); |
| 123 Browser::OpenApplication(profile(), extension, container); |
| 124 |
| 125 return true; |
| 126 } |
| 127 |
105 bool SetEnabledFunction::RunImpl() { | 128 bool SetEnabledFunction::RunImpl() { |
106 std::string extension_id; | 129 std::string extension_id; |
107 bool enable; | 130 bool enable; |
108 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id)); | 131 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id)); |
109 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &enable)); | 132 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &enable)); |
110 | 133 |
111 if (!service()->GetExtensionById(extension_id, true)) { | 134 if (!service()->GetExtensionById(extension_id, true)) { |
112 error_ = ExtensionErrorUtils::FormatErrorMessage( | 135 error_ = ExtensionErrorUtils::FormatErrorMessage( |
113 kNoExtensionError, extension_id); | 136 kNoExtensionError, extension_id); |
114 return false; | 137 return false; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 std::string args_json; | 223 std::string args_json; |
201 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); | 224 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); |
202 | 225 |
203 ExtensionMessageService* message_service = | 226 ExtensionMessageService* message_service = |
204 profile->GetExtensionMessageService(); | 227 profile->GetExtensionMessageService(); |
205 message_service->DispatchEventToRenderers(event_name, | 228 message_service->DispatchEventToRenderers(event_name, |
206 args_json, | 229 args_json, |
207 profile, | 230 profile, |
208 GURL()); | 231 GURL()); |
209 } | 232 } |
OLD | NEW |