Index: chrome/browser/extensions/crx_installer.cc |
diff --git a/chrome/browser/extensions/crx_installer.cc b/chrome/browser/extensions/crx_installer.cc |
index f997fc6fb78ab8869ba650c64851d3f9ff73df52..9300f7f46a2f087be59742b4b247d584175fe965 100644 |
--- a/chrome/browser/extensions/crx_installer.cc |
+++ b/chrome/browser/extensions/crx_installer.cc |
@@ -41,6 +41,7 @@ |
#include "chrome/common/extensions/extension_file_util.h" |
#include "chrome/common/extensions/extension_icon_set.h" |
#include "chrome/common/extensions/feature_switch.h" |
+#include "chrome/common/extensions/permissions/permission_set.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/notification_service.h" |
#include "content/public/browser/resource_dispatcher_host.h" |
@@ -108,7 +109,8 @@ CrxInstaller::CrxInstaller( |
error_on_unsupported_requirements_(false), |
requirements_checker_(new extensions::RequirementsChecker()), |
has_requirement_errors_(false), |
- install_wait_for_idle_(true) { |
+ install_wait_for_idle_(true), |
+ show_update_prompt_(false) { |
installer_task_runner_ = frontend_weak->GetFileTaskRunner(); |
if (!approval) |
return; |
@@ -428,6 +430,13 @@ void CrxInstaller::ConfirmInstall() { |
if (!frontend_weak_.get() || frontend_weak_->browser_terminating()) |
return; |
+ // Limit the extension update with update-prompt only to the updates |
+ // initiated from the extension settings page. |
+ if (client_ && |
+ off_store_install_allow_reason_ == |
+ OffStoreInstallAllowedFromSettingsPage) |
+ CheckExtensionExistsAlready(extension_.get()); |
+ |
string16 error; |
if (!ExtensionSystem::Get(profile_)->management_policy()-> |
UserMayLoad(extension_, &error)) { |
@@ -454,7 +463,10 @@ void CrxInstaller::ConfirmInstall() { |
if (client_ && (!allow_silent_install_ || !approved_)) { |
AddRef(); // Balanced in Proceed() and Abort(). |
- client_->ConfirmInstall(this, extension_.get(), show_dialog_callback_); |
+ if (show_update_prompt_) |
+ client_->ConfirmUpdate(this, extension_.get()); |
+ else |
+ client_->ConfirmInstall(this, extension_.get(), show_dialog_callback_); |
} else { |
if (!installer_task_runner_->PostTask( |
FROM_HERE, |
@@ -701,4 +713,35 @@ void CrxInstaller::CleanupTempFiles() { |
} |
} |
+void CrxInstaller::CheckExtensionExistsAlready(const Extension* extension) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ if (!frontend_weak_.get() || frontend_weak_->browser_terminating()) |
+ return; |
+ |
+ const Extension* installed_extension = |
+ frontend_weak_->GetInstalledExtension(extension->id()); |
+ if (installed_extension) { |
+ // Previous version of the extension exists. |
+ expected_id_ = installed_extension->id(); |
+ install_source_ = installed_extension->location(); |
+ install_cause_ = extension_misc::INSTALL_CAUSE_UPDATE; |
+ |
+ // Update prompt is shown only if the extension has requested for |
+ // additional permissions. |
+ scoped_refptr<PermissionSet> granted_permissions = |
+ frontend_weak_->extension_prefs()->GetGrantedPermissions( |
+ installed_extension->id()); |
+ CHECK(granted_permissions.get()); |
+ show_update_prompt_ = granted_permissions->HasLessPrivilegesThan( |
+ extension->GetActivePermissions()); |
+ if (!show_update_prompt_) { |
+ allow_silent_install_ = true; |
+ approved_ = true; |
+ } |
+ |
+ // Suppress the UI after success or failure. |
+ client_->install_ui()->SetSkipPostInstallUI(true); |
+ } |
+} |
+ |
} // namespace extensions |