summaryrefslogtreecommitdiff
path: root/chromium/components/shared_highlighting
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2021-05-20 09:47:09 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2021-06-07 11:15:42 +0000
commit189d4fd8fad9e3c776873be51938cd31a42b6177 (patch)
tree6497caeff5e383937996768766ab3bb2081a40b2 /chromium/components/shared_highlighting
parent8bc75099d364490b22f43a7ce366b366c08f4164 (diff)
downloadqtwebengine-chromium-189d4fd8fad9e3c776873be51938cd31a42b6177.tar.gz
BASELINE: Update Chromium to 90.0.4430.221
Change-Id: Iff4d9d18d2fcf1a576f3b1f453010f744a232920 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/shared_highlighting')
-rw-r--r--chromium/components/shared_highlighting/DIR_METADATA5
-rw-r--r--chromium/components/shared_highlighting/OWNERS5
-rw-r--r--chromium/components/shared_highlighting/core/common/BUILD.gn6
-rw-r--r--chromium/components/shared_highlighting/core/common/DEPS1
-rw-r--r--chromium/components/shared_highlighting/core/common/disabled_sites.cc52
-rw-r--r--chromium/components/shared_highlighting/core/common/disabled_sites.h20
-rw-r--r--chromium/components/shared_highlighting/core/common/disabled_sites_unittest.cc56
-rw-r--r--chromium/components/shared_highlighting/core/common/shared_highlighting_features.cc17
-rw-r--r--chromium/components/shared_highlighting/core/common/shared_highlighting_features.h23
-rw-r--r--chromium/components/shared_highlighting/core/common/shared_highlighting_metrics.cc9
-rw-r--r--chromium/components/shared_highlighting/core/common/shared_highlighting_metrics.h14
-rw-r--r--chromium/components/shared_highlighting/core/common/text_fragments_constants.cc6
-rw-r--r--chromium/components/shared_highlighting/core/common/text_fragments_constants.h6
13 files changed, 216 insertions, 4 deletions
diff --git a/chromium/components/shared_highlighting/DIR_METADATA b/chromium/components/shared_highlighting/DIR_METADATA
new file mode 100644
index 00000000000..eafcc7d2d2e
--- /dev/null
+++ b/chromium/components/shared_highlighting/DIR_METADATA
@@ -0,0 +1,5 @@
+monorail {
+ component: "UI>Browser>SharedHighlighting"
+}
+
+team_email: "chrome-shared-highlighting@google.com"
diff --git a/chromium/components/shared_highlighting/OWNERS b/chromium/components/shared_highlighting/OWNERS
index eab70ff53e9..a535e7086dc 100644
--- a/chromium/components/shared_highlighting/OWNERS
+++ b/chromium/components/shared_highlighting/OWNERS
@@ -1,5 +1,4 @@
+gayane@chromium.org
sebsg@chromium.org
seblalancette@chromium.org
-
-# COMPONENT: UI>Browser>SharedHighlighting
-# TEAM: chrome-shared-highlighting@google.com \ No newline at end of file
+tmartino@chromium.org
diff --git a/chromium/components/shared_highlighting/core/common/BUILD.gn b/chromium/components/shared_highlighting/core/common/BUILD.gn
index 39e5b8a3858..0cd5cd6206d 100644
--- a/chromium/components/shared_highlighting/core/common/BUILD.gn
+++ b/chromium/components/shared_highlighting/core/common/BUILD.gn
@@ -4,6 +4,10 @@
static_library("common") {
sources = [
+ "disabled_sites.cc",
+ "disabled_sites.h",
+ "shared_highlighting_features.cc",
+ "shared_highlighting_features.h",
"shared_highlighting_metrics.cc",
"shared_highlighting_metrics.h",
"text_fragment.cc",
@@ -19,12 +23,14 @@ static_library("common") {
"//components/search_engines:search_engine_utils",
"//services/metrics/public/cpp:metrics_cpp",
"//services/metrics/public/cpp:ukm_builders",
+ "//third_party/re2",
]
}
source_set("unit_tests") {
testonly = true
sources = [
+ "disabled_sites_unittest.cc",
"shared_highlighting_metrics_unittest.cc",
"text_fragment_unittest.cc",
"text_fragments_utils_unittest.cc",
diff --git a/chromium/components/shared_highlighting/core/common/DEPS b/chromium/components/shared_highlighting/core/common/DEPS
index f5a24182dff..22038631b03 100644
--- a/chromium/components/shared_highlighting/core/common/DEPS
+++ b/chromium/components/shared_highlighting/core/common/DEPS
@@ -4,5 +4,6 @@ include_rules = [
"+components/ukm/test_ukm_recorder.h",
"+net/base",
"+services/metrics/public",
+ "+third_party/re2",
"+url",
] \ No newline at end of file
diff --git a/chromium/components/shared_highlighting/core/common/disabled_sites.cc b/chromium/components/shared_highlighting/core/common/disabled_sites.cc
new file mode 100644
index 00000000000..27ba6a4992b
--- /dev/null
+++ b/chromium/components/shared_highlighting/core/common/disabled_sites.cc
@@ -0,0 +1,52 @@
+// 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 "components/shared_highlighting/core/common/disabled_sites.h"
+
+#include "base/feature_list.h"
+#include "components/shared_highlighting/core/common/shared_highlighting_features.h"
+#include "third_party/re2/src/re2/re2.h"
+
+#include <map>
+#include <utility>
+
+namespace shared_highlighting {
+
+bool ShouldOfferLinkToText(const GURL& url) {
+ if (base::FeatureList::IsEnabled(kSharedHighlightingUseBlocklist)) {
+ // 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.
+ const static std::map<std::string, std::string> kBlocklist = {
+ {"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", ".*"},
+
+ };
+
+ 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);
+ }
+
+ auto it = kBlocklist.find(domain);
+ if (it != kBlocklist.end()) {
+ return !re2::RE2::FullMatch(url.path(), it->second);
+ }
+ }
+ return true;
+}
+
+} // namespace shared_highlighting
diff --git a/chromium/components/shared_highlighting/core/common/disabled_sites.h b/chromium/components/shared_highlighting/core/common/disabled_sites.h
new file mode 100644
index 00000000000..01d509e631f
--- /dev/null
+++ b/chromium/components/shared_highlighting/core/common/disabled_sites.h
@@ -0,0 +1,20 @@
+// 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.
+
+#ifndef COMPONENTS_SHARED_HIGHLIGHTING_CORE_COMMON_DISABLED_SITES_H_
+#define COMPONENTS_SHARED_HIGHLIGHTING_CORE_COMMON_DISABLED_SITES_H_
+
+#include "url/gurl.h"
+
+namespace shared_highlighting {
+
+// Returns true iff Link to Text menu options should be enabled on this page.
+// Uses a blocklist to identify certain sites where personalized or dynamic
+// content make it unlikely that a generated URL will actually work when
+// shared.
+bool ShouldOfferLinkToText(const GURL& url);
+
+} // namespace shared_highlighting
+
+#endif // COMPONENTS_SHARED_HIGHLIGHTING_CORE_COMMON_DISABLED_SITES_H_
diff --git a/chromium/components/shared_highlighting/core/common/disabled_sites_unittest.cc b/chromium/components/shared_highlighting/core/common/disabled_sites_unittest.cc
new file mode 100644
index 00000000000..9cd99242198
--- /dev/null
+++ b/chromium/components/shared_highlighting/core/common/disabled_sites_unittest.cc
@@ -0,0 +1,56 @@
+// 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 "components/shared_highlighting/core/common/disabled_sites.h"
+
+#include "base/test/scoped_feature_list.h"
+#include "components/shared_highlighting/core/common/shared_highlighting_features.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+namespace shared_highlighting {
+namespace {
+
+TEST(DisabledSitesTest, AllPaths) {
+ EXPECT_FALSE(ShouldOfferLinkToText(GURL("https://www.youtube.com")));
+ 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/somepage")));
+}
+
+TEST(DisabledSitesTest, SpecificPages) {
+ // Paths starting with /amp/ are disabled.
+ EXPECT_FALSE(ShouldOfferLinkToText(GURL("https://www.google.com/amp/")));
+ EXPECT_FALSE(ShouldOfferLinkToText(GURL("https://www.google.com/amp/foo")));
+ EXPECT_FALSE(ShouldOfferLinkToText(GURL("https://google.com/amp/")));
+ EXPECT_FALSE(ShouldOfferLinkToText(GURL("https://google.com/amp/foo")));
+
+ // Other paths are not.
+ EXPECT_TRUE(ShouldOfferLinkToText(GURL("https://www.google.com")));
+ EXPECT_TRUE(ShouldOfferLinkToText(GURL("https://www.google.com/somepage")));
+ EXPECT_TRUE(ShouldOfferLinkToText(GURL("https://google.com")));
+ EXPECT_TRUE(ShouldOfferLinkToText(GURL("https://google.com/somepage")));
+
+ // Paths with /amp/ later on are also not affected.
+ EXPECT_TRUE(ShouldOfferLinkToText(GURL("https://google.com/foo/amp/")));
+ EXPECT_TRUE(ShouldOfferLinkToText(GURL("https://google.com/foo/amp/bar")));
+}
+
+TEST(DisabledSitesTest, NonMatchingHost) {
+ EXPECT_TRUE(ShouldOfferLinkToText(GURL("https://www.example.com")));
+}
+
+TEST(DisabledSitesTest, FeatureDisabled) {
+ base::test::ScopedFeatureList feature;
+ feature.InitAndDisableFeature(kSharedHighlightingUseBlocklist);
+
+ EXPECT_TRUE(ShouldOfferLinkToText(GURL("https://www.youtube.com")));
+ EXPECT_TRUE(ShouldOfferLinkToText(GURL("https://www.google.com/amp/")));
+ EXPECT_TRUE(ShouldOfferLinkToText(GURL("https://www.example.com")));
+}
+
+} // namespace
+} // namespace shared_highlighting
diff --git a/chromium/components/shared_highlighting/core/common/shared_highlighting_features.cc b/chromium/components/shared_highlighting/core/common/shared_highlighting_features.cc
new file mode 100644
index 00000000000..da51cb506a7
--- /dev/null
+++ b/chromium/components/shared_highlighting/core/common/shared_highlighting_features.cc
@@ -0,0 +1,17 @@
+// Copyright 2021 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 "components/shared_highlighting/core/common/shared_highlighting_features.h"
+
+#include "base/feature_list.h"
+
+namespace shared_highlighting {
+
+const base::Feature kPreemptiveLinkToTextGeneration{
+ "PreemptiveLinkToTextGeneration", base::FEATURE_DISABLED_BY_DEFAULT};
+
+const base::Feature kSharedHighlightingUseBlocklist{
+ "SharedHighlightingUseBlocklist", base::FEATURE_ENABLED_BY_DEFAULT};
+
+} // namespace shared_highlighting
diff --git a/chromium/components/shared_highlighting/core/common/shared_highlighting_features.h b/chromium/components/shared_highlighting/core/common/shared_highlighting_features.h
new file mode 100644
index 00000000000..5e5c44edfe8
--- /dev/null
+++ b/chromium/components/shared_highlighting/core/common/shared_highlighting_features.h
@@ -0,0 +1,23 @@
+// Copyright 2021 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.
+
+#ifndef COMPONENTS_SHARED_HIGHLIGHTING_CORE_COMMON_SHARED_HIGHLIGHTING_FEATURES_H_
+#define COMPONENTS_SHARED_HIGHLIGHTING_CORE_COMMON_SHARED_HIGHLIGHTING_FEATURES_H_
+
+namespace base {
+struct Feature;
+}
+
+namespace shared_highlighting {
+
+// Enables link to text to be generated in advance.
+extern const base::Feature kPreemptiveLinkToTextGeneration;
+
+// If enabled, a blocklist will disable link generation on certain pages where
+// the feature is unlikely to work correctly.
+extern const base::Feature kSharedHighlightingUseBlocklist;
+
+} // namespace shared_highlighting
+
+#endif // COMPONENTS_SHARED_HIGHLIGHTING_CORE_COMMON_SHARED_HIGHLIGHTING_FEATURES_H_
diff --git a/chromium/components/shared_highlighting/core/common/shared_highlighting_metrics.cc b/chromium/components/shared_highlighting/core/common/shared_highlighting_metrics.cc
index b4bd12ab06f..a30e7833715 100644
--- a/chromium/components/shared_highlighting/core/common/shared_highlighting_metrics.cc
+++ b/chromium/components/shared_highlighting/core/common/shared_highlighting_metrics.cc
@@ -56,6 +56,7 @@ void LogTextFragmentSelectorCount(int count) {
base::UmaHistogramCounts100("TextFragmentAnchor.SelectorCount", count);
}
+// TODO(gayane): Replace by one function LogGenerateError(Error).
void LogGenerateErrorTabHidden() {
LogLinkGenerationErrorReason(LinkGenerationError::kTabHidden);
}
@@ -72,6 +73,14 @@ void LogGenerateErrorIFrame() {
LogLinkGenerationErrorReason(LinkGenerationError::kIFrame);
}
+void LogGenerateErrorBlockList() {
+ LogLinkGenerationErrorReason(LinkGenerationError::kBlockList);
+}
+
+void LogGenerateErrorTimeout() {
+ LogLinkGenerationErrorReason(LinkGenerationError::kTimeout);
+}
+
void LogGenerateSuccessLatency(base::TimeDelta latency) {
base::UmaHistogramTimes("SharedHighlights.LinkGenerated.TimeToGenerate",
latency);
diff --git a/chromium/components/shared_highlighting/core/common/shared_highlighting_metrics.h b/chromium/components/shared_highlighting/core/common/shared_highlighting_metrics.h
index ea6befeaf84..ce3ff6f0e86 100644
--- a/chromium/components/shared_highlighting/core/common/shared_highlighting_metrics.h
+++ b/chromium/components/shared_highlighting/core/common/shared_highlighting_metrics.h
@@ -38,7 +38,11 @@ enum class LinkGenerationError {
// Timed-out waiting for a link to be generated.
kTimeout = 11,
- kMaxValue = kTimeout
+ // Link generation is not triggered because current page is not supported.
+ // Recorded on Android/Desktop.
+ kBlockList = 12,
+
+ kMaxValue = kBlockList
};
// These values are persisted to logs. Entries should not be renumbered and
@@ -86,6 +90,14 @@ void LogGenerateErrorTabCrash();
// iframe.
void LogGenerateErrorIFrame();
+// Records when link generation was not triggered because selection happened on
+// a blocklisted page.
+void LogGenerateErrorBlockList();
+
+// Records when link generation was not triggered because selection happened on
+// a blocklisted page.
+void LogGenerateErrorTimeout();
+
// Records the latency for successfully generating a link.
void LogGenerateSuccessLatency(base::TimeDelta latency);
diff --git a/chromium/components/shared_highlighting/core/common/text_fragments_constants.cc b/chromium/components/shared_highlighting/core/common/text_fragments_constants.cc
index 4cd3d68ff14..77ae68005ff 100644
--- a/chromium/components/shared_highlighting/core/common/text_fragments_constants.cc
+++ b/chromium/components/shared_highlighting/core/common/text_fragments_constants.cc
@@ -15,4 +15,10 @@ const char kFragmentTextStartKey[] = "textStart";
const char kFragmentTextEndKey[] = "textEnd";
const char kFragmentSuffixKey[] = "suffix";
+// Light purple.
+const int kFragmentTextBackgroundColorARGB = 0xFFE9D2FD;
+
+// Black.
+const int kFragmentTextForegroundColorARGB = 0xFF000000;
+
} // namespace shared_highlighting
diff --git a/chromium/components/shared_highlighting/core/common/text_fragments_constants.h b/chromium/components/shared_highlighting/core/common/text_fragments_constants.h
index 91f3c212e92..4f594c16f88 100644
--- a/chromium/components/shared_highlighting/core/common/text_fragments_constants.h
+++ b/chromium/components/shared_highlighting/core/common/text_fragments_constants.h
@@ -20,6 +20,12 @@ extern const char kFragmentTextStartKey[];
extern const char kFragmentTextEndKey[];
extern const char kFragmentSuffixKey[];
+// Default highlight color stored as a hexadecimal number.
+extern const int kFragmentTextBackgroundColorARGB;
+
+// Default text color stored as a hexadecimal number.
+extern const int kFragmentTextForegroundColorARGB;
+
} // namespace shared_highlighting
#endif // COMPONENTS_SHARED_HIGHLIGHTING_CORE_COMMON_TEXT_FRAGMENTS_CONSTANTS_H_