| 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" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/scoped_temp_dir.h" | 16 #include "base/scoped_temp_dir.h" |
| 17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
| 19 #include "base/string_util.h" |
| 19 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
| 20 #include "base/time.h" | 21 #include "base/time.h" |
| 21 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
| 22 #include "base/version.h" | 23 #include "base/version.h" |
| 23 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 24 #include "chrome/browser/extensions/convert_user_script.h" | 25 #include "chrome/browser/extensions/convert_user_script.h" |
| 25 #include "chrome/browser/extensions/convert_web_app.h" | 26 #include "chrome/browser/extensions/convert_web_app.h" |
| 26 #include "chrome/browser/extensions/default_apps_trial.h" | 27 #include "chrome/browser/extensions/default_apps_trial.h" |
| 27 #include "chrome/browser/extensions/extension_error_reporter.h" | 28 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 28 #include "chrome/browser/extensions/extension_install_ui.h" | 29 #include "chrome/browser/extensions/extension_install_ui.h" |
| 29 #include "chrome/browser/extensions/extension_service.h" | 30 #include "chrome/browser/extensions/extension_service.h" |
| 30 #include "chrome/browser/extensions/extension_system.h" | 31 #include "chrome/browser/extensions/extension_system.h" |
| 31 #include "chrome/browser/extensions/permissions_updater.h" | 32 #include "chrome/browser/extensions/permissions_updater.h" |
| 33 #include "chrome/browser/extensions/requirements_checker.h" |
| 32 #include "chrome/browser/extensions/webstore_installer.h" | 34 #include "chrome/browser/extensions/webstore_installer.h" |
| 33 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
| 34 #include "chrome/browser/shell_integration.h" | 36 #include "chrome/browser/shell_integration.h" |
| 35 #include "chrome/browser/web_applications/web_app.h" | 37 #include "chrome/browser/web_applications/web_app.h" |
| 36 #include "chrome/common/chrome_notification_types.h" | 38 #include "chrome/common/chrome_notification_types.h" |
| 37 #include "chrome/common/chrome_paths.h" | 39 #include "chrome/common/chrome_paths.h" |
| 38 #include "chrome/common/extensions/extension_constants.h" | 40 #include "chrome/common/extensions/extension_constants.h" |
| 39 #include "chrome/common/extensions/extension_file_util.h" | 41 #include "chrome/common/extensions/extension_file_util.h" |
| 40 #include "chrome/common/extensions/extension_icon_set.h" | 42 #include "chrome/common/extensions/extension_icon_set.h" |
| 41 #include "chrome/common/extensions/extension_switch_utils.h" | 43 #include "chrome/common/extensions/extension_switch_utils.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 create_app_shortcut_(false), | 96 create_app_shortcut_(false), |
| 95 frontend_weak_(frontend_weak), | 97 frontend_weak_(frontend_weak), |
| 96 profile_(frontend_weak->profile()), | 98 profile_(frontend_weak->profile()), |
| 97 client_(client), | 99 client_(client), |
| 98 apps_require_extension_mime_type_(false), | 100 apps_require_extension_mime_type_(false), |
| 99 allow_silent_install_(false), | 101 allow_silent_install_(false), |
| 100 install_cause_(extension_misc::INSTALL_CAUSE_UNSET), | 102 install_cause_(extension_misc::INSTALL_CAUSE_UNSET), |
| 101 creation_flags_(Extension::NO_FLAGS), | 103 creation_flags_(Extension::NO_FLAGS), |
| 102 off_store_install_allow_reason_(OffStoreInstallDisallowed), | 104 off_store_install_allow_reason_(OffStoreInstallDisallowed), |
| 103 did_handle_successfully_(true), | 105 did_handle_successfully_(true), |
| 104 record_oauth2_grant_(false) { | 106 record_oauth2_grant_(false), |
| 107 error_on_unsupported_requirements_(false), |
| 108 requirements_checker_(new extensions::RequirementsChecker()), |
| 109 has_requirement_errors_(false) { |
| 105 if (!approval) | 110 if (!approval) |
| 106 return; | 111 return; |
| 107 | 112 |
| 108 CHECK(profile_->IsSameProfile(approval->profile)); | 113 CHECK(profile_->IsSameProfile(approval->profile)); |
| 109 client_->install_ui()->SetUseAppInstalledBubble( | 114 client_->install_ui()->SetUseAppInstalledBubble( |
| 110 approval->use_app_installed_bubble); | 115 approval->use_app_installed_bubble); |
| 111 client_->install_ui()->SetSkipPostInstallUI(approval->skip_post_install_ui); | 116 client_->install_ui()->SetSkipPostInstallUI(approval->skip_post_install_ui); |
| 112 | 117 |
| 113 if (approval->skip_install_dialog) { | 118 if (approval->skip_install_dialog) { |
| 114 // Mark the extension as approved, but save the expected manifest and ID | 119 // Mark the extension as approved, but save the expected manifest and ID |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 } | 383 } |
| 379 | 384 |
| 380 if (client_) { | 385 if (client_) { |
| 381 Extension::DecodeIcon(extension_.get(), | 386 Extension::DecodeIcon(extension_.get(), |
| 382 extension_misc::EXTENSION_ICON_LARGE, | 387 extension_misc::EXTENSION_ICON_LARGE, |
| 383 ExtensionIconSet::MATCH_BIGGER, | 388 ExtensionIconSet::MATCH_BIGGER, |
| 384 &install_icon_); | 389 &install_icon_); |
| 385 } | 390 } |
| 386 | 391 |
| 387 if (!BrowserThread::PostTask( | 392 if (!BrowserThread::PostTask( |
| 388 BrowserThread::UI, FROM_HERE, | 393 BrowserThread::UI, FROM_HERE, |
| 389 base::Bind(&CrxInstaller::ConfirmInstall, this))) | 394 base::Bind(&CrxInstaller::CheckRequirements, this))) |
| 390 NOTREACHED(); | 395 NOTREACHED(); |
| 391 } | 396 } |
| 392 | 397 |
| 398 void CrxInstaller::CheckRequirements() { |
| 399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 400 requirements_checker_->Check(extension_, |
| 401 base::Bind(&CrxInstaller::RequirementsChecked, |
| 402 this)); |
| 403 } |
| 404 |
| 405 void CrxInstaller::RequirementsChecked(std::vector<std::string> errors) { |
| 406 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 407 |
| 408 if (!errors.empty()) { |
| 409 if (error_on_unsupported_requirements_) { |
| 410 ReportFailureFromUIThread(CrxInstallerError( |
| 411 UTF8ToUTF16(JoinString(errors, ' ')))); |
| 412 return; |
| 413 } |
| 414 has_requirement_errors_ = true; |
| 415 } |
| 416 |
| 417 ConfirmInstall(); |
| 418 } |
| 419 |
| 393 void CrxInstaller::ConfirmInstall() { | 420 void CrxInstaller::ConfirmInstall() { |
| 394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 395 if (!frontend_weak_.get()) | 422 if (!frontend_weak_.get()) |
| 396 return; | 423 return; |
| 397 | 424 |
| 398 if (frontend_weak_->extension_prefs() | 425 if (frontend_weak_->extension_prefs() |
| 399 ->IsExtensionBlacklisted(extension_->id())) { | 426 ->IsExtensionBlacklisted(extension_->id())) { |
| 400 VLOG(1) << "This extension: " << extension_->id() | 427 VLOG(1) << "This extension: " << extension_->id() |
| 401 << " is blacklisted. Install failed."; | 428 << " is blacklisted. Install failed."; |
| 402 ReportFailureFromUIThread( | 429 ReportFailureFromUIThread( |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 // We update the extension's granted permissions if the user already approved | 622 // We update the extension's granted permissions if the user already approved |
| 596 // the install (client_ is non NULL), or we are allowed to install this | 623 // the install (client_ is non NULL), or we are allowed to install this |
| 597 // silently. | 624 // silently. |
| 598 if (client_ || allow_silent_install_) { | 625 if (client_ || allow_silent_install_) { |
| 599 PermissionsUpdater perms_updater(profile()); | 626 PermissionsUpdater perms_updater(profile()); |
| 600 perms_updater.GrantActivePermissions(extension_, record_oauth2_grant_); | 627 perms_updater.GrantActivePermissions(extension_, record_oauth2_grant_); |
| 601 } | 628 } |
| 602 | 629 |
| 603 // Tell the frontend about the installation and hand off ownership of | 630 // Tell the frontend about the installation and hand off ownership of |
| 604 // extension_ to it. | 631 // extension_ to it. |
| 605 frontend_weak_->OnExtensionInstalled(extension_, is_gallery_install(), | 632 frontend_weak_->OnExtensionInstalled(extension_, |
| 606 page_ordinal_); | 633 is_gallery_install(), |
| 634 page_ordinal_, |
| 635 has_requirement_errors_); |
| 607 | 636 |
| 608 NotifyCrxInstallComplete(extension_.get()); | 637 NotifyCrxInstallComplete(extension_.get()); |
| 609 | 638 |
| 610 extension_ = NULL; | 639 extension_ = NULL; |
| 611 | 640 |
| 612 // We're done. We don't post any more tasks to ourselves so we are deleted | 641 // We're done. We don't post any more tasks to ourselves so we are deleted |
| 613 // soon. | 642 // soon. |
| 614 } | 643 } |
| 615 | 644 |
| 616 void CrxInstaller::NotifyCrxInstallComplete(const Extension* extension) { | 645 void CrxInstaller::NotifyCrxInstallComplete(const Extension* extension) { |
| 617 // Some users (such as the download shelf) need to know when a | 646 // Some users (such as the download shelf) need to know when a |
| 618 // CRXInstaller is done. Listening for the EXTENSION_* events | 647 // CRXInstaller is done. Listening for the EXTENSION_* events |
| 619 // is problematic because they don't know anything about the | 648 // is problematic because they don't know anything about the |
| 620 // extension before it is unpacked, so they cannot filter based | 649 // extension before it is unpacked, so they cannot filter based |
| 621 // on the extension. | 650 // on the extension. |
| 622 content::NotificationService::current()->Notify( | 651 content::NotificationService::current()->Notify( |
| 623 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 652 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 624 content::Source<CrxInstaller>(this), | 653 content::Source<CrxInstaller>(this), |
| 625 content::Details<const Extension>(extension)); | 654 content::Details<const Extension>(extension)); |
| 626 } | 655 } |
| 627 | 656 |
| 628 } // namespace extensions | 657 } // namespace extensions |
| OLD | NEW |