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 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); | |
|
sky
2016/05/19 20:25:54
nullptr
altimin
2016/05/19 23:04:47
Done.
| |
| 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 // Headless Chromium allows fallback to lower-res images. | |
| 367 is_test_resources_ = true; | |
| 368 | |
| 369 DCHECK(!ui::GetSupportedScaleFactors().empty()); | |
| 370 const ScaleFactor scale_factor(ui::GetSupportedScaleFactors()[0]); | |
| 371 // Use the given resource pak for both common and localized resources. | |
| 372 std::unique_ptr<DataPack> data_pack(new DataPack(scale_factor)); | |
| 373 if (data_pack->LoadFromBuffer(data)) | |
| 374 AddDataPack(data_pack.release()); | |
| 375 | |
| 376 data_pack.reset(new DataPack(ui::SCALE_FACTOR_NONE)); | |
| 377 if (data_pack->LoadFromBuffer(locale_data)) { | |
| 378 locale_resources_data_.reset(data_pack.release()); | |
| 379 } else { | |
| 380 locale_resources_data_.reset(new DataPack(ui::SCALE_FACTOR_NONE)); | |
| 381 } | |
| 382 } | |
| 383 | |
| 355 void ResourceBundle::UnloadLocaleResources() { | 384 void ResourceBundle::UnloadLocaleResources() { |
| 356 locale_resources_data_.reset(); | 385 locale_resources_data_.reset(); |
| 357 } | 386 } |
| 358 | 387 |
| 359 void ResourceBundle::OverrideLocalePakForTest(const base::FilePath& pak_path) { | 388 void ResourceBundle::OverrideLocalePakForTest(const base::FilePath& pak_path) { |
| 360 overridden_pak_path_ = pak_path; | 389 overridden_pak_path_ = pak_path; |
| 361 } | 390 } |
| 362 | 391 |
| 363 void ResourceBundle::OverrideLocaleStringResource( | 392 void ResourceBundle::OverrideLocaleStringResource( |
| 364 int message_id, | 393 int message_id, |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 896 // static | 925 // static |
| 897 bool ResourceBundle::DecodePNG(const unsigned char* buf, | 926 bool ResourceBundle::DecodePNG(const unsigned char* buf, |
| 898 size_t size, | 927 size_t size, |
| 899 SkBitmap* bitmap, | 928 SkBitmap* bitmap, |
| 900 bool* fell_back_to_1x) { | 929 bool* fell_back_to_1x) { |
| 901 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); | 930 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); |
| 902 return gfx::PNGCodec::Decode(buf, size, bitmap); | 931 return gfx::PNGCodec::Decode(buf, size, bitmap); |
| 903 } | 932 } |
| 904 | 933 |
| 905 } // namespace ui | 934 } // namespace ui |
| OLD | NEW |