diff options
author | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-05 01:33:36 +0000 |
---|---|---|
committer | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-05 01:33:36 +0000 |
commit | 04a1f975f55a6bd2d73a45f0cec8bb2b8a5a67dd (patch) | |
tree | 6da04673ee580778b5ae4f1d42bae5d83df2ae93 | |
parent | bec7e3c3e479216d419281af4bf52151101fb6a9 (diff) | |
download | chromium_src-04a1f975f55a6bd2d73a45f0cec8bb2b8a5a67dd.zip chromium_src-04a1f975f55a6bd2d73a45f0cec8bb2b8a5a67dd.tar.gz chromium_src-04a1f975f55a6bd2d73a45f0cec8bb2b8a5a67dd.tar.bz2 |
Make the DOMUIThemeSource load and pass through a PNG, rather than relying on decode/encode.
BUG=18427
TEST=Install a giant theme, load the NNTP, verify that you can type in the omnibox without delay while the page is loading.
Review URL: http://codereview.chromium.org/159891
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22457 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | app/theme_provider.h | 6 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider.cc | 18 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider.h | 11 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_theme_source.cc | 16 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_theme_source_unittest.cc | 16 | ||||
-rw-r--r-- | views/widget/default_theme_provider.h | 3 |
6 files changed, 46 insertions, 24 deletions
diff --git a/app/theme_provider.h b/app/theme_provider.h index ef19724..073247c 100644 --- a/app/theme_provider.h +++ b/app/theme_provider.h @@ -5,6 +5,8 @@ #ifndef APP_THEME_PROVIDER_H_ #define APP_THEME_PROVIDER_H_ +#include <vector> + #include "base/basictypes.h" #include "third_party/skia/include/core/SkColor.h" @@ -58,6 +60,10 @@ class ThemeProvider { // doesn't provide a certain image, but custom themes might (badges, etc). virtual bool HasCustomImage(int id) = 0; + // Reads the image data from the theme file into the specified vector. Returns + // true on success. + virtual bool GetRawData(int id, std::vector<unsigned char>* raw_data) = 0; + #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) // Gets the GdkPixbuf with the specified |id|. Returns a pointer to a shared // instance of the GdkPixbuf. This shared GdkPixbuf is owned by the theme diff --git a/chrome/browser/browser_theme_provider.cc b/chrome/browser/browser_theme_provider.cc index 116b4d8..ac15107 100644 --- a/chrome/browser/browser_theme_provider.cc +++ b/chrome/browser/browser_theme_provider.cc @@ -353,6 +353,22 @@ bool BrowserThemeProvider::HasCustomImage(int id) { return (images_.find(id) != images_.end()); } +bool BrowserThemeProvider::GetRawData(int id, + std::vector<unsigned char>* raw_data) { + if (raw_data_.find(id) != raw_data_.end()) { + *raw_data = raw_data_[id]; + return true; + } + + if (!ReadThemeFileData(id, raw_data)) { + if (!rb_.LoadImageResourceBytes(id, raw_data)) + return false; + } + + raw_data_[id] = *raw_data; + return true; +} + void BrowserThemeProvider::SetTheme(Extension* extension) { // Clear our image cache. ClearCaches(); @@ -364,6 +380,7 @@ void BrowserThemeProvider::SetTheme(Extension* extension) { SetColorData(extension->GetThemeColors()); SetTintData(extension->GetThemeTints()); SetDisplayPropertyData(extension->GetThemeDisplayProperties()); + raw_data_.clear(); GenerateFrameColors(); GenerateFrameImages(); GenerateTabImages(); @@ -780,6 +797,7 @@ void BrowserThemeProvider::ClearAllThemeData() { colors_.clear(); tints_.clear(); display_properties_.clear(); + raw_data_.clear(); SaveImageData(NULL); SaveColorData(); diff --git a/chrome/browser/browser_theme_provider.h b/chrome/browser/browser_theme_provider.h index d1cd510..525d396 100644 --- a/chrome/browser/browser_theme_provider.h +++ b/chrome/browser/browser_theme_provider.h @@ -154,6 +154,7 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, virtual bool GetDisplayProperty(int id, int* result); virtual bool ShouldUseNativeFrame(); virtual bool HasCustomImage(int id); + virtual bool GetRawData(int id, std::vector<unsigned char>* raw_data); #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) virtual GdkPixbuf* GetPixbufNamed(int id); virtual GdkPixbuf* GetRTLEnabledPixbufNamed(int id); @@ -176,6 +177,10 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, // locally customized.) std::string GetThemeID(); + // Reads the image data from the theme file into the specified vector. Returns + // true on success. + bool ReadThemeFileData(int id, std::vector<unsigned char>* raw_data); + // Convert a bitfield alignment into a string like "top left". Public so that // it can be used to generate CSS values. Takes a bitfield of AlignmentMasks. static std::string AlignmentToString(int alignment); @@ -229,10 +234,7 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, typedef std::map<const std::string, SkColor> ColorMap; typedef std::map<const std::string, skia::HSL> TintMap; typedef std::map<const std::string, int> DisplayPropertyMap; - - // Reads the image data from the theme file into the specified vector. Returns - // true on success. - bool ReadThemeFileData(int id, std::vector<unsigned char>* raw_data); + typedef std::map<const int, std::vector<unsigned char> > RawDataMap; // Returns the string key for the given tint |id| TINT_* enum value. const std::string GetTintKey(int id); @@ -316,6 +318,7 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, ImageMap images_; ColorMap colors_; TintMap tints_; + RawDataMap raw_data_; DisplayPropertyMap display_properties_; DISALLOW_COPY_AND_ASSIGN(BrowserThemeProvider); diff --git a/chrome/browser/dom_ui/dom_ui_theme_source.cc b/chrome/browser/dom_ui/dom_ui_theme_source.cc index 7e7fd38..2b7b826 100644 --- a/chrome/browser/dom_ui/dom_ui_theme_source.cc +++ b/chrome/browser/dom_ui/dom_ui_theme_source.cc @@ -155,18 +155,14 @@ void DOMUIThemeSource::SendThemeBitmap(int request_id, int resource_id) { ThemeProvider* tp = profile_->GetThemeProvider(); DCHECK(tp); - SkBitmap* image = tp->GetBitmapNamed(resource_id); - if (!image || image->empty()) { + std::vector<unsigned char> png_bytes; + if (tp->GetRawData(resource_id, &png_bytes)) { + scoped_refptr<RefCountedBytes> image_data = + new RefCountedBytes(png_bytes); + SendResponse(request_id, image_data); + } else { SendResponse(request_id, NULL); - return; } - - std::vector<unsigned char> png_bytes; - PNGEncoder::EncodeBGRASkBitmap(*image, false, &png_bytes); - - scoped_refptr<RefCountedBytes> image_data = - new RefCountedBytes(png_bytes); - SendResponse(request_id, image_data); } std::string DOMUIThemeSource::GetNewTabBackgroundCSS(bool bar_attached) { diff --git a/chrome/browser/dom_ui/dom_ui_theme_source_unittest.cc b/chrome/browser/dom_ui/dom_ui_theme_source_unittest.cc index 1d323fa..561cd6d 100644 --- a/chrome/browser/dom_ui/dom_ui_theme_source_unittest.cc +++ b/chrome/browser/dom_ui/dom_ui_theme_source_unittest.cc @@ -17,7 +17,7 @@ class MockThemeSource : public DOMUIThemeSource { explicit MockThemeSource(Profile* profile) : DOMUIThemeSource(profile), result_request_id_(-1), - result_data_size_(0) { + result_data_size_(0) { } virtual void SendResponse(int request_id, RefCountedBytes* data) { @@ -56,20 +56,16 @@ TEST_F(DOMUISourcesTest, ThemeSourceMimeTypes) { } TEST_F(DOMUISourcesTest, ThemeSourceImages) { - // Our test data. Rather than comparing the data itself, we just compare - // its size. - SkBitmap* image = ResourceBundle::GetSharedInstance().GetBitmapNamed( - IDR_THEME_FRAME_INCOGNITO); - std::vector<unsigned char> png_bytes; - PNGEncoder::EncodeBGRASkBitmap(*image, false, &png_bytes); - + // We used to PNGEncode the images ourselves, but encoder differences + // invalidated that. We now just check that the image exists. theme_source()->StartDataRequest("theme_frame_incognito", 1); + size_t min = 0; EXPECT_EQ(theme_source()->result_request_id_, 1); - EXPECT_EQ(theme_source()->result_data_size_, png_bytes.size()); + EXPECT_GT(theme_source()->result_data_size_, min); theme_source()->StartDataRequest("theme_toolbar", 2); EXPECT_EQ(theme_source()->result_request_id_, 2); - EXPECT_NE(theme_source()->result_data_size_, png_bytes.size()); + EXPECT_GT(theme_source()->result_data_size_, min); } TEST_F(DOMUISourcesTest, ThemeSourceCSS) { diff --git a/views/widget/default_theme_provider.h b/views/widget/default_theme_provider.h index 1a505cd..cc537b9 100644 --- a/views/widget/default_theme_provider.h +++ b/views/widget/default_theme_provider.h @@ -25,6 +25,9 @@ class DefaultThemeProvider : public ThemeProvider { virtual bool GetDisplayProperty(int id, int* result); virtual bool ShouldUseNativeFrame(); virtual bool HasCustomImage(int id); + virtual bool GetRawData(int id, std::vector<unsigned char>* raw_data) { + return false; + } private: DISALLOW_COPY_AND_ASSIGN(DefaultThemeProvider); |