1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <unordered_set>
#include "components/shared_highlighting/core/common/disabled_sites.h"
#include "base/containers/fixed_flat_map.h"
#include "base/feature_list.h"
#include "base/strings/string_util.h"
#include "components/shared_highlighting/core/common/shared_highlighting_features.h"
#include "third_party/re2/src/re2/re2.h"
namespace shared_highlighting {
static auto CreateBlocklist() {
if (base::FeatureList::IsEnabled(kSharedHighlightingRefinedBlocklist)) {
return base::MakeFixedFlatMap<base::StringPiece, base::StringPiece>(
{{"facebook.com", "(?!.*(about)).*"},
// TODO(crbug.com/1157981): special case this to cover other Google
// TLDs
{"google.com", "^\\/amp\\/.*"},
{"instagram.com", "(?!.*(/p/)).*"},
{"mail.google.com", ".*"},
{"outlook.live.com", ".*"},
{"reddit.com", "(?!.*(comments)).*"},
{"twitter.com", "(?!.*(status)).*"},
{"web.whatsapp.com", ".*"},
{"youtube.com", "?!.*(about|community)).*"}});
} else {
return base::MakeFixedFlatMap<base::StringPiece, base::StringPiece>(
{{"facebook.com", ".*"},
// TODO(crbug.com/1157981): special case this to cover other Google
// TLDs
{"google.com", "^\\/amp\\/.*"},
{"instagram.com", ".*"},
{"mail.google.com", ".*"},
{"outlook.live.com", ".*"},
{"reddit.com", ".*"},
{"twitter.com", ".*"},
{"web.whatsapp.com", ".*"},
{"youtube.com", ".*"}});
}
}
bool ShouldOfferLinkToText(const GURL& url) {
// If a URL's host matches a key in this map, then the path will be tested
// against the RE stored in the value. For example, {"foo.com", ".*"} means
// any page on the foo.com domain.
static auto kBlocklist = CreateBlocklist();
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);
} else if (domain.compare(0, 7, "mobile.") == 0) {
domain = domain.substr(7);
}
if (base::FeatureList::IsEnabled(kSharedHighlightingAmp) &&
domain.compare("google.com") == 0) {
return true;
}
auto* it = kBlocklist.find(domain);
if (it != kBlocklist.end()) {
return !re2::RE2::FullMatch(url.path(), it->second.data());
}
return true;
}
bool SupportsLinkGenerationInIframe(GURL main_frame_url) {
const std::unordered_set<std::string> good_hosts = {
"www.google.com", "m.google.com", "mobile.google.com",
"www.bing.com", "m.bing.com", "mobile.bing.com"};
return main_frame_url.SchemeIs(url::kHttpsScheme) &&
good_hosts.find(main_frame_url.host()) != good_hosts.end() &&
base::StartsWith(main_frame_url.path(), "/amp/");
}
} // namespace shared_highlighting
|