blob: 4f0ef54311fd2f0e82879dbdd2dcd27d1c202939 [file] [log] [blame]
[email protected]c82da8c42012-06-08 19:49:111// 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]b19fe572013-07-18 04:54:2610#include "base/message_loop/message_loop.h"
[email protected]3853a4c2013-02-11 17:15:5711#include "base/prefs/pref_service.h"
[email protected]3ea1b182013-02-08 22:38:4112#include "base/strings/string_number_conversions.h"
[email protected]00e7bef2013-06-10 20:35:1713#include "base/strings/string_util.h"
14#include "base/strings/stringprintf.h"
[email protected]112158af2013-06-07 23:46:1815#include "base/strings/utf_string_conversions.h"
[email protected]c82da8c42012-06-08 19:49:1116#include "chrome/browser/extensions/bundle_installer.h"
[email protected]c82da8c42012-06-08 19:49:1117#include "chrome/browser/extensions/extension_install_ui.h"
[email protected]ec7de0c5a2012-11-16 07:40:4718#include "chrome/browser/extensions/image_loader.h"
[email protected]c82da8c42012-06-08 19:49:1119#include "chrome/browser/profiles/profile.h"
[email protected]4f3fb352013-07-17 04:07:0120#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
[email protected]32fc4ff72012-06-15 21:50:0121#include "chrome/browser/ui/browser.h"
[email protected]619f86182012-07-03 21:30:1822#include "chrome/browser/ui/browser_window.h"
[email protected]c82da8c42012-06-08 19:49:1123#include "chrome/common/chrome_switches.h"
[email protected]29e0c4e72013-02-01 04:42:5624#include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h"
[email protected]fc5077942012-08-15 21:37:5925#include "chrome/common/pref_names.h"
[email protected]7274ef02014-03-24 22:43:4026#include "components/signin/core/browser/profile_oauth2_token_service.h"
[email protected]91e51d612012-10-21 23:03:0527#include "content/public/browser/web_contents.h"
[email protected]5db2e882012-12-20 10:17:2628#include "content/public/browser/web_contents_view.h"
[email protected]cda103d2014-04-04 16:22:3929#include "extensions/common/constants.h"
[email protected]e4452d32013-11-15 23:07:4130#include "extensions/common/extension.h"
[email protected]4b7908842014-04-07 23:50:2231#include "extensions/common/extension_icon_set.h"
[email protected]993da5e2013-03-23 21:25:1632#include "extensions/common/extension_resource.h"
[email protected]5ef835a2013-11-08 20:42:5733#include "extensions/common/feature_switch.h"
[email protected]d42c11152013-08-22 19:36:3234#include "extensions/common/manifest.h"
[email protected]6bf90612013-08-15 00:36:2735#include "extensions/common/manifest_constants.h"
[email protected]0db486f2014-04-09 19:32:2236#include "extensions/common/manifest_handlers/icons_handler.h"
[email protected]c41003472013-10-19 15:37:2537#include "extensions/common/permissions/permission_message_provider.h"
[email protected]5a55f3f2013-10-29 01:08:2938#include "extensions/common/permissions/permission_set.h"
[email protected]e4452d32013-11-15 23:07:4139#include "extensions/common/permissions/permissions_data.h"
[email protected]885c0e92012-11-13 20:27:4240#include "extensions/common/url_pattern.h"
[email protected]c82da8c42012-06-08 19:49:1141#include "grit/chromium_strings.h"
42#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:2343#include "grit/theme_resources.h"
[email protected]c82da8c42012-06-08 19:49:1144#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]c82da8c42012-06-08 19:49:1148using extensions::BundleInstaller;
49using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:4050using extensions::Manifest;
[email protected]c2e66e12012-06-27 06:27:0651using extensions::PermissionSet;
[email protected]c82da8c42012-06-08 19:49:1152
[email protected]612a1cb12012-10-17 13:18:0353namespace {
54
[email protected]c82da8c42012-06-08 19:49:1155static 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]612a1cb12012-10-17 13:18:0360 IDS_EXTENSION_PERMISSIONS_PROMPT_TITLE,
61 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_TITLE,
[email protected]15d267b42013-02-14 23:43:3262 IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_TITLE,
[email protected]1a93d8d2013-10-27 23:09:2063 IDS_EXTENSION_LAUNCH_APP_PROMPT_TITLE,
[email protected]c82da8c42012-06-08 19:49:1164};
65static const int kHeadingIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
66 IDS_EXTENSION_INSTALL_PROMPT_HEADING,
67 0, // Inline installs use the extension name.
68 0, // Heading for bundle installs depends on the bundle contents.
69 IDS_EXTENSION_RE_ENABLE_PROMPT_HEADING,
[email protected]612a1cb12012-10-17 13:18:0370 IDS_EXTENSION_PERMISSIONS_PROMPT_HEADING,
[email protected]846606012012-10-19 18:42:2571 0, // External installs use different strings for extensions/apps.
[email protected]15d267b42013-02-14 23:43:3272 IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_HEADING,
[email protected]1a93d8d2013-10-27 23:09:2073 IDS_EXTENSION_LAUNCH_APP_PROMPT_HEADING,
[email protected]15d267b42013-02-14 23:43:3274};
75static const int kButtons[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
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_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_CANCEL,
[email protected]aa5a5472013-10-04 03:41:0483 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
[email protected]c82da8c42012-06-08 19:49:1184};
85static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
86 IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
87 IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
88 IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
89 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON,
[email protected]612a1cb12012-10-17 13:18:0390 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON,
[email protected]846606012012-10-19 18:42:2591 0, // External installs use different strings for extensions/apps.
[email protected]a2886e8b2013-06-08 05:15:0292 IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_BUTTON,
[email protected]1a93d8d2013-10-27 23:09:2093 IDS_EXTENSION_PROMPT_LAUNCH_BUTTON,
[email protected]c82da8c42012-06-08 19:49:1194};
95static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
96 0, // These all use the platform's default cancel label.
97 0,
98 0,
99 0,
[email protected]612a1cb12012-10-17 13:18:03100 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON,
101 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ABORT_BUTTON,
[email protected]15d267b42013-02-14 23:43:32102 IDS_CLOSE,
[email protected]bc123c02013-10-15 06:41:13103 0, // Platform dependent cancel button.
[email protected]c82da8c42012-06-08 19:49:11104};
105static const int kPermissionsHeaderIds[
106 ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
107 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
108 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
109 IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO,
110 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO,
111 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO,
[email protected]612a1cb12012-10-17 13:18:03112 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
[email protected]15d267b42013-02-14 23:43:32113 IDS_EXTENSION_PROMPT_CAN_ACCESS,
[email protected]1a93d8d2013-10-27 23:09:20114 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
[email protected]c82da8c42012-06-08 19:49:11115};
[email protected]612a1cb12012-10-17 13:18:03116static const int kOAuthHeaderIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
[email protected]fc5077942012-08-15 21:37:59117 IDS_EXTENSION_PROMPT_OAUTH_HEADER,
118 0, // Inline installs don't show OAuth permissions.
119 0, // Bundle installs don't show OAuth permissions.
120 IDS_EXTENSION_PROMPT_OAUTH_REENABLE_HEADER,
121 IDS_EXTENSION_PROMPT_OAUTH_PERMISSIONS_HEADER,
[email protected]612a1cb12012-10-17 13:18:03122 0,
[email protected]15d267b42013-02-14 23:43:32123 0,
[email protected]aa5a5472013-10-04 03:41:04124 IDS_EXTENSION_PROMPT_OAUTH_HEADER,
[email protected]fc5077942012-08-15 21:37:59125};
[email protected]c82da8c42012-06-08 19:49:11126
[email protected]c82da8c42012-06-08 19:49:11127// Size of extension icon in top left of dialog.
128const int kIconSize = 69;
129
[email protected]dd46a4ce2012-09-15 10:50:50130// Returns pixel size under maximal scale factor for the icon whose device
131// independent size is |size_in_dip|
132int GetSizeForMaxScaleFactor(int size_in_dip) {
[email protected]50b66262013-09-24 03:25:48133 return static_cast<int>(size_in_dip * gfx::ImageSkia::GetMaxSupportedScale());
[email protected]dd46a4ce2012-09-15 10:50:50134}
135
136// Returns bitmap for the default icon with size equal to the default icon's
137// pixel size under maximal supported scale factor.
138SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
[email protected]702d8b42013-02-27 20:55:50139 const gfx::ImageSkia& image = is_app ?
140 extensions::IconsInfo::GetDefaultAppIcon() :
141 extensions::IconsInfo::GetDefaultExtensionIcon();
[email protected]50b66262013-09-24 03:25:48142 return image.GetRepresentation(
143 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap();
[email protected]dd46a4ce2012-09-15 10:50:50144}
145
[email protected]af6efb22012-10-12 02:23:05146// If auto confirm is enabled then posts a task to proceed with or cancel the
147// install and returns true. Otherwise returns false.
148bool AutoConfirmPrompt(ExtensionInstallPrompt::Delegate* delegate) {
149 const CommandLine* cmdline = CommandLine::ForCurrentProcess();
150 if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests))
151 return false;
152 std::string value = cmdline->GetSwitchValueASCII(
153 switches::kAppsGalleryInstallAutoConfirmForTests);
154
155 // We use PostTask instead of calling the delegate directly here, because in
156 // the real implementations it's highly likely the message loop will be
157 // pumping a few times before the user clicks accept or cancel.
158 if (value == "accept") {
[email protected]b3a25092013-05-28 22:08:16159 base::MessageLoop::current()->PostTask(
[email protected]af6efb22012-10-12 02:23:05160 FROM_HERE,
161 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIProceed,
162 base::Unretained(delegate)));
163 return true;
164 }
165
166 if (value == "cancel") {
[email protected]b3a25092013-05-28 22:08:16167 base::MessageLoop::current()->PostTask(
[email protected]af6efb22012-10-12 02:23:05168 FROM_HERE,
169 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIAbort,
170 base::Unretained(delegate),
171 true));
172 return true;
173 }
174
175 NOTREACHED();
176 return false;
177}
178
[email protected]91e51d612012-10-21 23:03:05179Profile* ProfileForWebContents(content::WebContents* web_contents) {
180 if (!web_contents)
181 return NULL;
182 return Profile::FromBrowserContext(web_contents->GetBrowserContext());
183}
184
[email protected]5db2e882012-12-20 10:17:26185gfx::NativeWindow NativeWindowForWebContents(content::WebContents* contents) {
186 if (!contents)
187 return NULL;
188
189 return contents->GetView()->GetTopLevelNativeWindow();
190}
191
[email protected]c82da8c42012-06-08 19:49:11192} // namespace
193
[email protected]5db2e882012-12-20 10:17:26194ExtensionInstallPrompt::Prompt::Prompt(PromptType type)
[email protected]c82da8c42012-06-08 19:49:11195 : type_(type),
[email protected]79a6f99a2013-08-29 00:32:58196 is_showing_details_for_retained_files_(false),
[email protected]c82da8c42012-06-08 19:49:11197 extension_(NULL),
198 bundle_(NULL),
199 average_rating_(0.0),
[email protected]dcde34b32013-07-31 02:28:45200 rating_count_(0),
[email protected]34b5f7f2014-01-29 02:48:11201 show_user_count_(false),
202 has_webstore_data_(false) {
[email protected]c82da8c42012-06-08 19:49:11203}
204
205ExtensionInstallPrompt::Prompt::~Prompt() {
206}
207
208void ExtensionInstallPrompt::Prompt::SetPermissions(
[email protected]d2065e062013-12-12 23:49:52209 const std::vector<base::string16>& permissions) {
[email protected]c82da8c42012-06-08 19:49:11210 permissions_ = permissions;
211}
212
[email protected]8ab7e6c2013-07-11 21:15:03213void ExtensionInstallPrompt::Prompt::SetPermissionsDetails(
[email protected]d2065e062013-12-12 23:49:52214 const std::vector<base::string16>& details) {
[email protected]8ab7e6c2013-07-11 21:15:03215 details_ = details;
[email protected]79a6f99a2013-08-29 00:32:58216 is_showing_details_for_permissions_.clear();
217 for (size_t i = 0; i < details.size(); ++i)
218 is_showing_details_for_permissions_.push_back(false);
219}
220
221void ExtensionInstallPrompt::Prompt::SetIsShowingDetails(
222 DetailsType type,
223 size_t index,
224 bool is_showing_details) {
225 switch (type) {
226 case PERMISSIONS_DETAILS:
227 is_showing_details_for_permissions_[index] = is_showing_details;
228 break;
229 case OAUTH_DETAILS:
230 is_showing_details_for_oauth_[index] = is_showing_details;
231 break;
232 case RETAINED_FILES_DETAILS:
233 is_showing_details_for_retained_files_ = is_showing_details;
234 break;
235 }
[email protected]8ab7e6c2013-07-11 21:15:03236}
237
[email protected]b70a2d92012-06-28 19:51:21238void ExtensionInstallPrompt::Prompt::SetOAuthIssueAdvice(
239 const IssueAdviceInfo& issue_advice) {
[email protected]79a6f99a2013-08-29 00:32:58240 is_showing_details_for_oauth_.clear();
241 for (size_t i = 0; i < issue_advice.size(); ++i)
242 is_showing_details_for_oauth_.push_back(false);
243
[email protected]b70a2d92012-06-28 19:51:21244 oauth_issue_advice_ = issue_advice;
245}
246
[email protected]5db2e882012-12-20 10:17:26247void ExtensionInstallPrompt::Prompt::SetUserNameFromProfile(Profile* profile) {
248 // |profile| can be NULL in unit tests.
249 if (profile) {
[email protected]04338722013-12-24 23:18:05250 oauth_user_name_ = base::UTF8ToUTF16(profile->GetPrefs()->GetString(
[email protected]5db2e882012-12-20 10:17:26251 prefs::kGoogleServicesUsername));
252 } else {
253 oauth_user_name_.clear();
254 }
255}
256
[email protected]34b5f7f2014-01-29 02:48:11257void ExtensionInstallPrompt::Prompt::SetWebstoreData(
[email protected]c82da8c42012-06-08 19:49:11258 const std::string& localized_user_count,
[email protected]dcde34b32013-07-31 02:28:45259 bool show_user_count,
[email protected]c82da8c42012-06-08 19:49:11260 double average_rating,
261 int rating_count) {
[email protected]34b5f7f2014-01-29 02:48:11262 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT);
[email protected]c82da8c42012-06-08 19:49:11263 localized_user_count_ = localized_user_count;
[email protected]dcde34b32013-07-31 02:28:45264 show_user_count_ = show_user_count;
[email protected]c82da8c42012-06-08 19:49:11265 average_rating_ = average_rating;
266 rating_count_ = rating_count;
[email protected]34b5f7f2014-01-29 02:48:11267 has_webstore_data_ = true;
[email protected]c82da8c42012-06-08 19:49:11268}
269
[email protected]6a72a632013-12-12 22:22:00270base::string16 ExtensionInstallPrompt::Prompt::GetDialogTitle() const {
[email protected]c82da8c42012-06-08 19:49:11271 int resource_id = kTitleIds[type_];
272
273 if (type_ == INSTALL_PROMPT) {
274 if (extension_->is_app())
275 resource_id = IDS_EXTENSION_INSTALL_APP_PROMPT_TITLE;
276 else if (extension_->is_theme())
277 resource_id = IDS_EXTENSION_INSTALL_THEME_PROMPT_TITLE;
278 else
279 resource_id = IDS_EXTENSION_INSTALL_EXTENSION_PROMPT_TITLE;
[email protected]612a1cb12012-10-17 13:18:03280 } else if (type_ == EXTERNAL_INSTALL_PROMPT) {
281 return l10n_util::GetStringFUTF16(
[email protected]04338722013-12-24 23:18:05282 resource_id, base::UTF8ToUTF16(extension_->name()));
[email protected]c82da8c42012-06-08 19:49:11283 }
284
285 return l10n_util::GetStringUTF16(resource_id);
286}
287
[email protected]6a72a632013-12-12 22:22:00288base::string16 ExtensionInstallPrompt::Prompt::GetHeading() const {
[email protected]c82da8c42012-06-08 19:49:11289 if (type_ == INLINE_INSTALL_PROMPT) {
[email protected]04338722013-12-24 23:18:05290 return base::UTF8ToUTF16(extension_->name());
[email protected]c82da8c42012-06-08 19:49:11291 } else if (type_ == BUNDLE_INSTALL_PROMPT) {
292 return bundle_->GetHeadingTextFor(BundleInstaller::Item::STATE_PENDING);
[email protected]612a1cb12012-10-17 13:18:03293 } else if (type_ == EXTERNAL_INSTALL_PROMPT) {
[email protected]846606012012-10-19 18:42:25294 int resource_id = -1;
295 if (extension_->is_app())
296 resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_APP;
297 else if (extension_->is_theme())
298 resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_THEME;
299 else
300 resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_EXTENSION;
301 return l10n_util::GetStringUTF16(resource_id);
[email protected]c82da8c42012-06-08 19:49:11302 } else {
303 return l10n_util::GetStringFUTF16(
[email protected]04338722013-12-24 23:18:05304 kHeadingIds[type_], base::UTF8ToUTF16(extension_->name()));
[email protected]c82da8c42012-06-08 19:49:11305 }
306}
307
[email protected]15d267b42013-02-14 23:43:32308int ExtensionInstallPrompt::Prompt::GetDialogButtons() const {
[email protected]a2886e8b2013-06-08 05:15:02309 if (type_ == POST_INSTALL_PERMISSIONS_PROMPT &&
310 ShouldDisplayRevokeFilesButton()) {
311 return kButtons[type_] | ui::DIALOG_BUTTON_OK;
312 }
313
[email protected]15d267b42013-02-14 23:43:32314 return kButtons[type_];
315}
316
[email protected]62a28d7c2013-12-28 01:34:49317bool ExtensionInstallPrompt::Prompt::ShouldShowExplanationText() const {
318 return type_ == INSTALL_PROMPT &&
319 extension_->is_extension() && experiment_ && experiment_->text_only();
320}
321
[email protected]15d267b42013-02-14 23:43:32322bool ExtensionInstallPrompt::Prompt::HasAcceptButtonLabel() const {
[email protected]a2886e8b2013-06-08 05:15:02323 if (kAcceptButtonIds[type_] == 0)
324 return false;
325
326 if (type_ == POST_INSTALL_PERMISSIONS_PROMPT)
327 return ShouldDisplayRevokeFilesButton();
328
329 return true;
[email protected]15d267b42013-02-14 23:43:32330}
331
[email protected]6a72a632013-12-12 22:22:00332base::string16 ExtensionInstallPrompt::Prompt::GetAcceptButtonLabel() const {
[email protected]846606012012-10-19 18:42:25333 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]62a28d7c2013-12-28 01:34:49343 if (ShouldShowExplanationText())
344 return experiment_->GetOkButtonText();
[email protected]c82da8c42012-06-08 19:49:11345 return l10n_util::GetStringUTF16(kAcceptButtonIds[type_]);
346}
347
348bool ExtensionInstallPrompt::Prompt::HasAbortButtonLabel() const {
[email protected]62a28d7c2013-12-28 01:34:49349 if (ShouldShowExplanationText())
350 return true;
[email protected]c82da8c42012-06-08 19:49:11351 return kAbortButtonIds[type_] > 0;
352}
353
[email protected]6a72a632013-12-12 22:22:00354base::string16 ExtensionInstallPrompt::Prompt::GetAbortButtonLabel() const {
[email protected]c82da8c42012-06-08 19:49:11355 CHECK(HasAbortButtonLabel());
[email protected]62a28d7c2013-12-28 01:34:49356 if (ShouldShowExplanationText())
357 return experiment_->GetCancelButtonText();
[email protected]c82da8c42012-06-08 19:49:11358 return l10n_util::GetStringUTF16(kAbortButtonIds[type_]);
359}
360
[email protected]6a72a632013-12-12 22:22:00361base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsHeading() const {
[email protected]c82da8c42012-06-08 19:49:11362 return l10n_util::GetStringUTF16(kPermissionsHeaderIds[type_]);
363}
364
[email protected]6a72a632013-12-12 22:22:00365base::string16 ExtensionInstallPrompt::Prompt::GetOAuthHeading() const {
[email protected]5db2e882012-12-20 10:17:26366 return l10n_util::GetStringFUTF16(kOAuthHeaderIds[type_], oauth_user_name_);
[email protected]813475e2012-07-02 23:54:18367}
368
[email protected]6a72a632013-12-12 22:22:00369base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const {
[email protected]4f1e1082013-09-23 10:30:53370 const int kRetainedFilesMessageIDs[6] = {
371 IDS_EXTENSION_PROMPT_RETAINED_FILES_DEFAULT,
372 IDS_EXTENSION_PROMPT_RETAINED_FILE_SINGULAR,
373 IDS_EXTENSION_PROMPT_RETAINED_FILES_ZERO,
374 IDS_EXTENSION_PROMPT_RETAINED_FILES_TWO,
375 IDS_EXTENSION_PROMPT_RETAINED_FILES_FEW,
376 IDS_EXTENSION_PROMPT_RETAINED_FILES_MANY,
377 };
378 std::vector<int> message_ids;
379 for (size_t i = 0; i < arraysize(kRetainedFilesMessageIDs); i++) {
380 message_ids.push_back(kRetainedFilesMessageIDs[i]);
381 }
382 return l10n_util::GetPluralStringFUTF16(message_ids, GetRetainedFileCount());
[email protected]8ab7e6c2013-07-11 21:15:03383}
384
[email protected]f2cd8992013-06-11 17:30:18385bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const {
386 return GetPermissionCount() > 0 || type_ == POST_INSTALL_PERMISSIONS_PROMPT;
387}
388
[email protected]c82da8c42012-06-08 19:49:11389void ExtensionInstallPrompt::Prompt::AppendRatingStars(
390 StarAppender appender, void* data) const {
391 CHECK(appender);
[email protected]34b5f7f2014-01-29 02:48:11392 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT);
[email protected]c82da8c42012-06-08 19:49:11393 int rating_integer = floor(average_rating_);
394 double rating_fractional = average_rating_ - rating_integer;
395
396 if (rating_fractional > 0.66) {
397 rating_integer++;
398 }
399
400 if (rating_fractional < 0.33 || rating_fractional > 0.66) {
401 rating_fractional = 0;
402 }
403
404 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
405 int i;
406 for (i = 0; i < rating_integer; i++) {
407 appender(rb.GetImageSkiaNamed(IDR_EXTENSIONS_RATING_STAR_ON), data);
408 }
409 if (rating_fractional) {
410 appender(rb.GetImageSkiaNamed(IDR_EXTENSIONS_RATING_STAR_HALF_LEFT), data);
411 i++;
412 }
413 for (; i < kMaxExtensionRating; i++) {
414 appender(rb.GetImageSkiaNamed(IDR_EXTENSIONS_RATING_STAR_OFF), data);
415 }
416}
417
[email protected]6a72a632013-12-12 22:22:00418base::string16 ExtensionInstallPrompt::Prompt::GetRatingCount() const {
[email protected]34b5f7f2014-01-29 02:48:11419 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT);
[email protected]6725048e2013-10-24 21:47:14420 return l10n_util::GetStringFUTF16(IDS_EXTENSION_RATING_COUNT,
421 base::IntToString16(rating_count_));
[email protected]c82da8c42012-06-08 19:49:11422}
423
[email protected]6a72a632013-12-12 22:22:00424base::string16 ExtensionInstallPrompt::Prompt::GetUserCount() const {
[email protected]34b5f7f2014-01-29 02:48:11425 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT);
[email protected]dcde34b32013-07-31 02:28:45426
427 if (show_user_count_) {
[email protected]6725048e2013-10-24 21:47:14428 return l10n_util::GetStringFUTF16(IDS_EXTENSION_USER_COUNT,
429 base::UTF8ToUTF16(localized_user_count_));
[email protected]dcde34b32013-07-31 02:28:45430 }
[email protected]6725048e2013-10-24 21:47:14431 return base::string16();
[email protected]c82da8c42012-06-08 19:49:11432}
433
434size_t ExtensionInstallPrompt::Prompt::GetPermissionCount() const {
435 return permissions_.size();
436}
437
[email protected]8ab7e6c2013-07-11 21:15:03438size_t ExtensionInstallPrompt::Prompt::GetPermissionsDetailsCount() const {
439 return details_.size();
440}
441
[email protected]6a72a632013-12-12 22:22:00442base::string16 ExtensionInstallPrompt::Prompt::GetPermission(size_t index)
443 const {
[email protected]c82da8c42012-06-08 19:49:11444 CHECK_LT(index, permissions_.size());
[email protected]ef2654e42012-08-11 03:57:56445 return permissions_[index];
[email protected]c82da8c42012-06-08 19:49:11446}
447
[email protected]6a72a632013-12-12 22:22:00448base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsDetails(
[email protected]8ab7e6c2013-07-11 21:15:03449 size_t index) const {
450 CHECK_LT(index, details_.size());
451 return details_[index];
452}
453
[email protected]79a6f99a2013-08-29 00:32:58454bool ExtensionInstallPrompt::Prompt::GetIsShowingDetails(
455 DetailsType type, size_t index) const {
456 switch (type) {
457 case PERMISSIONS_DETAILS:
458 CHECK_LT(index, is_showing_details_for_permissions_.size());
459 return is_showing_details_for_permissions_[index];
460 case OAUTH_DETAILS:
461 CHECK_LT(index, is_showing_details_for_oauth_.size());
462 return is_showing_details_for_oauth_[index];
463 case RETAINED_FILES_DETAILS:
464 return is_showing_details_for_retained_files_;
465 }
466 return false;
467}
468
[email protected]b70a2d92012-06-28 19:51:21469size_t ExtensionInstallPrompt::Prompt::GetOAuthIssueCount() const {
470 return oauth_issue_advice_.size();
471}
472
473const IssueAdviceInfoEntry& ExtensionInstallPrompt::Prompt::GetOAuthIssue(
474 size_t index) const {
475 CHECK_LT(index, oauth_issue_advice_.size());
476 return oauth_issue_advice_[index];
477}
478
[email protected]a2886e8b2013-06-08 05:15:02479size_t ExtensionInstallPrompt::Prompt::GetRetainedFileCount() const {
480 return retained_files_.size();
481}
482
[email protected]6a72a632013-12-12 22:22:00483base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFile(size_t index)
484 const {
[email protected]a2886e8b2013-06-08 05:15:02485 CHECK_LT(index, retained_files_.size());
[email protected]6725048e2013-10-24 21:47:14486 return retained_files_[index].AsUTF16Unsafe();
[email protected]a2886e8b2013-06-08 05:15:02487}
488
489bool ExtensionInstallPrompt::Prompt::ShouldDisplayRevokeFilesButton() const {
490 return !retained_files_.empty();
491}
492
[email protected]5db2e882012-12-20 10:17:26493ExtensionInstallPrompt::ShowParams::ShowParams(content::WebContents* contents)
494 : parent_web_contents(contents),
495 parent_window(NativeWindowForWebContents(contents)),
496 navigator(contents) {
497}
498
499ExtensionInstallPrompt::ShowParams::ShowParams(
500 gfx::NativeWindow window,
501 content::PageNavigator* navigator)
502 : parent_web_contents(NULL),
503 parent_window(window),
504 navigator(navigator) {
505}
506
[email protected]c82da8c42012-06-08 19:49:11507// static
508scoped_refptr<Extension>
509 ExtensionInstallPrompt::GetLocalizedExtensionForDisplay(
[email protected]023b3d12013-12-23 18:46:49510 const base::DictionaryValue* manifest,
[email protected]c422a862012-07-31 15:46:13511 int flags,
[email protected]c82da8c42012-06-08 19:49:11512 const std::string& id,
513 const std::string& localized_name,
514 const std::string& localized_description,
515 std::string* error) {
[email protected]023b3d12013-12-23 18:46:49516 scoped_ptr<base::DictionaryValue> localized_manifest;
[email protected]c82da8c42012-06-08 19:49:11517 if (!localized_name.empty() || !localized_description.empty()) {
518 localized_manifest.reset(manifest->DeepCopy());
519 if (!localized_name.empty()) {
[email protected]6bf90612013-08-15 00:36:27520 localized_manifest->SetString(extensions::manifest_keys::kName,
[email protected]c82da8c42012-06-08 19:49:11521 localized_name);
522 }
523 if (!localized_description.empty()) {
[email protected]6bf90612013-08-15 00:36:27524 localized_manifest->SetString(extensions::manifest_keys::kDescription,
[email protected]c82da8c42012-06-08 19:49:11525 localized_description);
526 }
527 }
528
529 return Extension::Create(
[email protected]650b2d52013-02-10 03:41:45530 base::FilePath(),
[email protected]1d5e58b2013-01-31 08:41:40531 Manifest::INTERNAL,
[email protected]c82da8c42012-06-08 19:49:11532 localized_manifest.get() ? *localized_manifest.get() : *manifest,
[email protected]c422a862012-07-31 15:46:13533 flags,
[email protected]c82da8c42012-06-08 19:49:11534 id,
535 error);
536}
537
[email protected]7f165342014-02-12 09:22:22538ExtensionInstallPrompt::ExtensionInstallPrompt(content::WebContents* contents)
[email protected]f1e98482013-12-27 00:45:59539 : OAuth2TokenService::Consumer("extensions_install"),
540 record_oauth2_grant_(false),
[email protected]b3a25092013-05-28 22:08:16541 ui_loop_(base::MessageLoop::current()),
[email protected]c82da8c42012-06-08 19:49:11542 extension_(NULL),
[email protected]7f165342014-02-12 09:22:22543 bundle_(NULL),
[email protected]91e51d612012-10-21 23:03:05544 install_ui_(ExtensionInstallUI::Create(ProfileForWebContents(contents))),
[email protected]5db2e882012-12-20 10:17:26545 show_params_(contents),
[email protected]c82da8c42012-06-08 19:49:11546 delegate_(NULL),
[email protected]5db2e882012-12-20 10:17:26547 prompt_(UNSET_PROMPT_TYPE) {
548 prompt_.SetUserNameFromProfile(install_ui_->profile());
549}
550
551ExtensionInstallPrompt::ExtensionInstallPrompt(
552 Profile* profile,
553 gfx::NativeWindow native_window,
554 content::PageNavigator* navigator)
[email protected]f1e98482013-12-27 00:45:59555 : OAuth2TokenService::Consumer("extensions_install"),
556 record_oauth2_grant_(false),
[email protected]b3a25092013-05-28 22:08:16557 ui_loop_(base::MessageLoop::current()),
[email protected]5db2e882012-12-20 10:17:26558 extension_(NULL),
[email protected]7f165342014-02-12 09:22:22559 bundle_(NULL),
[email protected]5db2e882012-12-20 10:17:26560 install_ui_(ExtensionInstallUI::Create(profile)),
561 show_params_(native_window, navigator),
562 delegate_(NULL),
563 prompt_(UNSET_PROMPT_TYPE) {
564 prompt_.SetUserNameFromProfile(install_ui_->profile());
[email protected]c82da8c42012-06-08 19:49:11565}
566
567ExtensionInstallPrompt::~ExtensionInstallPrompt() {
568}
569
570void ExtensionInstallPrompt::ConfirmBundleInstall(
571 extensions::BundleInstaller* bundle,
[email protected]c2e66e12012-06-27 06:27:06572 const PermissionSet* permissions) {
[email protected]b3a25092013-05-28 22:08:16573 DCHECK(ui_loop_ == base::MessageLoop::current());
[email protected]c82da8c42012-06-08 19:49:11574 bundle_ = bundle;
575 permissions_ = permissions;
576 delegate_ = bundle;
[email protected]5db2e882012-12-20 10:17:26577 prompt_.set_type(BUNDLE_INSTALL_PROMPT);
[email protected]c82da8c42012-06-08 19:49:11578
[email protected]4e494872013-09-06 09:13:54579 ShowConfirmation();
[email protected]c82da8c42012-06-08 19:49:11580}
581
[email protected]734bcec2012-10-08 20:29:05582void ExtensionInstallPrompt::ConfirmStandaloneInstall(
[email protected]c82da8c42012-06-08 19:49:11583 Delegate* delegate,
584 const Extension* extension,
585 SkBitmap* icon,
586 const ExtensionInstallPrompt::Prompt& prompt) {
[email protected]b3a25092013-05-28 22:08:16587 DCHECK(ui_loop_ == base::MessageLoop::current());
[email protected]c82da8c42012-06-08 19:49:11588 extension_ = extension;
589 permissions_ = extension->GetActivePermissions();
590 delegate_ = delegate;
591 prompt_ = prompt;
[email protected]c82da8c42012-06-08 19:49:11592
593 SetIcon(icon);
[email protected]4e494872013-09-06 09:13:54594 ShowConfirmation();
[email protected]c82da8c42012-06-08 19:49:11595}
596
[email protected]af6efb22012-10-12 02:23:05597void ExtensionInstallPrompt::ConfirmWebstoreInstall(
598 Delegate* delegate,
599 const Extension* extension,
600 const SkBitmap* icon,
601 const ShowDialogCallback& show_dialog_callback) {
[email protected]c82da8c42012-06-08 19:49:11602 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the
603 // remaining fields.
604 extension_ = extension;
605 SetIcon(icon);
[email protected]af6efb22012-10-12 02:23:05606 ConfirmInstall(delegate, extension, show_dialog_callback);
[email protected]c82da8c42012-06-08 19:49:11607}
608
[email protected]af6efb22012-10-12 02:23:05609void ExtensionInstallPrompt::ConfirmInstall(
610 Delegate* delegate,
611 const Extension* extension,
612 const ShowDialogCallback& show_dialog_callback) {
[email protected]b3a25092013-05-28 22:08:16613 DCHECK(ui_loop_ == base::MessageLoop::current());
[email protected]c82da8c42012-06-08 19:49:11614 extension_ = extension;
615 permissions_ = extension->GetActivePermissions();
616 delegate_ = delegate;
[email protected]5db2e882012-12-20 10:17:26617 prompt_.set_type(INSTALL_PROMPT);
[email protected]af6efb22012-10-12 02:23:05618 show_dialog_callback_ = show_dialog_callback;
[email protected]c82da8c42012-06-08 19:49:11619
620 // We special-case themes to not show any confirm UI. Instead they are
621 // immediately installed, and then we show an infobar (see OnInstallSuccess)
622 // to allow the user to revert if they don't like it.
623 //
624 // We don't do this in the case where off-store extension installs are
625 // disabled because in that case, we don't show the dangerous download UI, so
626 // we need the UI confirmation.
627 if (extension->is_theme()) {
628 if (extension->from_webstore() ||
[email protected]544471a2012-10-13 05:27:09629 extensions::FeatureSwitch::easy_off_store_install()->IsEnabled()) {
[email protected]c82da8c42012-06-08 19:49:11630 delegate->InstallUIProceed();
631 return;
632 }
633 }
634
635 LoadImageIfNeeded();
636}
637
638void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate,
639 const Extension* extension) {
[email protected]b3a25092013-05-28 22:08:16640 DCHECK(ui_loop_ == base::MessageLoop::current());
[email protected]c82da8c42012-06-08 19:49:11641 extension_ = extension;
642 permissions_ = extension->GetActivePermissions();
643 delegate_ = delegate;
[email protected]ab6c7be42014-01-16 02:05:54644 prompt_.set_type(extension->is_ephemeral() ? LAUNCH_PROMPT :
645 RE_ENABLE_PROMPT);
[email protected]c82da8c42012-06-08 19:49:11646
647 LoadImageIfNeeded();
648}
649
[email protected]612a1cb12012-10-17 13:18:03650void ExtensionInstallPrompt::ConfirmExternalInstall(
[email protected]c8ff7c9e2013-04-20 12:36:27651 Delegate* delegate,
652 const Extension* extension,
[email protected]34b5f7f2014-01-29 02:48:11653 const ShowDialogCallback& show_dialog_callback,
654 const Prompt& prompt) {
[email protected]b3a25092013-05-28 22:08:16655 DCHECK(ui_loop_ == base::MessageLoop::current());
[email protected]612a1cb12012-10-17 13:18:03656 extension_ = extension;
657 permissions_ = extension->GetActivePermissions();
658 delegate_ = delegate;
[email protected]34b5f7f2014-01-29 02:48:11659 prompt_ = prompt;
[email protected]c8ff7c9e2013-04-20 12:36:27660 show_dialog_callback_ = show_dialog_callback;
[email protected]612a1cb12012-10-17 13:18:03661
662 LoadImageIfNeeded();
663}
664
[email protected]c82da8c42012-06-08 19:49:11665void ExtensionInstallPrompt::ConfirmPermissions(
666 Delegate* delegate,
667 const Extension* extension,
[email protected]c2e66e12012-06-27 06:27:06668 const PermissionSet* permissions) {
[email protected]b3a25092013-05-28 22:08:16669 DCHECK(ui_loop_ == base::MessageLoop::current());
[email protected]c82da8c42012-06-08 19:49:11670 extension_ = extension;
671 permissions_ = permissions;
672 delegate_ = delegate;
[email protected]5db2e882012-12-20 10:17:26673 prompt_.set_type(PERMISSIONS_PROMPT);
[email protected]c82da8c42012-06-08 19:49:11674
675 LoadImageIfNeeded();
676}
677
[email protected]f746b3f2012-07-03 17:53:37678void ExtensionInstallPrompt::ConfirmIssueAdvice(
679 Delegate* delegate,
680 const Extension* extension,
681 const IssueAdviceInfo& issue_advice) {
[email protected]b3a25092013-05-28 22:08:16682 DCHECK(ui_loop_ == base::MessageLoop::current());
[email protected]f746b3f2012-07-03 17:53:37683 extension_ = extension;
684 delegate_ = delegate;
[email protected]5db2e882012-12-20 10:17:26685 prompt_.set_type(PERMISSIONS_PROMPT);
[email protected]f746b3f2012-07-03 17:53:37686
687 record_oauth2_grant_ = true;
688 prompt_.SetOAuthIssueAdvice(issue_advice);
689
690 LoadImageIfNeeded();
691}
692
[email protected]a2886e8b2013-06-08 05:15:02693void ExtensionInstallPrompt::ReviewPermissions(
694 Delegate* delegate,
695 const Extension* extension,
696 const std::vector<base::FilePath>& retained_file_paths) {
[email protected]b3a25092013-05-28 22:08:16697 DCHECK(ui_loop_ == base::MessageLoop::current());
[email protected]15d267b42013-02-14 23:43:32698 extension_ = extension;
699 permissions_ = extension->GetActivePermissions();
[email protected]a2886e8b2013-06-08 05:15:02700 prompt_.set_retained_files(retained_file_paths);
[email protected]15d267b42013-02-14 23:43:32701 delegate_ = delegate;
702 prompt_.set_type(POST_INSTALL_PERMISSIONS_PROMPT);
703
704 LoadImageIfNeeded();
705}
706
[email protected]c82da8c42012-06-08 19:49:11707void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension,
708 SkBitmap* icon) {
709 extension_ = extension;
710 SetIcon(icon);
711
712 install_ui_->OnInstallSuccess(extension, &icon_);
713}
714
[email protected]bf3d9df2012-07-24 23:20:27715void ExtensionInstallPrompt::OnInstallFailure(
716 const extensions::CrxInstallerError& error) {
[email protected]c82da8c42012-06-08 19:49:11717 install_ui_->OnInstallFailure(error);
718}
719
720void ExtensionInstallPrompt::SetIcon(const SkBitmap* image) {
721 if (image)
722 icon_ = *image;
723 else
724 icon_ = SkBitmap();
[email protected]dd46a4ce2012-09-15 10:50:50725 if (icon_.empty()) {
726 // Let's set default icon bitmap whose size is equal to the default icon's
727 // pixel size under maximal supported scale factor. If the bitmap is larger
728 // than the one we need, it will be scaled down by the ui code.
729 icon_ = GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app());
730 }
[email protected]c82da8c42012-06-08 19:49:11731}
732
[email protected]ec7de0c5a2012-11-16 07:40:47733void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image) {
[email protected]c82da8c42012-06-08 19:49:11734 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap());
[email protected]4e494872013-09-06 09:13:54735 ShowConfirmation();
[email protected]c82da8c42012-06-08 19:49:11736}
737
738void ExtensionInstallPrompt::LoadImageIfNeeded() {
739 // Bundle install prompts do not have an icon.
[email protected]5db2e882012-12-20 10:17:26740 // Also |install_ui_.profile()| can be NULL in unit tests.
741 if (!icon_.empty() || !install_ui_->profile()) {
[email protected]4e494872013-09-06 09:13:54742 ShowConfirmation();
[email protected]c82da8c42012-06-08 19:49:11743 return;
744 }
745
746 // Load the image asynchronously. For the response, check OnImageLoaded.
[email protected]993da5e2013-03-23 21:25:16747 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource(
[email protected]702d8b42013-02-27 20:55:50748 extension_,
749 extension_misc::EXTENSION_ICON_LARGE,
750 ExtensionIconSet::MATCH_BIGGER);
[email protected]dd46a4ce2012-09-15 10:50:50751 // Load the icon whose pixel size is large enough to be displayed under
752 // maximal supported scale factor. UI code will scale the icon down if needed.
753 // TODO(tbarzic): We should use IconImage here and load the required bitmap
754 // lazily.
755 int pixel_size = GetSizeForMaxScaleFactor(kIconSize);
[email protected]5db2e882012-12-20 10:17:26756 extensions::ImageLoader::Get(install_ui_->profile())->LoadImageAsync(
[email protected]ec7de0c5a2012-11-16 07:40:47757 extension_, image, gfx::Size(pixel_size, pixel_size),
758 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr()));
[email protected]c82da8c42012-06-08 19:49:11759}
760
[email protected]4f3fb352013-07-17 04:07:01761void ExtensionInstallPrompt::OnGetTokenSuccess(
762 const OAuth2TokenService::Request* request,
763 const std::string& access_token,
764 const base::Time& expiration_time) {
765 DCHECK_EQ(login_token_request_.get(), request);
766 login_token_request_.reset();
767
768 const extensions::OAuth2Info& oauth2_info =
769 extensions::OAuth2Info::GetOAuth2Info(extension_);
770
[email protected]b70a2d92012-06-28 19:51:21771 token_flow_.reset(new OAuth2MintTokenFlow(
[email protected]4f3fb352013-07-17 04:07:01772 install_ui_->profile()->GetRequestContext(),
[email protected]b70a2d92012-06-28 19:51:21773 this,
774 OAuth2MintTokenFlow::Parameters(
[email protected]4f3fb352013-07-17 04:07:01775 access_token,
[email protected]b70a2d92012-06-28 19:51:21776 extension_->id(),
777 oauth2_info.client_id,
[email protected]d4a37f1c2012-07-09 21:36:13778 oauth2_info.scopes,
[email protected]b70a2d92012-06-28 19:51:21779 OAuth2MintTokenFlow::MODE_ISSUE_ADVICE)));
780 token_flow_->Start();
781}
782
[email protected]4f3fb352013-07-17 04:07:01783void ExtensionInstallPrompt::OnGetTokenFailure(
784 const OAuth2TokenService::Request* request,
785 const GoogleServiceAuthError& error) {
786 DCHECK_EQ(login_token_request_.get(), request);
787 login_token_request_.reset();
788 ShowConfirmation();
789}
790
[email protected]b70a2d92012-06-28 19:51:21791void ExtensionInstallPrompt::OnIssueAdviceSuccess(
792 const IssueAdviceInfo& advice_info) {
793 prompt_.SetOAuthIssueAdvice(advice_info);
794 record_oauth2_grant_ = true;
795 ShowConfirmation();
796}
797
798void ExtensionInstallPrompt::OnMintTokenFailure(
799 const GoogleServiceAuthError& error) {
800 ShowConfirmation();
801}
802
[email protected]c82da8c42012-06-08 19:49:11803void ExtensionInstallPrompt::ShowConfirmation() {
[email protected]62a28d7c2013-12-28 01:34:49804 if (prompt_.type() == INSTALL_PROMPT)
805 prompt_.set_experiment(ExtensionInstallPromptExperiment::Find());
806 else
807 prompt_.set_experiment(ExtensionInstallPromptExperiment::ControlGroup());
808
[email protected]dc24976f2013-06-02 21:15:09809 if (permissions_.get() &&
[email protected]13c68b62013-05-17 11:29:05810 (!extension_ ||
811 !extensions::PermissionsData::ShouldSkipPermissionWarnings(
812 extension_))) {
[email protected]1d5e58b2013-01-31 08:41:40813 Manifest::Type extension_type = extension_ ?
814 extension_->GetType() : Manifest::TYPE_UNKNOWN;
[email protected]8ab7e6c2013-07-11 21:15:03815 prompt_.SetPermissions(
[email protected]c41003472013-10-19 15:37:25816 extensions::PermissionMessageProvider::Get()->
817 GetWarningMessages(permissions_, extension_type));
[email protected]8ab7e6c2013-07-11 21:15:03818 prompt_.SetPermissionsDetails(
[email protected]c41003472013-10-19 15:37:25819 extensions::PermissionMessageProvider::Get()->
820 GetWarningMessagesDetails(permissions_, extension_type));
[email protected]bebe1d02012-08-02 20:17:09821 }
[email protected]c82da8c42012-06-08 19:49:11822
[email protected]5db2e882012-12-20 10:17:26823 switch (prompt_.type()) {
[email protected]c82da8c42012-06-08 19:49:11824 case PERMISSIONS_PROMPT:
825 case RE_ENABLE_PROMPT:
826 case INLINE_INSTALL_PROMPT:
[email protected]612a1cb12012-10-17 13:18:03827 case EXTERNAL_INSTALL_PROMPT:
[email protected]15d267b42013-02-14 23:43:32828 case INSTALL_PROMPT:
[email protected]1a93d8d2013-10-27 23:09:20829 case LAUNCH_PROMPT:
[email protected]15d267b42013-02-14 23:43:32830 case POST_INSTALL_PERMISSIONS_PROMPT: {
[email protected]c82da8c42012-06-08 19:49:11831 prompt_.set_extension(extension_);
[email protected]32e7a9b2013-01-23 23:00:19832 prompt_.set_icon(gfx::Image::CreateFrom1xBitmap(icon_));
[email protected]c82da8c42012-06-08 19:49:11833 break;
834 }
835 case BUNDLE_INSTALL_PROMPT: {
836 prompt_.set_bundle(bundle_);
[email protected]c82da8c42012-06-08 19:49:11837 break;
838 }
839 default:
840 NOTREACHED() << "Unknown message";
[email protected]af6efb22012-10-12 02:23:05841 return;
[email protected]c82da8c42012-06-08 19:49:11842 }
[email protected]af6efb22012-10-12 02:23:05843
844 if (AutoConfirmPrompt(delegate_))
845 return;
846
[email protected]5db2e882012-12-20 10:17:26847 if (show_dialog_callback_.is_null())
848 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_);
849 else
850 show_dialog_callback_.Run(show_params_, delegate_, prompt_);
[email protected]c82da8c42012-06-08 19:49:11851}