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

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

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