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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 SkBitmap 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().bitmap; | 58 return entry->GetFavicon().AsBitmap(); |
59 | 59 |
60 entry = controller.GetLastCommittedEntry(); | 60 entry = controller.GetLastCommittedEntry(); |
61 if (entry) | 61 if (entry) |
62 return entry->GetFavicon().bitmap; | 62 return entry->GetFavicon().AsBitmap(); |
63 return SkBitmap(); | 63 return SkBitmap(); |
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(); |
(...skipping 27 matching lines...) Expand all Loading... |
100 if (!history) | 100 if (!history) |
101 return; | 101 return; |
102 history->AddPageNoVisitForBookmark(entry->GetURL(), entry->GetTitle()); | 102 history->AddPageNoVisitForBookmark(entry->GetURL(), entry->GetTitle()); |
103 | 103 |
104 FaviconService* service = profile_-> | 104 FaviconService* service = profile_-> |
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.bitmap.empty()) { | 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 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap, false, &image_data); | 114 // TODO: Save all representations. |
| 115 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.AsBitmap(), false, &image_data); |
115 service->SetFavicon( | 116 service->SetFavicon( |
116 entry->GetURL(), favicon.url, image_data, history::FAVICON); | 117 entry->GetURL(), favicon.url, image_data, history::FAVICON); |
117 } | 118 } |
118 | 119 |
119 int FaviconTabHelper::DownloadImage(const GURL& image_url, | 120 int FaviconTabHelper::DownloadImage(const GURL& image_url, |
120 int image_size, | 121 int image_size, |
121 history::IconType icon_type, | 122 history::IconType icon_type, |
122 const ImageDownloadCallback& callback) { | 123 const ImageDownloadCallback& callback) { |
123 if (icon_type == history::FAVICON) | 124 if (icon_type == history::FAVICON) |
124 return favicon_handler_->DownloadImage(image_url, image_size, icon_type, | 125 return favicon_handler_->DownloadImage(image_url, image_size, icon_type, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 187 |
187 void FaviconTabHelper::OnDidDownloadFavicon(int id, | 188 void FaviconTabHelper::OnDidDownloadFavicon(int id, |
188 const GURL& image_url, | 189 const GURL& image_url, |
189 bool errored, | 190 bool errored, |
190 const SkBitmap& image) { | 191 const SkBitmap& image) { |
191 gfx::Image favicon(image); | 192 gfx::Image favicon(image); |
192 favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); | 193 favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); |
193 if (touch_icon_handler_.get()) | 194 if (touch_icon_handler_.get()) |
194 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); | 195 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); |
195 } | 196 } |
OLD | NEW |