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

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

Issue 501273002: Update extension install prompt to reflect withheld permissions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor changes 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"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/browser/extensions/bundle_installer.h" 16 #include "chrome/browser/extensions/bundle_installer.h"
17 #include "chrome/browser/extensions/extension_install_ui.h" 17 #include "chrome/browser/extensions/extension_install_ui.h"
18 #include "chrome/browser/extensions/extension_util.h" 18 #include "chrome/browser/extensions/extension_util.h"
19 #include "chrome/browser/extensions/permissions_updater.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
22 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
24 #include "chrome/grit/chromium_strings.h" 25 #include "chrome/grit/chromium_strings.h"
25 #include "chrome/grit/generated_resources.h" 26 #include "chrome/grit/generated_resources.h"
26 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
27 #include "extensions/browser/extension_prefs.h" 28 #include "extensions/browser/extension_prefs.h"
28 #include "extensions/browser/extension_util.h" 29 #include "extensions/browser/extension_util.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 166
166 gfx::NativeWindow NativeWindowForWebContents(content::WebContents* contents) { 167 gfx::NativeWindow NativeWindowForWebContents(content::WebContents* contents) {
167 if (!contents) 168 if (!contents)
168 return NULL; 169 return NULL;
169 170
170 return contents->GetTopLevelNativeWindow(); 171 return contents->GetTopLevelNativeWindow();
171 } 172 }
172 173
173 } // namespace 174 } // namespace
174 175
176 ExtensionInstallPrompt::Prompt::PermissionsInfo::PermissionsInfo() {
177 }
178 ExtensionInstallPrompt::Prompt::PermissionsInfo::~PermissionsInfo() {
179 }
180
175 // static 181 // static
176 ExtensionInstallPrompt::AutoConfirmForTests 182 ExtensionInstallPrompt::AutoConfirmForTests
177 ExtensionInstallPrompt::g_auto_confirm_for_tests = ExtensionInstallPrompt::NONE; 183 ExtensionInstallPrompt::g_auto_confirm_for_tests = ExtensionInstallPrompt::NONE;
178 184
179 // This should match the PromptType enum. 185 // This should match the PromptType enum.
180 std::string ExtensionInstallPrompt::PromptTypeToString(PromptType type) { 186 std::string ExtensionInstallPrompt::PromptTypeToString(PromptType type) {
181 switch (type) { 187 switch (type) {
182 case ExtensionInstallPrompt::INSTALL_PROMPT: 188 case ExtensionInstallPrompt::INSTALL_PROMPT:
183 return "INSTALL_PROMPT"; 189 return "INSTALL_PROMPT";
184 case ExtensionInstallPrompt::INLINE_INSTALL_PROMPT: 190 case ExtensionInstallPrompt::INLINE_INSTALL_PROMPT:
(...skipping 27 matching lines...) Expand all
212 average_rating_(0.0), 218 average_rating_(0.0),
213 rating_count_(0), 219 rating_count_(0),
214 show_user_count_(false), 220 show_user_count_(false),
215 has_webstore_data_(false) { 221 has_webstore_data_(false) {
216 } 222 }
217 223
218 ExtensionInstallPrompt::Prompt::~Prompt() { 224 ExtensionInstallPrompt::Prompt::~Prompt() {
219 } 225 }
220 226
221 void ExtensionInstallPrompt::Prompt::SetPermissions( 227 void ExtensionInstallPrompt::Prompt::SetPermissions(
222 const std::vector<base::string16>& permissions) { 228 const std::vector<base::string16>& permissions,
223 permissions_ = permissions; 229 PermissionsType permissions_type) {
230 switch (permissions_type) {
231 case REGULAR_PERMISSIONS:
232 permissions_info_.permissions = permissions;
233 break;
234 case WITHHELD_PERMISSIONS:
235 withheld_permissions_info_.permissions = permissions;
236 break;
237 case ALL_PERMISSIONS:
238 NOTREACHED();
239 break;
240 }
224 } 241 }
225 242
226 void ExtensionInstallPrompt::Prompt::SetPermissionsDetails( 243 void ExtensionInstallPrompt::Prompt::SetPermissionsDetails(
227 const std::vector<base::string16>& details) { 244 const std::vector<base::string16>& details,
228 details_ = details; 245 PermissionsType permissions_type) {
229 is_showing_details_for_permissions_.clear(); 246 switch (permissions_type) {
230 for (size_t i = 0; i < details.size(); ++i) 247 case REGULAR_PERMISSIONS:
231 is_showing_details_for_permissions_.push_back(false); 248 permissions_info_.details = details;
249 permissions_info_.is_showing_details.clear();
250 for (size_t i = 0; i < details.size(); ++i)
251 permissions_info_.is_showing_details.push_back(false);
252 break;
253 case WITHHELD_PERMISSIONS:
254 withheld_permissions_info_.details = details;
255 withheld_permissions_info_.is_showing_details.clear();
256 for (size_t i = 0; i < details.size(); ++i)
257 withheld_permissions_info_.is_showing_details.push_back(false);
258 break;
259 case ALL_PERMISSIONS:
260 NOTREACHED();
261 break;
262 }
232 } 263 }
233 264
234 void ExtensionInstallPrompt::Prompt::SetIsShowingDetails( 265 void ExtensionInstallPrompt::Prompt::SetIsShowingDetails(
235 DetailsType type, 266 DetailsType type,
236 size_t index, 267 size_t index,
237 bool is_showing_details) { 268 bool is_showing_details) {
238 switch (type) { 269 switch (type) {
239 case PERMISSIONS_DETAILS: 270 case PERMISSIONS_DETAILS:
240 is_showing_details_for_permissions_[index] = is_showing_details; 271 permissions_info_.is_showing_details[index] = is_showing_details;
272 break;
273 case WITHHELD_PERMISSIONS_DETAILS:
274 withheld_permissions_info_.is_showing_details[index] = is_showing_details;
241 break; 275 break;
242 case RETAINED_FILES_DETAILS: 276 case RETAINED_FILES_DETAILS:
243 is_showing_details_for_retained_files_ = is_showing_details; 277 is_showing_details_for_retained_files_ = is_showing_details;
244 break; 278 break;
245 } 279 }
246 } 280 }
247 281
248 void ExtensionInstallPrompt::Prompt::SetWebstoreData( 282 void ExtensionInstallPrompt::Prompt::SetWebstoreData(
249 const std::string& localized_user_count, 283 const std::string& localized_user_count,
250 bool show_user_count, 284 bool show_user_count,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 return kAbortButtonIds[type_] > 0; 381 return kAbortButtonIds[type_] > 0;
348 } 382 }
349 383
350 base::string16 ExtensionInstallPrompt::Prompt::GetAbortButtonLabel() const { 384 base::string16 ExtensionInstallPrompt::Prompt::GetAbortButtonLabel() const {
351 CHECK(HasAbortButtonLabel()); 385 CHECK(HasAbortButtonLabel());
352 if (ShouldShowExplanationText()) 386 if (ShouldShowExplanationText())
353 return experiment_->GetCancelButtonText(); 387 return experiment_->GetCancelButtonText();
354 return l10n_util::GetStringUTF16(kAbortButtonIds[type_]); 388 return l10n_util::GetStringUTF16(kAbortButtonIds[type_]);
355 } 389 }
356 390
357 base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsHeading() const { 391 base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsHeading(
358 return l10n_util::GetStringUTF16(kPermissionsHeaderIds[type_]); 392 PermissionsType permissions_type) const {
393 switch (permissions_type) {
394 case REGULAR_PERMISSIONS:
395 return l10n_util::GetStringUTF16(kPermissionsHeaderIds[type_]);
396 case WITHHELD_PERMISSIONS:
397 return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WITHHELD);
398 case ALL_PERMISSIONS:
399 NOTREACHED();
400 return base::string16();
401 }
359 } 402 }
360 403
361 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const { 404 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const {
362 const int kRetainedFilesMessageIDs[6] = { 405 const int kRetainedFilesMessageIDs[6] = {
363 IDS_EXTENSION_PROMPT_RETAINED_FILES_DEFAULT, 406 IDS_EXTENSION_PROMPT_RETAINED_FILES_DEFAULT,
364 IDS_EXTENSION_PROMPT_RETAINED_FILE_SINGULAR, 407 IDS_EXTENSION_PROMPT_RETAINED_FILE_SINGULAR,
365 IDS_EXTENSION_PROMPT_RETAINED_FILES_ZERO, 408 IDS_EXTENSION_PROMPT_RETAINED_FILES_ZERO,
366 IDS_EXTENSION_PROMPT_RETAINED_FILES_TWO, 409 IDS_EXTENSION_PROMPT_RETAINED_FILES_TWO,
367 IDS_EXTENSION_PROMPT_RETAINED_FILES_FEW, 410 IDS_EXTENSION_PROMPT_RETAINED_FILES_FEW,
368 IDS_EXTENSION_PROMPT_RETAINED_FILES_MANY, 411 IDS_EXTENSION_PROMPT_RETAINED_FILES_MANY,
369 }; 412 };
370 std::vector<int> message_ids; 413 std::vector<int> message_ids;
371 for (size_t i = 0; i < arraysize(kRetainedFilesMessageIDs); i++) { 414 for (size_t i = 0; i < arraysize(kRetainedFilesMessageIDs); i++) {
372 message_ids.push_back(kRetainedFilesMessageIDs[i]); 415 message_ids.push_back(kRetainedFilesMessageIDs[i]);
373 } 416 }
374 return l10n_util::GetPluralStringFUTF16(message_ids, GetRetainedFileCount()); 417 return l10n_util::GetPluralStringFUTF16(message_ids, GetRetainedFileCount());
375 } 418 }
376 419
377 bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { 420 bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const {
378 return GetPermissionCount() > 0 || type_ == POST_INSTALL_PERMISSIONS_PROMPT; 421 return GetPermissionCount(REGULAR_PERMISSIONS) > 0 ||
422 GetPermissionCount(WITHHELD_PERMISSIONS) > 0 ||
423 type_ == POST_INSTALL_PERMISSIONS_PROMPT;
379 } 424 }
380 425
381 void ExtensionInstallPrompt::Prompt::AppendRatingStars( 426 void ExtensionInstallPrompt::Prompt::AppendRatingStars(
382 StarAppender appender, void* data) const { 427 StarAppender appender, void* data) const {
383 CHECK(appender); 428 CHECK(appender);
384 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); 429 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT);
385 int rating_integer = floor(average_rating_); 430 int rating_integer = floor(average_rating_);
386 double rating_fractional = average_rating_ - rating_integer; 431 double rating_fractional = average_rating_ - rating_integer;
387 432
388 if (rating_fractional > 0.66) { 433 if (rating_fractional > 0.66) {
(...skipping 27 matching lines...) Expand all
416 base::string16 ExtensionInstallPrompt::Prompt::GetUserCount() const { 461 base::string16 ExtensionInstallPrompt::Prompt::GetUserCount() const {
417 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); 462 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT);
418 463
419 if (show_user_count_) { 464 if (show_user_count_) {
420 return l10n_util::GetStringFUTF16(IDS_EXTENSION_USER_COUNT, 465 return l10n_util::GetStringFUTF16(IDS_EXTENSION_USER_COUNT,
421 base::UTF8ToUTF16(localized_user_count_)); 466 base::UTF8ToUTF16(localized_user_count_));
422 } 467 }
423 return base::string16(); 468 return base::string16();
424 } 469 }
425 470
426 size_t ExtensionInstallPrompt::Prompt::GetPermissionCount() const { 471 size_t ExtensionInstallPrompt::Prompt::GetPermissionCount(
427 return permissions_.size(); 472 PermissionsType permissions_type) const {
473 switch (permissions_type) {
474 case REGULAR_PERMISSIONS:
475 return permissions_info_.permissions.size();
476 case WITHHELD_PERMISSIONS:
477 return withheld_permissions_info_.permissions.size();
478 case ALL_PERMISSIONS:
479 return permissions_info_.permissions.size() +
480 withheld_permissions_info_.permissions.size();
481 }
428 } 482 }
429 483
430 size_t ExtensionInstallPrompt::Prompt::GetPermissionsDetailsCount() const { 484 size_t ExtensionInstallPrompt::Prompt::GetPermissionsDetailsCount(
431 return details_.size(); 485 PermissionsType permissions_type) const {
486 switch (permissions_type) {
487 case REGULAR_PERMISSIONS:
488 return permissions_info_.details.size();
489 case WITHHELD_PERMISSIONS:
490 return withheld_permissions_info_.details.size();
491 case ALL_PERMISSIONS:
492 return permissions_info_.details.size() +
493 withheld_permissions_info_.details.size();
494 }
432 } 495 }
433 496
434 base::string16 ExtensionInstallPrompt::Prompt::GetPermission(size_t index) 497 base::string16 ExtensionInstallPrompt::Prompt::GetPermission(
435 const { 498 size_t index,
436 CHECK_LT(index, permissions_.size()); 499 PermissionsType permissions_type) const {
437 return permissions_[index]; 500 switch (permissions_type) {
501 case REGULAR_PERMISSIONS:
502 CHECK_LT(index, permissions_info_.permissions.size());
503 return permissions_info_.permissions[index];
504 case WITHHELD_PERMISSIONS:
505 CHECK_LT(index, withheld_permissions_info_.permissions.size());
506 return withheld_permissions_info_.permissions[index];
507 case ALL_PERMISSIONS:
508 NOTREACHED();
509 return base::string16();
510 }
438 } 511 }
439 512
440 base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsDetails( 513 base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsDetails(
441 size_t index) const { 514 size_t index,
442 CHECK_LT(index, details_.size()); 515 PermissionsType permissions_type) const {
443 return details_[index]; 516 switch (permissions_type) {
517 case REGULAR_PERMISSIONS:
518 CHECK_LT(index, permissions_info_.details.size());
519 return permissions_info_.details[index];
520 case WITHHELD_PERMISSIONS:
521 CHECK_LT(index, withheld_permissions_info_.details.size());
522 return withheld_permissions_info_.details[index];
523 case ALL_PERMISSIONS:
524 NOTREACHED();
525 return base::string16();
526 }
444 } 527 }
445 528
446 bool ExtensionInstallPrompt::Prompt::GetIsShowingDetails( 529 bool ExtensionInstallPrompt::Prompt::GetIsShowingDetails(
447 DetailsType type, size_t index) const { 530 DetailsType type, size_t index) const {
448 switch (type) { 531 switch (type) {
449 case PERMISSIONS_DETAILS: 532 case PERMISSIONS_DETAILS:
450 CHECK_LT(index, is_showing_details_for_permissions_.size()); 533 CHECK_LT(index, permissions_info_.is_showing_details.size());
451 return is_showing_details_for_permissions_[index]; 534 return permissions_info_.is_showing_details[index];
535 case WITHHELD_PERMISSIONS_DETAILS:
536 CHECK_LT(index, withheld_permissions_info_.is_showing_details.size());
537 return withheld_permissions_info_.is_showing_details[index];
452 case RETAINED_FILES_DETAILS: 538 case RETAINED_FILES_DETAILS:
453 return is_showing_details_for_retained_files_; 539 return is_showing_details_for_retained_files_;
454 } 540 }
455 return false; 541 return false;
456 } 542 }
457 543
458 size_t ExtensionInstallPrompt::Prompt::GetRetainedFileCount() const { 544 size_t ExtensionInstallPrompt::Prompt::GetRetainedFileCount() const {
459 return retained_files_.size(); 545 return retained_files_.size();
460 } 546 }
461 547
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 ShowConfirmation(); 636 ShowConfirmation();
551 } 637 }
552 638
553 void ExtensionInstallPrompt::ConfirmStandaloneInstall( 639 void ExtensionInstallPrompt::ConfirmStandaloneInstall(
554 Delegate* delegate, 640 Delegate* delegate,
555 const Extension* extension, 641 const Extension* extension,
556 SkBitmap* icon, 642 SkBitmap* icon,
557 scoped_refptr<Prompt> prompt) { 643 scoped_refptr<Prompt> prompt) {
558 DCHECK(ui_loop_ == base::MessageLoop::current()); 644 DCHECK(ui_loop_ == base::MessageLoop::current());
559 extension_ = extension; 645 extension_ = extension;
560 permissions_ = extension->permissions_data()->active_permissions();
561 delegate_ = delegate; 646 delegate_ = delegate;
562 prompt_ = prompt; 647 prompt_ = prompt;
563 648
564 SetIcon(icon); 649 SetIcon(icon);
565 ShowConfirmation(); 650 ShowConfirmation();
566 } 651 }
567 652
568 void ExtensionInstallPrompt::ConfirmWebstoreInstall( 653 void ExtensionInstallPrompt::ConfirmWebstoreInstall(
569 Delegate* delegate, 654 Delegate* delegate,
570 const Extension* extension, 655 const Extension* extension,
571 const SkBitmap* icon, 656 const SkBitmap* icon,
572 const ShowDialogCallback& show_dialog_callback) { 657 const ShowDialogCallback& show_dialog_callback) {
573 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the 658 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the
574 // remaining fields. 659 // remaining fields.
575 extension_ = extension; 660 extension_ = extension;
576 SetIcon(icon); 661 SetIcon(icon);
577 ConfirmInstall(delegate, extension, show_dialog_callback); 662 ConfirmInstall(delegate, extension, show_dialog_callback);
578 } 663 }
579 664
580 void ExtensionInstallPrompt::ConfirmInstall( 665 void ExtensionInstallPrompt::ConfirmInstall(
581 Delegate* delegate, 666 Delegate* delegate,
582 const Extension* extension, 667 const Extension* extension,
583 const ShowDialogCallback& show_dialog_callback) { 668 const ShowDialogCallback& show_dialog_callback) {
584 DCHECK(ui_loop_ == base::MessageLoop::current()); 669 DCHECK(ui_loop_ == base::MessageLoop::current());
585 extension_ = extension; 670 extension_ = extension;
586 permissions_ = extension->permissions_data()->active_permissions();
587 delegate_ = delegate; 671 delegate_ = delegate;
588 prompt_ = new Prompt(INSTALL_PROMPT); 672 prompt_ = new Prompt(INSTALL_PROMPT);
589 show_dialog_callback_ = show_dialog_callback; 673 show_dialog_callback_ = show_dialog_callback;
590 674
591 // We special-case themes to not show any confirm UI. Instead they are 675 // We special-case themes to not show any confirm UI. Instead they are
592 // immediately installed, and then we show an infobar (see OnInstallSuccess) 676 // immediately installed, and then we show an infobar (see OnInstallSuccess)
593 // to allow the user to revert if they don't like it. 677 // to allow the user to revert if they don't like it.
594 // 678 //
595 // We don't do this in the case where off-store extension installs are 679 // We don't do this in the case where off-store extension installs are
596 // disabled because in that case, we don't show the dangerous download UI, so 680 // disabled because in that case, we don't show the dangerous download UI, so
597 // we need the UI confirmation. 681 // we need the UI confirmation.
598 if (extension->is_theme()) { 682 if (extension->is_theme()) {
599 if (extension->from_webstore() || 683 if (extension->from_webstore() ||
600 extensions::FeatureSwitch::easy_off_store_install()->IsEnabled()) { 684 extensions::FeatureSwitch::easy_off_store_install()->IsEnabled()) {
601 delegate->InstallUIProceed(); 685 delegate->InstallUIProceed();
602 return; 686 return;
603 } 687 }
604 } 688 }
605 689
606 LoadImageIfNeeded(); 690 LoadImageIfNeeded();
607 } 691 }
608 692
609 void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate, 693 void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate,
610 const Extension* extension) { 694 const Extension* extension) {
611 DCHECK(ui_loop_ == base::MessageLoop::current()); 695 DCHECK(ui_loop_ == base::MessageLoop::current());
612 extension_ = extension; 696 extension_ = extension;
613 permissions_ = extension->permissions_data()->active_permissions();
614 delegate_ = delegate; 697 delegate_ = delegate;
615 bool is_remote_install = 698 bool is_remote_install =
616 install_ui_->profile() && 699 install_ui_->profile() &&
617 extensions::ExtensionPrefs::Get(install_ui_->profile())->HasDisableReason( 700 extensions::ExtensionPrefs::Get(install_ui_->profile())->HasDisableReason(
618 extension->id(), extensions::Extension::DISABLE_REMOTE_INSTALL); 701 extension->id(), extensions::Extension::DISABLE_REMOTE_INSTALL);
619 bool is_ephemeral = 702 bool is_ephemeral =
620 extensions::util::IsEphemeralApp(extension->id(), install_ui_->profile()); 703 extensions::util::IsEphemeralApp(extension->id(), install_ui_->profile());
621 704
622 PromptType type = UNSET_PROMPT_TYPE; 705 PromptType type = UNSET_PROMPT_TYPE;
623 if (is_ephemeral) 706 if (is_ephemeral)
624 type = LAUNCH_PROMPT; 707 type = LAUNCH_PROMPT;
625 else if (is_remote_install) 708 else if (is_remote_install)
626 type = REMOTE_INSTALL_PROMPT; 709 type = REMOTE_INSTALL_PROMPT;
627 else 710 else
628 type = RE_ENABLE_PROMPT; 711 type = RE_ENABLE_PROMPT;
629 prompt_ = new Prompt(type); 712 prompt_ = new Prompt(type);
630 713
631 LoadImageIfNeeded(); 714 LoadImageIfNeeded();
632 } 715 }
633 716
634 void ExtensionInstallPrompt::ConfirmExternalInstall( 717 void ExtensionInstallPrompt::ConfirmExternalInstall(
635 Delegate* delegate, 718 Delegate* delegate,
636 const Extension* extension, 719 const Extension* extension,
637 const ShowDialogCallback& show_dialog_callback, 720 const ShowDialogCallback& show_dialog_callback,
638 scoped_refptr<Prompt> prompt) { 721 scoped_refptr<Prompt> prompt) {
639 DCHECK(ui_loop_ == base::MessageLoop::current()); 722 DCHECK(ui_loop_ == base::MessageLoop::current());
640 extension_ = extension; 723 extension_ = extension;
641 permissions_ = extension->permissions_data()->active_permissions();
642 delegate_ = delegate; 724 delegate_ = delegate;
643 prompt_ = prompt; 725 prompt_ = prompt;
644 show_dialog_callback_ = show_dialog_callback; 726 show_dialog_callback_ = show_dialog_callback;
645 727
646 LoadImageIfNeeded(); 728 LoadImageIfNeeded();
647 } 729 }
648 730
649 void ExtensionInstallPrompt::ConfirmPermissions( 731 void ExtensionInstallPrompt::ConfirmPermissions(
650 Delegate* delegate, 732 Delegate* delegate,
651 const Extension* extension, 733 const Extension* extension,
652 const PermissionSet* permissions) { 734 const PermissionSet* permissions) {
653 DCHECK(ui_loop_ == base::MessageLoop::current()); 735 DCHECK(ui_loop_ == base::MessageLoop::current());
654 extension_ = extension; 736 extension_ = extension;
655 permissions_ = permissions; 737 permissions_ = permissions;
656 delegate_ = delegate; 738 delegate_ = delegate;
657 prompt_ = new Prompt(PERMISSIONS_PROMPT); 739 prompt_ = new Prompt(PERMISSIONS_PROMPT);
658 740
659 LoadImageIfNeeded(); 741 LoadImageIfNeeded();
660 } 742 }
661 743
662 void ExtensionInstallPrompt::ReviewPermissions( 744 void ExtensionInstallPrompt::ReviewPermissions(
663 Delegate* delegate, 745 Delegate* delegate,
664 const Extension* extension, 746 const Extension* extension,
665 const std::vector<base::FilePath>& retained_file_paths) { 747 const std::vector<base::FilePath>& retained_file_paths) {
666 DCHECK(ui_loop_ == base::MessageLoop::current()); 748 DCHECK(ui_loop_ == base::MessageLoop::current());
667 extension_ = extension; 749 extension_ = extension;
668 permissions_ = extension->permissions_data()->active_permissions();
669 prompt_ = new Prompt(POST_INSTALL_PERMISSIONS_PROMPT); 750 prompt_ = new Prompt(POST_INSTALL_PERMISSIONS_PROMPT);
670 prompt_->set_retained_files(retained_file_paths); 751 prompt_->set_retained_files(retained_file_paths);
671 delegate_ = delegate; 752 delegate_ = delegate;
672 753
673 LoadImageIfNeeded(); 754 LoadImageIfNeeded();
674 } 755 }
675 756
676 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, 757 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension,
677 SkBitmap* icon) { 758 SkBitmap* icon) {
678 extension_ = extension; 759 extension_ = extension;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 images_list, 813 images_list,
733 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); 814 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr()));
734 } 815 }
735 816
736 void ExtensionInstallPrompt::ShowConfirmation() { 817 void ExtensionInstallPrompt::ShowConfirmation() {
737 if (prompt_->type() == INSTALL_PROMPT) 818 if (prompt_->type() == INSTALL_PROMPT)
738 prompt_->set_experiment(ExtensionInstallPromptExperiment::Find()); 819 prompt_->set_experiment(ExtensionInstallPromptExperiment::Find());
739 else 820 else
740 prompt_->set_experiment(ExtensionInstallPromptExperiment::ControlGroup()); 821 prompt_->set_experiment(ExtensionInstallPromptExperiment::ControlGroup());
741 822
823 if (extension_ && !permissions_) {
824 // Initialize |permissions_| if they have not already been set so that
Devlin 2014/09/04 22:06:08 This just seems so fragile. Let's make it a littl
gpdavis 2014/09/05 20:23:01 Clever! I like it. Done.
825 // withheld permissions don't end up in the install prompt. Special cases
826 // that do not require this will have already set |permissions_|.
827 extensions::PermissionsUpdater(install_ui_->profile())
828 .InitializePermissions(
829 extension_, extensions::PermissionsUpdater::INIT_FLAG_TRANSIENT);
830 permissions_ = extension_->permissions_data()->active_permissions();
831 }
832
742 if (permissions_.get() && 833 if (permissions_.get() &&
743 (!extension_ || 834 (!extension_ ||
744 !extensions::PermissionsData::ShouldSkipPermissionWarnings( 835 !extensions::PermissionsData::ShouldSkipPermissionWarnings(
745 extension_->id()))) { 836 extension_->id()))) {
746 Manifest::Type type = 837 Manifest::Type type =
747 extension_ ? extension_->GetType() : Manifest::TYPE_UNKNOWN; 838 extension_ ? extension_->GetType() : Manifest::TYPE_UNKNOWN;
748 const extensions::PermissionMessageProvider* message_provider = 839 const extensions::PermissionMessageProvider* message_provider =
749 extensions::PermissionMessageProvider::Get(); 840 extensions::PermissionMessageProvider::Get();
750 prompt_->SetPermissions( 841 prompt_->SetPermissions(
751 message_provider->GetWarningMessages(permissions_.get(), type)); 842 message_provider->GetWarningMessages(permissions_.get(), type),
843 REGULAR_PERMISSIONS);
752 prompt_->SetPermissionsDetails( 844 prompt_->SetPermissionsDetails(
753 message_provider->GetWarningMessagesDetails(permissions_.get(), type)); 845 message_provider->GetWarningMessagesDetails(permissions_.get(), type),
846 REGULAR_PERMISSIONS);
847
848 scoped_refptr<const extensions::PermissionSet> withheld =
849 extension_->permissions_data()->withheld_permissions();
850 if (!withheld->IsEmpty()) {
851 prompt_->SetPermissions(
852 message_provider->GetWarningMessages(withheld.get(), type),
853 PermissionsType::WITHHELD_PERMISSIONS);
854 prompt_->SetPermissionsDetails(
855 message_provider->GetWarningMessagesDetails(withheld.get(), type),
856 PermissionsType::WITHHELD_PERMISSIONS);
857 }
754 } 858 }
755 859
756 switch (prompt_->type()) { 860 switch (prompt_->type()) {
757 case PERMISSIONS_PROMPT: 861 case PERMISSIONS_PROMPT:
758 case RE_ENABLE_PROMPT: 862 case RE_ENABLE_PROMPT:
759 case INLINE_INSTALL_PROMPT: 863 case INLINE_INSTALL_PROMPT:
760 case EXTERNAL_INSTALL_PROMPT: 864 case EXTERNAL_INSTALL_PROMPT:
761 case INSTALL_PROMPT: 865 case INSTALL_PROMPT:
762 case LAUNCH_PROMPT: 866 case LAUNCH_PROMPT:
763 case POST_INSTALL_PERMISSIONS_PROMPT: 867 case POST_INSTALL_PERMISSIONS_PROMPT:
(...skipping 12 matching lines...) Expand all
776 } 880 }
777 881
778 if (AutoConfirmPrompt(delegate_)) 882 if (AutoConfirmPrompt(delegate_))
779 return; 883 return;
780 884
781 if (show_dialog_callback_.is_null()) 885 if (show_dialog_callback_.is_null())
782 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); 886 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_);
783 else 887 else
784 show_dialog_callback_.Run(show_params_, delegate_, prompt_); 888 show_dialog_callback_.Run(show_params_, delegate_, prompt_);
785 } 889 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698