Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(826)

Side by Side Diff: chrome/browser/extensions/extension_management_api.cc

Issue 3402027: Merge 60334 - Add a launchApp method to extension management API.... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/517/src/
Patch Set: Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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";
39 40
40 const char kNoExtensionError[] = "No extension with id *"; 41 const char kNoExtensionError[] = "No extension with id *";
41 42 const char kNotAnAppError[] = "Extension * is not an App";
42 } 43 }
43 44
44 ExtensionsService* ExtensionManagementFunction::service() { 45 ExtensionsService* ExtensionManagementFunction::service() {
45 return profile()->GetExtensionsService(); 46 return profile()->GetExtensionsService();
46 } 47 }
47 48
48 static DictionaryValue* CreateExtensionInfo(const Extension& extension, 49 static DictionaryValue* CreateExtensionInfo(const Extension& extension,
49 bool enabled) { 50 bool enabled) {
50 DictionaryValue* info = new DictionaryValue(); 51 DictionaryValue* info = new DictionaryValue();
51 info->SetString(kIdKey, extension.id()); 52 info->SetString(kIdKey, extension.id());
52 info->SetBoolean(kIsAppKey, extension.is_app()); 53 info->SetBoolean(kIsAppKey, extension.is_app());
53 info->SetString(kNameKey, extension.name()); 54 info->SetString(kNameKey, extension.name());
54 info->SetBoolean(kEnabledKey, enabled); 55 info->SetBoolean(kEnabledKey, enabled);
56 info->SetString(kVersionKey, extension.VersionString());
55 if (!extension.options_url().is_empty()) 57 if (!extension.options_url().is_empty())
56 info->SetString(kOptionsUrlKey, 58 info->SetString(kOptionsUrlKey,
57 extension.options_url().possibly_invalid_spec()); 59 extension.options_url().possibly_invalid_spec());
58 if (extension.is_app()) 60 if (extension.is_app())
59 info->SetString(kAppLaunchUrlKey, 61 info->SetString(kAppLaunchUrlKey,
60 extension.GetFullLaunchURL().possibly_invalid_spec()); 62 extension.GetFullLaunchURL().possibly_invalid_spec());
61 63
62 const std::map<int, std::string>& icons = extension.icons(); 64 const std::map<int, std::string>& icons = extension.icons();
63 if (!icons.empty()) { 65 if (!icons.empty()) {
64 ListValue* icon_list = new ListValue(); 66 ListValue* icon_list = new ListValue();
(...skipping 28 matching lines...) Expand all
93 bool GetAllExtensionsFunction::RunImpl() { 95 bool GetAllExtensionsFunction::RunImpl() {
94 ListValue* result = new ListValue(); 96 ListValue* result = new ListValue();
95 result_.reset(result); 97 result_.reset(result);
96 98
97 AddExtensionInfo(result, *service()->extensions(), true); 99 AddExtensionInfo(result, *service()->extensions(), true);
98 AddExtensionInfo(result, *service()->disabled_extensions(), false); 100 AddExtensionInfo(result, *service()->disabled_extensions(), false);
99 101
100 return true; 102 return true;
101 } 103 }
102 104
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
103 bool SetEnabledFunction::RunImpl() { 126 bool SetEnabledFunction::RunImpl() {
104 std::string extension_id; 127 std::string extension_id;
105 bool enable; 128 bool enable;
106 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id)); 129 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id));
107 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &enable)); 130 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &enable));
108 131
109 if (!service()->GetExtensionById(extension_id, true)) { 132 if (!service()->GetExtensionById(extension_id, true)) {
110 error_ = ExtensionErrorUtils::FormatErrorMessage( 133 error_ = ExtensionErrorUtils::FormatErrorMessage(
111 kNoExtensionError, extension_id); 134 kNoExtensionError, extension_id);
112 return false; 135 return false;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 std::string args_json; 221 std::string args_json;
199 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); 222 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json);
200 223
201 ExtensionMessageService* message_service = 224 ExtensionMessageService* message_service =
202 profile->GetExtensionMessageService(); 225 profile->GetExtensionMessageService();
203 message_service->DispatchEventToRenderers(event_name, 226 message_service->DispatchEventToRenderers(event_name,
204 args_json, 227 args_json,
205 profile, 228 profile,
206 GURL()); 229 GURL());
207 } 230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698