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