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/extension_install_prompt.h" | 5 #include "chrome/browser/extensions/extension_install_prompt.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 id, | 486 id, |
487 error); | 487 error); |
488 } | 488 } |
489 | 489 |
490 ExtensionInstallPrompt::ExtensionInstallPrompt(content::WebContents* contents) | 490 ExtensionInstallPrompt::ExtensionInstallPrompt(content::WebContents* contents) |
491 : ui_loop_(base::MessageLoop::current()), | 491 : ui_loop_(base::MessageLoop::current()), |
492 extension_(NULL), | 492 extension_(NULL), |
493 bundle_(NULL), | 493 bundle_(NULL), |
494 install_ui_(ExtensionInstallUI::Create(ProfileForWebContents(contents))), | 494 install_ui_(ExtensionInstallUI::Create(ProfileForWebContents(contents))), |
495 show_params_(contents), | 495 show_params_(contents), |
496 delegate_(NULL), | 496 delegate_(NULL) { |
497 prompt_(UNSET_PROMPT_TYPE) {} | 497 } |
498 | 498 |
499 ExtensionInstallPrompt::ExtensionInstallPrompt( | 499 ExtensionInstallPrompt::ExtensionInstallPrompt( |
500 Profile* profile, | 500 Profile* profile, |
501 gfx::NativeWindow native_window, | 501 gfx::NativeWindow native_window, |
502 content::PageNavigator* navigator) | 502 content::PageNavigator* navigator) |
503 : ui_loop_(base::MessageLoop::current()), | 503 : ui_loop_(base::MessageLoop::current()), |
504 extension_(NULL), | 504 extension_(NULL), |
505 bundle_(NULL), | 505 bundle_(NULL), |
506 install_ui_(ExtensionInstallUI::Create(profile)), | 506 install_ui_(ExtensionInstallUI::Create(profile)), |
507 show_params_(native_window, navigator), | 507 show_params_(native_window, navigator), |
508 delegate_(NULL), | 508 delegate_(NULL) { |
509 prompt_(UNSET_PROMPT_TYPE) {} | 509 } |
510 | 510 |
511 ExtensionInstallPrompt::~ExtensionInstallPrompt() { | 511 ExtensionInstallPrompt::~ExtensionInstallPrompt() { |
512 } | 512 } |
513 | 513 |
514 void ExtensionInstallPrompt::ConfirmBundleInstall( | 514 void ExtensionInstallPrompt::ConfirmBundleInstall( |
515 extensions::BundleInstaller* bundle, | 515 extensions::BundleInstaller* bundle, |
516 const PermissionSet* permissions) { | 516 const PermissionSet* permissions) { |
517 DCHECK(ui_loop_ == base::MessageLoop::current()); | 517 DCHECK(ui_loop_ == base::MessageLoop::current()); |
518 bundle_ = bundle; | 518 bundle_ = bundle; |
519 permissions_ = permissions; | 519 permissions_ = permissions; |
520 delegate_ = bundle; | 520 delegate_ = bundle; |
521 prompt_.set_type(BUNDLE_INSTALL_PROMPT); | 521 prompt_ = new Prompt(BUNDLE_INSTALL_PROMPT); |
522 | 522 |
523 ShowConfirmation(); | 523 ShowConfirmation(); |
524 } | 524 } |
525 | 525 |
526 void ExtensionInstallPrompt::ConfirmStandaloneInstall( | 526 void ExtensionInstallPrompt::ConfirmStandaloneInstall( |
527 Delegate* delegate, | 527 Delegate* delegate, |
528 const Extension* extension, | 528 const Extension* extension, |
529 SkBitmap* icon, | 529 SkBitmap* icon, |
530 const ExtensionInstallPrompt::Prompt& prompt) { | 530 scoped_refptr<Prompt> prompt) { |
531 DCHECK(ui_loop_ == base::MessageLoop::current()); | 531 DCHECK(ui_loop_ == base::MessageLoop::current()); |
532 extension_ = extension; | 532 extension_ = extension; |
533 permissions_ = extension->permissions_data()->active_permissions(); | 533 permissions_ = extension->permissions_data()->active_permissions(); |
534 delegate_ = delegate; | 534 delegate_ = delegate; |
535 prompt_ = prompt; | 535 prompt_ = prompt; |
536 | 536 |
537 SetIcon(icon); | 537 SetIcon(icon); |
538 ShowConfirmation(); | 538 ShowConfirmation(); |
539 } | 539 } |
540 | 540 |
(...skipping 10 matching lines...) Expand all Loading... |
551 } | 551 } |
552 | 552 |
553 void ExtensionInstallPrompt::ConfirmInstall( | 553 void ExtensionInstallPrompt::ConfirmInstall( |
554 Delegate* delegate, | 554 Delegate* delegate, |
555 const Extension* extension, | 555 const Extension* extension, |
556 const ShowDialogCallback& show_dialog_callback) { | 556 const ShowDialogCallback& show_dialog_callback) { |
557 DCHECK(ui_loop_ == base::MessageLoop::current()); | 557 DCHECK(ui_loop_ == base::MessageLoop::current()); |
558 extension_ = extension; | 558 extension_ = extension; |
559 permissions_ = extension->permissions_data()->active_permissions(); | 559 permissions_ = extension->permissions_data()->active_permissions(); |
560 delegate_ = delegate; | 560 delegate_ = delegate; |
561 prompt_.set_type(INSTALL_PROMPT); | 561 prompt_ = new Prompt(INSTALL_PROMPT); |
562 show_dialog_callback_ = show_dialog_callback; | 562 show_dialog_callback_ = show_dialog_callback; |
563 | 563 |
564 // We special-case themes to not show any confirm UI. Instead they are | 564 // We special-case themes to not show any confirm UI. Instead they are |
565 // immediately installed, and then we show an infobar (see OnInstallSuccess) | 565 // immediately installed, and then we show an infobar (see OnInstallSuccess) |
566 // to allow the user to revert if they don't like it. | 566 // to allow the user to revert if they don't like it. |
567 // | 567 // |
568 // We don't do this in the case where off-store extension installs are | 568 // We don't do this in the case where off-store extension installs are |
569 // disabled because in that case, we don't show the dangerous download UI, so | 569 // disabled because in that case, we don't show the dangerous download UI, so |
570 // we need the UI confirmation. | 570 // we need the UI confirmation. |
571 if (extension->is_theme()) { | 571 if (extension->is_theme()) { |
(...skipping 12 matching lines...) Expand all Loading... |
584 DCHECK(ui_loop_ == base::MessageLoop::current()); | 584 DCHECK(ui_loop_ == base::MessageLoop::current()); |
585 extension_ = extension; | 585 extension_ = extension; |
586 permissions_ = extension->permissions_data()->active_permissions(); | 586 permissions_ = extension->permissions_data()->active_permissions(); |
587 delegate_ = delegate; | 587 delegate_ = delegate; |
588 bool is_remote_install = | 588 bool is_remote_install = |
589 install_ui_->profile() && | 589 install_ui_->profile() && |
590 extensions::ExtensionPrefs::Get(install_ui_->profile())->HasDisableReason( | 590 extensions::ExtensionPrefs::Get(install_ui_->profile())->HasDisableReason( |
591 extension->id(), extensions::Extension::DISABLE_REMOTE_INSTALL); | 591 extension->id(), extensions::Extension::DISABLE_REMOTE_INSTALL); |
592 bool is_ephemeral = | 592 bool is_ephemeral = |
593 extensions::util::IsEphemeralApp(extension->id(), install_ui_->profile()); | 593 extensions::util::IsEphemeralApp(extension->id(), install_ui_->profile()); |
| 594 |
| 595 PromptType type = UNSET_PROMPT_TYPE; |
594 if (is_ephemeral) | 596 if (is_ephemeral) |
595 prompt_.set_type(LAUNCH_PROMPT); | 597 type = LAUNCH_PROMPT; |
596 else if (is_remote_install) | 598 else if (is_remote_install) |
597 prompt_.set_type(REMOTE_INSTALL_PROMPT); | 599 type = REMOTE_INSTALL_PROMPT; |
598 else | 600 else |
599 prompt_.set_type(RE_ENABLE_PROMPT); | 601 type = RE_ENABLE_PROMPT; |
| 602 prompt_ = new Prompt(type); |
| 603 |
600 LoadImageIfNeeded(); | 604 LoadImageIfNeeded(); |
601 } | 605 } |
602 | 606 |
603 void ExtensionInstallPrompt::ConfirmExternalInstall( | 607 void ExtensionInstallPrompt::ConfirmExternalInstall( |
604 Delegate* delegate, | 608 Delegate* delegate, |
605 const Extension* extension, | 609 const Extension* extension, |
606 const ShowDialogCallback& show_dialog_callback, | 610 const ShowDialogCallback& show_dialog_callback, |
607 const Prompt& prompt) { | 611 scoped_refptr<Prompt> prompt) { |
608 DCHECK(ui_loop_ == base::MessageLoop::current()); | 612 DCHECK(ui_loop_ == base::MessageLoop::current()); |
609 extension_ = extension; | 613 extension_ = extension; |
610 permissions_ = extension->permissions_data()->active_permissions(); | 614 permissions_ = extension->permissions_data()->active_permissions(); |
611 delegate_ = delegate; | 615 delegate_ = delegate; |
612 prompt_ = prompt; | 616 prompt_ = prompt; |
613 show_dialog_callback_ = show_dialog_callback; | 617 show_dialog_callback_ = show_dialog_callback; |
614 | 618 |
615 LoadImageIfNeeded(); | 619 LoadImageIfNeeded(); |
616 } | 620 } |
617 | 621 |
618 void ExtensionInstallPrompt::ConfirmPermissions( | 622 void ExtensionInstallPrompt::ConfirmPermissions( |
619 Delegate* delegate, | 623 Delegate* delegate, |
620 const Extension* extension, | 624 const Extension* extension, |
621 const PermissionSet* permissions) { | 625 const PermissionSet* permissions) { |
622 DCHECK(ui_loop_ == base::MessageLoop::current()); | 626 DCHECK(ui_loop_ == base::MessageLoop::current()); |
623 extension_ = extension; | 627 extension_ = extension; |
624 permissions_ = permissions; | 628 permissions_ = permissions; |
625 delegate_ = delegate; | 629 delegate_ = delegate; |
626 prompt_.set_type(PERMISSIONS_PROMPT); | 630 prompt_ = new Prompt(PERMISSIONS_PROMPT); |
627 | 631 |
628 LoadImageIfNeeded(); | 632 LoadImageIfNeeded(); |
629 } | 633 } |
630 | 634 |
631 void ExtensionInstallPrompt::ReviewPermissions( | 635 void ExtensionInstallPrompt::ReviewPermissions( |
632 Delegate* delegate, | 636 Delegate* delegate, |
633 const Extension* extension, | 637 const Extension* extension, |
634 const std::vector<base::FilePath>& retained_file_paths) { | 638 const std::vector<base::FilePath>& retained_file_paths) { |
635 DCHECK(ui_loop_ == base::MessageLoop::current()); | 639 DCHECK(ui_loop_ == base::MessageLoop::current()); |
636 extension_ = extension; | 640 extension_ = extension; |
637 permissions_ = extension->permissions_data()->active_permissions(); | 641 permissions_ = extension->permissions_data()->active_permissions(); |
638 prompt_.set_retained_files(retained_file_paths); | 642 prompt_ = new Prompt(POST_INSTALL_PERMISSIONS_PROMPT); |
| 643 prompt_->set_retained_files(retained_file_paths); |
639 delegate_ = delegate; | 644 delegate_ = delegate; |
640 prompt_.set_type(POST_INSTALL_PERMISSIONS_PROMPT); | |
641 | 645 |
642 LoadImageIfNeeded(); | 646 LoadImageIfNeeded(); |
643 } | 647 } |
644 | 648 |
645 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, | 649 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, |
646 SkBitmap* icon) { | 650 SkBitmap* icon) { |
647 extension_ = extension; | 651 extension_ = extension; |
648 SetIcon(icon); | 652 SetIcon(icon); |
649 | 653 |
650 install_ui_->OnInstallSuccess(extension, &icon_); | 654 install_ui_->OnInstallSuccess(extension, &icon_); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 extensions::ImageLoader::ImageRepresentation::NEVER_RESIZE, | 700 extensions::ImageLoader::ImageRepresentation::NEVER_RESIZE, |
697 gfx::Size(), | 701 gfx::Size(), |
698 ui::SCALE_FACTOR_100P)); | 702 ui::SCALE_FACTOR_100P)); |
699 loader->LoadImagesAsync( | 703 loader->LoadImagesAsync( |
700 extension_, | 704 extension_, |
701 images_list, | 705 images_list, |
702 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); | 706 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); |
703 } | 707 } |
704 | 708 |
705 void ExtensionInstallPrompt::ShowConfirmation() { | 709 void ExtensionInstallPrompt::ShowConfirmation() { |
706 if (prompt_.type() == INSTALL_PROMPT) | 710 if (prompt_->type() == INSTALL_PROMPT) |
707 prompt_.set_experiment(ExtensionInstallPromptExperiment::Find()); | 711 prompt_->set_experiment(ExtensionInstallPromptExperiment::Find()); |
708 else | 712 else |
709 prompt_.set_experiment(ExtensionInstallPromptExperiment::ControlGroup()); | 713 prompt_->set_experiment(ExtensionInstallPromptExperiment::ControlGroup()); |
710 | 714 |
711 if (permissions_.get()) { | 715 if (permissions_.get()) { |
712 if (extension_) { | 716 if (extension_) { |
713 const extensions::PermissionsData* permissions_data = | 717 const extensions::PermissionsData* permissions_data = |
714 extension_->permissions_data(); | 718 extension_->permissions_data(); |
715 prompt_.SetPermissions(permissions_data->GetPermissionMessageStrings()); | 719 prompt_->SetPermissions(permissions_data->GetPermissionMessageStrings()); |
716 prompt_.SetPermissionsDetails( | 720 prompt_->SetPermissionsDetails( |
717 permissions_data->GetPermissionMessageDetailsStrings()); | 721 permissions_data->GetPermissionMessageDetailsStrings()); |
718 } else { | 722 } else { |
719 const extensions::PermissionMessageProvider* message_provider = | 723 const extensions::PermissionMessageProvider* message_provider = |
720 extensions::PermissionMessageProvider::Get(); | 724 extensions::PermissionMessageProvider::Get(); |
721 prompt_.SetPermissions(message_provider->GetWarningMessages( | 725 prompt_->SetPermissions(message_provider->GetWarningMessages( |
722 permissions_, Manifest::TYPE_UNKNOWN)); | 726 permissions_, Manifest::TYPE_UNKNOWN)); |
723 prompt_.SetPermissionsDetails(message_provider->GetWarningMessagesDetails( | 727 prompt_->SetPermissionsDetails( |
724 permissions_, Manifest::TYPE_UNKNOWN)); | 728 message_provider->GetWarningMessagesDetails(permissions_, |
| 729 Manifest::TYPE_UNKNOWN)); |
725 } | 730 } |
726 } | 731 } |
727 | 732 |
728 switch (prompt_.type()) { | 733 switch (prompt_->type()) { |
729 case PERMISSIONS_PROMPT: | 734 case PERMISSIONS_PROMPT: |
730 case RE_ENABLE_PROMPT: | 735 case RE_ENABLE_PROMPT: |
731 case INLINE_INSTALL_PROMPT: | 736 case INLINE_INSTALL_PROMPT: |
732 case EXTERNAL_INSTALL_PROMPT: | 737 case EXTERNAL_INSTALL_PROMPT: |
733 case INSTALL_PROMPT: | 738 case INSTALL_PROMPT: |
734 case LAUNCH_PROMPT: | 739 case LAUNCH_PROMPT: |
735 case POST_INSTALL_PERMISSIONS_PROMPT: | 740 case POST_INSTALL_PERMISSIONS_PROMPT: |
736 case REMOTE_INSTALL_PROMPT: { | 741 case REMOTE_INSTALL_PROMPT: { |
737 prompt_.set_extension(extension_); | 742 prompt_->set_extension(extension_); |
738 prompt_.set_icon(gfx::Image::CreateFrom1xBitmap(icon_)); | 743 prompt_->set_icon(gfx::Image::CreateFrom1xBitmap(icon_)); |
739 break; | 744 break; |
740 } | 745 } |
741 case BUNDLE_INSTALL_PROMPT: { | 746 case BUNDLE_INSTALL_PROMPT: { |
742 prompt_.set_bundle(bundle_); | 747 prompt_->set_bundle(bundle_); |
743 break; | 748 break; |
744 } | 749 } |
745 default: | 750 default: |
746 NOTREACHED() << "Unknown message"; | 751 NOTREACHED() << "Unknown message"; |
747 return; | 752 return; |
748 } | 753 } |
749 | 754 |
750 if (AutoConfirmPrompt(delegate_)) | 755 if (AutoConfirmPrompt(delegate_)) |
751 return; | 756 return; |
752 | 757 |
753 if (show_dialog_callback_.is_null()) | 758 if (show_dialog_callback_.is_null()) |
754 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); | 759 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); |
755 else | 760 else |
756 show_dialog_callback_.Run(show_params_, delegate_, prompt_); | 761 show_dialog_callback_.Run(show_params_, delegate_, prompt_); |
757 } | 762 } |
OLD | NEW |