| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "chrome/browser/certificate_viewer.h" | 18 #include "chrome/browser/certificate_viewer.h" |
| 19 #include "chrome/browser/devtools/devtools_toggle_action.h" | |
| 20 #include "chrome/browser/devtools/devtools_window.h" | |
| 21 #include "chrome/browser/infobars/infobar_service.h" | 19 #include "chrome/browser/infobars/infobar_service.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/browser_dialogs.h" | 22 #include "chrome/browser/ui/browser_dialogs.h" |
| 25 #include "chrome/browser/ui/layout_constants.h" | 23 #include "chrome/browser/ui/layout_constants.h" |
| 26 #include "chrome/browser/ui/views/collected_cookies_views.h" | 24 #include "chrome/browser/ui/views/collected_cookies_views.h" |
| 27 #include "chrome/browser/ui/views/website_settings/chosen_object_row.h" | 25 #include "chrome/browser/ui/views/website_settings/chosen_object_row.h" |
| 28 #include "chrome/browser/ui/views/website_settings/non_accessible_image_view.h" | 26 #include "chrome/browser/ui/views/website_settings/non_accessible_image_view.h" |
| 29 #include "chrome/browser/ui/views/website_settings/permission_selector_row.h" | 27 #include "chrome/browser/ui/views/website_settings/permission_selector_row.h" |
| 30 #include "chrome/browser/ui/website_settings/website_settings.h" | 28 #include "chrome/browser/ui/website_settings/website_settings.h" |
| 31 #include "chrome/common/pref_names.h" | |
| 32 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 33 #include "chrome/grit/chromium_strings.h" | 30 #include "chrome/grit/chromium_strings.h" |
| 34 #include "chrome/grit/generated_resources.h" | 31 #include "chrome/grit/generated_resources.h" |
| 35 #include "chrome/grit/theme_resources.h" | 32 #include "chrome/grit/theme_resources.h" |
| 36 #include "components/content_settings/core/common/content_settings_types.h" | 33 #include "components/content_settings/core/common/content_settings_types.h" |
| 37 #include "components/prefs/pref_service.h" | |
| 38 #include "components/strings/grit/components_chromium_strings.h" | 34 #include "components/strings/grit/components_chromium_strings.h" |
| 39 #include "components/strings/grit/components_strings.h" | 35 #include "components/strings/grit/components_strings.h" |
| 40 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
| 41 #include "content/public/browser/user_metrics.h" | 37 #include "content/public/browser/user_metrics.h" |
| 42 #include "extensions/common/constants.h" | 38 #include "extensions/common/constants.h" |
| 43 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
| 44 #include "ui/base/material_design/material_design_controller.h" | 40 #include "ui/base/material_design/material_design_controller.h" |
| 45 #include "ui/base/models/simple_menu_model.h" | 41 #include "ui/base/models/simple_menu_model.h" |
| 46 #include "ui/base/resource/resource_bundle.h" | 42 #include "ui/base/resource/resource_bundle.h" |
| 47 #include "ui/gfx/canvas.h" | 43 #include "ui/gfx/canvas.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 class PopupHeaderView : public views::View { | 120 class PopupHeaderView : public views::View { |
| 125 public: | 121 public: |
| 126 explicit PopupHeaderView(views::ButtonListener* button_listener, | 122 explicit PopupHeaderView(views::ButtonListener* button_listener, |
| 127 views::StyledLabelListener* styled_label_listener); | 123 views::StyledLabelListener* styled_label_listener); |
| 128 ~PopupHeaderView() override; | 124 ~PopupHeaderView() override; |
| 129 | 125 |
| 130 // Sets the security summary for the current page. | 126 // Sets the security summary for the current page. |
| 131 void SetSummary(const base::string16& summary_text); | 127 void SetSummary(const base::string16& summary_text); |
| 132 | 128 |
| 133 // Sets the security details for the current page. | 129 // Sets the security details for the current page. |
| 134 void SetDetails(const base::string16& details_text, | 130 void SetDetails(const base::string16& details_text); |
| 135 bool include_details_link); | |
| 136 | 131 |
| 137 void AddResetDecisionsLabel(); | 132 void AddResetDecisionsLabel(); |
| 138 | 133 |
| 139 private: | 134 private: |
| 140 // The listener for the styled labels in this view. | 135 // The listener for the styled labels in this view. |
| 141 views::StyledLabelListener* styled_label_listener_; | 136 views::StyledLabelListener* styled_label_listener_; |
| 142 | 137 |
| 143 // The label that displays security summary for the current page. | 138 // The label that displays security summary for the current page. |
| 144 views::Label* summary_label_; | 139 views::Label* summary_label_; |
| 145 | 140 |
| 146 // The label that displays the status of the identity check for this site. | 141 // The label that displays the status of the identity check for this site. |
| 147 // Includes a link to open the DevTools Security panel. | 142 // Includes a link to open the Chrome Help Center article about connection |
| 143 // security. |
| 148 views::StyledLabel* details_label_; | 144 views::StyledLabel* details_label_; |
| 149 | 145 |
| 150 // A container for the styled label with a link for resetting cert decisions. | 146 // A container for the styled label with a link for resetting cert decisions. |
| 151 // This is only shown sometimes, so we use a container to keep track of | 147 // This is only shown sometimes, so we use a container to keep track of |
| 152 // where to place it (if needed). | 148 // where to place it (if needed). |
| 153 views::View* reset_decisions_label_container_; | 149 views::View* reset_decisions_label_container_; |
| 154 views::StyledLabel* reset_decisions_label_; | 150 views::StyledLabel* reset_decisions_label_; |
| 155 | 151 |
| 156 DISALLOW_COPY_AND_ASSIGN(PopupHeaderView); | 152 DISALLOW_COPY_AND_ASSIGN(PopupHeaderView); |
| 157 }; | 153 }; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 263 |
| 268 layout->AddPaddingRow(1, kHeaderPaddingBottom); | 264 layout->AddPaddingRow(1, kHeaderPaddingBottom); |
| 269 } | 265 } |
| 270 | 266 |
| 271 PopupHeaderView::~PopupHeaderView() {} | 267 PopupHeaderView::~PopupHeaderView() {} |
| 272 | 268 |
| 273 void PopupHeaderView::SetSummary(const base::string16& summary_text) { | 269 void PopupHeaderView::SetSummary(const base::string16& summary_text) { |
| 274 summary_label_->SetText(summary_text); | 270 summary_label_->SetText(summary_text); |
| 275 } | 271 } |
| 276 | 272 |
| 277 void PopupHeaderView::SetDetails(const base::string16& details_text, | 273 void PopupHeaderView::SetDetails(const base::string16& details_text) { |
| 278 bool include_details_label_link) { | 274 std::vector<base::string16> subst; |
| 279 if (include_details_label_link) { | 275 subst.push_back(details_text); |
| 280 base::string16 details_link_text = | 276 subst.push_back(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
| 281 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_DETAILS_LINK); | |
| 282 | 277 |
| 283 std::vector<base::string16> subst; | 278 std::vector<size_t> offsets; |
| 284 subst.push_back(details_text); | |
| 285 subst.push_back(details_link_text); | |
| 286 | 279 |
| 287 std::vector<size_t> offsets; | 280 base::string16 text = base::ReplaceStringPlaceholders( |
| 281 base::ASCIIToUTF16("$1 $2"), subst, &offsets); |
| 282 details_label_->SetText(text); |
| 283 gfx::Range details_range(offsets[1], text.length()); |
| 288 | 284 |
| 289 base::string16 text = base::ReplaceStringPlaceholders( | 285 views::StyledLabel::RangeStyleInfo link_style = |
| 290 base::ASCIIToUTF16("$1 $2"), subst, &offsets); | 286 views::StyledLabel::RangeStyleInfo::CreateForLink(); |
| 291 details_label_->SetText(text); | 287 if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) |
| 292 gfx::Range details_range(offsets[1], text.length()); | 288 link_style.font_style |= gfx::Font::FontStyle::UNDERLINE; |
| 289 link_style.disable_line_wrapping = false; |
| 293 | 290 |
| 294 views::StyledLabel::RangeStyleInfo link_style = | 291 details_label_->AddStyleRange(details_range, link_style); |
| 295 views::StyledLabel::RangeStyleInfo::CreateForLink(); | |
| 296 if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) | |
| 297 link_style.font_style |= gfx::Font::FontStyle::UNDERLINE; | |
| 298 link_style.disable_line_wrapping = false; | |
| 299 | |
| 300 details_label_->AddStyleRange(details_range, link_style); | |
| 301 } else { | |
| 302 details_label_->SetText(details_text); | |
| 303 } | |
| 304 } | 292 } |
| 305 | 293 |
| 306 void PopupHeaderView::AddResetDecisionsLabel() { | 294 void PopupHeaderView::AddResetDecisionsLabel() { |
| 307 std::vector<base::string16> subst; | 295 std::vector<base::string16> subst; |
| 308 subst.push_back( | 296 subst.push_back( |
| 309 l10n_util::GetStringUTF16(IDS_PAGEINFO_INVALID_CERTIFICATE_DESCRIPTION)); | 297 l10n_util::GetStringUTF16(IDS_PAGEINFO_INVALID_CERTIFICATE_DESCRIPTION)); |
| 310 subst.push_back(l10n_util::GetStringUTF16( | 298 subst.push_back(l10n_util::GetStringUTF16( |
| 311 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON)); | 299 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON)); |
| 312 | 300 |
| 313 std::vector<size_t> offsets; | 301 std::vector<size_t> offsets; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 profile_(profile), | 447 profile_(profile), |
| 460 header_(nullptr), | 448 header_(nullptr), |
| 461 separator_(nullptr), | 449 separator_(nullptr), |
| 462 site_settings_view_(nullptr), | 450 site_settings_view_(nullptr), |
| 463 cookies_view_(nullptr), | 451 cookies_view_(nullptr), |
| 464 cookie_dialog_link_(nullptr), | 452 cookie_dialog_link_(nullptr), |
| 465 permissions_view_(nullptr), | 453 permissions_view_(nullptr), |
| 466 weak_factory_(this) { | 454 weak_factory_(this) { |
| 467 g_shown_popup_type = POPUP_WEBSITE_SETTINGS; | 455 g_shown_popup_type = POPUP_WEBSITE_SETTINGS; |
| 468 set_parent_window(parent_window); | 456 set_parent_window(parent_window); |
| 469 is_devtools_disabled_ = | |
| 470 profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled); | |
| 471 | 457 |
| 472 // Compensate for built-in vertical padding in the anchor view's image. | 458 // Compensate for built-in vertical padding in the anchor view's image. |
| 473 set_anchor_view_insets(gfx::Insets( | 459 set_anchor_view_insets(gfx::Insets( |
| 474 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); | 460 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); |
| 475 | 461 |
| 476 views::GridLayout* layout = new views::GridLayout(this); | 462 views::GridLayout* layout = new views::GridLayout(this); |
| 477 SetLayoutManager(layout); | 463 SetLayoutManager(layout); |
| 478 const int content_column = 0; | 464 const int content_column = 0; |
| 479 views::ColumnSet* column_set = layout->AddColumnSet(content_column); | 465 views::ColumnSet* column_set = layout->AddColumnSet(content_column); |
| 480 column_set->AddColumn(views::GridLayout::FILL, | 466 column_set->AddColumn(views::GridLayout::FILL, |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 | 704 |
| 719 header_->SetSummary(security_description->summary); | 705 header_->SetSummary(security_description->summary); |
| 720 | 706 |
| 721 if (identity_info.certificate) { | 707 if (identity_info.certificate) { |
| 722 certificate_ = identity_info.certificate; | 708 certificate_ = identity_info.certificate; |
| 723 | 709 |
| 724 if (identity_info.show_ssl_decision_revoke_button) | 710 if (identity_info.show_ssl_decision_revoke_button) |
| 725 header_->AddResetDecisionsLabel(); | 711 header_->AddResetDecisionsLabel(); |
| 726 } | 712 } |
| 727 | 713 |
| 728 bool include_details_link = !is_devtools_disabled_ || certificate_; | 714 header_->SetDetails(security_description->details); |
| 729 | |
| 730 header_->SetDetails(security_description->details, include_details_link); | |
| 731 | 715 |
| 732 Layout(); | 716 Layout(); |
| 733 SizeToContents(); | 717 SizeToContents(); |
| 734 } | 718 } |
| 735 | 719 |
| 736 void WebsiteSettingsPopupView::SetSelectedTab(TabId tab_id) { | 720 void WebsiteSettingsPopupView::SetSelectedTab(TabId tab_id) { |
| 737 // TODO(lgarron): Remove this method. (https://crbug.com/571533) | 721 // TODO(lgarron): Remove this method. (https://crbug.com/571533) |
| 738 } | 722 } |
| 739 | 723 |
| 740 views::View* WebsiteSettingsPopupView::CreateSiteSettingsView() { | 724 views::View* WebsiteSettingsPopupView::CreateSiteSettingsView() { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 default: | 764 default: |
| 781 NOTREACHED(); | 765 NOTREACHED(); |
| 782 } | 766 } |
| 783 } | 767 } |
| 784 | 768 |
| 785 void WebsiteSettingsPopupView::StyledLabelLinkClicked(views::StyledLabel* label, | 769 void WebsiteSettingsPopupView::StyledLabelLinkClicked(views::StyledLabel* label, |
| 786 const gfx::Range& range, | 770 const gfx::Range& range, |
| 787 int event_flags) { | 771 int event_flags) { |
| 788 switch (label->id()) { | 772 switch (label->id()) { |
| 789 case STYLED_LABEL_SECURITY_DETAILS: | 773 case STYLED_LABEL_SECURITY_DETAILS: |
| 774 web_contents()->OpenURL(content::OpenURLParams( |
| 775 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(), |
| 776 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, |
| 777 false)); |
| 790 presenter_->RecordWebsiteSettingsAction( | 778 presenter_->RecordWebsiteSettingsAction( |
| 791 WebsiteSettings::WEBSITE_SETTINGS_SECURITY_DETAILS_OPENED); | 779 WebsiteSettings::WEBSITE_SETTINGS_CONNECTION_HELP_OPENED); |
| 792 | |
| 793 if (is_devtools_disabled_) { | |
| 794 DCHECK(certificate_); | |
| 795 gfx::NativeWindow parent = | |
| 796 anchor_widget() ? anchor_widget()->GetNativeWindow() : nullptr; | |
| 797 presenter_->RecordWebsiteSettingsAction( | |
| 798 WebsiteSettings::WEBSITE_SETTINGS_CERTIFICATE_DIALOG_OPENED); | |
| 799 ShowCertificateViewer(web_contents(), parent, certificate_.get()); | |
| 800 } else { | |
| 801 DevToolsWindow::OpenDevToolsWindow( | |
| 802 web_contents(), DevToolsToggleAction::ShowSecurityPanel()); | |
| 803 } | |
| 804 break; | 780 break; |
| 805 case STYLED_LABEL_RESET_CERTIFICATE_DECISIONS: | 781 case STYLED_LABEL_RESET_CERTIFICATE_DECISIONS: |
| 806 presenter_->OnRevokeSSLErrorBypassButtonPressed(); | 782 presenter_->OnRevokeSSLErrorBypassButtonPressed(); |
| 807 GetWidget()->Close(); | 783 GetWidget()->Close(); |
| 808 break; | 784 break; |
| 809 default: | 785 default: |
| 810 NOTREACHED(); | 786 NOTREACHED(); |
| 811 } | 787 } |
| 812 } | 788 } |
| OLD | NEW |