[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/extensions/extension_install_prompt.h" |
| 6 | |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 9 | #include "base/callback_helpers.h" |
skyostil | f221b7de | 2015-06-11 20:36:32 | [diff] [blame] | 10 | #include "base/location.h" |
fdoray | 283082bd | 2016-06-02 20:18:46 | [diff] [blame] | 11 | #include "base/single_thread_task_runner.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 12 | #include "base/strings/string_number_conversions.h" |
[email protected] | 00e7bef | 2013-06-10 20:35:17 | [diff] [blame] | 13 | #include "base/strings/string_util.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 14 | #include "base/strings/utf_string_conversions.h" |
gab | b15e1907 | 2016-05-11 20:45:41 | [diff] [blame] | 15 | #include "base/threading/thread_task_runner_handle.h" |
pkotwicz | 2f18178 | 2014-10-29 17:33:45 | [diff] [blame] | 16 | #include "chrome/browser/extensions/extension_install_prompt_show_params.h" |
[email protected] | 7eb20e3 | 2014-04-30 08:50:56 | [diff] [blame] | 17 | #include "chrome/browser/extensions/extension_util.h" |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 18 | #include "chrome/browser/extensions/permissions_updater.h" |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 19 | #include "chrome/browser/profiles/profile.h" |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 20 | #include "chrome/browser/ui/extensions/extension_install_ui_factory.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 21 | #include "chrome/grit/generated_resources.h" |
thestig | 4a2e88e | 2016-08-27 23:23:51 | [diff] [blame] | 22 | #include "chrome/grit/theme_resources.h" |
| 23 | #include "components/strings/grit/components_strings.h" |
[email protected] | 91e51d61 | 2012-10-21 23:03:05 | [diff] [blame] | 24 | #include "content/public/browser/web_contents.h" |
Devlin Cronin | bffe949eb | 2018-01-12 03:03:40 | [diff] [blame] | 25 | #include "extensions/browser/disable_reason.h" |
rdevlin.cronin | 6620949 | 2015-06-10 20:44:05 | [diff] [blame] | 26 | #include "extensions/browser/extension_dialog_auto_confirm.h" |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 27 | #include "extensions/browser/extension_prefs.h" |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 28 | #include "extensions/browser/extension_util.h" |
[email protected] | 326e6f0 | 2014-06-20 04:53:37 | [diff] [blame] | 29 | #include "extensions/browser/image_loader.h" |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 30 | #include "extensions/browser/install/extension_install_ui.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 31 | #include "extensions/common/extension.h" |
[email protected] | 4b790884 | 2014-04-07 23:50:22 | [diff] [blame] | 32 | #include "extensions/common/extension_icon_set.h" |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 33 | #include "extensions/common/extension_resource.h" |
[email protected] | 5ef835a | 2013-11-08 20:42:57 | [diff] [blame] | 34 | #include "extensions/common/feature_switch.h" |
[email protected] | d42c1115 | 2013-08-22 19:36:32 | [diff] [blame] | 35 | #include "extensions/common/manifest.h" |
[email protected] | 6bf9061 | 2013-08-15 00:36:27 | [diff] [blame] | 36 | #include "extensions/common/manifest_constants.h" |
[email protected] | 0db486f | 2014-04-09 19:32:22 | [diff] [blame] | 37 | #include "extensions/common/manifest_handlers/icons_handler.h" |
treib | 7496f63c | 2015-03-04 12:18:53 | [diff] [blame] | 38 | #include "extensions/common/manifest_handlers/permissions_parser.h" |
treib | f9dce31 | 2015-08-27 17:33:35 | [diff] [blame] | 39 | #include "extensions/common/permissions/permission_message_provider.h" |
[email protected] | 5a55f3f | 2013-10-29 01:08:29 | [diff] [blame] | 40 | #include "extensions/common/permissions/permission_set.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 41 | #include "extensions/common/permissions/permissions_data.h" |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 42 | #include "ui/base/l10n/l10n_util.h" |
| 43 | #include "ui/base/resource/resource_bundle.h" |
pkotwicz | 7fd0119 | 2014-10-09 04:43:50 | [diff] [blame] | 44 | #include "ui/base/ui_base_types.h" |
rdevlin.cronin | 3fe4bd3 | 2016-01-12 18:45:40 | [diff] [blame] | 45 | #include "ui/gfx/image/image_skia.h" |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 46 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 47 | using extensions::Extension; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 48 | using extensions::Manifest; |
treib | f9dce31 | 2015-08-27 17:33:35 | [diff] [blame] | 49 | using extensions::PermissionMessage; |
| 50 | using extensions::PermissionMessages; |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 51 | using extensions::PermissionSet; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 52 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 53 | namespace { |
| 54 | |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 55 | bool AllowWebstoreData(ExtensionInstallPrompt::PromptType type) { |
| 56 | return type == ExtensionInstallPrompt::INLINE_INSTALL_PROMPT || |
| 57 | type == ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT || |
| 58 | type == ExtensionInstallPrompt::REPAIR_PROMPT; |
| 59 | } |
| 60 | |
[email protected] | dd46a4ce | 2012-09-15 10:50:50 | [diff] [blame] | 61 | // Returns bitmap for the default icon with size equal to the default icon's |
| 62 | // pixel size under maximal supported scale factor. |
| 63 | SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) { |
[email protected] | 702d8b4 | 2013-02-27 20:55:50 | [diff] [blame] | 64 | const gfx::ImageSkia& image = is_app ? |
[email protected] | 7eb20e3 | 2014-04-30 08:50:56 | [diff] [blame] | 65 | extensions::util::GetDefaultAppIcon() : |
| 66 | extensions::util::GetDefaultExtensionIcon(); |
[email protected] | 50b6626 | 2013-09-24 03:25:48 | [diff] [blame] | 67 | return image.GetRepresentation( |
| 68 | gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); |
[email protected] | dd46a4ce | 2012-09-15 10:50:50 | [diff] [blame] | 69 | } |
| 70 | |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 71 | // If auto confirm is enabled then posts a task to proceed with or cancel the |
| 72 | // install and returns true. Otherwise returns false. |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 73 | bool AutoConfirmPrompt(ExtensionInstallPrompt::DoneCallback* callback) { |
rdevlin.cronin | 6620949 | 2015-06-10 20:44:05 | [diff] [blame] | 74 | switch (extensions::ScopedTestDialogAutoConfirm::GetAutoConfirmValue()) { |
| 75 | case extensions::ScopedTestDialogAutoConfirm::NONE: |
[email protected] | 2a74d6f6 | 2014-07-24 11:53:47 | [diff] [blame] | 76 | return false; |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 77 | // We use PostTask instead of calling the callback directly here, because in |
[email protected] | 2a74d6f6 | 2014-07-24 11:53:47 | [diff] [blame] | 78 | // the real implementations it's highly likely the message loop will be |
| 79 | // pumping a few times before the user clicks accept or cancel. |
rdevlin.cronin | 6620949 | 2015-06-10 20:44:05 | [diff] [blame] | 80 | case extensions::ScopedTestDialogAutoConfirm::ACCEPT: |
catmullings | ff559d9 | 2017-05-20 01:43:36 | [diff] [blame] | 81 | case extensions::ScopedTestDialogAutoConfirm::ACCEPT_AND_OPTION: |
fdoray | 283082bd | 2016-06-02 20:18:46 | [diff] [blame] | 82 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
tzik | 8d880ee | 2017-04-20 19:46:24 | [diff] [blame] | 83 | FROM_HERE, base::BindOnce(base::ResetAndReturn(callback), |
| 84 | ExtensionInstallPrompt::Result::ACCEPTED)); |
[email protected] | 2a74d6f6 | 2014-07-24 11:53:47 | [diff] [blame] | 85 | return true; |
rdevlin.cronin | 6620949 | 2015-06-10 20:44:05 | [diff] [blame] | 86 | case extensions::ScopedTestDialogAutoConfirm::CANCEL: |
skyostil | f221b7de | 2015-06-11 20:36:32 | [diff] [blame] | 87 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
tzik | 8d880ee | 2017-04-20 19:46:24 | [diff] [blame] | 88 | FROM_HERE, |
| 89 | base::BindOnce(base::ResetAndReturn(callback), |
| 90 | ExtensionInstallPrompt::Result::USER_CANCELED)); |
[email protected] | 2a74d6f6 | 2014-07-24 11:53:47 | [diff] [blame] | 91 | return true; |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | NOTREACHED(); |
| 95 | return false; |
| 96 | } |
| 97 | |
[email protected] | 91e51d61 | 2012-10-21 23:03:05 | [diff] [blame] | 98 | Profile* ProfileForWebContents(content::WebContents* web_contents) { |
| 99 | if (!web_contents) |
| 100 | return NULL; |
| 101 | return Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 102 | } |
| 103 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 104 | } // namespace |
| 105 | |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 106 | ExtensionInstallPrompt::Prompt::InstallPromptPermissions:: |
| 107 | InstallPromptPermissions() { |
| 108 | } |
| 109 | ExtensionInstallPrompt::Prompt::InstallPromptPermissions:: |
| 110 | ~InstallPromptPermissions() { |
| 111 | } |
| 112 | |
rdevlin.cronin | 092c677 | 2014-11-20 23:52:40 | [diff] [blame] | 113 | ExtensionInstallPrompt::PromptType |
| 114 | ExtensionInstallPrompt::g_last_prompt_type_for_tests = |
| 115 | ExtensionInstallPrompt::UNSET_PROMPT_TYPE; |
| 116 | |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 117 | ExtensionInstallPrompt::Prompt::Prompt(PromptType type) |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 118 | : type_(type), |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 119 | is_showing_details_for_retained_files_(false), |
reillyg | c64d3dd | 2014-09-29 21:10:11 | [diff] [blame] | 120 | is_showing_details_for_retained_devices_(false), |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 121 | extension_(NULL), |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 122 | average_rating_(0.0), |
[email protected] | dcde34b3 | 2013-07-31 02:28:45 | [diff] [blame] | 123 | rating_count_(0), |
[email protected] | 34b5f7f | 2014-01-29 02:48:11 | [diff] [blame] | 124 | show_user_count_(false), |
| 125 | has_webstore_data_(false) { |
rdevlin.cronin | c7f8d13 | 2017-02-22 14:29:02 | [diff] [blame] | 126 | DCHECK_NE(type_, UNSET_PROMPT_TYPE); |
| 127 | DCHECK_NE(type_, NUM_PROMPT_TYPES); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | ExtensionInstallPrompt::Prompt::~Prompt() { |
| 131 | } |
| 132 | |
isandrk | 98a3e4a1 | 2017-05-26 21:14:50 | [diff] [blame] | 133 | void ExtensionInstallPrompt::Prompt::AddPermissions( |
Devlin Cronin | d6e136a | 2018-05-15 23:39:32 | [diff] [blame^] | 134 | const PermissionMessages& permissions) { |
treib | f9dce31 | 2015-08-27 17:33:35 | [diff] [blame] | 135 | for (const PermissionMessage& msg : permissions) { |
Devlin Cronin | d6e136a | 2018-05-15 23:39:32 | [diff] [blame^] | 136 | prompt_permissions_.permissions.push_back(msg.message()); |
treib | 7b45a34b | 2015-04-16 11:48:02 | [diff] [blame] | 137 | // Add a dash to the front of each permission detail. |
| 138 | base::string16 details; |
treib | 8d2de48 | 2015-08-04 16:36:48 | [diff] [blame] | 139 | if (!msg.submessages().empty()) { |
sashab | eabd5df | 2014-11-06 02:38:25 | [diff] [blame] | 140 | std::vector<base::string16> detail_lines_with_bullets; |
treib | 8d2de48 | 2015-08-04 16:36:48 | [diff] [blame] | 141 | for (const auto& detail_line : msg.submessages()) { |
sashab | eabd5df | 2014-11-06 02:38:25 | [diff] [blame] | 142 | detail_lines_with_bullets.push_back(base::ASCIIToUTF16("- ") + |
| 143 | detail_line); |
treib | 7b45a34b | 2015-04-16 11:48:02 | [diff] [blame] | 144 | } |
sashab | eabd5df | 2014-11-06 02:38:25 | [diff] [blame] | 145 | |
brettw | d94a2214 | 2015-07-15 05:19:26 | [diff] [blame] | 146 | details = base::JoinString(detail_lines_with_bullets, |
| 147 | base::ASCIIToUTF16("\n")); |
sashab | eabd5df | 2014-11-06 02:38:25 | [diff] [blame] | 148 | } |
Devlin Cronin | d6e136a | 2018-05-15 23:39:32 | [diff] [blame^] | 149 | prompt_permissions_.details.push_back(details); |
| 150 | prompt_permissions_.is_showing_details.push_back(false); |
sashab | eabd5df | 2014-11-06 02:38:25 | [diff] [blame] | 151 | } |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | void ExtensionInstallPrompt::Prompt::SetIsShowingDetails( |
| 155 | DetailsType type, |
| 156 | size_t index, |
| 157 | bool is_showing_details) { |
| 158 | switch (type) { |
| 159 | case PERMISSIONS_DETAILS: |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 160 | prompt_permissions_.is_showing_details[index] = is_showing_details; |
| 161 | break; |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 162 | case RETAINED_FILES_DETAILS: |
| 163 | is_showing_details_for_retained_files_ = is_showing_details; |
| 164 | break; |
reillyg | c64d3dd | 2014-09-29 21:10:11 | [diff] [blame] | 165 | case RETAINED_DEVICES_DETAILS: |
| 166 | is_showing_details_for_retained_devices_ = is_showing_details; |
| 167 | break; |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 168 | } |
[email protected] | 8ab7e6c | 2013-07-11 21:15:03 | [diff] [blame] | 169 | } |
| 170 | |
[email protected] | 34b5f7f | 2014-01-29 02:48:11 | [diff] [blame] | 171 | void ExtensionInstallPrompt::Prompt::SetWebstoreData( |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 172 | const std::string& localized_user_count, |
[email protected] | dcde34b3 | 2013-07-31 02:28:45 | [diff] [blame] | 173 | bool show_user_count, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 174 | double average_rating, |
| 175 | int rating_count) { |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 176 | CHECK(AllowWebstoreData(type_)); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 177 | localized_user_count_ = localized_user_count; |
[email protected] | dcde34b3 | 2013-07-31 02:28:45 | [diff] [blame] | 178 | show_user_count_ = show_user_count; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 179 | average_rating_ = average_rating; |
| 180 | rating_count_ = rating_count; |
[email protected] | 34b5f7f | 2014-01-29 02:48:11 | [diff] [blame] | 181 | has_webstore_data_ = true; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 182 | } |
| 183 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 184 | base::string16 ExtensionInstallPrompt::Prompt::GetDialogTitle() const { |
rdevlin.cronin | c7f8d13 | 2017-02-22 14:29:02 | [diff] [blame] | 185 | int id = -1; |
| 186 | switch (type_) { |
| 187 | case INSTALL_PROMPT: |
| 188 | case INLINE_INSTALL_PROMPT: |
| 189 | id = IDS_EXTENSION_INSTALL_PROMPT_TITLE; |
| 190 | break; |
| 191 | case RE_ENABLE_PROMPT: |
| 192 | id = IDS_EXTENSION_RE_ENABLE_PROMPT_TITLE; |
| 193 | break; |
| 194 | case PERMISSIONS_PROMPT: |
| 195 | id = IDS_EXTENSION_PERMISSIONS_PROMPT_TITLE; |
| 196 | break; |
| 197 | case EXTERNAL_INSTALL_PROMPT: |
| 198 | if (extension_->is_app()) |
| 199 | id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_TITLE_APP; |
| 200 | else if (extension_->is_theme()) |
| 201 | id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_TITLE_THEME; |
| 202 | else |
| 203 | id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_TITLE_EXTENSION; |
| 204 | break; |
| 205 | case POST_INSTALL_PERMISSIONS_PROMPT: |
| 206 | id = IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_TITLE; |
| 207 | break; |
| 208 | case REMOTE_INSTALL_PROMPT: |
| 209 | id = IDS_EXTENSION_REMOTE_INSTALL_PROMPT_TITLE; |
| 210 | break; |
| 211 | case REPAIR_PROMPT: |
| 212 | id = IDS_EXTENSION_REPAIR_PROMPT_TITLE; |
| 213 | break; |
| 214 | case DELEGATED_PERMISSIONS_PROMPT: |
| 215 | // Special case: need to include the delegated username. |
| 216 | return l10n_util::GetStringFUTF16( |
| 217 | IDS_EXTENSION_DELEGATED_INSTALL_PROMPT_TITLE, |
| 218 | base::UTF8ToUTF16(extension_->name()), |
| 219 | base::UTF8ToUTF16(delegated_username_)); |
| 220 | case UNSET_PROMPT_TYPE: |
| 221 | case NUM_PROMPT_TYPES: |
| 222 | NOTREACHED(); |
treib | d3586225 | 2015-06-15 12:50:51 | [diff] [blame] | 223 | } |
rdevlin.cronin | c7f8d13 | 2017-02-22 14:29:02 | [diff] [blame] | 224 | |
treib | d3586225 | 2015-06-15 12:50:51 | [diff] [blame] | 225 | return l10n_util::GetStringFUTF16(id, base::UTF8ToUTF16(extension_->name())); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 226 | } |
| 227 | |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 228 | int ExtensionInstallPrompt::Prompt::GetDialogButtons() const { |
rdevlin.cronin | c7f8d13 | 2017-02-22 14:29:02 | [diff] [blame] | 229 | // The "OK" button in the post install permissions dialog allows revoking |
| 230 | // file/device access, and is only shown if such permissions exist; see |
| 231 | // ShouldDisplayRevokeButton(). |
| 232 | if (type_ == POST_INSTALL_PERMISSIONS_PROMPT && |
| 233 | !ShouldDisplayRevokeButton()) { |
| 234 | return ui::DIALOG_BUTTON_CANCEL; |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 235 | } |
rdevlin.cronin | c7f8d13 | 2017-02-22 14:29:02 | [diff] [blame] | 236 | return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 237 | } |
| 238 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 239 | base::string16 ExtensionInstallPrompt::Prompt::GetAcceptButtonLabel() const { |
rdevlin.cronin | c7f8d13 | 2017-02-22 14:29:02 | [diff] [blame] | 240 | int id = -1; |
| 241 | switch (type_) { |
| 242 | case INSTALL_PROMPT: |
| 243 | case INLINE_INSTALL_PROMPT: |
| 244 | if (extension_->is_app()) |
| 245 | id = IDS_EXTENSION_INSTALL_PROMPT_ACCEPT_BUTTON_APP; |
| 246 | else if (extension_->is_theme()) |
| 247 | id = IDS_EXTENSION_INSTALL_PROMPT_ACCEPT_BUTTON_THEME; |
| 248 | else |
| 249 | id = IDS_EXTENSION_INSTALL_PROMPT_ACCEPT_BUTTON_EXTENSION; |
| 250 | break; |
| 251 | case RE_ENABLE_PROMPT: |
| 252 | id = IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON; |
| 253 | break; |
| 254 | case PERMISSIONS_PROMPT: |
| 255 | id = IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON; |
| 256 | break; |
| 257 | case EXTERNAL_INSTALL_PROMPT: |
| 258 | if (extension_->is_app()) |
| 259 | id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_APP; |
| 260 | else if (extension_->is_theme()) |
| 261 | id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_THEME; |
| 262 | else |
| 263 | id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_EXTENSION; |
| 264 | break; |
| 265 | case POST_INSTALL_PERMISSIONS_PROMPT: |
| 266 | if (GetRetainedFileCount() && GetRetainedDeviceCount()) { |
| 267 | id = |
| 268 | IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_AND_DEVICES_BUTTON; |
| 269 | } else if (GetRetainedFileCount()) { |
| 270 | id = IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_BUTTON; |
| 271 | } else if (GetRetainedDeviceCount()) { |
| 272 | id = IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_DEVICES_BUTTON; |
| 273 | } |
| 274 | // If there are neither retained files nor devices, leave id -1 so there |
| 275 | // will be no "accept" button. |
| 276 | break; |
| 277 | case REMOTE_INSTALL_PROMPT: |
| 278 | if (extension_->is_app()) |
| 279 | id = IDS_EXTENSION_PROMPT_REMOTE_INSTALL_BUTTON_APP; |
| 280 | else |
| 281 | id = IDS_EXTENSION_PROMPT_REMOTE_INSTALL_BUTTON_EXTENSION; |
| 282 | break; |
| 283 | case REPAIR_PROMPT: |
| 284 | if (extension_->is_app()) |
| 285 | id = IDS_EXTENSION_PROMPT_REPAIR_BUTTON_APP; |
| 286 | else |
| 287 | id = IDS_EXTENSION_PROMPT_REPAIR_BUTTON_EXTENSION; |
| 288 | break; |
| 289 | case DELEGATED_PERMISSIONS_PROMPT: |
| 290 | id = IDS_EXTENSION_PROMPT_INSTALL_BUTTON; |
| 291 | break; |
| 292 | case UNSET_PROMPT_TYPE: |
| 293 | case NUM_PROMPT_TYPES: |
| 294 | NOTREACHED(); |
[email protected] | 84660601 | 2012-10-19 18:42:25 | [diff] [blame] | 295 | } |
rdevlin.cronin | c7f8d13 | 2017-02-22 14:29:02 | [diff] [blame] | 296 | |
| 297 | return id != -1 ? l10n_util::GetStringUTF16(id) : base::string16(); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 298 | } |
| 299 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 300 | base::string16 ExtensionInstallPrompt::Prompt::GetAbortButtonLabel() const { |
rdevlin.cronin | c7f8d13 | 2017-02-22 14:29:02 | [diff] [blame] | 301 | int id = -1; |
| 302 | switch (type_) { |
| 303 | case INSTALL_PROMPT: |
| 304 | case INLINE_INSTALL_PROMPT: |
| 305 | case RE_ENABLE_PROMPT: |
| 306 | case REMOTE_INSTALL_PROMPT: |
| 307 | case REPAIR_PROMPT: |
| 308 | case DELEGATED_PERMISSIONS_PROMPT: |
| 309 | id = IDS_CANCEL; |
| 310 | break; |
| 311 | case PERMISSIONS_PROMPT: |
| 312 | id = IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON; |
| 313 | break; |
| 314 | case EXTERNAL_INSTALL_PROMPT: |
| 315 | id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ABORT_BUTTON; |
| 316 | break; |
| 317 | case POST_INSTALL_PERMISSIONS_PROMPT: |
| 318 | id = IDS_CLOSE; |
| 319 | break; |
| 320 | case UNSET_PROMPT_TYPE: |
| 321 | case NUM_PROMPT_TYPES: |
| 322 | NOTREACHED(); |
| 323 | } |
| 324 | |
| 325 | return l10n_util::GetStringUTF16(id); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 326 | } |
| 327 | |
Devlin Cronin | d6e136a | 2018-05-15 23:39:32 | [diff] [blame^] | 328 | base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsHeading() const { |
| 329 | int id = -1; |
| 330 | switch (type_) { |
| 331 | case INSTALL_PROMPT: |
| 332 | case INLINE_INSTALL_PROMPT: |
| 333 | case EXTERNAL_INSTALL_PROMPT: |
| 334 | case REMOTE_INSTALL_PROMPT: |
| 335 | case DELEGATED_PERMISSIONS_PROMPT: |
| 336 | id = IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO; |
| 337 | break; |
| 338 | case RE_ENABLE_PROMPT: |
| 339 | id = IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO; |
| 340 | break; |
| 341 | case PERMISSIONS_PROMPT: |
| 342 | id = IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO; |
| 343 | break; |
| 344 | case POST_INSTALL_PERMISSIONS_PROMPT: |
| 345 | case REPAIR_PROMPT: |
| 346 | id = IDS_EXTENSION_PROMPT_CAN_ACCESS; |
| 347 | break; |
| 348 | case UNSET_PROMPT_TYPE: |
| 349 | case NUM_PROMPT_TYPES: |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 350 | NOTREACHED(); |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 351 | } |
Devlin Cronin | d6e136a | 2018-05-15 23:39:32 | [diff] [blame^] | 352 | return l10n_util::GetStringUTF16(id); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 353 | } |
| 354 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 355 | base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const { |
jshin | 3a6c36bb | 2015-04-09 21:58:08 | [diff] [blame] | 356 | return l10n_util::GetPluralStringFUTF16( |
| 357 | IDS_EXTENSION_PROMPT_RETAINED_FILES, GetRetainedFileCount()); |
[email protected] | 8ab7e6c | 2013-07-11 21:15:03 | [diff] [blame] | 358 | } |
| 359 | |
reillyg | c64d3dd | 2014-09-29 21:10:11 | [diff] [blame] | 360 | base::string16 ExtensionInstallPrompt::Prompt::GetRetainedDevicesHeading() |
| 361 | const { |
jshin | 3a6c36bb | 2015-04-09 21:58:08 | [diff] [blame] | 362 | return l10n_util::GetPluralStringFUTF16( |
| 363 | IDS_EXTENSION_PROMPT_RETAINED_DEVICES, GetRetainedDeviceCount()); |
reillyg | c64d3dd | 2014-09-29 21:10:11 | [diff] [blame] | 364 | } |
| 365 | |
[email protected] | f2cd899 | 2013-06-11 17:30:18 | [diff] [blame] | 366 | bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { |
Devlin Cronin | d6e136a | 2018-05-15 23:39:32 | [diff] [blame^] | 367 | return GetPermissionCount() > 0 || type_ == POST_INSTALL_PERMISSIONS_PROMPT; |
[email protected] | f2cd899 | 2013-06-11 17:30:18 | [diff] [blame] | 368 | } |
| 369 | |
asargent | 0a1c15f | 2015-12-09 02:25:21 | [diff] [blame] | 370 | bool ExtensionInstallPrompt::Prompt::ShouldUseTabModalDialog() const { |
| 371 | // For inline install, we want the install prompt to be tab modal so that the |
| 372 | // dialog is always clearly associated with the page that made the inline |
| 373 | // install request. |
| 374 | return type_ == INLINE_INSTALL_PROMPT; |
| 375 | } |
| 376 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 377 | void ExtensionInstallPrompt::Prompt::AppendRatingStars( |
| 378 | StarAppender appender, void* data) const { |
| 379 | CHECK(appender); |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 380 | CHECK(AllowWebstoreData(type_)); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 381 | int rating_integer = floor(average_rating_); |
| 382 | double rating_fractional = average_rating_ - rating_integer; |
| 383 | |
| 384 | if (rating_fractional > 0.66) { |
| 385 | rating_integer++; |
| 386 | } |
| 387 | |
| 388 | if (rating_fractional < 0.33 || rating_fractional > 0.66) { |
| 389 | rating_fractional = 0; |
| 390 | } |
| 391 | |
Lei Zhang | 7640d54 | 2017-10-03 16:26:49 | [diff] [blame] | 392 | ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 393 | int i; |
| 394 | for (i = 0; i < rating_integer; i++) { |
| 395 | appender(rb.GetImageSkiaNamed(IDR_EXTENSIONS_RATING_STAR_ON), data); |
| 396 | } |
| 397 | if (rating_fractional) { |
| 398 | appender(rb.GetImageSkiaNamed(IDR_EXTENSIONS_RATING_STAR_HALF_LEFT), data); |
| 399 | i++; |
| 400 | } |
| 401 | for (; i < kMaxExtensionRating; i++) { |
| 402 | appender(rb.GetImageSkiaNamed(IDR_EXTENSIONS_RATING_STAR_OFF), data); |
| 403 | } |
| 404 | } |
| 405 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 406 | base::string16 ExtensionInstallPrompt::Prompt::GetRatingCount() const { |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 407 | CHECK(AllowWebstoreData(type_)); |
[email protected] | 6725048e | 2013-10-24 21:47:14 | [diff] [blame] | 408 | return l10n_util::GetStringFUTF16(IDS_EXTENSION_RATING_COUNT, |
| 409 | base::IntToString16(rating_count_)); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 410 | } |
| 411 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 412 | base::string16 ExtensionInstallPrompt::Prompt::GetUserCount() const { |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 413 | CHECK(AllowWebstoreData(type_)); |
[email protected] | dcde34b3 | 2013-07-31 02:28:45 | [diff] [blame] | 414 | |
| 415 | if (show_user_count_) { |
[email protected] | 6725048e | 2013-10-24 21:47:14 | [diff] [blame] | 416 | return l10n_util::GetStringFUTF16(IDS_EXTENSION_USER_COUNT, |
| 417 | base::UTF8ToUTF16(localized_user_count_)); |
[email protected] | dcde34b3 | 2013-07-31 02:28:45 | [diff] [blame] | 418 | } |
[email protected] | 6725048e | 2013-10-24 21:47:14 | [diff] [blame] | 419 | return base::string16(); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 420 | } |
| 421 | |
Devlin Cronin | d6e136a | 2018-05-15 23:39:32 | [diff] [blame^] | 422 | size_t ExtensionInstallPrompt::Prompt::GetPermissionCount() const { |
| 423 | return prompt_permissions_.permissions.size(); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 424 | } |
| 425 | |
Devlin Cronin | d6e136a | 2018-05-15 23:39:32 | [diff] [blame^] | 426 | size_t ExtensionInstallPrompt::Prompt::GetPermissionsDetailsCount() const { |
| 427 | return prompt_permissions_.details.size(); |
[email protected] | 8ab7e6c | 2013-07-11 21:15:03 | [diff] [blame] | 428 | } |
| 429 | |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 430 | base::string16 ExtensionInstallPrompt::Prompt::GetPermission( |
Devlin Cronin | d6e136a | 2018-05-15 23:39:32 | [diff] [blame^] | 431 | size_t index) const { |
| 432 | CHECK_LT(index, prompt_permissions_.permissions.size()); |
| 433 | return prompt_permissions_.permissions[index]; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 434 | } |
| 435 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 436 | base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsDetails( |
Devlin Cronin | d6e136a | 2018-05-15 23:39:32 | [diff] [blame^] | 437 | size_t index) const { |
| 438 | CHECK_LT(index, prompt_permissions_.details.size()); |
| 439 | return prompt_permissions_.details[index]; |
[email protected] | 8ab7e6c | 2013-07-11 21:15:03 | [diff] [blame] | 440 | } |
| 441 | |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 442 | bool ExtensionInstallPrompt::Prompt::GetIsShowingDetails( |
| 443 | DetailsType type, size_t index) const { |
| 444 | switch (type) { |
| 445 | case PERMISSIONS_DETAILS: |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 446 | CHECK_LT(index, prompt_permissions_.is_showing_details.size()); |
| 447 | return prompt_permissions_.is_showing_details[index]; |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 448 | case RETAINED_FILES_DETAILS: |
| 449 | return is_showing_details_for_retained_files_; |
reillyg | c64d3dd | 2014-09-29 21:10:11 | [diff] [blame] | 450 | case RETAINED_DEVICES_DETAILS: |
| 451 | return is_showing_details_for_retained_devices_; |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 452 | } |
| 453 | return false; |
| 454 | } |
| 455 | |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 456 | size_t ExtensionInstallPrompt::Prompt::GetRetainedFileCount() const { |
| 457 | return retained_files_.size(); |
| 458 | } |
| 459 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 460 | base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFile(size_t index) |
| 461 | const { |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 462 | CHECK_LT(index, retained_files_.size()); |
[email protected] | 6725048e | 2013-10-24 21:47:14 | [diff] [blame] | 463 | return retained_files_[index].AsUTF16Unsafe(); |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 464 | } |
| 465 | |
reillyg | c64d3dd | 2014-09-29 21:10:11 | [diff] [blame] | 466 | size_t ExtensionInstallPrompt::Prompt::GetRetainedDeviceCount() const { |
| 467 | return retained_device_messages_.size(); |
| 468 | } |
| 469 | |
| 470 | base::string16 ExtensionInstallPrompt::Prompt::GetRetainedDeviceMessageString( |
| 471 | size_t index) const { |
| 472 | CHECK_LT(index, retained_device_messages_.size()); |
| 473 | return retained_device_messages_[index]; |
| 474 | } |
| 475 | |
| 476 | bool ExtensionInstallPrompt::Prompt::ShouldDisplayRevokeButton() const { |
| 477 | return !retained_files_.empty() || !retained_device_messages_.empty(); |
| 478 | } |
| 479 | |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 480 | bool ExtensionInstallPrompt::Prompt::ShouldDisplayRevokeFilesButton() const { |
| 481 | return !retained_files_.empty(); |
| 482 | } |
| 483 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 484 | // static |
rdevlin.cronin | f84cab7 | 2015-12-12 03:45:23 | [diff] [blame] | 485 | ExtensionInstallPrompt::PromptType |
| 486 | ExtensionInstallPrompt::GetReEnablePromptTypeForExtension( |
| 487 | content::BrowserContext* context, |
| 488 | const extensions::Extension* extension) { |
| 489 | bool is_remote_install = |
| 490 | context && |
| 491 | extensions::ExtensionPrefs::Get(context)->HasDisableReason( |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 492 | extension->id(), extensions::disable_reason::DISABLE_REMOTE_INSTALL); |
rdevlin.cronin | f84cab7 | 2015-12-12 03:45:23 | [diff] [blame] | 493 | |
| 494 | return is_remote_install ? REMOTE_INSTALL_PROMPT : RE_ENABLE_PROMPT; |
| 495 | } |
| 496 | |
| 497 | // static |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 498 | scoped_refptr<Extension> |
| 499 | ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 500 | const base::DictionaryValue* manifest, |
[email protected] | c422a86 | 2012-07-31 15:46:13 | [diff] [blame] | 501 | int flags, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 502 | const std::string& id, |
| 503 | const std::string& localized_name, |
| 504 | const std::string& localized_description, |
| 505 | std::string* error) { |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 506 | std::unique_ptr<base::DictionaryValue> localized_manifest; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 507 | if (!localized_name.empty() || !localized_description.empty()) { |
| 508 | localized_manifest.reset(manifest->DeepCopy()); |
| 509 | if (!localized_name.empty()) { |
[email protected] | 6bf9061 | 2013-08-15 00:36:27 | [diff] [blame] | 510 | localized_manifest->SetString(extensions::manifest_keys::kName, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 511 | localized_name); |
| 512 | } |
| 513 | if (!localized_description.empty()) { |
[email protected] | 6bf9061 | 2013-08-15 00:36:27 | [diff] [blame] | 514 | localized_manifest->SetString(extensions::manifest_keys::kDescription, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 515 | localized_description); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | return Extension::Create( |
rdevlin.cronin | 165732a4 | 2016-07-18 22:25:08 | [diff] [blame] | 520 | base::FilePath(), Manifest::INTERNAL, |
| 521 | localized_manifest.get() ? *localized_manifest : *manifest, flags, id, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 522 | error); |
| 523 | } |
| 524 | |
[email protected] | 7f16534 | 2014-02-12 09:22:22 | [diff] [blame] | 525 | ExtensionInstallPrompt::ExtensionInstallPrompt(content::WebContents* contents) |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 526 | : profile_(ProfileForWebContents(contents)), |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 527 | extension_(NULL), |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 528 | install_ui_(extensions::CreateExtensionInstallUI( |
| 529 | ProfileForWebContents(contents))), |
pkotwicz | 2f18178 | 2014-10-29 17:33:45 | [diff] [blame] | 530 | show_params_(new ExtensionInstallPromptShowParams(contents)), |
rdevlin.cronin | 3fe4bd3 | 2016-01-12 18:45:40 | [diff] [blame] | 531 | did_call_show_dialog_(false), |
| 532 | weak_factory_(this) { |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 533 | } |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 534 | |
pkotwicz | 2175c62 | 2014-10-22 19:56:28 | [diff] [blame] | 535 | ExtensionInstallPrompt::ExtensionInstallPrompt(Profile* profile, |
| 536 | gfx::NativeWindow native_window) |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 537 | : profile_(profile), |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 538 | extension_(NULL), |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 539 | install_ui_(extensions::CreateExtensionInstallUI(profile)), |
pkotwicz | 2f18178 | 2014-10-29 17:33:45 | [diff] [blame] | 540 | show_params_( |
| 541 | new ExtensionInstallPromptShowParams(profile, native_window)), |
rdevlin.cronin | 3fe4bd3 | 2016-01-12 18:45:40 | [diff] [blame] | 542 | did_call_show_dialog_(false), |
| 543 | weak_factory_(this) { |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 544 | } |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 545 | |
| 546 | ExtensionInstallPrompt::~ExtensionInstallPrompt() { |
| 547 | } |
| 548 | |
rdevlin.cronin | f84cab7 | 2015-12-12 03:45:23 | [diff] [blame] | 549 | void ExtensionInstallPrompt::ShowDialog( |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 550 | const DoneCallback& done_callback, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 551 | const Extension* extension, |
rdevlin.cronin | f84cab7 | 2015-12-12 03:45:23 | [diff] [blame] | 552 | const SkBitmap* icon, |
| 553 | const ShowDialogCallback& show_dialog_callback) { |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 554 | ShowDialog(done_callback, extension, icon, |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 555 | std::make_unique<Prompt>(INSTALL_PROMPT), show_dialog_callback); |
rdevlin.cronin | 2e25269 | 2015-12-15 21:47:02 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | void ExtensionInstallPrompt::ShowDialog( |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 559 | const DoneCallback& done_callback, |
rdevlin.cronin | 2e25269 | 2015-12-15 21:47:02 | [diff] [blame] | 560 | const Extension* extension, |
| 561 | const SkBitmap* icon, |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 562 | std::unique_ptr<Prompt> prompt, |
rdevlin.cronin | 2e25269 | 2015-12-15 21:47:02 | [diff] [blame] | 563 | const ShowDialogCallback& show_dialog_callback) { |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 564 | ShowDialog(done_callback, extension, icon, std::move(prompt), nullptr, |
rdevlin.cronin | f84cab7 | 2015-12-12 03:45:23 | [diff] [blame] | 565 | show_dialog_callback); |
| 566 | } |
| 567 | |
| 568 | void ExtensionInstallPrompt::ShowDialog( |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 569 | const DoneCallback& done_callback, |
rdevlin.cronin | f84cab7 | 2015-12-12 03:45:23 | [diff] [blame] | 570 | const Extension* extension, |
| 571 | const SkBitmap* icon, |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 572 | std::unique_ptr<Prompt> prompt, |
| 573 | std::unique_ptr<const PermissionSet> custom_permissions, |
rdevlin.cronin | f84cab7 | 2015-12-12 03:45:23 | [diff] [blame] | 574 | const ShowDialogCallback& show_dialog_callback) { |
fdoray | c16c6f8 | 2016-06-29 15:27:32 | [diff] [blame] | 575 | DCHECK(ui_thread_checker_.CalledOnValidThread()); |
rdevlin.cronin | 2e25269 | 2015-12-15 21:47:02 | [diff] [blame] | 576 | DCHECK(prompt); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 577 | extension_ = extension; |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 578 | done_callback_ = done_callback; |
rdevlin.cronin | fc1499f | 2015-12-21 18:22:00 | [diff] [blame] | 579 | if (icon && !icon->empty()) |
| 580 | SetIcon(icon); |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 581 | prompt_ = std::move(prompt); |
| 582 | custom_permissions_ = std::move(custom_permissions); |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 583 | show_dialog_callback_ = show_dialog_callback; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 584 | |
| 585 | // We special-case themes to not show any confirm UI. Instead they are |
| 586 | // immediately installed, and then we show an infobar (see OnInstallSuccess) |
| 587 | // to allow the user to revert if they don't like it. |
rdevlin.cronin | 10f3454 | 2017-02-06 18:22:47 | [diff] [blame] | 588 | if (extension->is_theme() && extension->from_webstore()) { |
| 589 | base::ResetAndReturn(&done_callback_).Run(Result::ACCEPTED); |
| 590 | return; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | LoadImageIfNeeded(); |
| 594 | } |
| 595 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 596 | void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, |
| 597 | SkBitmap* icon) { |
| 598 | extension_ = extension; |
| 599 | SetIcon(icon); |
| 600 | |
| 601 | install_ui_->OnInstallSuccess(extension, &icon_); |
| 602 | } |
| 603 | |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 604 | void ExtensionInstallPrompt::OnInstallFailure( |
ginkage | 47e603e | 2015-02-27 08:42:41 | [diff] [blame] | 605 | const extensions::CrxInstallError& error) { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 606 | install_ui_->OnInstallFailure(error); |
| 607 | } |
| 608 | |
| 609 | void ExtensionInstallPrompt::SetIcon(const SkBitmap* image) { |
| 610 | if (image) |
| 611 | icon_ = *image; |
| 612 | else |
| 613 | icon_ = SkBitmap(); |
[email protected] | dd46a4ce | 2012-09-15 10:50:50 | [diff] [blame] | 614 | if (icon_.empty()) { |
| 615 | // Let's set default icon bitmap whose size is equal to the default icon's |
| 616 | // pixel size under maximal supported scale factor. If the bitmap is larger |
| 617 | // than the one we need, it will be scaled down by the ui code. |
treib | d9e1d9d | 2015-04-24 11:17:04 | [diff] [blame] | 618 | icon_ = GetDefaultIconBitmapForMaxScaleFactor( |
| 619 | extension_ ? extension_->is_app() : false); |
[email protected] | dd46a4ce | 2012-09-15 10:50:50 | [diff] [blame] | 620 | } |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 621 | } |
| 622 | |
[email protected] | ec7de0c5a | 2012-11-16 07:40:47 | [diff] [blame] | 623 | void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image) { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 624 | SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); |
[email protected] | 4e49487 | 2013-09-06 09:13:54 | [diff] [blame] | 625 | ShowConfirmation(); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | void ExtensionInstallPrompt::LoadImageIfNeeded() { |
treib | 3d41d9f | 2016-04-12 08:53:01 | [diff] [blame] | 629 | // Don't override an icon that was passed in. Also, |profile_| can be null in |
| 630 | // unit tests. |
| 631 | if (!icon_.empty() || !profile_) { |
[email protected] | 4e49487 | 2013-09-06 09:13:54 | [diff] [blame] | 632 | ShowConfirmation(); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 633 | return; |
| 634 | } |
| 635 | |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 636 | extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( |
[email protected] | 702d8b4 | 2013-02-27 20:55:50 | [diff] [blame] | 637 | extension_, |
| 638 | extension_misc::EXTENSION_ICON_LARGE, |
| 639 | ExtensionIconSet::MATCH_BIGGER); |
[email protected] | 0d0ba18 | 2014-06-03 12:40:43 | [diff] [blame] | 640 | |
| 641 | // Load the image asynchronously. The response will be sent to OnImageLoaded. |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 642 | extensions::ImageLoader* loader = extensions::ImageLoader::Get(profile_); |
[email protected] | 0d0ba18 | 2014-06-03 12:40:43 | [diff] [blame] | 643 | |
| 644 | std::vector<extensions::ImageLoader::ImageRepresentation> images_list; |
| 645 | images_list.push_back(extensions::ImageLoader::ImageRepresentation( |
| 646 | image, |
| 647 | extensions::ImageLoader::ImageRepresentation::NEVER_RESIZE, |
| 648 | gfx::Size(), |
| 649 | ui::SCALE_FACTOR_100P)); |
| 650 | loader->LoadImagesAsync( |
| 651 | extension_, |
| 652 | images_list, |
rdevlin.cronin | 3fe4bd3 | 2016-01-12 18:45:40 | [diff] [blame] | 653 | base::Bind(&ExtensionInstallPrompt::OnImageLoaded, |
| 654 | weak_factory_.GetWeakPtr())); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | void ExtensionInstallPrompt::ShowConfirmation() { |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 658 | std::unique_ptr<const PermissionSet> permissions_wrapper; |
rdevlin.cronin | e2d0fd0 | 2015-09-24 22:35:49 | [diff] [blame] | 659 | const PermissionSet* permissions_to_display = nullptr; |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 660 | if (custom_permissions_.get()) { |
rdevlin.cronin | e2d0fd0 | 2015-09-24 22:35:49 | [diff] [blame] | 661 | permissions_to_display = custom_permissions_.get(); |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 662 | } else if (extension_) { |
| 663 | // Initialize permissions if they have not already been set so that |
Devlin Cronin | d6e136a | 2018-05-15 23:39:32 | [diff] [blame^] | 664 | // any transformations are correctly reflected in the install prompt. |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 665 | extensions::PermissionsUpdater( |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 666 | profile_, extensions::PermissionsUpdater::INIT_FLAG_TRANSIENT) |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 667 | .InitializePermissions(extension_); |
| 668 | permissions_to_display = |
rdevlin.cronin | d630c30 | 2015-09-30 20:19:33 | [diff] [blame] | 669 | &extension_->permissions_data()->active_permissions(); |
treib | 7496f63c | 2015-03-04 12:18:53 | [diff] [blame] | 670 | // For delegated installs, all optional permissions are pre-approved by the |
| 671 | // person who triggers the install, so add them to the list. |
treib | 3d41d9f | 2016-04-12 08:53:01 | [diff] [blame] | 672 | if (prompt_->type() == DELEGATED_PERMISSIONS_PROMPT) { |
rdevlin.cronin | d630c30 | 2015-09-30 20:19:33 | [diff] [blame] | 673 | const PermissionSet& optional_permissions = |
treib | 7496f63c | 2015-03-04 12:18:53 | [diff] [blame] | 674 | extensions::PermissionsParser::GetOptionalPermissions(extension_); |
rdevlin.cronin | e2d0fd0 | 2015-09-24 22:35:49 | [diff] [blame] | 675 | permissions_wrapper = PermissionSet::CreateUnion(*permissions_to_display, |
rdevlin.cronin | d630c30 | 2015-09-30 20:19:33 | [diff] [blame] | 676 | optional_permissions); |
rdevlin.cronin | e2d0fd0 | 2015-09-24 22:35:49 | [diff] [blame] | 677 | permissions_to_display = permissions_wrapper.get(); |
treib | 7496f63c | 2015-03-04 12:18:53 | [diff] [blame] | 678 | } |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 679 | } |
| 680 | |
rdevlin.cronin | e2d0fd0 | 2015-09-24 22:35:49 | [diff] [blame] | 681 | if (permissions_to_display && |
[email protected] | a397ec0 | 2014-08-08 15:48:13 | [diff] [blame] | 682 | (!extension_ || |
| 683 | !extensions::PermissionsData::ShouldSkipPermissionWarnings( |
| 684 | extension_->id()))) { |
| 685 | Manifest::Type type = |
| 686 | extension_ ? extension_->GetType() : Manifest::TYPE_UNKNOWN; |
| 687 | const extensions::PermissionMessageProvider* message_provider = |
| 688 | extensions::PermissionMessageProvider::Get(); |
treib | 7b45a34b | 2015-04-16 11:48:02 | [diff] [blame] | 689 | |
isandrk | 98a3e4a1 | 2017-05-26 21:14:50 | [diff] [blame] | 690 | prompt_->AddPermissions(message_provider->GetPermissionMessages( |
Devlin Cronin | d6e136a | 2018-05-15 23:39:32 | [diff] [blame^] | 691 | message_provider->GetAllPermissionIDs(*permissions_to_display, type))); |
[email protected] | bebe1d0 | 2012-08-02 20:17:09 | [diff] [blame] | 692 | } |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 693 | |
rdevlin.cronin | c7f8d13 | 2017-02-22 14:29:02 | [diff] [blame] | 694 | prompt_->set_extension(extension_); |
treib | d9e1d9d | 2015-04-24 11:17:04 | [diff] [blame] | 695 | prompt_->set_icon(gfx::Image::CreateFrom1xBitmap(icon_)); |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 696 | |
pkotwicz | 2f18178 | 2014-10-29 17:33:45 | [diff] [blame] | 697 | if (show_params_->WasParentDestroyed()) { |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 698 | base::ResetAndReturn(&done_callback_).Run(Result::ABORTED); |
pkotwicz | 2f18178 | 2014-10-29 17:33:45 | [diff] [blame] | 699 | return; |
| 700 | } |
| 701 | |
rdevlin.cronin | ca5bf2da | 2015-12-17 21:21:08 | [diff] [blame] | 702 | g_last_prompt_type_for_tests = prompt_->type(); |
| 703 | did_call_show_dialog_ = true; |
| 704 | |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 705 | if (AutoConfirmPrompt(&done_callback_)) |
rdevlin.cronin | ca5bf2da | 2015-12-17 21:21:08 | [diff] [blame] | 706 | return; |
| 707 | |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 708 | if (show_dialog_callback_.is_null()) |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 709 | show_dialog_callback_ = GetDefaultShowDialogCallback(); |
| 710 | base::ResetAndReturn(&show_dialog_callback_) |
| 711 | .Run(show_params_.get(), base::ResetAndReturn(&done_callback_), |
| 712 | std::move(prompt_)); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 713 | } |