OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
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 "chrome/browser/cancelable_request.h" | 14 #include "chrome/browser/cancelable_request.h" |
15 #include "chrome/browser/favicon/favicon_service.h" | 15 #include "chrome/browser/favicon/favicon_service.h" |
16 #include "chrome/browser/favicon/favicon_tab_helper.h" | 16 #include "chrome/browser/favicon/favicon_tab_helper.h" |
17 #include "chrome/common/favicon_url.h" | 17 #include "chrome/common/favicon_url.h" |
18 #include "chrome/common/ref_counted_util.h" | 18 #include "chrome/common/ref_counted_util.h" |
19 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
20 #include "ui/gfx/favicon_size.h" | 20 #include "ui/gfx/favicon_size.h" |
| 21 #include "ui/gfx/image/image.h" |
21 | 22 |
22 class FaviconHandlerDelegate; | 23 class FaviconHandlerDelegate; |
23 class Profile; | 24 class Profile; |
24 class RefCountedMemory; | 25 class RefCountedMemory; |
25 class SkBitmap; | 26 class SkBitmap; |
26 class TabContents; | 27 class TabContents; |
27 | 28 |
28 namespace content { | 29 namespace content { |
29 class NavigationEntry; | 30 class NavigationEntry; |
30 } | 31 } |
31 | 32 |
32 namespace gfx { | |
33 class Image; | |
34 } | |
35 | |
36 // FaviconHandler works with FaviconTabHelper to fetch the specific type of | 33 // FaviconHandler works with FaviconTabHelper to fetch the specific type of |
37 // favicon. | 34 // favicon. |
38 // | 35 // |
39 // FetchFavicon requests the favicon from the favicon service which in turn | 36 // FetchFavicon requests the favicon from the favicon service which in turn |
40 // requests the favicon from the history database. At this point | 37 // requests the favicon from the history database. At this point |
41 // we only know the URL of the page, and not necessarily the url of the | 38 // we only know the URL of the page, and not necessarily the url of the |
42 // favicon. To ensure we handle reloading stale favicons as well as | 39 // favicon. To ensure we handle reloading stale favicons as well as |
43 // reloading a favicon on page reload we always request the favicon from | 40 // reloading a favicon on page reload we always request the favicon from |
44 // history regardless of whether the NavigationEntry has a favicon. | 41 // history regardless of whether the NavigationEntry has a favicon. |
45 // | 42 // |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 const GURL& image_url, | 162 const GURL& image_url, |
166 const FaviconTabHelper::ImageDownloadCallback& callback, | 163 const FaviconTabHelper::ImageDownloadCallback& callback, |
167 history::IconType icon_type); | 164 history::IconType icon_type); |
168 | 165 |
169 GURL url; | 166 GURL url; |
170 GURL image_url; | 167 GURL image_url; |
171 FaviconTabHelper::ImageDownloadCallback callback; | 168 FaviconTabHelper::ImageDownloadCallback callback; |
172 history::IconType icon_type; | 169 history::IconType icon_type; |
173 }; | 170 }; |
174 | 171 |
| 172 struct FaviconCandidate { |
| 173 FaviconCandidate(); |
| 174 ~FaviconCandidate(); |
| 175 |
| 176 FaviconCandidate(const GURL& url, |
| 177 const GURL& image_url, |
| 178 const gfx::Image& image, |
| 179 history::IconType icon_type); |
| 180 |
| 181 GURL url; |
| 182 GURL image_url; |
| 183 gfx::Image image; |
| 184 history::IconType icon_type; |
| 185 }; |
| 186 typedef std::vector<FaviconCandidate> FaviconCandidates; |
| 187 |
175 // See description above class for details. | 188 // See description above class for details. |
176 void OnFaviconDataForInitialURL(FaviconService::Handle handle, | 189 void OnFaviconDataForInitialURL(FaviconService::Handle handle, |
177 history::FaviconData favicon); | 190 history::FaviconData favicon); |
178 | 191 |
179 // If the favicon has expired, asks the renderer to download the favicon. | 192 // If the favicon has expired, asks the renderer to download the favicon. |
180 // Otherwise asks history to update the mapping between page url and icon | 193 // Otherwise asks history to update the mapping between page url and icon |
181 // url with a callback to OnFaviconData when done. | 194 // url with a callback to OnFaviconData when done. |
182 void DownloadFaviconOrAskHistory(const GURL& page_url, | 195 void DownloadFaviconOrAskHistory(const GURL& page_url, |
183 const GURL& icon_url, | 196 const GURL& icon_url, |
184 history::IconType icon_type); | 197 history::IconType icon_type); |
185 | 198 |
186 // See description above class for details. | 199 // See description above class for details. |
187 void OnFaviconData(FaviconService::Handle handle, | 200 void OnFaviconData(FaviconService::Handle handle, |
188 history::FaviconData favicon); | 201 history::FaviconData favicon); |
189 | 202 |
190 // Schedules a download for the specified entry. This adds the request to | 203 // Schedules a download for the specified entry. This adds the request to |
191 // download_requests_. | 204 // download_requests_. |
192 int ScheduleDownload(const GURL& url, | 205 int ScheduleDownload(const GURL& url, |
193 const GURL& image_url, | 206 const GURL& image_url, |
194 int image_size, | 207 int image_size, |
195 history::IconType icon_type, | 208 history::IconType icon_type, |
196 const FaviconTabHelper::ImageDownloadCallback& callback); | 209 const FaviconTabHelper::ImageDownloadCallback& callback); |
197 | 210 |
198 // Sets the image data for the favicon. This is invoked asynchronously after | 211 // Once all candidates are download, this picks one and calls SetFavicon(). |
199 // we request the TabContents to download the favicon. | 212 void SetFaviconFromCandidates(); |
| 213 |
| 214 // Sets the image data for the favicon. |
200 void SetFavicon(const GURL& url, | 215 void SetFavicon(const GURL& url, |
201 const GURL& icon_url, | 216 const GURL& icon_url, |
202 const gfx::Image& image, | 217 const gfx::Image& image, |
203 history::IconType icon_type); | 218 history::IconType icon_type); |
204 | 219 |
205 // Converts the FAVICON's image data to an SkBitmap and sets it on the | 220 // Converts the FAVICON's image data to an SkBitmap and sets it on the |
206 // NavigationEntry. | 221 // NavigationEntry. |
207 // If the TabContents has a delegate, it is notified of the new favicon | 222 // If the TabContents has a delegate, it is notified of the new favicon |
208 // (INVALIDATE_FAVICON). | 223 // (INVALIDATE_FAVICON). |
209 void UpdateFavicon(content::NavigationEntry* entry, | 224 void UpdateFavicon(content::NavigationEntry* entry, |
210 scoped_refptr<RefCountedMemory> data); | 225 scoped_refptr<RefCountedMemory> data); |
211 void UpdateFavicon(content::NavigationEntry* entry, const gfx::Image* image); | 226 void UpdateFavicon(content::NavigationEntry* entry, const gfx::Image* image); |
212 | 227 |
213 // If the image is not already at its preferred size, scales the image such | 228 // If the image is not already at its preferred size, scales the image such |
214 // that either the width and/or height is 16 pixels wide. Does nothing if the | 229 // that either the width and/or height == gfx::kFaviconSize. Does nothing if |
215 // image is empty. | 230 // the image is empty. |
216 gfx::Image ResizeFaviconIfNeeded(const gfx::Image& image); | 231 gfx::Image ResizeFaviconIfNeeded(const gfx::Image& image); |
217 | 232 |
218 void FetchFaviconInternal(); | 233 void FetchFaviconInternal(); |
219 | 234 |
220 // Return the current candidate if any. | 235 // Return the current candidate if any. |
221 FaviconURL* current_candidate() { | 236 FaviconURL* current_candidate() { |
222 return (urls_.size() > current_url_index_) ? | 237 return (urls_.size() > current_url_index_) ? |
223 &urls_[current_url_index_] : NULL; | 238 &urls_[current_url_index_] : NULL; |
224 } | 239 } |
225 | 240 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 275 |
261 // The FaviconData from history. | 276 // The FaviconData from history. |
262 history::FaviconData history_icon_; | 277 history::FaviconData history_icon_; |
263 | 278 |
264 // The Profile associated with this handler. | 279 // The Profile associated with this handler. |
265 Profile* profile_; | 280 Profile* profile_; |
266 | 281 |
267 // This handler's delegate. | 282 // This handler's delegate. |
268 FaviconHandlerDelegate* delegate_; // weak | 283 FaviconHandlerDelegate* delegate_; // weak |
269 | 284 |
| 285 // Vector of favicon candidates. |
| 286 FaviconCandidates favicon_candidates_; |
| 287 |
270 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); | 288 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); |
271 }; | 289 }; |
272 | 290 |
273 #endif // CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ | 291 #endif // CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ |
OLD | NEW |