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