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