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

Side by Side Diff: chrome/browser/extensions/api/management/management_api.cc

Issue 11312228: Move extension_error_utils.* and url_pattern_set.* into (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: hate Created 8 years, 1 month 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) 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 #include <vector>
10 10
(...skipping 14 matching lines...) Expand all
25 #include "chrome/browser/extensions/extension_uninstall_dialog.h" 25 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
26 #include "chrome/browser/extensions/management_policy.h" 26 #include "chrome/browser/extensions/management_policy.h"
27 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/ui/extensions/application_launch.h" 28 #include "chrome/browser/ui/extensions/application_launch.h"
29 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" 29 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
30 #include "chrome/common/chrome_notification_types.h" 30 #include "chrome/common/chrome_notification_types.h"
31 #include "chrome/common/chrome_utility_messages.h" 31 #include "chrome/common/chrome_utility_messages.h"
32 #include "chrome/common/extensions/api/management.h" 32 #include "chrome/common/extensions/api/management.h"
33 #include "chrome/common/extensions/extension.h" 33 #include "chrome/common/extensions/extension.h"
34 #include "chrome/common/extensions/extension_constants.h" 34 #include "chrome/common/extensions/extension_constants.h"
35 #include "chrome/common/extensions/extension_error_utils.h"
36 #include "chrome/common/extensions/extension_icon_set.h" 35 #include "chrome/common/extensions/extension_icon_set.h"
37 #include "chrome/common/extensions/permissions/permission_set.h" 36 #include "chrome/common/extensions/permissions/permission_set.h"
38 #include "content/public/browser/notification_details.h" 37 #include "content/public/browser/notification_details.h"
39 #include "content/public/browser/notification_source.h" 38 #include "content/public/browser/notification_source.h"
40 #include "content/public/browser/utility_process_host.h" 39 #include "content/public/browser/utility_process_host.h"
41 #include "content/public/browser/utility_process_host_client.h" 40 #include "content/public/browser/utility_process_host_client.h"
41 #include "extensions/common/error_utils.h"
42 #include "extensions/common/url_pattern.h" 42 #include "extensions/common/url_pattern.h"
43 43
44 #if !defined(OS_ANDROID) 44 #if !defined(OS_ANDROID)
45 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" 45 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
46 #endif 46 #endif
47 47
48 using base::IntToString; 48 using base::IntToString;
49 using content::BrowserThread; 49 using content::BrowserThread;
50 using content::UtilityProcessHost; 50 using content::UtilityProcessHost;
51 using content::UtilityProcessHostClient; 51 using content::UtilityProcessHostClient;
52 using extensions::api::management::ExtensionInfo; 52 using extensions::api::management::ExtensionInfo;
53 using extensions::api::management::IconInfo; 53 using extensions::api::management::IconInfo;
54 using extensions::ErrorUtils;
54 using extensions::Extension; 55 using extensions::Extension;
55 using extensions::ExtensionSystem; 56 using extensions::ExtensionSystem;
56 using extensions::PermissionMessages; 57 using extensions::PermissionMessages;
57 58
58 namespace events = extensions::event_names; 59 namespace events = extensions::event_names;
59 namespace keys = extension_management_api_constants; 60 namespace keys = extension_management_api_constants;
60 namespace management = extensions::api::management; 61 namespace management = extensions::api::management;
61 62
62 namespace { 63 namespace {
63 64
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 const std::set<std::string> perms = 156 const std::set<std::string> perms =
156 extension.GetActivePermissions()->GetAPIsAsStrings(); 157 extension.GetActivePermissions()->GetAPIsAsStrings();
157 if (!perms.empty()) { 158 if (!perms.empty()) {
158 std::set<std::string>::const_iterator perms_iter; 159 std::set<std::string>::const_iterator perms_iter;
159 for (perms_iter = perms.begin(); perms_iter != perms.end(); ++perms_iter) 160 for (perms_iter = perms.begin(); perms_iter != perms.end(); ++perms_iter)
160 info->permissions.push_back(*perms_iter); 161 info->permissions.push_back(*perms_iter);
161 } 162 }
162 163
163 if (!extension.is_hosted_app()) { 164 if (!extension.is_hosted_app()) {
164 // Skip host permissions for hosted apps. 165 // Skip host permissions for hosted apps.
165 const URLPatternSet host_perms = 166 const extensions::URLPatternSet host_perms =
166 extension.GetActivePermissions()->explicit_hosts(); 167 extension.GetActivePermissions()->explicit_hosts();
167 if (!host_perms.is_empty()) { 168 if (!host_perms.is_empty()) {
168 for (URLPatternSet::const_iterator iter = host_perms.begin(); 169 for (extensions::URLPatternSet::const_iterator iter = host_perms.begin();
169 iter != host_perms.end(); ++iter) { 170 iter != host_perms.end(); ++iter) {
170 info->host_permissions.push_back(iter->GetAsString()); 171 info->host_permissions.push_back(iter->GetAsString());
171 } 172 }
172 } 173 }
173 } 174 }
174 175
175 switch (extension.location()) { 176 switch (extension.location()) {
176 case Extension::INTERNAL: 177 case Extension::INTERNAL:
177 info->install_type = management::ExtensionInfo::INSTALL_TYPE_NORMAL; 178 info->install_type = management::ExtensionInfo::INSTALL_TYPE_NORMAL;
178 break; 179 break;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 return true; 233 return true;
233 } 234 }
234 235
235 bool GetExtensionByIdFunction::RunImpl() { 236 bool GetExtensionByIdFunction::RunImpl() {
236 scoped_ptr<management::Get::Params> params( 237 scoped_ptr<management::Get::Params> params(
237 management::Get::Params::Create(*args_)); 238 management::Get::Params::Create(*args_));
238 EXTENSION_FUNCTION_VALIDATE(params.get()); 239 EXTENSION_FUNCTION_VALIDATE(params.get());
239 240
240 const Extension* extension = service()->GetExtensionById(params->id, true); 241 const Extension* extension = service()->GetExtensionById(params->id, true);
241 if (!extension) { 242 if (!extension) {
242 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoExtensionError, 243 error_ = ErrorUtils::FormatErrorMessage(keys::kNoExtensionError,
243 params->id); 244 params->id);
244 return false; 245 return false;
245 } 246 }
246 247
247 scoped_ptr<management::ExtensionInfo> info = CreateExtensionInfo( 248 scoped_ptr<management::ExtensionInfo> info = CreateExtensionInfo(
248 *extension, ExtensionSystem::Get(profile())); 249 *extension, ExtensionSystem::Get(profile()));
249 results_ = management::Get::Results::Create(*info); 250 results_ = management::Get::Results::Create(*info);
250 251
251 return true; 252 return true;
252 } 253 }
253 254
254 bool GetPermissionWarningsByIdFunction::RunImpl() { 255 bool GetPermissionWarningsByIdFunction::RunImpl() {
255 scoped_ptr<management::GetPermissionWarningsById::Params> params( 256 scoped_ptr<management::GetPermissionWarningsById::Params> params(
256 management::GetPermissionWarningsById::Params::Create(*args_)); 257 management::GetPermissionWarningsById::Params::Create(*args_));
257 EXTENSION_FUNCTION_VALIDATE(params.get()); 258 EXTENSION_FUNCTION_VALIDATE(params.get());
258 259
259 const Extension* extension = service()->GetExtensionById(params->id, true); 260 const Extension* extension = service()->GetExtensionById(params->id, true);
260 if (!extension) { 261 if (!extension) {
261 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoExtensionError, 262 error_ = ErrorUtils::FormatErrorMessage(keys::kNoExtensionError,
262 params->id); 263 params->id);
263 return false; 264 return false;
264 } 265 }
265 266
266 std::vector<std::string> warnings = CreateWarningsList(extension); 267 std::vector<std::string> warnings = CreateWarningsList(extension);
267 results_ = management::GetPermissionWarningsById::Results::Create(warnings); 268 results_ = management::GetPermissionWarningsById::Results::Create(warnings);
268 return true; 269 return true;
269 } 270 }
270 271
271 namespace { 272 namespace {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 // Matched with AddRef() in RunImpl(). 405 // Matched with AddRef() in RunImpl().
405 Release(); 406 Release();
406 } 407 }
407 408
408 bool LaunchAppFunction::RunImpl() { 409 bool LaunchAppFunction::RunImpl() {
409 scoped_ptr<management::LaunchApp::Params> params( 410 scoped_ptr<management::LaunchApp::Params> params(
410 management::LaunchApp::Params::Create(*args_)); 411 management::LaunchApp::Params::Create(*args_));
411 EXTENSION_FUNCTION_VALIDATE(params.get()); 412 EXTENSION_FUNCTION_VALIDATE(params.get());
412 const Extension* extension = service()->GetExtensionById(params->id, true); 413 const Extension* extension = service()->GetExtensionById(params->id, true);
413 if (!extension) { 414 if (!extension) {
414 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoExtensionError, 415 error_ = ErrorUtils::FormatErrorMessage(keys::kNoExtensionError,
415 params->id); 416 params->id);
416 return false; 417 return false;
417 } 418 }
418 if (!extension->is_app()) { 419 if (!extension->is_app()) {
419 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNotAnAppError, 420 error_ = ErrorUtils::FormatErrorMessage(keys::kNotAnAppError,
420 params->id); 421 params->id);
421 return false; 422 return false;
422 } 423 }
423 424
424 // Look at prefs to find the right launch container. 425 // Look at prefs to find the right launch container.
425 // |default_pref_value| is set to LAUNCH_REGULAR so that if 426 // |default_pref_value| is set to LAUNCH_REGULAR so that if
426 // the user has not set a preference, we open the app in a tab. 427 // the user has not set a preference, we open the app in a tab.
427 extension_misc::LaunchContainer launch_container = 428 extension_misc::LaunchContainer launch_container =
428 service()->extension_prefs()->GetLaunchContainer( 429 service()->extension_prefs()->GetLaunchContainer(
429 extension, extensions::ExtensionPrefs::LAUNCH_DEFAULT); 430 extension, extensions::ExtensionPrefs::LAUNCH_DEFAULT);
(...skipping 15 matching lines...) Expand all
445 446
446 bool SetEnabledFunction::RunImpl() { 447 bool SetEnabledFunction::RunImpl() {
447 scoped_ptr<management::SetEnabled::Params> params( 448 scoped_ptr<management::SetEnabled::Params> params(
448 management::SetEnabled::Params::Create(*args_)); 449 management::SetEnabled::Params::Create(*args_));
449 EXTENSION_FUNCTION_VALIDATE(params.get()); 450 EXTENSION_FUNCTION_VALIDATE(params.get());
450 451
451 extension_id_ = params->id; 452 extension_id_ = params->id;
452 453
453 const Extension* extension = service()->GetInstalledExtension(extension_id_); 454 const Extension* extension = service()->GetInstalledExtension(extension_id_);
454 if (!extension) { 455 if (!extension) {
455 error_ = ExtensionErrorUtils::FormatErrorMessage( 456 error_ = ErrorUtils::FormatErrorMessage(
456 keys::kNoExtensionError, extension_id_); 457 keys::kNoExtensionError, extension_id_);
457 return false; 458 return false;
458 } 459 }
459 460
460 const extensions::ManagementPolicy* policy = extensions::ExtensionSystem::Get( 461 const extensions::ManagementPolicy* policy = extensions::ExtensionSystem::Get(
461 profile())->management_policy(); 462 profile())->management_policy();
462 if (!policy->UserMayModifySettings(extension, NULL)) { 463 if (!policy->UserMayModifySettings(extension, NULL)) {
463 error_ = ExtensionErrorUtils::FormatErrorMessage( 464 error_ = ErrorUtils::FormatErrorMessage(
464 keys::kUserCantModifyError, extension_id_); 465 keys::kUserCantModifyError, extension_id_);
465 return false; 466 return false;
466 } 467 }
467 468
468 bool currently_enabled = service()->IsExtensionEnabled(extension_id_); 469 bool currently_enabled = service()->IsExtensionEnabled(extension_id_);
469 470
470 if (!currently_enabled && params->enabled) { 471 if (!currently_enabled && params->enabled) {
471 extensions::ExtensionPrefs* prefs = service()->extension_prefs(); 472 extensions::ExtensionPrefs* prefs = service()->extension_prefs();
472 if (prefs->DidExtensionEscalatePermissions(extension_id_)) { 473 if (prefs->DidExtensionEscalatePermissions(extension_id_)) {
473 if (!user_gesture()) { 474 if (!user_gesture()) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 EXTENSION_FUNCTION_VALIDATE(params.get()); 518 EXTENSION_FUNCTION_VALIDATE(params.get());
518 519
519 extension_id_ = params->id; 520 extension_id_ = params->id;
520 521
521 bool show_confirm_dialog = false; 522 bool show_confirm_dialog = false;
522 if (params->options.get() && params->options->show_confirm_dialog.get()) 523 if (params->options.get() && params->options->show_confirm_dialog.get())
523 show_confirm_dialog = *params->options->show_confirm_dialog; 524 show_confirm_dialog = *params->options->show_confirm_dialog;
524 525
525 const Extension* extension = service()->GetExtensionById(extension_id_, true); 526 const Extension* extension = service()->GetExtensionById(extension_id_, true);
526 if (!extension) { 527 if (!extension) {
527 error_ = ExtensionErrorUtils::FormatErrorMessage( 528 error_ = ErrorUtils::FormatErrorMessage(
528 keys::kNoExtensionError, extension_id_); 529 keys::kNoExtensionError, extension_id_);
529 return false; 530 return false;
530 } 531 }
531 532
532 if (!extensions::ExtensionSystem::Get( 533 if (!extensions::ExtensionSystem::Get(
533 profile())->management_policy()->UserMayModifySettings(extension, NULL)) { 534 profile())->management_policy()->UserMayModifySettings(extension, NULL)) {
534 error_ = ExtensionErrorUtils::FormatErrorMessage( 535 error_ = ErrorUtils::FormatErrorMessage(
535 keys::kUserCantModifyError, extension_id_); 536 keys::kUserCantModifyError, extension_id_);
536 return false; 537 return false;
537 } 538 }
538 539
539 if (auto_confirm_for_test == DO_NOT_SKIP) { 540 if (auto_confirm_for_test == DO_NOT_SKIP) {
540 if (show_confirm_dialog) { 541 if (show_confirm_dialog) {
541 AddRef(); // Balanced in ExtensionUninstallAccepted/Canceled 542 AddRef(); // Balanced in ExtensionUninstallAccepted/Canceled
542 extension_uninstall_dialog_.reset(ExtensionUninstallDialog::Create( 543 extension_uninstall_dialog_.reset(ExtensionUninstallDialog::Create(
543 GetCurrentBrowser(), this)); 544 GetCurrentBrowser(), this));
544 extension_uninstall_dialog_->ConfirmUninstall(extension); 545 extension_uninstall_dialog_->ConfirmUninstall(extension);
(...skipping 15 matching lines...) Expand all
560 void UninstallFunction::Finish(bool should_uninstall) { 561 void UninstallFunction::Finish(bool should_uninstall) {
561 if (should_uninstall) { 562 if (should_uninstall) {
562 bool success = service()->UninstallExtension( 563 bool success = service()->UninstallExtension(
563 extension_id_, 564 extension_id_,
564 false, /* external uninstall */ 565 false, /* external uninstall */
565 NULL); 566 NULL);
566 567
567 // TODO set error_ if !success 568 // TODO set error_ if !success
568 SendResponse(success); 569 SendResponse(success);
569 } else { 570 } else {
570 error_ = ExtensionErrorUtils::FormatErrorMessage( 571 error_ = ErrorUtils::FormatErrorMessage(
571 keys::kUninstallCanceledError, extension_id_); 572 keys::kUninstallCanceledError, extension_id_);
572 SendResponse(false); 573 SendResponse(false);
573 } 574 }
574 575
575 } 576 }
576 577
577 void UninstallFunction::ExtensionUninstallAccepted() { 578 void UninstallFunction::ExtensionUninstallAccepted() {
578 Finish(true); 579 Finish(true);
579 Release(); 580 Release();
580 } 581 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 CHECK(extension); 646 CHECK(extension);
646 scoped_ptr<management::ExtensionInfo> info = CreateExtensionInfo( 647 scoped_ptr<management::ExtensionInfo> info = CreateExtensionInfo(
647 *extension, ExtensionSystem::Get(profile)); 648 *extension, ExtensionSystem::Get(profile));
648 args->Append(info->ToValue().release()); 649 args->Append(info->ToValue().release());
649 } 650 }
650 651
651 extensions::ExtensionSystem::Get(profile)->event_router()-> 652 extensions::ExtensionSystem::Get(profile)->event_router()->
652 DispatchEventToRenderers(event_name, args.Pass(), NULL, GURL(), 653 DispatchEventToRenderers(event_name, args.Pass(), NULL, GURL(),
653 extensions::EventFilteringInfo()); 654 extensions::EventFilteringInfo());
654 } 655 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698