Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: chrome/browser/extensions/extension_install_prompt.cc

Issue 1349613003: [Extensions] Un-refcount PermissionSet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/location.h" 7 #include "base/location.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 new ExtensionInstallPromptShowParams(profile, native_window)), 616 new ExtensionInstallPromptShowParams(profile, native_window)),
617 delegate_(NULL) { 617 delegate_(NULL) {
618 } 618 }
619 619
620 ExtensionInstallPrompt::~ExtensionInstallPrompt() { 620 ExtensionInstallPrompt::~ExtensionInstallPrompt() {
621 } 621 }
622 622
623 void ExtensionInstallPrompt::ConfirmBundleInstall( 623 void ExtensionInstallPrompt::ConfirmBundleInstall(
624 extensions::BundleInstaller* bundle, 624 extensions::BundleInstaller* bundle,
625 const SkBitmap* icon, 625 const SkBitmap* icon,
626 const PermissionSet* permissions) { 626 scoped_ptr<const PermissionSet> permissions) {
627 DCHECK(ui_loop_ == base::MessageLoop::current()); 627 DCHECK(ui_loop_ == base::MessageLoop::current());
628 bundle_ = bundle; 628 bundle_ = bundle;
629 custom_permissions_ = permissions; 629 custom_permissions_ = permissions.Pass();
630 delegate_ = bundle; 630 delegate_ = bundle;
631 prompt_ = new Prompt(BUNDLE_INSTALL_PROMPT); 631 prompt_ = new Prompt(BUNDLE_INSTALL_PROMPT);
632 632
633 SetIcon(icon); 633 SetIcon(icon);
634 ShowConfirmation(); 634 ShowConfirmation();
635 } 635 }
636 636
637 void ExtensionInstallPrompt::ConfirmPermissionsForDelegatedBundleInstall( 637 void ExtensionInstallPrompt::ConfirmPermissionsForDelegatedBundleInstall(
638 extensions::BundleInstaller* bundle, 638 extensions::BundleInstaller* bundle,
639 const std::string& delegated_username, 639 const std::string& delegated_username,
640 const SkBitmap* icon, 640 const SkBitmap* icon,
641 const extensions::PermissionSet* permissions) { 641 scoped_ptr<const extensions::PermissionSet> permissions) {
642 DCHECK(ui_loop_ == base::MessageLoop::current()); 642 DCHECK(ui_loop_ == base::MessageLoop::current());
643 bundle_ = bundle; 643 bundle_ = bundle;
644 delegated_username_ = delegated_username; 644 delegated_username_ = delegated_username;
645 custom_permissions_ = permissions; 645 custom_permissions_ = permissions.Pass();
646 delegate_ = bundle; 646 delegate_ = bundle;
647 prompt_ = new Prompt(DELEGATED_BUNDLE_PERMISSIONS_PROMPT); 647 prompt_ = new Prompt(DELEGATED_BUNDLE_PERMISSIONS_PROMPT);
648 648
649 SetIcon(icon); 649 SetIcon(icon);
650 ShowConfirmation(); 650 ShowConfirmation();
651 } 651 }
652 652
653 void ExtensionInstallPrompt::ConfirmStandaloneInstall( 653 void ExtensionInstallPrompt::ConfirmStandaloneInstall(
654 Delegate* delegate, 654 Delegate* delegate,
655 const Extension* extension, 655 const Extension* extension,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 delegate_ = delegate; 752 delegate_ = delegate;
753 prompt_ = prompt; 753 prompt_ = prompt;
754 show_dialog_callback_ = show_dialog_callback; 754 show_dialog_callback_ = show_dialog_callback;
755 755
756 LoadImageIfNeeded(); 756 LoadImageIfNeeded();
757 } 757 }
758 758
759 void ExtensionInstallPrompt::ConfirmPermissions( 759 void ExtensionInstallPrompt::ConfirmPermissions(
760 Delegate* delegate, 760 Delegate* delegate,
761 const Extension* extension, 761 const Extension* extension,
762 const PermissionSet* permissions) { 762 scoped_ptr<const PermissionSet> permissions) {
763 DCHECK(ui_loop_ == base::MessageLoop::current()); 763 DCHECK(ui_loop_ == base::MessageLoop::current());
764 extension_ = extension; 764 extension_ = extension;
765 custom_permissions_ = permissions; 765 custom_permissions_ = permissions.Pass();
766 delegate_ = delegate; 766 delegate_ = delegate;
767 prompt_ = new Prompt(PERMISSIONS_PROMPT); 767 prompt_ = new Prompt(PERMISSIONS_PROMPT);
768 768
769 LoadImageIfNeeded(); 769 LoadImageIfNeeded();
770 } 770 }
771 771
772 void ExtensionInstallPrompt::ReviewPermissions( 772 void ExtensionInstallPrompt::ReviewPermissions(
773 Delegate* delegate, 773 Delegate* delegate,
774 const Extension* extension, 774 const Extension* extension,
775 const std::vector<base::FilePath>& retained_file_paths, 775 const std::vector<base::FilePath>& retained_file_paths,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 extensions::ImageLoader::ImageRepresentation::NEVER_RESIZE, 838 extensions::ImageLoader::ImageRepresentation::NEVER_RESIZE,
839 gfx::Size(), 839 gfx::Size(),
840 ui::SCALE_FACTOR_100P)); 840 ui::SCALE_FACTOR_100P));
841 loader->LoadImagesAsync( 841 loader->LoadImagesAsync(
842 extension_, 842 extension_,
843 images_list, 843 images_list,
844 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); 844 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr()));
845 } 845 }
846 846
847 void ExtensionInstallPrompt::ShowConfirmation() { 847 void ExtensionInstallPrompt::ShowConfirmation() {
848 scoped_refptr<const PermissionSet> permissions_to_display; 848 scoped_ptr<const PermissionSet> permissions_wrapper;
849 const PermissionSet* permissions_to_display = nullptr;
849 if (custom_permissions_.get()) { 850 if (custom_permissions_.get()) {
850 permissions_to_display = custom_permissions_; 851 permissions_to_display = custom_permissions_.get();
851 } else if (extension_) { 852 } else if (extension_) {
852 // Initialize permissions if they have not already been set so that 853 // Initialize permissions if they have not already been set so that
853 // withheld permissions are displayed properly in the install prompt. 854 // withheld permissions are displayed properly in the install prompt.
854 extensions::PermissionsUpdater( 855 extensions::PermissionsUpdater(
855 profile_, extensions::PermissionsUpdater::INIT_FLAG_TRANSIENT) 856 profile_, extensions::PermissionsUpdater::INIT_FLAG_TRANSIENT)
856 .InitializePermissions(extension_); 857 .InitializePermissions(extension_);
857 permissions_to_display = 858 permissions_to_display =
858 extension_->permissions_data()->active_permissions(); 859 extension_->permissions_data()->active_permissions();
859 // For delegated installs, all optional permissions are pre-approved by the 860 // For delegated installs, all optional permissions are pre-approved by the
860 // person who triggers the install, so add them to the list. 861 // person who triggers the install, so add them to the list.
861 if (prompt_->type() == DELEGATED_PERMISSIONS_PROMPT || 862 if (prompt_->type() == DELEGATED_PERMISSIONS_PROMPT ||
862 prompt_->type() == DELEGATED_BUNDLE_PERMISSIONS_PROMPT) { 863 prompt_->type() == DELEGATED_BUNDLE_PERMISSIONS_PROMPT) {
863 scoped_refptr<const PermissionSet> optional_permissions = 864 const PermissionSet* optional_permissions =
864 extensions::PermissionsParser::GetOptionalPermissions(extension_); 865 extensions::PermissionsParser::GetOptionalPermissions(extension_);
865 permissions_to_display = PermissionSet::CreateUnion( 866 permissions_wrapper = PermissionSet::CreateUnion(*permissions_to_display,
866 *permissions_to_display, *optional_permissions); 867 *optional_permissions);
868 permissions_to_display = permissions_wrapper.get();
867 } 869 }
868 } 870 }
869 871
870 if (permissions_to_display.get() && 872 if (permissions_to_display &&
871 (!extension_ || 873 (!extension_ ||
872 !extensions::PermissionsData::ShouldSkipPermissionWarnings( 874 !extensions::PermissionsData::ShouldSkipPermissionWarnings(
873 extension_->id()))) { 875 extension_->id()))) {
874 Manifest::Type type = 876 Manifest::Type type =
875 extension_ ? extension_->GetType() : Manifest::TYPE_UNKNOWN; 877 extension_ ? extension_->GetType() : Manifest::TYPE_UNKNOWN;
876 const extensions::PermissionMessageProvider* message_provider = 878 const extensions::PermissionMessageProvider* message_provider =
877 extensions::PermissionMessageProvider::Get(); 879 extensions::PermissionMessageProvider::Get();
878 880
879 prompt_->SetPermissions(message_provider->GetPermissionMessages( 881 prompt_->SetPermissions(message_provider->GetPermissionMessages(
880 message_provider->GetAllPermissionIDs( 882 message_provider->GetAllPermissionIDs(
881 permissions_to_display.get(), type)), 883 permissions_to_display, type)),
882 REGULAR_PERMISSIONS); 884 REGULAR_PERMISSIONS);
883 885
884 scoped_refptr<const extensions::PermissionSet> withheld = 886 const PermissionSet* withheld =
885 extension_ ? extension_->permissions_data()->withheld_permissions() 887 extension_ ? extension_->permissions_data()->withheld_permissions()
886 : nullptr; 888 : nullptr;
887 if (withheld && !withheld->IsEmpty()) { 889 if (withheld && !withheld->IsEmpty()) {
888 prompt_->SetPermissions( 890 prompt_->SetPermissions(
889 message_provider->GetPermissionMessages( 891 message_provider->GetPermissionMessages(
890 message_provider->GetAllPermissionIDs(withheld.get(), type)), 892 message_provider->GetAllPermissionIDs(withheld, type)),
891 WITHHELD_PERMISSIONS); 893 WITHHELD_PERMISSIONS);
892 } 894 }
893 } 895 }
894 896
895 switch (prompt_->type()) { 897 switch (prompt_->type()) {
896 case PERMISSIONS_PROMPT: 898 case PERMISSIONS_PROMPT:
897 case RE_ENABLE_PROMPT: 899 case RE_ENABLE_PROMPT:
898 case INLINE_INSTALL_PROMPT: 900 case INLINE_INSTALL_PROMPT:
899 case EXTERNAL_INSTALL_PROMPT: 901 case EXTERNAL_INSTALL_PROMPT:
900 case INSTALL_PROMPT: 902 case INSTALL_PROMPT:
(...skipping 25 matching lines...) Expand all
926 if (show_params_->WasParentDestroyed()) { 928 if (show_params_->WasParentDestroyed()) {
927 delegate_->InstallUIAbort(false); 929 delegate_->InstallUIAbort(false);
928 return; 930 return;
929 } 931 }
930 932
931 if (show_dialog_callback_.is_null()) 933 if (show_dialog_callback_.is_null())
932 GetDefaultShowDialogCallback().Run(show_params_.get(), delegate_, prompt_); 934 GetDefaultShowDialogCallback().Run(show_params_.get(), delegate_, prompt_);
933 else 935 else
934 show_dialog_callback_.Run(show_params_.get(), delegate_, prompt_); 936 show_dialog_callback_.Run(show_params_.get(), delegate_, prompt_);
935 } 937 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_install_prompt.h ('k') | chrome/browser/extensions/extension_install_prompt_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698