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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, | 112 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
113 IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO, | 113 IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO, |
114 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, | 114 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, |
115 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, | 115 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, |
116 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, | 116 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
117 IDS_EXTENSION_PROMPT_CAN_ACCESS, | 117 IDS_EXTENSION_PROMPT_CAN_ACCESS, |
118 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, | 118 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
119 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, | 119 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
120 }; | 120 }; |
121 | 121 |
122 // Size of extension icon in top left of dialog. | |
123 const int kIconSize = 69; | |
124 | |
125 // Returns pixel size under maximal scale factor for the icon whose device | |
126 // independent size is |size_in_dip| | |
127 int GetSizeForMaxScaleFactor(int size_in_dip) { | |
128 return static_cast<int>(size_in_dip * gfx::ImageSkia::GetMaxSupportedScale()); | |
129 } | |
130 | |
131 // Returns bitmap for the default icon with size equal to the default icon's | 122 // Returns bitmap for the default icon with size equal to the default icon's |
132 // pixel size under maximal supported scale factor. | 123 // pixel size under maximal supported scale factor. |
133 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) { | 124 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) { |
134 const gfx::ImageSkia& image = is_app ? | 125 const gfx::ImageSkia& image = is_app ? |
135 extensions::util::GetDefaultAppIcon() : | 126 extensions::util::GetDefaultAppIcon() : |
136 extensions::util::GetDefaultExtensionIcon(); | 127 extensions::util::GetDefaultExtensionIcon(); |
137 return image.GetRepresentation( | 128 return image.GetRepresentation( |
138 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); | 129 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); |
139 } | 130 } |
140 | 131 |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
683 } | 674 } |
684 | 675 |
685 void ExtensionInstallPrompt::LoadImageIfNeeded() { | 676 void ExtensionInstallPrompt::LoadImageIfNeeded() { |
686 // Bundle install prompts do not have an icon. | 677 // Bundle install prompts do not have an icon. |
687 // Also |install_ui_.profile()| can be NULL in unit tests. | 678 // Also |install_ui_.profile()| can be NULL in unit tests. |
688 if (!icon_.empty() || !install_ui_->profile()) { | 679 if (!icon_.empty() || !install_ui_->profile()) { |
689 ShowConfirmation(); | 680 ShowConfirmation(); |
690 return; | 681 return; |
691 } | 682 } |
692 | 683 |
693 // Load the image asynchronously. For the response, check OnImageLoaded. | |
694 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( | 684 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( |
695 extension_, | 685 extension_, |
696 extension_misc::EXTENSION_ICON_LARGE, | 686 extension_misc::EXTENSION_ICON_LARGE, |
697 ExtensionIconSet::MATCH_BIGGER); | 687 ExtensionIconSet::MATCH_BIGGER); |
698 // Load the icon whose pixel size is large enough to be displayed under | 688 |
699 // maximal supported scale factor. UI code will scale the icon down if needed. | 689 // Load the image asynchronously. The response will be sent to OnImageLoaded. |
700 // TODO(tbarzic): We should use IconImage here and load the required bitmap | 690 extensions::ImageLoader* loader = |
701 // lazily. | 691 extensions::ImageLoader::Get(install_ui_->profile()); |
702 int pixel_size = GetSizeForMaxScaleFactor(kIconSize); | 692 |
703 extensions::ImageLoader::Get(install_ui_->profile())->LoadImageAsync( | 693 std::vector<extensions::ImageLoader::ImageRepresentation> images_list; |
704 extension_, image, gfx::Size(pixel_size, pixel_size), | 694 images_list.push_back(extensions::ImageLoader::ImageRepresentation( |
695 image, | |
696 extensions::ImageLoader::ImageRepresentation::NEVER_RESIZE, | |
benwells
2014/06/02 06:07:02
Sorry if you've already been asked these questions
sashab
2014/06/03 01:17:32
If there is no appropriate image, OnImageLoaded()
| |
697 gfx::Size(), | |
698 ui::SCALE_FACTOR_100P)); | |
benwells
2014/06/02 06:07:02
What does this scale factor mean exactly? In parti
sashab
2014/06/03 01:17:32
If you look at ImageLoader::LoadImageAsync() (the
| |
699 loader->LoadImagesAsync( | |
700 extension_, | |
701 images_list, | |
705 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); | 702 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); |
706 } | 703 } |
707 | 704 |
708 void ExtensionInstallPrompt::ShowConfirmation() { | 705 void ExtensionInstallPrompt::ShowConfirmation() { |
709 if (prompt_.type() == INSTALL_PROMPT) | 706 if (prompt_.type() == INSTALL_PROMPT) |
710 prompt_.set_experiment(ExtensionInstallPromptExperiment::Find()); | 707 prompt_.set_experiment(ExtensionInstallPromptExperiment::Find()); |
711 else | 708 else |
712 prompt_.set_experiment(ExtensionInstallPromptExperiment::ControlGroup()); | 709 prompt_.set_experiment(ExtensionInstallPromptExperiment::ControlGroup()); |
713 | 710 |
714 if (permissions_.get() && | 711 if (permissions_.get() && |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
748 } | 745 } |
749 | 746 |
750 if (AutoConfirmPrompt(delegate_)) | 747 if (AutoConfirmPrompt(delegate_)) |
751 return; | 748 return; |
752 | 749 |
753 if (show_dialog_callback_.is_null()) | 750 if (show_dialog_callback_.is_null()) |
754 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); | 751 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); |
755 else | 752 else |
756 show_dialog_callback_.Run(show_params_, delegate_, prompt_); | 753 show_dialog_callback_.Run(show_params_, delegate_, prompt_); |
757 } | 754 } |
OLD | NEW |