Chromium Code Reviews| 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/history/history_types.h" | 7 #include "chrome/browser/history/history_types.h" |
| 8 #include "chrome/browser/history/select_favicon_frames.h" | 8 #include "chrome/browser/history/select_favicon_frames.h" |
| 9 #include "chrome/common/icon_messages.h" | 9 #include "chrome/common/icon_messages.h" |
| 10 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| 11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
| 12 #include "ui/gfx/codec/png_codec.h" | 12 #include "ui/gfx/codec/png_codec.h" |
| 13 #include "ui/gfx/image/image_skia.h" | 13 #include "ui/gfx/image/image_skia.h" |
| 14 | 14 |
| 15 // static | 15 // static |
| 16 std::vector<ui::ScaleFactor> FaviconUtil::GetFaviconScaleFactors() { | |
| 17 static std::vector<ui::ScaleFactor>* favicon_scale_factors = | |
|
sky
2012/11/15 18:14:54
Is it really worth caching this? If we do, it mean
| |
| 18 new std::vector<ui::ScaleFactor>(); | |
| 19 if (favicon_scale_factors->empty()) { | |
| 20 favicon_scale_factors->push_back(ui::SCALE_FACTOR_100P); | |
| 21 | |
| 22 std::vector<ui::ScaleFactor> supported_scale_factors = | |
| 23 ui::GetSupportedScaleFactors(); | |
| 24 for (size_t i = 0; i < supported_scale_factors.size(); ++i) { | |
| 25 ui::ScaleFactor scale_factor = supported_scale_factors[i]; | |
| 26 if (scale_factor != ui::SCALE_FACTOR_100P) | |
| 27 favicon_scale_factors->push_back(scale_factor); | |
| 28 } | |
| 29 } | |
| 30 return *favicon_scale_factors; | |
| 31 } | |
| 32 | |
| 33 // static | |
| 16 int FaviconUtil::DownloadFavicon(content::RenderViewHost* rvh, | 34 int FaviconUtil::DownloadFavicon(content::RenderViewHost* rvh, |
| 17 const GURL& url, | 35 const GURL& url, |
| 18 int image_size) { | 36 int image_size) { |
| 19 static int id = 0; | 37 static int id = 0; |
| 20 rvh->Send(new IconMsg_DownloadFavicon(rvh->GetRoutingID(), ++id, url, | 38 rvh->Send(new IconMsg_DownloadFavicon(rvh->GetRoutingID(), ++id, url, |
| 21 image_size)); | 39 image_size)); |
| 22 return id; | 40 return id; |
| 23 } | 41 } |
| 24 // static | 42 // static |
| 25 gfx::Image FaviconUtil::SelectFaviconFramesFromPNGs( | 43 gfx::Image FaviconUtil::SelectFaviconFramesFromPNGs( |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 36 png_data[i].bitmap_data->size(), | 54 png_data[i].bitmap_data->size(), |
| 37 &bitmap)) { | 55 &bitmap)) { |
| 38 bitmaps.push_back(bitmap); | 56 bitmaps.push_back(bitmap); |
| 39 } | 57 } |
| 40 } | 58 } |
| 41 | 59 |
| 42 if (bitmaps.empty()) | 60 if (bitmaps.empty()) |
| 43 return gfx::Image(); | 61 return gfx::Image(); |
| 44 | 62 |
| 45 gfx::ImageSkia resized_image_skia = SelectFaviconFrames(bitmaps, | 63 gfx::ImageSkia resized_image_skia = SelectFaviconFrames(bitmaps, |
| 46 ui::GetSupportedScaleFactors(), favicon_size, NULL); | 64 scale_factors, favicon_size, NULL); |
| 47 return gfx::Image(resized_image_skia); | 65 return gfx::Image(resized_image_skia); |
| 48 } | 66 } |
| OLD | NEW |