Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: ui/base/resource/resource_bundle.cc

Issue 145873006: ui/base/resource: Roll our own version of ReadBigEndian() function. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix for gcp20_device Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/logging.h" 12 #include "base/logging.h"
12 #include "base/memory/ref_counted_memory.h" 13 #include "base/memory/ref_counted_memory.h"
13 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
14 #include "base/path_service.h" 15 #include "base/path_service.h"
15 #include "base/stl_util.h" 16 #include "base/stl_util.h"
16 #include "base/strings/string_piece.h" 17 #include "base/strings/string_piece.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
18 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
19 #include "build/build_config.h" 20 #include "build/build_config.h"
20 #include "grit/app_locale_settings.h" 21 #include "grit/app_locale_settings.h"
21 #include "net/base/big_endian.h"
22 #include "skia/ext/image_operations.h" 22 #include "skia/ext/image_operations.h"
23 #include "third_party/skia/include/core/SkBitmap.h" 23 #include "third_party/skia/include/core/SkBitmap.h"
24 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/layout.h" 25 #include "ui/base/layout.h"
26 #include "ui/base/resource/data_pack.h" 26 #include "ui/base/resource/data_pack.h"
27 #include "ui/base/ui_base_paths.h" 27 #include "ui/base/ui_base_paths.h"
28 #include "ui/base/ui_base_switches.h" 28 #include "ui/base/ui_base_switches.h"
29 #include "ui/gfx/codec/jpeg_codec.h" 29 #include "ui/gfx/codec/jpeg_codec.h"
30 #include "ui/gfx/codec/png_codec.h" 30 #include "ui/gfx/codec/png_codec.h"
31 #include "ui/gfx/image/image_skia.h" 31 #include "ui/gfx/image/image_skia.h"
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 } 756 }
757 757
758 // static 758 // static
759 bool ResourceBundle::ShouldHighlightMissingScaledResources() { 759 bool ResourceBundle::ShouldHighlightMissingScaledResources() {
760 return CommandLine::ForCurrentProcess()->HasSwitch( 760 return CommandLine::ForCurrentProcess()->HasSwitch(
761 switches::kHighlightMissingScaledResources); 761 switches::kHighlightMissingScaledResources);
762 } 762 }
763 763
764 // static 764 // static
765 bool ResourceBundle::PNGContainsFallbackMarker(const unsigned char* buf, 765 bool ResourceBundle::PNGContainsFallbackMarker(const unsigned char* buf,
766 size_t size) { 766 size_t size) {
767 if (size < arraysize(kPngMagic) || 767 if (size < arraysize(kPngMagic) ||
768 memcmp(buf, kPngMagic, arraysize(kPngMagic)) != 0) { 768 memcmp(buf, kPngMagic, arraysize(kPngMagic)) != 0) {
769 // Data invalid or a JPEG. 769 // Data invalid or a JPEG.
770 return false; 770 return false;
771 } 771 }
772 size_t pos = arraysize(kPngMagic); 772 size_t pos = arraysize(kPngMagic);
773 773
774 // Scan for custom chunks until we find one, find the IDAT chunk, or run out 774 // Scan for custom chunks until we find one, find the IDAT chunk, or run out
775 // of chunks. 775 // of chunks.
776 for (;;) { 776 for (;;) {
777 if (size - pos < kPngChunkMetadataSize) 777 if (size - pos < kPngChunkMetadataSize)
778 break; 778 break;
779 uint32 length = 0; 779 uint32 length = 0;
780 net::ReadBigEndian(reinterpret_cast<const char*>(buf + pos), &length); 780 base::ReadBigEndian(reinterpret_cast<const char*>(buf + pos), &length);
781 if (size - pos - kPngChunkMetadataSize < length) 781 if (size - pos - kPngChunkMetadataSize < length)
782 break; 782 break;
783 if (length == 0 && memcmp(buf + pos + sizeof(uint32), kPngScaleChunkType, 783 if (length == 0 && memcmp(buf + pos + sizeof(uint32), kPngScaleChunkType,
784 arraysize(kPngScaleChunkType)) == 0) { 784 arraysize(kPngScaleChunkType)) == 0) {
785 return true; 785 return true;
786 } 786 }
787 if (memcmp(buf + pos + sizeof(uint32), kPngDataChunkType, 787 if (memcmp(buf + pos + sizeof(uint32), kPngDataChunkType,
788 arraysize(kPngDataChunkType)) == 0) { 788 arraysize(kPngDataChunkType)) == 0) {
789 // Stop looking for custom chunks, any custom chunks should be before an 789 // Stop looking for custom chunks, any custom chunks should be before an
790 // IDAT chunk. 790 // IDAT chunk.
791 break; 791 break;
792 } 792 }
793 pos += length + kPngChunkMetadataSize; 793 pos += length + kPngChunkMetadataSize;
794 } 794 }
795 return false; 795 return false;
796 } 796 }
797 797
798 // static 798 // static
799 bool ResourceBundle::DecodePNG(const unsigned char* buf, 799 bool ResourceBundle::DecodePNG(const unsigned char* buf,
800 size_t size, 800 size_t size,
801 SkBitmap* bitmap, 801 SkBitmap* bitmap,
802 bool* fell_back_to_1x) { 802 bool* fell_back_to_1x) {
803 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); 803 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size);
804 return gfx::PNGCodec::Decode(buf, size, bitmap); 804 return gfx::PNGCodec::Decode(buf, size, bitmap);
805 } 805 }
806 806
807 } // namespace ui 807 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698