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" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
13 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
14 #include "chrome/common/icon_messages.h" | 14 #include "chrome/common/icon_messages.h" |
15 #include "content/public/browser/favicon_status.h" | 15 #include "content/public/browser/favicon_status.h" |
16 #include "content/public/browser/invalidate_type.h" | 16 #include "content/public/browser/invalidate_type.h" |
17 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
18 #include "content/public/browser/navigation_details.h" | 18 #include "content/public/browser/navigation_details.h" |
19 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
20 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
21 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "content/public/browser/web_contents_delegate.h" | 23 #include "content/public/browser/web_contents_delegate.h" |
24 #include "content/public/browser/web_ui.h" | 24 #include "content/public/browser/web_ui.h" |
25 #include "ui/gfx/codec/png_codec.h" | 25 #include "ui/gfx/codec/png_codec.h" |
26 #include "ui/gfx/image/image.h" | 26 #include "ui/gfx/image/image.h" |
27 #include "ui/gfx/image/image_skia.h" | |
28 #include "ui/gfx/image/image_skia_rep.h" | |
27 | 29 |
28 using content::FaviconStatus; | 30 using content::FaviconStatus; |
29 using content::NavigationController; | 31 using content::NavigationController; |
30 using content::NavigationEntry; | 32 using content::NavigationEntry; |
31 using content::WebContents; | 33 using content::WebContents; |
32 | 34 |
33 FaviconTabHelper::FaviconTabHelper(WebContents* web_contents) | 35 FaviconTabHelper::FaviconTabHelper(WebContents* web_contents) |
34 : content::WebContentsObserver(web_contents), | 36 : content::WebContentsObserver(web_contents), |
35 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { | 37 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { |
36 favicon_handler_.reset(new FaviconHandler(profile_, this, | 38 favicon_handler_.reset(new FaviconHandler(profile_, this, |
37 FaviconHandler::FAVICON)); | 39 FaviconHandler::FAVICON)); |
38 if (chrome::kEnableTouchIcon) | 40 if (chrome::kEnableTouchIcon) |
39 touch_icon_handler_.reset(new FaviconHandler(profile_, this, | 41 touch_icon_handler_.reset(new FaviconHandler(profile_, this, |
40 FaviconHandler::TOUCH)); | 42 FaviconHandler::TOUCH)); |
41 } | 43 } |
42 | 44 |
43 FaviconTabHelper::~FaviconTabHelper() { | 45 FaviconTabHelper::~FaviconTabHelper() { |
44 } | 46 } |
45 | 47 |
46 void FaviconTabHelper::FetchFavicon(const GURL& url) { | 48 void FaviconTabHelper::FetchFavicon(const GURL& url) { |
47 favicon_handler_->FetchFavicon(url); | 49 favicon_handler_->FetchFavicon(url); |
48 if (touch_icon_handler_.get()) | 50 if (touch_icon_handler_.get()) |
49 touch_icon_handler_->FetchFavicon(url); | 51 touch_icon_handler_->FetchFavicon(url); |
50 } | 52 } |
51 | 53 |
52 SkBitmap FaviconTabHelper::GetFavicon() const { | 54 SkBitmap FaviconTabHelper::GetFavicon() const { |
55 // XXX delete | |
53 // Like GetTitle(), we also want to use the favicon for the last committed | 56 // Like GetTitle(), we also want to use the favicon for the last committed |
54 // entry rather than a pending navigation entry. | 57 // entry rather than a pending navigation entry. |
55 const NavigationController& controller = web_contents()->GetController(); | 58 const NavigationController& controller = web_contents()->GetController(); |
56 NavigationEntry* entry = controller.GetTransientEntry(); | 59 NavigationEntry* entry = controller.GetTransientEntry(); |
57 if (entry) | 60 if (entry) |
58 return entry->GetFavicon().bitmap; | 61 return entry->GetFavicon().bitmap; |
59 | 62 |
60 entry = controller.GetLastCommittedEntry(); | 63 entry = controller.GetLastCommittedEntry(); |
61 if (entry) | 64 if (entry) |
62 return entry->GetFavicon().bitmap; | 65 return entry->GetFavicon().bitmap; |
63 return SkBitmap(); | 66 return SkBitmap(); |
64 } | 67 } |
65 | 68 |
69 gfx::Image FaviconTabHelper::GetFaviconImage() const { | |
70 // Like GetTitle(), we also want to use the favicon for the last committed | |
71 // entry rather than a pending navigation entry. | |
72 const NavigationController& controller = web_contents()->GetController(); | |
73 NavigationEntry* entry = controller.GetTransientEntry(); | |
74 if (entry) | |
75 return entry->GetFavicon().image; | |
76 | |
77 entry = controller.GetLastCommittedEntry(); | |
78 if (entry) | |
79 return entry->GetFavicon().image; | |
80 return gfx::Image(); | |
81 } | |
82 | |
66 bool FaviconTabHelper::FaviconIsValid() const { | 83 bool FaviconTabHelper::FaviconIsValid() const { |
67 const NavigationController& controller = web_contents()->GetController(); | 84 const NavigationController& controller = web_contents()->GetController(); |
68 NavigationEntry* entry = controller.GetTransientEntry(); | 85 NavigationEntry* entry = controller.GetTransientEntry(); |
69 if (entry) | 86 if (entry) |
70 return entry->GetFavicon().valid; | 87 return entry->GetFavicon().valid; |
71 | 88 |
72 entry = controller.GetLastCommittedEntry(); | 89 entry = controller.GetLastCommittedEntry(); |
73 if (entry) | 90 if (entry) |
74 return entry->GetFavicon().valid; | 91 return entry->GetFavicon().valid; |
75 | 92 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 const std::vector<FaviconURL>& candidates) { | 151 const std::vector<FaviconURL>& candidates) { |
135 favicon_handler_->OnUpdateFaviconURL(page_id, candidates); | 152 favicon_handler_->OnUpdateFaviconURL(page_id, candidates); |
136 if (touch_icon_handler_.get()) | 153 if (touch_icon_handler_.get()) |
137 touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates); | 154 touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates); |
138 } | 155 } |
139 | 156 |
140 NavigationEntry* FaviconTabHelper::GetActiveEntry() { | 157 NavigationEntry* FaviconTabHelper::GetActiveEntry() { |
141 return web_contents()->GetController().GetActiveEntry(); | 158 return web_contents()->GetController().GetActiveEntry(); |
142 } | 159 } |
143 | 160 |
144 int FaviconTabHelper::StartDownload(const GURL& url, int image_size) { | 161 int FaviconTabHelper::StartDownload(const GURL& url, const std::vector<int>& ima ge_sizes) { |
145 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | 162 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); |
146 int id = FaviconUtil::DownloadFavicon(host, url, image_size); | 163 int id = FaviconUtil::DownloadFavicon(host, url, image_sizes); |
147 return id; | 164 return id; |
148 } | 165 } |
149 | 166 |
150 void FaviconTabHelper::NotifyFaviconUpdated() { | 167 void FaviconTabHelper::NotifyFaviconUpdated() { |
151 content::NotificationService::current()->Notify( | 168 content::NotificationService::current()->Notify( |
152 chrome::NOTIFICATION_FAVICON_UPDATED, | 169 chrome::NOTIFICATION_FAVICON_UPDATED, |
153 content::Source<WebContents>(web_contents()), | 170 content::Source<WebContents>(web_contents()), |
154 content::NotificationService::NoDetails()); | 171 content::NotificationService::NoDetails()); |
155 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); | 172 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
156 } | 173 } |
(...skipping 23 matching lines...) Expand all Loading... | |
180 IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon) | 197 IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon) |
181 IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) | 198 IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) |
182 IPC_MESSAGE_UNHANDLED(message_handled = false) | 199 IPC_MESSAGE_UNHANDLED(message_handled = false) |
183 IPC_END_MESSAGE_MAP() | 200 IPC_END_MESSAGE_MAP() |
184 return message_handled; | 201 return message_handled; |
185 } | 202 } |
186 | 203 |
187 void FaviconTabHelper::OnDidDownloadFavicon(int id, | 204 void FaviconTabHelper::OnDidDownloadFavicon(int id, |
188 const GURL& image_url, | 205 const GURL& image_url, |
189 bool errored, | 206 bool errored, |
190 const SkBitmap& image) { | 207 const std::vector<SkBitmap>& image) { |
pkotwicz
2012/08/02 23:47:08
Please name this parameter bitmaps
| |
191 gfx::Image favicon(image); | 208 // XXX use cole's desired scaling algorithm |
209 gfx::ImageSkia multi_image; | |
210 for (size_t i = 0; i < image.size(); ++i) { | |
211 if (!image[i].isNull()) { | |
212 multi_image.AddRepresentation( | |
213 gfx::ImageSkiaRep(image[i], | |
214 ui::GetScaleFactorFromScale( | |
215 image[i].width() / 16.0))); // XXX | |
pkotwicz
2012/08/02 23:47:08
16 -> gfx::kFaviconSize.
Probably going to be some
| |
216 } | |
217 } | |
218 | |
219 gfx::Image favicon(multi_image); | |
220 | |
192 favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); | 221 favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); |
193 if (touch_icon_handler_.get()) | 222 if (touch_icon_handler_.get()) |
194 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); | 223 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); |
195 } | 224 } |
OLD | NEW |