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/favicon/favicon_handler.h" | 7 #include "chrome/browser/favicon/favicon_handler.h" |
8 #include "chrome/browser/favicon/favicon_util.h" | 8 #include "chrome/browser/favicon/favicon_util.h" |
9 #include "chrome/browser/history/history.h" | 9 #include "chrome/browser/history/history.h" |
10 #include "chrome/browser/history/history_service_factory.h" | 10 #include "chrome/browser/history/history_service_factory.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 FaviconTabHelper::~FaviconTabHelper() { | 43 FaviconTabHelper::~FaviconTabHelper() { |
44 } | 44 } |
45 | 45 |
46 void FaviconTabHelper::FetchFavicon(const GURL& url) { | 46 void FaviconTabHelper::FetchFavicon(const GURL& url) { |
47 favicon_handler_->FetchFavicon(url); | 47 favicon_handler_->FetchFavicon(url); |
48 if (touch_icon_handler_.get()) | 48 if (touch_icon_handler_.get()) |
49 touch_icon_handler_->FetchFavicon(url); | 49 touch_icon_handler_->FetchFavicon(url); |
50 } | 50 } |
51 | 51 |
52 SkBitmap FaviconTabHelper::GetFavicon() const { | 52 gfx::Image FaviconTabHelper::GetFavicon() const { |
53 // Like GetTitle(), we also want to use the favicon for the last committed | 53 // Like GetTitle(), we also want to use the favicon for the last committed |
54 // entry rather than a pending navigation entry. | 54 // entry rather than a pending navigation entry. |
55 const NavigationController& controller = web_contents()->GetController(); | 55 const NavigationController& controller = web_contents()->GetController(); |
56 NavigationEntry* entry = controller.GetTransientEntry(); | 56 NavigationEntry* entry = controller.GetTransientEntry(); |
57 if (entry) | 57 if (entry) |
58 return entry->GetFavicon().AsBitmap(); | 58 return entry->GetFavicon().image; |
59 | 59 |
60 entry = controller.GetLastCommittedEntry(); | 60 entry = controller.GetLastCommittedEntry(); |
61 if (entry) | 61 if (entry) |
62 return entry->GetFavicon().AsBitmap(); | 62 return entry->GetFavicon().image; |
63 return SkBitmap(); | 63 return gfx::Image(); |
64 } | 64 } |
65 | 65 |
66 bool FaviconTabHelper::FaviconIsValid() const { | 66 bool FaviconTabHelper::FaviconIsValid() const { |
67 const NavigationController& controller = web_contents()->GetController(); | 67 const NavigationController& controller = web_contents()->GetController(); |
68 NavigationEntry* entry = controller.GetTransientEntry(); | 68 NavigationEntry* entry = controller.GetTransientEntry(); |
69 if (entry) | 69 if (entry) |
70 return entry->GetFavicon().valid; | 70 return entry->GetFavicon().valid; |
71 | 71 |
72 entry = controller.GetLastCommittedEntry(); | 72 entry = controller.GetLastCommittedEntry(); |
73 if (entry) | 73 if (entry) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 GetOriginalProfile()->GetFaviconService(Profile::IMPLICIT_ACCESS); | 105 GetOriginalProfile()->GetFaviconService(Profile::IMPLICIT_ACCESS); |
106 if (!service) | 106 if (!service) |
107 return; | 107 return; |
108 const FaviconStatus& favicon(entry->GetFavicon()); | 108 const FaviconStatus& favicon(entry->GetFavicon()); |
109 if (!favicon.valid || favicon.url.is_empty() || | 109 if (!favicon.valid || favicon.url.is_empty() || |
110 favicon.image.IsEmpty()) { | 110 favicon.image.IsEmpty()) { |
111 return; | 111 return; |
112 } | 112 } |
113 std::vector<unsigned char> image_data; | 113 std::vector<unsigned char> image_data; |
114 // TODO: Save all representations. | 114 // TODO: Save all representations. |
115 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.AsBitmap(), false, &image_data); | 115 gfx::PNGCodec::EncodeBGRASkBitmap( |
| 116 favicon.image.AsBitmap(), false, &image_data); |
116 service->SetFavicon( | 117 service->SetFavicon( |
117 entry->GetURL(), favicon.url, image_data, history::FAVICON); | 118 entry->GetURL(), favicon.url, image_data, history::FAVICON); |
118 } | 119 } |
119 | 120 |
120 int FaviconTabHelper::DownloadImage(const GURL& image_url, | 121 int FaviconTabHelper::DownloadImage(const GURL& image_url, |
121 int image_size, | 122 int image_size, |
122 history::IconType icon_type, | 123 history::IconType icon_type, |
123 const ImageDownloadCallback& callback) { | 124 const ImageDownloadCallback& callback) { |
124 if (icon_type == history::FAVICON) | 125 if (icon_type == history::FAVICON) |
125 return favicon_handler_->DownloadImage(image_url, image_size, icon_type, | 126 return favicon_handler_->DownloadImage(image_url, image_size, icon_type, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 188 |
188 void FaviconTabHelper::OnDidDownloadFavicon(int id, | 189 void FaviconTabHelper::OnDidDownloadFavicon(int id, |
189 const GURL& image_url, | 190 const GURL& image_url, |
190 bool errored, | 191 bool errored, |
191 const SkBitmap& image) { | 192 const SkBitmap& image) { |
192 gfx::Image favicon(image); | 193 gfx::Image favicon(image); |
193 favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); | 194 favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); |
194 if (touch_icon_handler_.get()) | 195 if (touch_icon_handler_.get()) |
195 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); | 196 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); |
196 } | 197 } |
OLD | NEW |