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