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