| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/big_endian.h" |
| 9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 11 #include "base/files/file.h" | 12 #include "base/files/file.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
| 14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 15 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 16 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 17 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
| 20 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 21 #include "grit/app_locale_settings.h" | 22 #include "grit/app_locale_settings.h" |
| 22 #include "net/base/big_endian.h" | |
| 23 #include "skia/ext/image_operations.h" | 23 #include "skia/ext/image_operations.h" |
| 24 #include "third_party/skia/include/core/SkBitmap.h" | 24 #include "third_party/skia/include/core/SkBitmap.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/base/layout.h" | 26 #include "ui/base/layout.h" |
| 27 #include "ui/base/resource/data_pack.h" | 27 #include "ui/base/resource/data_pack.h" |
| 28 #include "ui/base/ui_base_paths.h" | 28 #include "ui/base/ui_base_paths.h" |
| 29 #include "ui/base/ui_base_switches.h" | 29 #include "ui/base/ui_base_switches.h" |
| 30 #include "ui/gfx/codec/jpeg_codec.h" | 30 #include "ui/gfx/codec/jpeg_codec.h" |
| 31 #include "ui/gfx/codec/png_codec.h" | 31 #include "ui/gfx/codec/png_codec.h" |
| 32 #include "ui/gfx/image/image_skia.h" | 32 #include "ui/gfx/image/image_skia.h" |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 } | 757 } |
| 758 | 758 |
| 759 // static | 759 // static |
| 760 bool ResourceBundle::ShouldHighlightMissingScaledResources() { | 760 bool ResourceBundle::ShouldHighlightMissingScaledResources() { |
| 761 return CommandLine::ForCurrentProcess()->HasSwitch( | 761 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 762 switches::kHighlightMissingScaledResources); | 762 switches::kHighlightMissingScaledResources); |
| 763 } | 763 } |
| 764 | 764 |
| 765 // static | 765 // static |
| 766 bool ResourceBundle::PNGContainsFallbackMarker(const unsigned char* buf, | 766 bool ResourceBundle::PNGContainsFallbackMarker(const unsigned char* buf, |
| 767 size_t size) { | 767 size_t size) { |
| 768 if (size < arraysize(kPngMagic) || | 768 if (size < arraysize(kPngMagic) || |
| 769 memcmp(buf, kPngMagic, arraysize(kPngMagic)) != 0) { | 769 memcmp(buf, kPngMagic, arraysize(kPngMagic)) != 0) { |
| 770 // Data invalid or a JPEG. | 770 // Data invalid or a JPEG. |
| 771 return false; | 771 return false; |
| 772 } | 772 } |
| 773 size_t pos = arraysize(kPngMagic); | 773 size_t pos = arraysize(kPngMagic); |
| 774 | 774 |
| 775 // Scan for custom chunks until we find one, find the IDAT chunk, or run out | 775 // Scan for custom chunks until we find one, find the IDAT chunk, or run out |
| 776 // of chunks. | 776 // of chunks. |
| 777 for (;;) { | 777 for (;;) { |
| 778 if (size - pos < kPngChunkMetadataSize) | 778 if (size - pos < kPngChunkMetadataSize) |
| 779 break; | 779 break; |
| 780 uint32 length = 0; | 780 uint32 length = 0; |
| 781 net::ReadBigEndian(reinterpret_cast<const char*>(buf + pos), &length); | 781 base::ReadBigEndian(reinterpret_cast<const char*>(buf + pos), &length); |
| 782 if (size - pos - kPngChunkMetadataSize < length) | 782 if (size - pos - kPngChunkMetadataSize < length) |
| 783 break; | 783 break; |
| 784 if (length == 0 && memcmp(buf + pos + sizeof(uint32), kPngScaleChunkType, | 784 if (length == 0 && memcmp(buf + pos + sizeof(uint32), kPngScaleChunkType, |
| 785 arraysize(kPngScaleChunkType)) == 0) { | 785 arraysize(kPngScaleChunkType)) == 0) { |
| 786 return true; | 786 return true; |
| 787 } | 787 } |
| 788 if (memcmp(buf + pos + sizeof(uint32), kPngDataChunkType, | 788 if (memcmp(buf + pos + sizeof(uint32), kPngDataChunkType, |
| 789 arraysize(kPngDataChunkType)) == 0) { | 789 arraysize(kPngDataChunkType)) == 0) { |
| 790 // Stop looking for custom chunks, any custom chunks should be before an | 790 // Stop looking for custom chunks, any custom chunks should be before an |
| 791 // IDAT chunk. | 791 // IDAT chunk. |
| 792 break; | 792 break; |
| 793 } | 793 } |
| 794 pos += length + kPngChunkMetadataSize; | 794 pos += length + kPngChunkMetadataSize; |
| 795 } | 795 } |
| 796 return false; | 796 return false; |
| 797 } | 797 } |
| 798 | 798 |
| 799 // static | 799 // static |
| 800 bool ResourceBundle::DecodePNG(const unsigned char* buf, | 800 bool ResourceBundle::DecodePNG(const unsigned char* buf, |
| 801 size_t size, | 801 size_t size, |
| 802 SkBitmap* bitmap, | 802 SkBitmap* bitmap, |
| 803 bool* fell_back_to_1x) { | 803 bool* fell_back_to_1x) { |
| 804 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); | 804 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); |
| 805 return gfx::PNGCodec::Decode(buf, size, bitmap); | 805 return gfx::PNGCodec::Decode(buf, size, bitmap); |
| 806 } | 806 } |
| 807 | 807 |
| 808 } // namespace ui | 808 } // namespace ui |
| OLD | NEW |