| 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" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/extensions/bundle_installer.h" | 16 #include "chrome/browser/extensions/bundle_installer.h" |
| 17 #include "chrome/browser/extensions/extension_install_ui.h" | |
| 18 #include "chrome/browser/extensions/extension_util.h" | 17 #include "chrome/browser/extensions/extension_util.h" |
| 19 #include "chrome/browser/extensions/permissions_updater.h" | 18 #include "chrome/browser/extensions/permissions_updater.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h" |
| 21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/grit/chromium_strings.h" | 23 #include "chrome/grit/chromium_strings.h" |
| 24 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
| 25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "extensions/browser/extension_prefs.h" | 26 #include "extensions/browser/extension_prefs.h" |
| 27 #include "extensions/browser/extension_util.h" | 27 #include "extensions/browser/extension_util.h" |
| 28 #include "extensions/browser/image_loader.h" | 28 #include "extensions/browser/image_loader.h" |
| 29 #include "extensions/browser/install/extension_install_ui.h" |
| 29 #include "extensions/common/constants.h" | 30 #include "extensions/common/constants.h" |
| 30 #include "extensions/common/extension.h" | 31 #include "extensions/common/extension.h" |
| 31 #include "extensions/common/extension_icon_set.h" | 32 #include "extensions/common/extension_icon_set.h" |
| 32 #include "extensions/common/extension_resource.h" | 33 #include "extensions/common/extension_resource.h" |
| 33 #include "extensions/common/feature_switch.h" | 34 #include "extensions/common/feature_switch.h" |
| 34 #include "extensions/common/manifest.h" | 35 #include "extensions/common/manifest.h" |
| 35 #include "extensions/common/manifest_constants.h" | 36 #include "extensions/common/manifest_constants.h" |
| 36 #include "extensions/common/manifest_handlers/icons_handler.h" | 37 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 37 #include "extensions/common/permissions/permission_message_provider.h" | 38 #include "extensions/common/permissions/permission_message_provider.h" |
| 38 #include "extensions/common/permissions/permission_set.h" | 39 #include "extensions/common/permissions/permission_set.h" |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 return Extension::Create( | 652 return Extension::Create( |
| 652 base::FilePath(), | 653 base::FilePath(), |
| 653 Manifest::INTERNAL, | 654 Manifest::INTERNAL, |
| 654 localized_manifest.get() ? *localized_manifest.get() : *manifest, | 655 localized_manifest.get() ? *localized_manifest.get() : *manifest, |
| 655 flags, | 656 flags, |
| 656 id, | 657 id, |
| 657 error); | 658 error); |
| 658 } | 659 } |
| 659 | 660 |
| 660 ExtensionInstallPrompt::ExtensionInstallPrompt(content::WebContents* contents) | 661 ExtensionInstallPrompt::ExtensionInstallPrompt(content::WebContents* contents) |
| 661 : ui_loop_(base::MessageLoop::current()), | 662 : profile_(ProfileForWebContents(contents)), |
| 663 ui_loop_(base::MessageLoop::current()), |
| 662 extension_(NULL), | 664 extension_(NULL), |
| 663 bundle_(NULL), | 665 bundle_(NULL), |
| 664 install_ui_(ExtensionInstallUI::Create(ProfileForWebContents(contents))), | 666 install_ui_( |
| 667 extensions::CreateExtensionInstallUI( |
| 668 ProfileForWebContents(contents))), |
| 665 show_params_(contents), | 669 show_params_(contents), |
| 666 delegate_(NULL) { | 670 delegate_(NULL) { |
| 667 } | 671 } |
| 668 | 672 |
| 669 ExtensionInstallPrompt::ExtensionInstallPrompt( | 673 ExtensionInstallPrompt::ExtensionInstallPrompt( |
| 670 Profile* profile, | 674 Profile* profile, |
| 671 gfx::NativeWindow native_window, | 675 gfx::NativeWindow native_window, |
| 672 content::PageNavigator* navigator) | 676 content::PageNavigator* navigator) |
| 673 : ui_loop_(base::MessageLoop::current()), | 677 : profile_(profile), |
| 678 ui_loop_(base::MessageLoop::current()), |
| 674 extension_(NULL), | 679 extension_(NULL), |
| 675 bundle_(NULL), | 680 bundle_(NULL), |
| 676 install_ui_(ExtensionInstallUI::Create(profile)), | 681 install_ui_(extensions::CreateExtensionInstallUI(profile)), |
| 677 show_params_(native_window, navigator), | 682 show_params_(native_window, navigator), |
| 678 delegate_(NULL) { | 683 delegate_(NULL) { |
| 679 } | 684 } |
| 680 | 685 |
| 681 ExtensionInstallPrompt::~ExtensionInstallPrompt() { | 686 ExtensionInstallPrompt::~ExtensionInstallPrompt() { |
| 682 } | 687 } |
| 683 | 688 |
| 684 void ExtensionInstallPrompt::ConfirmBundleInstall( | 689 void ExtensionInstallPrompt::ConfirmBundleInstall( |
| 685 extensions::BundleInstaller* bundle, | 690 extensions::BundleInstaller* bundle, |
| 686 const PermissionSet* permissions) { | 691 const PermissionSet* permissions) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 | 751 |
| 747 LoadImageIfNeeded(); | 752 LoadImageIfNeeded(); |
| 748 } | 753 } |
| 749 | 754 |
| 750 void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate, | 755 void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate, |
| 751 const Extension* extension) { | 756 const Extension* extension) { |
| 752 DCHECK(ui_loop_ == base::MessageLoop::current()); | 757 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 753 extension_ = extension; | 758 extension_ = extension; |
| 754 delegate_ = delegate; | 759 delegate_ = delegate; |
| 755 bool is_remote_install = | 760 bool is_remote_install = |
| 756 install_ui_->profile() && | 761 profile_ && |
| 757 extensions::ExtensionPrefs::Get(install_ui_->profile())->HasDisableReason( | 762 extensions::ExtensionPrefs::Get(profile_)->HasDisableReason( |
| 758 extension->id(), extensions::Extension::DISABLE_REMOTE_INSTALL); | 763 extension->id(), extensions::Extension::DISABLE_REMOTE_INSTALL); |
| 759 bool is_ephemeral = | 764 bool is_ephemeral = |
| 760 extensions::util::IsEphemeralApp(extension->id(), install_ui_->profile()); | 765 extensions::util::IsEphemeralApp(extension->id(), profile_); |
| 761 | 766 |
| 762 PromptType type = UNSET_PROMPT_TYPE; | 767 PromptType type = UNSET_PROMPT_TYPE; |
| 763 if (is_ephemeral) | 768 if (is_ephemeral) |
| 764 type = LAUNCH_PROMPT; | 769 type = LAUNCH_PROMPT; |
| 765 else if (is_remote_install) | 770 else if (is_remote_install) |
| 766 type = REMOTE_INSTALL_PROMPT; | 771 type = REMOTE_INSTALL_PROMPT; |
| 767 else | 772 else |
| 768 type = RE_ENABLE_PROMPT; | 773 type = RE_ENABLE_PROMPT; |
| 769 prompt_ = new Prompt(type); | 774 prompt_ = new Prompt(type); |
| 770 | 775 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 } | 844 } |
| 840 } | 845 } |
| 841 | 846 |
| 842 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image) { | 847 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image) { |
| 843 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); | 848 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); |
| 844 ShowConfirmation(); | 849 ShowConfirmation(); |
| 845 } | 850 } |
| 846 | 851 |
| 847 void ExtensionInstallPrompt::LoadImageIfNeeded() { | 852 void ExtensionInstallPrompt::LoadImageIfNeeded() { |
| 848 // Bundle install prompts do not have an icon. | 853 // Bundle install prompts do not have an icon. |
| 849 // Also |install_ui_.profile()| can be NULL in unit tests. | 854 // Also |profile_| can be NULL in unit tests. |
| 850 if (!icon_.empty() || !install_ui_->profile()) { | 855 if (!icon_.empty() || !profile_) { |
| 851 ShowConfirmation(); | 856 ShowConfirmation(); |
| 852 return; | 857 return; |
| 853 } | 858 } |
| 854 | 859 |
| 855 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( | 860 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( |
| 856 extension_, | 861 extension_, |
| 857 extension_misc::EXTENSION_ICON_LARGE, | 862 extension_misc::EXTENSION_ICON_LARGE, |
| 858 ExtensionIconSet::MATCH_BIGGER); | 863 ExtensionIconSet::MATCH_BIGGER); |
| 859 | 864 |
| 860 // Load the image asynchronously. The response will be sent to OnImageLoaded. | 865 // Load the image asynchronously. The response will be sent to OnImageLoaded. |
| 861 extensions::ImageLoader* loader = | 866 extensions::ImageLoader* loader = extensions::ImageLoader::Get(profile_); |
| 862 extensions::ImageLoader::Get(install_ui_->profile()); | |
| 863 | 867 |
| 864 std::vector<extensions::ImageLoader::ImageRepresentation> images_list; | 868 std::vector<extensions::ImageLoader::ImageRepresentation> images_list; |
| 865 images_list.push_back(extensions::ImageLoader::ImageRepresentation( | 869 images_list.push_back(extensions::ImageLoader::ImageRepresentation( |
| 866 image, | 870 image, |
| 867 extensions::ImageLoader::ImageRepresentation::NEVER_RESIZE, | 871 extensions::ImageLoader::ImageRepresentation::NEVER_RESIZE, |
| 868 gfx::Size(), | 872 gfx::Size(), |
| 869 ui::SCALE_FACTOR_100P)); | 873 ui::SCALE_FACTOR_100P)); |
| 870 loader->LoadImagesAsync( | 874 loader->LoadImagesAsync( |
| 871 extension_, | 875 extension_, |
| 872 images_list, | 876 images_list, |
| 873 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); | 877 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); |
| 874 } | 878 } |
| 875 | 879 |
| 876 void ExtensionInstallPrompt::ShowConfirmation() { | 880 void ExtensionInstallPrompt::ShowConfirmation() { |
| 877 if (prompt_->type() == INSTALL_PROMPT) | 881 if (prompt_->type() == INSTALL_PROMPT) |
| 878 prompt_->set_experiment(ExtensionInstallPromptExperiment::Find()); | 882 prompt_->set_experiment(ExtensionInstallPromptExperiment::Find()); |
| 879 else | 883 else |
| 880 prompt_->set_experiment(ExtensionInstallPromptExperiment::ControlGroup()); | 884 prompt_->set_experiment(ExtensionInstallPromptExperiment::ControlGroup()); |
| 881 | 885 |
| 882 scoped_refptr<const PermissionSet> permissions_to_display; | 886 scoped_refptr<const PermissionSet> permissions_to_display; |
| 883 if (custom_permissions_.get()) { | 887 if (custom_permissions_.get()) { |
| 884 permissions_to_display = custom_permissions_; | 888 permissions_to_display = custom_permissions_; |
| 885 } else if (extension_) { | 889 } else if (extension_) { |
| 886 // Initialize permissions if they have not already been set so that | 890 // Initialize permissions if they have not already been set so that |
| 887 // withheld permissions are displayed properly in the install prompt. | 891 // withheld permissions are displayed properly in the install prompt. |
| 888 extensions::PermissionsUpdater( | 892 extensions::PermissionsUpdater( |
| 889 install_ui_->profile(), | 893 profile_, |
| 890 extensions::PermissionsUpdater::INIT_FLAG_TRANSIENT) | 894 extensions::PermissionsUpdater::INIT_FLAG_TRANSIENT) |
| 891 .InitializePermissions(extension_); | 895 .InitializePermissions(extension_); |
| 892 permissions_to_display = | 896 permissions_to_display = |
| 893 extension_->permissions_data()->active_permissions(); | 897 extension_->permissions_data()->active_permissions(); |
| 894 } | 898 } |
| 895 | 899 |
| 896 if (permissions_to_display.get() && | 900 if (permissions_to_display.get() && |
| 897 (!extension_ || | 901 (!extension_ || |
| 898 !extensions::PermissionsData::ShouldSkipPermissionWarnings( | 902 !extensions::PermissionsData::ShouldSkipPermissionWarnings( |
| 899 extension_->id()))) { | 903 extension_->id()))) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 } | 948 } |
| 945 | 949 |
| 946 if (AutoConfirmPrompt(delegate_)) | 950 if (AutoConfirmPrompt(delegate_)) |
| 947 return; | 951 return; |
| 948 | 952 |
| 949 if (show_dialog_callback_.is_null()) | 953 if (show_dialog_callback_.is_null()) |
| 950 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); | 954 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); |
| 951 else | 955 else |
| 952 show_dialog_callback_.Run(show_params_, delegate_, prompt_); | 956 show_dialog_callback_.Run(show_params_, delegate_, prompt_); |
| 953 } | 957 } |
| OLD | NEW |