Commit 3978211e authored by Filip Gorski's avatar Filip Gorski Committed by Commit Bot

[Zine] Update the referrer for Feed surfaces, make it configurable

* Updates referrer for content suggestions to https://feed.google.com
* Makes the referrer configurable through Field Trials bound to the
  NTPArticleSuggestions experiment.

Bug: 870750
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I87b0af69e05e9b1c38bf12caade61ebb80f6cee0
Reviewed-on: https://chromium-review.googlesource.com/1185857
Commit-Queue: Filip Gorski <fgorski@chromium.org>
Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586345}
parent 75f6f02d
...@@ -236,6 +236,7 @@ public abstract class ChromeFeatureList { ...@@ -236,6 +236,7 @@ public abstract class ChromeFeatureList {
public static final String NEW_PHOTO_PICKER = "NewPhotoPicker"; public static final String NEW_PHOTO_PICKER = "NewPhotoPicker";
public static final String NO_CREDIT_CARD_ABORT = "NoCreditCardAbort"; public static final String NO_CREDIT_CARD_ABORT = "NoCreditCardAbort";
public static final String NTP_ARTICLE_SUGGESTIONS = "NTPArticleSuggestions";
public static final String NTP_ARTICLE_SUGGESTIONS_EXPANDABLE_HEADER = public static final String NTP_ARTICLE_SUGGESTIONS_EXPANDABLE_HEADER =
"NTPArticleSuggestionsExpandableHeader"; "NTPArticleSuggestionsExpandableHeader";
public static final String NTP_BUTTON = "NTPButton"; public static final String NTP_BUTTON = "NTPButton";
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.suggestions; package org.chromium.chrome.browser.suggestions;
import android.content.res.Resources; import android.content.res.Resources;
import android.text.TextUtils;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R; import org.chromium.chrome.R;
...@@ -17,6 +18,18 @@ import org.chromium.chrome.browser.widget.displaystyle.UiConfig; ...@@ -17,6 +18,18 @@ import org.chromium.chrome.browser.widget.displaystyle.UiConfig;
* Provides configuration details for suggestions. * Provides configuration details for suggestions.
*/ */
public final class SuggestionsConfig { public final class SuggestionsConfig {
/**
* Field trial parameter for referrer URL.
* It must be kept in sync with //components/ntp_suggestions/features.cc
*/
private static final String REFERRER_URL_PARAM = "referrer_url";
/**
* Default value for referrer URL.
* It must be kept in sync with //components/ntp_suggestions/features.cc
*/
private static final String DEFAULT_REFERRER_URL = "https://feed.google.com/";
private SuggestionsConfig() {} private SuggestionsConfig() {}
/** /**
...@@ -67,4 +80,16 @@ public final class SuggestionsConfig { ...@@ -67,4 +80,16 @@ public final class SuggestionsConfig {
return FeatureUtilities.isChromeModernDesignEnabled() return FeatureUtilities.isChromeModernDesignEnabled()
|| ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_MODERN_LAYOUT); || ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_MODERN_LAYOUT);
} }
/** @return The value of referrer URL to use with content suggestions. */
public static String getReferrerUrl() {
String referrerParamValue = ChromeFeatureList.getFieldTrialParamByFeature(
ChromeFeatureList.NTP_ARTICLE_SUGGESTIONS, REFERRER_URL_PARAM);
if (!TextUtils.isEmpty(referrerParamValue)) {
return referrerParamValue;
}
return DEFAULT_REFERRER_URL;
}
} }
...@@ -41,8 +41,6 @@ import org.chromium.ui.widget.Toast; ...@@ -41,8 +41,6 @@ import org.chromium.ui.widget.Toast;
* {@link SuggestionsUiDelegate} implementation. * {@link SuggestionsUiDelegate} implementation.
*/ */
public class SuggestionsNavigationDelegateImpl implements SuggestionsNavigationDelegate { public class SuggestionsNavigationDelegateImpl implements SuggestionsNavigationDelegate {
private static final String CHROME_CONTENT_SUGGESTIONS_REFERRER =
"https://www.googleapis.com/auth/chrome-content-suggestions";
private static final String CHROME_CONTEXTUAL_SUGGESTIONS_REFERRER = private static final String CHROME_CONTEXTUAL_SUGGESTIONS_REFERRER =
"https://goto.google.com/explore-on-content-viewer"; "https://goto.google.com/explore-on-content-viewer";
private static final String NEW_TAB_URL_HELP = private static final String NEW_TAB_URL_HELP =
...@@ -149,8 +147,8 @@ public class SuggestionsNavigationDelegateImpl implements SuggestionsNavigationD ...@@ -149,8 +147,8 @@ public class SuggestionsNavigationDelegateImpl implements SuggestionsNavigationD
// to filter out these history entries for NTP tiles. // to filter out these history entries for NTP tiles.
// TODO(mastiz): Extend this with support for other categories. // TODO(mastiz): Extend this with support for other categories.
if (article.mCategory == KnownCategories.ARTICLES) { if (article.mCategory == KnownCategories.ARTICLES) {
loadUrlParams.setReferrer(new Referrer(CHROME_CONTENT_SUGGESTIONS_REFERRER, loadUrlParams.setReferrer(
WebReferrerPolicy.ALWAYS)); new Referrer(SuggestionsConfig.getReferrerUrl(), WebReferrerPolicy.ALWAYS));
} }
// Set appropriate referrer for contextual suggestions to distinguish them from navigation // Set appropriate referrer for contextual suggestions to distinguish them from navigation
......
...@@ -148,6 +148,7 @@ const base::Feature* kFeaturesExposedToJava[] = { ...@@ -148,6 +148,7 @@ const base::Feature* kFeaturesExposedToJava[] = {
&payments::features::kWebPaymentsSingleAppUiSkip, &payments::features::kWebPaymentsSingleAppUiSkip,
&media::kCafMediaRouterImpl, &media::kCafMediaRouterImpl,
&ntp_snippets::kArticleSuggestionsExpandableHeader, &ntp_snippets::kArticleSuggestionsExpandableHeader,
&ntp_snippets::kArticleSuggestionsFeature,
&ntp_snippets::kIncreasedVisibility, &ntp_snippets::kIncreasedVisibility,
&ntp_snippets::kForeignSessionsSuggestionsFeature, &ntp_snippets::kForeignSessionsSuggestionsFeature,
&ntp_snippets::kNotificationsFeature, &ntp_snippets::kNotificationsFeature,
......
...@@ -224,6 +224,7 @@ source_set("unit_tests") { ...@@ -224,6 +224,7 @@ source_set("unit_tests") {
"contextual/reporting/contextual_suggestions_composite_reporter_unittest.cc", "contextual/reporting/contextual_suggestions_composite_reporter_unittest.cc",
"contextual/reporting/contextual_suggestions_metrics_reporter_unittest.cc", "contextual/reporting/contextual_suggestions_metrics_reporter_unittest.cc",
"contextual/reporting/contextual_suggestions_ukm_entry_unittest.cc", "contextual/reporting/contextual_suggestions_ukm_entry_unittest.cc",
"features_unittest.cc",
"logger_unittest.cc", "logger_unittest.cc",
"reading_list/reading_list_suggestions_provider_unittest.cc", "reading_list/reading_list_suggestions_provider_unittest.cc",
"remote/cached_image_fetcher_unittest.cc", "remote/cached_image_fetcher_unittest.cc",
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "components/ntp_snippets/features.h" #include "components/ntp_snippets/features.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
#include "base/time/clock.h" #include "base/time/clock.h"
#include "components/ntp_snippets/category_rankers/click_based_category_ranker.h" #include "components/ntp_snippets/category_rankers/click_based_category_ranker.h"
#include "components/ntp_snippets/category_rankers/constant_category_ranker.h" #include "components/ntp_snippets/category_rankers/constant_category_ranker.h"
...@@ -166,4 +167,17 @@ std::vector<const base::Feature*> GetAllFeatures() { ...@@ -166,4 +167,17 @@ std::vector<const base::Feature*> GetAllFeatures() {
kAllFeatures, kAllFeatures + arraysize(kAllFeatures)); kAllFeatures, kAllFeatures + arraysize(kAllFeatures));
} }
// Default referrer for the content suggestions.
const char kDefaultReferrerUrl[] = "https://feed.google.com/";
// Provides ability to customize the referrer URL.
// When specifying a referrer through a field trial, it must contain a path.
// In case of default value above the path is empty, but it is specified.
base::FeatureParam<std::string> kArticleSuggestionsReferrerURLParam{
&kArticleSuggestionsFeature, "referrer_url", kDefaultReferrerUrl};
std::string GetContentSuggestionsReferrerURL() {
return kArticleSuggestionsReferrerURLParam.Get();
}
} // namespace ntp_snippets } // namespace ntp_snippets
...@@ -140,6 +140,8 @@ extern const base::Feature kContentSuggestionsDebugLog; ...@@ -140,6 +140,8 @@ extern const base::Feature kContentSuggestionsDebugLog;
// Return all the features as a vector. // Return all the features as a vector.
std::vector<const base::Feature*> GetAllFeatures(); std::vector<const base::Feature*> GetAllFeatures();
// Return a referrer URL for content suggestions.
std::string GetContentSuggestionsReferrerURL();
} // namespace ntp_snippets } // namespace ntp_snippets
#endif // COMPONENTS_NTP_SNIPPETS_FEATURES_H_ #endif // COMPONENTS_NTP_SNIPPETS_FEATURES_H_
// Copyright 2018 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/ntp_snippets/features.h"
#include <map>
#include <string>
#include "base/test/scoped_feature_list.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
namespace ntp_snippets {
namespace {
const char kTestFeedURL[] = "https://test.google.com/";
} // namespace
TEST(FeaturesTest, GetContentSuggestionsReferrerURL_DefaultValue) {
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(kArticleSuggestionsFeature);
EXPECT_EQ("https://feed.google.com/", GetContentSuggestionsReferrerURL());
// In code this will be often used inside of a GURL.
EXPECT_EQ("https://feed.google.com/",
GURL(GetContentSuggestionsReferrerURL()));
EXPECT_EQ("https://feed.google.com/",
GURL(GetContentSuggestionsReferrerURL()).spec());
}
TEST(FeaturesTest, GetContentSuggestionsReferrerURL_ParamValue) {
base::test::ScopedFeatureList feature_list;
std::map<std::string, std::string> parameters;
parameters["referrer_url"] = kTestFeedURL;
feature_list.InitAndEnableFeatureWithParameters(kArticleSuggestionsFeature,
parameters);
EXPECT_EQ(kTestFeedURL, GetContentSuggestionsReferrerURL());
}
} // namespace ntp_snippets
...@@ -101,8 +101,5 @@ const char kGoogleHistoryURL[] = "https://history.google.com"; ...@@ -101,8 +101,5 @@ const char kGoogleHistoryURL[] = "https://history.google.com";
const char kGoogleMyAccountURL[] = const char kGoogleMyAccountURL[] =
"https://myaccount.google.com/privacy#activitycontrols"; "https://myaccount.google.com/privacy#activitycontrols";
const char kNewTabPageReferrerURL[] =
"chrome://do_not_consider_for_most_visited/new_tab_page";
const char kReadingListReferrerURL[] = const char kReadingListReferrerURL[] =
"chrome://do_not_consider_for_most_visited/reading_list"; "chrome://do_not_consider_for_most_visited/reading_list";
...@@ -103,10 +103,6 @@ extern const char kGoogleHistoryURL[]; ...@@ -103,10 +103,6 @@ extern const char kGoogleHistoryURL[];
// Google my account URL for the sign-in confirmation screen. // Google my account URL for the sign-in confirmation screen.
extern const char kGoogleMyAccountURL[]; extern const char kGoogleMyAccountURL[];
// URL used in referrer to signal that the navigation originates from the New
// Tab page and thus should not be considered for Most Visited.
extern const char kNewTabPageReferrerURL[];
// URL used in referrer to signal that the navigation originates from Reading // URL used in referrer to signal that the navigation originates from Reading
// List page and thus should not be considered for Most Visited. // List page and thus should not be considered for Most Visited.
extern const char kReadingListReferrerURL[]; extern const char kReadingListReferrerURL[];
......
...@@ -49,6 +49,7 @@ source_set("tab_helper") { ...@@ -49,6 +49,7 @@ source_set("tab_helper") {
"//base", "//base",
"//components/history/core/browser", "//components/history/core/browser",
"//components/keyed_service/core", "//components/keyed_service/core",
"//components/ntp_snippets",
"//components/strings", "//components/strings",
"//ios/chrome/browser", "//ios/chrome/browser",
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "components/history/core/browser/history_constants.h" #include "components/history/core/browser/history_constants.h"
#include "components/history/core/browser/history_service.h" #include "components/history/core/browser/history_service.h"
#include "components/keyed_service/core/service_access_type.h" #include "components/keyed_service/core/service_access_type.h"
#include "components/ntp_snippets/features.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/chrome_url_constants.h" #include "ios/chrome/browser/chrome_url_constants.h"
...@@ -161,7 +162,7 @@ void HistoryTabHelper::DidFinishNavigation( ...@@ -161,7 +162,7 @@ void HistoryTabHelper::DidFinishNavigation(
// Navigations originating from New Tab Page or Reading List should not // Navigations originating from New Tab Page or Reading List should not
// contribute to Most Visited. // contribute to Most Visited.
const bool consider_for_ntp_most_visited = const bool consider_for_ntp_most_visited =
referrer_url != kNewTabPageReferrerURL && referrer_url != ntp_snippets::GetContentSuggestionsReferrerURL() &&
referrer_url != kReadingListReferrerURL; referrer_url != kReadingListReferrerURL;
// Top-level frame navigations are visible; everything else is hidden. // Top-level frame navigations are visible; everything else is hidden.
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h" #include "base/metrics/user_metrics_action.h"
#include "components/ntp_snippets/content_suggestions_service.h" #include "components/ntp_snippets/content_suggestions_service.h"
#include "components/ntp_snippets/features.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/chrome_url_constants.h" #include "ios/chrome/browser/chrome_url_constants.h"
#import "ios/chrome/browser/metrics/new_tab_page_uma.h" #import "ios/chrome/browser/metrics/new_tab_page_uma.h"
...@@ -241,7 +242,8 @@ const char kRateThisAppCommand[] = "ratethisapp"; ...@@ -241,7 +242,8 @@ const char kRateThisAppCommand[] = "ratethisapp";
// Use a referrer with a specific URL to mark this entry as coming from // Use a referrer with a specific URL to mark this entry as coming from
// ContentSuggestions. // ContentSuggestions.
params.referrer = params.referrer =
web::Referrer(GURL(kNewTabPageReferrerURL), web::ReferrerPolicyDefault); web::Referrer(GURL(ntp_snippets::GetContentSuggestionsReferrerURL()),
web::ReferrerPolicyDefault);
params.transition_type = ui::PAGE_TRANSITION_AUTO_BOOKMARK; params.transition_type = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
[self.dispatcher loadURLWithParams:params]; [self.dispatcher loadURLWithParams:params];
[self.NTPMetrics recordAction:new_tab_page_uma::ACTION_OPENED_SUGGESTION]; [self.NTPMetrics recordAction:new_tab_page_uma::ACTION_OPENED_SUGGESTION];
......
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