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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 98 } |
99 | 99 |
100 // static | 100 // static |
101 scoped_refptr<CrxInstaller> CrxInstaller::Create( | 101 scoped_refptr<CrxInstaller> CrxInstaller::Create( |
102 ExtensionService* service, | 102 ExtensionService* service, |
103 scoped_ptr<ExtensionInstallPrompt> client, | 103 scoped_ptr<ExtensionInstallPrompt> client, |
104 const WebstoreInstaller::Approval* approval) { | 104 const WebstoreInstaller::Approval* approval) { |
105 return new CrxInstaller(service->AsWeakPtr(), client.Pass(), approval); | 105 return new CrxInstaller(service->AsWeakPtr(), client.Pass(), approval); |
106 } | 106 } |
107 | 107 |
108 CrxInstaller::CrxInstaller( | 108 CrxInstaller::CrxInstaller(base::WeakPtr<ExtensionService> service_weak, |
109 base::WeakPtr<ExtensionService> service_weak, | 109 scoped_ptr<ExtensionInstallPrompt> client, |
110 scoped_ptr<ExtensionInstallPrompt> client, | 110 const WebstoreInstaller::Approval* approval) |
111 const WebstoreInstaller::Approval* approval) | |
112 : install_directory_(service_weak->install_directory()), | 111 : install_directory_(service_weak->install_directory()), |
113 install_source_(Manifest::INTERNAL), | 112 install_source_(Manifest::INTERNAL), |
114 approved_(false), | 113 approved_(false), |
115 expected_manifest_check_level_( | 114 expected_manifest_check_level_( |
116 WebstoreInstaller::MANIFEST_CHECK_LEVEL_STRICT), | 115 WebstoreInstaller::MANIFEST_CHECK_LEVEL_STRICT), |
117 expected_version_strict_checking_(false), | 116 expected_version_strict_checking_(false), |
118 extensions_enabled_(service_weak->extensions_enabled()), | 117 extensions_enabled_(service_weak->extensions_enabled()), |
119 delete_source_(false), | 118 delete_source_(false), |
120 create_app_shortcut_(false), | 119 create_app_shortcut_(false), |
121 service_weak_(service_weak), | 120 service_weak_(service_weak), |
122 // See header file comment on |client_| for why we use a raw pointer here. | 121 // See header file comment on |client_| for why we use a raw pointer here. |
123 client_(client.release()), | 122 client_(client.release()), |
124 apps_require_extension_mime_type_(false), | 123 apps_require_extension_mime_type_(false), |
125 allow_silent_install_(false), | 124 allow_silent_install_(GRANT_AFTER_PROMPT), |
126 install_cause_(extension_misc::INSTALL_CAUSE_UNSET), | 125 install_cause_(extension_misc::INSTALL_CAUSE_UNSET), |
127 creation_flags_(Extension::NO_FLAGS), | 126 creation_flags_(Extension::NO_FLAGS), |
128 off_store_install_allow_reason_(OffStoreInstallDisallowed), | 127 off_store_install_allow_reason_(OffStoreInstallDisallowed), |
129 did_handle_successfully_(true), | 128 did_handle_successfully_(true), |
130 error_on_unsupported_requirements_(false), | 129 error_on_unsupported_requirements_(false), |
131 has_requirement_errors_(false), | 130 has_requirement_errors_(false), |
132 blacklist_state_(extensions::NOT_BLACKLISTED), | 131 blacklist_state_(extensions::NOT_BLACKLISTED), |
133 install_wait_for_idle_(true), | 132 install_wait_for_idle_(true), |
134 update_from_settings_page_(false), | 133 update_from_settings_page_(false), |
135 installer_(service_weak->profile()) { | 134 installer_(service_weak->profile()) { |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 void CrxInstaller::OnBlacklistChecked( | 530 void CrxInstaller::OnBlacklistChecked( |
532 extensions::BlacklistState blacklist_state) { | 531 extensions::BlacklistState blacklist_state) { |
533 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 532 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
534 if (!service_weak_) | 533 if (!service_weak_) |
535 return; | 534 return; |
536 | 535 |
537 blacklist_state_ = blacklist_state; | 536 blacklist_state_ = blacklist_state; |
538 | 537 |
539 if ((blacklist_state_ == extensions::BLACKLISTED_MALWARE || | 538 if ((blacklist_state_ == extensions::BLACKLISTED_MALWARE || |
540 blacklist_state_ == extensions::BLACKLISTED_UNKNOWN) && | 539 blacklist_state_ == extensions::BLACKLISTED_UNKNOWN) && |
541 !allow_silent_install_) { | 540 allow_silent_install_ == GRANT_AFTER_PROMPT) { |
542 // User tried to install a blacklisted extension. Show an error and | 541 // User tried to install a blacklisted extension. Show an error and |
543 // refuse to install it. | 542 // refuse to install it. |
544 ReportFailureFromUIThread(extensions::CrxInstallerError( | 543 ReportFailureFromUIThread(extensions::CrxInstallerError( |
545 l10n_util::GetStringFUTF16(IDS_EXTENSION_IS_BLACKLISTED, | 544 l10n_util::GetStringFUTF16(IDS_EXTENSION_IS_BLACKLISTED, |
546 base::UTF8ToUTF16(extension()->name())))); | 545 base::UTF8ToUTF16(extension()->name())))); |
547 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlockCRX", | 546 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlockCRX", |
548 extension()->location(), | 547 extension()->location(), |
549 Manifest::NUM_LOCATIONS); | 548 Manifest::NUM_LOCATIONS); |
550 return; | 549 return; |
551 } | 550 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 CrxInstallerError( | 600 CrxInstallerError( |
602 l10n_util::GetStringFUTF16( | 601 l10n_util::GetStringFUTF16( |
603 IDS_EXTENSION_OVERLAPPING_WEB_EXTENT, | 602 IDS_EXTENSION_OVERLAPPING_WEB_EXTENT, |
604 base::UTF8ToUTF16(overlapping_extension->name())))); | 603 base::UTF8ToUTF16(overlapping_extension->name())))); |
605 return; | 604 return; |
606 } | 605 } |
607 | 606 |
608 current_version_ = ExtensionPrefs::Get(service->profile()) | 607 current_version_ = ExtensionPrefs::Get(service->profile()) |
609 ->GetVersionString(extension()->id()); | 608 ->GetVersionString(extension()->id()); |
610 | 609 |
611 if (client_ && | 610 if (client_ && (allow_silent_install_ == GRANT_AFTER_PROMPT || !approved_) && |
612 (!allow_silent_install_ || !approved_) && | |
613 !update_from_settings_page_) { | 611 !update_from_settings_page_) { |
614 AddRef(); // Balanced in InstallUIProceed() and InstallUIAbort(). | 612 AddRef(); // Balanced in InstallUIProceed() and InstallUIAbort(). |
615 client_->ConfirmInstall(this, extension(), show_dialog_callback_); | 613 client_->ConfirmInstall(this, extension(), show_dialog_callback_); |
616 } else { | 614 } else { |
617 if (!installer_task_runner_->PostTask( | 615 if (!installer_task_runner_->PostTask( |
618 FROM_HERE, | 616 FROM_HERE, |
619 base::Bind(&CrxInstaller::CompleteInstall, this))) | 617 base::Bind(&CrxInstaller::CompleteInstall, this))) |
620 NOTREACHED(); | 618 NOTREACHED(); |
621 } | 619 } |
622 return; | 620 return; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 return; | 786 return; |
789 | 787 |
790 if (!update_from_settings_page_) { | 788 if (!update_from_settings_page_) { |
791 // If there is a client, tell the client about installation. | 789 // If there is a client, tell the client about installation. |
792 if (client_) | 790 if (client_) |
793 client_->OnInstallSuccess(extension(), install_icon_.get()); | 791 client_->OnInstallSuccess(extension(), install_icon_.get()); |
794 | 792 |
795 // We update the extension's granted permissions if the user already | 793 // We update the extension's granted permissions if the user already |
796 // approved the install (client_ is non NULL), or we are allowed to install | 794 // approved the install (client_ is non NULL), or we are allowed to install |
797 // this silently. | 795 // this silently. |
798 if (client_ || allow_silent_install_) { | 796 if (client_ || allow_silent_install_ == GRANT_SILENTLY) { |
799 PermissionsUpdater perms_updater(profile()); | 797 PermissionsUpdater perms_updater(profile()); |
800 perms_updater.GrantActivePermissions(extension()); | 798 perms_updater.GrantActivePermissions(extension()); |
801 } | 799 } |
802 } | 800 } |
803 | 801 |
804 service_weak_->OnExtensionInstalled(extension(), | 802 service_weak_->OnExtensionInstalled(extension(), |
805 page_ordinal_, | 803 page_ordinal_, |
806 has_requirement_errors_, | 804 has_requirement_errors_, |
807 blacklist_state_, | 805 blacklist_state_, |
808 install_wait_for_idle_); | 806 install_wait_for_idle_); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 if (!prefs->DidExtensionEscalatePermissions(extension()->id())) | 888 if (!prefs->DidExtensionEscalatePermissions(extension()->id())) |
891 return; | 889 return; |
892 | 890 |
893 if (client_) { | 891 if (client_) { |
894 AddRef(); // Balanced in InstallUIProceed() and InstallUIAbort(). | 892 AddRef(); // Balanced in InstallUIProceed() and InstallUIAbort(). |
895 client_->ConfirmReEnable(this, extension()); | 893 client_->ConfirmReEnable(this, extension()); |
896 } | 894 } |
897 } | 895 } |
898 | 896 |
899 } // namespace extensions | 897 } // namespace extensions |
OLD | NEW |