| 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 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 virtual ~FaviconHandler(); | 87 virtual ~FaviconHandler(); |
| 88 | 88 |
| 89 // Returns the bit mask of favicon_base::IconType based on the handler's type. | 89 // Returns the bit mask of favicon_base::IconType based on the handler's type. |
| 90 static int GetIconTypesFromHandlerType(Type icon_type); | 90 static int GetIconTypesFromHandlerType(Type icon_type); |
| 91 | 91 |
| 92 // Initiates loading the favicon for the specified url. | 92 // Initiates loading the favicon for the specified url. |
| 93 void FetchFavicon(const GURL& url); | 93 void FetchFavicon(const GURL& url); |
| 94 | 94 |
| 95 // Message Handler. Must be public, because also called from | 95 // Message Handler. Must be public, because also called from |
| 96 // PrerenderContents. Collects the |image_urls| list. | 96 // PrerenderContents. Collects the |image_urls| list. |
| 97 void OnUpdateFaviconURL(const std::vector<favicon::FaviconURL>& candidates); | 97 void OnUpdateFaviconURL(const GURL& page_url, |
| 98 const std::vector<favicon::FaviconURL>& candidates); |
| 98 | 99 |
| 99 // Processes the current image_urls_ entry, requesting the image from the | 100 // Processes the current image_urls_ entry, requesting the image from the |
| 100 // history / download service. | 101 // history / download service. |
| 101 void ProcessCurrentUrl(); | 102 void ProcessCurrentUrl(); |
| 102 | 103 |
| 103 // Message handler for ImageHostMsg_DidDownloadImage. Called when the image | 104 // Message handler for ImageHostMsg_DidDownloadImage. Called when the image |
| 104 // at |image_url| has been downloaded. | 105 // at |image_url| has been downloaded. |
| 105 // |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|. |
| 106 // |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 |
| 107 // to the maximum bitmap size passed to DownloadFavicon(). | 108 // to the maximum bitmap size passed to DownloadFavicon(). |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 int icon_types, | 147 int icon_types, |
| 147 const favicon_base::FaviconResultsCallback& callback, | 148 const favicon_base::FaviconResultsCallback& callback, |
| 148 base::CancelableTaskTracker* tracker); | 149 base::CancelableTaskTracker* tracker); |
| 149 | 150 |
| 150 virtual void SetHistoryFavicons(const GURL& page_url, | 151 virtual void SetHistoryFavicons(const GURL& page_url, |
| 151 const GURL& icon_url, | 152 const GURL& icon_url, |
| 152 favicon_base::IconType icon_type, | 153 favicon_base::IconType icon_type, |
| 153 const gfx::Image& image); | 154 const gfx::Image& image); |
| 154 | 155 |
| 155 // Returns true if the favicon should be saved. | 156 // Returns true if the favicon should be saved. |
| 156 virtual bool ShouldSaveFavicon(const GURL& url); | 157 virtual bool ShouldSaveFavicon(); |
| 157 | 158 |
| 158 private: | 159 private: |
| 159 // For testing: | 160 // For testing: |
| 160 friend class TestFaviconHandler; | 161 friend class TestFaviconHandler; |
| 161 | 162 |
| 162 // Represents an in progress download of an image from the renderer. | 163 // Represents an in progress download of an image from the renderer. |
| 163 struct DownloadRequest { | 164 struct DownloadRequest { |
| 164 DownloadRequest(); | 165 DownloadRequest(); |
| 165 ~DownloadRequest(); | 166 ~DownloadRequest(); |
| 166 | 167 |
| 167 DownloadRequest(const GURL& url, | 168 DownloadRequest(const GURL& image_url, favicon_base::IconType icon_type); |
| 168 const GURL& image_url, | |
| 169 favicon_base::IconType icon_type); | |
| 170 | 169 |
| 171 GURL url; | |
| 172 GURL image_url; | 170 GURL image_url; |
| 173 favicon_base::IconType icon_type; | 171 favicon_base::IconType icon_type; |
| 174 }; | 172 }; |
| 175 | 173 |
| 176 // Used to track a candidate for the favicon. | 174 // Used to track a candidate for the favicon. |
| 177 struct FaviconCandidate { | 175 struct FaviconCandidate { |
| 178 FaviconCandidate(); | 176 FaviconCandidate(); |
| 179 ~FaviconCandidate(); | 177 ~FaviconCandidate(); |
| 180 | 178 |
| 181 FaviconCandidate(const GURL& url, | 179 FaviconCandidate(const GURL& image_url, |
| 182 const GURL& image_url, | |
| 183 const gfx::Image& image, | 180 const gfx::Image& image, |
| 184 float score, | 181 float score, |
| 185 favicon_base::IconType icon_type); | 182 favicon_base::IconType icon_type); |
| 186 | 183 |
| 187 GURL url; | |
| 188 GURL image_url; | 184 GURL image_url; |
| 189 gfx::Image image; | 185 gfx::Image image; |
| 190 float score; | 186 float score; |
| 191 favicon_base::IconType icon_type; | 187 favicon_base::IconType icon_type; |
| 192 }; | 188 }; |
| 193 | 189 |
| 194 // Get the maximal icon size in pixels for a icon of type |icon_type| for the | 190 // Get the maximal icon size in pixels for a icon of type |icon_type| for the |
| 195 // current platform. | 191 // current platform. |
| 196 static int GetMaximalIconSize(favicon_base::IconType icon_type); | 192 static int GetMaximalIconSize(favicon_base::IconType icon_type); |
| 197 | 193 |
| 198 // See description above class for details. | 194 // See description above class for details. |
| 199 void OnFaviconDataForInitialURLFromFaviconService(const std::vector< | 195 void OnFaviconDataForInitialURLFromFaviconService(const std::vector< |
| 200 favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results); | 196 favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results); |
| 201 | 197 |
| 202 // If the favicon has expired, asks the renderer to download the favicon. | 198 // If the favicon has expired, asks the renderer to download the favicon. |
| 203 // Otherwise asks history to update the mapping between page url and icon | 199 // Otherwise asks history to update the mapping between page url and icon |
| 204 // url with a callback to OnFaviconData when done. | 200 // url with a callback to OnFaviconData when done. |
| 205 void DownloadFaviconOrAskFaviconService(const GURL& page_url, | 201 void DownloadFaviconOrAskFaviconService(const GURL& icon_url, |
| 206 const GURL& icon_url, | |
| 207 favicon_base::IconType icon_type); | 202 favicon_base::IconType icon_type); |
| 208 | 203 |
| 209 // See description above class for details. | 204 // See description above class for details. |
| 210 void OnFaviconData(const std::vector<favicon_base::FaviconRawBitmapResult>& | 205 void OnFaviconData(const std::vector<favicon_base::FaviconRawBitmapResult>& |
| 211 favicon_bitmap_results); | 206 favicon_bitmap_results); |
| 212 | 207 |
| 213 // Schedules a download for the specified entry. This adds the request to | 208 // Schedules a download for the specified entry. This adds the request to |
| 214 // download_requests_. | 209 // download_requests_. |
| 215 void ScheduleDownload(const GURL& url, | 210 void ScheduleDownload(const GURL& image_url, |
| 216 const GURL& image_url, | |
| 217 favicon_base::IconType icon_type); | 211 favicon_base::IconType icon_type); |
| 218 | 212 |
| 219 // Updates |favicon_candidate_| and returns true if it is an exact match. | 213 // Updates |favicon_candidate_| and returns true if it is an exact match. |
| 220 bool UpdateFaviconCandidate(const GURL& url, | 214 bool UpdateFaviconCandidate(const GURL& image_url, |
| 221 const GURL& image_url, | |
| 222 const gfx::Image& image, | 215 const gfx::Image& image, |
| 223 float score, | 216 float score, |
| 224 favicon_base::IconType icon_type); | 217 favicon_base::IconType icon_type); |
| 225 | 218 |
| 226 // Sets the image data for the favicon. | 219 // Sets the image data for the favicon. |
| 227 void SetFavicon(const GURL& url, | 220 void SetFavicon(const GURL& icon_url, |
| 228 const GURL& icon_url, | |
| 229 const gfx::Image& image, | 221 const gfx::Image& image, |
| 230 favicon_base::IconType icon_type); | 222 favicon_base::IconType icon_type); |
| 231 | 223 |
| 232 // Notifies |driver_| favicon available. See | 224 // Notifies |driver_| favicon available. See |
| 233 // FaviconDriver::NotifyFaviconAvailable() for |is_active_favicon| in detail. | 225 // FaviconDriver::NotifyFaviconAvailable() for |is_active_favicon| in detail. |
| 234 void NotifyFaviconAvailable( | 226 void NotifyFaviconAvailable( |
| 235 const std::vector<favicon_base::FaviconRawBitmapResult>& | 227 const std::vector<favicon_base::FaviconRawBitmapResult>& |
| 236 favicon_bitmap_results); | 228 favicon_bitmap_results); |
| 237 void NotifyFaviconAvailable(const GURL& icon_url, | 229 void NotifyFaviconAvailable(const GURL& icon_url, |
| 238 const gfx::Image& image); | 230 const gfx::Image& image); |
| 239 | 231 |
| 240 // Return the current candidate if any. | 232 // Return the current candidate if any. |
| 241 favicon::FaviconURL* current_candidate() { | 233 favicon::FaviconURL* current_candidate() { |
| 242 return (!image_urls_.empty()) ? &image_urls_.front() : NULL; | 234 return (!image_urls_.empty()) ? &image_urls_.front() : NULL; |
| 243 } | 235 } |
| 244 | 236 |
| 245 // Returns whether the page's url changed since the favicon was requested. | |
| 246 bool PageChangedSinceFaviconWasRequested(); | |
| 247 | |
| 248 // Returns the preferred size of the image. 0 means no preference (any size | 237 // Returns the preferred size of the image. 0 means no preference (any size |
| 249 // will do). | 238 // will do). |
| 250 int preferred_icon_size() const { | 239 int preferred_icon_size() const { |
| 251 if (download_largest_icon_) | 240 if (download_largest_icon_) |
| 252 return 0; | 241 return 0; |
| 253 return handler_type_ == FAVICON ? gfx::kFaviconSize : 0; | 242 return handler_type_ == FAVICON ? gfx::kFaviconSize : 0; |
| 254 } | 243 } |
| 255 | 244 |
| 256 // Sorts the entries in |image_urls_| by icon size in descending order. | 245 // Sorts the entries in |image_urls_| by icon size in descending order. |
| 257 // Additionally removes any entries whose sizes are all greater than the max | 246 // Additionally removes any entries whose sizes are all greater than the max |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 // available the favicon service and the current page are updated (assuming | 293 // available the favicon service and the current page are updated (assuming |
| 305 // the image is for a favicon). | 294 // the image is for a favicon). |
| 306 FaviconCandidate best_favicon_candidate_; | 295 FaviconCandidate best_favicon_candidate_; |
| 307 | 296 |
| 308 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); | 297 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); |
| 309 }; | 298 }; |
| 310 | 299 |
| 311 } // namespace favicon | 300 } // namespace favicon |
| 312 | 301 |
| 313 #endif // COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_ | 302 #endif // COMPONENTS_FAVICON_CORE_FAVICON_HANDLER_H_ |
| OLD | NEW |