Commit 1c79c648 authored by Daniel Rubery's avatar Daniel Rubery Committed by Commit Bot

Add learn more link to Advanced Protection modal dialog

We will be adding more details to the Advanced Protection FAQ page (
https://support.google.com/accounts/?p=ap_faq) about deep scanning.
This CL adds a link with "Learn more" on the modal dialog, which links
to this FAQ page.

Screenshot: https://screenshot.googleplex.com/i5JHn4QZ42z.png
Bug: 1020418
Change-Id: I5bccd307f82ea17dc0b77e0c0b9e52fe0d5ea6f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2026590
Commit-Queue: Daniel Rubery <drubery@chromium.org>
Reviewed-by: default avatarXinghui Lu <xinghuilu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736511}
parent 68f0d672
......@@ -6,12 +6,20 @@
#include <memory>
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "components/constrained_window/constrained_window_views.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/page_transition_types.h"
#include "ui/base/ui_base_types.h"
#include "ui/base/window_open_disposition.h"
#include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/window/dialog_delegate.h"
......@@ -23,15 +31,17 @@ void PromptForScanningModalDialog::ShowForWebContents(
base::OnceClosure accept_callback,
base::OnceClosure open_now_callback) {
constrained_window::ShowWebModalDialogViews(
new PromptForScanningModalDialog(std::move(accept_callback),
new PromptForScanningModalDialog(web_contents, std::move(accept_callback),
std::move(open_now_callback)),
web_contents);
}
PromptForScanningModalDialog::PromptForScanningModalDialog(
content::WebContents* web_contents,
base::OnceClosure accept_callback,
base::OnceClosure open_now_callback)
: accept_callback_(std::move(accept_callback)),
: web_contents_(web_contents),
accept_callback_(std::move(accept_callback)),
open_now_callback_(std::move(open_now_callback)) {
DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_OK,
......@@ -56,13 +66,23 @@ PromptForScanningModalDialog::PromptForScanningModalDialog(
views::GridLayout::kFixedSize, views::GridLayout::FIXED,
kMaxMessageWidth, false);
// Create the message label text.
std::vector<size_t> offsets;
base::string16 message_text = base::ReplaceStringPlaceholders(
base::ASCIIToUTF16("$1 $2"),
{l10n_util::GetStringUTF16(IDS_DEEP_SCANNING_INFO_DIALOG_MESSAGE),
l10n_util::GetStringUTF16(IDS_LEARN_MORE)},
&offsets);
// Add the message label.
auto label = std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_DEEP_SCANNING_INFO_DIALOG_MESSAGE),
views::style::CONTEXT_MESSAGE_BOX_BODY_TEXT,
views::style::STYLE_SECONDARY);
auto label = std::make_unique<views::StyledLabel>(message_text, this);
gfx::Range learn_more_range(offsets[1], message_text.length());
views::StyledLabel::RangeStyleInfo link_style =
views::StyledLabel::RangeStyleInfo::CreateForLink();
label->AddStyleRange(learn_more_range, link_style);
label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
label->SetMultiLine(true);
label->SizeToFit(kMaxMessageWidth);
layout->StartRow(views::GridLayout::kFixedSize, 0);
layout->AddView(std::move(label));
......@@ -104,4 +124,14 @@ void PromptForScanningModalDialog::ButtonPressed(views::Button* sender,
}
}
void PromptForScanningModalDialog::StyledLabelLinkClicked(
views::StyledLabel* label,
const gfx::Range& range,
int event_flags) {
web_contents_->OpenURL(content::OpenURLParams(
GURL(chrome::kAdvancedProtectionDownloadLearnMoreURL),
content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB,
ui::PAGE_TRANSITION_LINK, /*is_renderer_initiated=*/false));
}
} // namespace safe_browsing
......@@ -10,6 +10,8 @@
#include "base/timer/timer.h"
#include "ui/base/ui_base_types.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/controls/styled_label_listener.h"
#include "ui/views/window/dialog_delegate.h"
namespace content {
......@@ -21,7 +23,8 @@ namespace safe_browsing {
// A tab modal dialog that provides more information to the user about the
// prompt for deep scanning.
class PromptForScanningModalDialog : public views::DialogDelegateView,
public views::ButtonListener {
public views::ButtonListener,
public views::StyledLabelListener {
public:
// Show this dialog for the given |web_contents|.
static void ShowForWebContents(content::WebContents* web_contents,
......@@ -30,7 +33,8 @@ class PromptForScanningModalDialog : public views::DialogDelegateView,
// Create a PromptForScanningModalDialog attached to |web_contents|. The
// dialog will call |accept_callback| if the user accepts the prompt.
PromptForScanningModalDialog(base::OnceClosure accept_callback,
PromptForScanningModalDialog(content::WebContents* web_contents,
base::OnceClosure accept_callback,
base::OnceClosure open_now_callback);
PromptForScanningModalDialog(const PromptForScanningModalDialog&) = delete;
PromptForScanningModalDialog& operator=(const PromptForScanningModalDialog&) =
......@@ -50,7 +54,15 @@ class PromptForScanningModalDialog : public views::DialogDelegateView,
// views::ButtonListener implementation:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// views::StyledLabelListener implementation:
void StyledLabelLinkClicked(views::StyledLabel* label,
const gfx::Range& range,
int event_flags) override;
private:
// The WebContents this dialog is attached to. This is unowned.
content::WebContents* web_contents_;
// The open now button for this dialog. The pointer is unowned, but this is a
// child View of this dialog's View, so it has the same lifetime.
views::Button* open_now_button_;
......
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