Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(885)

Unified Diff: components/favicon/core/favicon_handler.h

Issue 2799273002: Add support to process favicons from Web Manifests (Closed)
Patch Set: Added comment. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/favicon/core/favicon_handler.h
diff --git a/components/favicon/core/favicon_handler.h b/components/favicon/core/favicon_handler.h
index 9e6e22b9f97126bc1762aa49db194d4225a8f635..4090782180350f9fd238cf8881e5a6248d61ccbc 100644
--- a/components/favicon/core/favicon_handler.h
+++ b/components/favicon/core/favicon_handler.h
@@ -13,6 +13,7 @@
#include "base/cancelable_callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
+#include "base/optional.h"
#include "base/task/cancelable_task_tracker.h"
#include "components/favicon/core/favicon_driver_observer.h"
#include "components/favicon/core/favicon_url.h"
@@ -86,6 +87,10 @@ class FaviconHandler {
const std::vector<gfx::Size>& original_bitmap_sizes)>
ImageDownloadCallback;
+ typedef base::Callback<
+ void(int status_code, const std::vector<favicon::FaviconURL>& favicons)>
+ ManifestDownloadCallback;
+
// Starts the download for the given favicon. When finished, the callback
// is called with the results. Returns the unique id of the download
// request, which will also be passed to the callback. In case of error, 0
@@ -98,6 +103,10 @@ class FaviconHandler {
int max_image_size,
ImageDownloadCallback callback) = 0;
+ // Downloads a WebManifest and returns the favicons listed there.
+ virtual void DownloadManifest(const GURL& url,
+ ManifestDownloadCallback callback) = 0;
+
// Returns whether the user is operating in an off-the-record context.
virtual bool IsOffTheRecord() = 0;
@@ -124,10 +133,11 @@ class FaviconHandler {
// Initiates loading the favicon for the specified url.
void FetchFavicon(const GURL& url);
- // Message Handler. Must be public, because also called from
- // PrerenderContents. Collects the |image_urls| list.
- void OnUpdateFaviconURL(const GURL& page_url,
- const std::vector<favicon::FaviconURL>& candidates);
+ // Collects the candidate favicons as listed in the HTML head, as well as
+ // the WebManifest URL if available.
+ void OnUpdateCandidates(const GURL& page_url,
+ const std::vector<favicon::FaviconURL>& candidates,
+ const base::Optional<GURL>& manifest_url);
// For testing.
const std::vector<GURL> GetIconURLs() const;
@@ -174,6 +184,25 @@ class FaviconHandler {
static int GetIconTypesFromHandlerType(
FaviconDriverObserver::NotificationIconType handler_type);
+ // Called with the result of looking up cached icon data for the manifest's
+ // URL, which is used as icon URL.
+ void OnFaviconDataForManifestFromFaviconService(
+ const std::vector<favicon_base::FaviconRawBitmapResult>&
+ favicon_bitmap_results);
+
+ // Schedules a download for |manifest_url_|, which must not be empty. The
+ // request is stored in |manifest_download_request_| so it can be cancelled.
+ void ScheduleManifestDownload();
+
+ // Called when the dowloading of a manifest completes.
+ void OnDidDownloadManifest(int status_code,
+ const std::vector<FaviconURL>& candidates);
+
+ // Called when the actual list of favicon candidates to be processed is
+ // available, which can be either icon URLs listed in the HTML head instead
+ // or, if a Web Manifest was provided, the list of icons there.
+ void OnGotFinalIconURLCandidates(const std::vector<FaviconURL>& candidates);
+
// Called when the history request for favicon data mapped to |url_| has
// completed and the renderer has told us the icon URLs used by |url_|
void OnGotInitialHistoryDataAndIconURLCandidates();
@@ -188,14 +217,21 @@ class FaviconHandler {
// OnFaviconData() is called with the history data once it has been retrieved.
void DownloadCurrentCandidateOrAskFaviconService();
+ // Requests the favicon for |icon_url| from the favicon service. Unless in
+ // incognito, it also updates the page URL (url_) to |icon_url| mappings.
+ void GetFaviconAndUpdateMappingsUnlessIncognito(
+ const GURL& icon_url,
+ favicon_base::IconType icon_type,
+ const favicon_base::FaviconResultsCallback& callback);
+
// See description above class for details.
void OnFaviconData(const std::vector<favicon_base::FaviconRawBitmapResult>&
favicon_bitmap_results);
- // Schedules a download for the specified entry. This adds the request to
- // download_requests_.
- void ScheduleDownload(const GURL& image_url,
- favicon_base::IconType icon_type);
+ // Schedules a download for |image_url|. The request is stored in
+ // image_download_request_ so it can be cancelled.
+ void ScheduleFaviconDownload(const GURL& image_url,
+ favicon_base::IconType icon_type);
// Triggered when a download of an image has finished.
void OnDidDownloadFavicon(
@@ -265,9 +301,13 @@ class FaviconHandler {
// |image_urls_| one by one.
bool redownload_icons_;
+ // Requests to the renderer to download a manifest.
+ base::CancelableCallback<Delegate::ManifestDownloadCallback::RunType>
+ manifest_download_request_;
+
// Requests to the renderer to download favicons.
base::CancelableCallback<Delegate::ImageDownloadCallback::RunType>
- download_request_;
+ image_download_request_;
// The combination of the supported icon types.
const int icon_types_;
@@ -275,6 +315,14 @@ class FaviconHandler {
// Whether the largest icon should be downloaded.
const bool download_largest_icon_;
+ // The manifest URL from the renderer.
+ base::Optional<GURL> manifest_url_;
+
+ // Original list of candidates provided to OnUpdateCandidates(), stored to
+ // be able to fall back to, in case a manifest was provided and downloading it
+ // failed (or provided no icons).
+ std::vector<FaviconURL> non_manifest_original_candidates_;
+
// The prioritized favicon candidates from the page back from the renderer.
std::vector<FaviconCandidate> candidates_;

Powered by Google App Engine
This is Rietveld 408576698