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