| 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/crx_installer.h" | 5 #include "chrome/browser/extensions/crx_installer.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
| 18 #include "base/sequenced_task_runner.h" | 18 #include "base/sequenced_task_runner.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
| 22 #include "base/threading/thread_restrictions.h" | 22 #include "base/threading/thread_restrictions.h" |
| 23 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 24 #include "base/version.h" | 24 #include "base/version.h" |
| 25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 26 #include "chrome/browser/extensions/blacklist_check.h" |
| 26 #include "chrome/browser/extensions/convert_user_script.h" | 27 #include "chrome/browser/extensions/convert_user_script.h" |
| 27 #include "chrome/browser/extensions/convert_web_app.h" | 28 #include "chrome/browser/extensions/convert_web_app.h" |
| 28 #include "chrome/browser/extensions/extension_assets_manager.h" | 29 #include "chrome/browser/extensions/extension_assets_manager.h" |
| 29 #include "chrome/browser/extensions/extension_error_reporter.h" | 30 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 30 #include "chrome/browser/extensions/extension_install_checker.h" | |
| 31 #include "chrome/browser/extensions/extension_service.h" | 31 #include "chrome/browser/extensions/extension_service.h" |
| 32 #include "chrome/browser/extensions/install_tracker.h" | 32 #include "chrome/browser/extensions/install_tracker.h" |
| 33 #include "chrome/browser/extensions/install_tracker_factory.h" | 33 #include "chrome/browser/extensions/install_tracker_factory.h" |
| 34 #include "chrome/browser/extensions/permissions_updater.h" | 34 #include "chrome/browser/extensions/permissions_updater.h" |
| 35 #include "chrome/browser/extensions/webstore_installer.h" | 35 #include "chrome/browser/extensions/webstore_installer.h" |
| 36 #include "chrome/browser/profiles/profile.h" | 36 #include "chrome/browser/profiles/profile.h" |
| 37 #include "chrome/browser/web_applications/web_app.h" | 37 #include "chrome/browser/web_applications/web_app.h" |
| 38 #include "chrome/common/chrome_paths.h" | 38 #include "chrome/common/chrome_paths.h" |
| 39 #include "chrome/common/extensions/extension_constants.h" | 39 #include "chrome/common/extensions/extension_constants.h" |
| 40 #include "chrome/grit/generated_resources.h" | 40 #include "chrome/grit/generated_resources.h" |
| 41 #include "content/public/browser/browser_thread.h" | 41 #include "content/public/browser/browser_thread.h" |
| 42 #include "content/public/browser/notification_service.h" | 42 #include "content/public/browser/notification_service.h" |
| 43 #include "content/public/browser/resource_dispatcher_host.h" | 43 #include "content/public/browser/resource_dispatcher_host.h" |
| 44 #include "extensions/browser/extension_prefs.h" | 44 #include "extensions/browser/extension_prefs.h" |
| 45 #include "extensions/browser/extension_registry.h" | 45 #include "extensions/browser/extension_registry.h" |
| 46 #include "extensions/browser/extension_system.h" | 46 #include "extensions/browser/extension_system.h" |
| 47 #include "extensions/browser/install/crx_install_error.h" | 47 #include "extensions/browser/install/crx_install_error.h" |
| 48 #include "extensions/browser/install/extension_install_ui.h" | 48 #include "extensions/browser/install/extension_install_ui.h" |
| 49 #include "extensions/browser/install_flag.h" | 49 #include "extensions/browser/install_flag.h" |
| 50 #include "extensions/browser/notification_types.h" | 50 #include "extensions/browser/notification_types.h" |
| 51 #include "extensions/browser/preload_check.h" | 51 #include "extensions/browser/policy_check.h" |
| 52 #include "extensions/browser/preload_check_group.h" |
| 53 #include "extensions/browser/requirements_checker.h" |
| 52 #include "extensions/common/extension_icon_set.h" | 54 #include "extensions/common/extension_icon_set.h" |
| 53 #include "extensions/common/file_util.h" | 55 #include "extensions/common/file_util.h" |
| 54 #include "extensions/common/manifest.h" | 56 #include "extensions/common/manifest.h" |
| 55 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" | 57 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" |
| 56 #include "extensions/common/manifest_handlers/shared_module_info.h" | 58 #include "extensions/common/manifest_handlers/shared_module_info.h" |
| 57 #include "extensions/common/manifest_url_handlers.h" | 59 #include "extensions/common/manifest_url_handlers.h" |
| 58 #include "extensions/common/permissions/permission_message_provider.h" | 60 #include "extensions/common/permissions/permission_message_provider.h" |
| 59 #include "extensions/common/permissions/permission_set.h" | 61 #include "extensions/common/permissions/permission_set.h" |
| 60 #include "extensions/common/permissions/permissions_data.h" | 62 #include "extensions/common/permissions/permissions_data.h" |
| 61 #include "extensions/common/user_script.h" | 63 #include "extensions/common/user_script.h" |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 CrxInstallError::ERROR_DECLINED, | 502 CrxInstallError::ERROR_DECLINED, |
| 501 l10n_util::GetStringFUTF16( | 503 l10n_util::GetStringFUTF16( |
| 502 IDS_EXTENSION_INSTALL_DEPENDENCY_NOT_WHITELISTED, | 504 IDS_EXTENSION_INSTALL_DEPENDENCY_NOT_WHITELISTED, |
| 503 base::UTF8ToUTF16(extension()->name()), | 505 base::UTF8ToUTF16(extension()->name()), |
| 504 base::UTF8ToUTF16(imported_module->name())))); | 506 base::UTF8ToUTF16(imported_module->name())))); |
| 505 return; | 507 return; |
| 506 } | 508 } |
| 507 } | 509 } |
| 508 } | 510 } |
| 509 | 511 |
| 510 // Run the policy, requirements and blacklist checks in parallel. Skip the | 512 // Skip the checks if the extension is a bookmark app. |
| 511 // checks if the extension is a bookmark app. | |
| 512 if (extension()->from_bookmark()) { | 513 if (extension()->from_bookmark()) { |
| 513 ConfirmInstall(); | 514 ConfirmInstall(); |
| 514 } else { | 515 return; |
| 515 install_checker_ = base::MakeUnique<ExtensionInstallChecker>( | |
| 516 profile_, extension_, ExtensionInstallChecker::CHECK_ALL, | |
| 517 false /* fail fast */); | |
| 518 install_checker_->Start( | |
| 519 base::Bind(&CrxInstaller::OnInstallChecksComplete, this)); | |
| 520 } | 516 } |
| 517 |
| 518 // Run the policy, requirements and blacklist checks in parallel. |
| 519 check_group_ = base::MakeUnique<PreloadCheckGroup>(); |
| 520 |
| 521 policy_check_ = base::MakeUnique<PolicyCheck>(profile_, extension()); |
| 522 requirements_check_ = base::MakeUnique<RequirementsChecker>(extension()); |
| 523 blacklist_check_ = |
| 524 base::MakeUnique<BlacklistCheck>(Blacklist::Get(profile_), extension_); |
| 525 |
| 526 check_group_->AddCheck(policy_check_.get()); |
| 527 check_group_->AddCheck(requirements_check_.get()); |
| 528 check_group_->AddCheck(blacklist_check_.get()); |
| 529 |
| 530 check_group_->Start( |
| 531 base::BindOnce(&CrxInstaller::OnInstallChecksComplete, this)); |
| 521 } | 532 } |
| 522 | 533 |
| 523 void CrxInstaller::OnInstallChecksComplete(int failed_checks) { | 534 void CrxInstaller::OnInstallChecksComplete(PreloadCheck::Errors errors) { |
| 524 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 535 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 525 if (!service_weak_) | 536 if (!service_weak_) |
| 526 return; | 537 return; |
| 527 | 538 |
| 539 if (errors.empty()) { |
| 540 ConfirmInstall(); |
| 541 return; |
| 542 } |
| 543 |
| 528 // Check for requirement errors. | 544 // Check for requirement errors. |
| 529 if (!install_checker_->requirements_error_message().empty()) { | 545 if (!requirements_check_->GetErrorMessage().empty()) { |
| 530 if (error_on_unsupported_requirements_) { | 546 if (error_on_unsupported_requirements_) { |
| 531 ReportFailureFromUIThread( | 547 ReportFailureFromUIThread( |
| 532 CrxInstallError(CrxInstallError::ERROR_DECLINED, | 548 CrxInstallError(CrxInstallError::ERROR_DECLINED, |
| 533 install_checker_->requirements_error_message())); | 549 requirements_check_->GetErrorMessage())); |
| 534 return; | 550 return; |
| 535 } | 551 } |
| 536 install_flags_ |= kInstallFlagHasRequirementErrors; | 552 install_flags_ |= kInstallFlagHasRequirementErrors; |
| 537 } | 553 } |
| 538 | 554 |
| 539 // Check the blacklist state. | 555 // Check the blacklist state. |
| 540 if (install_checker_->blacklist_error() == PreloadCheck::BLACKLISTED_ID) { | 556 if (errors.count(PreloadCheck::BLACKLISTED_ID) || |
| 541 install_flags_ |= kInstallFlagIsBlacklistedForMalware; | 557 errors.count(PreloadCheck::BLACKLISTED_UNKNOWN)) { |
| 558 if (allow_silent_install_) { |
| 559 // NOTE: extension may still be blacklisted, but we're forced to silently |
| 560 // install it. In this case, ExtensionService::OnExtensionInstalled needs |
| 561 // to deal with it. |
| 562 if (errors.count(PreloadCheck::BLACKLISTED_ID)) |
| 563 install_flags_ |= kInstallFlagIsBlacklistedForMalware; |
| 564 } else { |
| 565 // User tried to install a blacklisted extension. Show an error and |
| 566 // refuse to install it. |
| 567 ReportFailureFromUIThread(CrxInstallError( |
| 568 CrxInstallError::ERROR_DECLINED, |
| 569 l10n_util::GetStringFUTF16(IDS_EXTENSION_IS_BLACKLISTED, |
| 570 base::UTF8ToUTF16(extension()->name())))); |
| 571 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlockCRX", |
| 572 extension()->location(), |
| 573 Manifest::NUM_LOCATIONS); |
| 574 return; |
| 575 } |
| 542 } | 576 } |
| 543 | 577 |
| 544 if ((install_checker_->blacklist_error() == PreloadCheck::BLACKLISTED_ID || | |
| 545 install_checker_->blacklist_error() == | |
| 546 PreloadCheck::BLACKLISTED_UNKNOWN) && | |
| 547 !allow_silent_install_) { | |
| 548 // User tried to install a blacklisted extension. Show an error and | |
| 549 // refuse to install it. | |
| 550 ReportFailureFromUIThread(CrxInstallError( | |
| 551 CrxInstallError::ERROR_DECLINED, | |
| 552 l10n_util::GetStringFUTF16(IDS_EXTENSION_IS_BLACKLISTED, | |
| 553 base::UTF8ToUTF16(extension()->name())))); | |
| 554 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlockCRX", | |
| 555 extension()->location(), | |
| 556 Manifest::NUM_LOCATIONS); | |
| 557 return; | |
| 558 } | |
| 559 | |
| 560 // NOTE: extension may still be blacklisted, but we're forced to silently | |
| 561 // install it. In this case, ExtensionService::OnExtensionInstalled needs to | |
| 562 // deal with it. | |
| 563 | |
| 564 // Check for policy errors. | 578 // Check for policy errors. |
| 565 if (!install_checker_->policy_error().empty()) { | 579 if (errors.count(PreloadCheck::DISALLOWED_BY_POLICY)) { |
| 566 // We don't want to show the error infobar for installs from the WebStore, | 580 // We don't want to show the error infobar for installs from the WebStore, |
| 567 // because the WebStore already shows an error dialog itself. | 581 // because the WebStore already shows an error dialog itself. |
| 568 // Note: |client_| can be NULL in unit_tests! | 582 // Note: |client_| can be NULL in unit_tests! |
| 569 if (extension()->from_webstore() && client_) | 583 if (extension()->from_webstore() && client_) |
| 570 client_->install_ui()->SetSkipPostInstallUI(true); | 584 client_->install_ui()->SetSkipPostInstallUI(true); |
| 585 |
| 571 ReportFailureFromUIThread(CrxInstallError( | 586 ReportFailureFromUIThread(CrxInstallError( |
| 572 CrxInstallError::ERROR_DECLINED, install_checker_->policy_error())); | 587 CrxInstallError::ERROR_DECLINED, policy_check_->GetErrorMessage())); |
| 573 return; | 588 return; |
| 574 } | 589 } |
| 575 | 590 |
| 576 ConfirmInstall(); | 591 ConfirmInstall(); |
| 577 } | 592 } |
| 578 | 593 |
| 579 void CrxInstaller::ConfirmInstall() { | 594 void CrxInstaller::ConfirmInstall() { |
| 580 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 595 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 581 ExtensionService* service = service_weak_.get(); | 596 ExtensionService* service = service_weak_.get(); |
| 582 if (!service || service->browser_terminating()) | 597 if (!service || service->browser_terminating()) |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension( | 920 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension( |
| 906 service->profile(), extension()); | 921 service->profile(), extension()); |
| 907 client_->ShowDialog(base::Bind(&CrxInstaller::OnInstallPromptDone, this), | 922 client_->ShowDialog(base::Bind(&CrxInstaller::OnInstallPromptDone, this), |
| 908 extension(), nullptr, | 923 extension(), nullptr, |
| 909 base::MakeUnique<ExtensionInstallPrompt::Prompt>(type), | 924 base::MakeUnique<ExtensionInstallPrompt::Prompt>(type), |
| 910 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); | 925 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); |
| 911 } | 926 } |
| 912 } | 927 } |
| 913 | 928 |
| 914 } // namespace extensions | 929 } // namespace extensions |
| OLD | NEW |