Commit 53b2989a authored by Emily Stark's avatar Emily Stark Committed by Commit Bot

Remove safety_tips namespace

Named namespaces are discouraged in chrome/ (as discussed on
chromium-dev and recently codified in
https://chromium.googlesource.com/chromium/src/+/master/styleguide/c++/c++-dos-and-donts.md#named-namespaces). This
removes the safety_tips namespace, renames a couple functions as
needed, and does a little more miscellaneous cleanup (e.g., removing
unnecessary aliases).

TBR=csharrison@chromium.org,ellyjones@chromium.org

Change-Id: I28dbd6ba2a90784fe148e91ccd75bc607d6192b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1876474Reviewed-by: default avatarEmily Stark <estark@chromium.org>
Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Reviewed-by: default avatarJoe DeBlasio <jdeblasio@chromium.org>
Commit-Queue: Emily Stark <estark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709073}
parent 0b4e397d
......@@ -101,7 +101,7 @@ void SafetyTipsComponentInstallerPolicy::ComponentReady(
FROM_HERE,
{base::ThreadPool(), base::MayBlock(), base::TaskPriority::BEST_EFFORT},
base::BindOnce(&LoadSafetyTipsProtoFromDisk, pb_path),
base::BindOnce(&safety_tips::SetRemoteConfigProto));
base::BindOnce(&SetSafetyTipsRemoteConfigProto));
}
// Called during startup and installation before ComponentReady().
......
......@@ -258,8 +258,8 @@ IN_PROC_BROWSER_TEST_F(SecurityStatePageLoadMetricsBrowserTest,
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();
safety_tips::ReputationWebContentsObserver* rep_observer =
safety_tips::ReputationWebContentsObserver::FromWebContents(contents);
ReputationWebContentsObserver* rep_observer =
ReputationWebContentsObserver::FromWebContents(contents);
ASSERT_TRUE(rep_observer);
// Navigate to |url| and wait for the reputation check to complete before
......@@ -308,8 +308,8 @@ IN_PROC_BROWSER_TEST_F(SecurityStatePageLoadMetricsBrowserTest,
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();
safety_tips::ReputationWebContentsObserver* rep_observer =
safety_tips::ReputationWebContentsObserver::FromWebContents(contents);
ReputationWebContentsObserver* rep_observer =
ReputationWebContentsObserver::FromWebContents(contents);
ASSERT_TRUE(rep_observer);
// Navigate to |url| and wait for the reputation check to complete before
......@@ -483,8 +483,8 @@ IN_PROC_BROWSER_TEST_F(SecurityStatePageLoadMetricsBrowserTest,
}
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();
safety_tips::ReputationWebContentsObserver* rep_observer =
safety_tips::ReputationWebContentsObserver::FromWebContents(contents);
ReputationWebContentsObserver* rep_observer =
ReputationWebContentsObserver::FromWebContents(contents);
ASSERT_TRUE(rep_observer);
// Navigate to |url| and wait for the reputation check to complete before
......
......@@ -25,8 +25,6 @@ const base::FeatureParam<bool> kEnableLookalikeEditDistanceSiteEngagement{
} // namespace
namespace safety_tips {
bool ShouldTriggerSafetyTipFromLookalike(
const GURL& url,
const DomainInfo& navigated_domain,
......@@ -103,5 +101,3 @@ bool ShouldTriggerSafetyTipFromKeywordInURL(
return false;
}
} // namespace safety_tips
......@@ -12,11 +12,6 @@
#include "chrome/browser/lookalikes/lookalike_url_service.h"
#include "url/gurl.h"
// These functions exist as utility functions, and are currently used in
// "safety_tip_heuristics". These functions SHOULD NOT be called directly. See
// reptuation_service.h for module use.
namespace safety_tips {
// Checks to see whether a given URL qualifies as a lookalike domain, and thus
// should trigger a safety tip. This algorithm factors in the sites that the
// user has already engaged with. This heuristic stores a "safe url" that the
......@@ -34,6 +29,4 @@ bool ShouldTriggerSafetyTipFromKeywordInURL(
const char* const sensitive_keywords[],
size_t num_keywords);
} // namespace safety_tips
#endif // CHROME_BROWSER_REPUTATION_LOCAL_HEURISTICS_H_
......@@ -104,7 +104,7 @@ TEST(SafetyTipHeuristicsTest, SensitiveKeywordsTest) {
for (const auto& test_case : test_cases) {
ASSERT_EQ(test_case.should_trigger,
safety_tips::ShouldTriggerSafetyTipFromKeywordInURL(
ShouldTriggerSafetyTipFromKeywordInURL(
test_case.url, keywords.data(), keywords.size()))
<< "Expected that \"" << test_case.url << "\" should"
<< (test_case.should_trigger ? "" : "n't") << " trigger but it did"
......
......@@ -29,7 +29,6 @@ namespace {
using chrome_browser_safety_tips::FlaggedPage;
using chrome_browser_safety_tips::UrlPattern;
using safe_browsing::V4ProtocolManagerUtil;
using safety_tips::ReputationService;
// This factory helps construct and find the singleton ReputationService linked
// to a Profile.
......@@ -57,7 +56,7 @@ class ReputationServiceFactory : public BrowserContextKeyedServiceFactory {
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* profile) const override {
return new safety_tips::ReputationService(static_cast<Profile*>(profile));
return new ReputationService(static_cast<Profile*>(profile));
}
content::BrowserContext* GetBrowserContextToUse(
......@@ -122,7 +121,7 @@ bool ShouldSuppressWarning(const GURL& url) {
std::vector<std::string> patterns;
UrlToPatterns(url, &patterns);
auto* proto = safety_tips::GetRemoteConfigProto();
auto* proto = GetSafetyTipsRemoteConfigProto();
if (!proto) {
// This happens when the component hasn't downloaded yet. This should only
// happen for a short time after initial upgrade to M79.
......@@ -153,8 +152,6 @@ bool ShouldSuppressWarning(const GURL& url) {
} // namespace
namespace safety_tips {
ReputationService::ReputationService(Profile* profile) : profile_(profile) {}
ReputationService::~ReputationService() {}
......@@ -234,7 +231,7 @@ void ReputationService::GetReputationStatusWithEngagedSites(
}
// 2. Server-side blocklist check.
security_state::SafetyTipStatus status = GetUrlBlockType(url);
security_state::SafetyTipStatus status = GetSafetyTipUrlBlockType(url);
if (status != security_state::SafetyTipStatus::kNone) {
std::move(callback).Run(status, IsIgnored(url), url, GURL());
return;
......@@ -271,11 +268,11 @@ void ReputationService::GetReputationStatusWithEngagedSites(
IsIgnored(url), url, GURL());
}
security_state::SafetyTipStatus GetUrlBlockType(const GURL& url) {
security_state::SafetyTipStatus GetSafetyTipUrlBlockType(const GURL& url) {
std::vector<std::string> patterns;
UrlToPatterns(url, &patterns);
auto* proto = safety_tips::GetRemoteConfigProto();
auto* proto = GetSafetyTipsRemoteConfigProto();
if (!proto) {
return security_state::SafetyTipStatus::kNone;
}
......@@ -305,5 +302,3 @@ security_state::SafetyTipStatus GetUrlBlockType(const GURL& url) {
return security_state::SafetyTipStatus::kNone;
}
} // namespace safety_tips
......@@ -19,8 +19,6 @@
class Profile;
struct DomainInfo;
namespace safety_tips {
// Callback type used for retrieving reputation status. |ignored| indicates
// whether the user has dismissed the warning and thus should not be warned
// again. |url| is the URL applicable for this result,
......@@ -78,8 +76,6 @@ class ReputationService : public KeyedService {
// Checks SafeBrowsing-style permutations of |url| against the component updater
// blocklist and returns the match type. kNone means the URL is not blocked.
security_state::SafetyTipStatus GetUrlBlockType(const GURL& url);
} // namespace safety_tips
security_state::SafetyTipStatus GetSafetyTipUrlBlockType(const GURL& url);
#endif // CHROME_BROWSER_REPUTATION_REPUTATION_SERVICE_H_
......@@ -14,8 +14,6 @@
#include "components/security_state/core/security_state.h"
#include "testing/gtest/include/gtest/gtest.h"
using safety_tips::GetUrlBlockType;
class ReputationServiceTest : public ChromeRenderViewHostTestHarness {
protected:
ReputationServiceTest() {}
......@@ -94,6 +92,6 @@ TEST_F(ReputationServiceTest, BlocklistTest) {
};
for (auto test : kTests) {
EXPECT_EQ(GetUrlBlockType(GURL(test.first)), test.second);
EXPECT_EQ(GetSafetyTipUrlBlockType(GURL(test.first)), test.second);
}
}
......@@ -18,34 +18,34 @@ namespace {
void OnSafetyTipClosed(security_state::SafetyTipStatus safety_tip_status,
base::Time start_time,
safety_tips::SafetyTipInteraction action) {
SafetyTipInteraction action) {
std::string action_suffix;
bool warning_dismissed = false;
switch (action) {
case safety_tips::SafetyTipInteraction::kNoAction:
case SafetyTipInteraction::kNoAction:
action_suffix = "NoAction";
break;
case safety_tips::SafetyTipInteraction::kLeaveSite:
case SafetyTipInteraction::kLeaveSite:
action_suffix = "LeaveSite";
break;
case safety_tips::SafetyTipInteraction::kDismiss:
case SafetyTipInteraction::kDismiss:
NOTREACHED();
// Do nothing because the dismissal action passed to this method should
// be the more specific version (esc, close, or ignore).
break;
case safety_tips::SafetyTipInteraction::kDismissWithEsc:
case SafetyTipInteraction::kDismissWithEsc:
action_suffix = "DismissWithEsc";
warning_dismissed = true;
break;
case safety_tips::SafetyTipInteraction::kDismissWithClose:
case SafetyTipInteraction::kDismissWithClose:
action_suffix = "DismissWithClose";
warning_dismissed = true;
break;
case safety_tips::SafetyTipInteraction::kDismissWithIgnore:
case SafetyTipInteraction::kDismissWithIgnore:
action_suffix = "DismissWithIgnore";
warning_dismissed = true;
break;
case safety_tips::SafetyTipInteraction::kLearnMore:
case SafetyTipInteraction::kLearnMore:
action_suffix = "LearnMore";
break;
}
......@@ -67,8 +67,6 @@ void OnSafetyTipClosed(security_state::SafetyTipStatus safety_tip_status,
} // namespace
namespace safety_tips {
ReputationWebContentsObserver::~ReputationWebContentsObserver() {}
void ReputationWebContentsObserver::DidFinishNavigation(
......@@ -187,5 +185,3 @@ void ReputationWebContentsObserver::MaybeCallReputationCheckCallback() {
}
WEB_CONTENTS_USER_DATA_KEY_IMPL(ReputationWebContentsObserver)
} // namespace safety_tips
......@@ -20,8 +20,6 @@
class Profile;
namespace safety_tips {
// Observes navigations and triggers a warning if a visited site is determined
// to be low-reputation as determined by heuristics or inclusion on
// pre-calculated lists.
......@@ -80,6 +78,4 @@ class ReputationWebContentsObserver
WEB_CONTENTS_USER_DATA_KEY_DECL();
};
} // namespace safety_tips
#endif // CHROME_BROWSER_REPUTATION_REPUTATION_WEB_CONTENTS_OBSERVER_H_
......@@ -15,9 +15,6 @@
#include "ui/gfx/image/image.h"
using base::android::ScopedJavaLocalRef;
using safety_tips::SafetyTipInfoBarDelegate;
namespace safety_tips {
// static
std::unique_ptr<infobars::InfoBar> SafetyTipInfoBar::CreateInfoBar(
......@@ -61,5 +58,3 @@ ScopedJavaLocalRef<jobject> SafetyTipInfoBar::CreateRenderInfoBar(JNIEnv* env) {
SafetyTipInfoBarDelegate* SafetyTipInfoBar::GetDelegate() {
return static_cast<SafetyTipInfoBarDelegate*>(delegate());
}
} // namespace safety_tips
......@@ -9,8 +9,6 @@
#include "base/macros.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
namespace safety_tips {
class SafetyTipInfoBarDelegate;
// SafetyTipInfoBar is a thin vineer over ConfirmInfoBar that adds a discrete
......@@ -18,22 +16,19 @@ class SafetyTipInfoBarDelegate;
class SafetyTipInfoBar : public ConfirmInfoBar {
public:
static std::unique_ptr<infobars::InfoBar> CreateInfoBar(
std::unique_ptr<safety_tips::SafetyTipInfoBarDelegate> delegate);
std::unique_ptr<SafetyTipInfoBarDelegate> delegate);
~SafetyTipInfoBar() override;
private:
explicit SafetyTipInfoBar(
std::unique_ptr<safety_tips::SafetyTipInfoBarDelegate> delegate);
explicit SafetyTipInfoBar(std::unique_ptr<SafetyTipInfoBarDelegate> delegate);
// ConfirmInfoBar:
base::android::ScopedJavaLocalRef<jobject> CreateRenderInfoBar(
JNIEnv* env) override;
safety_tips::SafetyTipInfoBarDelegate* GetDelegate();
SafetyTipInfoBarDelegate* GetDelegate();
DISALLOW_COPY_AND_ASSIGN(SafetyTipInfoBar);
};
} // namespace safety_tips
#endif // CHROME_BROWSER_REPUTATION_SAFETY_TIP_INFOBAR_H_
......@@ -16,11 +16,6 @@
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
using content::WebContents;
using safety_tips::SafetyTipInfoBarDelegate;
namespace safety_tips {
// From safety_tip_ui.h
void ShowSafetyTipDialog(
content::WebContents* web_contents,
......@@ -37,13 +32,11 @@ void ShowSafetyTipDialog(
SafetyTipInfoBar::CreateInfoBar(std::move(delegate)));
}
} // namespace safety_tips
SafetyTipInfoBarDelegate::SafetyTipInfoBarDelegate(
security_state::SafetyTipStatus safety_tip_status,
const GURL& url,
const GURL& suggested_url,
WebContents* web_contents,
content::WebContents* web_contents,
base::OnceCallback<void(SafetyTipInteraction)> close_callback)
: safety_tip_status_(safety_tip_status),
url_(url),
......@@ -82,8 +75,8 @@ bool SafetyTipInfoBarDelegate::Accept() {
action_taken_ = SafetyTipInteraction::kLeaveSite;
auto url = safety_tip_status_ == security_state::SafetyTipStatus::kLookalike
? suggested_url_
: GURL(safety_tips::kSafeUrl);
LeaveSite(web_contents_, url);
: GURL(kSafetyTipLeaveSiteUrl);
LeaveSiteFromSafetyTip(web_contents_, url);
return true;
}
......@@ -95,7 +88,7 @@ bool SafetyTipInfoBarDelegate::Cancel() {
if (action_taken_ != SafetyTipInteraction::kDismissWithClose) {
action_taken_ = SafetyTipInteraction::kDismissWithIgnore;
}
safety_tips::ReputationService::Get(tab->GetProfile())
ReputationService::Get(tab->GetProfile())
->SetUserIgnore(web_contents_, url_, action_taken_);
}
......
......@@ -11,8 +11,6 @@
#include "content/public/browser/web_contents.h"
#include "url/gurl.h"
namespace safety_tips {
class SafetyTipInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
SafetyTipInfoBarDelegate(
......@@ -54,6 +52,4 @@ class SafetyTipInfoBarDelegate : public ConfirmInfoBarDelegate {
content::WebContents* web_contents_;
};
} // namespace safety_tips
#endif // CHROME_BROWSER_REPUTATION_SAFETY_TIP_INFOBAR_DELEGATE_H_
......@@ -14,7 +14,7 @@ namespace {
// Retrieve existing config proto if set, or create a new one otherwise.
std::unique_ptr<chrome_browser_safety_tips::SafetyTipsConfig> GetConfig() {
auto* old = safety_tips::GetRemoteConfigProto();
auto* old = GetSafetyTipsRemoteConfigProto();
if (old) {
return std::make_unique<chrome_browser_safety_tips::SafetyTipsConfig>(*old);
}
......@@ -28,7 +28,7 @@ std::unique_ptr<chrome_browser_safety_tips::SafetyTipsConfig> GetConfig() {
} // namespace
void InitializeSafetyTipConfig() {
safety_tips::SetRemoteConfigProto(GetConfig());
SetSafetyTipsRemoteConfigProto(GetConfig());
}
void SetSafetyTipPatternsWithFlagType(
......@@ -43,7 +43,7 @@ void SetSafetyTipPatternsWithFlagType(
page->set_type(type);
}
safety_tips::SetRemoteConfigProto(std::move(config_proto));
SetSafetyTipsRemoteConfigProto(std::move(config_proto));
}
void SetSafetyTipBadRepPatterns(std::vector<std::string> patterns) {
......@@ -59,5 +59,5 @@ void SetSafetyTipAllowlistPatterns(std::vector<std::string> patterns) {
config_proto->add_allowed_pattern();
page->set_pattern(pattern);
}
safety_tips::SetRemoteConfigProto(std::move(config_proto));
SetSafetyTipsRemoteConfigProto(std::move(config_proto));
}
......@@ -14,8 +14,6 @@ class WebContents;
class GURL;
namespace safety_tips {
// Represents the different user interactions with a Safety Tip dialog.
//
// These values are persisted to logs. Entries should not be renumbered and
......@@ -51,6 +49,4 @@ void ShowSafetyTipDialog(
const GURL& suggested_url,
base::OnceCallback<void(SafetyTipInteraction)> close_callback);
} // namespace safety_tips
#endif // CHROME_BROWSER_REPUTATION_SAFETY_TIP_UI_H_
......@@ -14,10 +14,7 @@
#include "content/public/browser/web_contents.h"
#include "ui/base/l10n/l10n_util.h"
namespace safety_tips {
// URL that the "leave site" button aborts to.
const char kSafeUrl[] = "chrome://newtab";
const char kSafetyTipLeaveSiteUrl[] = "chrome://newtab";
void RecordSafetyTipInteractionHistogram(content::WebContents* web_contents,
SafetyTipInteraction interaction) {
......@@ -31,7 +28,8 @@ void RecordSafetyTipInteractionHistogram(content::WebContents* web_contents,
interaction);
}
void LeaveSite(content::WebContents* web_contents, const GURL& safe_url) {
void LeaveSiteFromSafetyTip(content::WebContents* web_contents,
const GURL& safe_url) {
RecordSafetyTipInteractionHistogram(web_contents,
SafetyTipInteraction::kLeaveSite);
content::OpenURLParams params(
......@@ -41,7 +39,7 @@ void LeaveSite(content::WebContents* web_contents, const GURL& safe_url) {
web_contents->OpenURL(params);
}
void OpenHelpCenter(content::WebContents* web_contents) {
void OpenHelpCenterFromSafetyTip(content::WebContents* web_contents) {
RecordSafetyTipInteractionHistogram(web_contents,
SafetyTipInteraction::kLearnMore);
web_contents->OpenURL(content::OpenURLParams(
......@@ -126,5 +124,3 @@ int GetSafetyTipLeaveButtonId(security_state::SafetyTipStatus warning_type) {
NOTREACHED();
return 0;
}
} // namespace safety_tips
......@@ -14,10 +14,8 @@ namespace content {
class WebContents;
}
namespace safety_tips {
// URL that the "leave site" button aborts to by default.
extern const char kSafeUrl[];
extern const char kSafetyTipLeaveSiteUrl[];
// Records a histogram for a user's interaction with a Safety Tip in the given
// |web_contents|.
......@@ -26,11 +24,12 @@ void RecordSafetyTipInteractionHistogram(content::WebContents* web_contents,
// Invokes action when 'leave site' button is clicked, and records a histogram.
// Navigates to a safe URL, replacing the current page in the process.
void LeaveSite(content::WebContents* web_contents, const GURL& safe_url);
void LeaveSiteFromSafetyTip(content::WebContents* web_contents,
const GURL& safe_url);
// Invoke action when 'Learn more' button is clicked, and records a histogram.
// Navigates to the help center URL.
void OpenHelpCenter(content::WebContents* web_contents);
void OpenHelpCenterFromSafetyTip(content::WebContents* web_contents);
// Get the titles, descriptions, and button strings or IDs needed to describe
// the applicable warning type. Handles both Android and desktop warnings.
......@@ -44,6 +43,4 @@ base::string16 GetSafetyTipDescription(
const GURL& suggested_url);
int GetSafetyTipLeaveButtonId(security_state::SafetyTipStatus warning_type);
} // namespace safety_tips
#endif // CHROME_BROWSER_REPUTATION_SAFETY_TIP_UI_HELPER_H_
......@@ -30,17 +30,14 @@ class SafetyTipsConfigSingleton {
} // namespace
namespace safety_tips {
// static
void SetRemoteConfigProto(
void SetSafetyTipsRemoteConfigProto(
std::unique_ptr<chrome_browser_safety_tips::SafetyTipsConfig> proto) {
SafetyTipsConfigSingleton::GetInstance().SetProto(std::move(proto));
}
// static
const chrome_browser_safety_tips::SafetyTipsConfig* GetRemoteConfigProto() {
const chrome_browser_safety_tips::SafetyTipsConfig*
GetSafetyTipsRemoteConfigProto() {
return SafetyTipsConfigSingleton::GetInstance().GetProto();
}
} // namespace safety_tips
......@@ -9,19 +9,16 @@
#include "chrome/browser/reputation/safety_tips.pb.h"
namespace safety_tips {
// Sets the global configuration for Safety Tips retrieved from the component
// updater. The configuration proto contains the list of URLs that can trigger
// a safety tip.
void SetRemoteConfigProto(
void SetSafetyTipsRemoteConfigProto(
std::unique_ptr<chrome_browser_safety_tips::SafetyTipsConfig> proto);
// Gets the global configuration for Safety Tips as retrieved from the component
// updater. The configuration proto contains the list of URLs that can trigger
// a safety tip.
const chrome_browser_safety_tips::SafetyTipsConfig* GetRemoteConfigProto();
} // namespace safety_tips
const chrome_browser_safety_tips::SafetyTipsConfig*
GetSafetyTipsRemoteConfigProto();
#endif // CHROME_BROWSER_REPUTATION_SAFETY_TIPS_CONFIG_H_
......@@ -158,9 +158,8 @@ SecurityStateTabHelper::GetVisibleSecurityState() {
// information is still being initialized, thus no need to check for that.
state->malicious_content_status = GetMaliciousContentStatus();
safety_tips::ReputationWebContentsObserver* reputation_web_contents_observer =
safety_tips::ReputationWebContentsObserver::FromWebContents(
web_contents());
ReputationWebContentsObserver* reputation_web_contents_observer =
ReputationWebContentsObserver::FromWebContents(web_contents());
state->safety_tip_info =
reputation_web_contents_observer
? reputation_web_contents_observer
......
......@@ -255,8 +255,7 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) {
web_contents);
safe_browsing::TriggerCreator::MaybeCreateTriggersForWebContents(
profile, web_contents);
safety_tips::ReputationWebContentsObserver::CreateForWebContents(
web_contents);
ReputationWebContentsObserver::CreateForWebContents(web_contents);
SearchEngineTabHelper::CreateForWebContents(web_contents);
SecurityStateTabHelper::CreateForWebContents(web_contents);
if (SiteEngagementService::IsEnabled())
......
......@@ -996,7 +996,7 @@ void PageInfoBubbleView::StyledLabelLinkClicked(views::StyledLabel* label,
switch (label->GetID()) {
case PageInfoBubbleView::VIEW_ID_PAGE_INFO_LABEL_SECURITY_DETAILS:
if (GetSecurityDescriptionType() == SecurityDescriptionType::SAFETY_TIP) {
safety_tips::OpenHelpCenter(web_contents());
OpenHelpCenterFromSafetyTip(web_contents());
} else {
web_contents()->OpenURL(content::OpenURLParams(
GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(),
......
......@@ -30,8 +30,6 @@
#include "ui/views/window/dialog_client_view.h"
#include "url/gurl.h"
using security_state::SafetyTipStatus;
namespace {
int GetSafetyTipBannerId(security_state::SafetyTipStatus safety_tip_status) {
......@@ -76,7 +74,7 @@ SafetyTipPageInfoBubbleView::SafetyTipPageInfoBubbleView(
security_state::SafetyTipStatus safety_tip_status,
const GURL& url,
const GURL& suggested_url,
base::OnceCallback<void(safety_tips::SafetyTipInteraction)> close_callback)
base::OnceCallback<void(SafetyTipInteraction)> close_callback)
: PageInfoBubbleViewBase(anchor_view,
anchor_rect,
parent_window,
......@@ -91,7 +89,7 @@ SafetyTipPageInfoBubbleView::SafetyTipPageInfoBubbleView(
set_close_on_deactivate(false);
const base::string16 title_text =
safety_tips::GetSafetyTipTitle(safety_tip_status, suggested_url);
GetSafetyTipTitle(safety_tip_status, suggested_url);
set_window_title(title_text);
views::BubbleDialogDelegateView::CreateBubble(this);
......@@ -154,9 +152,8 @@ SafetyTipPageInfoBubbleView::SafetyTipPageInfoBubbleView(
layout_provider->GetDistanceMetric(DISTANCE_CONTROL_LIST_VERTICAL);
bottom_layout->StartRowWithPadding(views::GridLayout::kFixedSize, kColumnId,
views::GridLayout::kFixedSize, spacing);
auto text_label =
std::make_unique<views::Label>(safety_tips::GetSafetyTipDescription(
safety_tip_status, url_, suggested_url_));
auto text_label = std::make_unique<views::Label>(
GetSafetyTipDescription(safety_tip_status, url_, suggested_url_));
text_label->SetMultiLine(true);
text_label->SetLineHeight(20);
text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
......@@ -211,9 +208,8 @@ SafetyTipPageInfoBubbleView::SafetyTipPageInfoBubbleView(
// Leave site button.
std::unique_ptr<views::Button> leave_button(
views::MdTextButton::CreateSecondaryUiBlueButton(
this,
l10n_util::GetStringUTF16(
safety_tips::GetSafetyTipLeaveButtonId(safety_tip_status))));
this, l10n_util::GetStringUTF16(
GetSafetyTipLeaveButtonId(safety_tip_status))));
leave_button->SetID(PageInfoBubbleView::VIEW_ID_PAGE_INFO_BUTTON_LEAVE_SITE);
leave_button_ = button_layout->AddView(std::move(leave_button));
......@@ -250,15 +246,15 @@ void SafetyTipPageInfoBubbleView::OnWidgetDestroying(views::Widget* widget) {
// stumble there again, we should warn again.
break;
case views::Widget::ClosedReason::kEscKeyPressed:
action_taken_ = safety_tips::SafetyTipInteraction::kDismissWithEsc;
action_taken_ = SafetyTipInteraction::kDismissWithEsc;
should_set_ignore = true;
break;
case views::Widget::ClosedReason::kCloseButtonClicked:
action_taken_ = safety_tips::SafetyTipInteraction::kDismissWithClose;
action_taken_ = SafetyTipInteraction::kDismissWithClose;
should_set_ignore = true;
break;
case views::Widget::ClosedReason::kCancelButtonClicked:
action_taken_ = safety_tips::SafetyTipInteraction::kDismissWithIgnore;
action_taken_ = SafetyTipInteraction::kDismissWithIgnore;
should_set_ignore = true;
break;
}
......@@ -266,7 +262,7 @@ void SafetyTipPageInfoBubbleView::OnWidgetDestroying(views::Widget* widget) {
if (should_set_ignore) {
Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
if (browser) {
safety_tips::ReputationService::Get(browser->profile())
ReputationService::Get(browser->profile())
->SetUserIgnore(web_contents(), url_, action_taken_);
}
}
......@@ -276,15 +272,16 @@ void SafetyTipPageInfoBubbleView::ButtonPressed(views::Button* button,
const ui::Event& event) {
switch (button->GetID()) {
case PageInfoBubbleView::VIEW_ID_PAGE_INFO_BUTTON_LEAVE_SITE:
action_taken_ = safety_tips::SafetyTipInteraction::kLeaveSite;
safety_tips::LeaveSite(web_contents(),
safety_tip_status_ == SafetyTipStatus::kLookalike
? suggested_url_
: GURL(safety_tips::kSafeUrl));
action_taken_ = SafetyTipInteraction::kLeaveSite;
LeaveSiteFromSafetyTip(
web_contents(),
safety_tip_status_ == security_state::SafetyTipStatus::kLookalike
? suggested_url_
: GURL(kSafetyTipLeaveSiteUrl));
return;
case PageInfoBubbleView::VIEW_ID_PAGE_INFO_BUTTON_IGNORE_WARNING:
action_taken_ = safety_tips::SafetyTipInteraction::kDismiss;
action_taken_ = SafetyTipInteraction::kDismiss;
GetWidget()->CloseWithReason(
views::Widget::ClosedReason::kCancelButtonClicked);
return;
......@@ -296,12 +293,10 @@ void SafetyTipPageInfoBubbleView::StyledLabelLinkClicked(
views::StyledLabel* label,
const gfx::Range& range,
int event_flags) {
action_taken_ = safety_tips::SafetyTipInteraction::kLearnMore;
safety_tips::OpenHelpCenter(web_contents());
action_taken_ = SafetyTipInteraction::kLearnMore;
OpenHelpCenterFromSafetyTip(web_contents());
}
namespace safety_tips {
void ShowSafetyTipDialog(
content::WebContents* web_contents,
security_state::SafetyTipStatus safety_tip_status,
......@@ -331,16 +326,13 @@ void ShowSafetyTipDialog(
bubble->GetWidget()->Show();
}
} // namespace safety_tips
PageInfoBubbleViewBase* CreateSafetyTipBubbleForTesting(
gfx::NativeView parent_view,
content::WebContents* web_contents,
security_state::SafetyTipStatus safety_tip_status,
const GURL& virtual_url,
const GURL& suggested_url,
base::OnceCallback<void(safety_tips::SafetyTipInteraction)>
close_callback) {
base::OnceCallback<void(SafetyTipInteraction)> close_callback) {
return new SafetyTipPageInfoBubbleView(
nullptr, gfx::Rect(), parent_view, web_contents, safety_tip_status,
virtual_url, suggested_url, std::move(close_callback));
......
......@@ -45,8 +45,7 @@ class SafetyTipPageInfoBubbleView : public PageInfoBubbleViewBase,
security_state::SafetyTipStatus safety_tip_status,
const GURL& url,
const GURL& suggested_url,
base::OnceCallback<void(safety_tips::SafetyTipInteraction)>
close_callback);
base::OnceCallback<void(SafetyTipInteraction)> close_callback);
~SafetyTipPageInfoBubbleView() override;
// views::WidgetObserver:
......@@ -79,9 +78,8 @@ class SafetyTipPageInfoBubbleView : public PageInfoBubbleViewBase,
views::StyledLabel* info_button_;
views::Button* ignore_button_;
views::Button* leave_button_;
base::OnceCallback<void(safety_tips::SafetyTipInteraction)> close_callback_;
safety_tips::SafetyTipInteraction action_taken_ =
safety_tips::SafetyTipInteraction::kNoAction;
base::OnceCallback<void(SafetyTipInteraction)> close_callback_;
SafetyTipInteraction action_taken_ = SafetyTipInteraction::kNoAction;
DISALLOW_COPY_AND_ASSIGN(SafetyTipPageInfoBubbleView);
};
......@@ -93,6 +91,6 @@ PageInfoBubbleViewBase* CreateSafetyTipBubbleForTesting(
security_state::SafetyTipStatus safety_tip_status,
const GURL& virtual_url,
const GURL& suggested_url,
base::OnceCallback<void(safety_tips::SafetyTipInteraction)> close_callback);
base::OnceCallback<void(SafetyTipInteraction)> close_callback);
#endif // CHROME_BROWSER_UI_VIEWS_PAGE_INFO_SAFETY_TIP_PAGE_INFO_BUBBLE_VIEW_H_
......@@ -648,7 +648,7 @@ IN_PROC_BROWSER_TEST_P(SafetyTipPageInfoBubbleViewBrowserTest,
CloseWarningLeaveSite(browser());
histogram_tester.ExpectUniqueSample(
kHistogramPrefix + "SafetyTip_Lookalike",
safety_tips::SafetyTipInteraction::kLeaveSite, 1);
SafetyTipInteraction::kLeaveSite, 1);
}
{
......@@ -663,10 +663,10 @@ IN_PROC_BROWSER_TEST_P(SafetyTipPageInfoBubbleViewBrowserTest,
CloseWarningIgnore(views::Widget::ClosedReason::kCloseButtonClicked);
histogram_tester.ExpectBucketCount(
kHistogramPrefix + "SafetyTip_BadReputation",
safety_tips::SafetyTipInteraction::kDismiss, 1);
SafetyTipInteraction::kDismiss, 1);
histogram_tester.ExpectBucketCount(
kHistogramPrefix + "SafetyTip_BadReputation",
safety_tips::SafetyTipInteraction::kDismissWithClose, 1);
SafetyTipInteraction::kDismissWithClose, 1);
}
// Test that the specific dismissal type is recorded correctly.
......@@ -678,10 +678,10 @@ IN_PROC_BROWSER_TEST_P(SafetyTipPageInfoBubbleViewBrowserTest,
CloseWarningIgnore(views::Widget::ClosedReason::kEscKeyPressed);
histogram_tester.ExpectBucketCount(
kHistogramPrefix + "SafetyTip_BadReputation",
safety_tips::SafetyTipInteraction::kDismiss, 1);
SafetyTipInteraction::kDismiss, 1);
histogram_tester.ExpectBucketCount(
kHistogramPrefix + "SafetyTip_BadReputation",
safety_tips::SafetyTipInteraction::kDismissWithEsc, 1);
SafetyTipInteraction::kDismissWithEsc, 1);
}
{
......@@ -692,10 +692,10 @@ IN_PROC_BROWSER_TEST_P(SafetyTipPageInfoBubbleViewBrowserTest,
CloseWarningIgnore(views::Widget::ClosedReason::kCancelButtonClicked);
histogram_tester.ExpectBucketCount(
kHistogramPrefix + "SafetyTip_BadReputation",
safety_tips::SafetyTipInteraction::kDismiss, 1);
SafetyTipInteraction::kDismiss, 1);
histogram_tester.ExpectBucketCount(
kHistogramPrefix + "SafetyTip_BadReputation",
safety_tips::SafetyTipInteraction::kDismissWithIgnore, 1);
SafetyTipInteraction::kDismissWithIgnore, 1);
}
}
......
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