| 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_(extensions::CreateExtensionInstallUI( |
| 667 ProfileForWebContents(contents))), |
| 665 show_params_(contents), | 668 show_params_(contents), |
| 666 delegate_(NULL) { | 669 delegate_(NULL) { |
| 667 } | 670 } |
| 668 | 671 |
| 669 ExtensionInstallPrompt::ExtensionInstallPrompt( | 672 ExtensionInstallPrompt::ExtensionInstallPrompt( |
| 670 Profile* profile, | 673 Profile* profile, |
| 671 gfx::NativeWindow native_window, | 674 gfx::NativeWindow native_window, |
| 672 content::PageNavigator* navigator) | 675 content::PageNavigator* navigator) |
| 673 : ui_loop_(base::MessageLoop::current()), | 676 : profile_(profile), |
| 677 ui_loop_(base::MessageLoop::current()), |
| 674 extension_(NULL), | 678 extension_(NULL), |
| 675 bundle_(NULL), | 679 bundle_(NULL), |
| 676 install_ui_(ExtensionInstallUI::Create(profile)), | 680 install_ui_(extensions::CreateExtensionInstallUI(profile)), |
| 677 show_params_(native_window, navigator), | 681 show_params_(native_window, navigator), |
| 678 delegate_(NULL) { | 682 delegate_(NULL) { |
| 679 } | 683 } |
| 680 | 684 |
| 681 ExtensionInstallPrompt::~ExtensionInstallPrompt() { | 685 ExtensionInstallPrompt::~ExtensionInstallPrompt() { |
| 682 } | 686 } |
| 683 | 687 |
| 684 void ExtensionInstallPrompt::ConfirmBundleInstall( | 688 void ExtensionInstallPrompt::ConfirmBundleInstall( |
| 685 extensions::BundleInstaller* bundle, | 689 extensions::BundleInstaller* bundle, |
| 686 const PermissionSet* permissions) { | 690 const PermissionSet* permissions) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 | 750 |
| 747 LoadImageIfNeeded(); | 751 LoadImageIfNeeded(); |
| 748 } | 752 } |
| 749 | 753 |
| 750 void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate, | 754 void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate, |
| 751 const Extension* extension) { | 755 const Extension* extension) { |
| 752 DCHECK(ui_loop_ == base::MessageLoop::current()); | 756 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 753 extension_ = extension; | 757 extension_ = extension; |
| 754 delegate_ = delegate; | 758 delegate_ = delegate; |
| 755 bool is_remote_install = | 759 bool is_remote_install = |
| 756 install_ui_->profile() && | 760 profile_ && |
| 757 extensions::ExtensionPrefs::Get(install_ui_->profile())->HasDisableReason( | 761 extensions::ExtensionPrefs::Get(profile_)->HasDisableReason( |
| 758 extension->id(), extensions::Extension::DISABLE_REMOTE_INSTALL); | 762 extension->id(), extensions::Extension::DISABLE_REMOTE_INSTALL); |
| 759 bool is_ephemeral = | 763 bool is_ephemeral = |
| 760 extensions::util::IsEphemeralApp(extension->id(), install_ui_->profile()); | 764 extensions::util::IsEphemeralApp(extension->id(), profile_); |
| 761 | 765 |
| 762 PromptType type = UNSET_PROMPT_TYPE; | 766 PromptType type = UNSET_PROMPT_TYPE; |
| 763 if (is_ephemeral) | 767 if (is_ephemeral) |
| 764 type = LAUNCH_PROMPT; | 768 type = LAUNCH_PROMPT; |
| 765 else if (is_remote_install) | 769 else if (is_remote_install) |
| 766 type = REMOTE_INSTALL_PROMPT; | 770 type = REMOTE_INSTALL_PROMPT; |
| 767 else | 771 else |
| 768 type = RE_ENABLE_PROMPT; | 772 type = RE_ENABLE_PROMPT; |
| 769 prompt_ = new Prompt(type); | 773 prompt_ = new Prompt(type); |
| 770 | 774 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 } | 843 } |
| 840 } | 844 } |
| 841 | 845 |
| 842 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image) { | 846 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image) { |
| 843 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); | 847 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); |
| 844 ShowConfirmation(); | 848 ShowConfirmation(); |
| 845 } | 849 } |
| 846 | 850 |
| 847 void ExtensionInstallPrompt::LoadImageIfNeeded() { | 851 void ExtensionInstallPrompt::LoadImageIfNeeded() { |
| 848 // Bundle install prompts do not have an icon. | 852 // Bundle install prompts do not have an icon. |
| 849 // Also |install_ui_.profile()| can be NULL in unit tests. | 853 // Also |profile_| can be NULL in unit tests. |
| 850 if (!icon_.empty() || !install_ui_->profile()) { | 854 if (!icon_.empty() || !profile_) { |
| 851 ShowConfirmation(); | 855 ShowConfirmation(); |
| 852 return; | 856 return; |
| 853 } | 857 } |
| 854 | 858 |
| 855 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( | 859 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( |
| 856 extension_, | 860 extension_, |
| 857 extension_misc::EXTENSION_ICON_LARGE, | 861 extension_misc::EXTENSION_ICON_LARGE, |
| 858 ExtensionIconSet::MATCH_BIGGER); | 862 ExtensionIconSet::MATCH_BIGGER); |
| 859 | 863 |
| 860 // Load the image asynchronously. The response will be sent to OnImageLoaded. | 864 // Load the image asynchronously. The response will be sent to OnImageLoaded. |
| 861 extensions::ImageLoader* loader = | 865 extensions::ImageLoader* loader = extensions::ImageLoader::Get(profile_); |
| 862 extensions::ImageLoader::Get(install_ui_->profile()); | |
| 863 | 866 |
| 864 std::vector<extensions::ImageLoader::ImageRepresentation> images_list; | 867 std::vector<extensions::ImageLoader::ImageRepresentation> images_list; |
| 865 images_list.push_back(extensions::ImageLoader::ImageRepresentation( | 868 images_list.push_back(extensions::ImageLoader::ImageRepresentation( |
| 866 image, | 869 image, |
| 867 extensions::ImageLoader::ImageRepresentation::NEVER_RESIZE, | 870 extensions::ImageLoader::ImageRepresentation::NEVER_RESIZE, |
| 868 gfx::Size(), | 871 gfx::Size(), |
| 869 ui::SCALE_FACTOR_100P)); | 872 ui::SCALE_FACTOR_100P)); |
| 870 loader->LoadImagesAsync( | 873 loader->LoadImagesAsync( |
| 871 extension_, | 874 extension_, |
| 872 images_list, | 875 images_list, |
| 873 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); | 876 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); |
| 874 } | 877 } |
| 875 | 878 |
| 876 void ExtensionInstallPrompt::ShowConfirmation() { | 879 void ExtensionInstallPrompt::ShowConfirmation() { |
| 877 if (prompt_->type() == INSTALL_PROMPT) | 880 if (prompt_->type() == INSTALL_PROMPT) |
| 878 prompt_->set_experiment(ExtensionInstallPromptExperiment::Find()); | 881 prompt_->set_experiment(ExtensionInstallPromptExperiment::Find()); |
| 879 else | 882 else |
| 880 prompt_->set_experiment(ExtensionInstallPromptExperiment::ControlGroup()); | 883 prompt_->set_experiment(ExtensionInstallPromptExperiment::ControlGroup()); |
| 881 | 884 |
| 882 scoped_refptr<const PermissionSet> permissions_to_display; | 885 scoped_refptr<const PermissionSet> permissions_to_display; |
| 883 if (custom_permissions_.get()) { | 886 if (custom_permissions_.get()) { |
| 884 permissions_to_display = custom_permissions_; | 887 permissions_to_display = custom_permissions_; |
| 885 } else if (extension_) { | 888 } else if (extension_) { |
| 886 // Initialize permissions if they have not already been set so that | 889 // Initialize permissions if they have not already been set so that |
| 887 // withheld permissions are displayed properly in the install prompt. | 890 // withheld permissions are displayed properly in the install prompt. |
| 888 extensions::PermissionsUpdater( | 891 extensions::PermissionsUpdater( |
| 889 install_ui_->profile(), | 892 profile_, extensions::PermissionsUpdater::INIT_FLAG_TRANSIENT) |
| 890 extensions::PermissionsUpdater::INIT_FLAG_TRANSIENT) | |
| 891 .InitializePermissions(extension_); | 893 .InitializePermissions(extension_); |
| 892 permissions_to_display = | 894 permissions_to_display = |
| 893 extension_->permissions_data()->active_permissions(); | 895 extension_->permissions_data()->active_permissions(); |
| 894 } | 896 } |
| 895 | 897 |
| 896 if (permissions_to_display.get() && | 898 if (permissions_to_display.get() && |
| 897 (!extension_ || | 899 (!extension_ || |
| 898 !extensions::PermissionsData::ShouldSkipPermissionWarnings( | 900 !extensions::PermissionsData::ShouldSkipPermissionWarnings( |
| 899 extension_->id()))) { | 901 extension_->id()))) { |
| 900 Manifest::Type type = | 902 Manifest::Type type = |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 } | 946 } |
| 945 | 947 |
| 946 if (AutoConfirmPrompt(delegate_)) | 948 if (AutoConfirmPrompt(delegate_)) |
| 947 return; | 949 return; |
| 948 | 950 |
| 949 if (show_dialog_callback_.is_null()) | 951 if (show_dialog_callback_.is_null()) |
| 950 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); | 952 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); |
| 951 else | 953 else |
| 952 show_dialog_callback_.Run(show_params_, delegate_, prompt_); | 954 show_dialog_callback_.Run(show_params_, delegate_, prompt_); |
| 953 } | 955 } |
| OLD | NEW |