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/website_settings/website_settings_popup_view.h
" | 5 #include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h
" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/certificate_viewer.h" | 11 #include "chrome/browser/certificate_viewer.h" |
12 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" |
14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_dialogs.h" | 16 #include "chrome/browser/ui/browser_dialogs.h" |
16 #include "chrome/browser/ui/views/collected_cookies_views.h" | 17 #include "chrome/browser/ui/views/collected_cookies_views.h" |
17 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h" | 18 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h" |
18 #include "chrome/browser/ui/website_settings/website_settings.h" | 19 #include "chrome/browser/ui/website_settings/website_settings.h" |
19 #include "chrome/browser/ui/website_settings/website_settings_utils.h" | 20 #include "chrome/browser/ui/website_settings/website_settings_utils.h" |
20 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
21 #include "components/content_settings/core/common/content_settings_types.h" | 22 #include "components/content_settings/core/common/content_settings_types.h" |
22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/cert_store.h" | 24 #include "content/public/browser/cert_store.h" |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 browser_(browser), | 304 browser_(browser), |
304 header_(NULL), | 305 header_(NULL), |
305 tabbed_pane_(NULL), | 306 tabbed_pane_(NULL), |
306 site_data_content_(NULL), | 307 site_data_content_(NULL), |
307 cookie_dialog_link_(NULL), | 308 cookie_dialog_link_(NULL), |
308 permissions_content_(NULL), | 309 permissions_content_(NULL), |
309 connection_tab_(NULL), | 310 connection_tab_(NULL), |
310 identity_info_content_(NULL), | 311 identity_info_content_(NULL), |
311 certificate_dialog_link_(NULL), | 312 certificate_dialog_link_(NULL), |
312 signed_certificate_timestamps_link_(NULL), | 313 signed_certificate_timestamps_link_(NULL), |
| 314 reset_decisions_button_(NULL), |
313 cert_id_(0), | 315 cert_id_(0), |
314 help_center_link_(NULL), | 316 help_center_link_(NULL), |
315 connection_info_content_(NULL), | 317 connection_info_content_(NULL), |
316 page_info_content_(NULL), | 318 page_info_content_(NULL), |
317 weak_factory_(this) { | 319 weak_factory_(this) { |
318 // Compensate for built-in vertical padding in the anchor view's image. | 320 // Compensate for built-in vertical padding in the anchor view's image. |
319 set_anchor_view_insets(gfx::Insets(kLocationIconVerticalMargin, 0, | 321 set_anchor_view_insets(gfx::Insets(kLocationIconVerticalMargin, 0, |
320 kLocationIconVerticalMargin, 0)); | 322 kLocationIconVerticalMargin, 0)); |
321 | 323 |
322 views::GridLayout* layout = new views::GridLayout(this); | 324 views::GridLayout* layout = new views::GridLayout(this); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 void WebsiteSettingsPopupView::OnPermissionChanged( | 373 void WebsiteSettingsPopupView::OnPermissionChanged( |
372 const WebsiteSettingsUI::PermissionInfo& permission) { | 374 const WebsiteSettingsUI::PermissionInfo& permission) { |
373 presenter_->OnSitePermissionChanged(permission.type, permission.setting); | 375 presenter_->OnSitePermissionChanged(permission.type, permission.setting); |
374 } | 376 } |
375 | 377 |
376 void WebsiteSettingsPopupView::OnWidgetDestroying(views::Widget* widget) { | 378 void WebsiteSettingsPopupView::OnWidgetDestroying(views::Widget* widget) { |
377 is_popup_showing = false; | 379 is_popup_showing = false; |
378 presenter_->OnUIClosing(); | 380 presenter_->OnUIClosing(); |
379 } | 381 } |
380 | 382 |
381 void WebsiteSettingsPopupView::ButtonPressed( | 383 void WebsiteSettingsPopupView::ButtonPressed(views::Button* button, |
382 views::Button* button, | 384 const ui::Event& event) { |
383 const ui::Event& event) { | 385 if (button == reset_decisions_button_) { |
384 GetWidget()->Close(); | 386 ChromeSSLHostStateDelegate* delegate = |
| 387 presenter_->chrome_ssl_host_state_delegate(); |
| 388 DCHECK(delegate); |
| 389 delegate->RevokeUserDecisionsHard(presenter_->site_url().host()); |
| 390 GetWidget()->Close(); |
| 391 } |
385 } | 392 } |
386 | 393 |
387 void WebsiteSettingsPopupView::LinkClicked(views::Link* source, | 394 void WebsiteSettingsPopupView::LinkClicked(views::Link* source, |
388 int event_flags) { | 395 int event_flags) { |
389 // The popup closes automatically when the collected cookies dialog or the | 396 if (source == cookie_dialog_link_) { |
390 // certificate viewer opens. So delay handling of the link clicked to avoid | 397 // Count how often the Collected Cookies dialog is opened. |
391 // a crash in the base class which needs to complete the mouse event handling. | 398 content::RecordAction( |
392 content::BrowserThread::PostTask( | 399 base::UserMetricsAction("WebsiteSettings_CookiesDialogOpened")); |
393 content::BrowserThread::UI, FROM_HERE, | 400 new CollectedCookiesViews(web_contents_); |
394 base::Bind(&WebsiteSettingsPopupView::HandleLinkClickedAsync, | 401 } else if (source == certificate_dialog_link_) { |
395 weak_factory_.GetWeakPtr(), source)); | 402 gfx::NativeWindow parent = GetAnchorView() ? |
| 403 GetAnchorView()->GetWidget()->GetNativeWindow() : NULL; |
| 404 ShowCertificateViewerByID(web_contents_, parent, cert_id_); |
| 405 } else if (source == signed_certificate_timestamps_link_) { |
| 406 chrome::ShowSignedCertificateTimestampsViewer( |
| 407 web_contents_, signed_certificate_timestamp_ids_); |
| 408 } else if (source == help_center_link_) { |
| 409 browser_->OpenURL( |
| 410 content::OpenURLParams(GURL(chrome::kPageInfoHelpCenterURL), |
| 411 content::Referrer(), |
| 412 NEW_FOREGROUND_TAB, |
| 413 content::PAGE_TRANSITION_LINK, |
| 414 false)); |
| 415 } |
396 } | 416 } |
397 | 417 |
398 void WebsiteSettingsPopupView::TabSelectedAt(int index) { | 418 void WebsiteSettingsPopupView::TabSelectedAt(int index) { |
399 tabbed_pane_->GetSelectedTab()->Layout(); | 419 tabbed_pane_->GetSelectedTab()->Layout(); |
400 SizeToContents(); | 420 SizeToContents(); |
401 } | 421 } |
402 | 422 |
403 gfx::Size WebsiteSettingsPopupView::GetPreferredSize() const { | 423 gfx::Size WebsiteSettingsPopupView::GetPreferredSize() const { |
404 if (header_ == NULL && tabbed_pane_ == NULL) | 424 if (header_ == NULL && tabbed_pane_ == NULL) |
405 return views::View::GetPreferredSize(); | 425 return views::View::GetPreferredSize(); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 l10n_util::GetStringUTF16(IDS_PAGEINFO_CERT_INFO_BUTTON)); | 569 l10n_util::GetStringUTF16(IDS_PAGEINFO_CERT_INFO_BUTTON)); |
550 certificate_dialog_link_->set_listener(this); | 570 certificate_dialog_link_->set_listener(this); |
551 | 571 |
552 if (!signed_certificate_timestamp_ids_.empty()) { | 572 if (!signed_certificate_timestamp_ids_.empty()) { |
553 signed_certificate_timestamps_link_ = | 573 signed_certificate_timestamps_link_ = |
554 new views::Link(l10n_util::GetStringUTF16( | 574 new views::Link(l10n_util::GetStringUTF16( |
555 IDS_PAGEINFO_CERT_TRANSPARENCY_INFO_BUTTON)); | 575 IDS_PAGEINFO_CERT_TRANSPARENCY_INFO_BUTTON)); |
556 signed_certificate_timestamps_link_->set_listener(this); | 576 signed_certificate_timestamps_link_->set_listener(this); |
557 } | 577 } |
558 | 578 |
| 579 if (identity_info.show_ssl_decision_revoke_button) { |
| 580 reset_decisions_button_ = new views::LabelButton( |
| 581 this, |
| 582 l10n_util::GetStringUTF16( |
| 583 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON)); |
| 584 reset_decisions_button_->SetStyle(views::Button::STYLE_BUTTON); |
| 585 } |
| 586 |
559 headline = base::UTF8ToUTF16(identity_info.site_identity); | 587 headline = base::UTF8ToUTF16(identity_info.site_identity); |
560 } | 588 } |
561 ResetConnectionSection( | 589 ResetConnectionSection( |
562 identity_info_content_, | 590 identity_info_content_, |
563 WebsiteSettingsUI::GetIdentityIcon(identity_info.identity_status), | 591 WebsiteSettingsUI::GetIdentityIcon(identity_info.identity_status), |
564 base::string16(), // The identity section has no headline. | 592 base::string16(), // The identity section has no headline. |
565 base::UTF8ToUTF16(identity_info.identity_status_description), | 593 base::UTF8ToUTF16(identity_info.identity_status_description), |
566 certificate_dialog_link_, | 594 certificate_dialog_link_, |
567 signed_certificate_timestamps_link_); | 595 signed_certificate_timestamps_link_, |
| 596 reset_decisions_button_); |
568 | 597 |
569 ResetConnectionSection( | 598 ResetConnectionSection( |
570 connection_info_content_, | 599 connection_info_content_, |
571 WebsiteSettingsUI::GetConnectionIcon(identity_info.connection_status), | 600 WebsiteSettingsUI::GetConnectionIcon(identity_info.connection_status), |
572 base::string16(), // The connection section has no headline. | 601 base::string16(), // The connection section has no headline. |
573 base::UTF8ToUTF16(identity_info.connection_status_description), | 602 base::UTF8ToUTF16(identity_info.connection_status_description), |
574 NULL, | 603 NULL, |
| 604 NULL, |
575 NULL); | 605 NULL); |
576 | 606 |
577 connection_tab_->InvalidateLayout(); | 607 connection_tab_->InvalidateLayout(); |
578 Layout(); | 608 Layout(); |
579 SizeToContents(); | 609 SizeToContents(); |
580 } | 610 } |
581 | 611 |
582 void WebsiteSettingsPopupView::SetFirstVisit( | 612 void WebsiteSettingsPopupView::SetFirstVisit( |
583 const base::string16& first_visit) { | 613 const base::string16& first_visit) { |
584 ResetConnectionSection( | 614 ResetConnectionSection( |
585 page_info_content_, | 615 page_info_content_, |
586 WebsiteSettingsUI::GetFirstVisitIcon(first_visit), | 616 WebsiteSettingsUI::GetFirstVisitIcon(first_visit), |
587 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_INFO_TITLE), | 617 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_INFO_TITLE), |
588 first_visit, | 618 first_visit, |
589 NULL, | 619 NULL, |
| 620 NULL, |
590 NULL); | 621 NULL); |
591 connection_tab_->InvalidateLayout(); | 622 connection_tab_->InvalidateLayout(); |
592 Layout(); | 623 Layout(); |
593 SizeToContents(); | 624 SizeToContents(); |
594 } | 625 } |
595 | 626 |
596 void WebsiteSettingsPopupView::SetSelectedTab(TabId tab_id) { | 627 void WebsiteSettingsPopupView::SetSelectedTab(TabId tab_id) { |
597 tabbed_pane_->SelectTabAt(tab_id); | 628 tabbed_pane_->SelectTabAt(tab_id); |
598 } | 629 } |
599 | 630 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 layout->AddPaddingRow(1, kPermissionsSectionPaddingBottom); | 729 layout->AddPaddingRow(1, kPermissionsSectionPaddingBottom); |
699 return container; | 730 return container; |
700 } | 731 } |
701 | 732 |
702 void WebsiteSettingsPopupView::ResetConnectionSection( | 733 void WebsiteSettingsPopupView::ResetConnectionSection( |
703 views::View* section_container, | 734 views::View* section_container, |
704 const gfx::Image& icon, | 735 const gfx::Image& icon, |
705 const base::string16& headline, | 736 const base::string16& headline, |
706 const base::string16& text, | 737 const base::string16& text, |
707 views::Link* link, | 738 views::Link* link, |
708 views::Link* secondary_link) { | 739 views::Link* secondary_link, |
| 740 views::LabelButton* reset_decisions_button) { |
709 section_container->RemoveAllChildViews(true); | 741 section_container->RemoveAllChildViews(true); |
710 | 742 |
711 views::GridLayout* layout = new views::GridLayout(section_container); | 743 views::GridLayout* layout = new views::GridLayout(section_container); |
712 section_container->SetLayoutManager(layout); | 744 section_container->SetLayoutManager(layout); |
713 views::ColumnSet* column_set = layout->AddColumnSet(0); | 745 views::ColumnSet* column_set = layout->AddColumnSet(0); |
714 column_set->AddPaddingColumn(0, kConnectionSectionPaddingLeft); | 746 column_set->AddPaddingColumn(0, kConnectionSectionPaddingLeft); |
715 column_set->AddColumn(views::GridLayout::LEADING, | 747 column_set->AddColumn(views::GridLayout::LEADING, |
716 views::GridLayout::LEADING, | 748 views::GridLayout::LEADING, |
717 0, | 749 0, |
718 views::GridLayout::USE_PREF, | 750 views::GridLayout::USE_PREF, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 if (link) { | 803 if (link) { |
772 content_layout->StartRow(1, 0); | 804 content_layout->StartRow(1, 0); |
773 content_layout->AddView(link); | 805 content_layout->AddView(link); |
774 } | 806 } |
775 | 807 |
776 if (secondary_link) { | 808 if (secondary_link) { |
777 content_layout->StartRow(1, 0); | 809 content_layout->StartRow(1, 0); |
778 content_layout->AddView(secondary_link); | 810 content_layout->AddView(secondary_link); |
779 } | 811 } |
780 | 812 |
| 813 if (reset_decisions_button) { |
| 814 content_layout->StartRow(1, 0); |
| 815 content_layout->AddView(reset_decisions_button); |
| 816 } |
| 817 |
781 layout->AddView(content_pane, 1, 1, views::GridLayout::LEADING, | 818 layout->AddView(content_pane, 1, 1, views::GridLayout::LEADING, |
782 views::GridLayout::LEADING); | 819 views::GridLayout::LEADING); |
783 layout->AddPaddingRow(0, kConnectionSectionPaddingBottom); | 820 layout->AddPaddingRow(0, kConnectionSectionPaddingBottom); |
784 } | 821 } |
785 | |
786 // Used to asynchronously handle clicks since these calls may cause the | |
787 // destruction of the settings view and the base class window still | |
788 // needs to be alive to finish handling the mouse click. | |
789 void WebsiteSettingsPopupView::HandleLinkClickedAsync(views::Link* source) { | |
790 if (source == cookie_dialog_link_) { | |
791 // Count how often the Collected Cookies dialog is opened. | |
792 content::RecordAction( | |
793 base::UserMetricsAction("WebsiteSettings_CookiesDialogOpened")); | |
794 new CollectedCookiesViews(web_contents_); | |
795 } else if (source == certificate_dialog_link_) { | |
796 gfx::NativeWindow parent = | |
797 GetAnchorView() ? GetAnchorView()->GetWidget()->GetNativeWindow() : | |
798 NULL; | |
799 ShowCertificateViewerByID(web_contents_, parent, cert_id_); | |
800 } else if (source == signed_certificate_timestamps_link_) { | |
801 chrome::ShowSignedCertificateTimestampsViewer( | |
802 web_contents_, signed_certificate_timestamp_ids_); | |
803 } else if (source == help_center_link_) { | |
804 browser_->OpenURL(content::OpenURLParams( | |
805 GURL(chrome::kPageInfoHelpCenterURL), | |
806 content::Referrer(), | |
807 NEW_FOREGROUND_TAB, | |
808 content::PAGE_TRANSITION_LINK, | |
809 false)); | |
810 } | |
811 } | |
OLD | NEW |