Commit 08471584 authored by Tommy Martino's avatar Tommy Martino Committed by Chromium LUCI CQ

[SH] Add sites to blocklist

This adds a handful of sites to the Shared Highlighting blocklist. It
also strips m. from hosts, similar to what we already do for www.

Bug: 1157981
Change-Id: If907ba6bd79529e98a634918e47a21dd1f2730cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2629571Reviewed-by: default avatarSebastien Lalancette <seblalancette@chromium.org>
Commit-Queue: Tommy Martino <tmartino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843753}
parent ddad167d
...@@ -19,13 +19,23 @@ bool ShouldOfferLinkToText(const GURL& url) { ...@@ -19,13 +19,23 @@ bool ShouldOfferLinkToText(const GURL& url) {
// against the RE stored in the value. For example, {"foo.com", ".*"} means // against the RE stored in the value. For example, {"foo.com", ".*"} means
// any page on the foo.com domain. // any page on the foo.com domain.
const static std::map<std::string, std::string> kBlocklist = { const static std::map<std::string, std::string> kBlocklist = {
{"youtube.com", ".*"}, {"facebook.com", ".*"},
// TODO(crbug.com/1157981): special case this to cover other Google TLDs // TODO(crbug.com/1157981): special case this to cover other Google TLDs
{"google.com", "^\\/amp\\/.*"}}; {"google.com", "^\\/amp\\/.*"},
{"instagram.com", ".*"},
{"reddit.com", ".*"},
{"web.whatsapp.com", ".*"},
{"youtube.com", ".*"},
};
std::string domain = url.host();
if (domain.compare(0, 4, "www.") == 0) {
domain = domain.substr(4);
} else if (domain.compare(0, 2, "m.") == 0) {
domain = domain.substr(2);
}
const std::string domain = url.host().compare(0, 4, "www.") == 0
? url.host().substr(4)
: url.host();
auto it = kBlocklist.find(domain); auto it = kBlocklist.find(domain);
if (it != kBlocklist.end()) { if (it != kBlocklist.end()) {
return !re2::RE2::FullMatch(url.path(), it->second); return !re2::RE2::FullMatch(url.path(), it->second);
......
...@@ -15,6 +15,8 @@ namespace { ...@@ -15,6 +15,8 @@ namespace {
TEST(DisabledSitesTest, AllPaths) { TEST(DisabledSitesTest, AllPaths) {
EXPECT_FALSE(ShouldOfferLinkToText(GURL("https://www.youtube.com"))); EXPECT_FALSE(ShouldOfferLinkToText(GURL("https://www.youtube.com")));
EXPECT_FALSE(ShouldOfferLinkToText(GURL("https://www.youtube.com/somepage"))); EXPECT_FALSE(ShouldOfferLinkToText(GURL("https://www.youtube.com/somepage")));
EXPECT_FALSE(ShouldOfferLinkToText(GURL("https://m.youtube.com")));
EXPECT_FALSE(ShouldOfferLinkToText(GURL("https://m.youtube.com/somepage")));
EXPECT_FALSE(ShouldOfferLinkToText(GURL("https://youtube.com"))); EXPECT_FALSE(ShouldOfferLinkToText(GURL("https://youtube.com")));
EXPECT_FALSE(ShouldOfferLinkToText(GURL("https://youtube.com/somepage"))); EXPECT_FALSE(ShouldOfferLinkToText(GURL("https://youtube.com/somepage")));
} }
......
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