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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_ 5 #ifndef COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_
6 #define COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_ 6 #define COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback_forward.h" 12 #include "base/callback_forward.h"
13 #include "base/cancelable_callback.h" 13 #include "base/cancelable_callback.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/optional.h"
16 #include "base/task/cancelable_task_tracker.h" 17 #include "base/task/cancelable_task_tracker.h"
17 #include "components/favicon/core/favicon_driver_observer.h" 18 #include "components/favicon/core/favicon_driver_observer.h"
18 #include "components/favicon/core/favicon_url.h" 19 #include "components/favicon/core/favicon_url.h"
19 #include "components/favicon_base/favicon_callback.h" 20 #include "components/favicon_base/favicon_callback.h"
20 #include "ui/gfx/favicon_size.h" 21 #include "ui/gfx/favicon_size.h"
21 #include "ui/gfx/image/image.h" 22 #include "ui/gfx/image/image.h"
22 #include "url/gurl.h" 23 #include "url/gurl.h"
23 24
24 class SkBitmap; 25 class SkBitmap;
25 26
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 public: 80 public:
80 // Mimics WebContents::ImageDownloadCallback. 81 // Mimics WebContents::ImageDownloadCallback.
81 typedef base::Callback<void( 82 typedef base::Callback<void(
82 int id, 83 int id,
83 int status_code, 84 int status_code,
84 const GURL& image_url, 85 const GURL& image_url,
85 const std::vector<SkBitmap>& bitmaps, 86 const std::vector<SkBitmap>& bitmaps,
86 const std::vector<gfx::Size>& original_bitmap_sizes)> 87 const std::vector<gfx::Size>& original_bitmap_sizes)>
87 ImageDownloadCallback; 88 ImageDownloadCallback;
88 89
90 typedef base::Callback<
91 void(int status_code, const std::vector<favicon::FaviconURL>& favicons)>
92 ManifestDownloadCallback;
93
89 // Starts the download for the given favicon. When finished, the callback 94 // Starts the download for the given favicon. When finished, the callback
90 // is called with the results. Returns the unique id of the download 95 // is called with the results. Returns the unique id of the download
91 // request, which will also be passed to the callback. In case of error, 0 96 // request, which will also be passed to the callback. In case of error, 0
92 // is returned and no callback will be called. 97 // is returned and no callback will be called.
93 // Bitmaps with pixel sizes larger than |max_bitmap_size| are filtered out 98 // Bitmaps with pixel sizes larger than |max_bitmap_size| are filtered out
94 // from the bitmap results. If there are no bitmap results <= 99 // from the bitmap results. If there are no bitmap results <=
95 // |max_bitmap_size|, the smallest bitmap is resized to |max_bitmap_size| 100 // |max_bitmap_size|, the smallest bitmap is resized to |max_bitmap_size|
96 // and is the only result. A |max_bitmap_size| of 0 means unlimited. 101 // and is the only result. A |max_bitmap_size| of 0 means unlimited.
97 virtual int DownloadImage(const GURL& url, 102 virtual int DownloadImage(const GURL& url,
98 int max_image_size, 103 int max_image_size,
99 ImageDownloadCallback callback) = 0; 104 ImageDownloadCallback callback) = 0;
100 105
106 // Downloads a WebManifest and returns the favicons listed there.
107 virtual void DownloadManifest(const GURL& url,
108 ManifestDownloadCallback callback) = 0;
109
101 // Returns whether the user is operating in an off-the-record context. 110 // Returns whether the user is operating in an off-the-record context.
102 virtual bool IsOffTheRecord() = 0; 111 virtual bool IsOffTheRecord() = 0;
103 112
104 // Returns whether |url| is bookmarked. 113 // Returns whether |url| is bookmarked.
105 virtual bool IsBookmarked(const GURL& url) = 0; 114 virtual bool IsBookmarked(const GURL& url) = 0;
106 115
107 // Notifies that the favicon image has been updated. Most delegates 116 // Notifies that the favicon image has been updated. Most delegates
108 // propagate the notification to FaviconDriverObserver::OnFaviconUpdated(). 117 // propagate the notification to FaviconDriverObserver::OnFaviconUpdated().
109 // See its documentation for details. 118 // See its documentation for details.
110 virtual void OnFaviconUpdated( 119 virtual void OnFaviconUpdated(
111 const GURL& page_url, 120 const GURL& page_url,
112 FaviconDriverObserver::NotificationIconType notification_icon_type, 121 FaviconDriverObserver::NotificationIconType notification_icon_type,
113 const GURL& icon_url, 122 const GURL& icon_url,
114 bool icon_url_changed, 123 bool icon_url_changed,
115 const gfx::Image& image) = 0; 124 const gfx::Image& image) = 0;
116 }; 125 };
117 126
118 // |delegate| must not be nullptr and must outlive this class. 127 // |delegate| must not be nullptr and must outlive this class.
119 FaviconHandler(FaviconService* service, 128 FaviconHandler(FaviconService* service,
120 Delegate* delegate, 129 Delegate* delegate,
121 FaviconDriverObserver::NotificationIconType handler_type); 130 FaviconDriverObserver::NotificationIconType handler_type);
122 ~FaviconHandler(); 131 ~FaviconHandler();
123 132
124 // Initiates loading the favicon for the specified url. 133 // Initiates loading the favicon for the specified url.
125 void FetchFavicon(const GURL& url); 134 void FetchFavicon(const GURL& url);
126 135
127 // Message Handler. Must be public, because also called from 136 // Collects the candidate favicons as listed in the HTML head, as well as
128 // PrerenderContents. Collects the |image_urls| list. 137 // the WebManifest URL if available.
129 void OnUpdateFaviconURL(const GURL& page_url, 138 void OnUpdateCandidates(const GURL& page_url,
130 const std::vector<favicon::FaviconURL>& candidates); 139 const std::vector<favicon::FaviconURL>& candidates,
140 const base::Optional<GURL>& manifest_url);
131 141
132 // For testing. 142 // For testing.
133 const std::vector<GURL> GetIconURLs() const; 143 const std::vector<GURL> GetIconURLs() const;
134 144
135 // Returns whether the handler is waiting for a download to complete or for 145 // Returns whether the handler is waiting for a download to complete or for
136 // data from the FaviconService. Reserved for testing. 146 // data from the FaviconService. Reserved for testing.
137 bool HasPendingTasksForTest(); 147 bool HasPendingTasksForTest();
138 148
139 // Get the maximal icon size in pixels for a handler of type |handler_type|. 149 // Get the maximal icon size in pixels for a handler of type |handler_type|.
140 static int GetMaximalIconSize( 150 static int GetMaximalIconSize(
(...skipping 26 matching lines...) Expand all
167 177
168 struct DownloadedFavicon { 178 struct DownloadedFavicon {
169 FaviconCandidate candidate; 179 FaviconCandidate candidate;
170 gfx::Image image; 180 gfx::Image image;
171 }; 181 };
172 182
173 // Returns the bit mask of favicon_base::IconType based on the handler's type. 183 // Returns the bit mask of favicon_base::IconType based on the handler's type.
174 static int GetIconTypesFromHandlerType( 184 static int GetIconTypesFromHandlerType(
175 FaviconDriverObserver::NotificationIconType handler_type); 185 FaviconDriverObserver::NotificationIconType handler_type);
176 186
187 // Called with the result of looking up cached icon data for the manifest's
188 // URL, which is used as icon URL.
189 void OnFaviconDataForManifestFromFaviconService(
190 const std::vector<favicon_base::FaviconRawBitmapResult>&
191 favicon_bitmap_results);
192
193 // Schedules a download for |manifest_url_|, which must not be empty. The
194 // request is stored in |manifest_download_request_| so it can be cancelled.
195 void ScheduleManifestDownload();
196
197 // Called when the dowloading of a manifest completes.
198 void OnDidDownloadManifest(int status_code,
199 const std::vector<FaviconURL>& candidates);
200
201 // Called when the actual list of favicon candidates to be processed is
202 // available, which can be either icon URLs listed in the HTML head instead
203 // or, if a Web Manifest was provided, the list of icons there.
204 void OnGotFinalIconURLCandidates(const std::vector<FaviconURL>& candidates);
205
177 // Called when the history request for favicon data mapped to |url_| has 206 // Called when the history request for favicon data mapped to |url_| has
178 // completed and the renderer has told us the icon URLs used by |url_| 207 // completed and the renderer has told us the icon URLs used by |url_|
179 void OnGotInitialHistoryDataAndIconURLCandidates(); 208 void OnGotInitialHistoryDataAndIconURLCandidates();
180 209
181 // See description above class for details. 210 // See description above class for details.
182 void OnFaviconDataForInitialURLFromFaviconService(const std::vector< 211 void OnFaviconDataForInitialURLFromFaviconService(const std::vector<
183 favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results); 212 favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results);
184 213
185 // If the favicon currently mapped to |url_| has expired, downloads the 214 // If the favicon currently mapped to |url_| has expired, downloads the
186 // current candidate favicon from the renderer. Otherwise requests data for 215 // current candidate favicon from the renderer. Otherwise requests data for
187 // the current favicon from history. If data is requested from history, 216 // the current favicon from history. If data is requested from history,
188 // OnFaviconData() is called with the history data once it has been retrieved. 217 // OnFaviconData() is called with the history data once it has been retrieved.
189 void DownloadCurrentCandidateOrAskFaviconService(); 218 void DownloadCurrentCandidateOrAskFaviconService();
190 219
220 // Requests the favicon for |icon_url| from the favicon service. Unless in
221 // incognito, it also updates the page URL (url_) to |icon_url| mappings.
222 void GetFaviconAndUpdateMappingsUnlessIncognito(
223 const GURL& icon_url,
224 favicon_base::IconType icon_type,
225 const favicon_base::FaviconResultsCallback& callback);
226
191 // See description above class for details. 227 // See description above class for details.
192 void OnFaviconData(const std::vector<favicon_base::FaviconRawBitmapResult>& 228 void OnFaviconData(const std::vector<favicon_base::FaviconRawBitmapResult>&
193 favicon_bitmap_results); 229 favicon_bitmap_results);
194 230
195 // Schedules a download for the specified entry. This adds the request to 231 // Schedules a download for |image_url|. The request is stored in
196 // download_requests_. 232 // image_download_request_ so it can be cancelled.
197 void ScheduleDownload(const GURL& image_url, 233 void ScheduleFaviconDownload(const GURL& image_url,
198 favicon_base::IconType icon_type); 234 favicon_base::IconType icon_type);
199 235
200 // Triggered when a download of an image has finished. 236 // Triggered when a download of an image has finished.
201 void OnDidDownloadFavicon( 237 void OnDidDownloadFavicon(
202 favicon_base::IconType icon_type, 238 favicon_base::IconType icon_type,
203 int id, 239 int id,
204 int http_status_code, 240 int http_status_code,
205 const GURL& image_url, 241 const GURL& image_url,
206 const std::vector<SkBitmap>& bitmaps, 242 const std::vector<SkBitmap>& bitmaps,
207 const std::vector<gfx::Size>& original_bitmap_sizes); 243 const std::vector<gfx::Size>& original_bitmap_sizes);
208 244
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 // to be incomplete. If true, it means there is a favicon mapped to |url_| in 294 // to be incomplete. If true, it means there is a favicon mapped to |url_| in
259 // history, but we need to redownload the icon URLs because the icon in the 295 // history, but we need to redownload the icon URLs because the icon in the
260 // database has expired or the data in the database is incomplete. 296 // database has expired or the data in the database is incomplete.
261 bool initial_history_result_expired_or_incomplete_; 297 bool initial_history_result_expired_or_incomplete_;
262 298
263 // Whether FaviconHandler should ignore history state and determine the 299 // Whether FaviconHandler should ignore history state and determine the
264 // optimal icon URL out of |image_urls_| for |url_| by downloading 300 // optimal icon URL out of |image_urls_| for |url_| by downloading
265 // |image_urls_| one by one. 301 // |image_urls_| one by one.
266 bool redownload_icons_; 302 bool redownload_icons_;
267 303
304 // Requests to the renderer to download a manifest.
305 base::CancelableCallback<Delegate::ManifestDownloadCallback::RunType>
306 manifest_download_request_;
307
268 // Requests to the renderer to download favicons. 308 // Requests to the renderer to download favicons.
269 base::CancelableCallback<Delegate::ImageDownloadCallback::RunType> 309 base::CancelableCallback<Delegate::ImageDownloadCallback::RunType>
270 download_request_; 310 image_download_request_;
271 311
272 // The combination of the supported icon types. 312 // The combination of the supported icon types.
273 const int icon_types_; 313 const int icon_types_;
274 314
275 // Whether the largest icon should be downloaded. 315 // Whether the largest icon should be downloaded.
276 const bool download_largest_icon_; 316 const bool download_largest_icon_;
277 317
318 // The manifest URL from the renderer.
319 base::Optional<GURL> manifest_url_;
320
321 // Original list of candidates provided to OnUpdateCandidates(), stored to
322 // be able to fall back to, in case a manifest was provided and downloading it
323 // failed (or provided no icons).
324 std::vector<FaviconURL> non_manifest_original_candidates_;
325
278 // The prioritized favicon candidates from the page back from the renderer. 326 // The prioritized favicon candidates from the page back from the renderer.
279 std::vector<FaviconCandidate> candidates_; 327 std::vector<FaviconCandidate> candidates_;
280 328
281 // The icon URL and the icon type of the favicon in the most recent 329 // The icon URL and the icon type of the favicon in the most recent
282 // FaviconDriver::OnFaviconAvailable() notification. 330 // FaviconDriver::OnFaviconAvailable() notification.
283 GURL notification_icon_url_; 331 GURL notification_icon_url_;
284 favicon_base::IconType notification_icon_type_; 332 favicon_base::IconType notification_icon_type_;
285 333
286 // The FaviconService which implements favicon operations. May be null during 334 // The FaviconService which implements favicon operations. May be null during
287 // testing. 335 // testing.
(...skipping 11 matching lines...) Expand all
299 // UpdateFaviconCandidate()), the favicon service and the delegate are 347 // UpdateFaviconCandidate()), the favicon service and the delegate are
300 // notified. 348 // notified.
301 DownloadedFavicon best_favicon_; 349 DownloadedFavicon best_favicon_;
302 350
303 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); 351 DISALLOW_COPY_AND_ASSIGN(FaviconHandler);
304 }; 352 };
305 353
306 } // namespace favicon 354 } // namespace favicon
307 355
308 #endif // COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_ 356 #endif // COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698