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(&CrxInstaller::RunRequirementsChecker, this)); | |
393 } | |
394 | |
395 void CrxInstaller::RunRequirementsChecker() { | |
396 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
397 requirements_checker_->Check(extension_, | |
398 base::Bind(&CrxInstaller::RequirementsChecked, | |
Aaron Boodman
2012/08/01 03:58:54
Why run this on the file thread? It seems like thi
eaugusti
2012/08/03 01:06:26
Done.
| |
399 this), | |
400 BrowserThread::FILE); | |
401 } | |
402 | |
403 void CrxInstaller::RequirementsChecked(std::vector<std::string> errors) { | |
404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
405 | |
406 if (!errors.empty()) { | |
407 if (error_on_unsported_requirements_) { | |
408 ReportFailureFromFileThread(CrxInstallerError( | |
409 UTF8ToUTF16(JoinString(errors, ' ')))); | |
410 return; | |
411 } | |
412 requirement_errors_.swap(errors); | |
413 } | |
414 | |
387 if (!BrowserThread::PostTask( | 415 if (!BrowserThread::PostTask( |
388 BrowserThread::UI, FROM_HERE, | 416 BrowserThread::UI, FROM_HERE, |
389 base::Bind(&CrxInstaller::ConfirmInstall, this))) | 417 base::Bind(&CrxInstaller::ConfirmInstall, this))) |
390 NOTREACHED(); | 418 NOTREACHED(); |
391 } | 419 } |
392 | 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; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
513 // TODO(rdevlin.cronin): Continue removing std::string errors and replacing | 541 // TODO(rdevlin.cronin): Continue removing std::string errors and replacing |
514 // with string16 | 542 // with string16 |
515 std::string error; | 543 std::string error; |
516 extension_ = extension_file_util::LoadExtension( | 544 extension_ = extension_file_util::LoadExtension( |
517 version_dir, | 545 version_dir, |
518 install_source_, | 546 install_source_, |
519 extension_->creation_flags() | Extension::REQUIRE_KEY, | 547 extension_->creation_flags() | Extension::REQUIRE_KEY, |
520 &error); | 548 &error); |
521 CHECK(error.empty()) << error; | 549 CHECK(error.empty()) << error; |
522 | 550 |
551 if (!requirement_errors_.empty()) { | |
552 extensions::Extension::InstallWarningVector install_warnings; | |
553 std::vector<std::string>::iterator it; | |
Aaron Boodman
2012/08/01 03:58:54
Since you don't need |it| outside the for loop def
eaugusti
2012/08/03 01:06:26
Done.
| |
554 for (it = requirement_errors_.begin(); it != requirement_errors_.end(); | |
555 ++it) { | |
556 install_warnings.push_back(Extension::InstallWarning( | |
557 Extension::InstallWarning::FORMAT_TEXT, *it)); | |
558 } | |
559 const_cast<Extension*>(extension_.get())->AddInstallWarnings( | |
Aaron Boodman
2012/08/01 03:58:54
You can avoid this const_cast by de-consting exten
Aaron Boodman
2012/08/01 04:03:57
s/modified/accessed/
eaugusti
2012/08/03 01:06:26
Done.
| |
560 install_warnings); | |
561 } | |
562 | |
523 ReportSuccessFromFileThread(); | 563 ReportSuccessFromFileThread(); |
524 } | 564 } |
525 | 565 |
526 void CrxInstaller::ReportFailureFromFileThread(const CrxInstallerError& error) { | 566 void CrxInstaller::ReportFailureFromFileThread(const CrxInstallerError& error) { |
527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 567 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
528 if (!BrowserThread::PostTask( | 568 if (!BrowserThread::PostTask( |
529 BrowserThread::UI, FROM_HERE, | 569 BrowserThread::UI, FROM_HERE, |
530 base::Bind(&CrxInstaller::ReportFailureFromUIThread, this, error))) { | 570 base::Bind(&CrxInstaller::ReportFailureFromUIThread, this, error))) { |
531 NOTREACHED(); | 571 NOTREACHED(); |
532 } | 572 } |
(...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 | 635 // 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 | 636 // the install (client_ is non NULL), or we are allowed to install this |
597 // silently. | 637 // silently. |
598 if (client_ || allow_silent_install_) { | 638 if (client_ || allow_silent_install_) { |
599 PermissionsUpdater perms_updater(profile()); | 639 PermissionsUpdater perms_updater(profile()); |
600 perms_updater.GrantActivePermissions(extension_, record_oauth2_grant_); | 640 perms_updater.GrantActivePermissions(extension_, record_oauth2_grant_); |
601 } | 641 } |
602 | 642 |
603 // Tell the frontend about the installation and hand off ownership of | 643 // Tell the frontend about the installation and hand off ownership of |
604 // extension_ to it. | 644 // extension_ to it. |
605 frontend_weak_->OnExtensionInstalled(extension_, is_gallery_install(), | 645 frontend_weak_->OnExtensionInstalled(extension_, |
606 page_ordinal_); | 646 is_gallery_install(), |
647 page_ordinal_, | |
648 requirement_errors_); | |
607 | 649 |
608 NotifyCrxInstallComplete(extension_.get()); | 650 NotifyCrxInstallComplete(extension_.get()); |
609 | 651 |
610 extension_ = NULL; | 652 extension_ = NULL; |
611 | 653 |
612 // We're done. We don't post any more tasks to ourselves so we are deleted | 654 // We're done. We don't post any more tasks to ourselves so we are deleted |
613 // soon. | 655 // soon. |
614 } | 656 } |
615 | 657 |
616 void CrxInstaller::NotifyCrxInstallComplete(const Extension* extension) { | 658 void CrxInstaller::NotifyCrxInstallComplete(const Extension* extension) { |
617 // Some users (such as the download shelf) need to know when a | 659 // Some users (such as the download shelf) need to know when a |
618 // CRXInstaller is done. Listening for the EXTENSION_* events | 660 // CRXInstaller is done. Listening for the EXTENSION_* events |
619 // is problematic because they don't know anything about the | 661 // is problematic because they don't know anything about the |
620 // extension before it is unpacked, so they cannot filter based | 662 // extension before it is unpacked, so they cannot filter based |
621 // on the extension. | 663 // on the extension. |
622 content::NotificationService::current()->Notify( | 664 content::NotificationService::current()->Notify( |
623 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 665 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
624 content::Source<CrxInstaller>(this), | 666 content::Source<CrxInstaller>(this), |
625 content::Details<const Extension>(extension)); | 667 content::Details<const Extension>(extension)); |
626 } | 668 } |
627 | 669 |
628 } // namespace extensions | 670 } // namespace extensions |
OLD | NEW |