summaryrefslogtreecommitdiff
path: root/chromium/components/ntp_tiles
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2019-06-27 11:18:24 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-07-03 09:38:30 +0000
commitd94af01c90575348c4e81a418257f254b6f8d225 (patch)
tree77a26669b33eaa4d46b88b07e17dacc61eba6001 /chromium/components/ntp_tiles
parent5d87695f37678f96492b258bbab36486c59866b4 (diff)
downloadqtwebengine-chromium-d94af01c90575348c4e81a418257f254b6f8d225.tar.gz
BASELINE: Update Chromium to 75.0.3770.116
Change-Id: Ifcd5227841577e8ce81a1b7a54c56caba4d85e02 Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'chromium/components/ntp_tiles')
-rw-r--r--chromium/components/ntp_tiles/BUILD.gn3
-rw-r--r--chromium/components/ntp_tiles/DEPS1
-rw-r--r--chromium/components/ntp_tiles/features.cc15
-rw-r--r--chromium/components/ntp_tiles/features.h19
-rw-r--r--chromium/components/ntp_tiles/metrics.cc3
-rw-r--r--chromium/components/ntp_tiles/most_visited_sites.cc59
-rw-r--r--chromium/components/ntp_tiles/most_visited_sites.h5
-rw-r--r--chromium/components/ntp_tiles/most_visited_sites_unittest.cc97
-rw-r--r--chromium/components/ntp_tiles/tile_source.h4
9 files changed, 205 insertions, 1 deletions
diff --git a/chromium/components/ntp_tiles/BUILD.gn b/chromium/components/ntp_tiles/BUILD.gn
index ec5c26da5e8..33d2c608dba 100644
--- a/chromium/components/ntp_tiles/BUILD.gn
+++ b/chromium/components/ntp_tiles/BUILD.gn
@@ -17,6 +17,8 @@ static_library("ntp_tiles") {
"custom_links_manager_impl.h",
"custom_links_store.cc",
"custom_links_store.h",
+ "features.cc",
+ "features.h",
"icon_cacher.h",
"icon_cacher_impl.cc",
"icon_cacher_impl.h",
@@ -61,6 +63,7 @@ static_library("ntp_tiles") {
"//components/rappor/public",
"//components/resources",
"//components/search_engines",
+ "//components/strings",
"//components/url_formatter",
"//components/variations",
"//components/variations/service",
diff --git a/chromium/components/ntp_tiles/DEPS b/chromium/components/ntp_tiles/DEPS
index e43f875d6d6..18f2f118b9b 100644
--- a/chromium/components/ntp_tiles/DEPS
+++ b/chromium/components/ntp_tiles/DEPS
@@ -11,6 +11,7 @@ include_rules = [
"+components/prefs",
"+components/rappor",
"+components/search_engines",
+ "+components/strings/grit/components_strings.h",
"+components/suggestions",
"+components/sync_preferences",
"+components/url_formatter",
diff --git a/chromium/components/ntp_tiles/features.cc b/chromium/components/ntp_tiles/features.cc
new file mode 100644
index 00000000000..d1f3c33814c
--- /dev/null
+++ b/chromium/components/ntp_tiles/features.cc
@@ -0,0 +1,15 @@
+// Copyright 2019 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_tiles/features.h"
+
+#include "base/feature_list.h"
+#include "ui/base/ui_base_features.h"
+
+namespace ntp_tiles {
+
+const base::Feature kDefaultSearchShortcut{"DefaultSearchShortcut",
+ base::FEATURE_DISABLED_BY_DEFAULT};
+
+} // namespace ntp_tiles
diff --git a/chromium/components/ntp_tiles/features.h b/chromium/components/ntp_tiles/features.h
new file mode 100644
index 00000000000..0c60cfc0d7b
--- /dev/null
+++ b/chromium/components/ntp_tiles/features.h
@@ -0,0 +1,19 @@
+// Copyright 2019 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_NTP_TILES_FEATURES_H_
+#define COMPONENTS_NTP_TILES_FEATURES_H_
+
+namespace base {
+struct Feature;
+} // namespace base
+
+namespace ntp_tiles {
+
+// If enabled, show a Google search shortcut on the NTP by default.
+extern const base::Feature kDefaultSearchShortcut;
+
+} // namespace ntp_tiles
+
+#endif // COMPONENTS_NTP_TILES_FEATURES_H_
diff --git a/chromium/components/ntp_tiles/metrics.cc b/chromium/components/ntp_tiles/metrics.cc
index f3df4427ada..9cc76163918 100644
--- a/chromium/components/ntp_tiles/metrics.cc
+++ b/chromium/components/ntp_tiles/metrics.cc
@@ -29,6 +29,7 @@ const char kHistogramBakedInName[] = "popular_baked_in";
const char kHistogramWhitelistName[] = "whitelist";
const char kHistogramHomepageName[] = "homepage";
const char kHistogramCustomLinksName[] = "custom_links";
+const char kHistogramSearchName[] = "search_page";
// Suffixes for the various icon types.
const char kTileTypeSuffixIconColor[] = "IconsColor";
@@ -59,6 +60,8 @@ std::string GetSourceHistogramName(TileSource source) {
return kHistogramHomepageName;
case TileSource::CUSTOM_LINKS:
return kHistogramCustomLinksName;
+ case TileSource::SEARCH_PAGE:
+ return kHistogramSearchName;
}
NOTREACHED();
return std::string();
diff --git a/chromium/components/ntp_tiles/most_visited_sites.cc b/chromium/components/ntp_tiles/most_visited_sites.cc
index a22597935bc..e643df1701a 100644
--- a/chromium/components/ntp_tiles/most_visited_sites.cc
+++ b/chromium/components/ntp_tiles/most_visited_sites.cc
@@ -15,13 +15,18 @@
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "build/build_config.h"
+#include "components/google/core/common/google_util.h"
#include "components/history/core/browser/top_sites.h"
#include "components/ntp_tiles/constants.h"
+#include "components/ntp_tiles/features.h"
#include "components/ntp_tiles/icon_cacher.h"
#include "components/ntp_tiles/pref_names.h"
#include "components/ntp_tiles/switches.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
+#include "components/strings/grit/components_strings.h"
+#include "ui/base/l10n/l10n_util.h"
using history::TopSites;
using suggestions::ChromeSuggestion;
@@ -184,6 +189,12 @@ bool MostVisitedSites::DoesSourceExist(TileSource source) const {
return supervisor_ != nullptr;
case TileSource::CUSTOM_LINKS:
return custom_links_ != nullptr;
+ case TileSource::SEARCH_PAGE:
+#if !defined(OS_ANDROID) && !defined(OS_IOS)
+ return true;
+#else
+ return false;
+#endif
}
NOTREACHED();
return false;
@@ -696,6 +707,51 @@ NTPTilesVector MostVisitedSites::InsertHomeTile(
return new_tiles;
}
+NTPTilesVector MostVisitedSites::InsertSearchTile(NTPTilesVector tiles) const {
+ DCHECK_GT(max_num_sites_, 0u);
+
+#if defined(OS_ANDROID)
+ return tiles;
+#else
+ NTPTilesVector new_tiles;
+ const GURL search_url(l10n_util::GetStringUTF16(IDS_NTP_DEFAULT_SEARCH_URL));
+ bool search_tile_added = false;
+
+ for (auto& tile : tiles) {
+ if (new_tiles.size() >= max_num_sites_) {
+ break;
+ }
+
+ // If there's a tile has the same host name with the search page, insert
+ // the tile to the first position of the list. This is also a deduplication.
+ if (google_util::IsGoogleHomePageUrl(tile.url) && !search_tile_added) {
+ tile.source = TileSource::SEARCH_PAGE;
+ search_tile_added = true;
+ new_tiles.insert(new_tiles.begin(), std::move(tile));
+ continue;
+ }
+ new_tiles.push_back(std::move(tile));
+ }
+
+ if (!search_tile_added) {
+ // Make room for the search tile.
+ if (new_tiles.size() >= max_num_sites_) {
+ new_tiles.pop_back();
+ }
+ NTPTile search_tile;
+ search_tile.url = search_url;
+ search_tile.title = l10n_util::GetStringUTF16(IDS_NTP_DEFAULT_SEARCH_TITLE);
+ search_tile.source = TileSource::SEARCH_PAGE;
+ search_tile.title_source = TileTitleSource::TITLE_TAG;
+
+ // Always insert |search_tile| to the front of |new_tiles| to ensure it's
+ // the first tile.
+ new_tiles.insert(new_tiles.begin(), std::move(search_tile));
+ }
+ return new_tiles;
+#endif
+}
+
void MostVisitedSites::OnCustomLinksChanged() {
DCHECK(custom_links_);
if (!custom_links_enabled_)
@@ -749,6 +805,9 @@ void MostVisitedSites::InitiateNotificationForNewTiles(
// copy of new tiles.
new_tiles = InsertHomeTile(std::move(new_tiles), base::string16());
}
+ if (base::FeatureList::IsEnabled(ntp_tiles::kDefaultSearchShortcut)) {
+ new_tiles = InsertSearchTile(std::move(new_tiles));
+ }
MergeMostVisitedTiles(std::move(new_tiles));
}
diff --git a/chromium/components/ntp_tiles/most_visited_sites.h b/chromium/components/ntp_tiles/most_visited_sites.h
index a5a9ed90b54..edcb280a039 100644
--- a/chromium/components/ntp_tiles/most_visited_sites.h
+++ b/chromium/components/ntp_tiles/most_visited_sites.h
@@ -309,6 +309,11 @@ class MostVisitedSites : public history::TopSitesObserver,
NTPTilesVector InsertHomeTile(NTPTilesVector tiles,
const base::string16& title) const;
+ // Adds the Google Search page as first tile to |tiles| and returns them as
+ // new vector. Drops existing tiles with the same host as the Google Search
+ // page and tiles that would exceed the maximum.
+ NTPTilesVector InsertSearchTile(NTPTilesVector tiles) const;
+
void OnHomepageTitleDetermined(NTPTilesVector tiles,
const base::Optional<base::string16>& title);
diff --git a/chromium/components/ntp_tiles/most_visited_sites_unittest.cc b/chromium/components/ntp_tiles/most_visited_sites_unittest.cc
index 12ff2fb71e3..fe08f7a1442 100644
--- a/chromium/components/ntp_tiles/most_visited_sites_unittest.cc
+++ b/chromium/components/ntp_tiles/most_visited_sites_unittest.cc
@@ -29,6 +29,7 @@
#include "components/history/core/browser/top_sites_observer.h"
#include "components/ntp_tiles/constants.h"
#include "components/ntp_tiles/custom_links_manager.h"
+#include "components/ntp_tiles/features.h"
#include "components/ntp_tiles/icon_cacher.h"
#include "components/ntp_tiles/json_unsafe_parser.h"
#include "components/ntp_tiles/popular_sites_impl.h"
@@ -91,6 +92,11 @@ std::string PrintTile(const std::string& title,
testing::PrintToString(static_cast<int>(source));
}
+MATCHER_P3(NotMatchesTile, title, url, source, PrintTile(title, url, source)) {
+ return arg.title != base::ASCIIToUTF16(title) && arg.url != GURL(url) &&
+ arg.source != source;
+}
+
MATCHER_P3(MatchesTile, title, url, source, PrintTile(title, url, source)) {
return arg.title == base::ASCIIToUTF16(title) && arg.url == GURL(url) &&
arg.source == source;
@@ -2111,4 +2117,95 @@ TEST(MostVisitedSitesMergeTest, ShouldMergeTilesFavoringPersonalOverPopular) {
TileSource::POPULAR)));
}
+#if !defined(OS_ANDROID) && !defined(OS_IOS)
+
+TEST_P(MostVisitedSitesTest, ShouldIncludeTileForSearchPage) {
+ base::test::ScopedFeatureList scoped_feature_list;
+ scoped_feature_list.InitWithFeatures(
+ /*enabled=*/{ntp_tiles::kDefaultSearchShortcut}, /*disabled=*/{});
+ DisableRemoteSuggestions();
+ EXPECT_CALL(*mock_top_sites_, GetMostVisitedURLs(_))
+ .WillRepeatedly(InvokeCallbackArgument<0>(MostVisitedURLList{}));
+ EXPECT_CALL(*mock_top_sites_, SyncWithHistory());
+ EXPECT_CALL(*mock_top_sites_,
+ IsBlacklisted(Eq(GURL("https://www.google.com"))))
+ .Times(AnyNumber())
+ .WillRepeatedly(Return(false));
+ EXPECT_CALL(mock_observer_, OnURLsAvailable(FirstPersonalizedTileIs(
+ "Google", "https://www.google.com/",
+ TileSource::SEARCH_PAGE)));
+ most_visited_sites_->SetMostVisitedURLsObserver(&mock_observer_,
+ /*num_sites=*/3);
+ base::RunLoop().RunUntilIdle();
+}
+
+TEST_P(MostVisitedSitesTest, ShouldHaveSearchPageFirstInListWhenFull) {
+ base::test::ScopedFeatureList scoped_feature_list;
+ scoped_feature_list.InitWithFeatures(
+ /*enabled=*/{ntp_tiles::kDefaultSearchShortcut}, /*disabled=*/{});
+ DisableRemoteSuggestions();
+ EXPECT_CALL(*mock_top_sites_, GetMostVisitedURLs(_))
+ .WillRepeatedly(InvokeCallbackArgument<0>((MostVisitedURLList{
+ MakeMostVisitedURL("Site 1", "http://site1/"),
+ MakeMostVisitedURL("Site 2", "http://site2/"),
+ MakeMostVisitedURL("Site 3", "http://site3/"),
+ MakeMostVisitedURL("Site 4", "http://site4/"),
+ MakeMostVisitedURL("Site 5", "http://site5/"),
+ })));
+ EXPECT_CALL(*mock_top_sites_, SyncWithHistory());
+ EXPECT_CALL(*mock_top_sites_,
+ IsBlacklisted(Eq(GURL("https://www.gooogle.com/"))))
+ .Times(AnyNumber())
+ .WillRepeatedly(Return(false));
+ std::map<SectionType, NTPTilesVector> sections;
+ EXPECT_CALL(mock_observer_, OnURLsAvailable(_))
+ .WillOnce(SaveArg<0>(&sections));
+ most_visited_sites_->SetMostVisitedURLsObserver(&mock_observer_,
+ /*num_sites=*/4);
+ base::RunLoop().RunUntilIdle();
+ ASSERT_THAT(sections, Contains(Key(SectionType::PERSONALIZED)));
+ NTPTilesVector tiles = sections.at(SectionType::PERSONALIZED);
+ ASSERT_THAT(tiles.size(), Ge(4ul));
+ // Assert that the search page is appended as the first tile.
+ EXPECT_THAT(tiles[0], MatchesTile("Google", "https://www.google.com",
+ TileSource::SEARCH_PAGE));
+}
+
+TEST_P(MostVisitedSitesTest, DedupesSearchPage) {
+ base::test::ScopedFeatureList scoped_feature_list;
+ scoped_feature_list.InitWithFeatures(
+ /*enabled=*/{ntp_tiles::kDefaultSearchShortcut}, /*disabled=*/{});
+ DisableRemoteSuggestions();
+ EXPECT_CALL(*mock_top_sites_, GetMostVisitedURLs(_))
+ .WillRepeatedly(InvokeCallbackArgument<0>((MostVisitedURLList{
+ MakeMostVisitedURL("Site 1", "http://site1/"),
+ MakeMostVisitedURL("Google", "https://www.google.com"),
+ MakeMostVisitedURL("Site 3", "http://site3/"),
+ MakeMostVisitedURL("Site 4", "http://site4/"),
+ })));
+ EXPECT_CALL(*mock_top_sites_, SyncWithHistory());
+ EXPECT_CALL(*mock_top_sites_,
+ IsBlacklisted(Eq(GURL("https://www.gooogle.com/"))))
+ .Times(AnyNumber())
+ .WillRepeatedly(Return(false));
+ std::map<SectionType, NTPTilesVector> sections;
+ EXPECT_CALL(mock_observer_, OnURLsAvailable(_))
+ .WillOnce(SaveArg<0>(&sections));
+ most_visited_sites_->SetMostVisitedURLsObserver(&mock_observer_,
+ /*num_sites=*/4);
+ base::RunLoop().RunUntilIdle();
+ ASSERT_THAT(sections, Contains(Key(SectionType::PERSONALIZED)));
+ NTPTilesVector tiles = sections.at(SectionType::PERSONALIZED);
+ ASSERT_THAT(tiles.size(), Ge(4ul));
+ // Assert that the search page is appended as the first tile.
+ EXPECT_THAT(tiles[0], MatchesTile("Google", "https://www.google.com/",
+ TileSource::SEARCH_PAGE));
+ for (auto i = 1u; i < tiles.size(); ++i) {
+ EXPECT_THAT(tiles[i], NotMatchesTile("Google", "https://www.google.com/",
+ TileSource::SEARCH_PAGE));
+ }
+}
+
+#endif
+
} // namespace ntp_tiles
diff --git a/chromium/components/ntp_tiles/tile_source.h b/chromium/components/ntp_tiles/tile_source.h
index 0d26c2a350e..689411b4302 100644
--- a/chromium/components/ntp_tiles/tile_source.h
+++ b/chromium/components/ntp_tiles/tile_source.h
@@ -26,8 +26,10 @@ enum class TileSource {
WHITELIST,
// Tile containing the user-set home page is replacing the home page button.
HOMEPAGE,
+ // Tile containing the Google Search page.
+ SEARCH_PAGE,
- LAST = HOMEPAGE
+ LAST = SEARCH_PAGE
};
} // namespace ntp_tiles