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

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

Issue 2783143005: Replace ExtensionInstallChecker with generic PreloadCheckGroup (Closed)
Patch Set: cleanup Created 3 years, 8 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
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/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
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
528 // Check for requirement errors. 539 if (!errors.empty()) {
Devlin 2017/04/04 01:37:26 this block hurts my eyes a bit. Maybe if (errors.
michaelpg 2017/04/04 21:41:29 Done. I also fiddled with the order of nested ifs
529 if (!install_checker_->requirements_error_message().empty()) { 540 // Check for requirement errors.
530 if (error_on_unsupported_requirements_) { 541 if (!requirements_check_->GetErrorMessage().empty()) {
531 ReportFailureFromUIThread( 542 if (error_on_unsupported_requirements_) {
532 CrxInstallError(CrxInstallError::ERROR_DECLINED, 543 ReportFailureFromUIThread(
533 install_checker_->requirements_error_message())); 544 CrxInstallError(CrxInstallError::ERROR_DECLINED,
545 requirements_check_->GetErrorMessage()));
546 return;
547 }
548 install_flags_ |= kInstallFlagHasRequirementErrors;
549 }
550
551 // Check the blacklist state.
552 if (errors.count(PreloadCheck::BLACKLISTED_ID))
553 install_flags_ |= kInstallFlagIsBlacklistedForMalware;
554
555 if ((errors.count(PreloadCheck::BLACKLISTED_ID) ||
556 errors.count(PreloadCheck::BLACKLISTED_UNKNOWN)) &&
557 !allow_silent_install_) {
558 // User tried to install a blacklisted extension. Show an error and
559 // refuse to install it.
560 ReportFailureFromUIThread(CrxInstallError(
561 CrxInstallError::ERROR_DECLINED,
562 l10n_util::GetStringFUTF16(IDS_EXTENSION_IS_BLACKLISTED,
563 base::UTF8ToUTF16(extension()->name()))));
564 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlockCRX",
565 extension()->location(),
566 Manifest::NUM_LOCATIONS);
534 return; 567 return;
535 } 568 }
536 install_flags_ |= kInstallFlagHasRequirementErrors;
537 }
538 569
539 // Check the blacklist state. 570 // NOTE: extension may still be blacklisted, but we're forced to silently
540 if (install_checker_->blacklist_error() == PreloadCheck::BLACKLISTED_ID) { 571 // install it. In this case, ExtensionService::OnExtensionInstalled needs to
541 install_flags_ |= kInstallFlagIsBlacklistedForMalware; 572 // deal with it.
542 }
543 573
544 if ((install_checker_->blacklist_error() == PreloadCheck::BLACKLISTED_ID || 574 // Check for policy errors.
545 install_checker_->blacklist_error() == 575 if (errors.count(PreloadCheck::DISALLOWED_BY_POLICY)) {
546 PreloadCheck::BLACKLISTED_UNKNOWN) && 576 // We don't want to show the error infobar for installs from the WebStore,
547 !allow_silent_install_) { 577 // because the WebStore already shows an error dialog itself.
548 // User tried to install a blacklisted extension. Show an error and 578 // Note: |client_| can be NULL in unit_tests!
549 // refuse to install it. 579 if (extension()->from_webstore() && client_)
550 ReportFailureFromUIThread(CrxInstallError( 580 client_->install_ui()->SetSkipPostInstallUI(true);
551 CrxInstallError::ERROR_DECLINED, 581 ReportFailureFromUIThread(CrxInstallError(
552 l10n_util::GetStringFUTF16(IDS_EXTENSION_IS_BLACKLISTED, 582 CrxInstallError::ERROR_DECLINED, policy_check_->GetErrorMessage()));
553 base::UTF8ToUTF16(extension()->name())))); 583 return;
554 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlockCRX", 584 }
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.
565 if (!install_checker_->policy_error().empty()) {
566 // We don't want to show the error infobar for installs from the WebStore,
567 // because the WebStore already shows an error dialog itself.
568 // Note: |client_| can be NULL in unit_tests!
569 if (extension()->from_webstore() && client_)
570 client_->install_ui()->SetSkipPostInstallUI(true);
571 ReportFailureFromUIThread(CrxInstallError(
572 CrxInstallError::ERROR_DECLINED, install_checker_->policy_error()));
573 return;
574 } 585 }
575 586
576 ConfirmInstall(); 587 ConfirmInstall();
577 } 588 }
578 589
579 void CrxInstaller::ConfirmInstall() { 590 void CrxInstaller::ConfirmInstall() {
580 DCHECK_CURRENTLY_ON(BrowserThread::UI); 591 DCHECK_CURRENTLY_ON(BrowserThread::UI);
581 ExtensionService* service = service_weak_.get(); 592 ExtensionService* service = service_weak_.get();
582 if (!service || service->browser_terminating()) 593 if (!service || service->browser_terminating())
583 return; 594 return;
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension( 916 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension(
906 service->profile(), extension()); 917 service->profile(), extension());
907 client_->ShowDialog(base::Bind(&CrxInstaller::OnInstallPromptDone, this), 918 client_->ShowDialog(base::Bind(&CrxInstaller::OnInstallPromptDone, this),
908 extension(), nullptr, 919 extension(), nullptr,
909 base::MakeUnique<ExtensionInstallPrompt::Prompt>(type), 920 base::MakeUnique<ExtensionInstallPrompt::Prompt>(type),
910 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); 921 ExtensionInstallPrompt::GetDefaultShowDialogCallback());
911 } 922 }
912 } 923 }
913 924
914 } // namespace extensions 925 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698