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 CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ |
6 #define CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ | 6 #define CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // favicon will be used, otherwise the one that best matches the preferred size | 71 // favicon will be used, otherwise the one that best matches the preferred size |
72 // is chosen (or the first one if there is no preferred size). Once the | 72 // is chosen (or the first one if there is no preferred size). Once the |
73 // matching favicon has been determined, SetFavicon is called which updates | 73 // matching favicon has been determined, SetFavicon is called which updates |
74 // the page's favicon and notifies the database to save the favicon. | 74 // the page's favicon and notifies the database to save the favicon. |
75 | 75 |
76 class FaviconHandler { | 76 class FaviconHandler { |
77 public: | 77 public: |
78 enum Type { | 78 enum Type { |
79 FAVICON, | 79 FAVICON, |
80 TOUCH, | 80 TOUCH, |
| 81 BIG, |
81 }; | 82 }; |
82 | 83 |
83 FaviconHandler(FaviconClient* client, | 84 FaviconHandler(FaviconClient* client, |
84 FaviconDriver* driver, | 85 FaviconDriver* driver, |
85 Type icon_type, | 86 Type handler_type, |
86 bool download_largest_icon); | 87 bool download_largest_icon); |
87 virtual ~FaviconHandler(); | 88 virtual ~FaviconHandler(); |
88 | 89 |
| 90 // Returns the bit mask of favicon_base::IconType based on the handler's type. |
| 91 static int GetIconTypesFromHandlerType(Type icon_type); |
| 92 |
89 // Initiates loading the favicon for the specified url. | 93 // Initiates loading the favicon for the specified url. |
90 void FetchFavicon(const GURL& url); | 94 void FetchFavicon(const GURL& url); |
91 | 95 |
92 // Message Handler. Must be public, because also called from | 96 // Message Handler. Must be public, because also called from |
93 // PrerenderContents. Collects the |image_urls| list. | 97 // PrerenderContents. Collects the |image_urls| list. |
94 void OnUpdateFaviconURL(const std::vector<favicon::FaviconURL>& candidates); | 98 void OnUpdateFaviconURL(const std::vector<favicon::FaviconURL>& candidates); |
95 | 99 |
96 // Processes the current image_irls_ entry, requesting the image from the | 100 // Processes the current image_urls_ entry, requesting the image from the |
97 // history / download service. | 101 // history / download service. |
98 void ProcessCurrentUrl(); | 102 void ProcessCurrentUrl(); |
99 | 103 |
100 // Message handler for ImageHostMsg_DidDownloadImage. Called when the image | 104 // Message handler for ImageHostMsg_DidDownloadImage. Called when the image |
101 // at |image_url| has been downloaded. | 105 // at |image_url| has been downloaded. |
102 // |bitmaps| is a list of all the frames of the image at |image_url|. | 106 // |bitmaps| is a list of all the frames of the image at |image_url|. |
103 // |original_bitmap_sizes| are the sizes of |bitmaps| before they were resized | 107 // |original_bitmap_sizes| are the sizes of |bitmaps| before they were resized |
104 // to the maximum bitmap size passed to DownloadFavicon(). | 108 // to the maximum bitmap size passed to DownloadFavicon(). |
105 void OnDidDownloadFavicon( | 109 void OnDidDownloadFavicon( |
106 int id, | 110 int id, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 } | 241 } |
238 | 242 |
239 // Returns whether the page's url changed since the favicon was requested. | 243 // Returns whether the page's url changed since the favicon was requested. |
240 bool PageChangedSinceFaviconWasRequested(); | 244 bool PageChangedSinceFaviconWasRequested(); |
241 | 245 |
242 // Returns the preferred size of the image. 0 means no preference (any size | 246 // Returns the preferred size of the image. 0 means no preference (any size |
243 // will do). | 247 // will do). |
244 int preferred_icon_size() const { | 248 int preferred_icon_size() const { |
245 if (download_largest_icon_) | 249 if (download_largest_icon_) |
246 return 0; | 250 return 0; |
247 return icon_types_ == favicon_base::FAVICON ? gfx::kFaviconSize : 0; | 251 return handler_type_ == FAVICON ? gfx::kFaviconSize : 0; |
248 } | 252 } |
249 | 253 |
250 // Sorts the entries in |image_urls_| by icon size in descending order. | 254 // Sorts the entries in |image_urls_| by icon size in descending order. |
251 // Additionally removes any entries whose sizes are all greater than the max | 255 // Additionally removes any entries whose sizes are all greater than the max |
252 // allowed size. | 256 // allowed size. |
253 void SortAndPruneImageUrls(); | 257 void SortAndPruneImageUrls(); |
254 | 258 |
255 // Used for FaviconService requests. | 259 // Used for FaviconService requests. |
256 base::CancelableTaskTracker cancelable_task_tracker_; | 260 base::CancelableTaskTracker cancelable_task_tracker_; |
257 | 261 |
258 // URL of the page we're requesting the favicon for. | 262 // URL of the page we're requesting the favicon for. |
259 GURL url_; | 263 GURL url_; |
260 | 264 |
261 // Whether we got the initial response for the favicon back from the renderer. | 265 // Whether we got the initial response for the favicon back from the renderer. |
262 bool got_favicon_from_history_; | 266 bool got_favicon_from_history_; |
263 | 267 |
264 // Whether the favicon is out of date or the favicon data in | 268 // Whether the favicon is out of date or the favicon data in |
265 // |history_results_| is known to be incomplete. If true, it means history | 269 // |history_results_| is known to be incomplete. If true, it means history |
266 // knows about the favicon, but we need to download the favicon because the | 270 // knows about the favicon, but we need to download the favicon because the |
267 // icon has expired or the data in the database is incomplete. | 271 // icon has expired or the data in the database is incomplete. |
268 bool favicon_expired_or_incomplete_; | 272 bool favicon_expired_or_incomplete_; |
269 | 273 |
270 // Requests to the renderer to download favicons. | 274 // Requests to the renderer to download favicons. |
271 typedef std::map<int, DownloadRequest> DownloadRequests; | 275 typedef std::map<int, DownloadRequest> DownloadRequests; |
272 DownloadRequests download_requests_; | 276 DownloadRequests download_requests_; |
273 | 277 |
| 278 // The type of the current handler. |
| 279 const Type handler_type_; |
| 280 |
274 // The combination of the supported icon types. | 281 // The combination of the supported icon types. |
275 const int icon_types_; | 282 const int icon_types_; |
276 | 283 |
277 // Whether the largest icon should be downloaded. | 284 // Whether the largest icon should be downloaded. |
278 const bool download_largest_icon_; | 285 const bool download_largest_icon_; |
279 | 286 |
280 // The prioritized favicon candidates from the page back from the renderer. | 287 // The prioritized favicon candidates from the page back from the renderer. |
281 std::vector<favicon::FaviconURL> image_urls_; | 288 std::vector<favicon::FaviconURL> image_urls_; |
282 | 289 |
283 // The FaviconRawBitmapResults from history. | 290 // The FaviconRawBitmapResults from history. |
284 std::vector<favicon_base::FaviconRawBitmapResult> history_results_; | 291 std::vector<favicon_base::FaviconRawBitmapResult> history_results_; |
285 | 292 |
286 // The client which implements embedder-specific Favicon operations. | 293 // The client which implements embedder-specific Favicon operations. |
287 FaviconClient* client_; // weak | 294 FaviconClient* client_; // weak |
288 | 295 |
289 // This handler's driver. | 296 // This handler's driver. |
290 FaviconDriver* driver_; // weak | 297 FaviconDriver* driver_; // weak |
291 | 298 |
292 // Best image we've seen so far. As images are downloaded from the page they | 299 // Best image we've seen so far. As images are downloaded from the page they |
293 // are stored here. When there is an exact match, or no more images are | 300 // are stored here. When there is an exact match, or no more images are |
294 // available the favicon service and the current page are updated (assuming | 301 // available the favicon service and the current page are updated (assuming |
295 // the image is for a favicon). | 302 // the image is for a favicon). |
296 FaviconCandidate best_favicon_candidate_; | 303 FaviconCandidate best_favicon_candidate_; |
297 | 304 |
298 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); | 305 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); |
299 }; | 306 }; |
300 | 307 |
301 #endif // CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ | 308 #endif // CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ |
OLD | NEW |