OLD | NEW |
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 Loading... |
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<void( |
| 91 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 Loading... |
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 a list of favicon candidates to be processed is available, which can |
| 188 // be either icon URLs listed in the HTML head instead or, if a Web Manifest |
| 189 // was provided, the list of icons there. |
| 190 void OnGotFinalIconURLCandidates(const std::vector<FaviconURL>& candidates); |
| 191 |
177 // Called when the history request for favicon data mapped to |url_| has | 192 // 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_| | 193 // completed and the renderer has told us the icon URLs used by |url_| |
179 void OnGotInitialHistoryDataAndIconURLCandidates(); | 194 void OnGotInitialHistoryDataAndIconURLCandidates(); |
180 | 195 |
181 // See description above class for details. | 196 // See description above class for details. |
182 void OnFaviconDataForInitialURLFromFaviconService(const std::vector< | 197 void OnFaviconDataForInitialURLFromFaviconService(const std::vector< |
183 favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results); | 198 favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results); |
184 | 199 |
| 200 void OnFaviconDataForManifestURLFromFaviconService( |
| 201 const std::vector<favicon_base::FaviconRawBitmapResult>& |
| 202 favicon_bitmap_results); |
| 203 |
185 // If the favicon currently mapped to |url_| has expired, downloads the | 204 // If the favicon currently mapped to |url_| has expired, downloads the |
186 // current candidate favicon from the renderer. Otherwise requests data for | 205 // current candidate favicon from the renderer. Otherwise requests data for |
187 // the current favicon from history. If data is requested from history, | 206 // the current favicon from history. If data is requested from history, |
188 // OnFaviconData() is called with the history data once it has been retrieved. | 207 // OnFaviconData() is called with the history data once it has been retrieved. |
189 void DownloadCurrentCandidateOrAskFaviconService(); | 208 void DownloadCurrentCandidateOrAskFaviconService(); |
190 | 209 |
191 // See description above class for details. | 210 // See description above class for details. |
192 void OnFaviconData(const std::vector<favicon_base::FaviconRawBitmapResult>& | 211 void OnFaviconData(const std::vector<favicon_base::FaviconRawBitmapResult>& |
193 favicon_bitmap_results); | 212 favicon_bitmap_results); |
194 | 213 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 // to be incomplete. If true, it means there is a favicon mapped to |url_| in | 277 // 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 | 278 // 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. | 279 // database has expired or the data in the database is incomplete. |
261 bool initial_history_result_expired_or_incomplete_; | 280 bool initial_history_result_expired_or_incomplete_; |
262 | 281 |
263 // Whether FaviconHandler should ignore history state and determine the | 282 // Whether FaviconHandler should ignore history state and determine the |
264 // optimal icon URL out of |image_urls_| for |url_| by downloading | 283 // optimal icon URL out of |image_urls_| for |url_| by downloading |
265 // |image_urls_| one by one. | 284 // |image_urls_| one by one. |
266 bool redownload_icons_; | 285 bool redownload_icons_; |
267 | 286 |
| 287 // Requests to the renderer to download a manifest. |
| 288 base::CancelableCallback<Delegate::ManifestDownloadCallback::RunType> |
| 289 manifest_download_request_; |
| 290 |
268 // Requests to the renderer to download favicons. | 291 // Requests to the renderer to download favicons. |
269 base::CancelableCallback<Delegate::ImageDownloadCallback::RunType> | 292 base::CancelableCallback<Delegate::ImageDownloadCallback::RunType> |
270 download_request_; | 293 image_download_request_; |
271 | 294 |
272 // The combination of the supported icon types. | 295 // The combination of the supported icon types. |
273 const int icon_types_; | 296 const int icon_types_; |
274 | 297 |
275 // Whether the largest icon should be downloaded. | 298 // Whether the largest icon should be downloaded. |
276 const bool download_largest_icon_; | 299 const bool download_largest_icon_; |
277 | 300 |
| 301 // The manifest URL from the renderer. |
| 302 base::Optional<GURL> manifest_url_; |
| 303 |
278 // The prioritized favicon candidates from the page back from the renderer. | 304 // The prioritized favicon candidates from the page back from the renderer. |
279 std::vector<FaviconCandidate> candidates_; | 305 std::vector<FaviconCandidate> candidates_; |
280 | 306 |
281 // The icon URL and the icon type of the favicon in the most recent | 307 // The icon URL and the icon type of the favicon in the most recent |
282 // FaviconDriver::OnFaviconAvailable() notification. | 308 // FaviconDriver::OnFaviconAvailable() notification. |
283 GURL notification_icon_url_; | 309 GURL notification_icon_url_; |
284 favicon_base::IconType notification_icon_type_; | 310 favicon_base::IconType notification_icon_type_; |
285 | 311 |
286 // The FaviconService which implements favicon operations. May be null during | 312 // The FaviconService which implements favicon operations. May be null during |
287 // testing. | 313 // testing. |
(...skipping 11 matching lines...) Expand all Loading... |
299 // UpdateFaviconCandidate()), the favicon service and the delegate are | 325 // UpdateFaviconCandidate()), the favicon service and the delegate are |
300 // notified. | 326 // notified. |
301 DownloadedFavicon best_favicon_; | 327 DownloadedFavicon best_favicon_; |
302 | 328 |
303 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); | 329 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); |
304 }; | 330 }; |
305 | 331 |
306 } // namespace favicon | 332 } // namespace favicon |
307 | 333 |
308 #endif // COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_ | 334 #endif // COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_ |
OLD | NEW |