| 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 26 matching lines...) Expand all Loading... |
| 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/common/extensions/manifest_url_handler.h" | 40 #include "chrome/common/extensions/manifest_url_handler.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 "content/public/browser/user_metrics.h" | 44 #include "content/public/browser/user_metrics.h" |
| 45 #include "extensions/browser/extension_prefs.h" | 45 #include "extensions/browser/extension_prefs.h" |
| 46 #include "extensions/browser/extension_system.h" | 46 #include "extensions/browser/extension_system.h" |
| 47 #include "extensions/browser/install_flag.h" |
| 47 #include "extensions/common/extension_icon_set.h" | 48 #include "extensions/common/extension_icon_set.h" |
| 48 #include "extensions/common/feature_switch.h" | 49 #include "extensions/common/feature_switch.h" |
| 49 #include "extensions/common/file_util.h" | 50 #include "extensions/common/file_util.h" |
| 50 #include "extensions/common/manifest.h" | 51 #include "extensions/common/manifest.h" |
| 51 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" | 52 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" |
| 52 #include "extensions/common/manifest_handlers/shared_module_info.h" | 53 #include "extensions/common/manifest_handlers/shared_module_info.h" |
| 53 #include "extensions/common/permissions/permission_message_provider.h" | 54 #include "extensions/common/permissions/permission_message_provider.h" |
| 54 #include "extensions/common/permissions/permission_set.h" | 55 #include "extensions/common/permissions/permission_set.h" |
| 55 #include "extensions/common/permissions/permissions_data.h" | 56 #include "extensions/common/permissions/permissions_data.h" |
| 56 #include "extensions/common/user_script.h" | 57 #include "extensions/common/user_script.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // See header file comment on |client_| for why we use a raw pointer here. | 124 // See header file comment on |client_| for why we use a raw pointer here. |
| 124 client_(client.release()), | 125 client_(client.release()), |
| 125 apps_require_extension_mime_type_(false), | 126 apps_require_extension_mime_type_(false), |
| 126 allow_silent_install_(false), | 127 allow_silent_install_(false), |
| 127 grant_permissions_(true), | 128 grant_permissions_(true), |
| 128 install_cause_(extension_misc::INSTALL_CAUSE_UNSET), | 129 install_cause_(extension_misc::INSTALL_CAUSE_UNSET), |
| 129 creation_flags_(Extension::NO_FLAGS), | 130 creation_flags_(Extension::NO_FLAGS), |
| 130 off_store_install_allow_reason_(OffStoreInstallDisallowed), | 131 off_store_install_allow_reason_(OffStoreInstallDisallowed), |
| 131 did_handle_successfully_(true), | 132 did_handle_successfully_(true), |
| 132 error_on_unsupported_requirements_(false), | 133 error_on_unsupported_requirements_(false), |
| 133 has_requirement_errors_(false), | |
| 134 blacklist_state_(extensions::NOT_BLACKLISTED), | |
| 135 install_wait_for_idle_(true), | |
| 136 update_from_settings_page_(false), | 134 update_from_settings_page_(false), |
| 137 is_ephemeral_(false), | 135 install_flags_(kInstallFlagNone), |
| 138 installer_(service_weak->profile()) { | 136 installer_(service_weak->profile()) { |
| 139 installer_task_runner_ = service_weak->GetFileTaskRunner(); | 137 installer_task_runner_ = service_weak->GetFileTaskRunner(); |
| 140 if (!approval) | 138 if (!approval) |
| 141 return; | 139 return; |
| 142 | 140 |
| 143 CHECK(profile()->IsSameProfile(approval->profile)); | 141 CHECK(profile()->IsSameProfile(approval->profile)); |
| 144 if (client_) { | 142 if (client_) { |
| 145 client_->install_ui()->SetUseAppInstalledBubble( | 143 client_->install_ui()->SetUseAppInstalledBubble( |
| 146 approval->use_app_installed_bubble); | 144 approval->use_app_installed_bubble); |
| 147 client_->install_ui()->set_skip_post_install_ui( | 145 client_->install_ui()->set_skip_post_install_ui( |
| 148 approval->skip_post_install_ui); | 146 approval->skip_post_install_ui); |
| 149 } | 147 } |
| 150 | 148 |
| 151 if (approval->skip_install_dialog) { | 149 if (approval->skip_install_dialog) { |
| 152 // Mark the extension as approved, but save the expected manifest and ID | 150 // Mark the extension as approved, but save the expected manifest and ID |
| 153 // so we can check that they match the CRX's. | 151 // so we can check that they match the CRX's. |
| 154 approved_ = true; | 152 approved_ = true; |
| 155 expected_manifest_check_level_ = approval->manifest_check_level; | 153 expected_manifest_check_level_ = approval->manifest_check_level; |
| 156 if (expected_manifest_check_level_ != | 154 if (expected_manifest_check_level_ != |
| 157 WebstoreInstaller::MANIFEST_CHECK_LEVEL_NONE) | 155 WebstoreInstaller::MANIFEST_CHECK_LEVEL_NONE) |
| 158 expected_manifest_.reset(approval->manifest->DeepCopy()); | 156 expected_manifest_.reset(approval->manifest->DeepCopy()); |
| 159 expected_id_ = approval->extension_id; | 157 expected_id_ = approval->extension_id; |
| 160 } | 158 } |
| 161 if (approval->minimum_version.get()) { | 159 if (approval->minimum_version.get()) { |
| 162 expected_version_.reset(new Version(*approval->minimum_version)); | 160 expected_version_.reset(new Version(*approval->minimum_version)); |
| 163 expected_version_strict_checking_ = false; | 161 expected_version_strict_checking_ = false; |
| 164 } | 162 } |
| 165 | 163 |
| 166 show_dialog_callback_ = approval->show_dialog_callback; | 164 show_dialog_callback_ = approval->show_dialog_callback; |
| 167 is_ephemeral_ = approval->is_ephemeral; | 165 set_is_ephemeral(approval->is_ephemeral); |
| 168 } | 166 } |
| 169 | 167 |
| 170 CrxInstaller::~CrxInstaller() { | 168 CrxInstaller::~CrxInstaller() { |
| 171 // Make sure the UI is deleted on the ui thread. | 169 // Make sure the UI is deleted on the ui thread. |
| 172 if (client_) { | 170 if (client_) { |
| 173 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, client_); | 171 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, client_); |
| 174 client_ = NULL; | 172 client_ = NULL; |
| 175 } | 173 } |
| 176 } | 174 } |
| 177 | 175 |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 519 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 522 if (!service_weak_) | 520 if (!service_weak_) |
| 523 return; | 521 return; |
| 524 | 522 |
| 525 if (!requirement_errors.empty()) { | 523 if (!requirement_errors.empty()) { |
| 526 if (error_on_unsupported_requirements_) { | 524 if (error_on_unsupported_requirements_) { |
| 527 ReportFailureFromUIThread(CrxInstallerError( | 525 ReportFailureFromUIThread(CrxInstallerError( |
| 528 base::UTF8ToUTF16(JoinString(requirement_errors, ' ')))); | 526 base::UTF8ToUTF16(JoinString(requirement_errors, ' ')))); |
| 529 return; | 527 return; |
| 530 } | 528 } |
| 531 has_requirement_errors_ = true; | 529 install_flags_ |= kInstallFlagHasRequirementErrors; |
| 532 } | 530 } |
| 533 | 531 |
| 534 ExtensionSystem::Get(profile())->blacklist()->IsBlacklisted( | 532 ExtensionSystem::Get(profile())->blacklist()->IsBlacklisted( |
| 535 extension()->id(), | 533 extension()->id(), |
| 536 base::Bind(&CrxInstaller::OnBlacklistChecked, this)); | 534 base::Bind(&CrxInstaller::OnBlacklistChecked, this)); |
| 537 } | 535 } |
| 538 | 536 |
| 539 void CrxInstaller::OnBlacklistChecked( | 537 void CrxInstaller::OnBlacklistChecked( |
| 540 extensions::BlacklistState blacklist_state) { | 538 extensions::BlacklistState blacklist_state) { |
| 541 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 539 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 542 if (!service_weak_) | 540 if (!service_weak_) |
| 543 return; | 541 return; |
| 544 | 542 |
| 545 blacklist_state_ = blacklist_state; | 543 if (blacklist_state == extensions::BLACKLISTED_MALWARE) { |
| 544 install_flags_ |= kInstallFlagIsBlacklistedForMalware; |
| 545 } |
| 546 | 546 |
| 547 if ((blacklist_state_ == extensions::BLACKLISTED_MALWARE || | 547 if ((blacklist_state == extensions::BLACKLISTED_MALWARE || |
| 548 blacklist_state_ == extensions::BLACKLISTED_UNKNOWN) && | 548 blacklist_state == extensions::BLACKLISTED_UNKNOWN) && |
| 549 !allow_silent_install_) { | 549 !allow_silent_install_) { |
| 550 // User tried to install a blacklisted extension. Show an error and | 550 // User tried to install a blacklisted extension. Show an error and |
| 551 // refuse to install it. | 551 // refuse to install it. |
| 552 ReportFailureFromUIThread(extensions::CrxInstallerError( | 552 ReportFailureFromUIThread(extensions::CrxInstallerError( |
| 553 l10n_util::GetStringFUTF16(IDS_EXTENSION_IS_BLACKLISTED, | 553 l10n_util::GetStringFUTF16(IDS_EXTENSION_IS_BLACKLISTED, |
| 554 base::UTF8ToUTF16(extension()->name())))); | 554 base::UTF8ToUTF16(extension()->name())))); |
| 555 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlockCRX", | 555 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlockCRX", |
| 556 extension()->location(), | 556 extension()->location(), |
| 557 Manifest::NUM_LOCATIONS); | 557 Manifest::NUM_LOCATIONS); |
| 558 return; | 558 return; |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 | 810 |
| 811 // We update the extension's granted permissions if the user already | 811 // We update the extension's granted permissions if the user already |
| 812 // approved the install (client_ is non NULL), or we are allowed to install | 812 // approved the install (client_ is non NULL), or we are allowed to install |
| 813 // this silently. | 813 // this silently. |
| 814 if ((client_ || allow_silent_install_) && grant_permissions_) { | 814 if ((client_ || allow_silent_install_) && grant_permissions_) { |
| 815 PermissionsUpdater perms_updater(profile()); | 815 PermissionsUpdater perms_updater(profile()); |
| 816 perms_updater.GrantActivePermissions(extension()); | 816 perms_updater.GrantActivePermissions(extension()); |
| 817 } | 817 } |
| 818 } | 818 } |
| 819 | 819 |
| 820 service_weak_->OnExtensionInstalled(extension(), | 820 service_weak_->OnExtensionInstalled( |
| 821 page_ordinal_, | 821 extension(), page_ordinal_, install_flags_); |
| 822 has_requirement_errors_, | |
| 823 blacklist_state_, | |
| 824 is_ephemeral_, | |
| 825 install_wait_for_idle_); | |
| 826 NotifyCrxInstallComplete(true); | 822 NotifyCrxInstallComplete(true); |
| 827 } | 823 } |
| 828 | 824 |
| 829 void CrxInstaller::NotifyCrxInstallBegin() { | 825 void CrxInstaller::NotifyCrxInstallBegin() { |
| 830 InstallTrackerFactory::GetForProfile(profile()) | 826 InstallTrackerFactory::GetForProfile(profile()) |
| 831 ->OnBeginCrxInstall(expected_id_); | 827 ->OnBeginCrxInstall(expected_id_); |
| 832 } | 828 } |
| 833 | 829 |
| 834 void CrxInstaller::NotifyCrxInstallComplete(bool success) { | 830 void CrxInstaller::NotifyCrxInstallComplete(bool success) { |
| 835 // Some users (such as the download shelf) need to know when a | 831 // Some users (such as the download shelf) need to know when a |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 if (!prefs->DidExtensionEscalatePermissions(extension()->id())) | 903 if (!prefs->DidExtensionEscalatePermissions(extension()->id())) |
| 908 return; | 904 return; |
| 909 | 905 |
| 910 if (client_) { | 906 if (client_) { |
| 911 AddRef(); // Balanced in InstallUIProceed() and InstallUIAbort(). | 907 AddRef(); // Balanced in InstallUIProceed() and InstallUIAbort(). |
| 912 client_->ConfirmReEnable(this, extension()); | 908 client_->ConfirmReEnable(this, extension()); |
| 913 } | 909 } |
| 914 } | 910 } |
| 915 | 911 |
| 916 } // namespace extensions | 912 } // namespace extensions |
| OLD | NEW |