[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 | |
| 7 | #include <map> |
| 8 | |
| 9 | #include "base/command_line.h" |
[email protected] | b19fe57 | 2013-07-18 04:54:26 | [diff] [blame] | 10 | #include "base/message_loop/message_loop.h" |
[email protected] | 3853a4c | 2013-02-11 17:15:57 | [diff] [blame] | 11 | #include "base/prefs/pref_service.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 12 | #include "base/strings/string_number_conversions.h" |
sashab | eabd5df | 2014-11-06 02:38:25 | [diff] [blame] | 13 | #include "base/strings/string_split.h" |
[email protected] | 00e7bef | 2013-06-10 20:35:17 | [diff] [blame] | 14 | #include "base/strings/string_util.h" |
| 15 | #include "base/strings/stringprintf.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 16 | #include "base/strings/utf_string_conversions.h" |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 17 | #include "chrome/browser/extensions/bundle_installer.h" |
pkotwicz | 2f18178 | 2014-10-29 17:33:45 | [diff] [blame] | 18 | #include "chrome/browser/extensions/extension_install_prompt_show_params.h" |
[email protected] | 7eb20e3 | 2014-04-30 08:50:56 | [diff] [blame] | 19 | #include "chrome/browser/extensions/extension_util.h" |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 20 | #include "chrome/browser/extensions/permissions_updater.h" |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 21 | #include "chrome/browser/profiles/profile.h" |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 22 | #include "chrome/browser/ui/extensions/extension_install_ui_factory.h" |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 23 | #include "chrome/common/chrome_switches.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 24 | #include "chrome/grit/chromium_strings.h" |
| 25 | #include "chrome/grit/generated_resources.h" |
[email protected] | 91e51d61 | 2012-10-21 23:03:05 | [diff] [blame] | 26 | #include "content/public/browser/web_contents.h" |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 27 | #include "extensions/browser/extension_prefs.h" |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 28 | #include "extensions/browser/extension_util.h" |
[email protected] | 326e6f0 | 2014-06-20 04:53:37 | [diff] [blame] | 29 | #include "extensions/browser/image_loader.h" |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 30 | #include "extensions/browser/install/extension_install_ui.h" |
[email protected] | cda103d | 2014-04-04 16:22:39 | [diff] [blame] | 31 | #include "extensions/common/constants.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 32 | #include "extensions/common/extension.h" |
[email protected] | 4b790884 | 2014-04-07 23:50:22 | [diff] [blame] | 33 | #include "extensions/common/extension_icon_set.h" |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 34 | #include "extensions/common/extension_resource.h" |
[email protected] | 5ef835a | 2013-11-08 20:42:57 | [diff] [blame] | 35 | #include "extensions/common/feature_switch.h" |
[email protected] | d42c1115 | 2013-08-22 19:36:32 | [diff] [blame] | 36 | #include "extensions/common/manifest.h" |
[email protected] | 6bf9061 | 2013-08-15 00:36:27 | [diff] [blame] | 37 | #include "extensions/common/manifest_constants.h" |
[email protected] | 0db486f | 2014-04-09 19:32:22 | [diff] [blame] | 38 | #include "extensions/common/manifest_handlers/icons_handler.h" |
treib | 7496f63c | 2015-03-04 12:18:53 | [diff] [blame^] | 39 | #include "extensions/common/manifest_handlers/permissions_parser.h" |
[email protected] | c4100347 | 2013-10-19 15:37:25 | [diff] [blame] | 40 | #include "extensions/common/permissions/permission_message_provider.h" |
[email protected] | 5a55f3f | 2013-10-29 01:08:29 | [diff] [blame] | 41 | #include "extensions/common/permissions/permission_set.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 42 | #include "extensions/common/permissions/permissions_data.h" |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 43 | #include "extensions/common/url_pattern.h" |
[email protected] | 2a28133 | 2012-07-11 22:20:23 | [diff] [blame] | 44 | #include "grit/theme_resources.h" |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 45 | #include "ui/base/l10n/l10n_util.h" |
| 46 | #include "ui/base/resource/resource_bundle.h" |
pkotwicz | 7fd0119 | 2014-10-09 04:43:50 | [diff] [blame] | 47 | #include "ui/base/ui_base_types.h" |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 48 | #include "ui/gfx/image/image.h" |
| 49 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 50 | using extensions::BundleInstaller; |
| 51 | using extensions::Extension; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 52 | using extensions::Manifest; |
[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 | 0, // The regular install prompt depends on what's being installed. |
| 65 | IDS_EXTENSION_INLINE_INSTALL_PROMPT_TITLE, |
| 66 | IDS_EXTENSION_INSTALL_PROMPT_TITLE, |
| 67 | IDS_EXTENSION_RE_ENABLE_PROMPT_TITLE, |
| 68 | IDS_EXTENSION_PERMISSIONS_PROMPT_TITLE, |
| 69 | IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_TITLE, |
| 70 | IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_TITLE, |
| 71 | IDS_EXTENSION_LAUNCH_APP_PROMPT_TITLE, |
| 72 | 0, // The remote install prompt depends on what's being installed. |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 73 | 0, // The repair install prompt depends on what's being installed. |
treib | 2d2f537 | 2015-03-01 12:20:49 | [diff] [blame] | 74 | 0, // The delegated install prompt depends on what's being installed. |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 75 | }; |
| 76 | static const int kHeadingIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 77 | IDS_EXTENSION_INSTALL_PROMPT_HEADING, |
| 78 | 0, // Inline installs use the extension name. |
| 79 | 0, // Heading for bundle installs depends on the bundle contents. |
| 80 | IDS_EXTENSION_RE_ENABLE_PROMPT_HEADING, |
| 81 | IDS_EXTENSION_PERMISSIONS_PROMPT_HEADING, |
| 82 | 0, // External installs use different strings for extensions/apps. |
| 83 | IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_HEADING, |
| 84 | IDS_EXTENSION_LAUNCH_APP_PROMPT_HEADING, |
| 85 | IDS_EXTENSION_REMOTE_INSTALL_PROMPT_HEADING, |
treib | 2d2f537 | 2015-03-01 12:20:49 | [diff] [blame] | 86 | IDS_EXTENSION_REPAIR_PROMPT_HEADING, |
| 87 | IDS_EXTENSION_INSTALL_PROMPT_HEADING, |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 88 | }; |
| 89 | static const int kButtons[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 90 | ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
| 91 | ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
| 92 | ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
| 93 | ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
| 94 | ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
| 95 | ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
| 96 | ui::DIALOG_BUTTON_CANCEL, |
| 97 | ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
| 98 | ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 99 | ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
treib | 2d2f537 | 2015-03-01 12:20:49 | [diff] [blame] | 100 | ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 101 | }; |
| 102 | static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 103 | IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
| 104 | IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
| 105 | IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
| 106 | IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON, |
| 107 | IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON, |
| 108 | 0, // External installs use different strings for extensions/apps. |
reillyg | c64d3dd | 2014-09-29 21:10:11 | [diff] [blame] | 109 | 0, // Different strings depending on the files and devices retained. |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 110 | IDS_EXTENSION_PROMPT_LAUNCH_BUTTON, |
| 111 | IDS_EXTENSION_PROMPT_REMOTE_INSTALL_BUTTON, |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 112 | IDS_EXTENSION_PROMPT_REPAIR_BUTTON, |
treib | 2d2f537 | 2015-03-01 12:20:49 | [diff] [blame] | 113 | IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 114 | }; |
| 115 | static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 116 | 0, // These all use the platform's default cancel label. |
| 117 | 0, |
| 118 | 0, |
| 119 | 0, |
| 120 | IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON, |
| 121 | IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ABORT_BUTTON, |
| 122 | IDS_CLOSE, |
| 123 | 0, // Platform dependent cancel button. |
| 124 | 0, |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 125 | 0, |
treib | 2d2f537 | 2015-03-01 12:20:49 | [diff] [blame] | 126 | IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 127 | }; |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 128 | static const int |
| 129 | kPermissionsHeaderIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
| 130 | IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
| 131 | IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
| 132 | IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO, |
| 133 | IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, |
| 134 | IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, |
| 135 | IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
| 136 | IDS_EXTENSION_PROMPT_CAN_ACCESS, |
| 137 | IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
| 138 | IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 139 | IDS_EXTENSION_PROMPT_CAN_ACCESS, |
treib | 2d2f537 | 2015-03-01 12:20:49 | [diff] [blame] | 140 | IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 141 | }; |
| 142 | |
[email protected] | dd46a4ce | 2012-09-15 10:50:50 | [diff] [blame] | 143 | // Returns bitmap for the default icon with size equal to the default icon's |
| 144 | // pixel size under maximal supported scale factor. |
| 145 | SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) { |
[email protected] | 702d8b4 | 2013-02-27 20:55:50 | [diff] [blame] | 146 | const gfx::ImageSkia& image = is_app ? |
[email protected] | 7eb20e3 | 2014-04-30 08:50:56 | [diff] [blame] | 147 | extensions::util::GetDefaultAppIcon() : |
| 148 | extensions::util::GetDefaultExtensionIcon(); |
[email protected] | 50b6626 | 2013-09-24 03:25:48 | [diff] [blame] | 149 | return image.GetRepresentation( |
| 150 | gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); |
[email protected] | dd46a4ce | 2012-09-15 10:50:50 | [diff] [blame] | 151 | } |
| 152 | |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 153 | // If auto confirm is enabled then posts a task to proceed with or cancel the |
| 154 | // install and returns true. Otherwise returns false. |
| 155 | bool AutoConfirmPrompt(ExtensionInstallPrompt::Delegate* delegate) { |
[email protected] | 2a74d6f6 | 2014-07-24 11:53:47 | [diff] [blame] | 156 | switch (ExtensionInstallPrompt::g_auto_confirm_for_tests) { |
| 157 | case ExtensionInstallPrompt::NONE: |
| 158 | return false; |
| 159 | // We use PostTask instead of calling the delegate directly here, because in |
| 160 | // the real implementations it's highly likely the message loop will be |
| 161 | // pumping a few times before the user clicks accept or cancel. |
| 162 | case ExtensionInstallPrompt::ACCEPT: |
| 163 | base::MessageLoop::current()->PostTask( |
| 164 | FROM_HERE, |
| 165 | base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIProceed, |
| 166 | base::Unretained(delegate))); |
| 167 | return true; |
| 168 | case ExtensionInstallPrompt::CANCEL: |
| 169 | base::MessageLoop::current()->PostTask( |
| 170 | FROM_HERE, |
| 171 | base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIAbort, |
| 172 | base::Unretained(delegate), |
| 173 | true)); |
| 174 | return true; |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | NOTREACHED(); |
| 178 | return false; |
| 179 | } |
| 180 | |
[email protected] | 91e51d61 | 2012-10-21 23:03:05 | [diff] [blame] | 181 | Profile* ProfileForWebContents(content::WebContents* web_contents) { |
| 182 | if (!web_contents) |
| 183 | return NULL; |
| 184 | return Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 185 | } |
| 186 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 187 | } // namespace |
| 188 | |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 189 | ExtensionInstallPrompt::Prompt::InstallPromptPermissions:: |
| 190 | InstallPromptPermissions() { |
| 191 | } |
| 192 | ExtensionInstallPrompt::Prompt::InstallPromptPermissions:: |
| 193 | ~InstallPromptPermissions() { |
| 194 | } |
| 195 | |
[email protected] | 2a74d6f6 | 2014-07-24 11:53:47 | [diff] [blame] | 196 | // static |
| 197 | ExtensionInstallPrompt::AutoConfirmForTests |
| 198 | ExtensionInstallPrompt::g_auto_confirm_for_tests = ExtensionInstallPrompt::NONE; |
| 199 | |
rdevlin.cronin | 092c677 | 2014-11-20 23:52:40 | [diff] [blame] | 200 | ExtensionInstallPrompt::PromptType |
| 201 | ExtensionInstallPrompt::g_last_prompt_type_for_tests = |
| 202 | ExtensionInstallPrompt::UNSET_PROMPT_TYPE; |
| 203 | |
[email protected] | eeb0d3e1 | 2014-08-15 15:10:44 | [diff] [blame] | 204 | // This should match the PromptType enum. |
| 205 | std::string ExtensionInstallPrompt::PromptTypeToString(PromptType type) { |
| 206 | switch (type) { |
| 207 | case ExtensionInstallPrompt::INSTALL_PROMPT: |
| 208 | return "INSTALL_PROMPT"; |
| 209 | case ExtensionInstallPrompt::INLINE_INSTALL_PROMPT: |
| 210 | return "INLINE_INSTALL_PROMPT"; |
| 211 | case ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT: |
| 212 | return "BUNDLE_INSTALL_PROMPT"; |
| 213 | case ExtensionInstallPrompt::RE_ENABLE_PROMPT: |
| 214 | return "RE_ENABLE_PROMPT"; |
| 215 | case ExtensionInstallPrompt::PERMISSIONS_PROMPT: |
| 216 | return "PERMISSIONS_PROMPT"; |
| 217 | case ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT: |
| 218 | return "EXTERNAL_INSTALL_PROMPT"; |
| 219 | case ExtensionInstallPrompt::POST_INSTALL_PERMISSIONS_PROMPT: |
| 220 | return "POST_INSTALL_PERMISSIONS_PROMPT"; |
| 221 | case ExtensionInstallPrompt::LAUNCH_PROMPT: |
| 222 | return "LAUNCH_PROMPT"; |
| 223 | case ExtensionInstallPrompt::REMOTE_INSTALL_PROMPT: |
| 224 | return "REMOTE_INSTALL_PROMPT"; |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 225 | case ExtensionInstallPrompt::REPAIR_PROMPT: |
| 226 | return "REPAIR_PROMPT"; |
treib | 2d2f537 | 2015-03-01 12:20:49 | [diff] [blame] | 227 | case ExtensionInstallPrompt::DELEGATED_PERMISSIONS_PROMPT: |
| 228 | return "DELEGATED_PERMISSIONS_PROMPT"; |
[email protected] | eeb0d3e1 | 2014-08-15 15:10:44 | [diff] [blame] | 229 | case ExtensionInstallPrompt::UNSET_PROMPT_TYPE: |
| 230 | case ExtensionInstallPrompt::NUM_PROMPT_TYPES: |
| 231 | break; |
| 232 | } |
| 233 | return "OTHER"; |
| 234 | } |
| 235 | |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 236 | ExtensionInstallPrompt::Prompt::Prompt(PromptType type) |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 237 | : type_(type), |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 238 | is_showing_details_for_retained_files_(false), |
reillyg | c64d3dd | 2014-09-29 21:10:11 | [diff] [blame] | 239 | is_showing_details_for_retained_devices_(false), |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 240 | extension_(NULL), |
| 241 | bundle_(NULL), |
| 242 | average_rating_(0.0), |
[email protected] | dcde34b3 | 2013-07-31 02:28:45 | [diff] [blame] | 243 | rating_count_(0), |
[email protected] | 34b5f7f | 2014-01-29 02:48:11 | [diff] [blame] | 244 | show_user_count_(false), |
| 245 | has_webstore_data_(false) { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | ExtensionInstallPrompt::Prompt::~Prompt() { |
| 249 | } |
| 250 | |
| 251 | void ExtensionInstallPrompt::Prompt::SetPermissions( |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 252 | const std::vector<base::string16>& permissions, |
| 253 | PermissionsType permissions_type) { |
| 254 | GetPermissionsForType(permissions_type).permissions = permissions; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 255 | } |
| 256 | |
[email protected] | 8ab7e6c | 2013-07-11 21:15:03 | [diff] [blame] | 257 | void ExtensionInstallPrompt::Prompt::SetPermissionsDetails( |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 258 | const std::vector<base::string16>& details, |
| 259 | PermissionsType permissions_type) { |
| 260 | InstallPromptPermissions& install_permissions = |
| 261 | GetPermissionsForType(permissions_type); |
sashab | eabd5df | 2014-11-06 02:38:25 | [diff] [blame] | 262 | |
| 263 | // Add a dash to the front of each permission detail. |
| 264 | for (const auto& details_entry : details) { |
| 265 | if (!details_entry.empty()) { |
| 266 | std::vector<base::string16> detail_lines; |
| 267 | base::SplitString(details_entry, base::char16('\n'), &detail_lines); |
| 268 | |
| 269 | std::vector<base::string16> detail_lines_with_bullets; |
| 270 | for (const auto& detail_line : detail_lines) |
| 271 | detail_lines_with_bullets.push_back(base::ASCIIToUTF16("- ") + |
| 272 | detail_line); |
| 273 | |
| 274 | install_permissions.details.push_back( |
| 275 | JoinString(detail_lines_with_bullets, '\n')); |
| 276 | } else { |
| 277 | install_permissions.details.push_back(details_entry); |
| 278 | } |
| 279 | } |
| 280 | |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 281 | install_permissions.is_showing_details.clear(); |
| 282 | install_permissions.is_showing_details.insert( |
| 283 | install_permissions.is_showing_details.begin(), details.size(), false); |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | void ExtensionInstallPrompt::Prompt::SetIsShowingDetails( |
| 287 | DetailsType type, |
| 288 | size_t index, |
| 289 | bool is_showing_details) { |
| 290 | switch (type) { |
| 291 | case PERMISSIONS_DETAILS: |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 292 | prompt_permissions_.is_showing_details[index] = is_showing_details; |
| 293 | break; |
| 294 | case WITHHELD_PERMISSIONS_DETAILS: |
| 295 | withheld_prompt_permissions_.is_showing_details[index] = |
| 296 | is_showing_details; |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 297 | break; |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 298 | case RETAINED_FILES_DETAILS: |
| 299 | is_showing_details_for_retained_files_ = is_showing_details; |
| 300 | break; |
reillyg | c64d3dd | 2014-09-29 21:10:11 | [diff] [blame] | 301 | case RETAINED_DEVICES_DETAILS: |
| 302 | is_showing_details_for_retained_devices_ = is_showing_details; |
| 303 | break; |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 304 | } |
[email protected] | 8ab7e6c | 2013-07-11 21:15:03 | [diff] [blame] | 305 | } |
| 306 | |
[email protected] | 34b5f7f | 2014-01-29 02:48:11 | [diff] [blame] | 307 | void ExtensionInstallPrompt::Prompt::SetWebstoreData( |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 308 | const std::string& localized_user_count, |
[email protected] | dcde34b3 | 2013-07-31 02:28:45 | [diff] [blame] | 309 | bool show_user_count, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 310 | double average_rating, |
| 311 | int rating_count) { |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 312 | CHECK(AllowWebstoreData(type_)); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 313 | localized_user_count_ = localized_user_count; |
[email protected] | dcde34b3 | 2013-07-31 02:28:45 | [diff] [blame] | 314 | show_user_count_ = show_user_count; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 315 | average_rating_ = average_rating; |
| 316 | rating_count_ = rating_count; |
[email protected] | 34b5f7f | 2014-01-29 02:48:11 | [diff] [blame] | 317 | has_webstore_data_ = true; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 318 | } |
| 319 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 320 | base::string16 ExtensionInstallPrompt::Prompt::GetDialogTitle() const { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 321 | int resource_id = kTitleIds[type_]; |
| 322 | |
| 323 | if (type_ == INSTALL_PROMPT) { |
| 324 | if (extension_->is_app()) |
| 325 | resource_id = IDS_EXTENSION_INSTALL_APP_PROMPT_TITLE; |
| 326 | else if (extension_->is_theme()) |
| 327 | resource_id = IDS_EXTENSION_INSTALL_THEME_PROMPT_TITLE; |
| 328 | else |
| 329 | resource_id = IDS_EXTENSION_INSTALL_EXTENSION_PROMPT_TITLE; |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 330 | } else if (type_ == EXTERNAL_INSTALL_PROMPT) { |
| 331 | return l10n_util::GetStringFUTF16( |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 332 | resource_id, base::UTF8ToUTF16(extension_->name())); |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 333 | } else if (type_ == REMOTE_INSTALL_PROMPT) { |
| 334 | if (extension_->is_app()) |
| 335 | resource_id = IDS_EXTENSION_REMOTE_INSTALL_APP_PROMPT_TITLE; |
| 336 | else |
| 337 | resource_id = IDS_EXTENSION_REMOTE_INSTALL_EXTENSION_PROMPT_TITLE; |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 338 | } else if (type_ == REPAIR_PROMPT) { |
| 339 | if (extension_->is_app()) |
| 340 | resource_id = IDS_EXTENSION_REPAIR_APP_PROMPT_TITLE; |
| 341 | else |
| 342 | resource_id = IDS_EXTENSION_REPAIR_EXTENSION_PROMPT_TITLE; |
treib | 2d2f537 | 2015-03-01 12:20:49 | [diff] [blame] | 343 | } else if (type_ == DELEGATED_PERMISSIONS_PROMPT) { |
| 344 | DCHECK(!delegated_username_.empty()); |
| 345 | if (extension_->is_app()) |
| 346 | resource_id = IDS_EXTENSION_DELEGATED_INSTALL_APP_PROMPT_TITLE; |
| 347 | else |
| 348 | resource_id = IDS_EXTENSION_DELEGATED_INSTALL_EXTENSION_PROMPT_TITLE; |
| 349 | return l10n_util::GetStringFUTF16( |
| 350 | resource_id, base::UTF8ToUTF16(delegated_username_)); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | return l10n_util::GetStringUTF16(resource_id); |
| 354 | } |
| 355 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 356 | base::string16 ExtensionInstallPrompt::Prompt::GetHeading() const { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 357 | if (type_ == INLINE_INSTALL_PROMPT) { |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 358 | return base::UTF8ToUTF16(extension_->name()); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 359 | } else if (type_ == BUNDLE_INSTALL_PROMPT) { |
| 360 | return bundle_->GetHeadingTextFor(BundleInstaller::Item::STATE_PENDING); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 361 | } else if (type_ == EXTERNAL_INSTALL_PROMPT) { |
[email protected] | 84660601 | 2012-10-19 18:42:25 | [diff] [blame] | 362 | int resource_id = -1; |
| 363 | if (extension_->is_app()) |
| 364 | resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_APP; |
| 365 | else if (extension_->is_theme()) |
| 366 | resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_THEME; |
| 367 | else |
| 368 | resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_EXTENSION; |
| 369 | return l10n_util::GetStringUTF16(resource_id); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 370 | } else { |
| 371 | return l10n_util::GetStringFUTF16( |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 372 | kHeadingIds[type_], base::UTF8ToUTF16(extension_->name())); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 376 | int ExtensionInstallPrompt::Prompt::GetDialogButtons() const { |
reillyg | c64d3dd | 2014-09-29 21:10:11 | [diff] [blame] | 377 | if (type_ == POST_INSTALL_PERMISSIONS_PROMPT && ShouldDisplayRevokeButton()) { |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 378 | return kButtons[type_] | ui::DIALOG_BUTTON_OK; |
| 379 | } |
| 380 | |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 381 | return kButtons[type_]; |
| 382 | } |
| 383 | |
[email protected] | 62a28d7c | 2013-12-28 01:34:49 | [diff] [blame] | 384 | bool ExtensionInstallPrompt::Prompt::ShouldShowExplanationText() const { |
dcheng | c704794 | 2014-08-26 05:05:31 | [diff] [blame] | 385 | return type_ == INSTALL_PROMPT && extension_->is_extension() && |
| 386 | experiment_.get() && experiment_->text_only(); |
[email protected] | 62a28d7c | 2013-12-28 01:34:49 | [diff] [blame] | 387 | } |
| 388 | |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 389 | bool ExtensionInstallPrompt::Prompt::HasAcceptButtonLabel() const { |
reillyg | c64d3dd | 2014-09-29 21:10:11 | [diff] [blame] | 390 | if (type_ == POST_INSTALL_PERMISSIONS_PROMPT) |
| 391 | return ShouldDisplayRevokeButton(); |
| 392 | |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 393 | if (kAcceptButtonIds[type_] == 0) |
| 394 | return false; |
| 395 | |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 396 | return true; |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 397 | } |
| 398 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 399 | base::string16 ExtensionInstallPrompt::Prompt::GetAcceptButtonLabel() const { |
[email protected] | 84660601 | 2012-10-19 18:42:25 | [diff] [blame] | 400 | if (type_ == EXTERNAL_INSTALL_PROMPT) { |
| 401 | int id = -1; |
| 402 | if (extension_->is_app()) |
| 403 | id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_APP; |
| 404 | else if (extension_->is_theme()) |
| 405 | id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_THEME; |
| 406 | else |
| 407 | id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_EXTENSION; |
| 408 | return l10n_util::GetStringUTF16(id); |
reillyg | c64d3dd | 2014-09-29 21:10:11 | [diff] [blame] | 409 | } else if (type_ == POST_INSTALL_PERMISSIONS_PROMPT) { |
| 410 | int id = -1; |
| 411 | if (GetRetainedFileCount() && GetRetainedDeviceCount()) { |
| 412 | id = |
| 413 | IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_AND_DEVICES_BUTTON; |
| 414 | } else if (GetRetainedFileCount()) { |
| 415 | id = IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_BUTTON; |
| 416 | } else { |
| 417 | DCHECK_LT(0U, GetRetainedDeviceCount()); |
| 418 | id = IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_DEVICES_BUTTON; |
| 419 | } |
| 420 | return l10n_util::GetStringUTF16(id); |
[email protected] | 84660601 | 2012-10-19 18:42:25 | [diff] [blame] | 421 | } |
[email protected] | 62a28d7c | 2013-12-28 01:34:49 | [diff] [blame] | 422 | if (ShouldShowExplanationText()) |
| 423 | return experiment_->GetOkButtonText(); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 424 | return l10n_util::GetStringUTF16(kAcceptButtonIds[type_]); |
| 425 | } |
| 426 | |
| 427 | bool ExtensionInstallPrompt::Prompt::HasAbortButtonLabel() const { |
[email protected] | 62a28d7c | 2013-12-28 01:34:49 | [diff] [blame] | 428 | if (ShouldShowExplanationText()) |
| 429 | return true; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 430 | return kAbortButtonIds[type_] > 0; |
| 431 | } |
| 432 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 433 | base::string16 ExtensionInstallPrompt::Prompt::GetAbortButtonLabel() const { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 434 | CHECK(HasAbortButtonLabel()); |
[email protected] | 62a28d7c | 2013-12-28 01:34:49 | [diff] [blame] | 435 | if (ShouldShowExplanationText()) |
| 436 | return experiment_->GetCancelButtonText(); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 437 | return l10n_util::GetStringUTF16(kAbortButtonIds[type_]); |
| 438 | } |
| 439 | |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 440 | base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsHeading( |
| 441 | PermissionsType permissions_type) const { |
| 442 | switch (permissions_type) { |
| 443 | case REGULAR_PERMISSIONS: |
| 444 | return l10n_util::GetStringUTF16(kPermissionsHeaderIds[type_]); |
| 445 | case WITHHELD_PERMISSIONS: |
| 446 | return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WITHHELD); |
| 447 | case ALL_PERMISSIONS: |
| 448 | default: |
| 449 | NOTREACHED(); |
| 450 | return base::string16(); |
| 451 | } |
[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::GetRetainedFilesHeading() const { |
[email protected] | 4f1e108 | 2013-09-23 10:30:53 | [diff] [blame] | 455 | const int kRetainedFilesMessageIDs[6] = { |
| 456 | IDS_EXTENSION_PROMPT_RETAINED_FILES_DEFAULT, |
| 457 | IDS_EXTENSION_PROMPT_RETAINED_FILE_SINGULAR, |
| 458 | IDS_EXTENSION_PROMPT_RETAINED_FILES_ZERO, |
| 459 | IDS_EXTENSION_PROMPT_RETAINED_FILES_TWO, |
| 460 | IDS_EXTENSION_PROMPT_RETAINED_FILES_FEW, |
| 461 | IDS_EXTENSION_PROMPT_RETAINED_FILES_MANY, |
| 462 | }; |
reillyg | c64d3dd | 2014-09-29 21:10:11 | [diff] [blame] | 463 | std::vector<int> message_ids( |
| 464 | kRetainedFilesMessageIDs, |
| 465 | kRetainedFilesMessageIDs + arraysize(kRetainedFilesMessageIDs)); |
| 466 | |
[email protected] | 4f1e108 | 2013-09-23 10:30:53 | [diff] [blame] | 467 | return l10n_util::GetPluralStringFUTF16(message_ids, GetRetainedFileCount()); |
[email protected] | 8ab7e6c | 2013-07-11 21:15:03 | [diff] [blame] | 468 | } |
| 469 | |
reillyg | c64d3dd | 2014-09-29 21:10:11 | [diff] [blame] | 470 | base::string16 ExtensionInstallPrompt::Prompt::GetRetainedDevicesHeading() |
| 471 | const { |
| 472 | const int kRetainedDevicesMessageIDs[6] = { |
| 473 | IDS_EXTENSION_PROMPT_RETAINED_DEVICES_DEFAULT, |
| 474 | IDS_EXTENSION_PROMPT_RETAINED_DEVICE_SINGULAR, |
| 475 | IDS_EXTENSION_PROMPT_RETAINED_DEVICES_ZERO, |
| 476 | IDS_EXTENSION_PROMPT_RETAINED_DEVICES_TWO, |
| 477 | IDS_EXTENSION_PROMPT_RETAINED_DEVICES_FEW, |
| 478 | IDS_EXTENSION_PROMPT_RETAINED_DEVICES_MANY, |
| 479 | }; |
| 480 | std::vector<int> message_ids( |
| 481 | kRetainedDevicesMessageIDs, |
| 482 | kRetainedDevicesMessageIDs + arraysize(kRetainedDevicesMessageIDs)); |
| 483 | |
| 484 | return l10n_util::GetPluralStringFUTF16(message_ids, |
| 485 | GetRetainedDeviceCount()); |
| 486 | } |
| 487 | |
[email protected] | f2cd899 | 2013-06-11 17:30:18 | [diff] [blame] | 488 | bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 489 | return GetPermissionCount(ALL_PERMISSIONS) > 0 || |
| 490 | type_ == POST_INSTALL_PERMISSIONS_PROMPT; |
[email protected] | f2cd899 | 2013-06-11 17:30:18 | [diff] [blame] | 491 | } |
| 492 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 493 | void ExtensionInstallPrompt::Prompt::AppendRatingStars( |
| 494 | StarAppender appender, void* data) const { |
| 495 | CHECK(appender); |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 496 | CHECK(AllowWebstoreData(type_)); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 497 | int rating_integer = floor(average_rating_); |
| 498 | double rating_fractional = average_rating_ - rating_integer; |
| 499 | |
| 500 | if (rating_fractional > 0.66) { |
| 501 | rating_integer++; |
| 502 | } |
| 503 | |
| 504 | if (rating_fractional < 0.33 || rating_fractional > 0.66) { |
| 505 | rating_fractional = 0; |
| 506 | } |
| 507 | |
| 508 | ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 509 | int i; |
| 510 | for (i = 0; i < rating_integer; i++) { |
| 511 | appender(rb.GetImageSkiaNamed(IDR_EXTENSIONS_RATING_STAR_ON), data); |
| 512 | } |
| 513 | if (rating_fractional) { |
| 514 | appender(rb.GetImageSkiaNamed(IDR_EXTENSIONS_RATING_STAR_HALF_LEFT), data); |
| 515 | i++; |
| 516 | } |
| 517 | for (; i < kMaxExtensionRating; i++) { |
| 518 | appender(rb.GetImageSkiaNamed(IDR_EXTENSIONS_RATING_STAR_OFF), data); |
| 519 | } |
| 520 | } |
| 521 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 522 | base::string16 ExtensionInstallPrompt::Prompt::GetRatingCount() const { |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 523 | CHECK(AllowWebstoreData(type_)); |
[email protected] | 6725048e | 2013-10-24 21:47:14 | [diff] [blame] | 524 | return l10n_util::GetStringFUTF16(IDS_EXTENSION_RATING_COUNT, |
| 525 | base::IntToString16(rating_count_)); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 526 | } |
| 527 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 528 | base::string16 ExtensionInstallPrompt::Prompt::GetUserCount() const { |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 529 | CHECK(AllowWebstoreData(type_)); |
[email protected] | dcde34b3 | 2013-07-31 02:28:45 | [diff] [blame] | 530 | |
| 531 | if (show_user_count_) { |
[email protected] | 6725048e | 2013-10-24 21:47:14 | [diff] [blame] | 532 | return l10n_util::GetStringFUTF16(IDS_EXTENSION_USER_COUNT, |
| 533 | base::UTF8ToUTF16(localized_user_count_)); |
[email protected] | dcde34b3 | 2013-07-31 02:28:45 | [diff] [blame] | 534 | } |
[email protected] | 6725048e | 2013-10-24 21:47:14 | [diff] [blame] | 535 | return base::string16(); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 536 | } |
| 537 | |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 538 | size_t ExtensionInstallPrompt::Prompt::GetPermissionCount( |
| 539 | PermissionsType permissions_type) const { |
| 540 | switch (permissions_type) { |
| 541 | case REGULAR_PERMISSIONS: |
| 542 | return prompt_permissions_.permissions.size(); |
| 543 | case WITHHELD_PERMISSIONS: |
| 544 | return withheld_prompt_permissions_.permissions.size(); |
| 545 | case ALL_PERMISSIONS: |
| 546 | return prompt_permissions_.permissions.size() + |
| 547 | withheld_prompt_permissions_.permissions.size(); |
| 548 | default: |
| 549 | NOTREACHED(); |
| 550 | return 0u; |
| 551 | } |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 552 | } |
| 553 | |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 554 | size_t ExtensionInstallPrompt::Prompt::GetPermissionsDetailsCount( |
| 555 | PermissionsType permissions_type) const { |
| 556 | switch (permissions_type) { |
| 557 | case REGULAR_PERMISSIONS: |
| 558 | return prompt_permissions_.details.size(); |
| 559 | case WITHHELD_PERMISSIONS: |
| 560 | return withheld_prompt_permissions_.details.size(); |
| 561 | case ALL_PERMISSIONS: |
| 562 | return prompt_permissions_.details.size() + |
| 563 | withheld_prompt_permissions_.details.size(); |
| 564 | default: |
| 565 | NOTREACHED(); |
| 566 | return 0u; |
| 567 | } |
[email protected] | 8ab7e6c | 2013-07-11 21:15:03 | [diff] [blame] | 568 | } |
| 569 | |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 570 | base::string16 ExtensionInstallPrompt::Prompt::GetPermission( |
| 571 | size_t index, |
| 572 | PermissionsType permissions_type) const { |
| 573 | const InstallPromptPermissions& install_permissions = |
| 574 | GetPermissionsForType(permissions_type); |
| 575 | CHECK_LT(index, install_permissions.permissions.size()); |
| 576 | return install_permissions.permissions[index]; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 577 | } |
| 578 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 579 | base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsDetails( |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 580 | size_t index, |
| 581 | PermissionsType permissions_type) const { |
| 582 | const InstallPromptPermissions& install_permissions = |
| 583 | GetPermissionsForType(permissions_type); |
| 584 | CHECK_LT(index, install_permissions.details.size()); |
| 585 | return install_permissions.details[index]; |
[email protected] | 8ab7e6c | 2013-07-11 21:15:03 | [diff] [blame] | 586 | } |
| 587 | |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 588 | bool ExtensionInstallPrompt::Prompt::GetIsShowingDetails( |
| 589 | DetailsType type, size_t index) const { |
| 590 | switch (type) { |
| 591 | case PERMISSIONS_DETAILS: |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 592 | CHECK_LT(index, prompt_permissions_.is_showing_details.size()); |
| 593 | return prompt_permissions_.is_showing_details[index]; |
| 594 | case WITHHELD_PERMISSIONS_DETAILS: |
| 595 | CHECK_LT(index, withheld_prompt_permissions_.is_showing_details.size()); |
| 596 | return withheld_prompt_permissions_.is_showing_details[index]; |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 597 | case RETAINED_FILES_DETAILS: |
| 598 | return is_showing_details_for_retained_files_; |
reillyg | c64d3dd | 2014-09-29 21:10:11 | [diff] [blame] | 599 | case RETAINED_DEVICES_DETAILS: |
| 600 | return is_showing_details_for_retained_devices_; |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 601 | } |
| 602 | return false; |
| 603 | } |
| 604 | |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 605 | size_t ExtensionInstallPrompt::Prompt::GetRetainedFileCount() const { |
| 606 | return retained_files_.size(); |
| 607 | } |
| 608 | |
[email protected] | 6a72a63 | 2013-12-12 22:22:00 | [diff] [blame] | 609 | base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFile(size_t index) |
| 610 | const { |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 611 | CHECK_LT(index, retained_files_.size()); |
[email protected] | 6725048e | 2013-10-24 21:47:14 | [diff] [blame] | 612 | return retained_files_[index].AsUTF16Unsafe(); |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 613 | } |
| 614 | |
reillyg | c64d3dd | 2014-09-29 21:10:11 | [diff] [blame] | 615 | size_t ExtensionInstallPrompt::Prompt::GetRetainedDeviceCount() const { |
| 616 | return retained_device_messages_.size(); |
| 617 | } |
| 618 | |
| 619 | base::string16 ExtensionInstallPrompt::Prompt::GetRetainedDeviceMessageString( |
| 620 | size_t index) const { |
| 621 | CHECK_LT(index, retained_device_messages_.size()); |
| 622 | return retained_device_messages_[index]; |
| 623 | } |
| 624 | |
| 625 | bool ExtensionInstallPrompt::Prompt::ShouldDisplayRevokeButton() const { |
| 626 | return !retained_files_.empty() || !retained_device_messages_.empty(); |
| 627 | } |
| 628 | |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 629 | ExtensionInstallPrompt::Prompt::InstallPromptPermissions& |
| 630 | ExtensionInstallPrompt::Prompt::GetPermissionsForType( |
| 631 | PermissionsType permissions_type) { |
| 632 | DCHECK_NE(ALL_PERMISSIONS, permissions_type); |
| 633 | return permissions_type == REGULAR_PERMISSIONS ? prompt_permissions_ |
| 634 | : withheld_prompt_permissions_; |
| 635 | } |
| 636 | |
| 637 | const ExtensionInstallPrompt::Prompt::InstallPromptPermissions& |
| 638 | ExtensionInstallPrompt::Prompt::GetPermissionsForType( |
| 639 | PermissionsType permissions_type) const { |
| 640 | DCHECK_NE(ALL_PERMISSIONS, permissions_type); |
| 641 | return permissions_type == REGULAR_PERMISSIONS ? prompt_permissions_ |
| 642 | : withheld_prompt_permissions_; |
| 643 | } |
| 644 | |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 645 | bool ExtensionInstallPrompt::Prompt::ShouldDisplayRevokeFilesButton() const { |
| 646 | return !retained_files_.empty(); |
| 647 | } |
| 648 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 649 | // static |
| 650 | scoped_refptr<Extension> |
| 651 | ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 652 | const base::DictionaryValue* manifest, |
[email protected] | c422a86 | 2012-07-31 15:46:13 | [diff] [blame] | 653 | int flags, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 654 | const std::string& id, |
| 655 | const std::string& localized_name, |
| 656 | const std::string& localized_description, |
| 657 | std::string* error) { |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 658 | scoped_ptr<base::DictionaryValue> localized_manifest; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 659 | if (!localized_name.empty() || !localized_description.empty()) { |
| 660 | localized_manifest.reset(manifest->DeepCopy()); |
| 661 | if (!localized_name.empty()) { |
[email protected] | 6bf9061 | 2013-08-15 00:36:27 | [diff] [blame] | 662 | localized_manifest->SetString(extensions::manifest_keys::kName, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 663 | localized_name); |
| 664 | } |
| 665 | if (!localized_description.empty()) { |
[email protected] | 6bf9061 | 2013-08-15 00:36:27 | [diff] [blame] | 666 | localized_manifest->SetString(extensions::manifest_keys::kDescription, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 667 | localized_description); |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | return Extension::Create( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 672 | base::FilePath(), |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 673 | Manifest::INTERNAL, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 674 | localized_manifest.get() ? *localized_manifest.get() : *manifest, |
[email protected] | c422a86 | 2012-07-31 15:46:13 | [diff] [blame] | 675 | flags, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 676 | id, |
| 677 | error); |
| 678 | } |
| 679 | |
[email protected] | 7f16534 | 2014-02-12 09:22:22 | [diff] [blame] | 680 | ExtensionInstallPrompt::ExtensionInstallPrompt(content::WebContents* contents) |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 681 | : profile_(ProfileForWebContents(contents)), |
| 682 | ui_loop_(base::MessageLoop::current()), |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 683 | extension_(NULL), |
[email protected] | 7f16534 | 2014-02-12 09:22:22 | [diff] [blame] | 684 | bundle_(NULL), |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 685 | install_ui_(extensions::CreateExtensionInstallUI( |
| 686 | ProfileForWebContents(contents))), |
pkotwicz | 2f18178 | 2014-10-29 17:33:45 | [diff] [blame] | 687 | show_params_(new ExtensionInstallPromptShowParams(contents)), |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 688 | delegate_(NULL) { |
| 689 | } |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 690 | |
pkotwicz | 2175c62 | 2014-10-22 19:56:28 | [diff] [blame] | 691 | ExtensionInstallPrompt::ExtensionInstallPrompt(Profile* profile, |
| 692 | gfx::NativeWindow native_window) |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 693 | : profile_(profile), |
| 694 | ui_loop_(base::MessageLoop::current()), |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 695 | extension_(NULL), |
[email protected] | 7f16534 | 2014-02-12 09:22:22 | [diff] [blame] | 696 | bundle_(NULL), |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 697 | install_ui_(extensions::CreateExtensionInstallUI(profile)), |
pkotwicz | 2f18178 | 2014-10-29 17:33:45 | [diff] [blame] | 698 | show_params_( |
| 699 | new ExtensionInstallPromptShowParams(profile, native_window)), |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 700 | delegate_(NULL) { |
| 701 | } |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 702 | |
| 703 | ExtensionInstallPrompt::~ExtensionInstallPrompt() { |
| 704 | } |
| 705 | |
| 706 | void ExtensionInstallPrompt::ConfirmBundleInstall( |
| 707 | extensions::BundleInstaller* bundle, |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 708 | const PermissionSet* permissions) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 709 | DCHECK(ui_loop_ == base::MessageLoop::current()); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 710 | bundle_ = bundle; |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 711 | custom_permissions_ = permissions; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 712 | delegate_ = bundle; |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 713 | prompt_ = new Prompt(BUNDLE_INSTALL_PROMPT); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 714 | |
[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 | |
[email protected] | 734bcec | 2012-10-08 20:29:05 | [diff] [blame] | 718 | void ExtensionInstallPrompt::ConfirmStandaloneInstall( |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 719 | Delegate* delegate, |
| 720 | const Extension* extension, |
| 721 | SkBitmap* icon, |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 722 | scoped_refptr<Prompt> prompt) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 723 | DCHECK(ui_loop_ == base::MessageLoop::current()); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 724 | extension_ = extension; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 725 | delegate_ = delegate; |
| 726 | prompt_ = prompt; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 727 | |
| 728 | SetIcon(icon); |
[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 | |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 732 | void ExtensionInstallPrompt::ConfirmWebstoreInstall( |
| 733 | Delegate* delegate, |
| 734 | const Extension* extension, |
| 735 | const SkBitmap* icon, |
| 736 | const ShowDialogCallback& show_dialog_callback) { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 737 | // SetIcon requires |extension_| to be set. ConfirmInstall will setup the |
| 738 | // remaining fields. |
| 739 | extension_ = extension; |
| 740 | SetIcon(icon); |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 741 | ConfirmInstall(delegate, extension, show_dialog_callback); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 742 | } |
| 743 | |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 744 | void ExtensionInstallPrompt::ConfirmInstall( |
| 745 | Delegate* delegate, |
| 746 | const Extension* extension, |
| 747 | const ShowDialogCallback& show_dialog_callback) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 748 | DCHECK(ui_loop_ == base::MessageLoop::current()); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 749 | extension_ = extension; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 750 | delegate_ = delegate; |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 751 | prompt_ = new Prompt(INSTALL_PROMPT); |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 752 | show_dialog_callback_ = show_dialog_callback; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 753 | |
| 754 | // We special-case themes to not show any confirm UI. Instead they are |
| 755 | // immediately installed, and then we show an infobar (see OnInstallSuccess) |
| 756 | // to allow the user to revert if they don't like it. |
| 757 | // |
| 758 | // We don't do this in the case where off-store extension installs are |
| 759 | // disabled because in that case, we don't show the dangerous download UI, so |
| 760 | // we need the UI confirmation. |
| 761 | if (extension->is_theme()) { |
| 762 | if (extension->from_webstore() || |
[email protected] | 544471a | 2012-10-13 05:27:09 | [diff] [blame] | 763 | extensions::FeatureSwitch::easy_off_store_install()->IsEnabled()) { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 764 | delegate->InstallUIProceed(); |
| 765 | return; |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | LoadImageIfNeeded(); |
| 770 | } |
| 771 | |
treib | 2d2f537 | 2015-03-01 12:20:49 | [diff] [blame] | 772 | void ExtensionInstallPrompt::ConfirmPermissionsForDelegatedInstall( |
| 773 | Delegate* delegate, |
| 774 | const Extension* extension, |
| 775 | const std::string& delegated_username, |
| 776 | const SkBitmap* icon) { |
| 777 | DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 778 | delegate_ = delegate; |
| 779 | extension_ = extension; |
| 780 | delegated_username_ = delegated_username; |
| 781 | SetIcon(icon); |
| 782 | prompt_ = new Prompt(DELEGATED_PERMISSIONS_PROMPT); |
| 783 | ShowConfirmation(); |
| 784 | } |
| 785 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 786 | void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate, |
| 787 | const Extension* extension) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 788 | DCHECK(ui_loop_ == base::MessageLoop::current()); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 789 | extension_ = extension; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 790 | delegate_ = delegate; |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 791 | bool is_remote_install = |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 792 | profile_ && |
| 793 | extensions::ExtensionPrefs::Get(profile_)->HasDisableReason( |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 794 | extension->id(), extensions::Extension::DISABLE_REMOTE_INSTALL); |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 795 | bool is_ephemeral = |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 796 | extensions::util::IsEphemeralApp(extension->id(), profile_); |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 797 | |
| 798 | PromptType type = UNSET_PROMPT_TYPE; |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 799 | if (is_ephemeral) |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 800 | type = LAUNCH_PROMPT; |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 801 | else if (is_remote_install) |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 802 | type = REMOTE_INSTALL_PROMPT; |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 803 | else |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 804 | type = RE_ENABLE_PROMPT; |
| 805 | prompt_ = new Prompt(type); |
| 806 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 807 | LoadImageIfNeeded(); |
| 808 | } |
| 809 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 810 | void ExtensionInstallPrompt::ConfirmExternalInstall( |
[email protected] | c8ff7c9e | 2013-04-20 12:36:27 | [diff] [blame] | 811 | Delegate* delegate, |
| 812 | const Extension* extension, |
[email protected] | 34b5f7f | 2014-01-29 02:48:11 | [diff] [blame] | 813 | const ShowDialogCallback& show_dialog_callback, |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 814 | scoped_refptr<Prompt> prompt) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 815 | DCHECK(ui_loop_ == base::MessageLoop::current()); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 816 | extension_ = extension; |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 817 | delegate_ = delegate; |
[email protected] | 34b5f7f | 2014-01-29 02:48:11 | [diff] [blame] | 818 | prompt_ = prompt; |
[email protected] | c8ff7c9e | 2013-04-20 12:36:27 | [diff] [blame] | 819 | show_dialog_callback_ = show_dialog_callback; |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 820 | |
| 821 | LoadImageIfNeeded(); |
| 822 | } |
| 823 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 824 | void ExtensionInstallPrompt::ConfirmPermissions( |
| 825 | Delegate* delegate, |
| 826 | const Extension* extension, |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 827 | const PermissionSet* permissions) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 828 | DCHECK(ui_loop_ == base::MessageLoop::current()); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 829 | extension_ = extension; |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 830 | custom_permissions_ = permissions; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 831 | delegate_ = delegate; |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 832 | prompt_ = new Prompt(PERMISSIONS_PROMPT); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 833 | |
| 834 | LoadImageIfNeeded(); |
| 835 | } |
| 836 | |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 837 | void ExtensionInstallPrompt::ReviewPermissions( |
| 838 | Delegate* delegate, |
| 839 | const Extension* extension, |
reillyg | c64d3dd | 2014-09-29 21:10:11 | [diff] [blame] | 840 | const std::vector<base::FilePath>& retained_file_paths, |
| 841 | const std::vector<base::string16>& retained_device_messages) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 842 | DCHECK(ui_loop_ == base::MessageLoop::current()); |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 843 | extension_ = extension; |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 844 | prompt_ = new Prompt(POST_INSTALL_PERMISSIONS_PROMPT); |
| 845 | prompt_->set_retained_files(retained_file_paths); |
reillyg | c64d3dd | 2014-09-29 21:10:11 | [diff] [blame] | 846 | prompt_->set_retained_device_messages(retained_device_messages); |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 847 | delegate_ = delegate; |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 848 | |
| 849 | LoadImageIfNeeded(); |
| 850 | } |
| 851 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 852 | void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, |
| 853 | SkBitmap* icon) { |
| 854 | extension_ = extension; |
| 855 | SetIcon(icon); |
| 856 | |
| 857 | install_ui_->OnInstallSuccess(extension, &icon_); |
| 858 | } |
| 859 | |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 860 | void ExtensionInstallPrompt::OnInstallFailure( |
ginkage | 47e603e | 2015-02-27 08:42:41 | [diff] [blame] | 861 | const extensions::CrxInstallError& error) { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 862 | install_ui_->OnInstallFailure(error); |
| 863 | } |
| 864 | |
| 865 | void ExtensionInstallPrompt::SetIcon(const SkBitmap* image) { |
| 866 | if (image) |
| 867 | icon_ = *image; |
| 868 | else |
| 869 | icon_ = SkBitmap(); |
[email protected] | dd46a4ce | 2012-09-15 10:50:50 | [diff] [blame] | 870 | if (icon_.empty()) { |
| 871 | // Let's set default icon bitmap whose size is equal to the default icon's |
| 872 | // pixel size under maximal supported scale factor. If the bitmap is larger |
| 873 | // than the one we need, it will be scaled down by the ui code. |
| 874 | icon_ = GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app()); |
| 875 | } |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 876 | } |
| 877 | |
[email protected] | ec7de0c5a | 2012-11-16 07:40:47 | [diff] [blame] | 878 | void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image) { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 879 | SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); |
[email protected] | 4e49487 | 2013-09-06 09:13:54 | [diff] [blame] | 880 | ShowConfirmation(); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | void ExtensionInstallPrompt::LoadImageIfNeeded() { |
| 884 | // Bundle install prompts do not have an icon. |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 885 | // Also |profile_| can be NULL in unit tests. |
| 886 | if (!icon_.empty() || !profile_) { |
[email protected] | 4e49487 | 2013-09-06 09:13:54 | [diff] [blame] | 887 | ShowConfirmation(); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 888 | return; |
| 889 | } |
| 890 | |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 891 | extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( |
[email protected] | 702d8b4 | 2013-02-27 20:55:50 | [diff] [blame] | 892 | extension_, |
| 893 | extension_misc::EXTENSION_ICON_LARGE, |
| 894 | ExtensionIconSet::MATCH_BIGGER); |
[email protected] | 0d0ba18 | 2014-06-03 12:40:43 | [diff] [blame] | 895 | |
| 896 | // Load the image asynchronously. The response will be sent to OnImageLoaded. |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 897 | extensions::ImageLoader* loader = extensions::ImageLoader::Get(profile_); |
[email protected] | 0d0ba18 | 2014-06-03 12:40:43 | [diff] [blame] | 898 | |
| 899 | std::vector<extensions::ImageLoader::ImageRepresentation> images_list; |
| 900 | images_list.push_back(extensions::ImageLoader::ImageRepresentation( |
| 901 | image, |
| 902 | extensions::ImageLoader::ImageRepresentation::NEVER_RESIZE, |
| 903 | gfx::Size(), |
| 904 | ui::SCALE_FACTOR_100P)); |
| 905 | loader->LoadImagesAsync( |
| 906 | extension_, |
| 907 | images_list, |
[email protected] | ec7de0c5a | 2012-11-16 07:40:47 | [diff] [blame] | 908 | base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | void ExtensionInstallPrompt::ShowConfirmation() { |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 912 | if (prompt_->type() == INSTALL_PROMPT) |
| 913 | prompt_->set_experiment(ExtensionInstallPromptExperiment::Find()); |
[email protected] | 62a28d7c | 2013-12-28 01:34:49 | [diff] [blame] | 914 | else |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 915 | prompt_->set_experiment(ExtensionInstallPromptExperiment::ControlGroup()); |
[email protected] | 62a28d7c | 2013-12-28 01:34:49 | [diff] [blame] | 916 | |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 917 | scoped_refptr<const PermissionSet> permissions_to_display; |
| 918 | if (custom_permissions_.get()) { |
| 919 | permissions_to_display = custom_permissions_; |
| 920 | } else if (extension_) { |
| 921 | // Initialize permissions if they have not already been set so that |
| 922 | // withheld permissions are displayed properly in the install prompt. |
| 923 | extensions::PermissionsUpdater( |
pkotwicz | a57a1f32 | 2014-10-21 00:24:30 | [diff] [blame] | 924 | profile_, extensions::PermissionsUpdater::INIT_FLAG_TRANSIENT) |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 925 | .InitializePermissions(extension_); |
| 926 | permissions_to_display = |
| 927 | extension_->permissions_data()->active_permissions(); |
treib | 7496f63c | 2015-03-04 12:18:53 | [diff] [blame^] | 928 | // For delegated installs, all optional permissions are pre-approved by the |
| 929 | // person who triggers the install, so add them to the list. |
| 930 | if (prompt_->type() == DELEGATED_PERMISSIONS_PROMPT) { |
| 931 | scoped_refptr<const PermissionSet> optional_permissions = |
| 932 | extensions::PermissionsParser::GetOptionalPermissions(extension_); |
| 933 | permissions_to_display = PermissionSet::CreateUnion( |
| 934 | permissions_to_display.get(), |
| 935 | optional_permissions.get()); |
| 936 | } |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | if (permissions_to_display.get() && |
[email protected] | a397ec0 | 2014-08-08 15:48:13 | [diff] [blame] | 940 | (!extension_ || |
| 941 | !extensions::PermissionsData::ShouldSkipPermissionWarnings( |
| 942 | extension_->id()))) { |
| 943 | Manifest::Type type = |
| 944 | extension_ ? extension_->GetType() : Manifest::TYPE_UNKNOWN; |
| 945 | const extensions::PermissionMessageProvider* message_provider = |
| 946 | extensions::PermissionMessageProvider::Get(); |
gpdavis.chromium | 0fbac4d | 2014-09-19 20:57:54 | [diff] [blame] | 947 | prompt_->SetPermissions(message_provider->GetWarningMessages( |
| 948 | permissions_to_display.get(), type), |
| 949 | REGULAR_PERMISSIONS); |
| 950 | prompt_->SetPermissionsDetails(message_provider->GetWarningMessagesDetails( |
| 951 | permissions_to_display.get(), type), |
| 952 | REGULAR_PERMISSIONS); |
| 953 | |
| 954 | scoped_refptr<const extensions::PermissionSet> withheld = |
| 955 | extension_->permissions_data()->withheld_permissions(); |
| 956 | if (!withheld->IsEmpty()) { |
| 957 | prompt_->SetPermissions( |
| 958 | message_provider->GetWarningMessages(withheld.get(), type), |
| 959 | PermissionsType::WITHHELD_PERMISSIONS); |
| 960 | prompt_->SetPermissionsDetails( |
| 961 | message_provider->GetWarningMessagesDetails(withheld.get(), type), |
| 962 | PermissionsType::WITHHELD_PERMISSIONS); |
| 963 | } |
[email protected] | bebe1d0 | 2012-08-02 20:17:09 | [diff] [blame] | 964 | } |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 965 | |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 966 | switch (prompt_->type()) { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 967 | case PERMISSIONS_PROMPT: |
| 968 | case RE_ENABLE_PROMPT: |
| 969 | case INLINE_INSTALL_PROMPT: |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 970 | case EXTERNAL_INSTALL_PROMPT: |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 971 | case INSTALL_PROMPT: |
[email protected] | 1a93d8d | 2013-10-27 23:09:20 | [diff] [blame] | 972 | case LAUNCH_PROMPT: |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 973 | case POST_INSTALL_PERMISSIONS_PROMPT: |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 974 | case REMOTE_INSTALL_PROMPT: |
treib | 2d2f537 | 2015-03-01 12:20:49 | [diff] [blame] | 975 | case REPAIR_PROMPT: |
| 976 | case DELEGATED_PERMISSIONS_PROMPT: { |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 977 | prompt_->set_extension(extension_); |
| 978 | prompt_->set_icon(gfx::Image::CreateFrom1xBitmap(icon_)); |
treib | 2d2f537 | 2015-03-01 12:20:49 | [diff] [blame] | 979 | prompt_->set_delegated_username(delegated_username_); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 980 | break; |
| 981 | } |
| 982 | case BUNDLE_INSTALL_PROMPT: { |
[email protected] | d382baa | 2014-06-17 18:50:01 | [diff] [blame] | 983 | prompt_->set_bundle(bundle_); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 984 | break; |
| 985 | } |
| 986 | default: |
| 987 | NOTREACHED() << "Unknown message"; |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 988 | return; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 989 | } |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 990 | |
rdevlin.cronin | 092c677 | 2014-11-20 23:52:40 | [diff] [blame] | 991 | g_last_prompt_type_for_tests = prompt_->type(); |
| 992 | |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 993 | if (AutoConfirmPrompt(delegate_)) |
| 994 | return; |
| 995 | |
pkotwicz | 2f18178 | 2014-10-29 17:33:45 | [diff] [blame] | 996 | if (show_params_->WasParentDestroyed()) { |
| 997 | delegate_->InstallUIAbort(false); |
| 998 | return; |
| 999 | } |
| 1000 | |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 1001 | if (show_dialog_callback_.is_null()) |
pkotwicz | 2f18178 | 2014-10-29 17:33:45 | [diff] [blame] | 1002 | GetDefaultShowDialogCallback().Run(show_params_.get(), delegate_, prompt_); |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 1003 | else |
pkotwicz | 2f18178 | 2014-10-29 17:33:45 | [diff] [blame] | 1004 | show_dialog_callback_.Run(show_params_.get(), delegate_, prompt_); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 1005 | } |