OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 bool valid_identity = (identity_info.identity_status != | |
639 PageInfo::SITE_IDENTITY_STATUS_ERROR); | |
640 const base::string16 link_title = l10n_util::GetStringUTF16( | |
641 valid_identity ? IDS_PAGE_INFO_CERTIFICATE_VALID_LINK | |
642 : IDS_PAGE_INFO_CERTIFICATE_INVALID_LINK); | |
643 | |
644 // Create the link to add to the Certificate Section. | |
645 views::Link* link_inspect = new views::Link(link_title); | |
lgarron
2017/04/28 23:16:43
Nit: `inspect_link`
(You might have been trying t
elawrence
2017/04/29 12:38:58
Done.
| |
646 link_inspect->set_id(LINK_CERTIFICATE_VIEWER); | |
647 if (valid_identity) { | |
648 link_inspect->SetTooltipText(l10n_util::GetStringFUTF16( | |
649 IDS_PAGE_INFO_CERTIFICATE_VALID_LINK_TOOLTIP, | |
650 base::UTF8ToUTF16(certificate_->issuer().GetDisplayName()))); | |
651 } | |
652 | |
653 // Add the Certificate Section. | |
654 site_settings_view_->AddChildViewAt( | |
lgarron
2017/04/28 23:16:43
This doesn't seem to wrap (at least on MacViews) -
elawrence
2017/04/29 12:38:58
Acknowledged.
| |
655 CreateInspectSection(PageInfoUI::GetCertificateIcon(), | |
656 IDS_PAGE_INFO_CERTIFICATE, link_inspect), | |
657 0); | |
658 } | |
686 } | 659 } |
687 | 660 |
688 header_->SetDetails(security_description->details); | 661 header_->SetDetails(security_description->details); |
689 | 662 |
690 Layout(); | 663 Layout(); |
691 SizeToContents(); | 664 SizeToContents(); |
692 } | 665 } |
693 | 666 |
694 views::View* PageInfoBubbleView::CreateSiteSettingsView(int side_margin) { | 667 views::View* PageInfoBubbleView::CreateSiteSettingsView(int side_margin) { |
695 views::View* site_settings_view = new views::View(); | 668 views::View* site_settings_view = new views::View(); |
696 views::BoxLayout* box_layout = | 669 views::BoxLayout* box_layout = |
697 new views::BoxLayout(views::BoxLayout::kVertical, side_margin, 0, 0); | 670 new views::BoxLayout(views::BoxLayout::kVertical, side_margin, 0, 0); |
698 site_settings_view->SetLayoutManager(box_layout); | 671 site_settings_view->SetLayoutManager(box_layout); |
699 box_layout->set_cross_axis_alignment( | 672 box_layout->set_cross_axis_alignment( |
700 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); | 673 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); |
701 | 674 |
702 // Add cookies view. | 675 // Create the link and icon for the Certificate section. |
703 cookies_view_ = new views::View(); | 676 cookie_dialog_link_ = new views::Link( |
704 site_settings_view->AddChildView(cookies_view_); | 677 l10n_util::GetPluralStringFUTF16(IDS_PAGE_INFO_NUM_COOKIES, 0)); |
678 cookie_dialog_link_->set_id(LINK_COOKIE_DIALOG); | |
679 | |
680 PageInfoUI::PermissionInfo info; | |
681 info.type = CONTENT_SETTINGS_TYPE_COOKIES; | |
682 info.setting = CONTENT_SETTING_ALLOW; | |
683 info.is_incognito = | |
684 Profile::FromBrowserContext(web_contents()->GetBrowserContext()) | |
685 ->IsOffTheRecord(); | |
686 | |
687 const gfx::ImageSkia icon = PageInfoUI::GetPermissionIcon(info).AsImageSkia(); | |
688 // Add the Cookies section. | |
689 site_settings_view->AddChildView(CreateInspectSection( | |
690 icon, IDS_PAGE_INFO_TITLE_SITE_DATA, cookie_dialog_link_)); | |
705 | 691 |
706 return site_settings_view; | 692 return site_settings_view; |
707 } | 693 } |
708 | 694 |
695 views::View* PageInfoBubbleView::CreateInspectSection( | |
696 const gfx::ImageSkia& image_icon, | |
697 const int title_id, | |
698 views::Link* link) { | |
699 views::View* new_view = new views::View(); | |
700 | |
701 views::GridLayout* layout = new views::GridLayout(new_view); | |
702 new_view->SetLayoutManager(layout); | |
703 | |
704 const int column = 0; | |
705 views::ColumnSet* column_set = layout->AddColumnSet(column); | |
706 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | |
707 views::GridLayout::FIXED, kPermissionIconColumnWidth, | |
708 0); | |
709 column_set->AddPaddingColumn(0, kPermissionImageSpacing); | |
710 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0, | |
711 views::GridLayout::USE_PREF, 0, 0); | |
712 | |
713 layout->AddPaddingRow(0, kSubViewsVerticalPadding); | |
714 | |
715 layout->StartRow(1, column); | |
716 | |
717 views::ImageView* icon = new NonAccessibleImageView(); | |
718 icon->SetImage(image_icon); | |
719 layout->AddView( | |
720 icon, 1, 2, views::GridLayout::FILL, | |
721 // TODO(lgarron): The vertical alignment may change to CENTER once | |
722 // Harmony is implemented. See https://crbug.com/512442#c48 | |
723 views::GridLayout::LEADING); | |
724 | |
725 views::Label* title_label = new views::Label( | |
726 l10n_util::GetStringUTF16(title_id), CONTEXT_BODY_TEXT_LARGE); | |
727 layout->AddView(title_label); | |
728 layout->StartRow(1, column); | |
729 layout->SkipColumns(1); | |
730 | |
731 link->set_listener(this); | |
732 layout->AddView(link); | |
733 return new_view; | |
734 } | |
735 | |
709 void PageInfoBubbleView::HandleLinkClickedAsync(views::Link* source) { | 736 void PageInfoBubbleView::HandleLinkClickedAsync(views::Link* source) { |
710 // Both switch cases require accessing web_contents(), so we check it here. | 737 // All switch cases require accessing web_contents(), so we check it here. |
711 if (web_contents() == nullptr || web_contents()->IsBeingDestroyed()) | 738 if (web_contents() == nullptr || web_contents()->IsBeingDestroyed()) |
712 return; | 739 return; |
713 switch (source->id()) { | 740 switch (source->id()) { |
714 case LINK_SITE_SETTINGS: | 741 case LINK_SITE_SETTINGS: |
715 // TODO(crbug.com/655876): This opens the general Content Settings pane, | 742 // 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 | 743 // 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 | 744 // 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. | 745 // that's available on desktop we should link to that here, too. |
719 web_contents()->OpenURL(content::OpenURLParams( | 746 web_contents()->OpenURL(content::OpenURLParams( |
720 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(), | 747 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(), |
721 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, | 748 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, |
722 false)); | 749 false)); |
723 presenter_->RecordPageInfoAction( | 750 presenter_->RecordPageInfoAction( |
724 PageInfo::PAGE_INFO_SITE_SETTINGS_OPENED); | 751 PageInfo::PAGE_INFO_SITE_SETTINGS_OPENED); |
725 break; | 752 break; |
726 case LINK_COOKIE_DIALOG: | 753 case LINK_COOKIE_DIALOG: |
727 // Count how often the Collected Cookies dialog is opened. | 754 // Count how often the Collected Cookies dialog is opened. |
728 presenter_->RecordPageInfoAction( | 755 presenter_->RecordPageInfoAction( |
729 PageInfo::PAGE_INFO_COOKIES_DIALOG_OPENED); | 756 PageInfo::PAGE_INFO_COOKIES_DIALOG_OPENED); |
730 new CollectedCookiesViews(web_contents()); | 757 new CollectedCookiesViews(web_contents()); |
731 break; | 758 break; |
759 case LINK_CERTIFICATE_VIEWER: { | |
760 gfx::NativeWindow top_window = web_contents()->GetTopLevelNativeWindow(); | |
761 if (certificate_ && top_window) { | |
762 presenter_->RecordPageInfoAction( | |
763 PageInfo::PAGE_INFO_CERTIFICATE_DIALOG_OPENED); | |
764 ShowCertificateViewer(web_contents(), top_window, certificate_.get()); | |
765 } | |
766 break; | |
767 } | |
732 default: | 768 default: |
733 NOTREACHED(); | 769 NOTREACHED(); |
734 } | 770 } |
735 } | 771 } |
736 | 772 |
737 void PageInfoBubbleView::StyledLabelLinkClicked(views::StyledLabel* label, | 773 void PageInfoBubbleView::StyledLabelLinkClicked(views::StyledLabel* label, |
738 const gfx::Range& range, | 774 const gfx::Range& range, |
739 int event_flags) { | 775 int event_flags) { |
740 switch (label->id()) { | 776 switch (label->id()) { |
741 case STYLED_LABEL_SECURITY_DETAILS: | 777 case STYLED_LABEL_SECURITY_DETAILS: |
742 web_contents()->OpenURL(content::OpenURLParams( | 778 web_contents()->OpenURL(content::OpenURLParams( |
743 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(), | 779 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(), |
744 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, | 780 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, |
745 false)); | 781 false)); |
746 presenter_->RecordPageInfoAction( | 782 presenter_->RecordPageInfoAction( |
747 PageInfo::PAGE_INFO_CONNECTION_HELP_OPENED); | 783 PageInfo::PAGE_INFO_CONNECTION_HELP_OPENED); |
748 break; | 784 break; |
749 case STYLED_LABEL_RESET_CERTIFICATE_DECISIONS: | 785 case STYLED_LABEL_RESET_CERTIFICATE_DECISIONS: |
750 presenter_->OnRevokeSSLErrorBypassButtonPressed(); | 786 presenter_->OnRevokeSSLErrorBypassButtonPressed(); |
751 GetWidget()->Close(); | 787 GetWidget()->Close(); |
752 break; | 788 break; |
753 default: | 789 default: |
754 NOTREACHED(); | 790 NOTREACHED(); |
755 } | 791 } |
756 } | 792 } |
OLD | NEW |