| 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 23 matching lines...) Expand all  Loading... | 
| 34 #include "chrome/browser/extensions/webstore_installer.h" | 34 #include "chrome/browser/extensions/webstore_installer.h" | 
| 35 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" | 
| 36 #include "chrome/browser/shell_integration.h" | 36 #include "chrome/browser/shell_integration.h" | 
| 37 #include "chrome/browser/web_applications/web_app.h" | 37 #include "chrome/browser/web_applications/web_app.h" | 
| 38 #include "chrome/common/chrome_notification_types.h" | 38 #include "chrome/common/chrome_notification_types.h" | 
| 39 #include "chrome/common/chrome_paths.h" | 39 #include "chrome/common/chrome_paths.h" | 
| 40 #include "chrome/common/extensions/extension_constants.h" | 40 #include "chrome/common/extensions/extension_constants.h" | 
| 41 #include "chrome/common/extensions/extension_file_util.h" | 41 #include "chrome/common/extensions/extension_file_util.h" | 
| 42 #include "chrome/common/extensions/extension_icon_set.h" | 42 #include "chrome/common/extensions/extension_icon_set.h" | 
| 43 #include "chrome/common/extensions/feature_switch.h" | 43 #include "chrome/common/extensions/feature_switch.h" | 
|  | 44 #include "chrome/common/extensions/permissions/permission_set.h" | 
| 44 #include "content/public/browser/browser_thread.h" | 45 #include "content/public/browser/browser_thread.h" | 
| 45 #include "content/public/browser/notification_service.h" | 46 #include "content/public/browser/notification_service.h" | 
| 46 #include "content/public/browser/resource_dispatcher_host.h" | 47 #include "content/public/browser/resource_dispatcher_host.h" | 
| 47 #include "content/public/browser/user_metrics.h" | 48 #include "content/public/browser/user_metrics.h" | 
| 48 #include "grit/chromium_strings.h" | 49 #include "grit/chromium_strings.h" | 
| 49 #include "grit/generated_resources.h" | 50 #include "grit/generated_resources.h" | 
| 50 #include "grit/theme_resources.h" | 51 #include "grit/theme_resources.h" | 
| 51 #include "third_party/skia/include/core/SkBitmap.h" | 52 #include "third_party/skia/include/core/SkBitmap.h" | 
| 52 #include "ui/base/l10n/l10n_util.h" | 53 #include "ui/base/l10n/l10n_util.h" | 
| 53 #include "ui/base/resource/resource_bundle.h" | 54 #include "ui/base/resource/resource_bundle.h" | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 101       allow_silent_install_(false), | 102       allow_silent_install_(false), | 
| 102       bypass_blacklist_for_test_(false), | 103       bypass_blacklist_for_test_(false), | 
| 103       install_cause_(extension_misc::INSTALL_CAUSE_UNSET), | 104       install_cause_(extension_misc::INSTALL_CAUSE_UNSET), | 
| 104       creation_flags_(Extension::NO_FLAGS), | 105       creation_flags_(Extension::NO_FLAGS), | 
| 105       off_store_install_allow_reason_(OffStoreInstallDisallowed), | 106       off_store_install_allow_reason_(OffStoreInstallDisallowed), | 
| 106       did_handle_successfully_(true), | 107       did_handle_successfully_(true), | 
| 107       record_oauth2_grant_(false), | 108       record_oauth2_grant_(false), | 
| 108       error_on_unsupported_requirements_(false), | 109       error_on_unsupported_requirements_(false), | 
| 109       requirements_checker_(new extensions::RequirementsChecker()), | 110       requirements_checker_(new extensions::RequirementsChecker()), | 
| 110       has_requirement_errors_(false), | 111       has_requirement_errors_(false), | 
| 111       install_wait_for_idle_(true) { | 112       install_wait_for_idle_(true), | 
|  | 113       show_update_prompt_(false) { | 
| 112   installer_task_runner_ = frontend_weak->GetFileTaskRunner(); | 114   installer_task_runner_ = frontend_weak->GetFileTaskRunner(); | 
| 113   if (!approval) | 115   if (!approval) | 
| 114     return; | 116     return; | 
| 115 | 117 | 
| 116   CHECK(profile_->IsSameProfile(approval->profile)); | 118   CHECK(profile_->IsSameProfile(approval->profile)); | 
| 117   if (client_) { | 119   if (client_) { | 
| 118     client_->install_ui()->SetUseAppInstalledBubble( | 120     client_->install_ui()->SetUseAppInstalledBubble( | 
| 119         approval->use_app_installed_bubble); | 121         approval->use_app_installed_bubble); | 
| 120     client_->install_ui()->SetSkipPostInstallUI(approval->skip_post_install_ui); | 122     client_->install_ui()->SetSkipPostInstallUI(approval->skip_post_install_ui); | 
| 121   } | 123   } | 
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 421   } | 423   } | 
| 422 | 424 | 
| 423   ConfirmInstall(); | 425   ConfirmInstall(); | 
| 424 } | 426 } | 
| 425 | 427 | 
| 426 void CrxInstaller::ConfirmInstall() { | 428 void CrxInstaller::ConfirmInstall() { | 
| 427   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 429   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| 428   if (!frontend_weak_.get() || frontend_weak_->browser_terminating()) | 430   if (!frontend_weak_.get() || frontend_weak_->browser_terminating()) | 
| 429     return; | 431     return; | 
| 430 | 432 | 
|  | 433   // Limit the extension update with update-prompt only to the updates | 
|  | 434   // initiated from the extension settings page. | 
|  | 435   if (client_ && | 
|  | 436       off_store_install_allow_reason_ == | 
|  | 437           OffStoreInstallAllowedFromSettingsPage) | 
|  | 438     CheckExtensionExistsAlready(extension_.get()); | 
|  | 439 | 
| 431   string16 error; | 440   string16 error; | 
| 432   if (!ExtensionSystem::Get(profile_)->management_policy()-> | 441   if (!ExtensionSystem::Get(profile_)->management_policy()-> | 
| 433       UserMayLoad(extension_, &error)) { | 442       UserMayLoad(extension_, &error)) { | 
| 434     ReportFailureFromUIThread(CrxInstallerError(error)); | 443     ReportFailureFromUIThread(CrxInstallerError(error)); | 
| 435     return; | 444     return; | 
| 436   } | 445   } | 
| 437 | 446 | 
| 438   GURL overlapping_url; | 447   GURL overlapping_url; | 
| 439   const Extension* overlapping_extension = | 448   const Extension* overlapping_extension = | 
| 440       frontend_weak_->extensions()-> | 449       frontend_weak_->extensions()-> | 
| 441       GetHostedAppByOverlappingWebExtent(extension_->web_extent()); | 450       GetHostedAppByOverlappingWebExtent(extension_->web_extent()); | 
| 442   if (overlapping_extension && | 451   if (overlapping_extension && | 
| 443       overlapping_extension->id() != extension_->id()) { | 452       overlapping_extension->id() != extension_->id()) { | 
| 444     ReportFailureFromUIThread( | 453     ReportFailureFromUIThread( | 
| 445         CrxInstallerError( | 454         CrxInstallerError( | 
| 446             l10n_util::GetStringFUTF16( | 455             l10n_util::GetStringFUTF16( | 
| 447                 IDS_EXTENSION_OVERLAPPING_WEB_EXTENT, | 456                 IDS_EXTENSION_OVERLAPPING_WEB_EXTENT, | 
| 448                 UTF8ToUTF16(overlapping_extension->name())))); | 457                 UTF8ToUTF16(overlapping_extension->name())))); | 
| 449     return; | 458     return; | 
| 450   } | 459   } | 
| 451 | 460 | 
| 452   current_version_ = | 461   current_version_ = | 
| 453       frontend_weak_->extension_prefs()->GetVersionString(extension_->id()); | 462       frontend_weak_->extension_prefs()->GetVersionString(extension_->id()); | 
| 454 | 463 | 
| 455   if (client_ && (!allow_silent_install_ || !approved_)) { | 464   if (client_ && (!allow_silent_install_ || !approved_)) { | 
| 456     AddRef();  // Balanced in Proceed() and Abort(). | 465     AddRef();  // Balanced in Proceed() and Abort(). | 
| 457     client_->ConfirmInstall(this, extension_.get(), show_dialog_callback_); | 466     if (show_update_prompt_) | 
|  | 467       client_->ConfirmUpdate(this, extension_.get()); | 
|  | 468     else | 
|  | 469       client_->ConfirmInstall(this, extension_.get(), show_dialog_callback_); | 
| 458   } else { | 470   } else { | 
| 459     if (!installer_task_runner_->PostTask( | 471     if (!installer_task_runner_->PostTask( | 
| 460             FROM_HERE, | 472             FROM_HERE, | 
| 461             base::Bind(&CrxInstaller::CompleteInstall, this))) | 473             base::Bind(&CrxInstaller::CompleteInstall, this))) | 
| 462       NOTREACHED(); | 474       NOTREACHED(); | 
| 463   } | 475   } | 
| 464   return; | 476   return; | 
| 465 } | 477 } | 
| 466 | 478 | 
| 467 void CrxInstaller::InstallUIProceed() { | 479 void CrxInstaller::InstallUIProceed() { | 
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 694     extension_file_util::DeleteFile(temp_dir_, true); | 706     extension_file_util::DeleteFile(temp_dir_, true); | 
| 695     temp_dir_ = base::FilePath(); | 707     temp_dir_ = base::FilePath(); | 
| 696   } | 708   } | 
| 697 | 709 | 
| 698   if (delete_source_ && !source_file_.value().empty()) { | 710   if (delete_source_ && !source_file_.value().empty()) { | 
| 699     extension_file_util::DeleteFile(source_file_, false); | 711     extension_file_util::DeleteFile(source_file_, false); | 
| 700     source_file_ = base::FilePath(); | 712     source_file_ = base::FilePath(); | 
| 701   } | 713   } | 
| 702 } | 714 } | 
| 703 | 715 | 
|  | 716 void CrxInstaller::CheckExtensionExistsAlready(const Extension* extension) { | 
|  | 717   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
|  | 718   if (!frontend_weak_.get() || frontend_weak_->browser_terminating()) | 
|  | 719     return; | 
|  | 720 | 
|  | 721   const Extension* installed_extension = | 
|  | 722       frontend_weak_->GetInstalledExtension(extension->id()); | 
|  | 723   if (installed_extension) { | 
|  | 724     // Previous version of the extension exists. | 
|  | 725     expected_id_ = installed_extension->id(); | 
|  | 726     install_source_ = installed_extension->location(); | 
|  | 727     install_cause_ = extension_misc::INSTALL_CAUSE_UPDATE; | 
|  | 728 | 
|  | 729     // Update prompt is shown only if the extension has requested for | 
|  | 730     // additional permissions. | 
|  | 731     scoped_refptr<PermissionSet> granted_permissions = | 
|  | 732         frontend_weak_->extension_prefs()->GetGrantedPermissions( | 
|  | 733             installed_extension->id()); | 
|  | 734     CHECK(granted_permissions.get()); | 
|  | 735     show_update_prompt_ = granted_permissions->HasLessPrivilegesThan( | 
|  | 736         extension->GetActivePermissions()); | 
|  | 737     if (!show_update_prompt_) { | 
|  | 738       allow_silent_install_ = true; | 
|  | 739       approved_ = true; | 
|  | 740     } | 
|  | 741 | 
|  | 742     // Suppress the UI after success or failure. | 
|  | 743     client_->install_ui()->SetSkipPostInstallUI(true); | 
|  | 744   } | 
|  | 745 } | 
|  | 746 | 
| 704 }  // namespace extensions | 747 }  // namespace extensions | 
| OLD | NEW | 
|---|