diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser_theme_pack.cc | 12 | ||||
-rw-r--r-- | chrome/browser/browser_theme_pack.h | 8 | ||||
-rw-r--r-- | chrome/browser/browser_theme_pack_unittest.cc | 13 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider.cc | 4 |
4 files changed, 31 insertions, 6 deletions
diff --git a/chrome/browser/browser_theme_pack.cc b/chrome/browser/browser_theme_pack.cc index 2446754..ea1474c 100644 --- a/chrome/browser/browser_theme_pack.cc +++ b/chrome/browser/browser_theme_pack.cc @@ -369,7 +369,8 @@ BrowserThemePack* BrowserThemePack::BuildFromExtension(Extension* extension) { &file_paths); pack->BuildSourceImagesArray(file_paths); - pack->LoadRawBitmapsTo(file_paths, &pack->prepared_images_); + if (!pack->LoadRawBitmapsTo(file_paths, &pack->prepared_images_)) + return NULL; pack->GenerateFrameImages(&pack->prepared_images_); @@ -877,12 +878,17 @@ void BrowserThemePack::BuildSourceImagesArray(const FilePathMap& file_paths) { source_images_[ids.size()] = -1; } -void BrowserThemePack::LoadRawBitmapsTo( +bool BrowserThemePack::LoadRawBitmapsTo( const FilePathMap& file_paths, ImageCache* raw_bitmaps) { for (FilePathMap::const_iterator it = file_paths.begin(); it != file_paths.end(); ++it) { scoped_refptr<RefCountedMemory> raw_data(ReadFileData(it->second)); + if (!raw_data.get()) { + LOG(ERROR) << "Could not load theme image"; + return false; + } + int id = it->first; // Some images need to go directly into |image_memory_|. No modification is @@ -908,6 +914,8 @@ void BrowserThemePack::LoadRawBitmapsTo( } } } + + return true; } void BrowserThemePack::GenerateFrameImages(ImageCache* bitmaps) const { diff --git a/chrome/browser/browser_theme_pack.h b/chrome/browser/browser_theme_pack.h index 656dc77..e9327e4 100644 --- a/chrome/browser/browser_theme_pack.h +++ b/chrome/browser/browser_theme_pack.h @@ -40,7 +40,8 @@ class BrowserThemePack : public base::RefCountedThreadSafe<BrowserThemePack> { ~BrowserThemePack(); // Builds the theme pack from all data from |extension|. This is often done - // on a separate thread as it takes so long. + // on a separate thread as it takes so long. This can fail and return NULL in + // the case where the theme has invalid data. static BrowserThemePack* BuildFromExtension(Extension* extension); // Builds the theme pack from a previously performed WriteToDisk(). This @@ -118,8 +119,9 @@ class BrowserThemePack : public base::RefCountedThreadSafe<BrowserThemePack> { // Creates the data for |source_images_| from |file_paths|. void BuildSourceImagesArray(const FilePathMap& file_paths); - // Loads the unmodified bitmaps packed in the extension to SkBitmaps. - void LoadRawBitmapsTo(const FilePathMap& file_paths, + // Loads the unmodified bitmaps packed in the extension to SkBitmaps. Returns + // true if all images loaded. + bool LoadRawBitmapsTo(const FilePathMap& file_paths, ImageCache* raw_bitmaps); // Creates tinted and composited frame images. Source and destination is diff --git a/chrome/browser/browser_theme_pack_unittest.cc b/chrome/browser/browser_theme_pack_unittest.cc index 4c0538b..1885a30 100644 --- a/chrome/browser/browser_theme_pack_unittest.cc +++ b/chrome/browser/browser_theme_pack_unittest.cc @@ -121,6 +121,11 @@ class BrowserThemePackTest : public ::testing::Test { theme_pack_->BuildSourceImagesArray(*out_file_paths); } + bool LoadRawBitmapsTo(const std::map<int, FilePath>& out_file_paths) { + return theme_pack_->LoadRawBitmapsTo(out_file_paths, + &theme_pack_->prepared_images_); + } + FilePath GetStarGazingPath() { FilePath test_path; if (!PathService::Get(chrome::DIR_TEST_DATA, &test_path)) { @@ -373,6 +378,14 @@ TEST_F(BrowserThemePackTest, TestHasCustomImage) { EXPECT_FALSE(theme_pack_->HasCustomImage(IDR_THEME_FRAME_INCOGNITO)); } +TEST_F(BrowserThemePackTest, TestNonExistantImages) { + std::string images = "{ \"theme_frame\": \"does_not_exist\" }"; + std::map<int, FilePath> out_file_paths; + ParseImageNamesJSON(images, &out_file_paths); + + EXPECT_FALSE(LoadRawBitmapsTo(out_file_paths)); +} + // TODO(erg): This test should actually test more of the built resources from // the extension data, but for now, exists so valgrind can test some of the // tricky memory stuff that BrowserThemePack does. diff --git a/chrome/browser/browser_theme_provider.cc b/chrome/browser/browser_theme_provider.cc index 45dff50..acbda59 100644 --- a/chrome/browser/browser_theme_provider.cc +++ b/chrome/browser/browser_theme_provider.cc @@ -590,7 +590,9 @@ void BrowserThemeProvider::BuildFromExtension(Extension* extension, scoped_refptr<BrowserThemePack> pack = BrowserThemePack::BuildFromExtension(extension); if (!pack.get()) { - NOTREACHED() << "Could not load theme."; + // TODO(erg): We've failed to install the theme; perhaps we should tell the + // user? http://crbug.com/34780 + LOG(ERROR) << "Could not load theme."; return; } |