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

Side by Side Diff: components/favicon/core/favicon_handler.h

Issue 2799273002: Add support to process favicons from Web Manifests (Closed)
Patch Set: Reverted fieldtrial_testing_config.json Created 3 years, 7 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
27 namespace base {
28 struct Feature;
29 } // namespace base
30
26 namespace favicon { 31 namespace favicon {
27 32
28 class FaviconService; 33 class FaviconService;
29 34
35 extern const base::Feature kFaviconsFromWebManifest;
36
30 // FaviconHandler works with FaviconDriver to fetch the specific type of 37 // FaviconHandler works with FaviconDriver to fetch the specific type of
31 // favicon. 38 // favicon.
32 // 39 //
33 // FetchFavicon requests the favicon from the favicon service which in turn 40 // FetchFavicon requests the favicon from the favicon service which in turn
34 // requests the favicon from the history database. At this point 41 // requests the favicon from the history database. At this point
35 // we only know the URL of the page, and not necessarily the url of the 42 // we only know the URL of the page, and not necessarily the url of the
36 // favicon. To ensure we handle reloading stale favicons as well as 43 // favicon. To ensure we handle reloading stale favicons as well as
37 // reloading a favicon on page reload we always request the favicon from 44 // reloading a favicon on page reload we always request the favicon from
38 // history regardless of whether the active favicon is valid. 45 // history regardless of whether the active favicon is valid.
39 // 46 //
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 public: 99 public:
93 // Mimics WebContents::ImageDownloadCallback. 100 // Mimics WebContents::ImageDownloadCallback.
94 typedef base::Callback<void( 101 typedef base::Callback<void(
95 int id, 102 int id,
96 int status_code, 103 int status_code,
97 const GURL& image_url, 104 const GURL& image_url,
98 const std::vector<SkBitmap>& bitmaps, 105 const std::vector<SkBitmap>& bitmaps,
99 const std::vector<gfx::Size>& original_bitmap_sizes)> 106 const std::vector<gfx::Size>& original_bitmap_sizes)>
100 ImageDownloadCallback; 107 ImageDownloadCallback;
101 108
109 typedef base::Callback<void(
110 const std::vector<favicon::FaviconURL>& favicons)>
111 ManifestDownloadCallback;
112
102 // Starts the download for the given favicon. When finished, the callback 113 // Starts the download for the given favicon. When finished, the callback
103 // is called with the results. Returns the unique id of the download 114 // is called with the results. Returns the unique id of the download
104 // request, which will also be passed to the callback. In case of error, 0 115 // request, which will also be passed to the callback. In case of error, 0
105 // is returned and no callback will be called. 116 // is returned and no callback will be called.
106 // Bitmaps with pixel sizes larger than |max_bitmap_size| are filtered out 117 // Bitmaps with pixel sizes larger than |max_bitmap_size| are filtered out
107 // from the bitmap results. If there are no bitmap results <= 118 // from the bitmap results. If there are no bitmap results <=
108 // |max_bitmap_size|, the smallest bitmap is resized to |max_bitmap_size| 119 // |max_bitmap_size|, the smallest bitmap is resized to |max_bitmap_size|
109 // and is the only result. A |max_bitmap_size| of 0 means unlimited. 120 // and is the only result. A |max_bitmap_size| of 0 means unlimited.
110 virtual int DownloadImage(const GURL& url, 121 virtual int DownloadImage(const GURL& url,
111 int max_image_size, 122 int max_image_size,
112 ImageDownloadCallback callback) = 0; 123 ImageDownloadCallback callback) = 0;
113 124
125 // Downloads a WebManifest and returns the favicons listed there.
126 virtual void DownloadManifest(const GURL& url,
127 ManifestDownloadCallback callback) = 0;
128
114 // Returns whether the user is operating in an off-the-record context. 129 // Returns whether the user is operating in an off-the-record context.
115 virtual bool IsOffTheRecord() = 0; 130 virtual bool IsOffTheRecord() = 0;
116 131
117 // Returns whether |url| is bookmarked. 132 // Returns whether |url| is bookmarked.
118 virtual bool IsBookmarked(const GURL& url) = 0; 133 virtual bool IsBookmarked(const GURL& url) = 0;
119 134
120 // Notifies that the favicon image has been updated. Most delegates 135 // Notifies that the favicon image has been updated. Most delegates
121 // propagate the notification to FaviconDriverObserver::OnFaviconUpdated(). 136 // propagate the notification to FaviconDriverObserver::OnFaviconUpdated().
122 // See its documentation for details. 137 // See its documentation for details.
123 virtual void OnFaviconUpdated( 138 virtual void OnFaviconUpdated(
124 const GURL& page_url, 139 const GURL& page_url,
125 FaviconDriverObserver::NotificationIconType notification_icon_type, 140 FaviconDriverObserver::NotificationIconType notification_icon_type,
126 const GURL& icon_url, 141 const GURL& icon_url,
127 bool icon_url_changed, 142 bool icon_url_changed,
128 const gfx::Image& image) = 0; 143 const gfx::Image& image) = 0;
129 }; 144 };
130 145
131 // |service| and |delegate| must not be nullptr and must outlive this class. 146 // |service| and |delegate| must not be nullptr and must outlive this class.
132 FaviconHandler(FaviconService* service, 147 FaviconHandler(FaviconService* service,
133 Delegate* delegate, 148 Delegate* delegate,
134 FaviconDriverObserver::NotificationIconType handler_type); 149 FaviconDriverObserver::NotificationIconType handler_type);
135 ~FaviconHandler(); 150 ~FaviconHandler();
136 151
137 // Initiates loading the favicon for the specified url. 152 // Initiates loading the favicon for the specified url.
138 void FetchFavicon(const GURL& url); 153 void FetchFavicon(const GURL& url);
139 154
140 // Message Handler. Must be public, because also called from 155 // Collects the candidate favicons as listed in the HTML head, as well as
141 // PrerenderContents. Collects the |image_urls| list. 156 // the WebManifest URL if available.
142 void OnUpdateCandidates(const GURL& page_url, 157 void OnUpdateCandidates(const GURL& page_url,
143 const std::vector<favicon::FaviconURL>& candidates); 158 const std::vector<favicon::FaviconURL>& candidates,
159 const base::Optional<GURL>& manifest_url);
160
161 // Returns the supported icon types, inferred from the handler type as passed
162 // in the constructor.
163 int icon_types() const { return icon_types_; }
144 164
145 // For testing. 165 // For testing.
146 const std::vector<GURL> GetIconURLs() const; 166 const std::vector<GURL> GetIconURLs() const;
147 167
148 // Returns whether the handler is waiting for a download to complete or for 168 // Returns whether the handler is waiting for a download to complete or for
149 // data from the FaviconService. Reserved for testing. 169 // data from the FaviconService. Reserved for testing.
150 bool HasPendingTasksForTest(); 170 bool HasPendingTasksForTest();
151 171
152 // Get the maximal icon size in pixels for a handler of type |handler_type|. 172 // Get the maximal icon size in pixels for a handler of type |handler_type|.
153 static int GetMaximalIconSize( 173 static int GetMaximalIconSize(
(...skipping 26 matching lines...) Expand all
180 200
181 struct DownloadedFavicon { 201 struct DownloadedFavicon {
182 FaviconCandidate candidate; 202 FaviconCandidate candidate;
183 gfx::Image image; 203 gfx::Image image;
184 }; 204 };
185 205
186 // Returns the bit mask of favicon_base::IconType based on the handler's type. 206 // Returns the bit mask of favicon_base::IconType based on the handler's type.
187 static int GetIconTypesFromHandlerType( 207 static int GetIconTypesFromHandlerType(
188 FaviconDriverObserver::NotificationIconType handler_type); 208 FaviconDriverObserver::NotificationIconType handler_type);
189 209
210 // Called with the result of looking up cached icon data for the manifest's
211 // URL, which is used as icon URL.
212 void OnFaviconDataForManifestFromFaviconService(
213 const std::vector<favicon_base::FaviconRawBitmapResult>&
214 favicon_bitmap_results);
215
216 // Called when the dowloading of a manifest completes.
217 void OnDidDownloadManifest(const std::vector<FaviconURL>& candidates);
218
219 // Called when the actual list of favicon candidates to be processed is
220 // available, which can be either icon URLs listed in the HTML head instead
221 // or, if a Web Manifest was provided, the list of icons there.
222 void OnGotFinalIconURLCandidates(const std::vector<FaviconURL>& candidates);
223
190 // Called when the history request for favicon data mapped to |url_| has 224 // Called when the history request for favicon data mapped to |url_| has
191 // completed and the renderer has told us the icon URLs used by |url_| 225 // completed and the renderer has told us the icon URLs used by |url_|
192 void OnGotInitialHistoryDataAndIconURLCandidates(); 226 void OnGotInitialHistoryDataAndIconURLCandidates();
193 227
194 // See description above class for details. 228 // See description above class for details.
195 void OnFaviconDataForInitialURLFromFaviconService(const std::vector< 229 void OnFaviconDataForInitialURLFromFaviconService(const std::vector<
196 favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results); 230 favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results);
197 231
198 // If the favicon currently mapped to |url_| has expired, downloads the 232 // If the favicon currently mapped to |url_| has expired, downloads the
199 // current candidate favicon from the renderer. Otherwise requests data for 233 // current candidate favicon from the renderer. Otherwise requests data for
200 // the current favicon from history. If data is requested from history, 234 // the current favicon from history. If data is requested from history,
201 // OnFaviconData() is called with the history data once it has been retrieved. 235 // OnFaviconData() is called with the history data once it has been retrieved.
202 void DownloadCurrentCandidateOrAskFaviconService(); 236 void DownloadCurrentCandidateOrAskFaviconService();
203 237
238 // Requests the favicon for |icon_url| from the favicon service. Unless in
239 // incognito, it also updates the page URL (url_) to |icon_url| mappings.
240 void GetFaviconAndUpdateMappingsUnlessIncognito(
241 const GURL& icon_url,
242 favicon_base::IconType icon_type,
243 const favicon_base::FaviconResultsCallback& callback);
244
204 // See description above class for details. 245 // See description above class for details.
205 void OnFaviconData(const std::vector<favicon_base::FaviconRawBitmapResult>& 246 void OnFaviconData(const std::vector<favicon_base::FaviconRawBitmapResult>&
206 favicon_bitmap_results); 247 favicon_bitmap_results);
207 248
208 // Schedules a download for the specified entry. This adds the request to 249 // Schedules a download for the specified entry. This adds the request to
209 // image_download_requests_. 250 // image_download_requests_.
210 void ScheduleImageDownload(const GURL& image_url, 251 void ScheduleImageDownload(const GURL& image_url,
211 favicon_base::IconType icon_type); 252 favicon_base::IconType icon_type);
212 253
213 // Triggered when a download of an image has finished. 254 // Triggered when a download of an image has finished.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 // to be incomplete. If true, it means there is a favicon mapped to |url_| in 317 // to be incomplete. If true, it means there is a favicon mapped to |url_| in
277 // history, but we need to redownload the icon URLs because the icon in the 318 // history, but we need to redownload the icon URLs because the icon in the
278 // database has expired or the data in the database is incomplete. 319 // database has expired or the data in the database is incomplete.
279 bool initial_history_result_expired_or_incomplete_; 320 bool initial_history_result_expired_or_incomplete_;
280 321
281 // Whether FaviconHandler should ignore history state and determine the 322 // Whether FaviconHandler should ignore history state and determine the
282 // optimal icon URL out of |image_urls_| for |url_| by downloading 323 // optimal icon URL out of |image_urls_| for |url_| by downloading
283 // |image_urls_| one by one. 324 // |image_urls_| one by one.
284 bool redownload_icons_; 325 bool redownload_icons_;
285 326
327 // Requests to the renderer to download a manifest.
328 base::CancelableCallback<Delegate::ManifestDownloadCallback::RunType>
329 manifest_download_request_;
330
286 // Requests to the renderer to download favicons. 331 // Requests to the renderer to download favicons.
287 base::CancelableCallback<Delegate::ImageDownloadCallback::RunType> 332 base::CancelableCallback<Delegate::ImageDownloadCallback::RunType>
288 image_download_request_; 333 image_download_request_;
289 334
290 // The combination of the supported icon types. 335 // The combination of the supported icon types.
291 const int icon_types_; 336 const int icon_types_;
292 337
293 // Whether the largest icon should be downloaded. 338 // Whether the largest icon should be downloaded.
294 const bool download_largest_icon_; 339 const bool download_largest_icon_;
295 340
341 // The manifest URL from the renderer.
342 base::Optional<GURL> manifest_url_;
343
344 // Original list of candidates provided to OnUpdateCandidates(), stored to
345 // be able to fall back to, in case a manifest was provided and downloading it
346 // failed (or provided no icons).
347 std::vector<FaviconURL> non_manifest_original_candidates_;
348
296 // The prioritized favicon candidates from the page back from the renderer. 349 // The prioritized favicon candidates from the page back from the renderer.
297 std::vector<FaviconCandidate> candidates_; 350 std::vector<FaviconCandidate> candidates_;
298 351
299 // The icon URL and the icon type of the favicon in the most recent 352 // The icon URL and the icon type of the favicon in the most recent
300 // FaviconDriver::OnFaviconAvailable() notification. 353 // FaviconDriver::OnFaviconAvailable() notification.
301 GURL notification_icon_url_; 354 GURL notification_icon_url_;
302 favicon_base::IconType notification_icon_type_; 355 favicon_base::IconType notification_icon_type_;
303 356
304 // The FaviconService which implements favicon operations. May be null during 357 // The FaviconService which implements favicon operations. May be null during
305 // testing. 358 // testing.
(...skipping 15 matching lines...) Expand all
321 // UpdateFaviconCandidate()), the favicon service and the delegate are 374 // UpdateFaviconCandidate()), the favicon service and the delegate are
322 // notified. 375 // notified.
323 DownloadedFavicon best_favicon_; 376 DownloadedFavicon best_favicon_;
324 377
325 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); 378 DISALLOW_COPY_AND_ASSIGN(FaviconHandler);
326 }; 379 };
327 380
328 } // namespace favicon 381 } // namespace favicon
329 382
330 #endif // COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_ 383 #endif // COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698