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 "third_party/skia/include/core/SkBitmap.h" |
20 #include "ui/gfx/favicon_size.h" | 21 #include "ui/gfx/favicon_size.h" |
| 22 #include "ui/gfx/image/image.h" |
21 | 23 |
22 class FaviconHandlerDelegate; | 24 class FaviconHandlerDelegate; |
23 class Profile; | 25 class Profile; |
24 class RefCountedMemory; | 26 class RefCountedMemory; |
25 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 const SkBitmap& bitmap, |
| 180 history::IconType icon_type); |
| 181 |
| 182 GURL url; |
| 183 GURL image_url; |
| 184 gfx::Image image; |
| 185 SkBitmap bitmap; |
| 186 history::IconType icon_type; |
| 187 }; |
| 188 |
175 // See description above class for details. | 189 // See description above class for details. |
176 void OnFaviconDataForInitialURL(FaviconService::Handle handle, | 190 void OnFaviconDataForInitialURL(FaviconService::Handle handle, |
177 history::FaviconData favicon); | 191 history::FaviconData favicon); |
178 | 192 |
179 // If the favicon has expired, asks the renderer to download the favicon. | 193 // 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 | 194 // Otherwise asks history to update the mapping between page url and icon |
181 // url with a callback to OnFaviconData when done. | 195 // url with a callback to OnFaviconData when done. |
182 void DownloadFaviconOrAskHistory(const GURL& page_url, | 196 void DownloadFaviconOrAskHistory(const GURL& page_url, |
183 const GURL& icon_url, | 197 const GURL& icon_url, |
184 history::IconType icon_type); | 198 history::IconType icon_type); |
185 | 199 |
186 // See description above class for details. | 200 // See description above class for details. |
187 void OnFaviconData(FaviconService::Handle handle, | 201 void OnFaviconData(FaviconService::Handle handle, |
188 history::FaviconData favicon); | 202 history::FaviconData favicon); |
189 | 203 |
190 // Schedules a download for the specified entry. This adds the request to | 204 // Schedules a download for the specified entry. This adds the request to |
191 // download_requests_. | 205 // download_requests_. |
192 int ScheduleDownload(const GURL& url, | 206 int ScheduleDownload(const GURL& url, |
193 const GURL& image_url, | 207 const GURL& image_url, |
194 int image_size, | 208 int image_size, |
195 history::IconType icon_type, | 209 history::IconType icon_type, |
196 const FaviconTabHelper::ImageDownloadCallback& callback); | 210 const FaviconTabHelper::ImageDownloadCallback& callback); |
197 | 211 |
198 // Sets the image data for the favicon. This is invoked asynchronously after | 212 // Updates |favicon_candidate_| and returns true if it is an exact match. |
199 // we request the TabContents to download the favicon. | 213 bool UpdateFaviconCandidate(const GURL& url, |
| 214 const GURL& image_url, |
| 215 const gfx::Image& image, |
| 216 history::IconType icon_type); |
| 217 |
| 218 // Sets the image data for the favicon. |
200 void SetFavicon(const GURL& url, | 219 void SetFavicon(const GURL& url, |
201 const GURL& icon_url, | 220 const GURL& icon_url, |
202 const gfx::Image& image, | 221 const gfx::Image& image, |
| 222 const SkBitmap& bitmap, |
203 history::IconType icon_type); | 223 history::IconType icon_type); |
204 | 224 |
205 // Converts the FAVICON's image data to an SkBitmap and sets it on the | 225 // Converts the FAVICON's image data to an SkBitmap and sets it on the |
206 // NavigationEntry. | 226 // NavigationEntry. |
207 // If the TabContents has a delegate, it is notified of the new favicon | 227 // If the TabContents has a delegate, it is notified of the new favicon |
208 // (INVALIDATE_FAVICON). | 228 // (INVALIDATE_FAVICON). |
209 void UpdateFavicon(content::NavigationEntry* entry, | 229 void UpdateFavicon(content::NavigationEntry* entry, |
210 scoped_refptr<RefCountedMemory> data); | 230 scoped_refptr<RefCountedMemory> data); |
211 void UpdateFavicon(content::NavigationEntry* entry, const gfx::Image* image); | 231 void UpdateFavicon(content::NavigationEntry* entry, const gfx::Image* image); |
212 | 232 |
213 // If the image is not already at its preferred size, scales the image such | 233 // 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 | 234 // that either the width and/or height == gfx::kFaviconSize. Does nothing if |
215 // image is empty. | 235 // the image is empty. |
216 gfx::Image ResizeFaviconIfNeeded(const gfx::Image& image); | 236 gfx::Image ResizeFaviconIfNeeded(const gfx::Image& image); |
217 | 237 |
218 void FetchFaviconInternal(); | 238 void FetchFaviconInternal(); |
219 | 239 |
220 // Return the current candidate if any. | 240 // Return the current candidate if any. |
221 FaviconURL* current_candidate() { | 241 FaviconURL* current_candidate() { |
222 return (urls_.size() > current_url_index_) ? | 242 return (urls_.size() > current_url_index_) ? |
223 &urls_[current_url_index_] : NULL; | 243 &urls_[current_url_index_] : NULL; |
224 } | 244 } |
225 | 245 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 280 |
261 // The FaviconData from history. | 281 // The FaviconData from history. |
262 history::FaviconData history_icon_; | 282 history::FaviconData history_icon_; |
263 | 283 |
264 // The Profile associated with this handler. | 284 // The Profile associated with this handler. |
265 Profile* profile_; | 285 Profile* profile_; |
266 | 286 |
267 // This handler's delegate. | 287 // This handler's delegate. |
268 FaviconHandlerDelegate* delegate_; // weak | 288 FaviconHandlerDelegate* delegate_; // weak |
269 | 289 |
| 290 // Current favicon candidate. |
| 291 FaviconCandidate favicon_candidate_; |
| 292 |
270 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); | 293 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); |
271 }; | 294 }; |
272 | 295 |
273 #endif // CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ | 296 #endif // CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ |
OLD | NEW |