Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(757)

Side by Side Diff: chrome/browser/extensions/extension_install_prompt.cc

Issue 580363002: Update app info and install prompt UI to show retained devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_install_prompt.h" 5 #include "chrome/browser/extensions/extension_install_prompt.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 84 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
85 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 85 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
86 }; 86 };
87 static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 87 static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
88 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, 88 IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
89 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, 89 IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
90 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, 90 IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
91 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON, 91 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON,
92 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON, 92 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON,
93 0, // External installs use different strings for extensions/apps. 93 0, // External installs use different strings for extensions/apps.
94 IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_BUTTON, 94 0, // Different strings depending on the files and devices retained.
95 IDS_EXTENSION_PROMPT_LAUNCH_BUTTON, 95 IDS_EXTENSION_PROMPT_LAUNCH_BUTTON,
96 IDS_EXTENSION_PROMPT_REMOTE_INSTALL_BUTTON, 96 IDS_EXTENSION_PROMPT_REMOTE_INSTALL_BUTTON,
97 }; 97 };
98 static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 98 static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
99 0, // These all use the platform's default cancel label. 99 0, // These all use the platform's default cancel label.
100 0, 100 0,
101 0, 101 0,
102 0, 102 0,
103 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON, 103 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON,
104 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ABORT_BUTTON, 104 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ABORT_BUTTON,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 case ExtensionInstallPrompt::UNSET_PROMPT_TYPE: 200 case ExtensionInstallPrompt::UNSET_PROMPT_TYPE:
201 case ExtensionInstallPrompt::NUM_PROMPT_TYPES: 201 case ExtensionInstallPrompt::NUM_PROMPT_TYPES:
202 break; 202 break;
203 } 203 }
204 return "OTHER"; 204 return "OTHER";
205 } 205 }
206 206
207 ExtensionInstallPrompt::Prompt::Prompt(PromptType type) 207 ExtensionInstallPrompt::Prompt::Prompt(PromptType type)
208 : type_(type), 208 : type_(type),
209 is_showing_details_for_retained_files_(false), 209 is_showing_details_for_retained_files_(false),
210 is_showing_details_for_retained_devices_(false),
210 extension_(NULL), 211 extension_(NULL),
211 bundle_(NULL), 212 bundle_(NULL),
212 average_rating_(0.0), 213 average_rating_(0.0),
213 rating_count_(0), 214 rating_count_(0),
214 show_user_count_(false), 215 show_user_count_(false),
215 has_webstore_data_(false) { 216 has_webstore_data_(false) {
216 } 217 }
217 218
218 ExtensionInstallPrompt::Prompt::~Prompt() { 219 ExtensionInstallPrompt::Prompt::~Prompt() {
219 } 220 }
(...skipping 15 matching lines...) Expand all
235 DetailsType type, 236 DetailsType type,
236 size_t index, 237 size_t index,
237 bool is_showing_details) { 238 bool is_showing_details) {
238 switch (type) { 239 switch (type) {
239 case PERMISSIONS_DETAILS: 240 case PERMISSIONS_DETAILS:
240 is_showing_details_for_permissions_[index] = is_showing_details; 241 is_showing_details_for_permissions_[index] = is_showing_details;
241 break; 242 break;
242 case RETAINED_FILES_DETAILS: 243 case RETAINED_FILES_DETAILS:
243 is_showing_details_for_retained_files_ = is_showing_details; 244 is_showing_details_for_retained_files_ = is_showing_details;
244 break; 245 break;
246 case RETAINED_DEVICES_DETAILS:
247 is_showing_details_for_retained_devices_ = is_showing_details;
248 break;
245 } 249 }
246 } 250 }
247 251
248 void ExtensionInstallPrompt::Prompt::SetWebstoreData( 252 void ExtensionInstallPrompt::Prompt::SetWebstoreData(
249 const std::string& localized_user_count, 253 const std::string& localized_user_count,
250 bool show_user_count, 254 bool show_user_count,
251 double average_rating, 255 double average_rating,
252 int rating_count) { 256 int rating_count) {
253 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); 257 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT);
254 localized_user_count_ = localized_user_count; 258 localized_user_count_ = localized_user_count;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 else 299 else
296 resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_EXTENSION; 300 resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_EXTENSION;
297 return l10n_util::GetStringUTF16(resource_id); 301 return l10n_util::GetStringUTF16(resource_id);
298 } else { 302 } else {
299 return l10n_util::GetStringFUTF16( 303 return l10n_util::GetStringFUTF16(
300 kHeadingIds[type_], base::UTF8ToUTF16(extension_->name())); 304 kHeadingIds[type_], base::UTF8ToUTF16(extension_->name()));
301 } 305 }
302 } 306 }
303 307
304 int ExtensionInstallPrompt::Prompt::GetDialogButtons() const { 308 int ExtensionInstallPrompt::Prompt::GetDialogButtons() const {
305 if (type_ == POST_INSTALL_PERMISSIONS_PROMPT && 309 if (type_ == POST_INSTALL_PERMISSIONS_PROMPT && ShouldDisplayRevokeButton()) {
306 ShouldDisplayRevokeFilesButton()) {
307 return kButtons[type_] | ui::DIALOG_BUTTON_OK; 310 return kButtons[type_] | ui::DIALOG_BUTTON_OK;
308 } 311 }
309 312
310 return kButtons[type_]; 313 return kButtons[type_];
311 } 314 }
312 315
313 bool ExtensionInstallPrompt::Prompt::ShouldShowExplanationText() const { 316 bool ExtensionInstallPrompt::Prompt::ShouldShowExplanationText() const {
314 return type_ == INSTALL_PROMPT && extension_->is_extension() && 317 return type_ == INSTALL_PROMPT && extension_->is_extension() &&
315 experiment_.get() && experiment_->text_only(); 318 experiment_.get() && experiment_->text_only();
316 } 319 }
317 320
318 bool ExtensionInstallPrompt::Prompt::HasAcceptButtonLabel() const { 321 bool ExtensionInstallPrompt::Prompt::HasAcceptButtonLabel() const {
322 if (type_ == POST_INSTALL_PERMISSIONS_PROMPT)
323 return ShouldDisplayRevokeButton();
324
319 if (kAcceptButtonIds[type_] == 0) 325 if (kAcceptButtonIds[type_] == 0)
320 return false; 326 return false;
321 327
322 if (type_ == POST_INSTALL_PERMISSIONS_PROMPT)
323 return ShouldDisplayRevokeFilesButton();
324
325 return true; 328 return true;
326 } 329 }
327 330
328 base::string16 ExtensionInstallPrompt::Prompt::GetAcceptButtonLabel() const { 331 base::string16 ExtensionInstallPrompt::Prompt::GetAcceptButtonLabel() const {
329 if (type_ == EXTERNAL_INSTALL_PROMPT) { 332 if (type_ == EXTERNAL_INSTALL_PROMPT) {
330 int id = -1; 333 int id = -1;
331 if (extension_->is_app()) 334 if (extension_->is_app())
332 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_APP; 335 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_APP;
333 else if (extension_->is_theme()) 336 else if (extension_->is_theme())
334 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_THEME; 337 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_THEME;
335 else 338 else
336 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_EXTENSION; 339 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_EXTENSION;
337 return l10n_util::GetStringUTF16(id); 340 return l10n_util::GetStringUTF16(id);
341 } else if (type_ == POST_INSTALL_PERMISSIONS_PROMPT) {
342 int id = -1;
343 if (GetRetainedFileCount() && GetRetainedDeviceCount()) {
344 id =
345 IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_AND_DEVICES_BUTT ON;
tapted 2014/09/19 04:09:09 (hm I guess clang-format put a line-break there to
346 } else if (GetRetainedFileCount()) {
347 id = IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_BUTTON;
348 } else {
349 DCHECK_LT(0U, GetRetainedDeviceCount());
350 id = IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_DEVICES_BUTTON;
351 }
352 return l10n_util::GetStringUTF16(id);
338 } 353 }
339 if (ShouldShowExplanationText()) 354 if (ShouldShowExplanationText())
340 return experiment_->GetOkButtonText(); 355 return experiment_->GetOkButtonText();
341 return l10n_util::GetStringUTF16(kAcceptButtonIds[type_]); 356 return l10n_util::GetStringUTF16(kAcceptButtonIds[type_]);
342 } 357 }
343 358
344 bool ExtensionInstallPrompt::Prompt::HasAbortButtonLabel() const { 359 bool ExtensionInstallPrompt::Prompt::HasAbortButtonLabel() const {
345 if (ShouldShowExplanationText()) 360 if (ShouldShowExplanationText())
346 return true; 361 return true;
347 return kAbortButtonIds[type_] > 0; 362 return kAbortButtonIds[type_] > 0;
(...skipping 19 matching lines...) Expand all
367 IDS_EXTENSION_PROMPT_RETAINED_FILES_FEW, 382 IDS_EXTENSION_PROMPT_RETAINED_FILES_FEW,
368 IDS_EXTENSION_PROMPT_RETAINED_FILES_MANY, 383 IDS_EXTENSION_PROMPT_RETAINED_FILES_MANY,
369 }; 384 };
370 std::vector<int> message_ids; 385 std::vector<int> message_ids;
371 for (size_t i = 0; i < arraysize(kRetainedFilesMessageIDs); i++) { 386 for (size_t i = 0; i < arraysize(kRetainedFilesMessageIDs); i++) {
372 message_ids.push_back(kRetainedFilesMessageIDs[i]); 387 message_ids.push_back(kRetainedFilesMessageIDs[i]);
373 } 388 }
374 return l10n_util::GetPluralStringFUTF16(message_ids, GetRetainedFileCount()); 389 return l10n_util::GetPluralStringFUTF16(message_ids, GetRetainedFileCount());
375 } 390 }
376 391
392 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedDevicesHeading()
393 const {
394 const int kRetainedDevicesMessageIDs[6] = {
395 IDS_EXTENSION_PROMPT_RETAINED_DEVICES_DEFAULT,
396 IDS_EXTENSION_PROMPT_RETAINED_DEVICE_SINGULAR,
397 IDS_EXTENSION_PROMPT_RETAINED_DEVICES_ZERO,
398 IDS_EXTENSION_PROMPT_RETAINED_DEVICES_TWO,
399 IDS_EXTENSION_PROMPT_RETAINED_DEVICES_FEW,
400 IDS_EXTENSION_PROMPT_RETAINED_DEVICES_MANY,
401 };
402 std::vector<int> message_ids;
tapted 2014/09/19 04:09:09 (optional) I would have used the iterator begin/en
Reilly Grant (use Gerrit) 2014/09/19 19:30:09 Done.
403 for (size_t i = 0; i < arraysize(kRetainedDevicesMessageIDs); i++) {
404 message_ids.push_back(kRetainedDevicesMessageIDs[i]);
405 }
406 return l10n_util::GetPluralStringFUTF16(message_ids,
407 GetRetainedDeviceCount());
408 }
409
377 bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { 410 bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const {
378 return GetPermissionCount() > 0 || type_ == POST_INSTALL_PERMISSIONS_PROMPT; 411 return GetPermissionCount() > 0 || type_ == POST_INSTALL_PERMISSIONS_PROMPT;
379 } 412 }
380 413
381 void ExtensionInstallPrompt::Prompt::AppendRatingStars( 414 void ExtensionInstallPrompt::Prompt::AppendRatingStars(
382 StarAppender appender, void* data) const { 415 StarAppender appender, void* data) const {
383 CHECK(appender); 416 CHECK(appender);
384 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); 417 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT);
385 int rating_integer = floor(average_rating_); 418 int rating_integer = floor(average_rating_);
386 double rating_fractional = average_rating_ - rating_integer; 419 double rating_fractional = average_rating_ - rating_integer;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 } 477 }
445 478
446 bool ExtensionInstallPrompt::Prompt::GetIsShowingDetails( 479 bool ExtensionInstallPrompt::Prompt::GetIsShowingDetails(
447 DetailsType type, size_t index) const { 480 DetailsType type, size_t index) const {
448 switch (type) { 481 switch (type) {
449 case PERMISSIONS_DETAILS: 482 case PERMISSIONS_DETAILS:
450 CHECK_LT(index, is_showing_details_for_permissions_.size()); 483 CHECK_LT(index, is_showing_details_for_permissions_.size());
451 return is_showing_details_for_permissions_[index]; 484 return is_showing_details_for_permissions_[index];
452 case RETAINED_FILES_DETAILS: 485 case RETAINED_FILES_DETAILS:
453 return is_showing_details_for_retained_files_; 486 return is_showing_details_for_retained_files_;
487 case RETAINED_DEVICES_DETAILS:
488 return is_showing_details_for_retained_devices_;
454 } 489 }
455 return false; 490 return false;
456 } 491 }
457 492
458 size_t ExtensionInstallPrompt::Prompt::GetRetainedFileCount() const { 493 size_t ExtensionInstallPrompt::Prompt::GetRetainedFileCount() const {
459 return retained_files_.size(); 494 return retained_files_.size();
460 } 495 }
461 496
462 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFile(size_t index) 497 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFile(size_t index)
463 const { 498 const {
464 CHECK_LT(index, retained_files_.size()); 499 CHECK_LT(index, retained_files_.size());
465 return retained_files_[index].AsUTF16Unsafe(); 500 return retained_files_[index].AsUTF16Unsafe();
466 } 501 }
467 502
468 bool ExtensionInstallPrompt::Prompt::ShouldDisplayRevokeFilesButton() const { 503 size_t ExtensionInstallPrompt::Prompt::GetRetainedDeviceCount() const {
469 return !retained_files_.empty(); 504 return retained_device_messages_.size();
505 }
506
507 bool ExtensionInstallPrompt::Prompt::ShouldDisplayRevokeButton() const {
508 return !retained_files_.empty() || !retained_device_messages_.empty();
509 }
510
511 const base::string16&
tapted 2014/09/19 04:09:09 nit: maybe return a value? just for consistency wi
Reilly Grant (use Gerrit) 2014/09/19 19:30:09 Done.
512 ExtensionInstallPrompt::Prompt::GetRetainedDeviceMessageString(
513 size_t index) const {
514 CHECK_LT(index, retained_device_messages_.size());
515 return retained_device_messages_[index];
470 } 516 }
471 517
472 ExtensionInstallPrompt::ShowParams::ShowParams(content::WebContents* contents) 518 ExtensionInstallPrompt::ShowParams::ShowParams(content::WebContents* contents)
473 : parent_web_contents(contents), 519 : parent_web_contents(contents),
474 parent_window(NativeWindowForWebContents(contents)), 520 parent_window(NativeWindowForWebContents(contents)),
475 navigator(contents) { 521 navigator(contents) {
476 } 522 }
477 523
478 ExtensionInstallPrompt::ShowParams::ShowParams( 524 ExtensionInstallPrompt::ShowParams::ShowParams(
479 gfx::NativeWindow window, 525 gfx::NativeWindow window,
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 permissions_ = permissions; 701 permissions_ = permissions;
656 delegate_ = delegate; 702 delegate_ = delegate;
657 prompt_ = new Prompt(PERMISSIONS_PROMPT); 703 prompt_ = new Prompt(PERMISSIONS_PROMPT);
658 704
659 LoadImageIfNeeded(); 705 LoadImageIfNeeded();
660 } 706 }
661 707
662 void ExtensionInstallPrompt::ReviewPermissions( 708 void ExtensionInstallPrompt::ReviewPermissions(
663 Delegate* delegate, 709 Delegate* delegate,
664 const Extension* extension, 710 const Extension* extension,
665 const std::vector<base::FilePath>& retained_file_paths) { 711 const std::vector<base::FilePath>& retained_file_paths,
712 const std::vector<base::string16>& retained_device_messages) {
666 DCHECK(ui_loop_ == base::MessageLoop::current()); 713 DCHECK(ui_loop_ == base::MessageLoop::current());
667 extension_ = extension; 714 extension_ = extension;
668 permissions_ = extension->permissions_data()->active_permissions(); 715 permissions_ = extension->permissions_data()->active_permissions();
669 prompt_ = new Prompt(POST_INSTALL_PERMISSIONS_PROMPT); 716 prompt_ = new Prompt(POST_INSTALL_PERMISSIONS_PROMPT);
670 prompt_->set_retained_files(retained_file_paths); 717 prompt_->set_retained_files(retained_file_paths);
718 prompt_->set_retained_device_messages(retained_device_messages);
671 delegate_ = delegate; 719 delegate_ = delegate;
672 720
673 LoadImageIfNeeded(); 721 LoadImageIfNeeded();
674 } 722 }
675 723
676 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, 724 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension,
677 SkBitmap* icon) { 725 SkBitmap* icon) {
678 extension_ = extension; 726 extension_ = extension;
679 SetIcon(icon); 727 SetIcon(icon);
680 728
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 } 824 }
777 825
778 if (AutoConfirmPrompt(delegate_)) 826 if (AutoConfirmPrompt(delegate_))
779 return; 827 return;
780 828
781 if (show_dialog_callback_.is_null()) 829 if (show_dialog_callback_.is_null())
782 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); 830 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_);
783 else 831 else
784 show_dialog_callback_.Run(show_params_, delegate_, prompt_); 832 show_dialog_callback_.Run(show_params_, delegate_, prompt_);
785 } 833 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698