Commit 036e47c7 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Move StyledLabelListener subclass around to simplify code.

Bug: none
Change-Id: Iaf29f57b6085d96fd5cf0dc890e57500bfc0bfb2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2384333
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Patti <patricialor@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarPatti <patricialor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802980}
parent ba492cf0
...@@ -132,13 +132,16 @@ std::unique_ptr<views::View> CreateSiteSettingsLink( ...@@ -132,13 +132,16 @@ std::unique_ptr<views::View> CreateSiteSettingsLink(
// |BubbleHeaderView| is the UI element (view) that represents the header of the // |BubbleHeaderView| is the UI element (view) that represents the header of the
// |PageInfoBubbleView|. The header shows the status of the site's // |PageInfoBubbleView|. The header shows the status of the site's
// identity check and the name of the site's identity. // identity check and the name of the site's identity.
class BubbleHeaderView : public views::View { class BubbleHeaderView : public views::View, public views::StyledLabelListener {
public: public:
BubbleHeaderView(views::ButtonListener* button_listener, BubbleHeaderView(PageInfoBubbleView* bubble, int side_margin);
views::StyledLabelListener* styled_label_listener,
int side_margin);
~BubbleHeaderView() override; ~BubbleHeaderView() override;
// views::StyledLabelListener:
void StyledLabelLinkClicked(views::StyledLabel* label,
const gfx::Range& range,
int event_flags) override;
// Sets the security summary for the current page. // Sets the security summary for the current page.
void SetSummary(const base::string16& summary_text); void SetSummary(const base::string16& summary_text);
...@@ -156,11 +159,8 @@ class BubbleHeaderView : public views::View { ...@@ -156,11 +159,8 @@ class BubbleHeaderView : public views::View {
void AddPasswordReuseButtons(bool is_saved_password); void AddPasswordReuseButtons(bool is_saved_password);
private: private:
// The listener for the buttons in this view. // Owns |this|.
views::ButtonListener* button_listener_; PageInfoBubbleView* bubble_;
// The listener for the styled labels in this view.
views::StyledLabelListener* styled_label_listener_;
// The label that displays the status of the identity check for this site. // The label that displays the status of the identity check for this site.
// Includes a link to open the Chrome Help Center article about connection // Includes a link to open the Chrome Help Center article about connection
...@@ -206,12 +206,8 @@ class InternalPageInfoBubbleView : public PageInfoBubbleViewBase { ...@@ -206,12 +206,8 @@ class InternalPageInfoBubbleView : public PageInfoBubbleViewBase {
// Bubble Header // Bubble Header
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BubbleHeaderView::BubbleHeaderView( BubbleHeaderView::BubbleHeaderView(PageInfoBubbleView* bubble, int side_margin)
views::ButtonListener* button_listener, : bubble_(bubble) {
views::StyledLabelListener* styled_label_listener,
int side_margin)
: button_listener_(button_listener),
styled_label_listener_(styled_label_listener) {
views::GridLayout* layout = views::GridLayout* layout =
SetLayoutManager(std::make_unique<views::GridLayout>()); SetLayoutManager(std::make_unique<views::GridLayout>());
...@@ -220,8 +216,7 @@ BubbleHeaderView::BubbleHeaderView( ...@@ -220,8 +216,7 @@ BubbleHeaderView::BubbleHeaderView(
layout->StartRow(views::GridLayout::kFixedSize, label_column_status); layout->StartRow(views::GridLayout::kFixedSize, label_column_status);
auto security_details_label = auto security_details_label = std::make_unique<views::StyledLabel>(this);
std::make_unique<views::StyledLabel>(styled_label_listener);
security_details_label->SetID( security_details_label->SetID(
PageInfoBubbleView::VIEW_ID_PAGE_INFO_LABEL_SECURITY_DETAILS); PageInfoBubbleView::VIEW_ID_PAGE_INFO_LABEL_SECURITY_DETAILS);
security_details_label_ = security_details_label_ =
...@@ -245,6 +240,20 @@ BubbleHeaderView::BubbleHeaderView( ...@@ -245,6 +240,20 @@ BubbleHeaderView::BubbleHeaderView(
BubbleHeaderView::~BubbleHeaderView() {} BubbleHeaderView::~BubbleHeaderView() {}
void BubbleHeaderView::StyledLabelLinkClicked(views::StyledLabel* label,
const gfx::Range& range,
int event_flags) {
if (label->GetID() ==
PageInfoBubbleView::VIEW_ID_PAGE_INFO_LABEL_SECURITY_DETAILS) {
bubble_->SecurityDetailsClicked(event_flags);
} else {
DCHECK_EQ(
PageInfoBubbleView::VIEW_ID_PAGE_INFO_LABEL_RESET_CERTIFICATE_DECISIONS,
label->GetID());
bubble_->ResetDecisionsClicked();
}
}
void BubbleHeaderView::SetDetails(const base::string16& details_text) { void BubbleHeaderView::SetDetails(const base::string16& details_text) {
std::vector<base::string16> subst; std::vector<base::string16> subst;
subst.push_back(details_text); subst.push_back(details_text);
...@@ -282,7 +291,7 @@ void BubbleHeaderView::AddResetDecisionsLabel() { ...@@ -282,7 +291,7 @@ void BubbleHeaderView::AddResetDecisionsLabel() {
base::ASCIIToUTF16("$1 $2"), subst, &offsets); base::ASCIIToUTF16("$1 $2"), subst, &offsets);
views::StyledLabel* reset_cert_decisions_label = views::StyledLabel* reset_cert_decisions_label =
reset_decisions_label_container_->AddChildView( reset_decisions_label_container_->AddChildView(
std::make_unique<views::StyledLabel>(styled_label_listener_)); std::make_unique<views::StyledLabel>(this));
reset_cert_decisions_label->SetText(text); reset_cert_decisions_label->SetText(text);
reset_cert_decisions_label->SetID( reset_cert_decisions_label->SetID(
PageInfoBubbleView::VIEW_ID_PAGE_INFO_LABEL_RESET_CERTIFICATE_DECISIONS); PageInfoBubbleView::VIEW_ID_PAGE_INFO_LABEL_RESET_CERTIFICATE_DECISIONS);
...@@ -324,13 +333,13 @@ void BubbleHeaderView::AddPasswordReuseButtons(bool is_saved_password) { ...@@ -324,13 +333,13 @@ void BubbleHeaderView::AddPasswordReuseButtons(bool is_saved_password) {
std::unique_ptr<views::MdTextButton> change_password_button; std::unique_ptr<views::MdTextButton> change_password_button;
if (change_password_template) { if (change_password_template) {
change_password_button = std::make_unique<views::MdTextButton>( change_password_button = std::make_unique<views::MdTextButton>(
button_listener_, l10n_util::GetStringUTF16(change_password_template)); bubble_, l10n_util::GetStringUTF16(change_password_template));
change_password_button->SetProminent(true); change_password_button->SetProminent(true);
change_password_button->SetID( change_password_button->SetID(
PageInfoBubbleView::VIEW_ID_PAGE_INFO_BUTTON_CHANGE_PASSWORD); PageInfoBubbleView::VIEW_ID_PAGE_INFO_BUTTON_CHANGE_PASSWORD);
} }
auto allowlist_password_reuse_button = std::make_unique<views::MdTextButton>( auto allowlist_password_reuse_button = std::make_unique<views::MdTextButton>(
button_listener_, bubble_,
l10n_util::GetStringUTF16(IDS_PAGE_INFO_ALLOWLIST_PASSWORD_REUSE_BUTTON)); l10n_util::GetStringUTF16(IDS_PAGE_INFO_ALLOWLIST_PASSWORD_REUSE_BUTTON));
allowlist_password_reuse_button->SetID( allowlist_password_reuse_button->SetID(
PageInfoBubbleView::VIEW_ID_PAGE_INFO_BUTTON_ALLOWLIST_PASSWORD_REUSE); PageInfoBubbleView::VIEW_ID_PAGE_INFO_BUTTON_ALLOWLIST_PASSWORD_REUSE);
...@@ -466,6 +475,24 @@ views::BubbleDialogDelegateView* PageInfoBubbleView::CreatePageInfoBubble( ...@@ -466,6 +475,24 @@ views::BubbleDialogDelegateView* PageInfoBubbleView::CreatePageInfoBubble(
web_contents, url, std::move(closing_callback)); web_contents, url, std::move(closing_callback));
} }
void PageInfoBubbleView::SecurityDetailsClicked(int event_flags) {
if (GetSecurityDescriptionType() == SecurityDescriptionType::SAFETY_TIP) {
OpenHelpCenterFromSafetyTip(web_contents());
} else {
web_contents()->OpenURL(content::OpenURLParams(
GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(),
WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
false));
presenter_->RecordPageInfoAction(
PageInfo::PAGE_INFO_CONNECTION_HELP_OPENED);
}
}
void PageInfoBubbleView::ResetDecisionsClicked() {
presenter_->OnRevokeSSLErrorBypassButtonPressed();
GetWidget()->Close();
}
PageInfoBubbleView::PageInfoBubbleView( PageInfoBubbleView::PageInfoBubbleView(
views::View* anchor_view, views::View* anchor_view,
const gfx::Rect& anchor_rect, const gfx::Rect& anchor_rect,
...@@ -507,8 +534,8 @@ PageInfoBubbleView::PageInfoBubbleView( ...@@ -507,8 +534,8 @@ PageInfoBubbleView::PageInfoBubbleView(
views::GridLayout::ColumnSize::kUsePreferred, 0, 0); views::GridLayout::ColumnSize::kUsePreferred, 0, 0);
layout->StartRow(views::GridLayout::kFixedSize, kColumnId); layout->StartRow(views::GridLayout::kFixedSize, kColumnId);
header_ = layout->AddView( header_ =
std::make_unique<BubbleHeaderView>(this, this, side_margin)); layout->AddView(std::make_unique<BubbleHeaderView>(this, side_margin));
layout->StartRow(views::GridLayout::kFixedSize, kColumnId); layout->StartRow(views::GridLayout::kFixedSize, kColumnId);
permissions_view_ = layout->AddView(std::make_unique<views::View>()); permissions_view_ = layout->AddView(std::make_unique<views::View>());
...@@ -1015,32 +1042,6 @@ void PageInfoBubbleView::HandleMoreInfoRequestAsync(int view_id) { ...@@ -1015,32 +1042,6 @@ void PageInfoBubbleView::HandleMoreInfoRequestAsync(int view_id) {
} }
} }
void PageInfoBubbleView::StyledLabelLinkClicked(views::StyledLabel* label,
const gfx::Range& range,
int event_flags) {
switch (label->GetID()) {
case PageInfoBubbleView::VIEW_ID_PAGE_INFO_LABEL_SECURITY_DETAILS:
if (GetSecurityDescriptionType() == SecurityDescriptionType::SAFETY_TIP) {
OpenHelpCenterFromSafetyTip(web_contents());
} else {
web_contents()->OpenURL(content::OpenURLParams(
GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(),
WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
false));
presenter_->RecordPageInfoAction(
PageInfo::PAGE_INFO_CONNECTION_HELP_OPENED);
}
break;
case PageInfoBubbleView::
VIEW_ID_PAGE_INFO_LABEL_RESET_CERTIFICATE_DECISIONS:
presenter_->OnRevokeSSLErrorBypassButtonPressed();
GetWidget()->Close();
break;
default:
NOTREACHED();
}
}
void ShowPageInfoDialogImpl(Browser* browser, void ShowPageInfoDialogImpl(Browser* browser,
content::WebContents* web_contents, content::WebContents* web_contents,
const GURL& virtual_url, const GURL& virtual_url,
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
#include "ui/views/controls/separator.h" #include "ui/views/controls/separator.h"
#include "ui/views/controls/styled_label.h" #include "ui/views/controls/styled_label.h"
#include "ui/views/controls/styled_label_listener.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
class BubbleHeaderView; class BubbleHeaderView;
...@@ -60,7 +59,6 @@ class PageInfoBubbleView : public PageInfoBubbleViewBase, ...@@ -60,7 +59,6 @@ class PageInfoBubbleView : public PageInfoBubbleViewBase,
public PermissionSelectorRowObserver, public PermissionSelectorRowObserver,
public ChosenObjectViewObserver, public ChosenObjectViewObserver,
public views::ButtonListener, public views::ButtonListener,
public views::StyledLabelListener,
public PageInfoUI { public PageInfoUI {
public: public:
// The width of the column size for permissions and chosen object icons. // The width of the column size for permissions and chosen object icons.
...@@ -100,6 +98,9 @@ class PageInfoBubbleView : public PageInfoBubbleViewBase, ...@@ -100,6 +98,9 @@ class PageInfoBubbleView : public PageInfoBubbleViewBase,
const GURL& url, const GURL& url,
PageInfoClosingCallback closing_callback); PageInfoClosingCallback closing_callback);
void SecurityDetailsClicked(int event_flags);
void ResetDecisionsClicked();
protected: protected:
const base::string16 details_text() const { return details_text_; } const base::string16 details_text() const { return details_text_; }
...@@ -132,11 +133,6 @@ class PageInfoBubbleView : public PageInfoBubbleViewBase, ...@@ -132,11 +133,6 @@ class PageInfoBubbleView : public PageInfoBubbleViewBase,
// views::ButtonListener: // views::ButtonListener:
void ButtonPressed(views::Button* button, const ui::Event& event) override; void ButtonPressed(views::Button* button, const ui::Event& event) override;
// views::StyledLabelListener:
void StyledLabelLinkClicked(views::StyledLabel* label,
const gfx::Range& range,
int event_flags) override;
// PageInfoUI: // PageInfoUI:
void SetCookieInfo(const CookieInfoList& cookie_info_list) override; void SetCookieInfo(const CookieInfoList& cookie_info_list) override;
void SetPermissionInfo(const PermissionInfoList& permission_info_list, void SetPermissionInfo(const PermissionInfoList& permission_info_list,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment