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

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

Issue 2737413004: Add a Certificate Viewer link to the Page Info dropdown (Closed)
Patch Set: Add Cocoa, Fix MaxViews, Add Flag Created 3 years, 8 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_popup_view.h" 5 #include "chrome/browser/ui/views/page_info/page_info_popup_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/command_line.h"
12 #include "base/i18n/rtl.h" 13 #include "base/i18n/rtl.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
15 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
16 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
18 #include "chrome/browser/certificate_viewer.h" 19 #include "chrome/browser/certificate_viewer.h"
19 #include "chrome/browser/infobars/infobar_service.h" 20 #include "chrome/browser/infobars/infobar_service.h"
20 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/browser_dialogs.h" 23 #include "chrome/browser/ui/browser_dialogs.h"
23 #include "chrome/browser/ui/layout_constants.h" 24 #include "chrome/browser/ui/layout_constants.h"
24 #include "chrome/browser/ui/page_info/page_info.h" 25 #include "chrome/browser/ui/page_info/page_info.h"
25 #include "chrome/browser/ui/views/collected_cookies_views.h" 26 #include "chrome/browser/ui/views/collected_cookies_views.h"
26 #include "chrome/browser/ui/views/harmony/chrome_typography.h" 27 #include "chrome/browser/ui/views/harmony/chrome_typography.h"
27 #include "chrome/browser/ui/views/harmony/layout_delegate.h" 28 #include "chrome/browser/ui/views/harmony/layout_delegate.h"
28 #include "chrome/browser/ui/views/page_info/chosen_object_row.h" 29 #include "chrome/browser/ui/views/page_info/chosen_object_row.h"
29 #include "chrome/browser/ui/views/page_info/non_accessible_image_view.h" 30 #include "chrome/browser/ui/views/page_info/non_accessible_image_view.h"
30 #include "chrome/browser/ui/views/page_info/permission_selector_row.h" 31 #include "chrome/browser/ui/views/page_info/permission_selector_row.h"
32 #include "chrome/common/chrome_switches.h"
31 #include "chrome/common/url_constants.h" 33 #include "chrome/common/url_constants.h"
32 #include "chrome/grit/chromium_strings.h" 34 #include "chrome/grit/chromium_strings.h"
33 #include "chrome/grit/generated_resources.h" 35 #include "chrome/grit/generated_resources.h"
34 #include "chrome/grit/theme_resources.h" 36 #include "chrome/grit/theme_resources.h"
35 #include "components/content_settings/core/common/content_settings_types.h" 37 #include "components/content_settings/core/common/content_settings_types.h"
36 #include "components/strings/grit/components_chromium_strings.h" 38 #include "components/strings/grit/components_chromium_strings.h"
37 #include "components/strings/grit/components_strings.h" 39 #include "components/strings/grit/components_strings.h"
38 #include "content/public/browser/browser_thread.h" 40 #include "content/public/browser/browser_thread.h"
39 #include "extensions/common/constants.h" 41 #include "extensions/common/constants.h"
40 #include "ui/base/l10n/l10n_util.h" 42 #include "ui/base/l10n/l10n_util.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 82
81 // Margin and padding values for the |PopupHeaderView|. 83 // Margin and padding values for the |PopupHeaderView|.
82 const int kHeaderMarginBottom = 10; 84 const int kHeaderMarginBottom = 10;
83 const int kHeaderPaddingBottom = 13; 85 const int kHeaderPaddingBottom = 13;
84 86
85 // Spacing between labels in the header. 87 // Spacing between labels in the header.
86 const int kHeaderLabelSpacing = 4; 88 const int kHeaderLabelSpacing = 4;
87 89
88 // Site Settings Section ------------------------------------------------------- 90 // Site Settings Section -------------------------------------------------------
89 91
90 // Spacing above and below the cookies view. 92 // Spacing above and below the cookies and certificate views.
91 const int kCookiesViewVerticalPadding = 6; 93 const int kSubViewsVerticalPadding = 6;
92 94
93 // Spacing between a permission image and the text. 95 // Spacing between a permission image and the text.
94 const int kPermissionImageSpacing = 6; 96 const int kPermissionImageSpacing = 6;
95 97
96 // Spacing between rows in the site settings section 98 // Spacing between rows in the site settings section
97 const int kPermissionsVerticalSpacing = 12; 99 const int kPermissionsVerticalSpacing = 12;
98 100
99 // Spacing between the label and the menu. 101 // Spacing between the label and the menu.
100 const int kPermissionMenuSpacing = 16; 102 const int kPermissionMenuSpacing = 16;
101 103
102 // Button/styled label/link IDs ------------------------------------------------ 104 // Button/styled label/link IDs ------------------------------------------------
103 const int BUTTON_CLOSE = 1337; 105 const int BUTTON_CLOSE = 1337;
104 const int STYLED_LABEL_SECURITY_DETAILS = 1338; 106 const int STYLED_LABEL_SECURITY_DETAILS = 1338;
105 const int STYLED_LABEL_RESET_CERTIFICATE_DECISIONS = 1339; 107 const int STYLED_LABEL_RESET_CERTIFICATE_DECISIONS = 1339;
106 const int LINK_COOKIE_DIALOG = 1340; 108 const int LINK_COOKIE_DIALOG = 1340;
107 const int LINK_SITE_SETTINGS = 1341; 109 const int LINK_SITE_SETTINGS = 1341;
110 const int LINK_CERTIFICATE_VIEWER = 1342;
108 111
109 // The default, ui::kTitleFontSizeDelta, is too large for the page info 112 // The default, ui::kTitleFontSizeDelta, is too large for the page info
110 // bubble (e.g. +3). Use +1 to obtain a smaller font. 113 // bubble (e.g. +3). Use +1 to obtain a smaller font.
111 constexpr int kSummaryFontSizeDelta = 1; 114 constexpr int kSummaryFontSizeDelta = 1;
112 115
113 // 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
114 // on either side of it with |margin| width. 117 // on either side of it with |margin| width.
115 void AddColumnWithSideMargin(views::GridLayout* layout, int margin, int id) { 118 void AddColumnWithSideMargin(views::GridLayout* layout, int margin, int id) {
116 views::ColumnSet* column_set = layout->AddColumnSet(id); 119 views::ColumnSet* column_set = layout->AddColumnSet(id);
117 column_set->AddPaddingColumn(0, margin); 120 column_set->AddPaddingColumn(0, margin);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 Profile* profile, 383 Profile* profile,
381 content::WebContents* web_contents, 384 content::WebContents* web_contents,
382 const GURL& url, 385 const GURL& url,
383 const security_state::SecurityInfo& security_info) 386 const security_state::SecurityInfo& security_info)
384 : content::WebContentsObserver(web_contents), 387 : content::WebContentsObserver(web_contents),
385 BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), 388 BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT),
386 profile_(profile), 389 profile_(profile),
387 header_(nullptr), 390 header_(nullptr),
388 separator_(nullptr), 391 separator_(nullptr),
389 site_settings_view_(nullptr), 392 site_settings_view_(nullptr),
393 certificate_view_(nullptr),
394 certificate_viewer_link_(nullptr),
390 cookies_view_(nullptr), 395 cookies_view_(nullptr),
391 cookie_dialog_link_(nullptr), 396 cookie_dialog_link_(nullptr),
392 permissions_view_(nullptr), 397 permissions_view_(nullptr),
393 weak_factory_(this) { 398 weak_factory_(this) {
394 g_shown_popup_type = POPUP_PAGE_INFO; 399 g_shown_popup_type = POPUP_PAGE_INFO;
395 set_parent_window(parent_window); 400 set_parent_window(parent_window);
396 401
397 // Compensate for built-in vertical padding in the anchor view's image. 402 // Compensate for built-in vertical padding in the anchor view's image.
398 set_anchor_view_insets(gfx::Insets( 403 set_anchor_view_insets(gfx::Insets(
399 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); 404 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0));
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 560
556 const int cookies_view_column = 0; 561 const int cookies_view_column = 0;
557 views::ColumnSet* column_set = layout->AddColumnSet(cookies_view_column); 562 views::ColumnSet* column_set = layout->AddColumnSet(cookies_view_column);
558 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, 563 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
559 views::GridLayout::FIXED, kPermissionIconColumnWidth, 564 views::GridLayout::FIXED, kPermissionIconColumnWidth,
560 0); 565 0);
561 column_set->AddPaddingColumn(0, kPermissionImageSpacing); 566 column_set->AddPaddingColumn(0, kPermissionImageSpacing);
562 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 567 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL,
563 0, views::GridLayout::USE_PREF, 0, 0); 568 0, views::GridLayout::USE_PREF, 0, 0);
564 569
565 layout->AddPaddingRow(0, kCookiesViewVerticalPadding); 570 layout->AddPaddingRow(0, kSubViewsVerticalPadding);
566 571
567 layout->StartRow(1, cookies_view_column); 572 layout->StartRow(1, cookies_view_column);
568 PageInfoUI::PermissionInfo info; 573 PageInfoUI::PermissionInfo info;
569 info.type = CONTENT_SETTINGS_TYPE_COOKIES; 574 info.type = CONTENT_SETTINGS_TYPE_COOKIES;
570 info.setting = CONTENT_SETTING_ALLOW; 575 info.setting = CONTENT_SETTING_ALLOW;
571 info.is_incognito = 576 info.is_incognito =
572 Profile::FromBrowserContext(web_contents()->GetBrowserContext()) 577 Profile::FromBrowserContext(web_contents()->GetBrowserContext())
573 ->IsOffTheRecord(); 578 ->IsOffTheRecord();
574 views::ImageView* icon = new NonAccessibleImageView(); 579 views::ImageView* icon = new NonAccessibleImageView();
575 const gfx::Image& image = PageInfoUI::GetPermissionIcon(info); 580 const gfx::Image& image = PageInfoUI::GetPermissionIcon(info);
576 icon->SetImage(image.ToImageSkia()); 581 icon->SetImage(image.ToImageSkia());
577 layout->AddView( 582 layout->AddView(
578 icon, 1, 2, views::GridLayout::FILL, 583 icon, 1, 2, views::GridLayout::FILL,
579 // TODO: The vertical alignment may change to CENTER once Harmony is 584 // TODO(lgarron): The vertical alignment may change to CENTER once
580 // implemented. See https://crbug.com/512442#c48 585 // Harmony is implemented. See https://crbug.com/512442#c48
581 views::GridLayout::LEADING); 586 views::GridLayout::LEADING);
582 587
583 views::Label* cookies_label = new views::Label( 588 views::Label* cookies_label = new views::Label(
584 l10n_util::GetStringUTF16(IDS_PAGE_INFO_TITLE_SITE_DATA), 589 l10n_util::GetStringUTF16(IDS_PAGE_INFO_TITLE_SITE_DATA),
585 CONTEXT_BODY_TEXT_LARGE); 590 CONTEXT_BODY_TEXT_LARGE);
586 layout->AddView(cookies_label); 591 layout->AddView(cookies_label);
587 layout->StartRow(1, cookies_view_column); 592 layout->StartRow(1, cookies_view_column);
588 layout->SkipColumns(1); 593 layout->SkipColumns(1);
589 594
590 layout->AddView(cookie_dialog_link_); 595 layout->AddView(cookie_dialog_link_);
591 596
592 layout->AddPaddingRow(0, kCookiesViewVerticalPadding); 597 layout->AddPaddingRow(0, kSubViewsVerticalPadding);
593 } 598 }
594 599
595 layout->Layout(cookies_view_); 600 layout->Layout(cookies_view_);
596 SizeToContents(); 601 SizeToContents();
597 } 602 }
598 603
599 void PageInfoPopupView::SetPermissionInfo( 604 void PageInfoPopupView::SetPermissionInfo(
600 const PermissionInfoList& permission_info_list, 605 const PermissionInfoList& permission_info_list,
601 ChosenObjectInfoList chosen_object_info_list) { 606 ChosenObjectInfoList chosen_object_info_list) {
602 // When a permission is changed, PageInfo::OnSitePermissionChanged() 607 // When a permission is changed, PageInfo::OnSitePermissionChanged()
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 identity_info.GetSecurityDescription(); 679 identity_info.GetSecurityDescription();
675 680
676 summary_text_ = security_description->summary; 681 summary_text_ = security_description->summary;
677 GetWidget()->UpdateWindowTitle(); 682 GetWidget()->UpdateWindowTitle();
678 683
679 if (identity_info.certificate) { 684 if (identity_info.certificate) {
680 certificate_ = identity_info.certificate; 685 certificate_ = identity_info.certificate;
681 686
682 if (identity_info.show_ssl_decision_revoke_button) 687 if (identity_info.show_ssl_decision_revoke_button)
683 header_->AddResetDecisionsLabel(); 688 header_->AddResetDecisionsLabel();
689
690 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
691 switches::kShowCertButton)) {
692 certificate_view_ = new views::View();
693 views::GridLayout* layout = static_cast<views::GridLayout*>(
694 certificate_view_->GetLayoutManager());
695 if (!layout) {
696 layout = new views::GridLayout(certificate_view_);
697 certificate_view_->SetLayoutManager(layout);
698
699 const int certificate_view_column = 0;
700 views::ColumnSet* column_set =
701 layout->AddColumnSet(certificate_view_column);
702 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
703 0, views::GridLayout::FIXED,
704 kPermissionIconColumnWidth, 0);
705 column_set->AddPaddingColumn(0, kPermissionImageSpacing);
706 column_set->AddColumn(views::GridLayout::LEADING,
707 views::GridLayout::FILL, 0,
708 views::GridLayout::USE_PREF, 0, 0);
709
710 layout->AddPaddingRow(0, kSubViewsVerticalPadding);
711
712 layout->StartRow(1, certificate_view_column);
713
714 views::ImageView* icon = new NonAccessibleImageView();
715 const gfx::Image& image = PageInfoUI::GetCertificateIcon();
716 icon->SetImage(image.ToImageSkia());
717 layout->AddView(
718 icon, 1, 2, views::GridLayout::FILL,
719 // TODO(lgarron): The vertical alignment may change to CENTER once
720 // Harmony is implemented. See https://crbug.com/512442#c48
721 views::GridLayout::LEADING);
722
723 views::Label* certificate_label = new views::Label(
724 l10n_util::GetStringUTF16(IDS_PAGE_INFO_CERTIFICATE),
725 CONTEXT_BODY_TEXT_LARGE);
726 layout->AddView(certificate_label);
727 layout->StartRow(1, certificate_view_column);
728 layout->SkipColumns(1);
729
730 // The text of link to the Certificate Viewer varies depending on the
731 // validity of the Certificate.
732 certificate_viewer_link_ = new views::Link(l10n_util::GetStringUTF16(
733 (identity_info.identity_status ==
734 PageInfo::SITE_IDENTITY_STATUS_ERROR)
735 ? IDS_PAGE_INFO_CERTIFICATE_INVALID_LINK
736 : IDS_PAGE_INFO_CERTIFICATE_VALID_LINK));
737 certificate_viewer_link_->set_id(LINK_CERTIFICATE_VIEWER);
738 certificate_viewer_link_->set_listener(this);
739
740 layout->AddView(certificate_viewer_link_);
741 }
742
743 layout->Layout(certificate_view_);
744 site_settings_view_->AddChildViewAt(certificate_view_, 0);
745 }
684 } 746 }
685 747
686 header_->SetDetails(security_description->details); 748 header_->SetDetails(security_description->details);
687 749
688 Layout(); 750 Layout();
689 SizeToContents(); 751 SizeToContents();
690 } 752 }
691 753
692 views::View* PageInfoPopupView::CreateSiteSettingsView(int side_margin) { 754 views::View* PageInfoPopupView::CreateSiteSettingsView(int side_margin) {
693 views::View* site_settings_view = new views::View(); 755 views::View* site_settings_view = new views::View();
694 views::BoxLayout* box_layout = 756 views::BoxLayout* box_layout =
695 new views::BoxLayout(views::BoxLayout::kVertical, side_margin, 0, 0); 757 new views::BoxLayout(views::BoxLayout::kVertical, side_margin, 0, 0);
696 site_settings_view->SetLayoutManager(box_layout); 758 site_settings_view->SetLayoutManager(box_layout);
697 box_layout->set_cross_axis_alignment( 759 box_layout->set_cross_axis_alignment(
698 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); 760 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH);
699 761
700 // Add cookies view. 762 // Add cookies view.
701 cookies_view_ = new views::View(); 763 cookies_view_ = new views::View();
702 site_settings_view->AddChildView(cookies_view_); 764 site_settings_view->AddChildView(cookies_view_);
703 765
704 return site_settings_view; 766 return site_settings_view;
705 } 767 }
706 768
707 void PageInfoPopupView::HandleLinkClickedAsync(views::Link* source) { 769 void PageInfoPopupView::HandleLinkClickedAsync(views::Link* source) {
708 // Both switch cases require accessing web_contents(), so we check it here. 770 // All switch cases require accessing web_contents(), so we check it here.
709 if (web_contents() == nullptr || web_contents()->IsBeingDestroyed()) 771 if (web_contents() == nullptr || web_contents()->IsBeingDestroyed())
710 return; 772 return;
711 switch (source->id()) { 773 switch (source->id()) {
712 case LINK_SITE_SETTINGS: 774 case LINK_SITE_SETTINGS:
713 // TODO(crbug.com/655876): This opens the general Content Settings pane, 775 // TODO(crbug.com/655876): This opens the general Content Settings pane,
714 // which is OK for now. But on Android, it opens a page specific to a 776 // which is OK for now. But on Android, it opens a page specific to a
715 // given origin that shows all of the settings for that origin. If/when 777 // given origin that shows all of the settings for that origin. If/when
716 // that's available on desktop we should link to that here, too. 778 // that's available on desktop we should link to that here, too.
717 web_contents()->OpenURL(content::OpenURLParams( 779 web_contents()->OpenURL(content::OpenURLParams(
718 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(), 780 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(),
719 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, 781 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
720 false)); 782 false));
721 presenter_->RecordPageInfoAction( 783 presenter_->RecordPageInfoAction(
722 PageInfo::PAGE_INFO_SITE_SETTINGS_OPENED); 784 PageInfo::PAGE_INFO_SITE_SETTINGS_OPENED);
723 break; 785 break;
724 case LINK_COOKIE_DIALOG: 786 case LINK_COOKIE_DIALOG:
725 // Count how often the Collected Cookies dialog is opened. 787 // Count how often the Collected Cookies dialog is opened.
726 presenter_->RecordPageInfoAction( 788 presenter_->RecordPageInfoAction(
727 PageInfo::PAGE_INFO_COOKIES_DIALOG_OPENED); 789 PageInfo::PAGE_INFO_COOKIES_DIALOG_OPENED);
728 new CollectedCookiesViews(web_contents()); 790 new CollectedCookiesViews(web_contents());
729 break; 791 break;
792 case LINK_CERTIFICATE_VIEWER: {
793 gfx::NativeWindow top_window = web_contents()->GetTopLevelNativeWindow();
794 if (certificate_ && top_window) {
795 presenter_->RecordPageInfoAction(
796 PageInfo::PAGE_INFO_CERTIFICATE_DIALOG_OPENED);
797 ShowCertificateViewer(web_contents(), top_window, certificate_.get());
798 }
799 } break;
730 default: 800 default:
731 NOTREACHED(); 801 NOTREACHED();
732 } 802 }
733 } 803 }
734 804
735 void PageInfoPopupView::StyledLabelLinkClicked(views::StyledLabel* label, 805 void PageInfoPopupView::StyledLabelLinkClicked(views::StyledLabel* label,
736 const gfx::Range& range, 806 const gfx::Range& range,
737 int event_flags) { 807 int event_flags) {
738 switch (label->id()) { 808 switch (label->id()) {
739 case STYLED_LABEL_SECURITY_DETAILS: 809 case STYLED_LABEL_SECURITY_DETAILS:
740 web_contents()->OpenURL(content::OpenURLParams( 810 web_contents()->OpenURL(content::OpenURLParams(
741 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(), 811 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(),
742 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, 812 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
743 false)); 813 false));
744 presenter_->RecordPageInfoAction( 814 presenter_->RecordPageInfoAction(
745 PageInfo::PAGE_INFO_CONNECTION_HELP_OPENED); 815 PageInfo::PAGE_INFO_CONNECTION_HELP_OPENED);
746 break; 816 break;
747 case STYLED_LABEL_RESET_CERTIFICATE_DECISIONS: 817 case STYLED_LABEL_RESET_CERTIFICATE_DECISIONS:
748 presenter_->OnRevokeSSLErrorBypassButtonPressed(); 818 presenter_->OnRevokeSSLErrorBypassButtonPressed();
749 GetWidget()->Close(); 819 GetWidget()->Close();
750 break; 820 break;
751 default: 821 default:
752 NOTREACHED(); 822 NOTREACHED();
753 } 823 }
754 } 824 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698