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" | |
8 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/favicon/chrome_favicon_client.h" |
9 #include "chrome/browser/favicon/favicon_handler.h" | 9 #include "chrome/browser/favicon/favicon_handler.h" |
10 #include "chrome/browser/favicon/favicon_service.h" | 10 #include "chrome/browser/favicon/favicon_service.h" |
11 #include "chrome/browser/favicon/favicon_service_factory.h" | 11 #include "chrome/browser/favicon/favicon_service_factory.h" |
12 #include "chrome/browser/favicon/favicon_util.h" | 12 #include "chrome/browser/favicon/favicon_util.h" |
13 #include "chrome/browser/history/history_service.h" | 13 #include "chrome/browser/history/history_service.h" |
14 #include "chrome/browser/history/history_service_factory.h" | 14 #include "chrome/browser/history/history_service_factory.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/search/search.h" | 16 #include "chrome/browser/search/search.h" |
17 #include "chrome/common/chrome_constants.h" | 17 #include "chrome/common/chrome_constants.h" |
18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
19 #include "components/bookmarks/browser/bookmark_model.h" | |
20 #include "components/favicon_base/favicon_types.h" | 19 #include "components/favicon_base/favicon_types.h" |
21 #include "content/public/browser/favicon_status.h" | 20 #include "content/public/browser/favicon_status.h" |
22 #include "content/public/browser/invalidate_type.h" | 21 #include "content/public/browser/invalidate_type.h" |
23 #include "content/public/browser/navigation_controller.h" | 22 #include "content/public/browser/navigation_controller.h" |
24 #include "content/public/browser/navigation_details.h" | 23 #include "content/public/browser/navigation_details.h" |
25 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
26 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
27 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
28 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
29 #include "content/public/browser/web_contents_delegate.h" | 28 #include "content/public/browser/web_contents_delegate.h" |
30 #include "content/public/common/favicon_url.h" | 29 #include "content/public/common/favicon_url.h" |
31 #include "ui/gfx/codec/png_codec.h" | 30 #include "ui/gfx/codec/png_codec.h" |
32 #include "ui/gfx/image/image.h" | 31 #include "ui/gfx/image/image.h" |
33 #include "ui/gfx/image/image_skia.h" | 32 #include "ui/gfx/image/image_skia.h" |
34 #include "ui/gfx/image/image_skia_rep.h" | 33 #include "ui/gfx/image/image_skia_rep.h" |
35 | 34 |
36 using content::FaviconStatus; | 35 using content::FaviconStatus; |
37 using content::NavigationController; | 36 using content::NavigationController; |
38 using content::NavigationEntry; | 37 using content::NavigationEntry; |
39 using content::WebContents; | 38 using content::WebContents; |
40 | 39 |
41 DEFINE_WEB_CONTENTS_USER_DATA_KEY(FaviconTabHelper); | 40 DEFINE_WEB_CONTENTS_USER_DATA_KEY(FaviconTabHelper); |
42 | 41 |
43 FaviconTabHelper::FaviconTabHelper(WebContents* web_contents) | 42 FaviconTabHelper::FaviconTabHelper(WebContents* web_contents) |
44 : content::WebContentsObserver(web_contents), | 43 : content::WebContentsObserver(web_contents), |
45 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { | 44 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { |
| 45 faviconClient_.reset(new ChromeFaviconClient(profile_)); |
46 #if defined(OS_ANDROID) | 46 #if defined(OS_ANDROID) |
47 bool download_largest_icon = true; | 47 bool download_largest_icon = true; |
48 #else | 48 #else |
49 bool download_largest_icon = false; | 49 bool download_largest_icon = false; |
50 #endif | 50 #endif |
51 favicon_handler_.reset( | 51 favicon_handler_.reset(new FaviconHandler(faviconClient_.get(), |
52 new FaviconHandler(this, this, FaviconHandler::FAVICON, | 52 this, |
53 download_largest_icon)); | 53 FaviconHandler::FAVICON, |
| 54 download_largest_icon)); |
54 if (chrome::kEnableTouchIcon) | 55 if (chrome::kEnableTouchIcon) |
55 touch_icon_handler_.reset( | 56 touch_icon_handler_.reset(new FaviconHandler(faviconClient_.get(), |
56 new FaviconHandler(this, this, FaviconHandler::TOUCH, | 57 this, |
57 download_largest_icon)); | 58 FaviconHandler::TOUCH, |
| 59 download_largest_icon)); |
58 } | 60 } |
59 | 61 |
60 FaviconTabHelper::~FaviconTabHelper() { | 62 FaviconTabHelper::~FaviconTabHelper() { |
61 } | 63 } |
62 | 64 |
63 void FaviconTabHelper::FetchFavicon(const GURL& url) { | 65 void FaviconTabHelper::FetchFavicon(const GURL& url) { |
64 favicon_handler_->FetchFavicon(url); | 66 favicon_handler_->FetchFavicon(url); |
65 if (touch_icon_handler_.get()) | 67 if (touch_icon_handler_.get()) |
66 touch_icon_handler_->FetchFavicon(url); | 68 touch_icon_handler_->FetchFavicon(url); |
67 } | 69 } |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 favicon_urls.push_back( | 256 favicon_urls.push_back( |
255 favicon::FaviconURL(candidate.icon_url, | 257 favicon::FaviconURL(candidate.icon_url, |
256 ToChromeIconType(candidate.icon_type), | 258 ToChromeIconType(candidate.icon_type), |
257 candidate.icon_sizes)); | 259 candidate.icon_sizes)); |
258 } | 260 } |
259 favicon_handler_->OnUpdateFaviconURL(favicon_urls); | 261 favicon_handler_->OnUpdateFaviconURL(favicon_urls); |
260 if (touch_icon_handler_.get()) | 262 if (touch_icon_handler_.get()) |
261 touch_icon_handler_->OnUpdateFaviconURL(favicon_urls); | 263 touch_icon_handler_->OnUpdateFaviconURL(favicon_urls); |
262 } | 264 } |
263 | 265 |
264 FaviconService* FaviconTabHelper::GetFaviconService() { | |
265 return FaviconServiceFactory::GetForProfile(profile_, | |
266 Profile::EXPLICIT_ACCESS); | |
267 } | |
268 | |
269 bool FaviconTabHelper::IsBookmarked(const GURL& url) { | |
270 BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile_); | |
271 return bookmark_model && bookmark_model->IsBookmarked(url); | |
272 } | |
273 | |
274 void FaviconTabHelper::DidDownloadFavicon( | 266 void FaviconTabHelper::DidDownloadFavicon( |
275 int id, | 267 int id, |
276 int http_status_code, | 268 int http_status_code, |
277 const GURL& image_url, | 269 const GURL& image_url, |
278 const std::vector<SkBitmap>& bitmaps, | 270 const std::vector<SkBitmap>& bitmaps, |
279 const std::vector<gfx::Size>& original_bitmap_sizes) { | 271 const std::vector<gfx::Size>& original_bitmap_sizes) { |
280 | 272 |
281 if (bitmaps.empty() && http_status_code == 404) { | 273 if (bitmaps.empty() && http_status_code == 404) { |
282 DVLOG(1) << "Failed to Download Favicon:" << image_url; | 274 DVLOG(1) << "Failed to Download Favicon:" << image_url; |
283 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 275 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
284 profile_->GetOriginalProfile(), Profile::IMPLICIT_ACCESS); | 276 profile_->GetOriginalProfile(), Profile::IMPLICIT_ACCESS); |
285 if (favicon_service) | 277 if (favicon_service) |
286 favicon_service->UnableToDownloadFavicon(image_url); | 278 favicon_service->UnableToDownloadFavicon(image_url); |
287 } | 279 } |
288 | 280 |
289 favicon_handler_->OnDidDownloadFavicon( | 281 favicon_handler_->OnDidDownloadFavicon( |
290 id, image_url, bitmaps, original_bitmap_sizes); | 282 id, image_url, bitmaps, original_bitmap_sizes); |
291 if (touch_icon_handler_.get()) { | 283 if (touch_icon_handler_.get()) { |
292 touch_icon_handler_->OnDidDownloadFavicon( | 284 touch_icon_handler_->OnDidDownloadFavicon( |
293 id, image_url, bitmaps, original_bitmap_sizes); | 285 id, image_url, bitmaps, original_bitmap_sizes); |
294 } | 286 } |
295 } | 287 } |
OLD | NEW |