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_unsported_requirements_(false), | |
108 requirements_checker_(new extensions::RequirementsChecker()) { | |
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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
377 return; | 381 return; |
378 } | 382 } |
379 | 383 |
380 if (client_) { | 384 if (client_) { |
381 Extension::DecodeIcon(extension_.get(), | 385 Extension::DecodeIcon(extension_.get(), |
382 ExtensionIconSet::EXTENSION_ICON_LARGE, | 386 ExtensionIconSet::EXTENSION_ICON_LARGE, |
383 ExtensionIconSet::MATCH_BIGGER, | 387 ExtensionIconSet::MATCH_BIGGER, |
384 &install_icon_); | 388 &install_icon_); |
385 } | 389 } |
386 | 390 |
391 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
392 base::Bind(&extensions::RequirementsChecker::Check, | |
393 base::Unretained(requirements_checker_.get()), | |
394 extension_, | |
395 base::Bind(&CrxInstaller::RequirementsChecked, this), | |
396 BrowserThread::FILE)); | |
397 } | |
398 | |
399 void CrxInstaller::RequirementsChecked(std::vector<std::string> errors) { | |
400 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
401 | |
402 if (!errors.empty()) { | |
403 if (error_on_unsported_requirements_) { | |
404 ReportFailureFromFileThread(CrxInstallerError( | |
405 UTF8ToUTF16(JoinString(errors, ' ')))); | |
eaugusti
2012/07/26 23:24:13
Errors should probably be joined and formatted bet
| |
406 return; | |
407 } | |
408 requirement_errors_.swap(errors); | |
409 } | |
410 | |
387 if (!BrowserThread::PostTask( | 411 if (!BrowserThread::PostTask( |
388 BrowserThread::UI, FROM_HERE, | 412 BrowserThread::UI, FROM_HERE, |
389 base::Bind(&CrxInstaller::ConfirmInstall, this))) | 413 base::Bind(&CrxInstaller::ConfirmInstall, this))) |
390 NOTREACHED(); | 414 NOTREACHED(); |
391 } | 415 } |
392 | 416 |
393 void CrxInstaller::ConfirmInstall() { | 417 void CrxInstaller::ConfirmInstall() { |
394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
395 if (!frontend_weak_.get()) | 419 if (!frontend_weak_.get()) |
396 return; | 420 return; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
513 // TODO(rdevlin.cronin): Continue removing std::string errors and replacing | 537 // TODO(rdevlin.cronin): Continue removing std::string errors and replacing |
514 // with string16 | 538 // with string16 |
515 std::string error; | 539 std::string error; |
516 extension_ = extension_file_util::LoadExtension( | 540 extension_ = extension_file_util::LoadExtension( |
517 version_dir, | 541 version_dir, |
518 install_source_, | 542 install_source_, |
519 extension_->creation_flags() | Extension::REQUIRE_KEY, | 543 extension_->creation_flags() | Extension::REQUIRE_KEY, |
520 &error); | 544 &error); |
521 CHECK(error.empty()) << error; | 545 CHECK(error.empty()) << error; |
522 | 546 |
547 if (!requirement_errors_.empty()) { | |
548 extensions::Extension::InstallWarningVector install_warnings; | |
549 std::vector<std::string>::iterator it; | |
550 for (it = requirement_errors_.begin(); it != requirement_errors_.end(); | |
551 ++it) { | |
552 install_warnings.push_back(Extension::InstallWarning( | |
553 Extension::InstallWarning::FORMAT_TEXT, *it)); | |
554 } | |
555 const_cast<Extension*>(extension_.get())->AddInstallWarnings( | |
556 install_warnings); | |
557 } | |
558 | |
523 ReportSuccessFromFileThread(); | 559 ReportSuccessFromFileThread(); |
524 } | 560 } |
525 | 561 |
526 void CrxInstaller::ReportFailureFromFileThread(const CrxInstallerError& error) { | 562 void CrxInstaller::ReportFailureFromFileThread(const CrxInstallerError& error) { |
527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 563 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
528 if (!BrowserThread::PostTask( | 564 if (!BrowserThread::PostTask( |
529 BrowserThread::UI, FROM_HERE, | 565 BrowserThread::UI, FROM_HERE, |
530 base::Bind(&CrxInstaller::ReportFailureFromUIThread, this, error))) { | 566 base::Bind(&CrxInstaller::ReportFailureFromUIThread, this, error))) { |
531 NOTREACHED(); | 567 NOTREACHED(); |
532 } | 568 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
595 // We update the extension's granted permissions if the user already approved | 631 // 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 | 632 // the install (client_ is non NULL), or we are allowed to install this |
597 // silently. | 633 // silently. |
598 if (client_ || allow_silent_install_) { | 634 if (client_ || allow_silent_install_) { |
599 PermissionsUpdater perms_updater(profile()); | 635 PermissionsUpdater perms_updater(profile()); |
600 perms_updater.GrantActivePermissions(extension_, record_oauth2_grant_); | 636 perms_updater.GrantActivePermissions(extension_, record_oauth2_grant_); |
601 } | 637 } |
602 | 638 |
603 // Tell the frontend about the installation and hand off ownership of | 639 // Tell the frontend about the installation and hand off ownership of |
604 // extension_ to it. | 640 // extension_ to it. |
605 frontend_weak_->OnExtensionInstalled(extension_, is_gallery_install(), | 641 frontend_weak_->OnExtensionInstalled(extension_, |
606 page_ordinal_); | 642 is_gallery_install(), |
643 page_ordinal_, | |
644 requirement_errors_); | |
607 | 645 |
608 NotifyCrxInstallComplete(extension_.get()); | 646 NotifyCrxInstallComplete(extension_.get()); |
609 | 647 |
610 extension_ = NULL; | 648 extension_ = NULL; |
611 | 649 |
612 // We're done. We don't post any more tasks to ourselves so we are deleted | 650 // We're done. We don't post any more tasks to ourselves so we are deleted |
613 // soon. | 651 // soon. |
614 } | 652 } |
615 | 653 |
616 void CrxInstaller::NotifyCrxInstallComplete(const Extension* extension) { | 654 void CrxInstaller::NotifyCrxInstallComplete(const Extension* extension) { |
617 // Some users (such as the download shelf) need to know when a | 655 // Some users (such as the download shelf) need to know when a |
618 // CRXInstaller is done. Listening for the EXTENSION_* events | 656 // CRXInstaller is done. Listening for the EXTENSION_* events |
619 // is problematic because they don't know anything about the | 657 // is problematic because they don't know anything about the |
620 // extension before it is unpacked, so they cannot filter based | 658 // extension before it is unpacked, so they cannot filter based |
621 // on the extension. | 659 // on the extension. |
622 content::NotificationService::current()->Notify( | 660 content::NotificationService::current()->Notify( |
623 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 661 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
624 content::Source<CrxInstaller>(this), | 662 content::Source<CrxInstaller>(this), |
625 content::Details<const Extension>(extension)); | 663 content::Details<const Extension>(extension)); |
626 } | 664 } |
627 | 665 |
628 } // namespace extensions | 666 } // namespace extensions |
OLD | NEW |