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