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 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 return; | 470 return; |
471 } | 471 } |
472 | 472 |
473 if (!BrowserThread::PostTask( | 473 if (!BrowserThread::PostTask( |
474 BrowserThread::UI, FROM_HERE, | 474 BrowserThread::UI, FROM_HERE, |
475 base::Bind(&CrxInstaller::CheckImportsAndRequirements, this))) | 475 base::Bind(&CrxInstaller::CheckImportsAndRequirements, this))) |
476 NOTREACHED(); | 476 NOTREACHED(); |
477 } | 477 } |
478 | 478 |
479 void CrxInstaller::CheckImportsAndRequirements() { | 479 void CrxInstaller::CheckImportsAndRequirements() { |
480 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 480 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
481 ExtensionService* service = service_weak_.get(); | 481 ExtensionService* service = service_weak_.get(); |
482 if (!service || service->browser_terminating()) | 482 if (!service || service->browser_terminating()) |
483 return; | 483 return; |
484 | 484 |
485 if (SharedModuleInfo::ImportsModules(extension())) { | 485 if (SharedModuleInfo::ImportsModules(extension())) { |
486 const std::vector<SharedModuleInfo::ImportInfo>& imports = | 486 const std::vector<SharedModuleInfo::ImportInfo>& imports = |
487 SharedModuleInfo::GetImports(extension()); | 487 SharedModuleInfo::GetImports(extension()); |
488 std::vector<SharedModuleInfo::ImportInfo>::const_iterator i; | 488 std::vector<SharedModuleInfo::ImportInfo>::const_iterator i; |
489 for (i = imports.begin(); i != imports.end(); ++i) { | 489 for (i = imports.begin(); i != imports.end(); ++i) { |
490 Version version_required(i->minimum_version); | 490 Version version_required(i->minimum_version); |
491 const Extension* imported_module = | 491 const Extension* imported_module = |
492 service->GetExtensionById(i->extension_id, true); | 492 service->GetExtensionById(i->extension_id, true); |
493 if (imported_module && | 493 if (imported_module && |
494 !SharedModuleInfo::IsSharedModule(imported_module)) { | 494 !SharedModuleInfo::IsSharedModule(imported_module)) { |
495 ReportFailureFromUIThread( | 495 ReportFailureFromUIThread( |
496 CrxInstallerError(l10n_util::GetStringFUTF16( | 496 CrxInstallerError(l10n_util::GetStringFUTF16( |
497 IDS_EXTENSION_INSTALL_DEPENDENCY_NOT_SHARED_MODULE, | 497 IDS_EXTENSION_INSTALL_DEPENDENCY_NOT_SHARED_MODULE, |
498 base::ASCIIToUTF16(i->extension_id)))); | 498 base::ASCIIToUTF16(i->extension_id)))); |
499 return; | 499 return; |
500 } | 500 } |
501 } | 501 } |
502 } | 502 } |
503 installer_.CheckRequirements(base::Bind(&CrxInstaller::OnRequirementsChecked, | 503 installer_.CheckRequirements(base::Bind(&CrxInstaller::OnRequirementsChecked, |
504 this)); | 504 this)); |
505 } | 505 } |
506 | 506 |
507 void CrxInstaller::OnRequirementsChecked( | 507 void CrxInstaller::OnRequirementsChecked( |
508 std::vector<std::string> requirement_errors) { | 508 std::vector<std::string> requirement_errors) { |
509 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 509 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
510 if (!service_weak_) | 510 if (!service_weak_) |
511 return; | 511 return; |
512 | 512 |
513 if (!requirement_errors.empty()) { | 513 if (!requirement_errors.empty()) { |
514 if (error_on_unsupported_requirements_) { | 514 if (error_on_unsupported_requirements_) { |
515 ReportFailureFromUIThread(CrxInstallerError( | 515 ReportFailureFromUIThread(CrxInstallerError( |
516 base::UTF8ToUTF16(JoinString(requirement_errors, ' ')))); | 516 base::UTF8ToUTF16(JoinString(requirement_errors, ' ')))); |
517 return; | 517 return; |
518 } | 518 } |
519 has_requirement_errors_ = true; | 519 has_requirement_errors_ = true; |
520 } | 520 } |
521 | 521 |
522 ExtensionSystem::Get(profile())->blacklist()->IsBlacklisted( | 522 ExtensionSystem::Get(profile())->blacklist()->IsBlacklisted( |
523 extension()->id(), | 523 extension()->id(), |
524 base::Bind(&CrxInstaller::OnBlacklistChecked, this)); | 524 base::Bind(&CrxInstaller::OnBlacklistChecked, this)); |
525 } | 525 } |
526 | 526 |
527 void CrxInstaller::OnBlacklistChecked( | 527 void CrxInstaller::OnBlacklistChecked( |
528 extensions::BlacklistState blacklist_state) { | 528 extensions::BlacklistState blacklist_state) { |
529 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 529 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
530 if (!service_weak_) | 530 if (!service_weak_) |
531 return; | 531 return; |
532 | 532 |
533 blacklist_state_ = blacklist_state; | 533 blacklist_state_ = blacklist_state; |
534 | 534 |
535 if ((blacklist_state_ == extensions::BLACKLISTED_MALWARE || | 535 if ((blacklist_state_ == extensions::BLACKLISTED_MALWARE || |
536 blacklist_state_ == extensions::BLACKLISTED_UNKNOWN) && | 536 blacklist_state_ == extensions::BLACKLISTED_UNKNOWN) && |
537 !allow_silent_install_) { | 537 !allow_silent_install_) { |
538 // User tried to install a blacklisted extension. Show an error and | 538 // User tried to install a blacklisted extension. Show an error and |
539 // refuse to install it. | 539 // refuse to install it. |
540 ReportFailureFromUIThread(extensions::CrxInstallerError( | 540 ReportFailureFromUIThread(extensions::CrxInstallerError( |
541 l10n_util::GetStringFUTF16(IDS_EXTENSION_IS_BLACKLISTED, | 541 l10n_util::GetStringFUTF16(IDS_EXTENSION_IS_BLACKLISTED, |
542 base::UTF8ToUTF16(extension()->name())))); | 542 base::UTF8ToUTF16(extension()->name())))); |
543 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlockCRX", | 543 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlockCRX", |
544 extension()->location(), | 544 extension()->location(), |
545 Manifest::NUM_LOCATIONS); | 545 Manifest::NUM_LOCATIONS); |
546 return; | 546 return; |
547 } | 547 } |
548 | 548 |
549 // NOTE: extension may still be blacklisted, but we're forced to silently | 549 // NOTE: extension may still be blacklisted, but we're forced to silently |
550 // install it. In this case, ExtensionService::OnExtensionInstalled needs to | 550 // install it. In this case, ExtensionService::OnExtensionInstalled needs to |
551 // deal with it. | 551 // deal with it. |
552 ConfirmInstall(); | 552 ConfirmInstall(); |
553 } | 553 } |
554 | 554 |
555 void CrxInstaller::ConfirmInstall() { | 555 void CrxInstaller::ConfirmInstall() { |
556 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 556 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
557 ExtensionService* service = service_weak_.get(); | 557 ExtensionService* service = service_weak_.get(); |
558 if (!service || service->browser_terminating()) | 558 if (!service || service->browser_terminating()) |
559 return; | 559 return; |
560 | 560 |
561 if (KioskModeInfo::IsKioskOnly(installer_.extension())) { | 561 if (KioskModeInfo::IsKioskOnly(installer_.extension())) { |
562 bool in_kiosk_mode = false; | 562 bool in_kiosk_mode = false; |
563 #if defined(OS_CHROMEOS) | 563 #if defined(OS_CHROMEOS) |
564 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | 564 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
565 in_kiosk_mode = user_manager && user_manager->IsLoggedInAsKioskApp(); | 565 in_kiosk_mode = user_manager && user_manager->IsLoggedInAsKioskApp(); |
566 #endif | 566 #endif |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 } else { | 611 } else { |
612 if (!installer_task_runner_->PostTask( | 612 if (!installer_task_runner_->PostTask( |
613 FROM_HERE, | 613 FROM_HERE, |
614 base::Bind(&CrxInstaller::CompleteInstall, this))) | 614 base::Bind(&CrxInstaller::CompleteInstall, this))) |
615 NOTREACHED(); | 615 NOTREACHED(); |
616 } | 616 } |
617 return; | 617 return; |
618 } | 618 } |
619 | 619 |
620 void CrxInstaller::InstallUIProceed() { | 620 void CrxInstaller::InstallUIProceed() { |
621 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 621 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
622 | 622 |
623 ExtensionService* service = service_weak_.get(); | 623 ExtensionService* service = service_weak_.get(); |
624 if (!service || service->browser_terminating()) | 624 if (!service || service->browser_terminating()) |
625 return; | 625 return; |
626 | 626 |
627 // If update_from_settings_page_ boolean is true, this functions is | 627 // If update_from_settings_page_ boolean is true, this functions is |
628 // getting called in response to ExtensionInstallPrompt::ConfirmReEnable() | 628 // getting called in response to ExtensionInstallPrompt::ConfirmReEnable() |
629 // and if it is false, this function is called in response to | 629 // and if it is false, this function is called in response to |
630 // ExtensionInstallPrompt::ConfirmInstall(). | 630 // ExtensionInstallPrompt::ConfirmInstall(). |
631 if (update_from_settings_page_) { | 631 if (update_from_settings_page_) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 void CrxInstaller::ReportFailureFromFileThread(const CrxInstallerError& error) { | 723 void CrxInstaller::ReportFailureFromFileThread(const CrxInstallerError& error) { |
724 DCHECK(installer_task_runner_->RunsTasksOnCurrentThread()); | 724 DCHECK(installer_task_runner_->RunsTasksOnCurrentThread()); |
725 if (!BrowserThread::PostTask( | 725 if (!BrowserThread::PostTask( |
726 BrowserThread::UI, FROM_HERE, | 726 BrowserThread::UI, FROM_HERE, |
727 base::Bind(&CrxInstaller::ReportFailureFromUIThread, this, error))) { | 727 base::Bind(&CrxInstaller::ReportFailureFromUIThread, this, error))) { |
728 NOTREACHED(); | 728 NOTREACHED(); |
729 } | 729 } |
730 } | 730 } |
731 | 731 |
732 void CrxInstaller::ReportFailureFromUIThread(const CrxInstallerError& error) { | 732 void CrxInstaller::ReportFailureFromUIThread(const CrxInstallerError& error) { |
733 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 733 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
734 | 734 |
735 content::NotificationService* service = | 735 content::NotificationService* service = |
736 content::NotificationService::current(); | 736 content::NotificationService::current(); |
737 service->Notify(chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, | 737 service->Notify(chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, |
738 content::Source<CrxInstaller>(this), | 738 content::Source<CrxInstaller>(this), |
739 content::Details<const base::string16>(&error.message())); | 739 content::Details<const base::string16>(&error.message())); |
740 | 740 |
741 // This isn't really necessary, it is only used because unit tests expect to | 741 // This isn't really necessary, it is only used because unit tests expect to |
742 // see errors get reported via this interface. | 742 // see errors get reported via this interface. |
743 // | 743 // |
(...skipping 23 matching lines...) Expand all Loading... |
767 if (!BrowserThread::PostTask( | 767 if (!BrowserThread::PostTask( |
768 BrowserThread::UI, FROM_HERE, | 768 BrowserThread::UI, FROM_HERE, |
769 base::Bind(&CrxInstaller::ReportSuccessFromUIThread, this))) | 769 base::Bind(&CrxInstaller::ReportSuccessFromUIThread, this))) |
770 NOTREACHED(); | 770 NOTREACHED(); |
771 | 771 |
772 // Delete temporary files. | 772 // Delete temporary files. |
773 CleanupTempFiles(); | 773 CleanupTempFiles(); |
774 } | 774 } |
775 | 775 |
776 void CrxInstaller::ReportSuccessFromUIThread() { | 776 void CrxInstaller::ReportSuccessFromUIThread() { |
777 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 777 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
778 | 778 |
779 if (!service_weak_.get() || service_weak_->browser_terminating()) | 779 if (!service_weak_.get() || service_weak_->browser_terminating()) |
780 return; | 780 return; |
781 | 781 |
782 if (!update_from_settings_page_) { | 782 if (!update_from_settings_page_) { |
783 // If there is a client, tell the client about installation. | 783 // If there is a client, tell the client about installation. |
784 if (client_) | 784 if (client_) |
785 client_->OnInstallSuccess(extension(), install_icon_.get()); | 785 client_->OnInstallSuccess(extension(), install_icon_.get()); |
786 | 786 |
787 // We update the extension's granted permissions if the user already | 787 // We update the extension's granted permissions if the user already |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 temp_dir_ = base::FilePath(); | 833 temp_dir_ = base::FilePath(); |
834 } | 834 } |
835 | 835 |
836 if (delete_source_ && !source_file_.value().empty()) { | 836 if (delete_source_ && !source_file_.value().empty()) { |
837 extension_file_util::DeleteFile(source_file_, false); | 837 extension_file_util::DeleteFile(source_file_, false); |
838 source_file_ = base::FilePath(); | 838 source_file_ = base::FilePath(); |
839 } | 839 } |
840 } | 840 } |
841 | 841 |
842 void CrxInstaller::CheckUpdateFromSettingsPage() { | 842 void CrxInstaller::CheckUpdateFromSettingsPage() { |
843 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 843 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
844 | 844 |
845 ExtensionService* service = service_weak_.get(); | 845 ExtensionService* service = service_weak_.get(); |
846 if (!service || service->browser_terminating()) | 846 if (!service || service->browser_terminating()) |
847 return; | 847 return; |
848 | 848 |
849 if (off_store_install_allow_reason_ != OffStoreInstallAllowedFromSettingsPage) | 849 if (off_store_install_allow_reason_ != OffStoreInstallAllowedFromSettingsPage) |
850 return; | 850 return; |
851 | 851 |
852 const Extension* installed_extension = | 852 const Extension* installed_extension = |
853 service->GetInstalledExtension(extension()->id()); | 853 service->GetInstalledExtension(extension()->id()); |
854 if (installed_extension) { | 854 if (installed_extension) { |
855 // Previous version of the extension exists. | 855 // Previous version of the extension exists. |
856 update_from_settings_page_ = true; | 856 update_from_settings_page_ = true; |
857 expected_id_ = installed_extension->id(); | 857 expected_id_ = installed_extension->id(); |
858 install_source_ = installed_extension->location(); | 858 install_source_ = installed_extension->location(); |
859 install_cause_ = extension_misc::INSTALL_CAUSE_UPDATE; | 859 install_cause_ = extension_misc::INSTALL_CAUSE_UPDATE; |
860 } | 860 } |
861 } | 861 } |
862 | 862 |
863 void CrxInstaller::ConfirmReEnable() { | 863 void CrxInstaller::ConfirmReEnable() { |
864 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 864 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
865 | 865 |
866 ExtensionService* service = service_weak_.get(); | 866 ExtensionService* service = service_weak_.get(); |
867 if (!service || service->browser_terminating()) | 867 if (!service || service->browser_terminating()) |
868 return; | 868 return; |
869 | 869 |
870 if (!update_from_settings_page_) | 870 if (!update_from_settings_page_) |
871 return; | 871 return; |
872 | 872 |
873 ExtensionPrefs* prefs = ExtensionPrefs::Get(service->profile()); | 873 ExtensionPrefs* prefs = ExtensionPrefs::Get(service->profile()); |
874 if (!prefs->DidExtensionEscalatePermissions(extension()->id())) | 874 if (!prefs->DidExtensionEscalatePermissions(extension()->id())) |
875 return; | 875 return; |
876 | 876 |
877 if (client_) { | 877 if (client_) { |
878 AddRef(); // Balanced in InstallUIProceed() and InstallUIAbort(). | 878 AddRef(); // Balanced in InstallUIProceed() and InstallUIAbort(). |
879 client_->ConfirmReEnable(this, extension()); | 879 client_->ConfirmReEnable(this, extension()); |
880 } | 880 } |
881 } | 881 } |
882 | 882 |
883 } // namespace extensions | 883 } // namespace extensions |
OLD | NEW |