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 <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/task/cancelable_task_tracker.h" | 14 #include "base/task/cancelable_task_tracker.h" |
| 15 #include "components/favicon/core/favicon_driver_observer.h" |
15 #include "components/favicon/core/favicon_url.h" | 16 #include "components/favicon/core/favicon_url.h" |
16 #include "components/favicon_base/favicon_callback.h" | 17 #include "components/favicon_base/favicon_callback.h" |
17 #include "ui/gfx/favicon_size.h" | 18 #include "ui/gfx/favicon_size.h" |
18 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
20 | 21 |
21 class SkBitmap; | 22 class SkBitmap; |
22 | 23 |
23 namespace base { | 24 namespace base { |
24 class RefCountedMemory; | 25 class RefCountedMemory; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // | 72 // |
72 // When the renderer downloads favicons, it considers the entire list of | 73 // When the renderer downloads favicons, it considers the entire list of |
73 // favicon candidates, if |download_largest_favicon_| is true, the largest | 74 // favicon candidates, if |download_largest_favicon_| is true, the largest |
74 // favicon will be used, otherwise the one that best matches the preferred size | 75 // favicon will be used, otherwise the one that best matches the preferred size |
75 // is chosen (or the first one if there is no preferred size). Once the | 76 // is chosen (or the first one if there is no preferred size). Once the |
76 // matching favicon has been determined, SetFavicon is called which updates | 77 // matching favicon has been determined, SetFavicon is called which updates |
77 // the page's favicon and notifies the database to save the favicon. | 78 // the page's favicon and notifies the database to save the favicon. |
78 | 79 |
79 class FaviconHandler { | 80 class FaviconHandler { |
80 public: | 81 public: |
81 enum Type { | |
82 // Selects the icon URL of type favicon_base::FAVICON with bitmaps whose | |
83 // edge sizes most closely match "16 * favicon_base::GetFaviconScales()". | |
84 // When favicon_base::GetFaviconScales() returns multiple scales, the ideal | |
85 // match is a .ico file. | |
86 FAVICON, | |
87 | |
88 // Selects the icon URL of type favicon_base::FAVICON with the largest | |
89 // bitmap. | |
90 LARGEST_FAVICON, | |
91 | |
92 // Selects the icon URL of type favicon_base::TOUCH_ICON or | |
93 // favicon_base::TOUCH_PRECOMPOSED_ICON with the largest bitmap. | |
94 LARGEST_TOUCH | |
95 }; | |
96 | |
97 FaviconHandler(FaviconService* service, | 82 FaviconHandler(FaviconService* service, |
98 FaviconDriver* driver, | 83 FaviconDriver* driver, |
99 Type handler_type); | 84 FaviconDriverObserver::NotificationIconType handler_type); |
100 virtual ~FaviconHandler(); | 85 virtual ~FaviconHandler(); |
101 | 86 |
102 // Returns the bit mask of favicon_base::IconType based on the handler's type. | 87 // Returns the bit mask of favicon_base::IconType based on the handler's type. |
103 static int GetIconTypesFromHandlerType(Type icon_type); | 88 static int GetIconTypesFromHandlerType( |
| 89 FaviconDriverObserver::NotificationIconType handler_type); |
104 | 90 |
105 // Initiates loading the favicon for the specified url. | 91 // Initiates loading the favicon for the specified url. |
106 void FetchFavicon(const GURL& url); | 92 void FetchFavicon(const GURL& url); |
107 | 93 |
108 // Message Handler. Must be public, because also called from | 94 // Message Handler. Must be public, because also called from |
109 // PrerenderContents. Collects the |image_urls| list. | 95 // PrerenderContents. Collects the |image_urls| list. |
110 void OnUpdateFaviconURL(const GURL& page_url, | 96 void OnUpdateFaviconURL(const GURL& page_url, |
111 const std::vector<favicon::FaviconURL>& candidates); | 97 const std::vector<favicon::FaviconURL>& candidates); |
112 | 98 |
113 // Called when the history request for favicon data mapped to |url_| has | 99 // Called when the history request for favicon data mapped to |url_| has |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 bool UpdateFaviconCandidate(const GURL& image_url, | 213 bool UpdateFaviconCandidate(const GURL& image_url, |
228 const gfx::Image& image, | 214 const gfx::Image& image, |
229 float score, | 215 float score, |
230 favicon_base::IconType icon_type); | 216 favicon_base::IconType icon_type); |
231 | 217 |
232 // Sets the image data for the favicon. | 218 // Sets the image data for the favicon. |
233 void SetFavicon(const GURL& icon_url, | 219 void SetFavicon(const GURL& icon_url, |
234 const gfx::Image& image, | 220 const gfx::Image& image, |
235 favicon_base::IconType icon_type); | 221 favicon_base::IconType icon_type); |
236 | 222 |
237 // Notifies |driver_| favicon available. See | 223 // Notifies |driver_| that FaviconHandler found an icon which matches the |
238 // FaviconDriver::NotifyFaviconAvailable() for |is_active_favicon| in detail. | 224 // |handler_type_| criteria. NotifyFaviconUpdated() can be called multiple |
239 void NotifyFaviconAvailable( | 225 // times for the same page if: |
| 226 // - a better match is found for |handler_type_| (e.g. newer bitmap data) |
| 227 // - Javascript changes the page's icon URLs. |
| 228 void NotifyFaviconUpdated( |
240 const std::vector<favicon_base::FaviconRawBitmapResult>& | 229 const std::vector<favicon_base::FaviconRawBitmapResult>& |
241 favicon_bitmap_results); | 230 favicon_bitmap_results); |
242 void NotifyFaviconAvailable(const GURL& icon_url, | 231 void NotifyFaviconUpdated(const GURL& icon_url, |
243 favicon_base::IconType icon_type, | 232 favicon_base::IconType icon_type, |
244 const gfx::Image& image); | 233 const gfx::Image& image); |
245 | 234 |
246 // Return the current candidate if any. | 235 // Return the current candidate if any. |
247 favicon::FaviconURL* current_candidate() { | 236 favicon::FaviconURL* current_candidate() { |
248 return current_candidate_index_ < image_urls_.size() | 237 return current_candidate_index_ < image_urls_.size() |
249 ? &image_urls_[current_candidate_index_] | 238 ? &image_urls_[current_candidate_index_] |
250 : nullptr; | 239 : nullptr; |
251 } | 240 } |
252 | 241 |
253 // Returns the preferred size of the image. 0 means no preference (any size | 242 // Returns the preferred size of the image. 0 means no preference (any size |
254 // will do). | 243 // will do). |
255 int preferred_icon_size() const { | 244 int preferred_icon_size() const { |
256 return download_largest_icon_ ? 0 : gfx::kFaviconSize; | 245 return download_largest_icon_ ? 0 : gfx::kFaviconSize; |
257 } | 246 } |
258 | 247 |
259 // Used for FaviconService requests. | 248 // Used for FaviconService requests. |
260 base::CancelableTaskTracker cancelable_task_tracker_; | 249 base::CancelableTaskTracker cancelable_task_tracker_; |
261 | 250 |
| 251 FaviconDriverObserver::NotificationIconType handler_type_; |
| 252 |
262 // URL of the page we're requesting the favicon for. | 253 // URL of the page we're requesting the favicon for. |
263 GURL url_; | 254 GURL url_; |
264 | 255 |
265 // Whether we got data back for the initial request to the FaviconService. | 256 // Whether we got data back for the initial request to the FaviconService. |
266 bool got_favicon_from_history_; | 257 bool got_favicon_from_history_; |
267 | 258 |
268 // Whether the history data returned in | 259 // Whether the history data returned in |
269 // OnFaviconDataForInitialURLFromFaviconService() is out of date or is known | 260 // OnFaviconDataForInitialURLFromFaviconService() is out of date or is known |
270 // to be incomplete. If true, it means there is a favicon mapped to |url_| in | 261 // to be incomplete. If true, it means there is a favicon mapped to |url_| in |
271 // history, but we need to redownload the icon URLs because the icon in the | 262 // history, but we need to redownload the icon URLs because the icon in the |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 // available the favicon service and the current page are updated (assuming | 302 // available the favicon service and the current page are updated (assuming |
312 // the image is for a favicon). | 303 // the image is for a favicon). |
313 FaviconCandidate best_favicon_candidate_; | 304 FaviconCandidate best_favicon_candidate_; |
314 | 305 |
315 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); | 306 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); |
316 }; | 307 }; |
317 | 308 |
318 } // namespace favicon | 309 } // namespace favicon |
319 | 310 |
320 #endif // COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_ | 311 #endif // COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_ |
OLD | NEW |