| 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 #include <vector> |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 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/extension_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 Loading... |
| 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 Loading... |
| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 // Matched with AddRef() in RunImpl(). | 403 // Matched with AddRef() in RunImpl(). |
| 403 Release(); | 404 Release(); |
| 404 } | 405 } |
| 405 | 406 |
| 406 bool LaunchAppFunction::RunImpl() { | 407 bool LaunchAppFunction::RunImpl() { |
| 407 scoped_ptr<management::LaunchApp::Params> params( | 408 scoped_ptr<management::LaunchApp::Params> params( |
| 408 management::LaunchApp::Params::Create(*args_)); | 409 management::LaunchApp::Params::Create(*args_)); |
| 409 EXTENSION_FUNCTION_VALIDATE(params.get()); | 410 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 410 const Extension* extension = service()->GetExtensionById(params->id, true); | 411 const Extension* extension = service()->GetExtensionById(params->id, true); |
| 411 if (!extension) { | 412 if (!extension) { |
| 412 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoExtensionError, | 413 error_ = ErrorUtils::FormatErrorMessage(keys::kNoExtensionError, |
| 413 params->id); | 414 params->id); |
| 414 return false; | 415 return false; |
| 415 } | 416 } |
| 416 if (!extension->is_app()) { | 417 if (!extension->is_app()) { |
| 417 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNotAnAppError, | 418 error_ = ErrorUtils::FormatErrorMessage(keys::kNotAnAppError, |
| 418 params->id); | 419 params->id); |
| 419 return false; | 420 return false; |
| 420 } | 421 } |
| 421 | 422 |
| 422 // Look at prefs to find the right launch container. | 423 // Look at prefs to find the right launch container. |
| 423 // |default_pref_value| is set to LAUNCH_REGULAR so that if | 424 // |default_pref_value| is set to LAUNCH_REGULAR so that if |
| 424 // the user has not set a preference, we open the app in a tab. | 425 // the user has not set a preference, we open the app in a tab. |
| 425 extension_misc::LaunchContainer launch_container = | 426 extension_misc::LaunchContainer launch_container = |
| 426 service()->extension_prefs()->GetLaunchContainer( | 427 service()->extension_prefs()->GetLaunchContainer( |
| 427 extension, extensions::ExtensionPrefs::LAUNCH_DEFAULT); | 428 extension, extensions::ExtensionPrefs::LAUNCH_DEFAULT); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 443 | 444 |
| 444 bool SetEnabledFunction::RunImpl() { | 445 bool SetEnabledFunction::RunImpl() { |
| 445 scoped_ptr<management::SetEnabled::Params> params( | 446 scoped_ptr<management::SetEnabled::Params> params( |
| 446 management::SetEnabled::Params::Create(*args_)); | 447 management::SetEnabled::Params::Create(*args_)); |
| 447 EXTENSION_FUNCTION_VALIDATE(params.get()); | 448 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 448 | 449 |
| 449 extension_id_ = params->id; | 450 extension_id_ = params->id; |
| 450 | 451 |
| 451 const Extension* extension = service()->GetInstalledExtension(extension_id_); | 452 const Extension* extension = service()->GetInstalledExtension(extension_id_); |
| 452 if (!extension) { | 453 if (!extension) { |
| 453 error_ = ExtensionErrorUtils::FormatErrorMessage( | 454 error_ = ErrorUtils::FormatErrorMessage( |
| 454 keys::kNoExtensionError, extension_id_); | 455 keys::kNoExtensionError, extension_id_); |
| 455 return false; | 456 return false; |
| 456 } | 457 } |
| 457 | 458 |
| 458 const extensions::ManagementPolicy* policy = extensions::ExtensionSystem::Get( | 459 const extensions::ManagementPolicy* policy = extensions::ExtensionSystem::Get( |
| 459 profile())->management_policy(); | 460 profile())->management_policy(); |
| 460 if (!policy->UserMayModifySettings(extension, NULL)) { | 461 if (!policy->UserMayModifySettings(extension, NULL)) { |
| 461 error_ = ExtensionErrorUtils::FormatErrorMessage( | 462 error_ = ErrorUtils::FormatErrorMessage( |
| 462 keys::kUserCantModifyError, extension_id_); | 463 keys::kUserCantModifyError, extension_id_); |
| 463 return false; | 464 return false; |
| 464 } | 465 } |
| 465 | 466 |
| 466 bool currently_enabled = service()->IsExtensionEnabled(extension_id_); | 467 bool currently_enabled = service()->IsExtensionEnabled(extension_id_); |
| 467 | 468 |
| 468 if (!currently_enabled && params->enabled) { | 469 if (!currently_enabled && params->enabled) { |
| 469 extensions::ExtensionPrefs* prefs = service()->extension_prefs(); | 470 extensions::ExtensionPrefs* prefs = service()->extension_prefs(); |
| 470 if (prefs->DidExtensionEscalatePermissions(extension_id_)) { | 471 if (prefs->DidExtensionEscalatePermissions(extension_id_)) { |
| 471 if (!user_gesture()) { | 472 if (!user_gesture()) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 EXTENSION_FUNCTION_VALIDATE(params.get()); | 516 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 516 | 517 |
| 517 extension_id_ = params->id; | 518 extension_id_ = params->id; |
| 518 | 519 |
| 519 bool show_confirm_dialog = false; | 520 bool show_confirm_dialog = false; |
| 520 if (params->options.get() && params->options->show_confirm_dialog.get()) | 521 if (params->options.get() && params->options->show_confirm_dialog.get()) |
| 521 show_confirm_dialog = *params->options->show_confirm_dialog; | 522 show_confirm_dialog = *params->options->show_confirm_dialog; |
| 522 | 523 |
| 523 const Extension* extension = service()->GetExtensionById(extension_id_, true); | 524 const Extension* extension = service()->GetExtensionById(extension_id_, true); |
| 524 if (!extension) { | 525 if (!extension) { |
| 525 error_ = ExtensionErrorUtils::FormatErrorMessage( | 526 error_ = ErrorUtils::FormatErrorMessage( |
| 526 keys::kNoExtensionError, extension_id_); | 527 keys::kNoExtensionError, extension_id_); |
| 527 return false; | 528 return false; |
| 528 } | 529 } |
| 529 | 530 |
| 530 if (!extensions::ExtensionSystem::Get( | 531 if (!extensions::ExtensionSystem::Get( |
| 531 profile())->management_policy()->UserMayModifySettings(extension, NULL)) { | 532 profile())->management_policy()->UserMayModifySettings(extension, NULL)) { |
| 532 error_ = ExtensionErrorUtils::FormatErrorMessage( | 533 error_ = ErrorUtils::FormatErrorMessage( |
| 533 keys::kUserCantModifyError, extension_id_); | 534 keys::kUserCantModifyError, extension_id_); |
| 534 return false; | 535 return false; |
| 535 } | 536 } |
| 536 | 537 |
| 537 if (auto_confirm_for_test == DO_NOT_SKIP) { | 538 if (auto_confirm_for_test == DO_NOT_SKIP) { |
| 538 if (show_confirm_dialog) { | 539 if (show_confirm_dialog) { |
| 539 AddRef(); // Balanced in ExtensionUninstallAccepted/Canceled | 540 AddRef(); // Balanced in ExtensionUninstallAccepted/Canceled |
| 540 extension_uninstall_dialog_.reset(ExtensionUninstallDialog::Create( | 541 extension_uninstall_dialog_.reset(ExtensionUninstallDialog::Create( |
| 541 GetCurrentBrowser(), this)); | 542 GetCurrentBrowser(), this)); |
| 542 extension_uninstall_dialog_->ConfirmUninstall(extension); | 543 extension_uninstall_dialog_->ConfirmUninstall(extension); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 558 void UninstallFunction::Finish(bool should_uninstall) { | 559 void UninstallFunction::Finish(bool should_uninstall) { |
| 559 if (should_uninstall) { | 560 if (should_uninstall) { |
| 560 bool success = service()->UninstallExtension( | 561 bool success = service()->UninstallExtension( |
| 561 extension_id_, | 562 extension_id_, |
| 562 false, /* external uninstall */ | 563 false, /* external uninstall */ |
| 563 NULL); | 564 NULL); |
| 564 | 565 |
| 565 // TODO set error_ if !success | 566 // TODO set error_ if !success |
| 566 SendResponse(success); | 567 SendResponse(success); |
| 567 } else { | 568 } else { |
| 568 error_ = ExtensionErrorUtils::FormatErrorMessage( | 569 error_ = ErrorUtils::FormatErrorMessage( |
| 569 keys::kUninstallCanceledError, extension_id_); | 570 keys::kUninstallCanceledError, extension_id_); |
| 570 SendResponse(false); | 571 SendResponse(false); |
| 571 } | 572 } |
| 572 | 573 |
| 573 } | 574 } |
| 574 | 575 |
| 575 void UninstallFunction::ExtensionUninstallAccepted() { | 576 void UninstallFunction::ExtensionUninstallAccepted() { |
| 576 Finish(true); | 577 Finish(true); |
| 577 Release(); | 578 Release(); |
| 578 } | 579 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 CHECK(extension); | 644 CHECK(extension); |
| 644 scoped_ptr<management::ExtensionInfo> info = CreateExtensionInfo( | 645 scoped_ptr<management::ExtensionInfo> info = CreateExtensionInfo( |
| 645 *extension, ExtensionSystem::Get(profile)); | 646 *extension, ExtensionSystem::Get(profile)); |
| 646 args->Append(info->ToValue().release()); | 647 args->Append(info->ToValue().release()); |
| 647 } | 648 } |
| 648 | 649 |
| 649 extensions::ExtensionSystem::Get(profile)->event_router()-> | 650 extensions::ExtensionSystem::Get(profile)->event_router()-> |
| 650 DispatchEventToRenderers(event_name, args.Pass(), NULL, GURL(), | 651 DispatchEventToRenderers(event_name, args.Pass(), NULL, GURL(), |
| 651 extensions::EventFilteringInfo()); | 652 extensions::EventFilteringInfo()); |
| 652 } | 653 } |
| OLD | NEW |