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