[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" |
[email protected] | 00e7bef | 2013-06-10 20:35:17 | [diff] [blame] | 13 | #include "base/strings/string_util.h" |
| 14 | #include "base/strings/stringprintf.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 15 | #include "base/strings/utf_string_conversions.h" |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 16 | #include "chrome/browser/extensions/bundle_installer.h" |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 17 | #include "chrome/browser/extensions/extension_install_ui.h" |
[email protected] | ec7de0c5a | 2012-11-16 07:40:47 | [diff] [blame] | 18 | #include "chrome/browser/extensions/image_loader.h" |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 19 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 4f3fb35 | 2013-07-17 04:07:01 | [diff] [blame] | 20 | #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 21 | #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
[email protected] | 32fc4ff7 | 2012-06-15 21:50:01 | [diff] [blame] | 22 | #include "chrome/browser/ui/browser.h" |
[email protected] | 619f8618 | 2012-07-03 21:30:18 | [diff] [blame] | 23 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 24 | #include "chrome/common/chrome_switches.h" |
[email protected] | 29e0c4e7 | 2013-02-01 04:42:56 | [diff] [blame] | 25 | #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 26 | #include "chrome/common/extensions/extension.h" |
[email protected] | faf8719 | 2012-08-17 00:07:59 | [diff] [blame] | 27 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 28 | #include "chrome/common/extensions/extension_icon_set.h" |
[email protected] | 544471a | 2012-10-13 05:27:09 | [diff] [blame] | 29 | #include "chrome/common/extensions/feature_switch.h" |
[email protected] | abe720c0 | 2013-04-12 04:00:10 | [diff] [blame] | 30 | #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
[email protected] | bebe1d0 | 2012-08-02 20:17:09 | [diff] [blame] | 31 | #include "chrome/common/extensions/permissions/permission_set.h" |
[email protected] | 13c68b6 | 2013-05-17 11:29:05 | [diff] [blame] | 32 | #include "chrome/common/extensions/permissions/permissions_data.h" |
[email protected] | fc507794 | 2012-08-15 21:37:59 | [diff] [blame] | 33 | #include "chrome/common/pref_names.h" |
[email protected] | 91e51d61 | 2012-10-21 23:03:05 | [diff] [blame] | 34 | #include "content/public/browser/web_contents.h" |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 35 | #include "content/public/browser/web_contents_view.h" |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 36 | #include "extensions/common/extension_resource.h" |
[email protected] | d42c1115 | 2013-08-22 19:36:32 | [diff] [blame] | 37 | #include "extensions/common/manifest.h" |
[email protected] | 6bf9061 | 2013-08-15 00:36:27 | [diff] [blame] | 38 | #include "extensions/common/manifest_constants.h" |
[email protected] | c4100347 | 2013-10-19 15:37:25 | [diff] [blame] | 39 | #include "extensions/common/permissions/permission_message_provider.h" |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 40 | #include "extensions/common/url_pattern.h" |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 41 | #include "grit/chromium_strings.h" |
| 42 | #include "grit/generated_resources.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" |
| 46 | #include "ui/gfx/image/image.h" |
| 47 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 48 | using extensions::BundleInstaller; |
| 49 | using extensions::Extension; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 50 | using extensions::Manifest; |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 51 | using extensions::PermissionSet; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 52 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 53 | namespace { |
| 54 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 55 | static const int kTitleIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
| 56 | 0, // The regular install prompt depends on what's being installed. |
| 57 | IDS_EXTENSION_INLINE_INSTALL_PROMPT_TITLE, |
| 58 | IDS_EXTENSION_INSTALL_PROMPT_TITLE, |
| 59 | IDS_EXTENSION_RE_ENABLE_PROMPT_TITLE, |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 60 | IDS_EXTENSION_PERMISSIONS_PROMPT_TITLE, |
| 61 | IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_TITLE, |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 62 | IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_TITLE, |
[email protected] | bc123c0 | 2013-10-15 06:41:13 | [diff] [blame] | 63 | IDS_EXTENSION_FIRST_RUN_PROMPT_TITLE, |
[email protected] | 1a93d8d | 2013-10-27 23:09:20 | [diff] [blame^] | 64 | IDS_EXTENSION_LAUNCH_APP_PROMPT_TITLE, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 65 | }; |
| 66 | static const int kHeadingIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
| 67 | IDS_EXTENSION_INSTALL_PROMPT_HEADING, |
| 68 | 0, // Inline installs use the extension name. |
| 69 | 0, // Heading for bundle installs depends on the bundle contents. |
| 70 | IDS_EXTENSION_RE_ENABLE_PROMPT_HEADING, |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 71 | IDS_EXTENSION_PERMISSIONS_PROMPT_HEADING, |
[email protected] | 84660601 | 2012-10-19 18:42:25 | [diff] [blame] | 72 | 0, // External installs use different strings for extensions/apps. |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 73 | IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_HEADING, |
[email protected] | bc123c0 | 2013-10-15 06:41:13 | [diff] [blame] | 74 | IDS_EXTENSION_FIRST_RUN_PROMPT_HEADING, |
[email protected] | 1a93d8d | 2013-10-27 23:09:20 | [diff] [blame^] | 75 | IDS_EXTENSION_LAUNCH_APP_PROMPT_HEADING, |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 76 | }; |
| 77 | static const int kButtons[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
| 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, |
| 84 | ui::DIALOG_BUTTON_CANCEL, |
[email protected] | aa5a547 | 2013-10-04 03:41:04 | [diff] [blame] | 85 | ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
[email protected] | 1a93d8d | 2013-10-27 23:09:20 | [diff] [blame^] | 86 | ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 87 | }; |
| 88 | static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
| 89 | IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
| 90 | IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
| 91 | IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
| 92 | IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON, |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 93 | IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON, |
[email protected] | 84660601 | 2012-10-19 18:42:25 | [diff] [blame] | 94 | 0, // External installs use different strings for extensions/apps. |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 95 | IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_BUTTON, |
[email protected] | 1a93d8d | 2013-10-27 23:09:20 | [diff] [blame^] | 96 | IDS_EXTENSION_PROMPT_FIRST_RUN_ACCEPT_BUTTON, |
| 97 | IDS_EXTENSION_PROMPT_LAUNCH_BUTTON, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 98 | }; |
| 99 | static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
| 100 | 0, // These all use the platform's default cancel label. |
| 101 | 0, |
| 102 | 0, |
| 103 | 0, |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 104 | IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON, |
| 105 | IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ABORT_BUTTON, |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 106 | IDS_CLOSE, |
[email protected] | bc123c0 | 2013-10-15 06:41:13 | [diff] [blame] | 107 | 0, // Platform dependent cancel button. |
[email protected] | 1a93d8d | 2013-10-27 23:09:20 | [diff] [blame^] | 108 | 0, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 109 | }; |
| 110 | static const int kPermissionsHeaderIds[ |
| 111 | ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
| 112 | IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
| 113 | IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
| 114 | IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO, |
| 115 | IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, |
| 116 | IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 117 | IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 118 | IDS_EXTENSION_PROMPT_CAN_ACCESS, |
[email protected] | aa5a547 | 2013-10-04 03:41:04 | [diff] [blame] | 119 | IDS_EXTENSION_PROMPT_CAN_ACCESS, |
[email protected] | 1a93d8d | 2013-10-27 23:09:20 | [diff] [blame^] | 120 | IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 121 | }; |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 122 | static const int kOAuthHeaderIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
[email protected] | fc507794 | 2012-08-15 21:37:59 | [diff] [blame] | 123 | IDS_EXTENSION_PROMPT_OAUTH_HEADER, |
| 124 | 0, // Inline installs don't show OAuth permissions. |
| 125 | 0, // Bundle installs don't show OAuth permissions. |
| 126 | IDS_EXTENSION_PROMPT_OAUTH_REENABLE_HEADER, |
| 127 | IDS_EXTENSION_PROMPT_OAUTH_PERMISSIONS_HEADER, |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 128 | 0, |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 129 | 0, |
[email protected] | aa5a547 | 2013-10-04 03:41:04 | [diff] [blame] | 130 | IDS_EXTENSION_PROMPT_OAUTH_HEADER, |
[email protected] | 1a93d8d | 2013-10-27 23:09:20 | [diff] [blame^] | 131 | IDS_EXTENSION_PROMPT_OAUTH_HEADER, |
[email protected] | fc507794 | 2012-08-15 21:37:59 | [diff] [blame] | 132 | }; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 133 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 134 | // Size of extension icon in top left of dialog. |
| 135 | const int kIconSize = 69; |
| 136 | |
[email protected] | dd46a4ce | 2012-09-15 10:50:50 | [diff] [blame] | 137 | // Returns pixel size under maximal scale factor for the icon whose device |
| 138 | // independent size is |size_in_dip| |
| 139 | int GetSizeForMaxScaleFactor(int size_in_dip) { |
[email protected] | 50b6626 | 2013-09-24 03:25:48 | [diff] [blame] | 140 | return static_cast<int>(size_in_dip * gfx::ImageSkia::GetMaxSupportedScale()); |
[email protected] | dd46a4ce | 2012-09-15 10:50:50 | [diff] [blame] | 141 | } |
| 142 | |
| 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 ? |
| 147 | extensions::IconsInfo::GetDefaultAppIcon() : |
| 148 | extensions::IconsInfo::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) { |
| 156 | const CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
| 157 | if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests)) |
| 158 | return false; |
| 159 | std::string value = cmdline->GetSwitchValueASCII( |
| 160 | switches::kAppsGalleryInstallAutoConfirmForTests); |
| 161 | |
| 162 | // We use PostTask instead of calling the delegate directly here, because in |
| 163 | // the real implementations it's highly likely the message loop will be |
| 164 | // pumping a few times before the user clicks accept or cancel. |
| 165 | if (value == "accept") { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 166 | base::MessageLoop::current()->PostTask( |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 167 | FROM_HERE, |
| 168 | base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIProceed, |
| 169 | base::Unretained(delegate))); |
| 170 | return true; |
| 171 | } |
| 172 | |
| 173 | if (value == "cancel") { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 174 | base::MessageLoop::current()->PostTask( |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 175 | FROM_HERE, |
| 176 | base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIAbort, |
| 177 | base::Unretained(delegate), |
| 178 | true)); |
| 179 | return true; |
| 180 | } |
| 181 | |
| 182 | NOTREACHED(); |
| 183 | return false; |
| 184 | } |
| 185 | |
[email protected] | 91e51d61 | 2012-10-21 23:03:05 | [diff] [blame] | 186 | Profile* ProfileForWebContents(content::WebContents* web_contents) { |
| 187 | if (!web_contents) |
| 188 | return NULL; |
| 189 | return Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 190 | } |
| 191 | |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 192 | gfx::NativeWindow NativeWindowForWebContents(content::WebContents* contents) { |
| 193 | if (!contents) |
| 194 | return NULL; |
| 195 | |
| 196 | return contents->GetView()->GetTopLevelNativeWindow(); |
| 197 | } |
| 198 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 199 | } // namespace |
| 200 | |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 201 | ExtensionInstallPrompt::Prompt::Prompt(PromptType type) |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 202 | : type_(type), |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 203 | is_showing_details_for_retained_files_(false), |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 204 | extension_(NULL), |
| 205 | bundle_(NULL), |
| 206 | average_rating_(0.0), |
[email protected] | dcde34b3 | 2013-07-31 02:28:45 | [diff] [blame] | 207 | rating_count_(0), |
| 208 | show_user_count_(false) { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | ExtensionInstallPrompt::Prompt::~Prompt() { |
| 212 | } |
| 213 | |
| 214 | void ExtensionInstallPrompt::Prompt::SetPermissions( |
| 215 | const std::vector<string16>& permissions) { |
| 216 | permissions_ = permissions; |
| 217 | } |
| 218 | |
[email protected] | 8ab7e6c | 2013-07-11 21:15:03 | [diff] [blame] | 219 | void ExtensionInstallPrompt::Prompt::SetPermissionsDetails( |
| 220 | const std::vector<string16>& details) { |
| 221 | details_ = details; |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 222 | is_showing_details_for_permissions_.clear(); |
| 223 | for (size_t i = 0; i < details.size(); ++i) |
| 224 | is_showing_details_for_permissions_.push_back(false); |
| 225 | } |
| 226 | |
| 227 | void ExtensionInstallPrompt::Prompt::SetIsShowingDetails( |
| 228 | DetailsType type, |
| 229 | size_t index, |
| 230 | bool is_showing_details) { |
| 231 | switch (type) { |
| 232 | case PERMISSIONS_DETAILS: |
| 233 | is_showing_details_for_permissions_[index] = is_showing_details; |
| 234 | break; |
| 235 | case OAUTH_DETAILS: |
| 236 | is_showing_details_for_oauth_[index] = is_showing_details; |
| 237 | break; |
| 238 | case RETAINED_FILES_DETAILS: |
| 239 | is_showing_details_for_retained_files_ = is_showing_details; |
| 240 | break; |
| 241 | } |
[email protected] | 8ab7e6c | 2013-07-11 21:15:03 | [diff] [blame] | 242 | } |
| 243 | |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 244 | void ExtensionInstallPrompt::Prompt::SetOAuthIssueAdvice( |
| 245 | const IssueAdviceInfo& issue_advice) { |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 246 | is_showing_details_for_oauth_.clear(); |
| 247 | for (size_t i = 0; i < issue_advice.size(); ++i) |
| 248 | is_showing_details_for_oauth_.push_back(false); |
| 249 | |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 250 | oauth_issue_advice_ = issue_advice; |
| 251 | } |
| 252 | |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 253 | void ExtensionInstallPrompt::Prompt::SetUserNameFromProfile(Profile* profile) { |
| 254 | // |profile| can be NULL in unit tests. |
| 255 | if (profile) { |
| 256 | oauth_user_name_ = UTF8ToUTF16(profile->GetPrefs()->GetString( |
| 257 | prefs::kGoogleServicesUsername)); |
| 258 | } else { |
| 259 | oauth_user_name_.clear(); |
| 260 | } |
| 261 | } |
| 262 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 263 | void ExtensionInstallPrompt::Prompt::SetInlineInstallWebstoreData( |
| 264 | const std::string& localized_user_count, |
[email protected] | dcde34b3 | 2013-07-31 02:28:45 | [diff] [blame] | 265 | bool show_user_count, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 266 | double average_rating, |
| 267 | int rating_count) { |
| 268 | CHECK_EQ(INLINE_INSTALL_PROMPT, type_); |
| 269 | localized_user_count_ = localized_user_count; |
[email protected] | dcde34b3 | 2013-07-31 02:28:45 | [diff] [blame] | 270 | show_user_count_ = show_user_count; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 271 | average_rating_ = average_rating; |
| 272 | rating_count_ = rating_count; |
| 273 | } |
| 274 | |
| 275 | string16 ExtensionInstallPrompt::Prompt::GetDialogTitle() const { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 276 | int resource_id = kTitleIds[type_]; |
| 277 | |
| 278 | if (type_ == INSTALL_PROMPT) { |
| 279 | if (extension_->is_app()) |
| 280 | resource_id = IDS_EXTENSION_INSTALL_APP_PROMPT_TITLE; |
| 281 | else if (extension_->is_theme()) |
| 282 | resource_id = IDS_EXTENSION_INSTALL_THEME_PROMPT_TITLE; |
| 283 | else |
| 284 | resource_id = IDS_EXTENSION_INSTALL_EXTENSION_PROMPT_TITLE; |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 285 | } else if (type_ == EXTERNAL_INSTALL_PROMPT) { |
| 286 | return l10n_util::GetStringFUTF16( |
| 287 | resource_id, UTF8ToUTF16(extension_->name())); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | return l10n_util::GetStringUTF16(resource_id); |
| 291 | } |
| 292 | |
| 293 | string16 ExtensionInstallPrompt::Prompt::GetHeading() const { |
| 294 | if (type_ == INLINE_INSTALL_PROMPT) { |
| 295 | return UTF8ToUTF16(extension_->name()); |
| 296 | } else if (type_ == BUNDLE_INSTALL_PROMPT) { |
| 297 | return bundle_->GetHeadingTextFor(BundleInstaller::Item::STATE_PENDING); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 298 | } else if (type_ == EXTERNAL_INSTALL_PROMPT) { |
[email protected] | 84660601 | 2012-10-19 18:42:25 | [diff] [blame] | 299 | int resource_id = -1; |
| 300 | if (extension_->is_app()) |
| 301 | resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_APP; |
| 302 | else if (extension_->is_theme()) |
| 303 | resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_THEME; |
| 304 | else |
| 305 | resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_EXTENSION; |
| 306 | return l10n_util::GetStringUTF16(resource_id); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 307 | } else { |
| 308 | return l10n_util::GetStringFUTF16( |
| 309 | kHeadingIds[type_], UTF8ToUTF16(extension_->name())); |
| 310 | } |
| 311 | } |
| 312 | |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 313 | int ExtensionInstallPrompt::Prompt::GetDialogButtons() const { |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 314 | if (type_ == POST_INSTALL_PERMISSIONS_PROMPT && |
| 315 | ShouldDisplayRevokeFilesButton()) { |
| 316 | return kButtons[type_] | ui::DIALOG_BUTTON_OK; |
| 317 | } |
| 318 | |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 319 | return kButtons[type_]; |
| 320 | } |
| 321 | |
| 322 | bool ExtensionInstallPrompt::Prompt::HasAcceptButtonLabel() const { |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 323 | if (kAcceptButtonIds[type_] == 0) |
| 324 | return false; |
| 325 | |
| 326 | if (type_ == POST_INSTALL_PERMISSIONS_PROMPT) |
| 327 | return ShouldDisplayRevokeFilesButton(); |
| 328 | |
| 329 | return true; |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 330 | } |
| 331 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 332 | string16 ExtensionInstallPrompt::Prompt::GetAcceptButtonLabel() const { |
[email protected] | 84660601 | 2012-10-19 18:42:25 | [diff] [blame] | 333 | if (type_ == EXTERNAL_INSTALL_PROMPT) { |
| 334 | int id = -1; |
| 335 | if (extension_->is_app()) |
| 336 | id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_APP; |
| 337 | else if (extension_->is_theme()) |
| 338 | id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_THEME; |
| 339 | else |
| 340 | id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_EXTENSION; |
| 341 | return l10n_util::GetStringUTF16(id); |
| 342 | } |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 343 | return l10n_util::GetStringUTF16(kAcceptButtonIds[type_]); |
| 344 | } |
| 345 | |
| 346 | bool ExtensionInstallPrompt::Prompt::HasAbortButtonLabel() const { |
| 347 | return kAbortButtonIds[type_] > 0; |
| 348 | } |
| 349 | |
| 350 | string16 ExtensionInstallPrompt::Prompt::GetAbortButtonLabel() const { |
| 351 | CHECK(HasAbortButtonLabel()); |
| 352 | return l10n_util::GetStringUTF16(kAbortButtonIds[type_]); |
| 353 | } |
| 354 | |
| 355 | string16 ExtensionInstallPrompt::Prompt::GetPermissionsHeading() const { |
| 356 | return l10n_util::GetStringUTF16(kPermissionsHeaderIds[type_]); |
| 357 | } |
| 358 | |
[email protected] | 813475e | 2012-07-02 23:54:18 | [diff] [blame] | 359 | string16 ExtensionInstallPrompt::Prompt::GetOAuthHeading() const { |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 360 | return l10n_util::GetStringFUTF16(kOAuthHeaderIds[type_], oauth_user_name_); |
[email protected] | 813475e | 2012-07-02 23:54:18 | [diff] [blame] | 361 | } |
| 362 | |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 363 | string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const { |
[email protected] | 4f1e108 | 2013-09-23 10:30:53 | [diff] [blame] | 364 | const int kRetainedFilesMessageIDs[6] = { |
| 365 | IDS_EXTENSION_PROMPT_RETAINED_FILES_DEFAULT, |
| 366 | IDS_EXTENSION_PROMPT_RETAINED_FILE_SINGULAR, |
| 367 | IDS_EXTENSION_PROMPT_RETAINED_FILES_ZERO, |
| 368 | IDS_EXTENSION_PROMPT_RETAINED_FILES_TWO, |
| 369 | IDS_EXTENSION_PROMPT_RETAINED_FILES_FEW, |
| 370 | IDS_EXTENSION_PROMPT_RETAINED_FILES_MANY, |
| 371 | }; |
| 372 | std::vector<int> message_ids; |
| 373 | for (size_t i = 0; i < arraysize(kRetainedFilesMessageIDs); i++) { |
| 374 | message_ids.push_back(kRetainedFilesMessageIDs[i]); |
| 375 | } |
| 376 | return l10n_util::GetPluralStringFUTF16(message_ids, GetRetainedFileCount()); |
[email protected] | 8ab7e6c | 2013-07-11 21:15:03 | [diff] [blame] | 377 | } |
| 378 | |
[email protected] | f2cd899 | 2013-06-11 17:30:18 | [diff] [blame] | 379 | bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { |
| 380 | return GetPermissionCount() > 0 || type_ == POST_INSTALL_PERMISSIONS_PROMPT; |
| 381 | } |
| 382 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 383 | void ExtensionInstallPrompt::Prompt::AppendRatingStars( |
| 384 | StarAppender appender, void* data) const { |
| 385 | CHECK(appender); |
| 386 | CHECK_EQ(INLINE_INSTALL_PROMPT, type_); |
| 387 | int rating_integer = floor(average_rating_); |
| 388 | double rating_fractional = average_rating_ - rating_integer; |
| 389 | |
| 390 | if (rating_fractional > 0.66) { |
| 391 | rating_integer++; |
| 392 | } |
| 393 | |
| 394 | if (rating_fractional < 0.33 || rating_fractional > 0.66) { |
| 395 | rating_fractional = 0; |
| 396 | } |
| 397 | |
| 398 | ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 399 | int i; |
| 400 | for (i = 0; i < rating_integer; i++) { |
| 401 | appender(rb.GetImageSkiaNamed(IDR_EXTENSIONS_RATING_STAR_ON), data); |
| 402 | } |
| 403 | if (rating_fractional) { |
| 404 | appender(rb.GetImageSkiaNamed(IDR_EXTENSIONS_RATING_STAR_HALF_LEFT), data); |
| 405 | i++; |
| 406 | } |
| 407 | for (; i < kMaxExtensionRating; i++) { |
| 408 | appender(rb.GetImageSkiaNamed(IDR_EXTENSIONS_RATING_STAR_OFF), data); |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | string16 ExtensionInstallPrompt::Prompt::GetRatingCount() const { |
| 413 | CHECK_EQ(INLINE_INSTALL_PROMPT, type_); |
[email protected] | 6725048e | 2013-10-24 21:47:14 | [diff] [blame] | 414 | return l10n_util::GetStringFUTF16(IDS_EXTENSION_RATING_COUNT, |
| 415 | base::IntToString16(rating_count_)); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | string16 ExtensionInstallPrompt::Prompt::GetUserCount() const { |
| 419 | CHECK_EQ(INLINE_INSTALL_PROMPT, type_); |
[email protected] | dcde34b3 | 2013-07-31 02:28:45 | [diff] [blame] | 420 | |
| 421 | if (show_user_count_) { |
[email protected] | 6725048e | 2013-10-24 21:47:14 | [diff] [blame] | 422 | return l10n_util::GetStringFUTF16(IDS_EXTENSION_USER_COUNT, |
| 423 | base::UTF8ToUTF16(localized_user_count_)); |
[email protected] | dcde34b3 | 2013-07-31 02:28:45 | [diff] [blame] | 424 | } |
[email protected] | 6725048e | 2013-10-24 21:47:14 | [diff] [blame] | 425 | return base::string16(); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | size_t ExtensionInstallPrompt::Prompt::GetPermissionCount() const { |
| 429 | return permissions_.size(); |
| 430 | } |
| 431 | |
[email protected] | 8ab7e6c | 2013-07-11 21:15:03 | [diff] [blame] | 432 | size_t ExtensionInstallPrompt::Prompt::GetPermissionsDetailsCount() const { |
| 433 | return details_.size(); |
| 434 | } |
| 435 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 436 | string16 ExtensionInstallPrompt::Prompt::GetPermission(size_t index) const { |
| 437 | CHECK_LT(index, permissions_.size()); |
[email protected] | ef2654e4 | 2012-08-11 03:57:56 | [diff] [blame] | 438 | return permissions_[index]; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 439 | } |
| 440 | |
[email protected] | 8ab7e6c | 2013-07-11 21:15:03 | [diff] [blame] | 441 | string16 ExtensionInstallPrompt::Prompt::GetPermissionsDetails( |
| 442 | size_t index) const { |
| 443 | CHECK_LT(index, details_.size()); |
| 444 | return details_[index]; |
| 445 | } |
| 446 | |
[email protected] | 79a6f99a | 2013-08-29 00:32:58 | [diff] [blame] | 447 | bool ExtensionInstallPrompt::Prompt::GetIsShowingDetails( |
| 448 | DetailsType type, size_t index) const { |
| 449 | switch (type) { |
| 450 | case PERMISSIONS_DETAILS: |
| 451 | CHECK_LT(index, is_showing_details_for_permissions_.size()); |
| 452 | return is_showing_details_for_permissions_[index]; |
| 453 | case OAUTH_DETAILS: |
| 454 | CHECK_LT(index, is_showing_details_for_oauth_.size()); |
| 455 | return is_showing_details_for_oauth_[index]; |
| 456 | case RETAINED_FILES_DETAILS: |
| 457 | return is_showing_details_for_retained_files_; |
| 458 | } |
| 459 | return false; |
| 460 | } |
| 461 | |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 462 | size_t ExtensionInstallPrompt::Prompt::GetOAuthIssueCount() const { |
| 463 | return oauth_issue_advice_.size(); |
| 464 | } |
| 465 | |
| 466 | const IssueAdviceInfoEntry& ExtensionInstallPrompt::Prompt::GetOAuthIssue( |
| 467 | size_t index) const { |
| 468 | CHECK_LT(index, oauth_issue_advice_.size()); |
| 469 | return oauth_issue_advice_[index]; |
| 470 | } |
| 471 | |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 472 | size_t ExtensionInstallPrompt::Prompt::GetRetainedFileCount() const { |
| 473 | return retained_files_.size(); |
| 474 | } |
| 475 | |
| 476 | string16 ExtensionInstallPrompt::Prompt::GetRetainedFile(size_t index) const { |
| 477 | CHECK_LT(index, retained_files_.size()); |
[email protected] | 6725048e | 2013-10-24 21:47:14 | [diff] [blame] | 478 | return retained_files_[index].AsUTF16Unsafe(); |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | bool ExtensionInstallPrompt::Prompt::ShouldDisplayRevokeFilesButton() const { |
| 482 | return !retained_files_.empty(); |
| 483 | } |
| 484 | |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 485 | ExtensionInstallPrompt::ShowParams::ShowParams(content::WebContents* contents) |
| 486 | : parent_web_contents(contents), |
| 487 | parent_window(NativeWindowForWebContents(contents)), |
| 488 | navigator(contents) { |
| 489 | } |
| 490 | |
| 491 | ExtensionInstallPrompt::ShowParams::ShowParams( |
| 492 | gfx::NativeWindow window, |
| 493 | content::PageNavigator* navigator) |
| 494 | : parent_web_contents(NULL), |
| 495 | parent_window(window), |
| 496 | navigator(navigator) { |
| 497 | } |
| 498 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 499 | // static |
| 500 | scoped_refptr<Extension> |
| 501 | ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( |
| 502 | const DictionaryValue* manifest, |
[email protected] | c422a86 | 2012-07-31 15:46:13 | [diff] [blame] | 503 | int flags, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 504 | const std::string& id, |
| 505 | const std::string& localized_name, |
| 506 | const std::string& localized_description, |
| 507 | std::string* error) { |
| 508 | scoped_ptr<DictionaryValue> localized_manifest; |
| 509 | if (!localized_name.empty() || !localized_description.empty()) { |
| 510 | localized_manifest.reset(manifest->DeepCopy()); |
| 511 | if (!localized_name.empty()) { |
[email protected] | 6bf9061 | 2013-08-15 00:36:27 | [diff] [blame] | 512 | localized_manifest->SetString(extensions::manifest_keys::kName, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 513 | localized_name); |
| 514 | } |
| 515 | if (!localized_description.empty()) { |
[email protected] | 6bf9061 | 2013-08-15 00:36:27 | [diff] [blame] | 516 | localized_manifest->SetString(extensions::manifest_keys::kDescription, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 517 | localized_description); |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | return Extension::Create( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 522 | base::FilePath(), |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 523 | Manifest::INTERNAL, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 524 | localized_manifest.get() ? *localized_manifest.get() : *manifest, |
[email protected] | c422a86 | 2012-07-31 15:46:13 | [diff] [blame] | 525 | flags, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 526 | id, |
| 527 | error); |
| 528 | } |
| 529 | |
[email protected] | 619f8618 | 2012-07-03 21:30:18 | [diff] [blame] | 530 | ExtensionInstallPrompt::ExtensionInstallPrompt( |
[email protected] | 91e51d61 | 2012-10-21 23:03:05 | [diff] [blame] | 531 | content::WebContents* contents) |
[email protected] | 16798da83 | 2012-08-30 20:46:04 | [diff] [blame] | 532 | : record_oauth2_grant_(false), |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 533 | ui_loop_(base::MessageLoop::current()), |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 534 | extension_(NULL), |
[email protected] | 91e51d61 | 2012-10-21 23:03:05 | [diff] [blame] | 535 | install_ui_(ExtensionInstallUI::Create(ProfileForWebContents(contents))), |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 536 | show_params_(contents), |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 537 | delegate_(NULL), |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 538 | prompt_(UNSET_PROMPT_TYPE) { |
| 539 | prompt_.SetUserNameFromProfile(install_ui_->profile()); |
| 540 | } |
| 541 | |
| 542 | ExtensionInstallPrompt::ExtensionInstallPrompt( |
| 543 | Profile* profile, |
| 544 | gfx::NativeWindow native_window, |
| 545 | content::PageNavigator* navigator) |
| 546 | : record_oauth2_grant_(false), |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 547 | ui_loop_(base::MessageLoop::current()), |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 548 | extension_(NULL), |
| 549 | install_ui_(ExtensionInstallUI::Create(profile)), |
| 550 | show_params_(native_window, navigator), |
| 551 | delegate_(NULL), |
| 552 | prompt_(UNSET_PROMPT_TYPE) { |
| 553 | prompt_.SetUserNameFromProfile(install_ui_->profile()); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | ExtensionInstallPrompt::~ExtensionInstallPrompt() { |
| 557 | } |
| 558 | |
| 559 | void ExtensionInstallPrompt::ConfirmBundleInstall( |
| 560 | extensions::BundleInstaller* bundle, |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 561 | const PermissionSet* permissions) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 562 | DCHECK(ui_loop_ == base::MessageLoop::current()); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 563 | bundle_ = bundle; |
| 564 | permissions_ = permissions; |
| 565 | delegate_ = bundle; |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 566 | prompt_.set_type(BUNDLE_INSTALL_PROMPT); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 567 | |
[email protected] | 4e49487 | 2013-09-06 09:13:54 | [diff] [blame] | 568 | ShowConfirmation(); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 569 | } |
| 570 | |
[email protected] | 734bcec | 2012-10-08 20:29:05 | [diff] [blame] | 571 | void ExtensionInstallPrompt::ConfirmStandaloneInstall( |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 572 | Delegate* delegate, |
| 573 | const Extension* extension, |
| 574 | SkBitmap* icon, |
| 575 | const ExtensionInstallPrompt::Prompt& prompt) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 576 | DCHECK(ui_loop_ == base::MessageLoop::current()); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 577 | extension_ = extension; |
| 578 | permissions_ = extension->GetActivePermissions(); |
| 579 | delegate_ = delegate; |
| 580 | prompt_ = prompt; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 581 | |
| 582 | SetIcon(icon); |
[email protected] | 4e49487 | 2013-09-06 09:13:54 | [diff] [blame] | 583 | ShowConfirmation(); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 584 | } |
| 585 | |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 586 | void ExtensionInstallPrompt::ConfirmWebstoreInstall( |
| 587 | Delegate* delegate, |
| 588 | const Extension* extension, |
| 589 | const SkBitmap* icon, |
| 590 | const ShowDialogCallback& show_dialog_callback) { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 591 | // SetIcon requires |extension_| to be set. ConfirmInstall will setup the |
| 592 | // remaining fields. |
| 593 | extension_ = extension; |
| 594 | SetIcon(icon); |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 595 | ConfirmInstall(delegate, extension, show_dialog_callback); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 596 | } |
| 597 | |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 598 | void ExtensionInstallPrompt::ConfirmInstall( |
| 599 | Delegate* delegate, |
| 600 | const Extension* extension, |
| 601 | const ShowDialogCallback& show_dialog_callback) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 602 | DCHECK(ui_loop_ == base::MessageLoop::current()); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 603 | extension_ = extension; |
| 604 | permissions_ = extension->GetActivePermissions(); |
| 605 | delegate_ = delegate; |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 606 | prompt_.set_type(INSTALL_PROMPT); |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 607 | show_dialog_callback_ = show_dialog_callback; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 608 | |
| 609 | // We special-case themes to not show any confirm UI. Instead they are |
| 610 | // immediately installed, and then we show an infobar (see OnInstallSuccess) |
| 611 | // to allow the user to revert if they don't like it. |
| 612 | // |
| 613 | // We don't do this in the case where off-store extension installs are |
| 614 | // disabled because in that case, we don't show the dangerous download UI, so |
| 615 | // we need the UI confirmation. |
| 616 | if (extension->is_theme()) { |
| 617 | if (extension->from_webstore() || |
[email protected] | 544471a | 2012-10-13 05:27:09 | [diff] [blame] | 618 | extensions::FeatureSwitch::easy_off_store_install()->IsEnabled()) { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 619 | delegate->InstallUIProceed(); |
| 620 | return; |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | LoadImageIfNeeded(); |
| 625 | } |
| 626 | |
| 627 | void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate, |
| 628 | const Extension* extension) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 629 | DCHECK(ui_loop_ == base::MessageLoop::current()); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 630 | extension_ = extension; |
| 631 | permissions_ = extension->GetActivePermissions(); |
| 632 | delegate_ = delegate; |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 633 | prompt_.set_type(RE_ENABLE_PROMPT); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 634 | |
| 635 | LoadImageIfNeeded(); |
| 636 | } |
| 637 | |
[email protected] | aa5a547 | 2013-10-04 03:41:04 | [diff] [blame] | 638 | void ExtensionInstallPrompt::ConfirmDefaultInstallFirstRun( |
| 639 | Delegate* delegate, |
| 640 | const Extension* extension) { |
| 641 | DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 642 | extension_ = extension; |
| 643 | permissions_ = extension->GetActivePermissions(); |
| 644 | delegate_ = delegate; |
| 645 | prompt_.set_type(DEFAULT_INSTALL_FIRST_RUN_PROMPT); |
| 646 | LoadImageIfNeeded(); |
| 647 | } |
| 648 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 649 | void ExtensionInstallPrompt::ConfirmExternalInstall( |
[email protected] | c8ff7c9e | 2013-04-20 12:36:27 | [diff] [blame] | 650 | Delegate* delegate, |
| 651 | const Extension* extension, |
| 652 | const ShowDialogCallback& show_dialog_callback) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 653 | DCHECK(ui_loop_ == base::MessageLoop::current()); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 654 | extension_ = extension; |
| 655 | permissions_ = extension->GetActivePermissions(); |
| 656 | delegate_ = delegate; |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 657 | prompt_.set_type(EXTERNAL_INSTALL_PROMPT); |
[email protected] | c8ff7c9e | 2013-04-20 12:36:27 | [diff] [blame] | 658 | show_dialog_callback_ = show_dialog_callback; |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 659 | |
| 660 | LoadImageIfNeeded(); |
| 661 | } |
| 662 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 663 | void ExtensionInstallPrompt::ConfirmPermissions( |
| 664 | Delegate* delegate, |
| 665 | const Extension* extension, |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 666 | const PermissionSet* permissions) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 667 | DCHECK(ui_loop_ == base::MessageLoop::current()); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 668 | extension_ = extension; |
| 669 | permissions_ = permissions; |
| 670 | delegate_ = delegate; |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 671 | prompt_.set_type(PERMISSIONS_PROMPT); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 672 | |
| 673 | LoadImageIfNeeded(); |
| 674 | } |
| 675 | |
[email protected] | f746b3f | 2012-07-03 17:53:37 | [diff] [blame] | 676 | void ExtensionInstallPrompt::ConfirmIssueAdvice( |
| 677 | Delegate* delegate, |
| 678 | const Extension* extension, |
| 679 | const IssueAdviceInfo& issue_advice) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 680 | DCHECK(ui_loop_ == base::MessageLoop::current()); |
[email protected] | f746b3f | 2012-07-03 17:53:37 | [diff] [blame] | 681 | extension_ = extension; |
| 682 | delegate_ = delegate; |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 683 | prompt_.set_type(PERMISSIONS_PROMPT); |
[email protected] | f746b3f | 2012-07-03 17:53:37 | [diff] [blame] | 684 | |
| 685 | record_oauth2_grant_ = true; |
| 686 | prompt_.SetOAuthIssueAdvice(issue_advice); |
| 687 | |
| 688 | LoadImageIfNeeded(); |
| 689 | } |
| 690 | |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 691 | void ExtensionInstallPrompt::ReviewPermissions( |
| 692 | Delegate* delegate, |
| 693 | const Extension* extension, |
| 694 | const std::vector<base::FilePath>& retained_file_paths) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 695 | DCHECK(ui_loop_ == base::MessageLoop::current()); |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 696 | extension_ = extension; |
| 697 | permissions_ = extension->GetActivePermissions(); |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 698 | prompt_.set_retained_files(retained_file_paths); |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 699 | delegate_ = delegate; |
| 700 | prompt_.set_type(POST_INSTALL_PERMISSIONS_PROMPT); |
| 701 | |
| 702 | LoadImageIfNeeded(); |
| 703 | } |
| 704 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 705 | void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, |
| 706 | SkBitmap* icon) { |
| 707 | extension_ = extension; |
| 708 | SetIcon(icon); |
| 709 | |
| 710 | install_ui_->OnInstallSuccess(extension, &icon_); |
| 711 | } |
| 712 | |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 713 | void ExtensionInstallPrompt::OnInstallFailure( |
| 714 | const extensions::CrxInstallerError& error) { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 715 | install_ui_->OnInstallFailure(error); |
| 716 | } |
| 717 | |
| 718 | void ExtensionInstallPrompt::SetIcon(const SkBitmap* image) { |
| 719 | if (image) |
| 720 | icon_ = *image; |
| 721 | else |
| 722 | icon_ = SkBitmap(); |
[email protected] | dd46a4ce | 2012-09-15 10:50:50 | [diff] [blame] | 723 | if (icon_.empty()) { |
| 724 | // Let's set default icon bitmap whose size is equal to the default icon's |
| 725 | // pixel size under maximal supported scale factor. If the bitmap is larger |
| 726 | // than the one we need, it will be scaled down by the ui code. |
| 727 | icon_ = GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app()); |
| 728 | } |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 729 | } |
| 730 | |
[email protected] | ec7de0c5a | 2012-11-16 07:40:47 | [diff] [blame] | 731 | void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image) { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 732 | SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); |
[email protected] | 4e49487 | 2013-09-06 09:13:54 | [diff] [blame] | 733 | ShowConfirmation(); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | void ExtensionInstallPrompt::LoadImageIfNeeded() { |
| 737 | // Bundle install prompts do not have an icon. |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 738 | // Also |install_ui_.profile()| can be NULL in unit tests. |
| 739 | if (!icon_.empty() || !install_ui_->profile()) { |
[email protected] | 4e49487 | 2013-09-06 09:13:54 | [diff] [blame] | 740 | ShowConfirmation(); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 741 | return; |
| 742 | } |
| 743 | |
| 744 | // Load the image asynchronously. For the response, check OnImageLoaded. |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 745 | extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( |
[email protected] | 702d8b4 | 2013-02-27 20:55:50 | [diff] [blame] | 746 | extension_, |
| 747 | extension_misc::EXTENSION_ICON_LARGE, |
| 748 | ExtensionIconSet::MATCH_BIGGER); |
[email protected] | dd46a4ce | 2012-09-15 10:50:50 | [diff] [blame] | 749 | // Load the icon whose pixel size is large enough to be displayed under |
| 750 | // maximal supported scale factor. UI code will scale the icon down if needed. |
| 751 | // TODO(tbarzic): We should use IconImage here and load the required bitmap |
| 752 | // lazily. |
| 753 | int pixel_size = GetSizeForMaxScaleFactor(kIconSize); |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 754 | extensions::ImageLoader::Get(install_ui_->profile())->LoadImageAsync( |
[email protected] | ec7de0c5a | 2012-11-16 07:40:47 | [diff] [blame] | 755 | extension_, image, gfx::Size(pixel_size, pixel_size), |
| 756 | base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 757 | } |
| 758 | |
[email protected] | 4f3fb35 | 2013-07-17 04:07:01 | [diff] [blame] | 759 | void ExtensionInstallPrompt::OnGetTokenSuccess( |
| 760 | const OAuth2TokenService::Request* request, |
| 761 | const std::string& access_token, |
| 762 | const base::Time& expiration_time) { |
| 763 | DCHECK_EQ(login_token_request_.get(), request); |
| 764 | login_token_request_.reset(); |
| 765 | |
| 766 | const extensions::OAuth2Info& oauth2_info = |
| 767 | extensions::OAuth2Info::GetOAuth2Info(extension_); |
| 768 | |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 769 | token_flow_.reset(new OAuth2MintTokenFlow( |
[email protected] | 4f3fb35 | 2013-07-17 04:07:01 | [diff] [blame] | 770 | install_ui_->profile()->GetRequestContext(), |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 771 | this, |
| 772 | OAuth2MintTokenFlow::Parameters( |
[email protected] | 4f3fb35 | 2013-07-17 04:07:01 | [diff] [blame] | 773 | access_token, |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 774 | extension_->id(), |
| 775 | oauth2_info.client_id, |
[email protected] | d4a37f1c | 2012-07-09 21:36:13 | [diff] [blame] | 776 | oauth2_info.scopes, |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 777 | OAuth2MintTokenFlow::MODE_ISSUE_ADVICE))); |
| 778 | token_flow_->Start(); |
| 779 | } |
| 780 | |
[email protected] | 4f3fb35 | 2013-07-17 04:07:01 | [diff] [blame] | 781 | void ExtensionInstallPrompt::OnGetTokenFailure( |
| 782 | const OAuth2TokenService::Request* request, |
| 783 | const GoogleServiceAuthError& error) { |
| 784 | DCHECK_EQ(login_token_request_.get(), request); |
| 785 | login_token_request_.reset(); |
| 786 | ShowConfirmation(); |
| 787 | } |
| 788 | |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 789 | void ExtensionInstallPrompt::OnIssueAdviceSuccess( |
| 790 | const IssueAdviceInfo& advice_info) { |
| 791 | prompt_.SetOAuthIssueAdvice(advice_info); |
| 792 | record_oauth2_grant_ = true; |
| 793 | ShowConfirmation(); |
| 794 | } |
| 795 | |
| 796 | void ExtensionInstallPrompt::OnMintTokenFailure( |
| 797 | const GoogleServiceAuthError& error) { |
| 798 | ShowConfirmation(); |
| 799 | } |
| 800 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 801 | void ExtensionInstallPrompt::ShowConfirmation() { |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 802 | if (permissions_.get() && |
[email protected] | 13c68b6 | 2013-05-17 11:29:05 | [diff] [blame] | 803 | (!extension_ || |
| 804 | !extensions::PermissionsData::ShouldSkipPermissionWarnings( |
| 805 | extension_))) { |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 806 | Manifest::Type extension_type = extension_ ? |
| 807 | extension_->GetType() : Manifest::TYPE_UNKNOWN; |
[email protected] | 8ab7e6c | 2013-07-11 21:15:03 | [diff] [blame] | 808 | prompt_.SetPermissions( |
[email protected] | c4100347 | 2013-10-19 15:37:25 | [diff] [blame] | 809 | extensions::PermissionMessageProvider::Get()-> |
| 810 | GetWarningMessages(permissions_, extension_type)); |
[email protected] | 8ab7e6c | 2013-07-11 21:15:03 | [diff] [blame] | 811 | prompt_.SetPermissionsDetails( |
[email protected] | c4100347 | 2013-10-19 15:37:25 | [diff] [blame] | 812 | extensions::PermissionMessageProvider::Get()-> |
| 813 | GetWarningMessagesDetails(permissions_, extension_type)); |
[email protected] | bebe1d0 | 2012-08-02 20:17:09 | [diff] [blame] | 814 | } |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 815 | |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 816 | switch (prompt_.type()) { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 817 | case PERMISSIONS_PROMPT: |
| 818 | case RE_ENABLE_PROMPT: |
[email protected] | aa5a547 | 2013-10-04 03:41:04 | [diff] [blame] | 819 | case DEFAULT_INSTALL_FIRST_RUN_PROMPT: |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 820 | case INLINE_INSTALL_PROMPT: |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 821 | case EXTERNAL_INSTALL_PROMPT: |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 822 | case INSTALL_PROMPT: |
[email protected] | 1a93d8d | 2013-10-27 23:09:20 | [diff] [blame^] | 823 | case LAUNCH_PROMPT: |
[email protected] | 15d267b4 | 2013-02-14 23:43:32 | [diff] [blame] | 824 | case POST_INSTALL_PERMISSIONS_PROMPT: { |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 825 | prompt_.set_extension(extension_); |
[email protected] | 32e7a9b | 2013-01-23 23:00:19 | [diff] [blame] | 826 | prompt_.set_icon(gfx::Image::CreateFrom1xBitmap(icon_)); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 827 | break; |
| 828 | } |
| 829 | case BUNDLE_INSTALL_PROMPT: { |
| 830 | prompt_.set_bundle(bundle_); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 831 | break; |
| 832 | } |
| 833 | default: |
| 834 | NOTREACHED() << "Unknown message"; |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 835 | return; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 836 | } |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 837 | |
| 838 | if (AutoConfirmPrompt(delegate_)) |
| 839 | return; |
| 840 | |
[email protected] | 5db2e88 | 2012-12-20 10:17:26 | [diff] [blame] | 841 | if (show_dialog_callback_.is_null()) |
| 842 | GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); |
| 843 | else |
| 844 | show_dialog_callback_.Run(show_params_, delegate_, prompt_); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 845 | } |