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/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_dialogs.h" | 15 #include "chrome/browser/ui/browser_dialogs.h" |
16 #include "chrome/browser/ui/views/collected_cookies_views.h" | 16 #include "chrome/browser/ui/views/collected_cookies_views.h" |
17 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h" | 17 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h" |
18 #include "chrome/browser/ui/website_settings/website_settings.h" | 18 #include "chrome/browser/ui/website_settings/website_settings.h" |
19 #include "chrome/browser/ui/website_settings/website_settings_utils.h" | 19 #include "chrome/browser/ui/website_settings/website_settings_utils.h" |
20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
21 #include "components/content_settings/core/common/content_settings_types.h" | 21 #include "components/content_settings/core/common/content_settings_types.h" |
22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/cert_store.h" | 23 #include "content/public/browser/cert_store.h" |
| 24 #include "content/public/browser/ssl_host_state.h" |
24 #include "content/public/browser/user_metrics.h" | 25 #include "content/public/browser/user_metrics.h" |
25 #include "grit/chromium_strings.h" | 26 #include "grit/chromium_strings.h" |
26 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
27 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" |
28 #include "grit/ui_resources.h" | 29 #include "grit/ui_resources.h" |
29 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
30 #include "ui/base/models/simple_menu_model.h" | 31 #include "ui/base/models/simple_menu_model.h" |
31 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
32 #include "ui/gfx/canvas.h" | 33 #include "ui/gfx/canvas.h" |
33 #include "ui/gfx/font_list.h" | 34 #include "ui/gfx/font_list.h" |
(...skipping 269 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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( |
382 views::Button* button, | 384 views::Button* button, |
383 const ui::Event& event) { | 385 const ui::Event& event) { |
384 GetWidget()->Close(); | |
385 } | 386 } |
386 | 387 |
387 void WebsiteSettingsPopupView::LinkClicked(views::Link* source, | 388 void WebsiteSettingsPopupView::LinkClicked(views::Link* source, |
388 int event_flags) { | 389 int event_flags) { |
389 // The popup closes automatically when the collected cookies dialog or the | 390 // The popup closes automatically when the collected cookies dialog or the |
390 // certificate viewer opens. So delay handling of the link clicked to avoid | 391 // certificate viewer opens. So delay handling of the link clicked to avoid |
391 // a crash in the base class which needs to complete the mouse event handling. | 392 // a crash in the base class which needs to complete the mouse event handling. |
392 content::BrowserThread::PostTask( | 393 content::BrowserThread::PostTask( |
393 content::BrowserThread::UI, FROM_HERE, | 394 content::BrowserThread::UI, FROM_HERE, |
394 base::Bind(&WebsiteSettingsPopupView::HandleLinkClickedAsync, | 395 base::Bind(&WebsiteSettingsPopupView::HandleLinkClickedAsync, |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 l10n_util::GetStringUTF16(IDS_PAGEINFO_CERT_INFO_BUTTON)); | 550 l10n_util::GetStringUTF16(IDS_PAGEINFO_CERT_INFO_BUTTON)); |
550 certificate_dialog_link_->set_listener(this); | 551 certificate_dialog_link_->set_listener(this); |
551 | 552 |
552 if (!signed_certificate_timestamp_ids_.empty()) { | 553 if (!signed_certificate_timestamp_ids_.empty()) { |
553 signed_certificate_timestamps_link_ = | 554 signed_certificate_timestamps_link_ = |
554 new views::Link(l10n_util::GetStringUTF16( | 555 new views::Link(l10n_util::GetStringUTF16( |
555 IDS_PAGEINFO_CERT_TRANSPARENCY_INFO_BUTTON)); | 556 IDS_PAGEINFO_CERT_TRANSPARENCY_INFO_BUTTON)); |
556 signed_certificate_timestamps_link_->set_listener(this); | 557 signed_certificate_timestamps_link_->set_listener(this); |
557 } | 558 } |
558 | 559 |
| 560 if (identity_info.certificate_decision_made) { |
| 561 reset_decisions_button_ = new views::Link(l10n_util::GetStringUTF16( |
| 562 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON)); |
| 563 reset_decisions_button_->set_listener(this); |
| 564 } |
| 565 |
559 headline = base::UTF8ToUTF16(identity_info.site_identity); | 566 headline = base::UTF8ToUTF16(identity_info.site_identity); |
560 } | 567 } |
561 ResetConnectionSection( | 568 ResetConnectionSection( |
562 identity_info_content_, | 569 identity_info_content_, |
563 WebsiteSettingsUI::GetIdentityIcon(identity_info.identity_status), | 570 WebsiteSettingsUI::GetIdentityIcon(identity_info.identity_status), |
564 base::string16(), // The identity section has no headline. | 571 base::string16(), // The identity section has no headline. |
565 base::UTF8ToUTF16(identity_info.identity_status_description), | 572 base::UTF8ToUTF16(identity_info.identity_status_description), |
566 certificate_dialog_link_, | 573 certificate_dialog_link_, |
567 signed_certificate_timestamps_link_); | 574 signed_certificate_timestamps_link_, |
| 575 reset_decisions_button_); |
568 | 576 |
569 ResetConnectionSection( | 577 ResetConnectionSection( |
570 connection_info_content_, | 578 connection_info_content_, |
571 WebsiteSettingsUI::GetConnectionIcon(identity_info.connection_status), | 579 WebsiteSettingsUI::GetConnectionIcon(identity_info.connection_status), |
572 base::string16(), // The connection section has no headline. | 580 base::string16(), // The connection section has no headline. |
573 base::UTF8ToUTF16(identity_info.connection_status_description), | 581 base::UTF8ToUTF16(identity_info.connection_status_description), |
574 NULL, | 582 NULL, |
| 583 NULL, |
575 NULL); | 584 NULL); |
576 | 585 |
577 connection_tab_->InvalidateLayout(); | 586 connection_tab_->InvalidateLayout(); |
578 Layout(); | 587 Layout(); |
579 SizeToContents(); | 588 SizeToContents(); |
580 } | 589 } |
581 | 590 |
582 void WebsiteSettingsPopupView::SetFirstVisit( | 591 void WebsiteSettingsPopupView::SetFirstVisit( |
583 const base::string16& first_visit) { | 592 const base::string16& first_visit) { |
584 ResetConnectionSection( | 593 ResetConnectionSection( |
585 page_info_content_, | 594 page_info_content_, |
586 WebsiteSettingsUI::GetFirstVisitIcon(first_visit), | 595 WebsiteSettingsUI::GetFirstVisitIcon(first_visit), |
587 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_INFO_TITLE), | 596 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_INFO_TITLE), |
588 first_visit, | 597 first_visit, |
589 NULL, | 598 NULL, |
| 599 NULL, |
590 NULL); | 600 NULL); |
591 connection_tab_->InvalidateLayout(); | 601 connection_tab_->InvalidateLayout(); |
592 Layout(); | 602 Layout(); |
593 SizeToContents(); | 603 SizeToContents(); |
594 } | 604 } |
595 | 605 |
596 void WebsiteSettingsPopupView::SetSelectedTab(TabId tab_id) { | 606 void WebsiteSettingsPopupView::SetSelectedTab(TabId tab_id) { |
597 tabbed_pane_->SelectTabAt(tab_id); | 607 tabbed_pane_->SelectTabAt(tab_id); |
598 } | 608 } |
599 | 609 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 layout->AddPaddingRow(1, kPermissionsSectionPaddingBottom); | 708 layout->AddPaddingRow(1, kPermissionsSectionPaddingBottom); |
699 return container; | 709 return container; |
700 } | 710 } |
701 | 711 |
702 void WebsiteSettingsPopupView::ResetConnectionSection( | 712 void WebsiteSettingsPopupView::ResetConnectionSection( |
703 views::View* section_container, | 713 views::View* section_container, |
704 const gfx::Image& icon, | 714 const gfx::Image& icon, |
705 const base::string16& headline, | 715 const base::string16& headline, |
706 const base::string16& text, | 716 const base::string16& text, |
707 views::Link* link, | 717 views::Link* link, |
708 views::Link* secondary_link) { | 718 views::Link* secondary_link, |
| 719 views::Link* reset_decisions_button) { |
709 section_container->RemoveAllChildViews(true); | 720 section_container->RemoveAllChildViews(true); |
710 | 721 |
711 views::GridLayout* layout = new views::GridLayout(section_container); | 722 views::GridLayout* layout = new views::GridLayout(section_container); |
712 section_container->SetLayoutManager(layout); | 723 section_container->SetLayoutManager(layout); |
713 views::ColumnSet* column_set = layout->AddColumnSet(0); | 724 views::ColumnSet* column_set = layout->AddColumnSet(0); |
714 column_set->AddPaddingColumn(0, kConnectionSectionPaddingLeft); | 725 column_set->AddPaddingColumn(0, kConnectionSectionPaddingLeft); |
715 column_set->AddColumn(views::GridLayout::LEADING, | 726 column_set->AddColumn(views::GridLayout::LEADING, |
716 views::GridLayout::LEADING, | 727 views::GridLayout::LEADING, |
717 0, | 728 0, |
718 views::GridLayout::USE_PREF, | 729 views::GridLayout::USE_PREF, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 if (link) { | 782 if (link) { |
772 content_layout->StartRow(1, 0); | 783 content_layout->StartRow(1, 0); |
773 content_layout->AddView(link); | 784 content_layout->AddView(link); |
774 } | 785 } |
775 | 786 |
776 if (secondary_link) { | 787 if (secondary_link) { |
777 content_layout->StartRow(1, 0); | 788 content_layout->StartRow(1, 0); |
778 content_layout->AddView(secondary_link); | 789 content_layout->AddView(secondary_link); |
779 } | 790 } |
780 | 791 |
| 792 if (reset_decisions_button) { |
| 793 content_layout->StartRow(1, 0); |
| 794 content_layout->AddView(reset_decisions_button); |
| 795 } |
| 796 |
781 layout->AddView(content_pane, 1, 1, views::GridLayout::LEADING, | 797 layout->AddView(content_pane, 1, 1, views::GridLayout::LEADING, |
782 views::GridLayout::LEADING); | 798 views::GridLayout::LEADING); |
783 layout->AddPaddingRow(0, kConnectionSectionPaddingBottom); | 799 layout->AddPaddingRow(0, kConnectionSectionPaddingBottom); |
784 } | 800 } |
785 | 801 |
786 // Used to asynchronously handle clicks since these calls may cause the | 802 // Used to asynchronously handle clicks since these calls may cause the |
787 // destruction of the settings view and the base class window still | 803 // destruction of the settings view and the base class window still |
788 // needs to be alive to finish handling the mouse click. | 804 // needs to be alive to finish handling the mouse click. |
789 void WebsiteSettingsPopupView::HandleLinkClickedAsync(views::Link* source) { | 805 void WebsiteSettingsPopupView::HandleLinkClickedAsync(views::Link* source) { |
790 if (source == cookie_dialog_link_) { | 806 if (source == cookie_dialog_link_) { |
791 // Count how often the Collected Cookies dialog is opened. | 807 // Count how often the Collected Cookies dialog is opened. |
792 content::RecordAction( | 808 content::RecordAction( |
793 base::UserMetricsAction("WebsiteSettings_CookiesDialogOpened")); | 809 base::UserMetricsAction("WebsiteSettings_CookiesDialogOpened")); |
794 new CollectedCookiesViews(web_contents_); | 810 new CollectedCookiesViews(web_contents_); |
795 } else if (source == certificate_dialog_link_) { | 811 } else if (source == certificate_dialog_link_) { |
796 gfx::NativeWindow parent = | 812 gfx::NativeWindow parent = |
797 GetAnchorView() ? GetAnchorView()->GetWidget()->GetNativeWindow() : | 813 GetAnchorView() ? GetAnchorView()->GetWidget()->GetNativeWindow() : |
798 NULL; | 814 NULL; |
799 ShowCertificateViewerByID(web_contents_, parent, cert_id_); | 815 ShowCertificateViewerByID(web_contents_, parent, cert_id_); |
800 } else if (source == signed_certificate_timestamps_link_) { | 816 } else if (source == signed_certificate_timestamps_link_) { |
801 chrome::ShowSignedCertificateTimestampsViewer( | 817 chrome::ShowSignedCertificateTimestampsViewer( |
802 web_contents_, signed_certificate_timestamp_ids_); | 818 web_contents_, signed_certificate_timestamp_ids_); |
803 } else if (source == help_center_link_) { | 819 } else if (source == help_center_link_) { |
804 browser_->OpenURL(content::OpenURLParams( | 820 browser_->OpenURL(content::OpenURLParams( |
805 GURL(chrome::kPageInfoHelpCenterURL), | 821 GURL(chrome::kPageInfoHelpCenterURL), |
806 content::Referrer(), | 822 content::Referrer(), |
807 NEW_FOREGROUND_TAB, | 823 NEW_FOREGROUND_TAB, |
808 content::PAGE_TRANSITION_LINK, | 824 content::PAGE_TRANSITION_LINK, |
809 false)); | 825 false)); |
| 826 } else if (source == reset_decisions_button_) { |
| 827 content::BrowserContext* context = web_contents_->GetBrowserContext(); |
| 828 content::SSLHostState::GetFor(context)->RevokeAllowAndDenyPreferences( |
| 829 presenter_->site_url().host()); |
| 830 GetWidget()->Close(); |
810 } | 831 } |
811 } | 832 } |
OLD | NEW |