| 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 "ui/base/resource/resource_bundle.h" | 5 #include "ui/base/resource/resource_bundle.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/big_endian.h" | 10 #include "base/big_endian.h" |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 void ResourceBundle::AddDataPackFromFile(base::File file, | 243 void ResourceBundle::AddDataPackFromFile(base::File file, |
| 244 ScaleFactor scale_factor) { | 244 ScaleFactor scale_factor) { |
| 245 AddDataPackFromFileRegion( | 245 AddDataPackFromFileRegion( |
| 246 file.Pass(), base::MemoryMappedFile::Region::kWholeFile, scale_factor); | 246 file.Pass(), base::MemoryMappedFile::Region::kWholeFile, scale_factor); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void ResourceBundle::AddDataPackFromFileRegion( | 249 void ResourceBundle::AddDataPackFromFileRegion( |
| 250 base::File file, | 250 base::File file, |
| 251 const base::MemoryMappedFile::Region& region, | 251 const base::MemoryMappedFile::Region& region, |
| 252 ScaleFactor scale_factor) { | 252 ScaleFactor scale_factor) { |
| 253 scoped_ptr<DataPack> data_pack( | 253 scoped_ptr<DataPack> data_pack(new DataPack(scale_factor)); |
| 254 new DataPack(scale_factor)); | |
| 255 if (data_pack->LoadFromFileRegion(file.Pass(), region)) { | 254 if (data_pack->LoadFromFileRegion(file.Pass(), region)) { |
| 256 AddDataPack(data_pack.release()); | 255 AddDataPack(data_pack.release()); |
| 257 } else { | 256 } else { |
| 258 LOG(ERROR) << "Failed to load data pack from file." | 257 LOG(ERROR) << "Failed to load data pack from file." |
| 259 << "\nSome features may not be available."; | 258 << "\nSome features may not be available."; |
| 260 } | 259 } |
| 261 } | 260 } |
| 262 | 261 |
| 263 #if !defined(OS_MACOSX) | 262 #if !defined(OS_MACOSX) |
| 264 base::FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale, | 263 base::FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 base::FilePath locale_file_path = GetOverriddenPakPath(); | 297 base::FilePath locale_file_path = GetOverriddenPakPath(); |
| 299 if (locale_file_path.empty()) | 298 if (locale_file_path.empty()) |
| 300 locale_file_path = GetLocaleFilePath(app_locale, true); | 299 locale_file_path = GetLocaleFilePath(app_locale, true); |
| 301 | 300 |
| 302 if (locale_file_path.empty()) { | 301 if (locale_file_path.empty()) { |
| 303 // It's possible that there is no locale.pak. | 302 // It's possible that there is no locale.pak. |
| 304 LOG(WARNING) << "locale_file_path.empty()"; | 303 LOG(WARNING) << "locale_file_path.empty()"; |
| 305 return std::string(); | 304 return std::string(); |
| 306 } | 305 } |
| 307 | 306 |
| 308 scoped_ptr<DataPack> data_pack( | 307 scoped_ptr<DataPack> data_pack(new DataPack(SCALE_FACTOR_100P)); |
| 309 new DataPack(SCALE_FACTOR_100P)); | |
| 310 if (!data_pack->LoadFromPath(locale_file_path)) { | 308 if (!data_pack->LoadFromPath(locale_file_path)) { |
| 311 UMA_HISTOGRAM_ENUMERATION("ResourceBundle.LoadLocaleResourcesError", | 309 UMA_HISTOGRAM_ENUMERATION("ResourceBundle.LoadLocaleResourcesError", |
| 312 logging::GetLastSystemErrorCode(), 16000); | 310 logging::GetLastSystemErrorCode(), 16000); |
| 313 LOG(ERROR) << "failed to load locale.pak"; | 311 LOG(ERROR) << "failed to load locale.pak"; |
| 314 NOTREACHED(); | 312 NOTREACHED(); |
| 315 return std::string(); | 313 return std::string(); |
| 316 } | 314 } |
| 317 | 315 |
| 318 locale_resources_data_.reset(data_pack.release()); | 316 locale_resources_data_.reset(data_pack.release()); |
| 319 return app_locale; | 317 return app_locale; |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 ScaleFactor scale_factor, | 656 ScaleFactor scale_factor, |
| 659 bool optional) { | 657 bool optional) { |
| 660 // Do not pass an empty |path| value to this method. If the absolute path is | 658 // Do not pass an empty |path| value to this method. If the absolute path is |
| 661 // unknown pass just the pack file name. | 659 // unknown pass just the pack file name. |
| 662 DCHECK(!path.empty()); | 660 DCHECK(!path.empty()); |
| 663 | 661 |
| 664 base::FilePath pack_path = path; | 662 base::FilePath pack_path = path; |
| 665 if (delegate_) | 663 if (delegate_) |
| 666 pack_path = delegate_->GetPathForResourcePack(pack_path, scale_factor); | 664 pack_path = delegate_->GetPathForResourcePack(pack_path, scale_factor); |
| 667 | 665 |
| 668 // Don't try to load empty values or values that are not absolute paths. | 666 // An empty path is a request from the delegate to cancel loading. |
| 669 if (pack_path.empty() || !pack_path.IsAbsolute()) | 667 if (pack_path.empty()) |
| 670 return; | 668 return; |
| 671 | 669 |
| 672 scoped_ptr<DataPack> data_pack( | 670 scoped_ptr<DataPack> data_pack(new DataPack(scale_factor)); |
| 673 new DataPack(scale_factor)); | |
| 674 if (data_pack->LoadFromPath(pack_path)) { | 671 if (data_pack->LoadFromPath(pack_path)) { |
| 675 AddDataPack(data_pack.release()); | 672 AddDataPack(data_pack.release()); |
| 676 } else if (!optional) { | 673 } else if (!optional) { |
| 677 LOG(ERROR) << "Failed to load " << pack_path.value() | 674 DLOG(FATAL) << "Failed to load " << pack_path.value(); |
| 678 << "\nSome features may not be available."; | |
| 679 } | 675 } |
| 680 } | 676 } |
| 681 | 677 |
| 682 void ResourceBundle::AddDataPack(DataPack* data_pack) { | 678 void ResourceBundle::AddDataPack(DataPack* data_pack) { |
| 683 data_packs_.push_back(data_pack); | 679 data_packs_.push_back(data_pack); |
| 684 | 680 |
| 685 if (GetScaleForScaleFactor(data_pack->GetScaleFactor()) > | 681 if (GetScaleForScaleFactor(data_pack->GetScaleFactor()) > |
| 686 GetScaleForScaleFactor(max_scale_factor_)) | 682 GetScaleForScaleFactor(max_scale_factor_)) |
| 687 max_scale_factor_ = data_pack->GetScaleFactor(); | 683 max_scale_factor_ = data_pack->GetScaleFactor(); |
| 688 } | 684 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 // static | 852 // static |
| 857 bool ResourceBundle::DecodePNG(const unsigned char* buf, | 853 bool ResourceBundle::DecodePNG(const unsigned char* buf, |
| 858 size_t size, | 854 size_t size, |
| 859 SkBitmap* bitmap, | 855 SkBitmap* bitmap, |
| 860 bool* fell_back_to_1x) { | 856 bool* fell_back_to_1x) { |
| 861 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); | 857 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); |
| 862 return gfx::PNGCodec::Decode(buf, size, bitmap); | 858 return gfx::PNGCodec::Decode(buf, size, bitmap); |
| 863 } | 859 } |
| 864 | 860 |
| 865 } // namespace ui | 861 } // namespace ui |
| OLD | NEW |