[NTP] Fix article suggestion clicks contributing to Most Visited tiles
There's a need to distinguish clicks on different elements on the NTP:
a) clicks on Most Visited tiles.
b) clicks on (newly introduced) article suggestions (aka snippets).
The first should contribute to Most Visited tiles (i.e. boost tiles
that have been clicked in the past). The second shouldn't.
We choose to achieve this by specifying a referrer for article
suggestion clicks. This exposes the referrer to third parties, which
has been discussed and considered a desirable feature.
The fix relies on such a workaround due to the current lack of
infrastructure to propagate opaque feature-specific data from upper
layers to navigation history (and sync).
The approach competes with more intrusive/controversial alternatives to
achieve the same:
1. Use page transition types (LINK vs AUTO_BOOKMARK) to distinguish
tile clicks from article suggestion clicks: unfortunately both types
have been used in the past (older versions of Chrome).
2. Introducing a new page transition type or qualifier: this can be
considered a layering violation.
3. Introduce a dummy redirect by means of a data: schema page.
BUG=645895
Review-Url: https://codereview.chromium.org/2338133006
Cr-Commit-Position: refs/heads/master@{#419242}
diff --git a/chrome/browser/history/history_tab_helper.cc b/chrome/browser/history/history_tab_helper.cc
index c633e3c..9e19218 100644
--- a/chrome/browser/history/history_tab_helper.cc
+++ b/chrome/browser/history/history_tab_helper.cc
@@ -30,6 +30,14 @@
DEFINE_WEB_CONTENTS_USER_DATA_KEY(HistoryTabHelper);
+namespace {
+
+// Referrer used for clicks on article suggestions on the NTP.
+const char kChromeContentSuggestionsReferrer[] =
+ "https://www.googleapis.com/auth/chrome-content-suggestions";
+
+} // namespace
+
HistoryTabHelper::HistoryTabHelper(WebContents* web_contents)
: content::WebContentsObserver(web_contents),
received_page_title_(false) {
@@ -58,10 +66,16 @@
bool did_replace_entry,
int nav_entry_id,
const content::FrameNavigateParams& params) {
+ // Clicks on content suggestions on the NTP should not contribute to the
+ // Most Visited tiles in the NTP.
+ const bool consider_for_ntp_most_visited =
+ params.referrer.url != GURL(kChromeContentSuggestionsReferrer);
+
history::HistoryAddPageArgs add_page_args(
params.url, timestamp, history::ContextIDForWebContents(web_contents()),
nav_entry_id, params.referrer.url, params.redirects, params.transition,
- history::SOURCE_BROWSED, did_replace_entry);
+ history::SOURCE_BROWSED, did_replace_entry,
+ consider_for_ntp_most_visited);
if (ui::PageTransitionIsMainFrame(params.transition) &&
virtual_url != params.url) {
// Hack on the "virtual" URL so that it will appear in history. For some