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

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: Rebased to ToT. Created 6 years, 2 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 94 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
95 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 95 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
96 }; 96 };
97 static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 97 static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
98 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, 98 IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
99 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, 99 IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
100 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, 100 IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
101 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON, 101 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON,
102 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON, 102 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON,
103 0, // External installs use different strings for extensions/apps. 103 0, // External installs use different strings for extensions/apps.
104 IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_BUTTON, 104 0, // Different strings depending on the files and devices retained.
105 IDS_EXTENSION_PROMPT_LAUNCH_BUTTON, 105 IDS_EXTENSION_PROMPT_LAUNCH_BUTTON,
106 IDS_EXTENSION_PROMPT_REMOTE_INSTALL_BUTTON, 106 IDS_EXTENSION_PROMPT_REMOTE_INSTALL_BUTTON,
107 IDS_EXTENSION_PROMPT_REPAIR_BUTTON, 107 IDS_EXTENSION_PROMPT_REPAIR_BUTTON,
108 }; 108 };
109 static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 109 static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
110 0, // These all use the platform's default cancel label. 110 0, // These all use the platform's default cancel label.
111 0, 111 0,
112 0, 112 0,
113 0, 113 0,
114 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON, 114 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 case ExtensionInstallPrompt::UNSET_PROMPT_TYPE: 222 case ExtensionInstallPrompt::UNSET_PROMPT_TYPE:
223 case ExtensionInstallPrompt::NUM_PROMPT_TYPES: 223 case ExtensionInstallPrompt::NUM_PROMPT_TYPES:
224 break; 224 break;
225 } 225 }
226 return "OTHER"; 226 return "OTHER";
227 } 227 }
228 228
229 ExtensionInstallPrompt::Prompt::Prompt(PromptType type) 229 ExtensionInstallPrompt::Prompt::Prompt(PromptType type)
230 : type_(type), 230 : type_(type),
231 is_showing_details_for_retained_files_(false), 231 is_showing_details_for_retained_files_(false),
232 is_showing_details_for_retained_devices_(false),
232 extension_(NULL), 233 extension_(NULL),
233 bundle_(NULL), 234 bundle_(NULL),
234 average_rating_(0.0), 235 average_rating_(0.0),
235 rating_count_(0), 236 rating_count_(0),
236 show_user_count_(false), 237 show_user_count_(false),
237 has_webstore_data_(false) { 238 has_webstore_data_(false) {
238 } 239 }
239 240
240 ExtensionInstallPrompt::Prompt::~Prompt() { 241 ExtensionInstallPrompt::Prompt::~Prompt() {
241 } 242 }
(...skipping 23 matching lines...) Expand all
265 case PERMISSIONS_DETAILS: 266 case PERMISSIONS_DETAILS:
266 prompt_permissions_.is_showing_details[index] = is_showing_details; 267 prompt_permissions_.is_showing_details[index] = is_showing_details;
267 break; 268 break;
268 case WITHHELD_PERMISSIONS_DETAILS: 269 case WITHHELD_PERMISSIONS_DETAILS:
269 withheld_prompt_permissions_.is_showing_details[index] = 270 withheld_prompt_permissions_.is_showing_details[index] =
270 is_showing_details; 271 is_showing_details;
271 break; 272 break;
272 case RETAINED_FILES_DETAILS: 273 case RETAINED_FILES_DETAILS:
273 is_showing_details_for_retained_files_ = is_showing_details; 274 is_showing_details_for_retained_files_ = is_showing_details;
274 break; 275 break;
276 case RETAINED_DEVICES_DETAILS:
277 is_showing_details_for_retained_devices_ = is_showing_details;
278 break;
275 } 279 }
276 } 280 }
277 281
278 void ExtensionInstallPrompt::Prompt::SetWebstoreData( 282 void ExtensionInstallPrompt::Prompt::SetWebstoreData(
279 const std::string& localized_user_count, 283 const std::string& localized_user_count,
280 bool show_user_count, 284 bool show_user_count,
281 double average_rating, 285 double average_rating,
282 int rating_count) { 286 int rating_count) {
283 CHECK(AllowWebstoreData(type_)); 287 CHECK(AllowWebstoreData(type_));
284 localized_user_count_ = localized_user_count; 288 localized_user_count_ = localized_user_count;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 else 334 else
331 resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_EXTENSION; 335 resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_EXTENSION;
332 return l10n_util::GetStringUTF16(resource_id); 336 return l10n_util::GetStringUTF16(resource_id);
333 } else { 337 } else {
334 return l10n_util::GetStringFUTF16( 338 return l10n_util::GetStringFUTF16(
335 kHeadingIds[type_], base::UTF8ToUTF16(extension_->name())); 339 kHeadingIds[type_], base::UTF8ToUTF16(extension_->name()));
336 } 340 }
337 } 341 }
338 342
339 int ExtensionInstallPrompt::Prompt::GetDialogButtons() const { 343 int ExtensionInstallPrompt::Prompt::GetDialogButtons() const {
340 if (type_ == POST_INSTALL_PERMISSIONS_PROMPT && 344 if (type_ == POST_INSTALL_PERMISSIONS_PROMPT && ShouldDisplayRevokeButton()) {
341 ShouldDisplayRevokeFilesButton()) {
342 return kButtons[type_] | ui::DIALOG_BUTTON_OK; 345 return kButtons[type_] | ui::DIALOG_BUTTON_OK;
343 } 346 }
344 347
345 return kButtons[type_]; 348 return kButtons[type_];
346 } 349 }
347 350
348 bool ExtensionInstallPrompt::Prompt::ShouldShowExplanationText() const { 351 bool ExtensionInstallPrompt::Prompt::ShouldShowExplanationText() const {
349 return type_ == INSTALL_PROMPT && extension_->is_extension() && 352 return type_ == INSTALL_PROMPT && extension_->is_extension() &&
350 experiment_.get() && experiment_->text_only(); 353 experiment_.get() && experiment_->text_only();
351 } 354 }
352 355
353 bool ExtensionInstallPrompt::Prompt::HasAcceptButtonLabel() const { 356 bool ExtensionInstallPrompt::Prompt::HasAcceptButtonLabel() const {
357 if (type_ == POST_INSTALL_PERMISSIONS_PROMPT)
358 return ShouldDisplayRevokeButton();
359
354 if (kAcceptButtonIds[type_] == 0) 360 if (kAcceptButtonIds[type_] == 0)
355 return false; 361 return false;
356 362
357 if (type_ == POST_INSTALL_PERMISSIONS_PROMPT)
358 return ShouldDisplayRevokeFilesButton();
359
360 return true; 363 return true;
361 } 364 }
362 365
363 base::string16 ExtensionInstallPrompt::Prompt::GetAcceptButtonLabel() const { 366 base::string16 ExtensionInstallPrompt::Prompt::GetAcceptButtonLabel() const {
364 if (type_ == EXTERNAL_INSTALL_PROMPT) { 367 if (type_ == EXTERNAL_INSTALL_PROMPT) {
365 int id = -1; 368 int id = -1;
366 if (extension_->is_app()) 369 if (extension_->is_app())
367 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_APP; 370 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_APP;
368 else if (extension_->is_theme()) 371 else if (extension_->is_theme())
369 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_THEME; 372 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_THEME;
370 else 373 else
371 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_EXTENSION; 374 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_EXTENSION;
372 return l10n_util::GetStringUTF16(id); 375 return l10n_util::GetStringUTF16(id);
376 } else if (type_ == POST_INSTALL_PERMISSIONS_PROMPT) {
377 int id = -1;
378 if (GetRetainedFileCount() && GetRetainedDeviceCount()) {
379 id =
380 IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_AND_DEVICES_BUTT ON;
381 } else if (GetRetainedFileCount()) {
382 id = IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_BUTTON;
383 } else {
384 DCHECK_LT(0U, GetRetainedDeviceCount());
385 id = IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_DEVICES_BUTTON;
386 }
387 return l10n_util::GetStringUTF16(id);
373 } 388 }
374 if (ShouldShowExplanationText()) 389 if (ShouldShowExplanationText())
375 return experiment_->GetOkButtonText(); 390 return experiment_->GetOkButtonText();
376 return l10n_util::GetStringUTF16(kAcceptButtonIds[type_]); 391 return l10n_util::GetStringUTF16(kAcceptButtonIds[type_]);
377 } 392 }
378 393
379 bool ExtensionInstallPrompt::Prompt::HasAbortButtonLabel() const { 394 bool ExtensionInstallPrompt::Prompt::HasAbortButtonLabel() const {
380 if (ShouldShowExplanationText()) 395 if (ShouldShowExplanationText())
381 return true; 396 return true;
382 return kAbortButtonIds[type_] > 0; 397 return kAbortButtonIds[type_] > 0;
(...skipping 22 matching lines...) Expand all
405 420
406 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const { 421 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const {
407 const int kRetainedFilesMessageIDs[6] = { 422 const int kRetainedFilesMessageIDs[6] = {
408 IDS_EXTENSION_PROMPT_RETAINED_FILES_DEFAULT, 423 IDS_EXTENSION_PROMPT_RETAINED_FILES_DEFAULT,
409 IDS_EXTENSION_PROMPT_RETAINED_FILE_SINGULAR, 424 IDS_EXTENSION_PROMPT_RETAINED_FILE_SINGULAR,
410 IDS_EXTENSION_PROMPT_RETAINED_FILES_ZERO, 425 IDS_EXTENSION_PROMPT_RETAINED_FILES_ZERO,
411 IDS_EXTENSION_PROMPT_RETAINED_FILES_TWO, 426 IDS_EXTENSION_PROMPT_RETAINED_FILES_TWO,
412 IDS_EXTENSION_PROMPT_RETAINED_FILES_FEW, 427 IDS_EXTENSION_PROMPT_RETAINED_FILES_FEW,
413 IDS_EXTENSION_PROMPT_RETAINED_FILES_MANY, 428 IDS_EXTENSION_PROMPT_RETAINED_FILES_MANY,
414 }; 429 };
415 std::vector<int> message_ids; 430 std::vector<int> message_ids(
416 for (size_t i = 0; i < arraysize(kRetainedFilesMessageIDs); i++) { 431 kRetainedFilesMessageIDs,
417 message_ids.push_back(kRetainedFilesMessageIDs[i]); 432 kRetainedFilesMessageIDs + arraysize(kRetainedFilesMessageIDs));
418 } 433
419 return l10n_util::GetPluralStringFUTF16(message_ids, GetRetainedFileCount()); 434 return l10n_util::GetPluralStringFUTF16(message_ids, GetRetainedFileCount());
420 } 435 }
421 436
437 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedDevicesHeading()
438 const {
439 const int kRetainedDevicesMessageIDs[6] = {
440 IDS_EXTENSION_PROMPT_RETAINED_DEVICES_DEFAULT,
441 IDS_EXTENSION_PROMPT_RETAINED_DEVICE_SINGULAR,
442 IDS_EXTENSION_PROMPT_RETAINED_DEVICES_ZERO,
443 IDS_EXTENSION_PROMPT_RETAINED_DEVICES_TWO,
444 IDS_EXTENSION_PROMPT_RETAINED_DEVICES_FEW,
445 IDS_EXTENSION_PROMPT_RETAINED_DEVICES_MANY,
446 };
447 std::vector<int> message_ids(
448 kRetainedDevicesMessageIDs,
449 kRetainedDevicesMessageIDs + arraysize(kRetainedDevicesMessageIDs));
450
451 return l10n_util::GetPluralStringFUTF16(message_ids,
452 GetRetainedDeviceCount());
453 }
454
422 bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { 455 bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const {
423 return GetPermissionCount(ALL_PERMISSIONS) > 0 || 456 return GetPermissionCount(ALL_PERMISSIONS) > 0 ||
424 type_ == POST_INSTALL_PERMISSIONS_PROMPT; 457 type_ == POST_INSTALL_PERMISSIONS_PROMPT;
425 } 458 }
426 459
427 void ExtensionInstallPrompt::Prompt::AppendRatingStars( 460 void ExtensionInstallPrompt::Prompt::AppendRatingStars(
428 StarAppender appender, void* data) const { 461 StarAppender appender, void* data) const {
429 CHECK(appender); 462 CHECK(appender);
430 CHECK(AllowWebstoreData(type_)); 463 CHECK(AllowWebstoreData(type_));
431 int rating_integer = floor(average_rating_); 464 int rating_integer = floor(average_rating_);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 DetailsType type, size_t index) const { 556 DetailsType type, size_t index) const {
524 switch (type) { 557 switch (type) {
525 case PERMISSIONS_DETAILS: 558 case PERMISSIONS_DETAILS:
526 CHECK_LT(index, prompt_permissions_.is_showing_details.size()); 559 CHECK_LT(index, prompt_permissions_.is_showing_details.size());
527 return prompt_permissions_.is_showing_details[index]; 560 return prompt_permissions_.is_showing_details[index];
528 case WITHHELD_PERMISSIONS_DETAILS: 561 case WITHHELD_PERMISSIONS_DETAILS:
529 CHECK_LT(index, withheld_prompt_permissions_.is_showing_details.size()); 562 CHECK_LT(index, withheld_prompt_permissions_.is_showing_details.size());
530 return withheld_prompt_permissions_.is_showing_details[index]; 563 return withheld_prompt_permissions_.is_showing_details[index];
531 case RETAINED_FILES_DETAILS: 564 case RETAINED_FILES_DETAILS:
532 return is_showing_details_for_retained_files_; 565 return is_showing_details_for_retained_files_;
566 case RETAINED_DEVICES_DETAILS:
567 return is_showing_details_for_retained_devices_;
533 } 568 }
534 return false; 569 return false;
535 } 570 }
536 571
537 size_t ExtensionInstallPrompt::Prompt::GetRetainedFileCount() const { 572 size_t ExtensionInstallPrompt::Prompt::GetRetainedFileCount() const {
538 return retained_files_.size(); 573 return retained_files_.size();
539 } 574 }
540 575
541 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFile(size_t index) 576 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFile(size_t index)
542 const { 577 const {
543 CHECK_LT(index, retained_files_.size()); 578 CHECK_LT(index, retained_files_.size());
544 return retained_files_[index].AsUTF16Unsafe(); 579 return retained_files_[index].AsUTF16Unsafe();
545 } 580 }
546 581
582 size_t ExtensionInstallPrompt::Prompt::GetRetainedDeviceCount() const {
583 return retained_device_messages_.size();
584 }
585
586 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedDeviceMessageString(
587 size_t index) const {
588 CHECK_LT(index, retained_device_messages_.size());
589 return retained_device_messages_[index];
590 }
591
592 bool ExtensionInstallPrompt::Prompt::ShouldDisplayRevokeButton() const {
593 return !retained_files_.empty() || !retained_device_messages_.empty();
594 }
595
547 ExtensionInstallPrompt::Prompt::InstallPromptPermissions& 596 ExtensionInstallPrompt::Prompt::InstallPromptPermissions&
548 ExtensionInstallPrompt::Prompt::GetPermissionsForType( 597 ExtensionInstallPrompt::Prompt::GetPermissionsForType(
549 PermissionsType permissions_type) { 598 PermissionsType permissions_type) {
550 DCHECK_NE(ALL_PERMISSIONS, permissions_type); 599 DCHECK_NE(ALL_PERMISSIONS, permissions_type);
551 return permissions_type == REGULAR_PERMISSIONS ? prompt_permissions_ 600 return permissions_type == REGULAR_PERMISSIONS ? prompt_permissions_
552 : withheld_prompt_permissions_; 601 : withheld_prompt_permissions_;
553 } 602 }
554 603
555 const ExtensionInstallPrompt::Prompt::InstallPromptPermissions& 604 const ExtensionInstallPrompt::Prompt::InstallPromptPermissions&
556 ExtensionInstallPrompt::Prompt::GetPermissionsForType( 605 ExtensionInstallPrompt::Prompt::GetPermissionsForType(
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 custom_permissions_ = permissions; 795 custom_permissions_ = permissions;
747 delegate_ = delegate; 796 delegate_ = delegate;
748 prompt_ = new Prompt(PERMISSIONS_PROMPT); 797 prompt_ = new Prompt(PERMISSIONS_PROMPT);
749 798
750 LoadImageIfNeeded(); 799 LoadImageIfNeeded();
751 } 800 }
752 801
753 void ExtensionInstallPrompt::ReviewPermissions( 802 void ExtensionInstallPrompt::ReviewPermissions(
754 Delegate* delegate, 803 Delegate* delegate,
755 const Extension* extension, 804 const Extension* extension,
756 const std::vector<base::FilePath>& retained_file_paths) { 805 const std::vector<base::FilePath>& retained_file_paths,
806 const std::vector<base::string16>& retained_device_messages) {
757 DCHECK(ui_loop_ == base::MessageLoop::current()); 807 DCHECK(ui_loop_ == base::MessageLoop::current());
758 extension_ = extension; 808 extension_ = extension;
759 prompt_ = new Prompt(POST_INSTALL_PERMISSIONS_PROMPT); 809 prompt_ = new Prompt(POST_INSTALL_PERMISSIONS_PROMPT);
760 prompt_->set_retained_files(retained_file_paths); 810 prompt_->set_retained_files(retained_file_paths);
811 prompt_->set_retained_device_messages(retained_device_messages);
761 delegate_ = delegate; 812 delegate_ = delegate;
762 813
763 LoadImageIfNeeded(); 814 LoadImageIfNeeded();
764 } 815 }
765 816
766 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, 817 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension,
767 SkBitmap* icon) { 818 SkBitmap* icon) {
768 extension_ = extension; 819 extension_ = extension;
769 SetIcon(icon); 820 SetIcon(icon);
770 821
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 } 945 }
895 946
896 if (AutoConfirmPrompt(delegate_)) 947 if (AutoConfirmPrompt(delegate_))
897 return; 948 return;
898 949
899 if (show_dialog_callback_.is_null()) 950 if (show_dialog_callback_.is_null())
900 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); 951 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_);
901 else 952 else
902 show_dialog_callback_.Run(show_params_, delegate_, prompt_); 953 show_dialog_callback_.Run(show_params_, delegate_, prompt_);
903 } 954 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698