| 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 200 |
| 201 // static | 201 // static |
| 202 void ResourceBundle::InitSharedInstanceWithPakPath(const base::FilePath& path) { | 202 void ResourceBundle::InitSharedInstanceWithPakPath(const base::FilePath& path) { |
| 203 InitSharedInstance(NULL); | 203 InitSharedInstance(NULL); |
| 204 g_shared_instance_->LoadTestResources(path, path); | 204 g_shared_instance_->LoadTestResources(path, path); |
| 205 | 205 |
| 206 g_shared_instance_->InitDefaultFontList(); | 206 g_shared_instance_->InitDefaultFontList(); |
| 207 } | 207 } |
| 208 | 208 |
| 209 // static | 209 // static |
| 210 void ResourceBundle::InitSharedInstanceWithPakBuffer(base::StringPiece buffer) { |
| 211 InitSharedInstance(NULL); |
| 212 g_shared_instance_->LoadTestResourcesFromBuffer(buffer, buffer); |
| 213 |
| 214 g_shared_instance_->InitDefaultFontList(); |
| 215 } |
| 216 |
| 217 // static |
| 210 void ResourceBundle::CleanupSharedInstance() { | 218 void ResourceBundle::CleanupSharedInstance() { |
| 211 if (g_shared_instance_) { | 219 if (g_shared_instance_) { |
| 212 delete g_shared_instance_; | 220 delete g_shared_instance_; |
| 213 g_shared_instance_ = NULL; | 221 g_shared_instance_ = NULL; |
| 214 } | 222 } |
| 215 } | 223 } |
| 216 | 224 |
| 217 // static | 225 // static |
| 218 bool ResourceBundle::HasSharedInstance() { | 226 bool ResourceBundle::HasSharedInstance() { |
| 219 return g_shared_instance_ != NULL; | 227 return g_shared_instance_ != NULL; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 AddDataPack(data_pack.release()); | 353 AddDataPack(data_pack.release()); |
| 346 | 354 |
| 347 data_pack.reset(new DataPack(ui::SCALE_FACTOR_NONE)); | 355 data_pack.reset(new DataPack(ui::SCALE_FACTOR_NONE)); |
| 348 if (!locale_path.empty() && data_pack->LoadFromPath(locale_path)) { | 356 if (!locale_path.empty() && data_pack->LoadFromPath(locale_path)) { |
| 349 locale_resources_data_.reset(data_pack.release()); | 357 locale_resources_data_.reset(data_pack.release()); |
| 350 } else { | 358 } else { |
| 351 locale_resources_data_.reset(new DataPack(ui::SCALE_FACTOR_NONE)); | 359 locale_resources_data_.reset(new DataPack(ui::SCALE_FACTOR_NONE)); |
| 352 } | 360 } |
| 353 } | 361 } |
| 354 | 362 |
| 363 void ResourceBundle::LoadTestResourcesFromBuffer( |
| 364 base::StringPiece data, |
| 365 base::StringPiece locale_data) { |
| 366 is_test_resources_ = true; |
| 367 DCHECK(!ui::GetSupportedScaleFactors().empty()); |
| 368 const ScaleFactor scale_factor(ui::GetSupportedScaleFactors()[0]); |
| 369 // Use the given resource pak for both common and localized resources. |
| 370 std::unique_ptr<DataPack> data_pack(new DataPack(scale_factor)); |
| 371 if (data_pack->LoadFromBuffer(data)) |
| 372 AddDataPack(data_pack.release()); |
| 373 |
| 374 data_pack.reset(new DataPack(ui::SCALE_FACTOR_NONE)); |
| 375 if (data_pack->LoadFromBuffer(locale_data)) { |
| 376 locale_resources_data_.reset(data_pack.release()); |
| 377 } else { |
| 378 locale_resources_data_.reset(new DataPack(ui::SCALE_FACTOR_NONE)); |
| 379 } |
| 380 } |
| 381 |
| 355 void ResourceBundle::UnloadLocaleResources() { | 382 void ResourceBundle::UnloadLocaleResources() { |
| 356 locale_resources_data_.reset(); | 383 locale_resources_data_.reset(); |
| 357 } | 384 } |
| 358 | 385 |
| 359 void ResourceBundle::OverrideLocalePakForTest(const base::FilePath& pak_path) { | 386 void ResourceBundle::OverrideLocalePakForTest(const base::FilePath& pak_path) { |
| 360 overridden_pak_path_ = pak_path; | 387 overridden_pak_path_ = pak_path; |
| 361 } | 388 } |
| 362 | 389 |
| 363 void ResourceBundle::OverrideLocaleStringResource( | 390 void ResourceBundle::OverrideLocaleStringResource( |
| 364 int message_id, | 391 int message_id, |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 // static | 923 // static |
| 897 bool ResourceBundle::DecodePNG(const unsigned char* buf, | 924 bool ResourceBundle::DecodePNG(const unsigned char* buf, |
| 898 size_t size, | 925 size_t size, |
| 899 SkBitmap* bitmap, | 926 SkBitmap* bitmap, |
| 900 bool* fell_back_to_1x) { | 927 bool* fell_back_to_1x) { |
| 901 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); | 928 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); |
| 902 return gfx::PNGCodec::Decode(buf, size, bitmap); | 929 return gfx::PNGCodec::Decode(buf, size, bitmap); |
| 903 } | 930 } |
| 904 | 931 |
| 905 } // namespace ui | 932 } // namespace ui |
| OLD | NEW |