| 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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 int resource_id, | 455 int resource_id, |
| 456 ScaleFactor scale_factor) const { | 456 ScaleFactor scale_factor) const { |
| 457 base::StringPiece data; | 457 base::StringPiece data; |
| 458 if (delegate_ && | 458 if (delegate_ && |
| 459 delegate_->GetRawDataResource(resource_id, scale_factor, &data)) | 459 delegate_->GetRawDataResource(resource_id, scale_factor, &data)) |
| 460 return data; | 460 return data; |
| 461 | 461 |
| 462 if (scale_factor != ui::SCALE_FACTOR_100P) { | 462 if (scale_factor != ui::SCALE_FACTOR_100P) { |
| 463 for (size_t i = 0; i < data_packs_.size(); i++) { | 463 for (size_t i = 0; i < data_packs_.size(); i++) { |
| 464 if (data_packs_[i]->GetScaleFactor() == scale_factor && | 464 if (data_packs_[i]->GetScaleFactor() == scale_factor && |
| 465 data_packs_[i]->GetStringPiece(resource_id, &data)) | 465 data_packs_[i]->GetStringPiece(static_cast<uint16>(resource_id), |
| 466 &data)) |
| 466 return data; | 467 return data; |
| 467 } | 468 } |
| 468 } | 469 } |
| 469 for (size_t i = 0; i < data_packs_.size(); i++) { | 470 for (size_t i = 0; i < data_packs_.size(); i++) { |
| 470 if ((data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_100P || | 471 if ((data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_100P || |
| 471 data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_200P || | 472 data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_200P || |
| 472 data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_NONE) && | 473 data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_NONE) && |
| 473 data_packs_[i]->GetStringPiece(resource_id, &data)) | 474 data_packs_[i]->GetStringPiece(static_cast<uint16>(resource_id), |
| 475 &data)) |
| 474 return data; | 476 return data; |
| 475 } | 477 } |
| 476 | 478 |
| 477 return base::StringPiece(); | 479 return base::StringPiece(); |
| 478 } | 480 } |
| 479 | 481 |
| 480 base::string16 ResourceBundle::GetLocalizedString(int message_id) { | 482 base::string16 ResourceBundle::GetLocalizedString(int message_id) { |
| 481 base::string16 string; | 483 base::string16 string; |
| 482 if (delegate_ && delegate_->GetLocalizedString(message_id, &string)) | 484 if (delegate_ && delegate_->GetLocalizedString(message_id, &string)) |
| 483 return string; | 485 return string; |
| 484 | 486 |
| 485 // Ensure that ReloadLocaleResources() doesn't drop the resources while | 487 // Ensure that ReloadLocaleResources() doesn't drop the resources while |
| 486 // we're using them. | 488 // we're using them. |
| 487 base::AutoLock lock_scope(*locale_resources_data_lock_); | 489 base::AutoLock lock_scope(*locale_resources_data_lock_); |
| 488 | 490 |
| 489 IdToStringMap::const_iterator it = | 491 IdToStringMap::const_iterator it = |
| 490 overridden_locale_strings_.find(message_id); | 492 overridden_locale_strings_.find(message_id); |
| 491 if (it != overridden_locale_strings_.end()) | 493 if (it != overridden_locale_strings_.end()) |
| 492 return it->second; | 494 return it->second; |
| 493 | 495 |
| 494 // If for some reason we were unable to load the resources , return an empty | 496 // If for some reason we were unable to load the resources , return an empty |
| 495 // string (better than crashing). | 497 // string (better than crashing). |
| 496 if (!locale_resources_data_.get()) { | 498 if (!locale_resources_data_.get()) { |
| 497 LOG(WARNING) << "locale resources are not loaded"; | 499 LOG(WARNING) << "locale resources are not loaded"; |
| 498 return base::string16(); | 500 return base::string16(); |
| 499 } | 501 } |
| 500 | 502 |
| 501 base::StringPiece data; | 503 base::StringPiece data; |
| 502 if (!locale_resources_data_->GetStringPiece(message_id, &data)) { | 504 if (!locale_resources_data_->GetStringPiece(static_cast<uint16>(message_id), |
| 505 &data)) { |
| 503 // Fall back on the main data pack (shouldn't be any strings here except in | 506 // Fall back on the main data pack (shouldn't be any strings here except in |
| 504 // unittests). | 507 // unittests). |
| 505 data = GetRawDataResource(message_id); | 508 data = GetRawDataResource(message_id); |
| 506 if (data.empty()) { | 509 if (data.empty()) { |
| 507 NOTREACHED() << "unable to find resource: " << message_id; | 510 NOTREACHED() << "unable to find resource: " << message_id; |
| 508 return base::string16(); | 511 return base::string16(); |
| 509 } | 512 } |
| 510 } | 513 } |
| 511 | 514 |
| 512 // Strings should not be loaded from a data pack that contains binary data. | 515 // Strings should not be loaded from a data pack that contains binary data. |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 return scoped_ptr<gfx::FontList>(new gfx::FontList(*font)); | 759 return scoped_ptr<gfx::FontList>(new gfx::FontList(*font)); |
| 757 return scoped_ptr<gfx::FontList>(); | 760 return scoped_ptr<gfx::FontList>(); |
| 758 } | 761 } |
| 759 | 762 |
| 760 bool ResourceBundle::LoadBitmap(const ResourceHandle& data_handle, | 763 bool ResourceBundle::LoadBitmap(const ResourceHandle& data_handle, |
| 761 int resource_id, | 764 int resource_id, |
| 762 SkBitmap* bitmap, | 765 SkBitmap* bitmap, |
| 763 bool* fell_back_to_1x) const { | 766 bool* fell_back_to_1x) const { |
| 764 DCHECK(fell_back_to_1x); | 767 DCHECK(fell_back_to_1x); |
| 765 scoped_refptr<base::RefCountedMemory> memory( | 768 scoped_refptr<base::RefCountedMemory> memory( |
| 766 data_handle.GetStaticMemory(resource_id)); | 769 data_handle.GetStaticMemory(static_cast<uint16>(resource_id))); |
| 767 if (!memory.get()) | 770 if (!memory.get()) |
| 768 return false; | 771 return false; |
| 769 | 772 |
| 770 if (DecodePNG(memory->front(), memory->size(), bitmap, fell_back_to_1x)) | 773 if (DecodePNG(memory->front(), memory->size(), bitmap, fell_back_to_1x)) |
| 771 return true; | 774 return true; |
| 772 | 775 |
| 773 #if !defined(OS_IOS) | 776 #if !defined(OS_IOS) |
| 774 // iOS does not compile or use the JPEG codec. On other platforms, | 777 // iOS does not compile or use the JPEG codec. On other platforms, |
| 775 // 99% of our assets are PNGs, however fallback to JPEG. | 778 // 99% of our assets are PNGs, however fallback to JPEG. |
| 776 scoped_ptr<SkBitmap> jpeg_bitmap( | 779 scoped_ptr<SkBitmap> jpeg_bitmap( |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 // static | 859 // static |
| 857 bool ResourceBundle::DecodePNG(const unsigned char* buf, | 860 bool ResourceBundle::DecodePNG(const unsigned char* buf, |
| 858 size_t size, | 861 size_t size, |
| 859 SkBitmap* bitmap, | 862 SkBitmap* bitmap, |
| 860 bool* fell_back_to_1x) { | 863 bool* fell_back_to_1x) { |
| 861 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); | 864 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); |
| 862 return gfx::PNGCodec::Decode(buf, size, bitmap); | 865 return gfx::PNGCodec::Decode(buf, size, bitmap); |
| 863 } | 866 } |
| 864 | 867 |
| 865 } // namespace ui | 868 } // namespace ui |
| OLD | NEW |