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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 if (locale_file_path.empty() || !locale_file_path.IsAbsolute()) | 258 if (locale_file_path.empty() || !locale_file_path.IsAbsolute()) |
259 return base::FilePath(); | 259 return base::FilePath(); |
260 | 260 |
261 if (test_file_exists && !base::PathExists(locale_file_path)) | 261 if (test_file_exists && !base::PathExists(locale_file_path)) |
262 return base::FilePath(); | 262 return base::FilePath(); |
263 | 263 |
264 return locale_file_path; | 264 return locale_file_path; |
265 } | 265 } |
266 #endif | 266 #endif |
267 | 267 |
| 268 #if !defined(OS_ANDROID) |
268 std::string ResourceBundle::LoadLocaleResources( | 269 std::string ResourceBundle::LoadLocaleResources( |
269 const std::string& pref_locale) { | 270 const std::string& pref_locale) { |
270 DCHECK(!locale_resources_data_.get()) << "locale.pak already loaded"; | 271 DCHECK(!locale_resources_data_.get()) << "locale.pak already loaded"; |
271 std::string app_locale = l10n_util::GetApplicationLocale(pref_locale); | 272 std::string app_locale = l10n_util::GetApplicationLocale(pref_locale); |
272 base::FilePath locale_file_path = GetOverriddenPakPath(); | 273 base::FilePath locale_file_path = GetOverriddenPakPath(); |
273 if (locale_file_path.empty()) | 274 if (locale_file_path.empty()) |
274 locale_file_path = GetLocaleFilePath(app_locale, true); | 275 locale_file_path = GetLocaleFilePath(app_locale, true); |
275 | 276 |
276 if (locale_file_path.empty()) { | 277 if (locale_file_path.empty()) { |
277 // It's possible that there is no locale.pak. | 278 // It's possible that there is no locale.pak. |
278 LOG(WARNING) << "locale_file_path.empty()"; | 279 LOG(WARNING) << "locale_file_path.empty() for locale " << app_locale; |
279 return std::string(); | 280 return std::string(); |
280 } | 281 } |
281 | 282 |
282 scoped_ptr<DataPack> data_pack( | 283 scoped_ptr<DataPack> data_pack( |
283 new DataPack(SCALE_FACTOR_100P)); | 284 new DataPack(SCALE_FACTOR_100P)); |
284 if (!data_pack->LoadFromPath(locale_file_path)) { | 285 if (!data_pack->LoadFromPath(locale_file_path)) { |
285 UMA_HISTOGRAM_ENUMERATION("ResourceBundle.LoadLocaleResourcesError", | 286 UMA_HISTOGRAM_ENUMERATION("ResourceBundle.LoadLocaleResourcesError", |
286 logging::GetLastSystemErrorCode(), 16000); | 287 logging::GetLastSystemErrorCode(), 16000); |
287 LOG(ERROR) << "failed to load locale.pak"; | 288 LOG(ERROR) << "failed to load locale.pak"; |
288 NOTREACHED(); | 289 NOTREACHED(); |
289 return std::string(); | 290 return std::string(); |
290 } | 291 } |
291 | 292 |
292 locale_resources_data_.reset(data_pack.release()); | 293 locale_resources_data_.reset(data_pack.release()); |
293 return app_locale; | 294 return app_locale; |
294 } | 295 } |
| 296 #endif // defined(OS_ANDROID) |
295 | 297 |
296 void ResourceBundle::LoadTestResources(const base::FilePath& path, | 298 void ResourceBundle::LoadTestResources(const base::FilePath& path, |
297 const base::FilePath& locale_path) { | 299 const base::FilePath& locale_path) { |
298 DCHECK(!ui::GetSupportedScaleFactors().empty()); | 300 DCHECK(!ui::GetSupportedScaleFactors().empty()); |
299 const ScaleFactor scale_factor(ui::GetSupportedScaleFactors()[0]); | 301 const ScaleFactor scale_factor(ui::GetSupportedScaleFactors()[0]); |
300 // Use the given resource pak for both common and localized resources. | 302 // Use the given resource pak for both common and localized resources. |
301 scoped_ptr<DataPack> data_pack(new DataPack(scale_factor)); | 303 scoped_ptr<DataPack> data_pack(new DataPack(scale_factor)); |
302 if (!path.empty() && data_pack->LoadFromPath(path)) | 304 if (!path.empty() && data_pack->LoadFromPath(path)) |
303 AddDataPack(data_pack.release()); | 305 AddDataPack(data_pack.release()); |
304 | 306 |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 // static | 852 // static |
851 bool ResourceBundle::DecodePNG(const unsigned char* buf, | 853 bool ResourceBundle::DecodePNG(const unsigned char* buf, |
852 size_t size, | 854 size_t size, |
853 SkBitmap* bitmap, | 855 SkBitmap* bitmap, |
854 bool* fell_back_to_1x) { | 856 bool* fell_back_to_1x) { |
855 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); | 857 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); |
856 return gfx::PNGCodec::Decode(buf, size, bitmap); | 858 return gfx::PNGCodec::Decode(buf, size, bitmap); |
857 } | 859 } |
858 | 860 |
859 } // namespace ui | 861 } // namespace ui |
OLD | NEW |