diff options
-rw-r--r-- | chrome/browser/jumplist_win.cc | 4 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app.cc | 2 | ||||
-rw-r--r-- | gfx/icon_util.cc | 4 | ||||
-rw-r--r-- | gfx/icon_util.h | 6 | ||||
-rw-r--r-- | gfx/icon_util_unittest.cc | 86 |
5 files changed, 53 insertions, 49 deletions
diff --git a/chrome/browser/jumplist_win.cc b/chrome/browser/jumplist_win.cc index 1f434f6..baf6938 100644 --- a/chrome/browser/jumplist_win.cc +++ b/chrome/browser/jumplist_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -255,7 +255,7 @@ bool CreateIconFile(const SkBitmap& bitmap, // Create an icon file from the favicon attached to the given |page|, and // save it as the temporary file. - if (!IconUtil::CreateIconFileFromSkBitmap(bitmap, path.value())) + if (!IconUtil::CreateIconFileFromSkBitmap(bitmap, path)) return false; // Add this icon file to the list and return its absolute path. diff --git a/chrome/browser/web_applications/web_app.cc b/chrome/browser/web_applications/web_app.cc index 97a2329..df01bd5 100644 --- a/chrome/browser/web_applications/web_app.cc +++ b/chrome/browser/web_applications/web_app.cc @@ -128,7 +128,7 @@ void GetImageCheckSum(const SkBitmap& image, MD5Digest* digest) { #if defined(OS_WIN) // Saves |image| as an |icon_file| with the checksum. bool SaveIconWithCheckSum(const FilePath& icon_file, const SkBitmap& image) { - if (!IconUtil::CreateIconFileFromSkBitmap(image, icon_file.value())) + if (!IconUtil::CreateIconFileFromSkBitmap(image, icon_file)) return false; MD5Digest digest; diff --git a/gfx/icon_util.cc b/gfx/icon_util.cc index 75435e0..35aa230 100644 --- a/gfx/icon_util.cc +++ b/gfx/icon_util.cc @@ -255,6 +255,10 @@ bool IconUtil::CreateIconFileFromSkBitmap(const SkBitmap& bitmap, return !delete_file; } +bool IconUtil::CreateIconFileFromSkBitmap(const SkBitmap& bitmap, + const FilePath& icon_path) { + return CreateIconFileFromSkBitmap(bitmap, icon_path.ToWStringHack()); +} bool IconUtil::PixelsHaveAlpha(const uint32* pixels, size_t num_pixels) { for (const uint32* end = pixels + num_pixels; pixels != end; ++pixels) { if ((*pixels & 0xff000000) != 0) diff --git a/gfx/icon_util.h b/gfx/icon_util.h index 7a1233e..80c81f6 100644 --- a/gfx/icon_util.h +++ b/gfx/icon_util.h @@ -12,8 +12,9 @@ #include "base/basictypes.h" namespace gfx { - class Size; +class Size; } +class FilePath; class SkBitmap; /////////////////////////////////////////////////////////////////////////////// @@ -77,8 +78,11 @@ class IconUtil { // the desired .ico file. // // The function returns true on success and false otherwise. + // TODO(tfarina): Deprecated version of the FilePath version below. static bool CreateIconFileFromSkBitmap(const SkBitmap& bitmap, const std::wstring& icon_file_name); + static bool CreateIconFileFromSkBitmap(const SkBitmap& bitmap, + const FilePath& icon_path); private: // The icon format is published in the MSDN but there is no definition of diff --git a/gfx/icon_util_unittest.cc b/gfx/icon_util_unittest.cc index aba8e5c..996dac4 100644 --- a/gfx/icon_util_unittest.cc +++ b/gfx/icon_util_unittest.cc @@ -2,62 +2,59 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/scoped_ptr.h" #include "base/file_util.h" #include "base/path_service.h" +#include "base/scoped_ptr.h" #include "gfx/gfx_paths.h" #include "gfx/icon_util.h" #include "gfx/size.h" -#include "third_party/skia/include/core/SkBitmap.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/skia/include/core/SkBitmap.h" namespace { - static const wchar_t* const kSmallIconName = L"icon_util\\16_X_16_icon.ico"; - static const wchar_t* const kLargeIconName = L"icon_util\\128_X_128_icon.ico"; - static const wchar_t* const kTempIconFilename = L"temp_test_icon.ico"; +static const char kSmallIconName[] = "icon_util/16_X_16_icon.ico"; +static const char kLargeIconName[] = "icon_util/128_X_128_icon.ico"; +static const char kTempIconFilename[] = "temp_test_icon.ico"; - class IconUtilTest : public testing::Test { - public: - IconUtilTest() { - PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_); - } - ~IconUtilTest() {} +class IconUtilTest : public testing::Test { + public: + IconUtilTest() { + PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_); + } + ~IconUtilTest() {} - static const int kSmallIconWidth = 16; - static const int kSmallIconHeight = 16; - static const int kLargeIconWidth = 128; - static const int kLargeIconHeight = 128; + static const int kSmallIconWidth = 16; + static const int kSmallIconHeight = 16; + static const int kLargeIconWidth = 128; + static const int kLargeIconHeight = 128; - // Given a file name for an .ico file and an image dimentions, this - // function loads the icon and returns an HICON handle. - HICON LoadIconFromFile(const std::wstring& filename, - int width, - int height) { - HICON icon = - static_cast<HICON>(LoadImage(NULL, - filename.c_str(), - IMAGE_ICON, - width, - height, - LR_LOADTRANSPARENT | LR_LOADFROMFILE)); - return icon; - } + // Given a file name for an .ico file and an image dimentions, this + // function loads the icon and returns an HICON handle. + HICON LoadIconFromFile(const FilePath& filename, int width, int height) { + HICON icon = static_cast<HICON>(LoadImage(NULL, + filename.value().c_str(), + IMAGE_ICON, + width, + height, + LR_LOADTRANSPARENT | LR_LOADFROMFILE)); + return icon; + } - protected: - // The root directory for test files. - std::wstring test_data_directory_; + protected: + // The root directory for test files. + FilePath test_data_directory_; - private: - DISALLOW_COPY_AND_ASSIGN(IconUtilTest); - }; + private: + DISALLOW_COPY_AND_ASSIGN(IconUtilTest); }; +} // namespace + // The following test case makes sure IconUtil::SkBitmapFromHICON fails // gracefully when called with invalid input parameters. TEST_F(IconUtilTest, TestIconToBitmapInvalidParameters) { - std::wstring icon_filename(test_data_directory_); - file_util::AppendToPath(&icon_filename, kSmallIconName); + FilePath icon_filename = test_data_directory_.AppendASCII(kSmallIconName); gfx::Size icon_size(kSmallIconWidth, kSmallIconHeight); HICON icon = LoadIconFromFile(icon_filename, icon_size.width(), @@ -114,8 +111,8 @@ TEST_F(IconUtilTest, TestBitmapToIconInvalidParameters) { // fails gracefully when called with invalid input parameters. TEST_F(IconUtilTest, TestCreateIconFileInvalidParameters) { scoped_ptr<SkBitmap> bitmap; - std::wstring valid_icon_filename(test_data_directory_); - file_util::AppendToPath(&valid_icon_filename, kSmallIconName); + FilePath valid_icon_filename = test_data_directory_.AppendASCII( + kSmallIconName); std::wstring invalid_icon_filename(L"C:\\<>?.ico"); // Wrong bitmap format. @@ -153,8 +150,8 @@ TEST_F(IconUtilTest, TestCreateIconFileInvalidParameters) { // the HICON into a bitmap, the bitmap has the expected format and dimentions. TEST_F(IconUtilTest, TestCreateSkBitmapFromHICON) { scoped_ptr<SkBitmap> bitmap; - std::wstring small_icon_filename(test_data_directory_); - file_util::AppendToPath(&small_icon_filename, kSmallIconName); + FilePath small_icon_filename = test_data_directory_.AppendASCII( + kSmallIconName); gfx::Size small_icon_size(kSmallIconWidth, kSmallIconHeight); HICON small_icon = LoadIconFromFile(small_icon_filename, small_icon_size.width(), @@ -167,8 +164,8 @@ TEST_F(IconUtilTest, TestCreateSkBitmapFromHICON) { EXPECT_EQ(bitmap->config(), SkBitmap::kARGB_8888_Config); ::DestroyIcon(small_icon); - std::wstring large_icon_filename(test_data_directory_); - file_util::AppendToPath(&large_icon_filename, kLargeIconName); + FilePath large_icon_filename = test_data_directory_.AppendASCII( + kLargeIconName); gfx::Size large_icon_size(kLargeIconWidth, kLargeIconHeight); HICON large_icon = LoadIconFromFile(large_icon_filename, large_icon_size.width(), @@ -230,8 +227,7 @@ TEST_F(IconUtilTest, TestBasicCreateHICONFromSkBitmap) { // creates a valid .ico file given an SkBitmap. TEST_F(IconUtilTest, TestCreateIconFile) { scoped_ptr<SkBitmap> bitmap; - std::wstring icon_filename(test_data_directory_); - file_util::AppendToPath(&icon_filename, kTempIconFilename); + FilePath icon_filename = test_data_directory_.AppendASCII(kTempIconFilename); // Allocating the bitmap. bitmap.reset(new SkBitmap); |