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