diff options
author | MHX348@motorola.com <MHX348@motorola.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-01 01:58:29 +0000 |
---|---|---|
committer | MHX348@motorola.com <MHX348@motorola.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-01 01:58:29 +0000 |
commit | b86b9eedf43f356393d1fd44b33411037b89fcd7 (patch) | |
tree | 9448559669be3dde6e4c1c9ceda00602832237ff /chrome/browser/extensions/crx_installer.cc | |
parent | e82c0e351d9c1f2be8f72fd880ac7e7a271dc3af (diff) | |
download | chromium_src-b86b9eedf43f356393d1fd44b33411037b89fcd7.zip chromium_src-b86b9eedf43f356393d1fd44b33411037b89fcd7.tar.gz chromium_src-b86b9eedf43f356393d1fd44b33411037b89fcd7.tar.bz2 |
Update extensions with Drag-and-Drop in extension settings page.
While dropping a CRX on the extension page, if there is a previous version installed, then do the following.
- If the extension requires no new permission, then update silently.
- If the extension requires additional permission, install the update silently which causes the extension to get disabled. And show the re-enable prompt.
* if user cancels the prompt, extension will continue to be disabled.
* if user confirms re-enable, extension will be enabled back.
Screenshot of the re-enable prompt is uploaded at http://crbug.com/169521#c11
BUG=169521
Review URL: https://chromiumcodereview.appspot.com/12319131
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@185401 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/crx_installer.cc')
-rw-r--r-- | chrome/browser/extensions/crx_installer.cc | 143 |
1 files changed, 105 insertions, 38 deletions
diff --git a/chrome/browser/extensions/crx_installer.cc b/chrome/browser/extensions/crx_installer.cc index 6179662..2ccfc4a 100644 --- a/chrome/browser/extensions/crx_installer.cc +++ b/chrome/browser/extensions/crx_installer.cc @@ -110,7 +110,8 @@ CrxInstaller::CrxInstaller( error_on_unsupported_requirements_(false), requirements_checker_(new RequirementsChecker()), has_requirement_errors_(false), - install_wait_for_idle_(true) { + install_wait_for_idle_(true), + update_from_settings_page_(false) { installer_task_runner_ = frontend_weak->GetFileTaskRunner(); if (!approval) return; @@ -430,6 +431,10 @@ void CrxInstaller::ConfirmInstall() { if (!frontend_weak_.get() || frontend_weak_->browser_terminating()) return; + // Check whether this install is initiated from the settings page to + // update an existing extension or app. + CheckUpdateFromSettingsPage(); + string16 error; if (!ExtensionSystem::Get(profile_)->management_policy()-> UserMayLoad(extension_, &error)) { @@ -454,8 +459,10 @@ void CrxInstaller::ConfirmInstall() { current_version_ = frontend_weak_->extension_prefs()->GetVersionString(extension_->id()); - if (client_ && (!allow_silent_install_ || !approved_)) { - AddRef(); // Balanced in Proceed() and Abort(). + if (client_ && + (!allow_silent_install_ || !approved_) && + !update_from_settings_page_) { + AddRef(); // Balanced in InstallUIProceed() and InstallUIAbort(). client_->ConfirmInstall(this, extension_.get(), show_dialog_callback_); } else { if (!installer_task_runner_->PostTask( @@ -467,31 +474,51 @@ void CrxInstaller::ConfirmInstall() { } void CrxInstaller::InstallUIProceed() { - if (!installer_task_runner_->PostTask( - FROM_HERE, - base::Bind(&CrxInstaller::CompleteInstall, this))) - NOTREACHED(); + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - Release(); // balanced in ConfirmInstall(). -} + if (!frontend_weak_.get() || frontend_weak_->browser_terminating()) + return; -void CrxInstaller::InstallUIAbort(bool user_initiated) { - std::string histogram_name = user_initiated ? - "Extensions.Permissions_InstallCancel" : - "Extensions.Permissions_InstallAbort"; - ExtensionService::RecordPermissionMessagesHistogram( - extension_, histogram_name.c_str()); + // If update_from_settings_page_ boolean is true, this functions is + // getting called in response to ExtensionInstallPrompt::ConfirmReEnable() + // and if it is false, this function is called in response to + // ExtensionInstallPrompt::ConfirmInstall(). + if (update_from_settings_page_) { + frontend_weak_->GrantPermissionsAndEnableExtension( + extension_.get(), client_->record_oauth2_grant()); + } else { + if (!installer_task_runner_->PostTask( + FROM_HERE, + base::Bind(&CrxInstaller::CompleteInstall, this))) + NOTREACHED(); + } - // Kill the theme loading bubble. - content::NotificationService* service = - content::NotificationService::current(); - service->Notify(chrome::NOTIFICATION_NO_THEME_DETECTED, - content::Source<CrxInstaller>(this), - content::NotificationService::NoDetails()); + Release(); // balanced in ConfirmInstall() or ConfirmReEnable(). +} - NotifyCrxInstallComplete(false); +void CrxInstaller::InstallUIAbort(bool user_initiated) { + // If update_from_settings_page_ boolean is true, this functions is + // getting called in response to ExtensionInstallPrompt::ConfirmReEnable() + // and if it is false, this function is called in response to + // ExtensionInstallPrompt::ConfirmInstall(). + if (!update_from_settings_page_) { + std::string histogram_name = user_initiated ? + "Extensions.Permissions_InstallCancel" : + "Extensions.Permissions_InstallAbort"; + ExtensionService::RecordPermissionMessagesHistogram( + extension_, histogram_name.c_str()); + + // Kill the theme loading bubble. + content::NotificationService* service = + content::NotificationService::current(); + service->Notify(chrome::NOTIFICATION_NO_THEME_DETECTED, + content::Source<CrxInstaller>(this), + content::NotificationService::NoDetails()); + + NotifyCrxInstallComplete(false); + } - Release(); // balanced in ConfirmInstall(). + Release(); // balanced in ConfirmInstall() or ConfirmReEnable(). // We're done. Since we don't post any more tasks to ourself, our ref count // should go to zero and we die. The destructor will clean up the temp dir. @@ -613,20 +640,21 @@ void CrxInstaller::ReportSuccessFromUIThread() { if (!frontend_weak_.get() || frontend_weak_->browser_terminating()) return; - // If there is a client, tell the client about installation. - if (client_) { - client_->OnInstallSuccess(extension_.get(), install_icon_.get()); - } + if (!update_from_settings_page_) { + // If there is a client, tell the client about installation. + if (client_) + client_->OnInstallSuccess(extension_.get(), install_icon_.get()); - if (client_ && !approved_) - record_oauth2_grant_ = client_->record_oauth2_grant(); + if (client_ && !approved_) + record_oauth2_grant_ = client_->record_oauth2_grant(); - // We update the extension's granted permissions if the user already approved - // the install (client_ is non NULL), or we are allowed to install this - // silently. - if (client_ || allow_silent_install_) { - PermissionsUpdater perms_updater(profile()); - perms_updater.GrantActivePermissions(extension_, record_oauth2_grant_); + // We update the extension's granted permissions if the user already + // approved the install (client_ is non NULL), or we are allowed to install + // this silently. + if (client_ || allow_silent_install_) { + PermissionsUpdater perms_updater(profile()); + perms_updater.GrantActivePermissions(extension_, record_oauth2_grant_); + } } // Install the extension if it's not blacklisted, but notify either way. @@ -678,9 +706,9 @@ void CrxInstaller::NotifyCrxInstallComplete(bool success) { content::Source<CrxInstaller>(this), content::Details<const Extension>(success ? extension_.get() : NULL)); - // We're done. We don't post any more tasks to ourselves so we are deleted - // soon. - extension_ = NULL; + if (success) + ConfirmReEnable(); + } void CrxInstaller::CleanupTempFiles() { @@ -705,4 +733,43 @@ void CrxInstaller::CleanupTempFiles() { } } +void CrxInstaller::CheckUpdateFromSettingsPage() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + if (!frontend_weak_.get() || frontend_weak_->browser_terminating()) + return; + + if (off_store_install_allow_reason_ != OffStoreInstallAllowedFromSettingsPage) + return; + + const Extension* installed_extension = + frontend_weak_->GetInstalledExtension(extension_->id()); + if (installed_extension) { + // Previous version of the extension exists. + update_from_settings_page_ = true; + expected_id_ = installed_extension->id(); + install_source_ = installed_extension->location(); + install_cause_ = extension_misc::INSTALL_CAUSE_UPDATE; + } +} + +void CrxInstaller::ConfirmReEnable() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + if (!frontend_weak_.get() || frontend_weak_->browser_terminating()) + return; + + if (!update_from_settings_page_) + return; + + extensions::ExtensionPrefs* prefs = frontend_weak_->extension_prefs(); + if (!prefs->DidExtensionEscalatePermissions(extension_->id())) + return; + + if (client_) { + AddRef(); // Balanced in InstallUIProceed() and InstallUIAbort(). + client_->ConfirmReEnable(this, extension_.get()); + } +} + } // namespace extensions |