| 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_util.h" | 5 #include "chrome/browser/favicon/favicon_util.h" |
| 6 | 6 |
| 7 #include "chrome/browser/favicon/select_favicon_frames.h" |
| 8 #include "chrome/browser/history/history_types.h" |
| 7 #include "chrome/common/icon_messages.h" | 9 #include "chrome/common/icon_messages.h" |
| 8 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| 9 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
| 12 #include "ui/gfx/codec/png_codec.h" |
| 13 #include "ui/gfx/image/image_skia.h" |
| 10 | 14 |
| 11 // static | 15 // static |
| 12 int FaviconUtil::DownloadFavicon(content::RenderViewHost* rvh, | 16 int FaviconUtil::DownloadFavicon(content::RenderViewHost* rvh, |
| 13 const GURL& url, | 17 const GURL& url, |
| 14 int image_size) { | 18 int image_size) { |
| 15 static int id = 0; | 19 static int id = 0; |
| 16 rvh->Send(new IconMsg_DownloadFavicon(rvh->GetRoutingID(), ++id, url, | 20 rvh->Send(new IconMsg_DownloadFavicon(rvh->GetRoutingID(), ++id, url, |
| 17 image_size)); | 21 image_size)); |
| 18 return id; | 22 return id; |
| 19 } | 23 } |
| 24 // static |
| 25 gfx::Image FaviconUtil::SelectFaviconFramesFromPNGs( |
| 26 const std::vector<history::FaviconBitmapResult>& png_data, |
| 27 const std::vector<ui::ScaleFactor> scale_factors, |
| 28 int favicon_size) { |
| 29 std::vector<SkBitmap> bitmaps; |
| 30 for (size_t i = 0; i < png_data.size(); ++i) { |
| 31 if (!png_data[i].is_valid()) |
| 32 continue; |
| 33 |
| 34 SkBitmap bitmap; |
| 35 if (gfx::PNGCodec::Decode(png_data[i].bitmap_data->front(), |
| 36 png_data[i].bitmap_data->size(), |
| 37 &bitmap)) { |
| 38 bitmaps.push_back(bitmap); |
| 39 } |
| 40 } |
| 41 |
| 42 if (bitmaps.empty()) |
| 43 return gfx::Image(); |
| 44 |
| 45 gfx::ImageSkia resized_image_skia = SelectFaviconFrames(bitmaps, |
| 46 ui::GetSupportedScaleFactors(), favicon_size, NULL); |
| 47 return gfx::Image(resized_image_skia); |
| 48 } |
| OLD | NEW |