Chromium Code Reviews| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 #include "ui/display/screen.h" | 37 #include "ui/display/screen.h" |
| 38 #include "ui/gfx/codec/jpeg_codec.h" | 38 #include "ui/gfx/codec/jpeg_codec.h" |
| 39 #include "ui/gfx/codec/png_codec.h" | 39 #include "ui/gfx/codec/png_codec.h" |
| 40 #include "ui/gfx/geometry/safe_integer_conversions.h" | 40 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 41 #include "ui/gfx/geometry/size_conversions.h" | 41 #include "ui/gfx/geometry/size_conversions.h" |
| 42 #include "ui/gfx/image/image_skia.h" | 42 #include "ui/gfx/image/image_skia.h" |
| 43 #include "ui/gfx/image/image_skia_source.h" | 43 #include "ui/gfx/image/image_skia_source.h" |
| 44 #include "ui/strings/grit/app_locale_settings.h" | 44 #include "ui/strings/grit/app_locale_settings.h" |
| 45 | 45 |
| 46 #if defined(OS_ANDROID) | 46 #if defined(OS_ANDROID) |
| 47 #include "base/android/build_info.h" | |
| 47 #include "ui/base/resource/resource_bundle_android.h" | 48 #include "ui/base/resource/resource_bundle_android.h" |
| 48 #endif | 49 #endif |
| 49 | 50 |
| 50 #if defined(OS_CHROMEOS) | 51 #if defined(OS_CHROMEOS) |
| 51 #include "ui/gfx/platform_font_linux.h" | 52 #include "ui/gfx/platform_font_linux.h" |
| 52 #endif | 53 #endif |
| 53 | 54 |
| 54 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
| 55 #include "ui/display/win/dpi.h" | 56 #include "ui/display/win/dpi.h" |
| 56 #endif | 57 #endif |
| 57 | 58 |
| 58 namespace ui { | 59 namespace ui { |
| 59 | 60 |
| 60 namespace { | 61 namespace { |
| 61 | 62 |
| 62 // PNG-related constants. | 63 // PNG-related constants. |
| 63 const unsigned char kPngMagic[8] = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 }; | 64 const unsigned char kPngMagic[8] = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 }; |
| 64 const size_t kPngChunkMetadataSize = 12; // length, type, crc32 | 65 const size_t kPngChunkMetadataSize = 12; // length, type, crc32 |
| 65 const unsigned char kPngScaleChunkType[4] = { 'c', 's', 'C', 'l' }; | 66 const unsigned char kPngScaleChunkType[4] = { 'c', 's', 'C', 'l' }; |
| 66 const unsigned char kPngDataChunkType[4] = { 'I', 'D', 'A', 'T' }; | 67 const unsigned char kPngDataChunkType[4] = { 'I', 'D', 'A', 'T' }; |
| 67 | 68 |
| 68 #if !defined(OS_MACOSX) | 69 #if !defined(OS_MACOSX) |
| 69 const char kPakFileSuffix[] = ".pak"; | 70 const char kPakFileExtension[] = ".pak"; |
| 70 #endif | 71 #endif |
| 71 | 72 |
| 72 ResourceBundle* g_shared_instance_ = NULL; | 73 ResourceBundle* g_shared_instance_ = NULL; |
| 73 | 74 |
| 74 #if defined(OS_ANDROID) | 75 #if defined(OS_ANDROID) |
| 75 // Returns the scale factor closest to |scale| from the full list of factors. | 76 // Returns the scale factor closest to |scale| from the full list of factors. |
| 76 // Note that it does NOT rely on the list of supported scale factors. | 77 // Note that it does NOT rely on the list of supported scale factors. |
| 77 // Finding the closest match is inefficient and shouldn't be done frequently. | 78 // Finding the closest match is inefficient and shouldn't be done frequently. |
| 78 ScaleFactor FindClosestScaleFactorUnsafe(float scale) { | 79 ScaleFactor FindClosestScaleFactorUnsafe(float scale) { |
| 79 float smallest_diff = std::numeric_limits<float>::max(); | 80 float smallest_diff = std::numeric_limits<float>::max(); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 base::FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale, | 298 base::FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale, |
| 298 bool test_file_exists) { | 299 bool test_file_exists) { |
| 299 if (app_locale.empty()) | 300 if (app_locale.empty()) |
| 300 return base::FilePath(); | 301 return base::FilePath(); |
| 301 | 302 |
| 302 base::FilePath locale_file_path; | 303 base::FilePath locale_file_path; |
| 303 | 304 |
| 304 PathService::Get(ui::DIR_LOCALES, &locale_file_path); | 305 PathService::Get(ui::DIR_LOCALES, &locale_file_path); |
| 305 | 306 |
| 306 if (!locale_file_path.empty()) { | 307 if (!locale_file_path.empty()) { |
| 308 #if defined(OS_ANDROID) | |
| 309 if (locale_file_path.value().find("chromium_tests") == std::string::npos) { | |
|
agrieve
2017/04/20 15:54:38
Note: Although ugly, it's actually already the cas
| |
| 310 std::string extracted_file_suffix = | |
| 311 base::android::BuildInfo::GetInstance()->extracted_file_suffix(); | |
| 312 locale_file_path = locale_file_path.AppendASCII( | |
| 313 app_locale + kPakFileExtension + extracted_file_suffix); | |
| 314 } else { | |
| 315 // TODO(agrieve): Update tests to not side-load pak files and remove | |
| 316 // this special-case. https://crbug.com/691719 | |
| 317 locale_file_path = | |
| 318 locale_file_path.AppendASCII(app_locale + kPakFileExtension); | |
| 319 } | |
| 320 #else | |
| 307 locale_file_path = | 321 locale_file_path = |
| 308 locale_file_path.AppendASCII(app_locale + kPakFileSuffix); | 322 locale_file_path.AppendASCII(app_locale + kPakFileExtension); |
| 323 #endif | |
| 309 } | 324 } |
| 310 | 325 |
| 311 if (delegate_) { | 326 if (delegate_) { |
| 312 locale_file_path = | 327 locale_file_path = |
| 313 delegate_->GetPathForLocalePack(locale_file_path, app_locale); | 328 delegate_->GetPathForLocalePack(locale_file_path, app_locale); |
| 314 } | 329 } |
| 315 | 330 |
| 316 // Don't try to load empty values or values that are not absolute paths. | 331 // Don't try to load empty values or values that are not absolute paths. |
| 317 if (locale_file_path.empty() || !locale_file_path.IsAbsolute()) | 332 if (locale_file_path.empty() || !locale_file_path.IsAbsolute()) |
| 318 return base::FilePath(); | 333 return base::FilePath(); |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 909 // static | 924 // static |
| 910 bool ResourceBundle::DecodePNG(const unsigned char* buf, | 925 bool ResourceBundle::DecodePNG(const unsigned char* buf, |
| 911 size_t size, | 926 size_t size, |
| 912 SkBitmap* bitmap, | 927 SkBitmap* bitmap, |
| 913 bool* fell_back_to_1x) { | 928 bool* fell_back_to_1x) { |
| 914 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); | 929 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); |
| 915 return gfx::PNGCodec::Decode(buf, size, bitmap); | 930 return gfx::PNGCodec::Decode(buf, size, bitmap); |
| 916 } | 931 } |
| 917 | 932 |
| 918 } // namespace ui | 933 } // namespace ui |
| OLD | NEW |