Chromium Code Reviews| Index: components/favicon/core/favicon_handler.h |
| diff --git a/components/favicon/core/favicon_handler.h b/components/favicon/core/favicon_handler.h |
| index 30c0b1df498a75d7fa63229de28d3941d0af158e..a6c495f7e34c0b1736857da7ead58c347cd1a49b 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" |
| @@ -99,6 +100,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 |
| @@ -111,6 +116,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; |
| @@ -137,10 +146,15 @@ 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); |
| + |
| + // Returns the supported icon types, inferred from the handler type as passed |
| + // in the constructor. |
| + int icon_types() const { return icon_types_; } |
| // For testing. |
| const std::vector<GURL> GetIconURLs() const; |
| @@ -187,6 +201,21 @@ 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); |
| + |
| + // 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(); |
| @@ -201,14 +230,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( |
| @@ -258,7 +294,7 @@ class FaviconHandler { |
| // Used for FaviconService requests. |
| base::CancelableTaskTracker cancelable_task_tracker_; |
| - FaviconDriverObserver::NotificationIconType handler_type_; |
| + const FaviconDriverObserver::NotificationIconType handler_type_; |
| // URL of the page we're requesting the favicon for. |
| GURL url_; |
| @@ -278,9 +314,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_; |
| @@ -288,6 +328,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_; |
|
pkotwicz
2017/04/24 14:42:15
Can you use an empty GURL() instead of base::Optio
mastiz
2017/04/27 13:54:50
I've no objection to that, but let's defer this di
pkotwicz
2017/05/01 04:56:53
OK
|
| + |
| + // 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_; |