| 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/themes/browser_theme_pack.h" | 5 #include "chrome/browser/themes/browser_theme_pack.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 // kTabBackgroundMap. | 280 // kTabBackgroundMap. |
| 281 const int kPreloadIDs[] = { | 281 const int kPreloadIDs[] = { |
| 282 PRS_THEME_TOOLBAR, | 282 PRS_THEME_TOOLBAR, |
| 283 PRS_THEME_NTP_BACKGROUND, | 283 PRS_THEME_NTP_BACKGROUND, |
| 284 PRS_THEME_BUTTON_BACKGROUND, | 284 PRS_THEME_BUTTON_BACKGROUND, |
| 285 PRS_THEME_NTP_ATTRIBUTION, | 285 PRS_THEME_NTP_ATTRIBUTION, |
| 286 PRS_THEME_WINDOW_CONTROL_BACKGROUND | 286 PRS_THEME_WINDOW_CONTROL_BACKGROUND |
| 287 }; | 287 }; |
| 288 | 288 |
| 289 // Returns a piece of memory with the contents of the file |path|. | 289 // Returns a piece of memory with the contents of the file |path|. |
| 290 RefCountedMemory* ReadFileData(const FilePath& path) { | 290 base::RefCountedMemory* ReadFileData(const FilePath& path) { |
| 291 if (!path.empty()) { | 291 if (!path.empty()) { |
| 292 net::FileStream file(NULL); | 292 net::FileStream file(NULL); |
| 293 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ; | 293 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ; |
| 294 if (file.OpenSync(path, flags) == net::OK) { | 294 if (file.OpenSync(path, flags) == net::OK) { |
| 295 int64 avail = file.Available(); | 295 int64 avail = file.Available(); |
| 296 if (avail > 0 && avail < INT_MAX) { | 296 if (avail > 0 && avail < INT_MAX) { |
| 297 size_t size = static_cast<size_t>(avail); | 297 size_t size = static_cast<size_t>(avail); |
| 298 std::vector<unsigned char> raw_data; | 298 std::vector<unsigned char> raw_data; |
| 299 raw_data.resize(size); | 299 raw_data.resize(size); |
| 300 char* data = reinterpret_cast<char*>(&(raw_data.front())); | 300 char* data = reinterpret_cast<char*>(&(raw_data.front())); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 // Check our cache of prepared images, first. | 521 // Check our cache of prepared images, first. |
| 522 ImageCache::const_iterator image_iter = prepared_images_.find(prs_id); | 522 ImageCache::const_iterator image_iter = prepared_images_.find(prs_id); |
| 523 if (image_iter != prepared_images_.end()) | 523 if (image_iter != prepared_images_.end()) |
| 524 return image_iter->second; | 524 return image_iter->second; |
| 525 | 525 |
| 526 // Check if we've already loaded this image. | 526 // Check if we've already loaded this image. |
| 527 image_iter = loaded_images_.find(prs_id); | 527 image_iter = loaded_images_.find(prs_id); |
| 528 if (image_iter != loaded_images_.end()) | 528 if (image_iter != loaded_images_.end()) |
| 529 return image_iter->second; | 529 return image_iter->second; |
| 530 | 530 |
| 531 scoped_refptr<RefCountedMemory> memory; | 531 scoped_refptr<base::RefCountedMemory> memory; |
| 532 if (data_pack_.get()) { | 532 if (data_pack_.get()) { |
| 533 memory = data_pack_->GetStaticMemory(prs_id); | 533 memory = data_pack_->GetStaticMemory(prs_id); |
| 534 } else { | 534 } else { |
| 535 RawImages::const_iterator it = image_memory_.find(prs_id); | 535 RawImages::const_iterator it = image_memory_.find(prs_id); |
| 536 if (it != image_memory_.end()) { | 536 if (it != image_memory_.end()) { |
| 537 memory = it->second; | 537 memory = it->second; |
| 538 } | 538 } |
| 539 } | 539 } |
| 540 | 540 |
| 541 if (memory.get()) { | 541 if (memory.get()) { |
| 542 // Decode the PNG. | 542 // Decode the PNG. |
| 543 SkBitmap bitmap; | 543 SkBitmap bitmap; |
| 544 if (!gfx::PNGCodec::Decode(memory->front(), memory->size(), | 544 if (!gfx::PNGCodec::Decode(memory->front(), memory->size(), |
| 545 &bitmap)) { | 545 &bitmap)) { |
| 546 NOTREACHED() << "Unable to decode theme image resource " << idr_id | 546 NOTREACHED() << "Unable to decode theme image resource " << idr_id |
| 547 << " from saved DataPack."; | 547 << " from saved DataPack."; |
| 548 return NULL; | 548 return NULL; |
| 549 } | 549 } |
| 550 | 550 |
| 551 gfx::Image* ret = new gfx::Image(bitmap); | 551 gfx::Image* ret = new gfx::Image(bitmap); |
| 552 loaded_images_[prs_id] = ret; | 552 loaded_images_[prs_id] = ret; |
| 553 | 553 |
| 554 return ret; | 554 return ret; |
| 555 } | 555 } |
| 556 | 556 |
| 557 return NULL; | 557 return NULL; |
| 558 } | 558 } |
| 559 | 559 |
| 560 RefCountedMemory* BrowserThemePack::GetRawData(int idr_id) const { | 560 base::RefCountedMemory* BrowserThemePack::GetRawData(int idr_id) const { |
| 561 RefCountedMemory* memory = NULL; | 561 base::RefCountedMemory* memory = NULL; |
| 562 int prs_id = GetPersistentIDByIDR(idr_id); | 562 int prs_id = GetPersistentIDByIDR(idr_id); |
| 563 | 563 |
| 564 if (prs_id != -1) { | 564 if (prs_id != -1) { |
| 565 if (data_pack_.get()) { | 565 if (data_pack_.get()) { |
| 566 memory = data_pack_->GetStaticMemory(prs_id); | 566 memory = data_pack_->GetStaticMemory(prs_id); |
| 567 } else { | 567 } else { |
| 568 RawImages::const_iterator it = image_memory_.find(prs_id); | 568 RawImages::const_iterator it = image_memory_.find(prs_id); |
| 569 if (it != image_memory_.end()) { | 569 if (it != image_memory_.end()) { |
| 570 memory = it->second; | 570 memory = it->second; |
| 571 } | 571 } |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 | 863 |
| 864 bool BrowserThemePack::LoadRawBitmapsTo( | 864 bool BrowserThemePack::LoadRawBitmapsTo( |
| 865 const FilePathMap& file_paths, | 865 const FilePathMap& file_paths, |
| 866 ImageCache* raw_bitmaps) { | 866 ImageCache* raw_bitmaps) { |
| 867 // Themes should be loaded on the file thread, not the UI thread. | 867 // Themes should be loaded on the file thread, not the UI thread. |
| 868 // http://crbug.com/61838 | 868 // http://crbug.com/61838 |
| 869 base::ThreadRestrictions::ScopedAllowIO allow_io; | 869 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 870 | 870 |
| 871 for (FilePathMap::const_iterator it = file_paths.begin(); | 871 for (FilePathMap::const_iterator it = file_paths.begin(); |
| 872 it != file_paths.end(); ++it) { | 872 it != file_paths.end(); ++it) { |
| 873 scoped_refptr<RefCountedMemory> raw_data(ReadFileData(it->second)); | 873 scoped_refptr<base::RefCountedMemory> raw_data(ReadFileData(it->second)); |
| 874 if (!raw_data.get()) { | 874 if (!raw_data.get()) { |
| 875 LOG(ERROR) << "Could not load theme image"; | 875 LOG(ERROR) << "Could not load theme image"; |
| 876 return false; | 876 return false; |
| 877 } | 877 } |
| 878 | 878 |
| 879 int id = it->first; | 879 int id = it->first; |
| 880 | 880 |
| 881 // Some images need to go directly into |image_memory_|. No modification is | 881 // Some images need to go directly into |image_memory_|. No modification is |
| 882 // necessary or desirable. | 882 // necessary or desirable. |
| 883 bool is_copyable = false; | 883 bool is_copyable = false; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 hsl.h = tints_[i].h; | 1070 hsl.h = tints_[i].h; |
| 1071 hsl.s = tints_[i].s; | 1071 hsl.s = tints_[i].s; |
| 1072 hsl.l = tints_[i].l; | 1072 hsl.l = tints_[i].l; |
| 1073 return hsl; | 1073 return hsl; |
| 1074 } | 1074 } |
| 1075 } | 1075 } |
| 1076 } | 1076 } |
| 1077 | 1077 |
| 1078 return ThemeService::GetDefaultTint(id); | 1078 return ThemeService::GetDefaultTint(id); |
| 1079 } | 1079 } |
| OLD | NEW |