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