diff options
-rw-r--r-- | chrome/browser/extensions/extension_web_ui.cc | 4 | ||||
-rw-r--r-- | chrome/browser/favicon/DEPS | 13 | ||||
-rw-r--r-- | chrome/browser/favicon/favicon_handler.cc | 16 | ||||
-rw-r--r-- | chrome/browser/favicon/favicon_service.cc | 41 | ||||
-rw-r--r-- | chrome/browser/favicon/favicon_tab_helper.cc | 1 | ||||
-rw-r--r-- | chrome/browser/favicon/favicon_util.h | 45 | ||||
-rw-r--r-- | chrome/browser/sync/test/integration/bookmarks_helper.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/metro_pin_tab_helper_win.cc | 1 | ||||
-rw-r--r-- | chrome/browser/ui/views/create_application_shortcut_view.cc | 1 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | components/favicon_base.gypi | 2 | ||||
-rw-r--r-- | components/favicon_base/BUILD.gn | 2 | ||||
-rw-r--r-- | components/favicon_base/favicon_util.cc (renamed from chrome/browser/favicon/favicon_util.cc) | 53 | ||||
-rw-r--r-- | components/favicon_base/favicon_util.h | 41 |
14 files changed, 110 insertions, 116 deletions
diff --git a/chrome/browser/extensions/extension_web_ui.cc b/chrome/browser/extensions/extension_web_ui.cc index aba836d..6e054bb 100644 --- a/chrome/browser/extensions/extension_web_ui.cc +++ b/chrome/browser/extensions/extension_web_ui.cc @@ -18,11 +18,11 @@ #include "chrome/browser/extensions/extension_util.h" #include "chrome/browser/extensions/image_loader.h" #include "chrome/browser/favicon/favicon_service.h" -#include "chrome/browser/favicon/favicon_util.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/url_constants.h" +#include "components/favicon_base/favicon_util.h" #include "components/pref_registry/pref_registry_syncable.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/web_contents.h" @@ -425,7 +425,7 @@ void ExtensionWebUI::GetFaviconForURL( // 1x) immediately instead of in an as needed fashion to be consistent with // how favicons are requested for chrome:// and page URLs. const std::vector<ui::ScaleFactor>& scale_factors = - FaviconUtil::GetFaviconScaleFactors(); + favicon_base::GetFaviconScaleFactors(); std::vector<extensions::ImageLoader::ImageRepresentation> info_list; for (size_t i = 0; i < scale_factors.size(); ++i) { float scale = ui::GetScaleForScaleFactor(scale_factors[i]); diff --git a/chrome/browser/favicon/DEPS b/chrome/browser/favicon/DEPS index 40d15b4..83f4054 100644 --- a/chrome/browser/favicon/DEPS +++ b/chrome/browser/favicon/DEPS @@ -29,16 +29,3 @@ include_rules = [ # Do not add to the list of temporarily-allowed dependencies above, # and please do not introduce more #includes of these files. ] - -specific_include_rules = { - # TODO(caitkp): Look into removing history/ dependencies. - 'favicon_util\.(h|cc)': [ - "-chrome", - "-chrome/browser", - "+chrome/browser/favicon/favicon_util.h", - "+chrome/common/favicon/favicon_types.h", - "+chrome/common/icon_messages.h", - "!chrome/browser/history/history_types.h", - "!chrome/browser/history/select_favicon_frames.h", - ] -} diff --git a/chrome/browser/favicon/favicon_handler.cc b/chrome/browser/favicon/favicon_handler.cc index f6d7160..be6d9af 100644 --- a/chrome/browser/favicon/favicon_handler.cc +++ b/chrome/browser/favicon/favicon_handler.cc @@ -14,7 +14,7 @@ #include "base/memory/ref_counted_memory.h" #include "chrome/browser/favicon/favicon_service.h" #include "chrome/browser/favicon/favicon_service_factory.h" -#include "chrome/browser/favicon/favicon_util.h" +#include "components/favicon_base/favicon_util.h" #include "components/favicon_base/select_favicon_frames.h" #include "skia/ext/image_operations.h" #include "ui/gfx/codec/png_codec.h" @@ -98,7 +98,7 @@ bool IsValid(const favicon_base::FaviconRawBitmapResult& bitmap_result) { // Returns true if at least one of the bitmaps in |bitmap_results| is expired or // if |bitmap_results| is missing favicons for |desired_size_in_dip| and one of -// the scale factors in FaviconUtil::GetFaviconScaleFactors(). +// the scale factors in favicon_base::GetFaviconScaleFactors(). bool HasExpiredOrIncompleteResult( int desired_size_in_dip, const std::vector<favicon_base::FaviconRawBitmapResult>& bitmap_results) { @@ -115,7 +115,7 @@ bool HasExpiredOrIncompleteResult( // Check if the favicon for at least one of the scale factors is missing. // |bitmap_results| should always be complete for data inserted by // FaviconHandler as the FaviconHandler stores favicons resized to all - // of FaviconUtil::GetFaviconScaleFactors() into the history backend. + // of favicon_base::GetFaviconScaleFactors() into the history backend. // Examples of when |bitmap_results| can be incomplete: // - Favicons inserted into the history backend by sync. // - Favicons for imported bookmarks. @@ -124,7 +124,7 @@ bool HasExpiredOrIncompleteResult( favicon_sizes.push_back(bitmap_results[i].pixel_size); std::vector<ui::ScaleFactor> scale_factors = - FaviconUtil::GetFaviconScaleFactors(); + favicon_base::GetFaviconScaleFactors(); for (size_t i = 0; i < scale_factors.size(); ++i) { int edge_size_in_pixel = floor( desired_size_in_dip * ui::GetScaleForScaleFactor(scale_factors[i])); @@ -315,9 +315,9 @@ void FaviconHandler::SetFavicon(const GURL& url, void FaviconHandler::SetFaviconOnActivePage(const std::vector< favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results) { - gfx::Image resized_image = FaviconUtil::SelectFaviconFramesFromPNGs( + gfx::Image resized_image = favicon_base::SelectFaviconFramesFromPNGs( favicon_bitmap_results, - FaviconUtil::GetFaviconScaleFactors(), + favicon_base::GetFaviconScaleFactors(), preferred_icon_size()); // The history service sends back results for a single icon URL, so it does // not matter which result we get the |icon_url| from. @@ -338,7 +338,7 @@ void FaviconHandler::SetFaviconOnActivePage(const GURL& icon_url, return; gfx::Image image_with_adjusted_colorspace = image; - FaviconUtil::SetFaviconColorSpace(&image_with_adjusted_colorspace); + favicon_base::SetFaviconColorSpace(&image_with_adjusted_colorspace); driver_->SetActiveFaviconImage(image_with_adjusted_colorspace); NotifyFaviconUpdated(icon_url_changed); @@ -429,7 +429,7 @@ void FaviconHandler::OnDidDownloadFavicon( image_skia = gfx::ImageSkia(gfx::ImageSkiaRep(bitmaps[index], 1)); } else { std::vector<ui::ScaleFactor> scale_factors = - FaviconUtil::GetFaviconScaleFactors(); + favicon_base::GetFaviconScaleFactors(); image_skia = SelectFaviconFrames(bitmaps, original_bitmap_sizes, scale_factors, diff --git a/chrome/browser/favicon/favicon_service.cc b/chrome/browser/favicon/favicon_service.cc index afa0142..5d4763e 100644 --- a/chrome/browser/favicon/favicon_service.cc +++ b/chrome/browser/favicon/favicon_service.cc @@ -6,7 +6,6 @@ #include "base/hash.h" #include "base/message_loop/message_loop_proxy.h" -#include "chrome/browser/favicon/favicon_util.h" #include "chrome/browser/history/history_backend.h" #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" @@ -14,6 +13,7 @@ #include "chrome/common/importer/imported_favicon_usage.h" #include "chrome/common/url_constants.h" #include "components/favicon_base/favicon_types.h" +#include "components/favicon_base/favicon_util.h" #include "components/favicon_base/select_favicon_frames.h" #include "extensions/common/constants.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -89,9 +89,12 @@ base::CancelableTaskTracker::TaskId FaviconService::GetFaviconImage( if (history_service_) { std::vector<GURL> icon_urls; icon_urls.push_back(icon_url); - return history_service_->GetFavicons( - icon_urls, icon_type, desired_size_in_dip, - FaviconUtil::GetFaviconScaleFactors(), callback_runner, tracker); + return history_service_->GetFavicons(icon_urls, + icon_type, + desired_size_in_dip, + favicon_base::GetFaviconScaleFactors(), + callback_runner, + tracker); } return RunWithEmptyResultAsync(callback_runner, tracker); } @@ -132,9 +135,12 @@ base::CancelableTaskTracker::TaskId FaviconService::GetFavicon( if (history_service_) { std::vector<GURL> icon_urls; icon_urls.push_back(icon_url); - return history_service_->GetFavicons( - icon_urls, icon_type, desired_size_in_dip, - FaviconUtil::GetFaviconScaleFactors(), callback, tracker); + return history_service_->GetFavicons(icon_urls, + icon_type, + desired_size_in_dip, + favicon_base::GetFaviconScaleFactors(), + callback, + tracker); } return RunWithEmptyResultAsync(callback, tracker); } @@ -149,8 +155,13 @@ FaviconService::UpdateFaviconMappingsAndFetch( base::CancelableTaskTracker* tracker) { if (history_service_) { return history_service_->UpdateFaviconMappingsAndFetch( - page_url, icon_urls, icon_types, desired_size_in_dip, - FaviconUtil::GetFaviconScaleFactors(), callback, tracker); + page_url, + icon_urls, + icon_types, + desired_size_in_dip, + favicon_base::GetFaviconScaleFactors(), + callback, + tracker); } return RunWithEmptyResultAsync(callback, tracker); } @@ -161,7 +172,7 @@ base::CancelableTaskTracker::TaskId FaviconService::GetFaviconImageForPageURL( base::CancelableTaskTracker* tracker) { return GetFaviconForPageURLImpl( params, - FaviconUtil::GetFaviconScaleFactors(), + favicon_base::GetFaviconScaleFactors(), Bind(&FaviconService::RunFaviconImageCallbackWithBitmapResults, base::Unretained(this), callback, @@ -220,7 +231,7 @@ base::CancelableTaskTracker::TaskId FaviconService::GetFaviconForPageURL( const favicon_base::FaviconResultsCallback& callback, base::CancelableTaskTracker* tracker) { return GetFaviconForPageURLImpl( - params, FaviconUtil::GetFaviconScaleFactors(), callback, tracker); + params, favicon_base::GetFaviconScaleFactors(), callback, tracker); } base::CancelableTaskTracker::TaskId FaviconService::GetLargestRawFaviconForID( @@ -349,11 +360,11 @@ void FaviconService::RunFaviconImageCallbackWithBitmapResults( const std::vector<favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results) { favicon_base::FaviconImageResult image_result; - image_result.image = FaviconUtil::SelectFaviconFramesFromPNGs( + image_result.image = favicon_base::SelectFaviconFramesFromPNGs( favicon_bitmap_results, - FaviconUtil::GetFaviconScaleFactors(), + favicon_base::GetFaviconScaleFactors(), desired_size_in_dip); - FaviconUtil::SetFaviconColorSpace(&image_result.image); + favicon_base::SetFaviconColorSpace(&image_result.image); image_result.icon_url = image_result.image.IsEmpty() ? GURL() : favicon_bitmap_results[0].icon_url; @@ -399,7 +410,7 @@ void FaviconService::RunFaviconRawBitmapCallbackWithBitmapResults( // convert back. std::vector<ui::ScaleFactor> desired_scale_factors; desired_scale_factors.push_back(desired_scale_factor); - gfx::Image resized_image = FaviconUtil::SelectFaviconFramesFromPNGs( + gfx::Image resized_image = favicon_base::SelectFaviconFramesFromPNGs( favicon_bitmap_results, desired_scale_factors, desired_size_in_dip); std::vector<unsigned char> resized_bitmap_data; diff --git a/chrome/browser/favicon/favicon_tab_helper.cc b/chrome/browser/favicon/favicon_tab_helper.cc index 67eb093..793b582 100644 --- a/chrome/browser/favicon/favicon_tab_helper.cc +++ b/chrome/browser/favicon/favicon_tab_helper.cc @@ -9,7 +9,6 @@ #include "chrome/browser/favicon/favicon_handler.h" #include "chrome/browser/favicon/favicon_service.h" #include "chrome/browser/favicon/favicon_service_factory.h" -#include "chrome/browser/favicon/favicon_util.h" #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/profiles/profile.h" diff --git a/chrome/browser/favicon/favicon_util.h b/chrome/browser/favicon/favicon_util.h deleted file mode 100644 index 8f9c0ca..0000000 --- a/chrome/browser/favicon/favicon_util.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_FAVICON_FAVICON_UTIL_H_ -#define CHROME_BROWSER_FAVICON_FAVICON_UTIL_H_ - -#include <vector> - -#include "components/favicon_base/favicon_types.h" -#include "ui/base/layout.h" - -namespace chrome { -struct FaviconRawBitmapResult; -} - -namespace gfx { -class Image; -} - -// Utility class for common favicon related code. -class FaviconUtil { - public: - // Returns the scale factors at which favicons should be fetched. This is - // different from ui::GetSupportedScaleFactors() because clients which do - // not support 1x should still fetch a favicon for 1x to push to sync. This - // guarantees that the clients receiving sync updates pushed by this client - // receive a favicon (potentially of the wrong scale factor) and do not show - // the default favicon. - static std::vector<ui::ScaleFactor> GetFaviconScaleFactors(); - - // Sets the color space used for converting |image| to an NSImage to the - // system colorspace. This makes the favicon look the same in the browser UI - // as it does in the renderer. - static void SetFaviconColorSpace(gfx::Image* image); - - // Takes a vector of png-encoded frames, decodes them, and converts them to - // a favicon of size favicon_size (in DIPs) at the desired ui scale factors. - static gfx::Image SelectFaviconFramesFromPNGs( - const std::vector<favicon_base::FaviconRawBitmapResult>& png_data, - const std::vector<ui::ScaleFactor>& scale_factors, - int favicon_size); -}; - -#endif // CHROME_BROWSER_FAVICON_FAVICON_UTIL_H_ diff --git a/chrome/browser/sync/test/integration/bookmarks_helper.cc b/chrome/browser/sync/test/integration/bookmarks_helper.cc index a8d3ea0..a05d296 100644 --- a/chrome/browser/sync/test/integration/bookmarks_helper.cc +++ b/chrome/browser/sync/test/integration/bookmarks_helper.cc @@ -16,7 +16,6 @@ #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/favicon/favicon_service.h" #include "chrome/browser/favicon/favicon_service_factory.h" -#include "chrome/browser/favicon/favicon_util.h" #include "chrome/browser/history/history_db_task.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/history_types.h" @@ -31,6 +30,7 @@ #include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model_observer.h" #include "components/bookmarks/browser/bookmark_utils.h" +#include "components/favicon_base/favicon_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/models/tree_node_iterator.h" @@ -769,7 +769,7 @@ gfx::Image CreateFavicon(SkColor color) { const int dip_width = 16; const int dip_height = 16; std::vector<ui::ScaleFactor> favicon_scale_factors = - FaviconUtil::GetFaviconScaleFactors(); + favicon_base::GetFaviconScaleFactors(); gfx::ImageSkia favicon; for (size_t i = 0; i < favicon_scale_factors.size(); ++i) { float scale = ui::GetScaleForScaleFactor(favicon_scale_factors[i]); diff --git a/chrome/browser/ui/metro_pin_tab_helper_win.cc b/chrome/browser/ui/metro_pin_tab_helper_win.cc index bb334e2..9b3b978 100644 --- a/chrome/browser/ui/metro_pin_tab_helper_win.cc +++ b/chrome/browser/ui/metro_pin_tab_helper_win.cc @@ -19,7 +19,6 @@ #include "base/strings/utf_string_conversions.h" #include "base/win/metro.h" #include "chrome/browser/favicon/favicon_tab_helper.h" -#include "chrome/browser/favicon/favicon_util.h" #include "chrome/common/chrome_paths.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/web_contents.h" diff --git a/chrome/browser/ui/views/create_application_shortcut_view.cc b/chrome/browser/ui/views/create_application_shortcut_view.cc index b9dd297..2b7f0ee 100644 --- a/chrome/browser/ui/views/create_application_shortcut_view.cc +++ b/chrome/browser/ui/views/create_application_shortcut_view.cc @@ -12,7 +12,6 @@ #include "base/strings/utf_string_conversions.h" #include "base/win/windows_version.h" #include "chrome/browser/extensions/tab_helper.h" -#include "chrome/browser/favicon/favicon_util.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 22a5d43..841c733 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -656,8 +656,6 @@ 'browser/favicon/favicon_service_factory.h', 'browser/favicon/favicon_tab_helper.cc', 'browser/favicon/favicon_tab_helper.h', - 'browser/favicon/favicon_util.cc', - 'browser/favicon/favicon_util.h', 'browser/file_select_helper.cc', 'browser/file_select_helper.h', 'browser/first_run/first_run.cc', diff --git a/components/favicon_base.gypi b/components/favicon_base.gypi index d1d0e2e..75210ca 100644 --- a/components/favicon_base.gypi +++ b/components/favicon_base.gypi @@ -17,6 +17,8 @@ 'favicon_base/favicon_callback.h', 'favicon_base/favicon_types.cc', 'favicon_base/favicon_types.h', + 'favicon_base/favicon_util.cc', + 'favicon_base/favicon_util.h', 'favicon_base/select_favicon_frames.cc', 'favicon_base/select_favicon_frames.h', ], diff --git a/components/favicon_base/BUILD.gn b/components/favicon_base/BUILD.gn index 3d4f638..6e40b06 100644 --- a/components/favicon_base/BUILD.gn +++ b/components/favicon_base/BUILD.gn @@ -7,6 +7,8 @@ source_set("favicon_base") { "favicon_callback.h", "favicon_types.cc", "favicon_types.h", + "favicon_util.cc", + "favicon_util.h", "select_favicon_frames.cc", "select_favicon_frames.h", ] diff --git a/chrome/browser/favicon/favicon_util.cc b/components/favicon_base/favicon_util.cc index d903b8b..0a3f0a2 100644 --- a/chrome/browser/favicon/favicon_util.cc +++ b/components/favicon_base/favicon_util.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/favicon/favicon_util.h" +#include "components/favicon_base/favicon_util.h" #include "components/favicon_base/favicon_types.h" #include "components/favicon_base/select_favicon_frames.h" @@ -19,6 +19,7 @@ #include "base/mac/mac_util.h" #endif // defined(OS_MACOSX) && !defined(OS_IOS) +namespace favicon_base { namespace { // Creates image reps of DIP size |favicon_size| for the subset of @@ -52,8 +53,8 @@ std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing( // supported by the platform. (ui::GetSupportedScaleFactor() cannot be used.) std::map<int, ui::ScaleFactor> desired_pixel_sizes; for (size_t i = 0; i < scale_factors.size(); ++i) { - int pixel_size = floor(favicon_size * - ui::GetScaleForScaleFactor(scale_factors[i])); + int pixel_size = + floor(favicon_size * ui::GetScaleForScaleFactor(scale_factors[i])); desired_pixel_sizes[pixel_size] = scale_factors[i]; } @@ -65,14 +66,13 @@ std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing( if (pixel_size.width() != pixel_size.height()) continue; - std::map<int, ui::ScaleFactor>::iterator it = desired_pixel_sizes.find( - pixel_size.width()); + std::map<int, ui::ScaleFactor>::iterator it = + desired_pixel_sizes.find(pixel_size.width()); if (it == desired_pixel_sizes.end()) continue; - png_reps.push_back( - gfx::ImagePNGRep(png_data[i].bitmap_data, - ui::GetScaleForScaleFactor(it->second))); + png_reps.push_back(gfx::ImagePNGRep( + png_data[i].bitmap_data, ui::GetScaleForScaleFactor(it->second))); } return png_reps; @@ -136,8 +136,7 @@ SkBitmap ResizeBitmapByDownsamplingIfPossible( } // namespace -// static -std::vector<ui::ScaleFactor> FaviconUtil::GetFaviconScaleFactors() { +std::vector<ui::ScaleFactor> GetFaviconScaleFactors() { const float kScale1x = 1.0f; std::vector<ui::ScaleFactor> favicon_scale_factors = ui::GetSupportedScaleFactors(); @@ -164,15 +163,13 @@ std::vector<ui::ScaleFactor> FaviconUtil::GetFaviconScaleFactors() { return favicon_scale_factors; } -// static -void FaviconUtil::SetFaviconColorSpace(gfx::Image* image) { +void SetFaviconColorSpace(gfx::Image* image) { #if defined(OS_MACOSX) && !defined(OS_IOS) image->SetSourceColorSpace(base::mac::GetSystemColorSpace()); #endif // defined(OS_MACOSX) && !defined(OS_IOS) } -// static -gfx::Image FaviconUtil::SelectFaviconFramesFromPNGs( +gfx::Image SelectFaviconFramesFromPNGs( const std::vector<favicon_base::FaviconRawBitmapResult>& png_data, const std::vector<ui::ScaleFactor>& scale_factors, int favicon_size) { @@ -189,8 +186,8 @@ gfx::Image FaviconUtil::SelectFaviconFramesFromPNGs( // significant performance hit if a user has many bookmarks. // TODO(pkotwicz): Move the decoding off the UI thread. std::vector<gfx::ImagePNGRep> png_reps = - SelectFaviconFramesFromPNGsWithoutResizing(png_data, scale_factors, - favicon_size); + SelectFaviconFramesFromPNGsWithoutResizing( + png_data, scale_factors, favicon_size); // SelectFaviconFramesFromPNGsWithoutResizing() should have selected the // largest favicon if |favicon_size| == 0. @@ -199,10 +196,10 @@ gfx::Image FaviconUtil::SelectFaviconFramesFromPNGs( std::vector<ui::ScaleFactor> scale_factors_to_generate = scale_factors; for (size_t i = 0; i < png_reps.size(); ++i) { - for (int j = static_cast<int>(scale_factors_to_generate.size()) - 1; - j >= 0; --j) { - if (png_reps[i].scale == ui::GetScaleForScaleFactor( - scale_factors_to_generate[j])) { + for (int j = static_cast<int>(scale_factors_to_generate.size()) - 1; j >= 0; + --j) { + if (png_reps[i].scale == + ui::GetScaleForScaleFactor(scale_factors_to_generate[j])) { scale_factors_to_generate.erase(scale_factors_to_generate.begin() + j); } } @@ -231,8 +228,8 @@ gfx::Image FaviconUtil::SelectFaviconFramesFromPNGs( for (size_t i = 0; i < scale_factors_to_generate.size(); ++i) { float scale = ui::GetScaleForScaleFactor(scale_factors_to_generate[i]); int desired_size_in_pixel = ceil(favicon_size * scale); - SkBitmap bitmap = ResizeBitmapByDownsamplingIfPossible( - bitmaps, desired_size_in_pixel); + SkBitmap bitmap = + ResizeBitmapByDownsamplingIfPossible(bitmaps, desired_size_in_pixel); resized_image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); } @@ -244,11 +241,15 @@ gfx::Image FaviconUtil::SelectFaviconFramesFromPNGs( for (size_t i = 0; i < resized_image_skia_reps.size(); ++i) { scoped_refptr<base::RefCountedBytes> png_bytes(new base::RefCountedBytes()); if (gfx::PNGCodec::EncodeBGRASkBitmap( - resized_image_skia_reps[i].sk_bitmap(), false, &png_bytes->data())) { - png_reps.push_back(gfx::ImagePNGRep(png_bytes, - resized_image_skia_reps[i].scale())); + resized_image_skia_reps[i].sk_bitmap(), + false, + &png_bytes->data())) { + png_reps.push_back( + gfx::ImagePNGRep(png_bytes, resized_image_skia_reps[i].scale())); } } return gfx::Image(png_reps); } + +} // namespace favicon_base diff --git a/components/favicon_base/favicon_util.h b/components/favicon_base/favicon_util.h new file mode 100644 index 0000000..ee59428 --- /dev/null +++ b/components/favicon_base/favicon_util.h @@ -0,0 +1,41 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_FAVICON_BASE_FAVICON_UTIL_H_ +#define COMPONENTS_FAVICON_BASE_FAVICON_UTIL_H_ + +#include <vector> + +#include "components/favicon_base/favicon_types.h" +#include "ui/base/layout.h" + +namespace gfx { +class Image; +} + +namespace favicon_base { + +// Returns the scale factors at which favicons should be fetched. This is +// different from ui::GetSupportedScaleFactors() because clients which do +// not support 1x should still fetch a favicon for 1x to push to sync. This +// guarantees that the clients receiving sync updates pushed by this client +// receive a favicon (potentially of the wrong scale factor) and do not show +// the default favicon. +std::vector<ui::ScaleFactor> GetFaviconScaleFactors(); + +// Sets the color space used for converting |image| to an NSImage to the +// system colorspace. This makes the favicon look the same in the browser UI +// as it does in the renderer. +void SetFaviconColorSpace(gfx::Image* image); + +// Takes a vector of png-encoded frames, decodes them, and converts them to +// a favicon of size favicon_size (in DIPs) at the desired ui scale factors. +gfx::Image SelectFaviconFramesFromPNGs( + const std::vector<favicon_base::FaviconRawBitmapResult>& png_data, + const std::vector<ui::ScaleFactor>& scale_factors, + int favicon_size); + +} // namspace favicon_base + +#endif // COMPONENTS_FAVICON_BASE_FAVICON_UTIL_H_ |