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