OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/api/management/management_api.h" | 5 #include "chrome/browser/extensions/api/management/management_api.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
| 9 #include <vector> |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/memory/linked_ptr.h" |
| 15 #include "base/memory/scoped_ptr.h" |
13 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
14 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
15 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/extensions/api/management/management_api_constants.h" | 20 #include "chrome/browser/extensions/api/management/management_api_constants.h" |
17 #include "chrome/browser/extensions/event_names.h" | 21 #include "chrome/browser/extensions/event_names.h" |
18 #include "chrome/browser/extensions/event_router.h" | 22 #include "chrome/browser/extensions/event_router.h" |
19 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
20 #include "chrome/browser/extensions/extension_system.h" | 24 #include "chrome/browser/extensions/extension_system.h" |
21 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | 25 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
22 #include "chrome/browser/extensions/management_policy.h" | 26 #include "chrome/browser/extensions/management_policy.h" |
23 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/ui/extensions/application_launch.h" | 28 #include "chrome/browser/ui/extensions/application_launch.h" |
25 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 29 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
26 #include "chrome/common/chrome_notification_types.h" | 30 #include "chrome/common/chrome_notification_types.h" |
27 #include "chrome/common/chrome_utility_messages.h" | 31 #include "chrome/common/chrome_utility_messages.h" |
| 32 #include "chrome/common/extensions/api/management.h" |
28 #include "chrome/common/extensions/extension.h" | 33 #include "chrome/common/extensions/extension.h" |
29 #include "chrome/common/extensions/extension_constants.h" | 34 #include "chrome/common/extensions/extension_constants.h" |
30 #include "chrome/common/extensions/extension_error_utils.h" | 35 #include "chrome/common/extensions/extension_error_utils.h" |
31 #include "chrome/common/extensions/extension_icon_set.h" | 36 #include "chrome/common/extensions/extension_icon_set.h" |
32 #include "chrome/common/extensions/permissions/permission_set.h" | 37 #include "chrome/common/extensions/permissions/permission_set.h" |
33 #include "chrome/common/extensions/url_pattern.h" | 38 #include "chrome/common/extensions/url_pattern.h" |
34 #include "content/public/browser/notification_details.h" | 39 #include "content/public/browser/notification_details.h" |
35 #include "content/public/browser/notification_source.h" | 40 #include "content/public/browser/notification_source.h" |
36 #include "content/public/browser/utility_process_host.h" | 41 #include "content/public/browser/utility_process_host.h" |
37 #include "content/public/browser/utility_process_host_client.h" | 42 #include "content/public/browser/utility_process_host_client.h" |
38 | 43 |
39 #if !defined(OS_ANDROID) | 44 #if !defined(OS_ANDROID) |
40 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 45 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
41 #endif | 46 #endif |
42 | 47 |
43 using base::IntToString; | 48 using base::IntToString; |
44 using content::BrowserThread; | 49 using content::BrowserThread; |
45 using content::UtilityProcessHost; | 50 using content::UtilityProcessHost; |
46 using content::UtilityProcessHostClient; | 51 using content::UtilityProcessHostClient; |
47 using extensions::Extension; | 52 using extensions::Extension; |
| 53 using extensions::ExtensionSystem; |
48 using extensions::PermissionMessages; | 54 using extensions::PermissionMessages; |
49 | 55 |
50 namespace events = extensions::event_names; | 56 namespace events = extensions::event_names; |
51 namespace keys = extension_management_api_constants; | 57 namespace keys = extension_management_api_constants; |
| 58 namespace management = extensions::api::management; |
52 | 59 |
53 namespace { | 60 namespace { |
54 | 61 |
| 62 typedef std::vector<linked_ptr<management::ExtensionInfo> > ExtensionInfoList; |
| 63 typedef std::vector<linked_ptr<management::IconInfo> > IconInfoList; |
| 64 |
55 enum AutoConfirmForTest { | 65 enum AutoConfirmForTest { |
56 DO_NOT_SKIP = 0, | 66 DO_NOT_SKIP = 0, |
57 PROCEED, | 67 PROCEED, |
58 ABORT | 68 ABORT |
59 }; | 69 }; |
60 | 70 |
61 AutoConfirmForTest auto_confirm_for_test = DO_NOT_SKIP; | 71 AutoConfirmForTest auto_confirm_for_test = DO_NOT_SKIP; |
62 | 72 |
| 73 std::vector<std::string> CreateWarningsList(const Extension* extension) { |
| 74 std::vector<std::string> warnings_list; |
| 75 PermissionMessages warnings = extension->GetPermissionMessages(); |
| 76 for (PermissionMessages::const_iterator iter = warnings.begin(); |
| 77 iter != warnings.end(); ++iter) { |
| 78 warnings_list.push_back(UTF16ToUTF8(iter->message())); |
| 79 } |
| 80 |
| 81 return warnings_list; |
| 82 } |
| 83 |
| 84 scoped_ptr<management::ExtensionInfo> CreateExtensionInfo( |
| 85 const Extension& extension, |
| 86 ExtensionSystem* system) { |
| 87 scoped_ptr<management::ExtensionInfo> info(new management::ExtensionInfo()); |
| 88 ExtensionService* service = system->extension_service(); |
| 89 |
| 90 info->id = extension.id(); |
| 91 info->name = extension.name(); |
| 92 info->enabled = service->IsExtensionEnabled(info->id); |
| 93 info->offline_enabled = extension.offline_enabled(); |
| 94 info->version = extension.VersionString(); |
| 95 info->description = extension.description(); |
| 96 info->options_url = extension.options_url().spec(); |
| 97 info->homepage_url.reset(new std::string( |
| 98 extension.GetHomepageURL().spec())); |
| 99 info->may_disable = system->management_policy()-> |
| 100 UserMayModifySettings(&extension, NULL); |
| 101 info->is_app = extension.is_app(); |
| 102 |
| 103 if (info->enabled) { |
| 104 info->disabled_reason = management::ExtensionInfo::DISABLED_REASON_NONE; |
| 105 } else { |
| 106 extensions::ExtensionPrefs* prefs = service->extension_prefs(); |
| 107 if (prefs->DidExtensionEscalatePermissions(extension.id())) { |
| 108 info->disabled_reason = |
| 109 management::ExtensionInfo::DISABLED_REASON_PERMISSIONS_INCREASE; |
| 110 } else { |
| 111 info->disabled_reason = |
| 112 management::ExtensionInfo::DISABLED_REASON_UNKNOWN; |
| 113 } |
| 114 } |
| 115 |
| 116 if (!extension.update_url().is_empty()) { |
| 117 info->update_url.reset(new std::string( |
| 118 extension.update_url().spec())); |
| 119 } |
| 120 |
| 121 if (extension.is_app()) { |
| 122 info->app_launch_url.reset(new std::string( |
| 123 extension.GetFullLaunchURL().spec())); |
| 124 } |
| 125 |
| 126 const ExtensionIconSet::IconMap& icons = extension.icons().map(); |
| 127 if (!icons.empty()) { |
| 128 info->icons.reset(new IconInfoList()); |
| 129 std::map<ExtensionIconSet::Icons, std::string>::const_iterator icon_iter; |
| 130 for (icon_iter = icons.begin(); icon_iter != icons.end(); ++icon_iter) { |
| 131 management::IconInfo* icon_info = new management::IconInfo(); |
| 132 icon_info->size = icon_iter->first; |
| 133 GURL url = ExtensionIconSource::GetIconURL( |
| 134 &extension, icon_info->size, ExtensionIconSet::MATCH_EXACTLY, false, |
| 135 NULL); |
| 136 icon_info->url = url.spec(); |
| 137 info->icons->push_back(make_linked_ptr<management::IconInfo>(icon_info)); |
| 138 } |
| 139 } |
| 140 |
| 141 const std::set<std::string> perms = |
| 142 extension.GetActivePermissions()->GetAPIsAsStrings(); |
| 143 if (!perms.empty()) { |
| 144 std::set<std::string>::const_iterator perms_iter; |
| 145 for (perms_iter = perms.begin(); perms_iter != perms.end(); ++perms_iter) |
| 146 info->permissions.push_back(*perms_iter); |
| 147 } |
| 148 |
| 149 if (!extension.is_hosted_app()) { |
| 150 // Skip host permissions for hosted apps. |
| 151 const URLPatternSet host_perms = |
| 152 extension.GetActivePermissions()->explicit_hosts(); |
| 153 if (!host_perms.is_empty()) { |
| 154 for (URLPatternSet::const_iterator iter = host_perms.begin(); |
| 155 iter != host_perms.end(); ++iter) { |
| 156 info->host_permissions.push_back(iter->GetAsString()); |
| 157 } |
| 158 } |
| 159 } |
| 160 |
| 161 switch (extension.location()) { |
| 162 case Extension::INTERNAL: |
| 163 info->install_type = management::ExtensionInfo::INSTALL_TYPE_NORMAL; |
| 164 break; |
| 165 case Extension::LOAD: |
| 166 info->install_type = management::ExtensionInfo::INSTALL_TYPE_DEVELOPMENT; |
| 167 break; |
| 168 case Extension::EXTERNAL_PREF: |
| 169 case Extension::EXTERNAL_REGISTRY: |
| 170 case Extension::EXTERNAL_PREF_DOWNLOAD: |
| 171 info->install_type = management::ExtensionInfo::INSTALL_TYPE_SIDELOAD; |
| 172 break; |
| 173 case Extension::EXTERNAL_POLICY_DOWNLOAD: |
| 174 info->install_type = management::ExtensionInfo::INSTALL_TYPE_ADMIN; |
| 175 break; |
| 176 default: |
| 177 info->install_type = management::ExtensionInfo::INSTALL_TYPE_OTHER; |
| 178 break; |
| 179 } |
| 180 |
| 181 return info.Pass(); |
| 182 } |
| 183 |
| 184 void AddExtensionInfo(const ExtensionSet& extensions, |
| 185 ExtensionSystem* system, |
| 186 ExtensionInfoList* extension_list) { |
| 187 for (ExtensionSet::const_iterator iter = extensions.begin(); |
| 188 iter != extensions.end(); ++iter) { |
| 189 const Extension& extension = **iter; |
| 190 |
| 191 if (extension.location() == Extension::COMPONENT) |
| 192 continue; // Skip built-in extensions. |
| 193 |
| 194 extension_list->push_back(make_linked_ptr<management::ExtensionInfo>( |
| 195 CreateExtensionInfo(extension, system).release())); |
| 196 } |
| 197 } |
| 198 |
63 } // namespace | 199 } // namespace |
64 | 200 |
65 ExtensionService* ExtensionManagementFunction::service() { | 201 ExtensionService* ExtensionManagementFunction::service() { |
66 return profile()->GetExtensionService(); | 202 return profile()->GetExtensionService(); |
67 } | 203 } |
68 | 204 |
69 ExtensionService* AsyncExtensionManagementFunction::service() { | 205 ExtensionService* AsyncExtensionManagementFunction::service() { |
70 return profile()->GetExtensionService(); | 206 return profile()->GetExtensionService(); |
71 } | 207 } |
72 | 208 |
73 static DictionaryValue* CreateExtensionInfo(const Extension& extension, | 209 bool GetAllExtensionsFunction::RunImpl() { |
74 ExtensionService* service) { | 210 ExtensionInfoList extensions; |
75 DictionaryValue* info = new DictionaryValue(); | 211 ExtensionSystem* system = ExtensionSystem::Get(profile()); |
76 bool enabled = service->IsExtensionEnabled(extension.id()); | |
77 extension.GetBasicInfo(enabled, info); | |
78 | 212 |
79 const extensions::ManagementPolicy* policy = extensions::ExtensionSystem::Get( | 213 AddExtensionInfo(*service()->extensions(), system, &extensions); |
80 service->profile())->management_policy(); | 214 AddExtensionInfo(*service()->disabled_extensions(), system, &extensions); |
81 info->SetBoolean(keys::kMayDisableKey, | |
82 policy->UserMayModifySettings(&extension, NULL)); | |
83 | 215 |
84 info->SetBoolean(keys::kIsAppKey, extension.is_app()); | 216 results_ = management::GetAll::Results::Create(extensions); |
85 | |
86 if (!enabled) { | |
87 extensions::ExtensionPrefs* prefs = service->extension_prefs(); | |
88 bool permissions_escalated = | |
89 prefs->DidExtensionEscalatePermissions(extension.id()); | |
90 const char* reason = permissions_escalated ? | |
91 keys::kDisabledReasonPermissionsIncrease : keys::kDisabledReasonUnknown; | |
92 info->SetString(keys::kDisabledReasonKey, reason); | |
93 } | |
94 | |
95 if (!extension.update_url().is_empty()) | |
96 info->SetString(keys::kUpdateUrlKey, | |
97 extension.update_url().possibly_invalid_spec()); | |
98 if (extension.is_app()) | |
99 info->SetString(keys::kAppLaunchUrlKey, | |
100 extension.GetFullLaunchURL().possibly_invalid_spec()); | |
101 | |
102 const ExtensionIconSet::IconMap& icons = extension.icons().map(); | |
103 if (!icons.empty()) { | |
104 ListValue* icon_list = new ListValue(); | |
105 std::map<ExtensionIconSet::Icons, std::string>::const_iterator icon_iter; | |
106 for (icon_iter = icons.begin(); icon_iter != icons.end(); ++icon_iter) { | |
107 DictionaryValue* icon_info = new DictionaryValue(); | |
108 ExtensionIconSet::Icons size = icon_iter->first; | |
109 GURL url = ExtensionIconSource::GetIconURL( | |
110 &extension, size, ExtensionIconSet::MATCH_EXACTLY, false, NULL); | |
111 icon_info->SetInteger(keys::kSizeKey, icon_iter->first); | |
112 icon_info->SetString(keys::kUrlKey, url.spec()); | |
113 icon_list->Append(icon_info); | |
114 } | |
115 info->Set(keys::kIconsKey, icon_list); | |
116 } | |
117 | |
118 const std::set<std::string> perms = | |
119 extension.GetActivePermissions()->GetAPIsAsStrings(); | |
120 ListValue* permission_list = new ListValue(); | |
121 if (!perms.empty()) { | |
122 std::set<std::string>::const_iterator perms_iter; | |
123 for (perms_iter = perms.begin(); perms_iter != perms.end(); ++perms_iter) { | |
124 StringValue* permission_name = new StringValue(*perms_iter); | |
125 permission_list->Append(permission_name); | |
126 } | |
127 } | |
128 info->Set(keys::kPermissionsKey, permission_list); | |
129 | |
130 ListValue* host_permission_list = new ListValue(); | |
131 if (!extension.is_hosted_app()) { | |
132 // Skip host permissions for hosted apps. | |
133 const URLPatternSet host_perms = | |
134 extension.GetActivePermissions()->explicit_hosts(); | |
135 if (!host_perms.is_empty()) { | |
136 URLPatternSet::const_iterator host_perms_iter; | |
137 for (host_perms_iter = host_perms.begin(); | |
138 host_perms_iter != host_perms.end(); | |
139 ++host_perms_iter) { | |
140 StringValue* name = new StringValue(host_perms_iter->GetAsString()); | |
141 host_permission_list->Append(name); | |
142 } | |
143 } | |
144 } | |
145 info->Set(keys::kHostPermissionsKey, host_permission_list); | |
146 | |
147 std::string install_type = keys::kInstallTypeOther; | |
148 switch (extension.location()) { | |
149 case Extension::INTERNAL: | |
150 install_type = keys::kInstallTypeNormal; | |
151 break; | |
152 case Extension::LOAD: | |
153 install_type = keys::kInstallTypeDevelopment; | |
154 break; | |
155 case Extension::EXTERNAL_PREF: | |
156 case Extension::EXTERNAL_REGISTRY: | |
157 case Extension::EXTERNAL_PREF_DOWNLOAD: | |
158 install_type = keys::kInstallTypeSideload; | |
159 break; | |
160 case Extension::EXTERNAL_POLICY_DOWNLOAD: | |
161 install_type = keys::kInstallTypeAdmin; | |
162 break; | |
163 default: | |
164 install_type = keys::kInstallTypeOther; | |
165 } | |
166 info->SetString(keys::kInstallTypeKey, install_type); | |
167 | |
168 return info; | |
169 } | |
170 | |
171 static void AddExtensionInfo(ListValue* list, | |
172 const ExtensionSet& extensions, | |
173 ExtensionService* service) { | |
174 for (ExtensionSet::const_iterator i = extensions.begin(); | |
175 i != extensions.end(); ++i) { | |
176 const Extension& extension = **i; | |
177 | |
178 if (extension.location() == Extension::COMPONENT) | |
179 continue; // Skip built-in extensions. | |
180 | |
181 list->Append(CreateExtensionInfo(extension, service)); | |
182 } | |
183 } | |
184 | |
185 bool GetAllExtensionsFunction::RunImpl() { | |
186 ListValue* result = new ListValue(); | |
187 SetResult(result); | |
188 | |
189 AddExtensionInfo(result, *service()->extensions(), service()); | |
190 AddExtensionInfo(result, *service()->disabled_extensions(), service()); | |
191 | |
192 return true; | 217 return true; |
193 } | 218 } |
194 | 219 |
195 bool GetExtensionByIdFunction::RunImpl() { | 220 bool GetExtensionByIdFunction::RunImpl() { |
196 std::string extension_id; | 221 scoped_ptr<management::Get::Params> params( |
197 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id)); | 222 management::Get::Params::Create(*args_)); |
198 const Extension* extension = service()->GetExtensionById(extension_id, true); | 223 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 224 |
| 225 const Extension* extension = service()->GetExtensionById(params->id, true); |
199 if (!extension) { | 226 if (!extension) { |
200 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoExtensionError, | 227 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoExtensionError, |
201 extension_id); | 228 params->id); |
202 return false; | 229 return false; |
203 } | 230 } |
204 DictionaryValue* result = CreateExtensionInfo(*extension, service()); | 231 |
205 SetResult(result); | 232 scoped_ptr<management::ExtensionInfo> info = CreateExtensionInfo( |
| 233 *extension, ExtensionSystem::Get(profile())); |
| 234 results_ = management::Get::Results::Create(*info); |
206 | 235 |
207 return true; | 236 return true; |
208 } | 237 } |
209 | 238 |
210 bool GetPermissionWarningsByIdFunction::RunImpl() { | 239 bool GetPermissionWarningsByIdFunction::RunImpl() { |
211 std::string ext_id; | 240 scoped_ptr<management::GetPermissionWarningsById::Params> params( |
212 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &ext_id)); | 241 management::GetPermissionWarningsById::Params::Create(*args_)); |
| 242 EXTENSION_FUNCTION_VALIDATE(params.get()); |
213 | 243 |
214 const Extension* extension = service()->GetExtensionById(ext_id, true); | 244 const Extension* extension = service()->GetExtensionById(params->id, true); |
215 if (!extension) { | 245 if (!extension) { |
216 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoExtensionError, | 246 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoExtensionError, |
217 ext_id); | 247 params->id); |
218 return false; | 248 return false; |
219 } | 249 } |
220 | 250 |
221 PermissionMessages warnings = extension->GetPermissionMessages(); | 251 std::vector<std::string> warnings = CreateWarningsList(extension); |
222 ListValue* result = new ListValue(); | 252 results_ = management::GetPermissionWarningsById::Results::Create(warnings); |
223 for (PermissionMessages::const_iterator i = warnings.begin(); | |
224 i < warnings.end(); ++i) | |
225 result->Append(Value::CreateStringValue(i->message())); | |
226 SetResult(result); | |
227 return true; | 253 return true; |
228 } | 254 } |
229 | 255 |
230 namespace { | 256 namespace { |
231 | 257 |
232 // This class helps GetPermissionWarningsByManifestFunction manage | 258 // This class helps GetPermissionWarningsByManifestFunction manage |
233 // sending manifest JSON strings to the utility process for parsing. | 259 // sending manifest JSON strings to the utility process for parsing. |
234 class SafeManifestJSONParser : public UtilityProcessHostClient { | 260 class SafeManifestJSONParser : public UtilityProcessHostClient { |
235 public: | 261 public: |
236 SafeManifestJSONParser(GetPermissionWarningsByManifestFunction* client, | 262 SafeManifestJSONParser(GetPermissionWarningsByManifestFunction* client, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 336 |
311 // Results of parsing. | 337 // Results of parsing. |
312 scoped_ptr<DictionaryValue> parsed_manifest_; | 338 scoped_ptr<DictionaryValue> parsed_manifest_; |
313 | 339 |
314 std::string error_; | 340 std::string error_; |
315 }; | 341 }; |
316 | 342 |
317 } // namespace | 343 } // namespace |
318 | 344 |
319 bool GetPermissionWarningsByManifestFunction::RunImpl() { | 345 bool GetPermissionWarningsByManifestFunction::RunImpl() { |
320 std::string manifest_str; | 346 scoped_ptr<management::GetPermissionWarningsByManifest::Params> params( |
321 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &manifest_str)); | 347 management::GetPermissionWarningsByManifest::Params::Create(*args_)); |
| 348 EXTENSION_FUNCTION_VALIDATE(params.get()); |
322 | 349 |
323 scoped_refptr<SafeManifestJSONParser> parser = | 350 scoped_refptr<SafeManifestJSONParser> parser = |
324 new SafeManifestJSONParser(this, manifest_str); | 351 new SafeManifestJSONParser(this, params->manifest_str); |
325 parser->Start(); | 352 parser->Start(); |
326 | 353 |
327 // Matched with a Release() in OnParseSuccess/Failure(). | 354 // Matched with a Release() in OnParseSuccess/Failure(). |
328 AddRef(); | 355 AddRef(); |
329 | 356 |
330 // Response is sent async in OnParseSuccess/Failure(). | 357 // Response is sent async in OnParseSuccess/Failure(). |
331 return true; | 358 return true; |
332 } | 359 } |
333 | 360 |
334 void GetPermissionWarningsByManifestFunction::OnParseSuccess( | 361 void GetPermissionWarningsByManifestFunction::OnParseSuccess( |
335 DictionaryValue* parsed_manifest) { | 362 DictionaryValue* parsed_manifest) { |
336 CHECK(parsed_manifest); | 363 CHECK(parsed_manifest); |
337 | 364 |
338 scoped_refptr<Extension> extension = Extension::Create( | 365 scoped_refptr<Extension> extension = Extension::Create( |
339 FilePath(), Extension::INVALID, *parsed_manifest, Extension::NO_FLAGS, | 366 FilePath(), Extension::INVALID, *parsed_manifest, Extension::NO_FLAGS, |
340 &error_); | 367 &error_); |
341 if (!extension.get()) { | 368 if (!extension.get()) { |
342 OnParseFailure(keys::kExtensionCreateError); | 369 OnParseFailure(keys::kExtensionCreateError); |
343 return; | 370 return; |
344 } | 371 } |
345 | 372 |
346 PermissionMessages warnings = extension->GetPermissionMessages(); | 373 std::vector<std::string> warnings = CreateWarningsList(extension); |
347 ListValue* result = new ListValue(); | 374 results_ = management::GetPermissionWarningsByManifest::Results::Create( |
348 for (PermissionMessages::const_iterator i = warnings.begin(); | 375 warnings); |
349 i < warnings.end(); ++i) | |
350 result->Append(Value::CreateStringValue(i->message())); | |
351 SetResult(result); | |
352 SendResponse(true); | 376 SendResponse(true); |
353 | 377 |
354 // Matched with AddRef() in RunImpl(). | 378 // Matched with AddRef() in RunImpl(). |
355 Release(); | 379 Release(); |
356 } | 380 } |
357 | 381 |
358 void GetPermissionWarningsByManifestFunction::OnParseFailure( | 382 void GetPermissionWarningsByManifestFunction::OnParseFailure( |
359 const std::string& error) { | 383 const std::string& error) { |
360 error_ = error; | 384 error_ = error; |
361 SendResponse(false); | 385 SendResponse(false); |
362 | 386 |
363 // Matched with AddRef() in RunImpl(). | 387 // Matched with AddRef() in RunImpl(). |
364 Release(); | 388 Release(); |
365 } | 389 } |
366 | 390 |
367 bool LaunchAppFunction::RunImpl() { | 391 bool LaunchAppFunction::RunImpl() { |
368 std::string extension_id; | 392 scoped_ptr<management::LaunchApp::Params> params( |
369 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id)); | 393 management::LaunchApp::Params::Create(*args_)); |
370 const Extension* extension = service()->GetExtensionById(extension_id, true); | 394 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 395 const Extension* extension = service()->GetExtensionById(params->id, true); |
371 if (!extension) { | 396 if (!extension) { |
372 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoExtensionError, | 397 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoExtensionError, |
373 extension_id); | 398 params->id); |
374 return false; | 399 return false; |
375 } | 400 } |
376 if (!extension->is_app()) { | 401 if (!extension->is_app()) { |
377 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNotAnAppError, | 402 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNotAnAppError, |
378 extension_id); | 403 params->id); |
379 return false; | 404 return false; |
380 } | 405 } |
381 | 406 |
382 // Look at prefs to find the right launch container. | 407 // Look at prefs to find the right launch container. |
383 // |default_pref_value| is set to LAUNCH_REGULAR so that if | 408 // |default_pref_value| is set to LAUNCH_REGULAR so that if |
384 // the user has not set a preference, we open the app in a tab. | 409 // the user has not set a preference, we open the app in a tab. |
385 extension_misc::LaunchContainer launch_container = | 410 extension_misc::LaunchContainer launch_container = |
386 service()->extension_prefs()->GetLaunchContainer( | 411 service()->extension_prefs()->GetLaunchContainer( |
387 extension, extensions::ExtensionPrefs::LAUNCH_DEFAULT); | 412 extension, extensions::ExtensionPrefs::LAUNCH_DEFAULT); |
388 application_launch::OpenApplication(application_launch::LaunchParams( | 413 application_launch::OpenApplication(application_launch::LaunchParams( |
389 profile(), extension, launch_container, NEW_FOREGROUND_TAB)); | 414 profile(), extension, launch_container, NEW_FOREGROUND_TAB)); |
390 #if !defined(OS_ANDROID) | 415 #if !defined(OS_ANDROID) |
391 AppLauncherHandler::RecordAppLaunchType( | 416 AppLauncherHandler::RecordAppLaunchType( |
392 extension_misc::APP_LAUNCH_EXTENSION_API); | 417 extension_misc::APP_LAUNCH_EXTENSION_API); |
393 #endif | 418 #endif |
394 | 419 |
395 return true; | 420 return true; |
396 } | 421 } |
397 | 422 |
398 SetEnabledFunction::SetEnabledFunction() { | 423 SetEnabledFunction::SetEnabledFunction() { |
399 } | 424 } |
400 | 425 |
401 SetEnabledFunction::~SetEnabledFunction() { | 426 SetEnabledFunction::~SetEnabledFunction() { |
402 } | 427 } |
403 | 428 |
404 bool SetEnabledFunction::RunImpl() { | 429 bool SetEnabledFunction::RunImpl() { |
405 bool enable; | 430 scoped_ptr<management::SetEnabled::Params> params( |
406 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_)); | 431 management::SetEnabled::Params::Create(*args_)); |
407 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &enable)); | 432 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 433 |
| 434 extension_id_ = params->id; |
408 | 435 |
409 const Extension* extension = service()->GetExtensionById(extension_id_, true); | 436 const Extension* extension = service()->GetExtensionById(extension_id_, true); |
410 if (!extension) { | 437 if (!extension) { |
411 error_ = ExtensionErrorUtils::FormatErrorMessage( | 438 error_ = ExtensionErrorUtils::FormatErrorMessage( |
412 keys::kNoExtensionError, extension_id_); | 439 keys::kNoExtensionError, extension_id_); |
413 return false; | 440 return false; |
414 } | 441 } |
415 | 442 |
416 const extensions::ManagementPolicy* policy = extensions::ExtensionSystem::Get( | 443 const extensions::ManagementPolicy* policy = extensions::ExtensionSystem::Get( |
417 profile())->management_policy(); | 444 profile())->management_policy(); |
418 if (!policy->UserMayModifySettings(extension, NULL)) { | 445 if (!policy->UserMayModifySettings(extension, NULL)) { |
419 error_ = ExtensionErrorUtils::FormatErrorMessage( | 446 error_ = ExtensionErrorUtils::FormatErrorMessage( |
420 keys::kUserCantModifyError, extension_id_); | 447 keys::kUserCantModifyError, extension_id_); |
421 return false; | 448 return false; |
422 } | 449 } |
423 | 450 |
424 bool currently_enabled = service()->IsExtensionEnabled(extension_id_); | 451 bool currently_enabled = service()->IsExtensionEnabled(extension_id_); |
425 | 452 |
426 if (!currently_enabled && enable) { | 453 if (!currently_enabled && params->enabled) { |
427 extensions::ExtensionPrefs* prefs = service()->extension_prefs(); | 454 extensions::ExtensionPrefs* prefs = service()->extension_prefs(); |
428 if (prefs->DidExtensionEscalatePermissions(extension_id_)) { | 455 if (prefs->DidExtensionEscalatePermissions(extension_id_)) { |
429 if (!user_gesture()) { | 456 if (!user_gesture()) { |
430 error_ = keys::kGestureNeededForEscalationError; | 457 error_ = keys::kGestureNeededForEscalationError; |
431 return false; | 458 return false; |
432 } | 459 } |
433 AddRef(); // Matched in InstallUIProceed/InstallUIAbort | 460 AddRef(); // Matched in InstallUIProceed/InstallUIAbort |
434 install_prompt_.reset( | 461 install_prompt_.reset( |
435 chrome::CreateExtensionInstallPromptWithBrowser(GetCurrentBrowser())); | 462 chrome::CreateExtensionInstallPromptWithBrowser(GetCurrentBrowser())); |
436 install_prompt_->ConfirmReEnable(this, extension); | 463 install_prompt_->ConfirmReEnable(this, extension); |
437 return true; | 464 return true; |
438 } | 465 } |
439 service()->EnableExtension(extension_id_); | 466 service()->EnableExtension(extension_id_); |
440 } else if (currently_enabled && !enable) { | 467 } else if (currently_enabled && !params->enabled) { |
441 service()->DisableExtension(extension_id_, Extension::DISABLE_USER_ACTION); | 468 service()->DisableExtension(extension_id_, Extension::DISABLE_USER_ACTION); |
442 } | 469 } |
443 | 470 |
444 BrowserThread::PostTask( | 471 BrowserThread::PostTask( |
445 BrowserThread::UI, | 472 BrowserThread::UI, |
446 FROM_HERE, | 473 FROM_HERE, |
447 base::Bind(&SetEnabledFunction::SendResponse, this, true)); | 474 base::Bind(&SetEnabledFunction::SendResponse, this, true)); |
448 | 475 |
449 return true; | 476 return true; |
450 } | 477 } |
(...skipping 10 matching lines...) Expand all Loading... |
461 Release(); | 488 Release(); |
462 } | 489 } |
463 | 490 |
464 UninstallFunction::UninstallFunction() { | 491 UninstallFunction::UninstallFunction() { |
465 } | 492 } |
466 | 493 |
467 UninstallFunction::~UninstallFunction() { | 494 UninstallFunction::~UninstallFunction() { |
468 } | 495 } |
469 | 496 |
470 bool UninstallFunction::RunImpl() { | 497 bool UninstallFunction::RunImpl() { |
| 498 scoped_ptr<management::Uninstall::Params> params( |
| 499 management::Uninstall::Params::Create(*args_)); |
| 500 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 501 |
| 502 extension_id_ = params->id; |
| 503 |
471 bool show_confirm_dialog = false; | 504 bool show_confirm_dialog = false; |
472 | 505 if (params->options.get() && params->options->show_confirm_dialog.get()) |
473 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_)); | 506 show_confirm_dialog = *params->options->show_confirm_dialog; |
474 | |
475 if (HasOptionalArgument(1)) { | |
476 DictionaryValue* options = NULL; | |
477 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &options)); | |
478 | |
479 if (options->HasKey(keys::kShowConfirmDialogKey)) { | |
480 EXTENSION_FUNCTION_VALIDATE(options->GetBoolean( | |
481 keys::kShowConfirmDialogKey, &show_confirm_dialog)); | |
482 } | |
483 } | |
484 | 507 |
485 const Extension* extension = service()->GetExtensionById(extension_id_, true); | 508 const Extension* extension = service()->GetExtensionById(extension_id_, true); |
486 if (!extension) { | 509 if (!extension) { |
487 error_ = ExtensionErrorUtils::FormatErrorMessage( | 510 error_ = ExtensionErrorUtils::FormatErrorMessage( |
488 keys::kNoExtensionError, extension_id_); | 511 keys::kNoExtensionError, extension_id_); |
489 return false; | 512 return false; |
490 } | 513 } |
491 | 514 |
492 if (!extensions::ExtensionSystem::Get( | 515 if (!extensions::ExtensionSystem::Get( |
493 profile())->management_policy()->UserMayModifySettings(extension, NULL)) { | 516 profile())->management_policy()->UserMayModifySettings(extension, NULL)) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 event_name = events::kOnExtensionDisabled; | 611 event_name = events::kOnExtensionDisabled; |
589 break; | 612 break; |
590 default: | 613 default: |
591 NOTREACHED(); | 614 NOTREACHED(); |
592 return; | 615 return; |
593 } | 616 } |
594 | 617 |
595 scoped_ptr<ListValue> args(new ListValue()); | 618 scoped_ptr<ListValue> args(new ListValue()); |
596 if (event_name == events::kOnExtensionUninstalled) { | 619 if (event_name == events::kOnExtensionUninstalled) { |
597 args->Append(Value::CreateStringValue( | 620 args->Append(Value::CreateStringValue( |
598 content::Details<const extensions::Extension>(details).ptr()->id())); | 621 content::Details<const Extension>(details).ptr()->id())); |
599 } else { | 622 } else { |
600 const Extension* extension = NULL; | 623 const Extension* extension = NULL; |
601 if (event_name == events::kOnExtensionDisabled) { | 624 if (event_name == events::kOnExtensionDisabled) { |
602 extension = content::Details<extensions::UnloadedExtensionInfo>( | 625 extension = content::Details<extensions::UnloadedExtensionInfo>( |
603 details)->extension; | 626 details)->extension; |
604 } else { | 627 } else { |
605 extension = content::Details<const Extension>(details).ptr(); | 628 extension = content::Details<const Extension>(details).ptr(); |
606 } | 629 } |
607 CHECK(extension); | 630 CHECK(extension); |
608 ExtensionService* service = profile->GetExtensionService(); | 631 scoped_ptr<management::ExtensionInfo> info = CreateExtensionInfo( |
609 args->Append(CreateExtensionInfo(*extension, service)); | 632 *extension, ExtensionSystem::Get(profile)); |
| 633 args->Append(info->ToValue().release()); |
610 } | 634 } |
611 | 635 |
612 profile->GetExtensionEventRouter()->DispatchEventToRenderers( | 636 profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
613 event_name, args.Pass(), NULL, GURL(), extensions::EventFilteringInfo()); | 637 event_name, args.Pass(), NULL, GURL(), extensions::EventFilteringInfo()); |
614 } | 638 } |
OLD | NEW |