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/favicon/select_favicon_frames.h" |
9 #include "chrome/browser/history/history.h" | 10 #include "chrome/browser/history/history.h" |
10 #include "chrome/browser/history/history_service_factory.h" | 11 #include "chrome/browser/history/history_service_factory.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
13 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
14 #include "chrome/common/icon_messages.h" | 15 #include "chrome/common/icon_messages.h" |
15 #include "content/public/browser/favicon_status.h" | 16 #include "content/public/browser/favicon_status.h" |
16 #include "content/public/browser/invalidate_type.h" | 17 #include "content/public/browser/invalidate_type.h" |
17 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
18 #include "content/public/browser/navigation_details.h" | 19 #include "content/public/browser/navigation_details.h" |
19 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
20 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
21 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
22 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
23 #include "content/public/browser/web_contents_delegate.h" | 24 #include "content/public/browser/web_contents_delegate.h" |
24 #include "content/public/browser/web_ui.h" | 25 #include "content/public/browser/web_ui.h" |
25 #include "ui/gfx/codec/png_codec.h" | 26 #include "ui/gfx/codec/png_codec.h" |
26 #include "ui/gfx/image/image.h" | 27 #include "ui/gfx/image/image.h" |
| 28 #include "ui/gfx/image/image_skia.h" |
| 29 #include "ui/gfx/image/image_skia_rep.h" |
27 | 30 |
28 using content::FaviconStatus; | 31 using content::FaviconStatus; |
29 using content::NavigationController; | 32 using content::NavigationController; |
30 using content::NavigationEntry; | 33 using content::NavigationEntry; |
31 using content::WebContents; | 34 using content::WebContents; |
32 | 35 |
33 FaviconTabHelper::FaviconTabHelper(WebContents* web_contents) | 36 FaviconTabHelper::FaviconTabHelper(WebContents* web_contents) |
34 : content::WebContentsObserver(web_contents), | 37 : content::WebContentsObserver(web_contents), |
35 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { | 38 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { |
36 favicon_handler_.reset(new FaviconHandler(profile_, this, | 39 favicon_handler_.reset(new FaviconHandler(profile_, this, |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 bool FaviconTabHelper::OnMessageReceived(const IPC::Message& message) { | 182 bool FaviconTabHelper::OnMessageReceived(const IPC::Message& message) { |
180 bool message_handled = false; // Allow other handlers to receive these. | 183 bool message_handled = false; // Allow other handlers to receive these. |
181 IPC_BEGIN_MESSAGE_MAP(FaviconTabHelper, message) | 184 IPC_BEGIN_MESSAGE_MAP(FaviconTabHelper, message) |
182 IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon) | 185 IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon) |
183 IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) | 186 IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) |
184 IPC_MESSAGE_UNHANDLED(message_handled = false) | 187 IPC_MESSAGE_UNHANDLED(message_handled = false) |
185 IPC_END_MESSAGE_MAP() | 188 IPC_END_MESSAGE_MAP() |
186 return message_handled; | 189 return message_handled; |
187 } | 190 } |
188 | 191 |
189 void FaviconTabHelper::OnDidDownloadFavicon(int id, | 192 void FaviconTabHelper::OnDidDownloadFavicon( |
190 const GURL& image_url, | 193 int id, |
191 bool errored, | 194 const GURL& image_url, |
192 const SkBitmap& image) { | 195 bool errored, |
193 gfx::Image favicon(image); | 196 int requested_size, |
| 197 const std::vector<SkBitmap>& bitmaps) { |
| 198 // TODO: Possibly do bitmap selection in FaviconHandler, so that it can score |
| 199 // favicons better. |
| 200 std::vector<ui::ScaleFactor> scale_factors; |
| 201 #if defined(OS_MACOSX) |
| 202 scale_factors = ui::GetSupportedScaleFactors(); |
| 203 #else |
| 204 scale_factors.push_back(ui::SCALE_FACTOR_100P); // TODO: Aura? |
| 205 #endif |
| 206 gfx::Image favicon( |
| 207 SelectFaviconFrames(bitmaps, scale_factors, requested_size)); |
194 favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); | 208 favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); |
195 if (touch_icon_handler_.get()) | 209 if (touch_icon_handler_.get()) |
196 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); | 210 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); |
197 } | 211 } |
OLD | NEW |