Commit d8b62308 authored by Mathieu Perreault's avatar Mathieu Perreault Committed by Commit Bot

[New Tab] Provide icons for the prepopulated pages on the NTP.

Web Store will have an icon now!

Bug: 853349
Test: out/Default/ntp_render_browsertests
Change-Id: I46182b509b08d2772cb2a439f60f0a3313e5cb81
Reviewed-on: https://chromium-review.googlesource.com/1147105Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Mathieu Perreault <mathp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577578}
parent 5dae36dd
......@@ -30,6 +30,7 @@
#include "components/history/core/browser/top_sites_impl.h"
#include "components/history/core/browser/top_sites_provider.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/ntp_tiles/constants.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "content/public/browser/browser_thread.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -44,23 +45,22 @@ bool IsTopSitesDisabled() {
}
struct RawPrepopulatedPage {
int url_id; // The resource for the page URL.
int title_id; // The resource for the page title.
int favicon_id; // The raw data resource for the favicon.
int thumbnail_id; // The raw data resource for the thumbnail.
SkColor color; // The best color to highlight the page (should roughly
// match favicon).
int url_id; // The resource for the page URL.
int title_id; // The resource for the page title.
int favicon_id; // The raw data resource for the favicon.
int large_favicon_id; // The raw data resource for the larger favicon.
int thumbnail_id; // The raw data resource for the thumbnail.
SkColor color; // The best color to highlight the page (should
// roughly match favicon).
};
#if !defined(OS_ANDROID)
// Android does not use prepopulated pages.
const RawPrepopulatedPage kRawPrepopulatedPages[] = {
{
IDS_WEBSTORE_URL,
IDS_EXTENSION_WEB_STORE_TITLE,
IDR_WEBSTORE_ICON_16,
IDR_NEWTAB_WEBSTORE_THUMBNAIL,
SkColorSetRGB(63, 132, 197),
IDS_WEBSTORE_URL, IDS_EXTENSION_WEB_STORE_TITLE, IDR_WEBSTORE_ICON_16,
IDR_WEBSTORE_ICON_32, IDR_NEWTAB_WEBSTORE_THUMBNAIL,
SkColorSetRGB(63, 132, 197),
},
};
#endif
......@@ -74,7 +74,8 @@ void InitializePrepopulatedPageList(
const RawPrepopulatedPage& page = kRawPrepopulatedPages[i];
prepopulated_pages->push_back(history::PrepopulatedPage(
GURL(l10n_util::GetStringUTF8(page.url_id)),
l10n_util::GetStringUTF16(page.title_id), page.favicon_id,
l10n_util::GetStringUTF16(page.title_id),
ntp_tiles::IsMDIconsEnabled() ? page.large_favicon_id : page.favicon_id,
page.thumbnail_id, page.color));
}
#endif
......
......@@ -14,6 +14,7 @@
#include "base/strings/string_number_conversions.h"
#include "cc/paint/skia_paint_canvas.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/history/top_sites_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/instant_io_context.h"
#include "chrome/browser/search/suggestions/image_decoder_impl.h"
......@@ -24,6 +25,7 @@
#include "components/favicon/core/fallback_url_util.h"
#include "components/favicon/core/favicon_service.h"
#include "components/favicon_base/favicon_types.h"
#include "components/history/core/browser/top_sites.h"
#include "components/image_fetcher/core/image_fetcher_impl.h"
#include "components/suggestions/proto/suggestions.pb.h"
#include "components/suggestions/suggestions_service.h"
......@@ -34,6 +36,7 @@
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/webui/web_ui_util.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/codec/png_codec.h"
......@@ -255,18 +258,35 @@ void NtpIconSource::StartDataRequest(
const ParsedNtpIconPath parsed = ParseNtpIconPath(path);
if (parsed.url.is_valid()) {
int icon_size_in_pixels =
std::ceil(parsed.size_in_dip * parsed.device_scale_factor);
NtpIconRequest request(callback, parsed.url, icon_size_in_pixels,
parsed.device_scale_factor);
// Check if the requested URL is part of the prepopulated pages (currently,
// only the Web Store).
scoped_refptr<history::TopSites> top_sites =
TopSitesFactory::GetForProfile(profile_);
if (top_sites) {
for (const auto& prepopulated_page : top_sites->GetPrepopulatedPages()) {
if (parsed.url == prepopulated_page.most_visited.url) {
gfx::Image& image =
ui::ResourceBundle::GetSharedInstance().GetImageNamed(
prepopulated_page.favicon_id);
ReturnRenderedIconForRequest(request, image.AsBitmap());
return;
}
}
}
// This will query for a local favicon. If not found, will take alternative
// action in OnLocalFaviconAvailable.
const bool fallback_to_host = true;
int icon_size_in_pixels =
std::ceil(parsed.size_in_dip * parsed.device_scale_factor);
favicon_service->GetRawFaviconForPageURL(
parsed.url, {favicon_base::IconType::kFavicon}, icon_size_in_pixels,
fallback_to_host,
base::Bind(&NtpIconSource::OnLocalFaviconAvailable,
weak_ptr_factory_.GetWeakPtr(),
NtpIconRequest(callback, parsed.url, icon_size_in_pixels,
parsed.device_scale_factor)),
weak_ptr_factory_.GetWeakPtr(), request),
&cancelable_task_tracker_);
} else {
callback.Run(nullptr);
......
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