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

Side by Side Diff: chrome/browser/ui/views/page_info/page_info_bubble_view.cc

Issue 2846913002: Add a Certificate Viewer link to the Page Info dropdown (Closed)
Patch Set: Omit Vector icons on Android Created 3 years, 7 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/ui/views/page_info/page_info_bubble_view.h" 5 #include "chrome/browser/ui/views/page_info/page_info_bubble_view.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <utility>
11 11
12 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "chrome/browser/certificate_viewer.h" 18 #include "chrome/browser/certificate_viewer.h"
19 #include "chrome/browser/infobars/infobar_service.h" 19 #include "chrome/browser/infobars/infobar_service.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 // Margin and padding values for the |BubbleHeaderView|. 83 // Margin and padding values for the |BubbleHeaderView|.
84 const int kHeaderMarginBottom = 10; 84 const int kHeaderMarginBottom = 10;
85 const int kHeaderPaddingBottom = 13; 85 const int kHeaderPaddingBottom = 13;
86 86
87 // Spacing between labels in the header. 87 // Spacing between labels in the header.
88 const int kHeaderLabelSpacing = 4; 88 const int kHeaderLabelSpacing = 4;
89 89
90 // Site Settings Section ------------------------------------------------------- 90 // Site Settings Section -------------------------------------------------------
91 91
92 // Spacing above and below the cookies view. 92 // Spacing above and below the cookies and certificate views.
93 const int kCookiesViewVerticalPadding = 6; 93 const int kSubViewsVerticalPadding = 6;
94 94
95 // Spacing between a permission image and the text. 95 // Spacing between a permission image and the text.
96 const int kPermissionImageSpacing = 6; 96 const int kPermissionImageSpacing = 6;
97 97
98 // Spacing between rows in the site settings section 98 // Spacing between rows in the site settings section
99 const int kPermissionsVerticalSpacing = 12; 99 const int kPermissionsVerticalSpacing = 12;
100 100
101 // Spacing between the label and the menu. 101 // Spacing between the label and the menu.
102 const int kPermissionMenuSpacing = 16; 102 const int kPermissionMenuSpacing = 16;
103 103
104 // Button/styled label/link IDs ------------------------------------------------ 104 // Button/styled label/link IDs ------------------------------------------------
105 const int BUTTON_CLOSE = 1337; 105 const int BUTTON_CLOSE = 1337;
106 const int STYLED_LABEL_SECURITY_DETAILS = 1338; 106 const int STYLED_LABEL_SECURITY_DETAILS = 1338;
107 const int STYLED_LABEL_RESET_CERTIFICATE_DECISIONS = 1339; 107 const int STYLED_LABEL_RESET_CERTIFICATE_DECISIONS = 1339;
108 const int LINK_COOKIE_DIALOG = 1340; 108 const int LINK_COOKIE_DIALOG = 1340;
109 const int LINK_SITE_SETTINGS = 1341; 109 const int LINK_SITE_SETTINGS = 1341;
110 const int LINK_CERTIFICATE_VIEWER = 1342;
110 111
111 // The default, ui::kTitleFontSizeDelta, is too large for the page info 112 // The default, ui::kTitleFontSizeDelta, is too large for the page info
112 // bubble (e.g. +3). Use +1 to obtain a smaller font. 113 // bubble (e.g. +3). Use +1 to obtain a smaller font.
113 constexpr int kSummaryFontSizeDelta = 1; 114 constexpr int kSummaryFontSizeDelta = 1;
114 115
115 // Adds a ColumnSet on |layout| with a single View column and padding columns 116 // Adds a ColumnSet on |layout| with a single View column and padding columns
116 // on either side of it with |margin| width. 117 // on either side of it with |margin| width.
117 void AddColumnWithSideMargin(views::GridLayout* layout, int margin, int id) { 118 void AddColumnWithSideMargin(views::GridLayout* layout, int margin, int id) {
118 views::ColumnSet* column_set = layout->AddColumnSet(id); 119 views::ColumnSet* column_set = layout->AddColumnSet(id);
119 column_set->AddPaddingColumn(0, margin); 120 column_set->AddPaddingColumn(0, margin);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 Profile* profile, 383 Profile* profile,
383 content::WebContents* web_contents, 384 content::WebContents* web_contents,
384 const GURL& url, 385 const GURL& url,
385 const security_state::SecurityInfo& security_info) 386 const security_state::SecurityInfo& security_info)
386 : content::WebContentsObserver(web_contents), 387 : content::WebContentsObserver(web_contents),
387 BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), 388 BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT),
388 profile_(profile), 389 profile_(profile),
389 header_(nullptr), 390 header_(nullptr),
390 separator_(nullptr), 391 separator_(nullptr),
391 site_settings_view_(nullptr), 392 site_settings_view_(nullptr),
392 cookies_view_(nullptr),
393 cookie_dialog_link_(nullptr), 393 cookie_dialog_link_(nullptr),
394 permissions_view_(nullptr), 394 permissions_view_(nullptr),
395 weak_factory_(this) { 395 weak_factory_(this) {
396 g_shown_bubble_type = BUBBLE_PAGE_INFO; 396 g_shown_bubble_type = BUBBLE_PAGE_INFO;
397 set_parent_window(parent_window); 397 set_parent_window(parent_window);
398 398
399 // Compensate for built-in vertical padding in the anchor view's image. 399 // Compensate for built-in vertical padding in the anchor view's image.
400 set_anchor_view_insets(gfx::Insets( 400 set_anchor_view_insets(gfx::Insets(
401 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); 401 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0));
402 402
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 void PageInfoBubbleView::SetCookieInfo(const CookieInfoList& cookie_info_list) { 534 void PageInfoBubbleView::SetCookieInfo(const CookieInfoList& cookie_info_list) {
535 // |cookie_info_list| should only ever have 2 items: first- and third-party 535 // |cookie_info_list| should only ever have 2 items: first- and third-party
536 // cookies. 536 // cookies.
537 DCHECK_EQ(cookie_info_list.size(), 2u); 537 DCHECK_EQ(cookie_info_list.size(), 2u);
538 int total_allowed = 0; 538 int total_allowed = 0;
539 for (const auto& i : cookie_info_list) 539 for (const auto& i : cookie_info_list)
540 total_allowed += i.allowed; 540 total_allowed += i.allowed;
541 base::string16 label_text = l10n_util::GetPluralStringFUTF16( 541 base::string16 label_text = l10n_util::GetPluralStringFUTF16(
542 IDS_PAGE_INFO_NUM_COOKIES, total_allowed); 542 IDS_PAGE_INFO_NUM_COOKIES, total_allowed);
543 543
544 if (!cookie_dialog_link_) { 544 cookie_dialog_link_->SetText(label_text);
545 cookie_dialog_link_ = new views::Link(label_text); 545 Layout();
546 cookie_dialog_link_->set_id(LINK_COOKIE_DIALOG);
547 cookie_dialog_link_->set_listener(this);
548 } else {
549 cookie_dialog_link_->SetText(label_text);
550 }
551
552 views::GridLayout* layout =
553 static_cast<views::GridLayout*>(cookies_view_->GetLayoutManager());
554 if (!layout) {
555 layout = new views::GridLayout(cookies_view_);
556 cookies_view_->SetLayoutManager(layout);
557
558 const int cookies_view_column = 0;
559 views::ColumnSet* column_set = layout->AddColumnSet(cookies_view_column);
560 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
561 views::GridLayout::FIXED, kPermissionIconColumnWidth,
562 0);
563 column_set->AddPaddingColumn(0, kPermissionImageSpacing);
564 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL,
565 0, views::GridLayout::USE_PREF, 0, 0);
566
567 layout->AddPaddingRow(0, kCookiesViewVerticalPadding);
568
569 layout->StartRow(1, cookies_view_column);
570 PageInfoUI::PermissionInfo info;
571 info.type = CONTENT_SETTINGS_TYPE_COOKIES;
572 info.setting = CONTENT_SETTING_ALLOW;
573 info.is_incognito =
574 Profile::FromBrowserContext(web_contents()->GetBrowserContext())
575 ->IsOffTheRecord();
576 views::ImageView* icon = new NonAccessibleImageView();
577 const gfx::Image& image = PageInfoUI::GetPermissionIcon(info);
578 icon->SetImage(image.ToImageSkia());
579 layout->AddView(
580 icon, 1, 2, views::GridLayout::FILL,
581 // TODO: The vertical alignment may change to CENTER once Harmony is
582 // implemented. See https://crbug.com/512442#c48
583 views::GridLayout::LEADING);
584
585 views::Label* cookies_label = new views::Label(
586 l10n_util::GetStringUTF16(IDS_PAGE_INFO_TITLE_SITE_DATA),
587 CONTEXT_BODY_TEXT_LARGE);
588 layout->AddView(cookies_label);
589 layout->StartRow(1, cookies_view_column);
590 layout->SkipColumns(1);
591
592 layout->AddView(cookie_dialog_link_);
593
594 layout->AddPaddingRow(0, kCookiesViewVerticalPadding);
595 }
596
597 layout->Layout(cookies_view_);
598 SizeToContents(); 546 SizeToContents();
599 } 547 }
600 548
601 void PageInfoBubbleView::SetPermissionInfo( 549 void PageInfoBubbleView::SetPermissionInfo(
602 const PermissionInfoList& permission_info_list, 550 const PermissionInfoList& permission_info_list,
603 ChosenObjectInfoList chosen_object_info_list) { 551 ChosenObjectInfoList chosen_object_info_list) {
604 // When a permission is changed, PageInfo::OnSitePermissionChanged() 552 // When a permission is changed, PageInfo::OnSitePermissionChanged()
605 // calls this method with updated permissions. However, PermissionSelectorRow 553 // calls this method with updated permissions. However, PermissionSelectorRow
606 // will have already updated its state, so it's already reflected in the UI. 554 // will have already updated its state, so it's already reflected in the UI.
607 // In addition, if a permission is set to the default setting, PageInfo 555 // In addition, if a permission is set to the default setting, PageInfo
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 identity_info.GetSecurityDescription(); 624 identity_info.GetSecurityDescription();
677 625
678 summary_text_ = security_description->summary; 626 summary_text_ = security_description->summary;
679 GetWidget()->UpdateWindowTitle(); 627 GetWidget()->UpdateWindowTitle();
680 628
681 if (identity_info.certificate) { 629 if (identity_info.certificate) {
682 certificate_ = identity_info.certificate; 630 certificate_ = identity_info.certificate;
683 631
684 if (identity_info.show_ssl_decision_revoke_button) 632 if (identity_info.show_ssl_decision_revoke_button)
685 header_->AddResetDecisionsLabel(); 633 header_->AddResetDecisionsLabel();
634
635 if (PageInfoUI::ShouldShowCertificateLink()) {
636 // The text of link to the Certificate Viewer varies depending on the
637 // validity of the Certificate.
638 const base::string16 link_title =
639 l10n_util::GetStringUTF16((identity_info.identity_status ==
640 PageInfo::SITE_IDENTITY_STATUS_ERROR)
Evan Stade 2017/04/28 19:51:20 nit: might be easier to read if you pulled this co
elawrence 2017/04/28 20:36:51 Done.
641 ? IDS_PAGE_INFO_CERTIFICATE_INVALID_LINK
642 : IDS_PAGE_INFO_CERTIFICATE_VALID_LINK);
643
644 // Create the link to add to the Certificate Section.
645 views::Link* link_inspect = new views::Link(link_title);
646 link_inspect->set_id(LINK_CERTIFICATE_VIEWER);
647 if (identity_info.identity_status !=
648 PageInfo::SITE_IDENTITY_STATUS_ERROR) {
649 link_inspect->SetTooltipText(l10n_util::GetStringFUTF16(
650 IDS_PAGE_INFO_CERTIFICATE_VALID_LINK_TOOLTIP,
651 base::UTF8ToUTF16(certificate_->issuer().GetDisplayName())));
652 }
653
654 // Add the Certificate Section.
655 site_settings_view_->AddChildViewAt(
656 CreateInspectSection(
657 PageInfoUI::GetCertificateIcon(),
658 l10n_util::GetStringUTF16(IDS_PAGE_INFO_CERTIFICATE),
659 link_inspect),
660 0);
661 }
686 } 662 }
687 663
688 header_->SetDetails(security_description->details); 664 header_->SetDetails(security_description->details);
689 665
690 Layout(); 666 Layout();
691 SizeToContents(); 667 SizeToContents();
692 } 668 }
693 669
694 views::View* PageInfoBubbleView::CreateSiteSettingsView(int side_margin) { 670 views::View* PageInfoBubbleView::CreateSiteSettingsView(int side_margin) {
695 views::View* site_settings_view = new views::View(); 671 views::View* site_settings_view = new views::View();
696 views::BoxLayout* box_layout = 672 views::BoxLayout* box_layout =
697 new views::BoxLayout(views::BoxLayout::kVertical, side_margin, 0, 0); 673 new views::BoxLayout(views::BoxLayout::kVertical, side_margin, 0, 0);
698 site_settings_view->SetLayoutManager(box_layout); 674 site_settings_view->SetLayoutManager(box_layout);
699 box_layout->set_cross_axis_alignment( 675 box_layout->set_cross_axis_alignment(
700 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); 676 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH);
701 677
702 // Add cookies view. 678 // Create the link and icon for the Certificate section.
703 cookies_view_ = new views::View(); 679 cookie_dialog_link_ = new views::Link(
704 site_settings_view->AddChildView(cookies_view_); 680 l10n_util::GetPluralStringFUTF16(IDS_PAGE_INFO_NUM_COOKIES, 0));
681 cookie_dialog_link_->set_id(LINK_COOKIE_DIALOG);
682
683 PageInfoUI::PermissionInfo info;
684 info.type = CONTENT_SETTINGS_TYPE_COOKIES;
685 info.setting = CONTENT_SETTING_ALLOW;
686 info.is_incognito =
687 Profile::FromBrowserContext(web_contents()->GetBrowserContext())
688 ->IsOffTheRecord();
689
690 const gfx::ImageSkia* icon =
691 PageInfoUI::GetPermissionIcon(info).ToImageSkia();
Evan Stade 2017/04/28 19:51:21 nit: AsImageSkia()
elawrence 2017/04/28 20:36:51 Done.
692 // Add the Cookies section.
693 site_settings_view->AddChildView(CreateInspectSection(
694 *icon, l10n_util::GetStringUTF16(IDS_PAGE_INFO_TITLE_SITE_DATA),
695 cookie_dialog_link_));
705 696
706 return site_settings_view; 697 return site_settings_view;
707 } 698 }
708 699
700 views::View* PageInfoBubbleView::CreateInspectSection(
Evan Stade 2017/04/28 19:51:21 does this need to be a method? Can we make it a st
elawrence 2017/04/28 20:36:51 It could be converted to a static method that eith
Evan Stade 2017/04/28 20:56:55 static function in this file declutters the header
elawrence 2017/04/29 12:38:58 Done.
701 const gfx::ImageSkia& image_icon,
702 const base::string16& title,
Evan Stade 2017/04/28 19:51:21 nit: if you make this take an int (IDS_ value) it
elawrence 2017/04/28 20:36:51 Good point! Done.
703 views::Link* link) {
704 views::View* new_view = new views::View();
705
706 views::GridLayout* layout = new views::GridLayout(new_view);
707 new_view->SetLayoutManager(layout);
708
709 const int column = 0;
710 views::ColumnSet* column_set = layout->AddColumnSet(column);
711 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
712 views::GridLayout::FIXED, kPermissionIconColumnWidth,
713 0);
714 column_set->AddPaddingColumn(0, kPermissionImageSpacing);
715 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0,
716 views::GridLayout::USE_PREF, 0, 0);
717
718 layout->AddPaddingRow(0, kSubViewsVerticalPadding);
719
720 layout->StartRow(1, column);
721
722 views::ImageView* icon = new NonAccessibleImageView();
723 icon->SetImage(image_icon);
724 layout->AddView(
725 icon, 1, 2, views::GridLayout::FILL,
726 // TODO(lgarron): The vertical alignment may change to CENTER once
727 // Harmony is implemented. See https://crbug.com/512442#c48
728 views::GridLayout::LEADING);
729
730 views::Label* title_label = new views::Label(title, CONTEXT_BODY_TEXT_LARGE);
731 layout->AddView(title_label);
732 layout->StartRow(1, column);
733 layout->SkipColumns(1);
734
735 link->set_listener(this);
736 layout->AddView(link);
737 return new_view;
738 }
739
709 void PageInfoBubbleView::HandleLinkClickedAsync(views::Link* source) { 740 void PageInfoBubbleView::HandleLinkClickedAsync(views::Link* source) {
710 // Both switch cases require accessing web_contents(), so we check it here. 741 // All switch cases require accessing web_contents(), so we check it here.
711 if (web_contents() == nullptr || web_contents()->IsBeingDestroyed()) 742 if (web_contents() == nullptr || web_contents()->IsBeingDestroyed())
712 return; 743 return;
713 switch (source->id()) { 744 switch (source->id()) {
714 case LINK_SITE_SETTINGS: 745 case LINK_SITE_SETTINGS:
715 // TODO(crbug.com/655876): This opens the general Content Settings pane, 746 // TODO(crbug.com/655876): This opens the general Content Settings pane,
716 // which is OK for now. But on Android, it opens a page specific to a 747 // which is OK for now. But on Android, it opens a page specific to a
717 // given origin that shows all of the settings for that origin. If/when 748 // given origin that shows all of the settings for that origin. If/when
718 // that's available on desktop we should link to that here, too. 749 // that's available on desktop we should link to that here, too.
719 web_contents()->OpenURL(content::OpenURLParams( 750 web_contents()->OpenURL(content::OpenURLParams(
720 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(), 751 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(),
721 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, 752 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
722 false)); 753 false));
723 presenter_->RecordPageInfoAction( 754 presenter_->RecordPageInfoAction(
724 PageInfo::PAGE_INFO_SITE_SETTINGS_OPENED); 755 PageInfo::PAGE_INFO_SITE_SETTINGS_OPENED);
725 break; 756 break;
726 case LINK_COOKIE_DIALOG: 757 case LINK_COOKIE_DIALOG:
727 // Count how often the Collected Cookies dialog is opened. 758 // Count how often the Collected Cookies dialog is opened.
728 presenter_->RecordPageInfoAction( 759 presenter_->RecordPageInfoAction(
729 PageInfo::PAGE_INFO_COOKIES_DIALOG_OPENED); 760 PageInfo::PAGE_INFO_COOKIES_DIALOG_OPENED);
730 new CollectedCookiesViews(web_contents()); 761 new CollectedCookiesViews(web_contents());
731 break; 762 break;
763 case LINK_CERTIFICATE_VIEWER: {
764 gfx::NativeWindow top_window = web_contents()->GetTopLevelNativeWindow();
765 if (certificate_ && top_window) {
766 presenter_->RecordPageInfoAction(
767 PageInfo::PAGE_INFO_CERTIFICATE_DIALOG_OPENED);
768 ShowCertificateViewer(web_contents(), top_window, certificate_.get());
769 }
770 break;
771 }
732 default: 772 default:
733 NOTREACHED(); 773 NOTREACHED();
734 } 774 }
735 } 775 }
736 776
737 void PageInfoBubbleView::StyledLabelLinkClicked(views::StyledLabel* label, 777 void PageInfoBubbleView::StyledLabelLinkClicked(views::StyledLabel* label,
738 const gfx::Range& range, 778 const gfx::Range& range,
739 int event_flags) { 779 int event_flags) {
740 switch (label->id()) { 780 switch (label->id()) {
741 case STYLED_LABEL_SECURITY_DETAILS: 781 case STYLED_LABEL_SECURITY_DETAILS:
742 web_contents()->OpenURL(content::OpenURLParams( 782 web_contents()->OpenURL(content::OpenURLParams(
743 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(), 783 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(),
744 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, 784 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
745 false)); 785 false));
746 presenter_->RecordPageInfoAction( 786 presenter_->RecordPageInfoAction(
747 PageInfo::PAGE_INFO_CONNECTION_HELP_OPENED); 787 PageInfo::PAGE_INFO_CONNECTION_HELP_OPENED);
748 break; 788 break;
749 case STYLED_LABEL_RESET_CERTIFICATE_DECISIONS: 789 case STYLED_LABEL_RESET_CERTIFICATE_DECISIONS:
750 presenter_->OnRevokeSSLErrorBypassButtonPressed(); 790 presenter_->OnRevokeSSLErrorBypassButtonPressed();
751 GetWidget()->Close(); 791 GetWidget()->Close();
752 break; 792 break;
753 default: 793 default:
754 NOTREACHED(); 794 NOTREACHED();
755 } 795 }
756 } 796 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/page_info/page_info_bubble_view.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698