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

Side by Side Diff: chrome/browser/ui/views/website_settings/website_settings_popup_view.cc

Issue 2429693002: Fix wiring for Page Info buttons/links. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/website_settings/website_settings_popup_view.h " 5 #include "chrome/browser/ui/views/website_settings/website_settings_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 <vector>
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 // Spacing above and below the cookies view. 101 // Spacing above and below the cookies view.
102 const int kCookiesViewVerticalPadding = 6; 102 const int kCookiesViewVerticalPadding = 6;
103 103
104 // Spacing between a permission image and the text. 104 // Spacing between a permission image and the text.
105 const int kPermissionImageSpacing = 6; 105 const int kPermissionImageSpacing = 6;
106 106
107 // Spacing between rows in the site settings section 107 // Spacing between rows in the site settings section
108 const int kPermissionsVerticalSpacing = 12; 108 const int kPermissionsVerticalSpacing = 12;
109 109
110 // Button IDs ------------------------------------------------------------------ 110 // Button/styled label/link IDs ------------------------------------------------
111 111 const int BUTTON_CLOSE = 1337;
112 const int BUTTON_RESET_CERTIFICATE_DECISIONS = 1337; 112 const int STYLED_LABEL_SECURITY_DETAILS = 1338;
113 const int BUTTON_SITE_SETTINGS = 1338; 113 const int STYLED_LABEL_RESET_CERTIFICATE_DECISIONS = 1339;
114 const int LINK_COOKIE_DIALOG = 1340;
115 const int LINK_SITE_SETTINGS = 1341;
114 116
115 } // namespace 117 } // namespace
116 118
117 // |PopupHeaderView| is the UI element (view) that represents the header of the 119 // |PopupHeaderView| is the UI element (view) that represents the header of the
118 // |WebsiteSettingsPopupView|. The header shows the status of the site's 120 // |WebsiteSettingsPopupView|. The header shows the status of the site's
119 // identity check and the name of the site's identity. 121 // identity check and the name of the site's identity.
120 class PopupHeaderView : public views::View { 122 class PopupHeaderView : public views::View {
121 public: 123 public:
122 explicit PopupHeaderView(views::ButtonListener* button_listener, 124 explicit PopupHeaderView(views::ButtonListener* button_listener,
123 views::StyledLabelListener* styled_label_listener); 125 views::StyledLabelListener* styled_label_listener);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 220
219 layout->StartRow(0, label_column); 221 layout->StartRow(0, label_column);
220 const gfx::FontList& font_list = rb.GetFontListWithDelta(1); 222 const gfx::FontList& font_list = rb.GetFontListWithDelta(1);
221 summary_label_ = new views::Label(base::string16(), font_list); 223 summary_label_ = new views::Label(base::string16(), font_list);
222 summary_label_->SetMultiLine(true); 224 summary_label_->SetMultiLine(true);
223 summary_label_->SetBorder(views::Border::CreateEmptyBorder( 225 summary_label_->SetBorder(views::Border::CreateEmptyBorder(
224 kHeaderPaddingTop - kHeaderPaddingForCloseButton, 0, 0, 0)); 226 kHeaderPaddingTop - kHeaderPaddingForCloseButton, 0, 0, 0));
225 layout->AddView(summary_label_, 1, 1, views::GridLayout::LEADING, 227 layout->AddView(summary_label_, 1, 1, views::GridLayout::LEADING,
226 views::GridLayout::TRAILING); 228 views::GridLayout::TRAILING);
227 views::ImageButton* close_button = new views::ImageButton(button_listener); 229 views::ImageButton* close_button = new views::ImageButton(button_listener);
230 close_button->set_id(BUTTON_CLOSE);
228 close_button->SetImage(views::CustomButton::STATE_NORMAL, 231 close_button->SetImage(views::CustomButton::STATE_NORMAL,
229 rb.GetImageNamed(IDR_CLOSE_2).ToImageSkia()); 232 rb.GetImageNamed(IDR_CLOSE_2).ToImageSkia());
230 close_button->SetImage(views::CustomButton::STATE_HOVERED, 233 close_button->SetImage(views::CustomButton::STATE_HOVERED,
231 rb.GetImageNamed(IDR_CLOSE_2_H).ToImageSkia()); 234 rb.GetImageNamed(IDR_CLOSE_2_H).ToImageSkia());
232 close_button->SetImage(views::CustomButton::STATE_PRESSED, 235 close_button->SetImage(views::CustomButton::STATE_PRESSED,
233 rb.GetImageNamed(IDR_CLOSE_2_P).ToImageSkia()); 236 rb.GetImageNamed(IDR_CLOSE_2_P).ToImageSkia());
234 layout->AddView(close_button, 1, 1, views::GridLayout::TRAILING, 237 layout->AddView(close_button, 1, 1, views::GridLayout::TRAILING,
235 views::GridLayout::LEADING); 238 views::GridLayout::LEADING);
236 239
237 layout->AddPaddingRow(0, kHeaderLabelSpacing); 240 layout->AddPaddingRow(0, kHeaderLabelSpacing);
238 241
239 const int label_column_status = 1; 242 const int label_column_status = 1;
240 views::ColumnSet* column_set_status = 243 views::ColumnSet* column_set_status =
241 layout->AddColumnSet(label_column_status); 244 layout->AddColumnSet(label_column_status);
242 column_set_status->AddPaddingColumn(0, kSectionPaddingHorizontal); 245 column_set_status->AddPaddingColumn(0, kSectionPaddingHorizontal);
243 column_set_status->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 246 column_set_status->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
244 1, views::GridLayout::USE_PREF, 0, 0); 247 1, views::GridLayout::USE_PREF, 0, 0);
245 column_set_status->AddPaddingColumn(0, kSectionPaddingHorizontal); 248 column_set_status->AddPaddingColumn(0, kSectionPaddingHorizontal);
246 249
247 layout->AddPaddingRow(0, kHeaderLabelSpacing); 250 layout->AddPaddingRow(0, kHeaderLabelSpacing);
248 251
249 layout->StartRow(0, label_column_status); 252 layout->StartRow(0, label_column_status);
250 details_label_ = 253 details_label_ =
251 new views::StyledLabel(base::string16(), styled_label_listener); 254 new views::StyledLabel(base::string16(), styled_label_listener);
255 details_label_->set_id(STYLED_LABEL_SECURITY_DETAILS);
252 layout->AddView(details_label_, 1, 1, views::GridLayout::FILL, 256 layout->AddView(details_label_, 1, 1, views::GridLayout::FILL,
253 views::GridLayout::LEADING); 257 views::GridLayout::LEADING);
254 258
255 layout->StartRow(0, label_column_status); 259 layout->StartRow(0, label_column_status);
256 reset_decisions_label_container_ = new views::View(); 260 reset_decisions_label_container_ = new views::View();
257 reset_decisions_label_container_->SetLayoutManager( 261 reset_decisions_label_container_->SetLayoutManager(
258 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); 262 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
259 layout->AddView(reset_decisions_label_container_, 1, 1, 263 layout->AddView(reset_decisions_label_container_, 1, 1,
260 views::GridLayout::FILL, views::GridLayout::LEADING); 264 views::GridLayout::FILL, views::GridLayout::LEADING);
261 265
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 subst.push_back( 306 subst.push_back(
303 l10n_util::GetStringUTF16(IDS_PAGEINFO_INVALID_CERTIFICATE_DESCRIPTION)); 307 l10n_util::GetStringUTF16(IDS_PAGEINFO_INVALID_CERTIFICATE_DESCRIPTION));
304 subst.push_back(l10n_util::GetStringUTF16( 308 subst.push_back(l10n_util::GetStringUTF16(
305 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON)); 309 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON));
306 310
307 std::vector<size_t> offsets; 311 std::vector<size_t> offsets;
308 312
309 base::string16 text = base::ReplaceStringPlaceholders( 313 base::string16 text = base::ReplaceStringPlaceholders(
310 base::ASCIIToUTF16("$1 $2"), subst, &offsets); 314 base::ASCIIToUTF16("$1 $2"), subst, &offsets);
311 reset_decisions_label_ = new views::StyledLabel(text, styled_label_listener_); 315 reset_decisions_label_ = new views::StyledLabel(text, styled_label_listener_);
316 reset_decisions_label_->set_id(STYLED_LABEL_RESET_CERTIFICATE_DECISIONS);
312 gfx::Range link_range(offsets[1], text.length()); 317 gfx::Range link_range(offsets[1], text.length());
313 318
314 views::StyledLabel::RangeStyleInfo link_style = 319 views::StyledLabel::RangeStyleInfo link_style =
315 views::StyledLabel::RangeStyleInfo::CreateForLink(); 320 views::StyledLabel::RangeStyleInfo::CreateForLink();
316 if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) 321 if (!ui::MaterialDesignController::IsSecondaryUiMaterial())
317 link_style.font_style |= gfx::Font::FontStyle::UNDERLINE; 322 link_style.font_style |= gfx::Font::FontStyle::UNDERLINE;
318 link_style.disable_line_wrapping = false; 323 link_style.disable_line_wrapping = false;
319 324
320 reset_decisions_label_->AddStyleRange(link_range, link_style); 325 reset_decisions_label_->AddStyleRange(link_range, link_style);
326 // Fit the styled label to occupy available width.
327 reset_decisions_label_->SizeToFit(0);
321 reset_decisions_label_container_->AddChildView(reset_decisions_label_); 328 reset_decisions_label_container_->AddChildView(reset_decisions_label_);
322 329
323 // Now that it contains a label, the container needs padding at the top. 330 // Now that it contains a label, the container needs padding at the top.
324 reset_decisions_label_container_->SetBorder( 331 reset_decisions_label_container_->SetBorder(
325 views::Border::CreateEmptyBorder(8, 0, 0, 0)); 332 views::Border::CreateEmptyBorder(8, 0, 0, 0));
333
334 InvalidateLayout();
326 } 335 }
327 336
328 //////////////////////////////////////////////////////////////////////////////// 337 ////////////////////////////////////////////////////////////////////////////////
329 // InternalPageInfoPopupView 338 // InternalPageInfoPopupView
330 //////////////////////////////////////////////////////////////////////////////// 339 ////////////////////////////////////////////////////////////////////////////////
331 340
332 InternalPageInfoPopupView::InternalPageInfoPopupView( 341 InternalPageInfoPopupView::InternalPageInfoPopupView(
333 views::View* anchor_view, 342 views::View* anchor_view,
334 gfx::NativeView parent_window, 343 gfx::NativeView parent_window,
335 const GURL& url) 344 const GURL& url)
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 is_popup_showing = false; 530 is_popup_showing = false;
522 presenter_->OnUIClosing(); 531 presenter_->OnUIClosing();
523 } 532 }
524 533
525 int WebsiteSettingsPopupView::GetDialogButtons() const { 534 int WebsiteSettingsPopupView::GetDialogButtons() const {
526 return ui::DIALOG_BUTTON_NONE; 535 return ui::DIALOG_BUTTON_NONE;
527 } 536 }
528 537
529 void WebsiteSettingsPopupView::ButtonPressed(views::Button* button, 538 void WebsiteSettingsPopupView::ButtonPressed(views::Button* button,
530 const ui::Event& event) { 539 const ui::Event& event) {
531 switch (button->id()) { 540 DCHECK_EQ(BUTTON_CLOSE, button->id());
532 case BUTTON_RESET_CERTIFICATE_DECISIONS: 541 GetWidget()->Close();
533 presenter_->OnRevokeSSLErrorBypassButtonPressed();
534 GetWidget()->Close();
535 break;
536 case BUTTON_SITE_SETTINGS:
537 // TODO(palmer): This opens the general Content Settings pane, which is OK
538 // for now. But on Android, it opens a page specific to a given origin
539 // that shows all of the settings for that origin. If/when that's
540 // available on desktop we should link to that here, too.
541 web_contents()->OpenURL(content::OpenURLParams(
542 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(),
543 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
544 false));
545 presenter_->RecordWebsiteSettingsAction(
546 WebsiteSettings::WEBSITE_SETTINGS_SITE_SETTINGS_OPENED);
547 break;
548 default:
549 NOTREACHED();
550 }
551 } 542 }
552 543
553 void WebsiteSettingsPopupView::LinkClicked(views::Link* source, 544 void WebsiteSettingsPopupView::LinkClicked(views::Link* source,
554 int event_flags) { 545 int event_flags) {
555 // The popup closes automatically when the collected cookies dialog or the 546 // The popup closes automatically when the collected cookies dialog or the
556 // certificate viewer opens. So delay handling of the link clicked to avoid 547 // certificate viewer opens. So delay handling of the link clicked to avoid
557 // a crash in the base class which needs to complete the mouse event handling. 548 // a crash in the base class which needs to complete the mouse event handling.
558 content::BrowserThread::PostTask( 549 content::BrowserThread::PostTask(
559 content::BrowserThread::UI, FROM_HERE, 550 content::BrowserThread::UI, FROM_HERE,
560 base::Bind(&WebsiteSettingsPopupView::HandleLinkClickedAsync, 551 base::Bind(&WebsiteSettingsPopupView::HandleLinkClickedAsync,
(...skipping 26 matching lines...) Expand all
587 // cookies. 578 // cookies.
588 DCHECK_EQ(cookie_info_list.size(), 2u); 579 DCHECK_EQ(cookie_info_list.size(), 2u);
589 int total_allowed = 0; 580 int total_allowed = 0;
590 for (const auto& i : cookie_info_list) 581 for (const auto& i : cookie_info_list)
591 total_allowed += i.allowed; 582 total_allowed += i.allowed;
592 base::string16 label_text = l10n_util::GetPluralStringFUTF16( 583 base::string16 label_text = l10n_util::GetPluralStringFUTF16(
593 IDS_WEBSITE_SETTINGS_NUM_COOKIES, total_allowed); 584 IDS_WEBSITE_SETTINGS_NUM_COOKIES, total_allowed);
594 585
595 if (!cookie_dialog_link_) { 586 if (!cookie_dialog_link_) {
596 cookie_dialog_link_ = new views::Link(label_text); 587 cookie_dialog_link_ = new views::Link(label_text);
588 cookie_dialog_link_->set_id(LINK_COOKIE_DIALOG);
597 cookie_dialog_link_->set_listener(this); 589 cookie_dialog_link_->set_listener(this);
598 } else { 590 } else {
599 cookie_dialog_link_->SetText(label_text); 591 cookie_dialog_link_->SetText(label_text);
600 } 592 }
601 593
602 views::GridLayout* layout = 594 views::GridLayout* layout =
603 static_cast<views::GridLayout*>(cookies_view_->GetLayoutManager()); 595 static_cast<views::GridLayout*>(cookies_view_->GetLayoutManager());
604 if (!layout) { 596 if (!layout) {
605 layout = new views::GridLayout(cookies_view_); 597 layout = new views::GridLayout(cookies_view_);
606 cookies_view_->SetLayoutManager(layout); 598 cookies_view_->SetLayoutManager(layout);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 layout->AddView(object_view, 1, 1, views::GridLayout::LEADING, 690 layout->AddView(object_view, 1, 1, views::GridLayout::LEADING,
699 views::GridLayout::CENTER); 691 views::GridLayout::CENTER);
700 layout->AddPaddingRow(1, kPermissionsVerticalSpacing); 692 layout->AddPaddingRow(1, kPermissionsVerticalSpacing);
701 } 693 }
702 694
703 layout->Layout(permissions_view_); 695 layout->Layout(permissions_view_);
704 696
705 // Add site settings link. 697 // Add site settings link.
706 views::Link* site_settings_link = new views::Link( 698 views::Link* site_settings_link = new views::Link(
707 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_SETTINGS_LINK)); 699 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_SETTINGS_LINK));
700 site_settings_link->set_id(LINK_SITE_SETTINGS);
708 site_settings_link->set_listener(this); 701 site_settings_link->set_listener(this);
709 views::View* link_section = new views::View(); 702 views::View* link_section = new views::View();
710 const int kLinkMarginTop = 4; 703 const int kLinkMarginTop = 4;
711 link_section->SetLayoutManager(new views::BoxLayout( 704 link_section->SetLayoutManager(new views::BoxLayout(
712 views::BoxLayout::kHorizontal, 0, kLinkMarginTop, 0)); 705 views::BoxLayout::kHorizontal, 0, kLinkMarginTop, 0));
713 link_section->AddChildView(site_settings_link); 706 link_section->AddChildView(site_settings_link);
714 site_settings_view_->AddChildView(link_section); 707 site_settings_view_->AddChildView(link_section);
715 708
716 SizeToContents(); 709 SizeToContents();
717 } 710 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 gfx::Insets(0, kSectionPaddingHorizontal)); 746 gfx::Insets(0, kSectionPaddingHorizontal));
754 747
755 // Add cookies view. 748 // Add cookies view.
756 cookies_view_ = new views::View(); 749 cookies_view_ = new views::View();
757 site_settings_view->AddChildView(cookies_view_); 750 site_settings_view->AddChildView(cookies_view_);
758 751
759 return site_settings_view; 752 return site_settings_view;
760 } 753 }
761 754
762 void WebsiteSettingsPopupView::HandleLinkClickedAsync(views::Link* source) { 755 void WebsiteSettingsPopupView::HandleLinkClickedAsync(views::Link* source) {
756 // Both switch cases require accessing web_contents(), so we check it here.
763 if (web_contents() == nullptr || web_contents()->IsBeingDestroyed()) 757 if (web_contents() == nullptr || web_contents()->IsBeingDestroyed())
764 return; 758 return;
765 DCHECK_EQ(source, cookie_dialog_link_); 759 switch (source->id()) {
766 // Count how often the Collected Cookies dialog is opened. 760 case LINK_SITE_SETTINGS:
767 presenter_->RecordWebsiteSettingsAction( 761 // TODO(crbug.com/655876): This opens the general Content Settings pane,
768 WebsiteSettings::WEBSITE_SETTINGS_COOKIES_DIALOG_OPENED); 762 // which is OK for now. But on Android, it opens a page specific to a
769 new CollectedCookiesViews(web_contents()); 763 // given origin that shows all of the settings for that origin. If/when
764 // that's available on desktop we should link to that here, too.
765 web_contents()->OpenURL(content::OpenURLParams(
766 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(),
767 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
768 false));
769 presenter_->RecordWebsiteSettingsAction(
770 WebsiteSettings::WEBSITE_SETTINGS_SITE_SETTINGS_OPENED);
771 break;
772 case LINK_COOKIE_DIALOG:
773 // Count how often the Collected Cookies dialog is opened.
774 presenter_->RecordWebsiteSettingsAction(
775 WebsiteSettings::WEBSITE_SETTINGS_COOKIES_DIALOG_OPENED);
776 new CollectedCookiesViews(web_contents());
777 break;
778 default:
779 NOTREACHED();
780 }
770 } 781 }
771 782
772 void WebsiteSettingsPopupView::StyledLabelLinkClicked(views::StyledLabel* label, 783 void WebsiteSettingsPopupView::StyledLabelLinkClicked(views::StyledLabel* label,
773 const gfx::Range& range, 784 const gfx::Range& range,
774 int event_flags) { 785 int event_flags) {
775 presenter_->RecordWebsiteSettingsAction( 786 switch (label->id()) {
776 WebsiteSettings::WEBSITE_SETTINGS_SECURITY_DETAILS_OPENED); 787 case STYLED_LABEL_SECURITY_DETAILS:
788 presenter_->RecordWebsiteSettingsAction(
789 WebsiteSettings::WEBSITE_SETTINGS_SECURITY_DETAILS_OPENED);
777 790
778 if (is_devtools_disabled_) { 791 if (is_devtools_disabled_) {
779 DCHECK(certificate_); 792 DCHECK(certificate_);
780 gfx::NativeWindow parent = 793 gfx::NativeWindow parent =
781 anchor_widget() ? anchor_widget()->GetNativeWindow() : nullptr; 794 anchor_widget() ? anchor_widget()->GetNativeWindow() : nullptr;
782 presenter_->RecordWebsiteSettingsAction( 795 presenter_->RecordWebsiteSettingsAction(
783 WebsiteSettings::WEBSITE_SETTINGS_CERTIFICATE_DIALOG_OPENED); 796 WebsiteSettings::WEBSITE_SETTINGS_CERTIFICATE_DIALOG_OPENED);
784 ShowCertificateViewer(web_contents(), parent, certificate_.get()); 797 ShowCertificateViewer(web_contents(), parent, certificate_.get());
785 } else { 798 } else {
786 DevToolsWindow::OpenDevToolsWindow( 799 DevToolsWindow::OpenDevToolsWindow(
787 web_contents(), DevToolsToggleAction::ShowSecurityPanel()); 800 web_contents(), DevToolsToggleAction::ShowSecurityPanel());
801 }
802 break;
803 case STYLED_LABEL_RESET_CERTIFICATE_DECISIONS:
804 presenter_->OnRevokeSSLErrorBypassButtonPressed();
805 GetWidget()->Close();
806 break;
807 default:
808 NOTREACHED();
788 } 809 }
789 } 810 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698