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 #include "chrome/browser/favicon/favicon_tab_helper.h" | 5 #include "chrome/browser/favicon/favicon_tab_helper.h" |
6 | 6 |
7 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 7 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/favicon/favicon_handler.h" | 9 #include "chrome/browser/favicon/favicon_handler.h" |
10 #include "chrome/browser/favicon/favicon_service_factory.h" | 10 #include "chrome/browser/favicon/favicon_service_factory.h" |
11 #include "chrome/browser/favicon/favicon_util.h" | 11 #include "chrome/browser/favicon/favicon_util.h" |
12 #include "chrome/browser/history/history_service.h" | 12 #include "chrome/browser/history/history_service.h" |
13 #include "chrome/browser/history/history_service_factory.h" | 13 #include "chrome/browser/history/history_service_factory.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/search/search.h" | 15 #include "chrome/browser/search/search.h" |
16 #include "chrome/common/chrome_constants.h" | 16 #include "chrome/common/chrome_constants.h" |
17 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
18 #include "components/bookmarks/core/browser/bookmark_model.h" | 18 #include "components/bookmarks/core/browser/bookmark_model.h" |
19 #include "components/favicon_base/favicon_types.h" | |
19 #include "content/public/browser/favicon_status.h" | 20 #include "content/public/browser/favicon_status.h" |
20 #include "content/public/browser/invalidate_type.h" | 21 #include "content/public/browser/invalidate_type.h" |
21 #include "content/public/browser/navigation_controller.h" | 22 #include "content/public/browser/navigation_controller.h" |
22 #include "content/public/browser/navigation_details.h" | 23 #include "content/public/browser/navigation_details.h" |
23 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
24 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
27 #include "content/public/browser/web_contents_delegate.h" | 28 #include "content/public/browser/web_contents_delegate.h" |
29 #include "content/public/common/favicon_url.h" | |
28 #include "ui/gfx/codec/png_codec.h" | 30 #include "ui/gfx/codec/png_codec.h" |
29 #include "ui/gfx/image/image.h" | 31 #include "ui/gfx/image/image.h" |
30 #include "ui/gfx/image/image_skia.h" | 32 #include "ui/gfx/image/image_skia.h" |
31 #include "ui/gfx/image/image_skia_rep.h" | 33 #include "ui/gfx/image/image_skia_rep.h" |
32 | 34 |
33 using content::FaviconStatus; | 35 using content::FaviconStatus; |
34 using content::NavigationController; | 36 using content::NavigationController; |
35 using content::NavigationEntry; | 37 using content::NavigationEntry; |
36 using content::WebContents; | 38 using content::WebContents; |
37 | 39 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 } | 217 } |
216 | 218 |
217 void FaviconTabHelper::DidNavigateMainFrame( | 219 void FaviconTabHelper::DidNavigateMainFrame( |
218 const content::LoadCommittedDetails& details, | 220 const content::LoadCommittedDetails& details, |
219 const content::FrameNavigateParams& params) { | 221 const content::FrameNavigateParams& params) { |
220 favicon_urls_.clear(); | 222 favicon_urls_.clear(); |
221 // Get the favicon, either from history or request it from the net. | 223 // Get the favicon, either from history or request it from the net. |
222 FetchFavicon(details.entry->GetURL()); | 224 FetchFavicon(details.entry->GetURL()); |
223 } | 225 } |
224 | 226 |
227 // Returns favicon_base::IconType the given icon_type corresponds to. | |
228 favicon_base::IconType ToChromeIconType( | |
blundell
2014/05/16 07:33:30
This conversion function seems like it would make
jif
2014/05/16 17:32:30
I agree.
Added TODO.
| |
229 content::FaviconURL::IconType icon_type) { | |
230 switch (icon_type) { | |
231 case content::FaviconURL::FAVICON: | |
232 return favicon_base::FAVICON; | |
233 case content::FaviconURL::TOUCH_ICON: | |
234 return favicon_base::TOUCH_ICON; | |
235 case content::FaviconURL::TOUCH_PRECOMPOSED_ICON: | |
236 return favicon_base::TOUCH_PRECOMPOSED_ICON; | |
237 case content::FaviconURL::INVALID_ICON: | |
238 return favicon_base::INVALID_ICON; | |
239 } | |
240 NOTREACHED(); | |
241 return favicon_base::INVALID_ICON; | |
242 } | |
243 | |
225 void FaviconTabHelper::DidUpdateFaviconURL( | 244 void FaviconTabHelper::DidUpdateFaviconURL( |
226 const std::vector<content::FaviconURL>& candidates) { | 245 const std::vector<content::FaviconURL>& candidates) { |
227 DCHECK(!candidates.empty()); | 246 DCHECK(!candidates.empty()); |
228 favicon_urls_ = candidates; | 247 favicon_urls_ = candidates; |
229 | 248 std::vector<favicon::FaviconURL> favicon_urls; |
230 favicon_handler_->OnUpdateFaviconURL(candidates); | 249 for (size_t i = 0; i < candidates.size(); i++) { |
250 const content::FaviconURL& candidate = candidates[i]; | |
251 favicon_urls.push_back( | |
252 favicon::FaviconURL(candidate.icon_url, | |
253 ToChromeIconType(candidate.icon_type), | |
254 candidate.icon_sizes)); | |
255 } | |
256 favicon_handler_->OnUpdateFaviconURL(favicon_urls); | |
231 if (touch_icon_handler_.get()) | 257 if (touch_icon_handler_.get()) |
232 touch_icon_handler_->OnUpdateFaviconURL(candidates); | 258 touch_icon_handler_->OnUpdateFaviconURL(favicon_urls); |
233 } | 259 } |
234 | 260 |
235 FaviconService* FaviconTabHelper::GetFaviconService() { | 261 FaviconService* FaviconTabHelper::GetFaviconService() { |
236 return FaviconServiceFactory::GetForProfile(profile_, | 262 return FaviconServiceFactory::GetForProfile(profile_, |
237 Profile::EXPLICIT_ACCESS); | 263 Profile::EXPLICIT_ACCESS); |
238 } | 264 } |
239 | 265 |
240 bool FaviconTabHelper::IsBookmarked(const GURL& url) { | 266 bool FaviconTabHelper::IsBookmarked(const GURL& url) { |
241 BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile_); | 267 BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile_); |
242 return bookmark_model && bookmark_model->IsBookmarked(url); | 268 return bookmark_model && bookmark_model->IsBookmarked(url); |
(...skipping 14 matching lines...) Expand all Loading... | |
257 favicon_service->UnableToDownloadFavicon(image_url); | 283 favicon_service->UnableToDownloadFavicon(image_url); |
258 } | 284 } |
259 | 285 |
260 favicon_handler_->OnDidDownloadFavicon( | 286 favicon_handler_->OnDidDownloadFavicon( |
261 id, image_url, bitmaps, original_bitmap_sizes); | 287 id, image_url, bitmaps, original_bitmap_sizes); |
262 if (touch_icon_handler_.get()) { | 288 if (touch_icon_handler_.get()) { |
263 touch_icon_handler_->OnDidDownloadFavicon( | 289 touch_icon_handler_->OnDidDownloadFavicon( |
264 id, image_url, bitmaps, original_bitmap_sizes); | 290 id, image_url, bitmaps, original_bitmap_sizes); |
265 } | 291 } |
266 } | 292 } |
OLD | NEW |