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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // Must call InitSharedInstance before this function. | 82 // Must call InitSharedInstance before this function. |
83 CHECK(g_shared_instance_ != NULL); | 83 CHECK(g_shared_instance_ != NULL); |
84 return *g_shared_instance_; | 84 return *g_shared_instance_; |
85 } | 85 } |
86 | 86 |
87 // static | 87 // static |
88 bool ResourceBundle::LocaleDataPakExists(const std::string& locale) { | 88 bool ResourceBundle::LocaleDataPakExists(const std::string& locale) { |
89 return !GetLocaleFilePath(locale).empty(); | 89 return !GetLocaleFilePath(locale).empty(); |
90 } | 90 } |
91 | 91 |
92 void ResourceBundle::AddDataPack(const FilePath& path) { | 92 void ResourceBundle::AddDataPack(const FilePath& path, float scale_factor) { |
93 scoped_ptr<DataPack> data_pack(new DataPack()); | 93 scoped_ptr<DataPack> data_pack(new DataPack(ResourceHandle::kScaleFactor1x)); |
94 if (data_pack->Load(path)) { | 94 if (data_pack->Load(path)) { |
95 data_packs_.push_back(data_pack.release()); | 95 data_packs_.push_back(data_pack.release()); |
96 } else { | 96 } else { |
97 LOG(ERROR) << "Failed to load " << path.value() | 97 LOG(ERROR) << "Failed to load " << path.value() |
98 << "\nSome features may not be available."; | 98 << "\nSome features may not be available."; |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 #if !defined(OS_MACOSX) | 102 #if !defined(OS_MACOSX) |
103 // static | 103 // static |
(...skipping 30 matching lines...) Expand all Loading... |
134 locale_file_path = GetLocaleFilePath(app_locale); | 134 locale_file_path = GetLocaleFilePath(app_locale); |
135 } | 135 } |
136 } | 136 } |
137 | 137 |
138 if (locale_file_path.empty()) { | 138 if (locale_file_path.empty()) { |
139 // It's possible that there is no locale.pak. | 139 // It's possible that there is no locale.pak. |
140 NOTREACHED(); | 140 NOTREACHED(); |
141 return std::string(); | 141 return std::string(); |
142 } | 142 } |
143 | 143 |
144 scoped_ptr<DataPack> data_pack(new DataPack()); | 144 scoped_ptr<DataPack> data_pack(new DataPack(ResourceHandle::kScaleFactor1x)); |
145 if (!data_pack->Load(locale_file_path)) { | 145 if (!data_pack->Load(locale_file_path)) { |
146 UMA_HISTOGRAM_ENUMERATION("ResourceBundle.LoadLocaleResourcesError", | 146 UMA_HISTOGRAM_ENUMERATION("ResourceBundle.LoadLocaleResourcesError", |
147 logging::GetLastSystemErrorCode(), 16000); | 147 logging::GetLastSystemErrorCode(), 16000); |
148 NOTREACHED() << "failed to load locale.pak"; | 148 NOTREACHED() << "failed to load locale.pak"; |
149 return std::string(); | 149 return std::string(); |
150 } | 150 } |
151 | 151 |
152 locale_resources_data_.reset(data_pack.release()); | 152 locale_resources_data_.reset(data_pack.release()); |
153 return app_locale; | 153 return app_locale; |
154 } | 154 } |
155 | 155 |
156 void ResourceBundle::LoadTestResources(const FilePath& path) { | 156 void ResourceBundle::LoadTestResources(const FilePath& path) { |
157 // Use the given resource pak for both common and localized resources. | 157 // Use the given resource pak for both common and localized resources. |
158 scoped_ptr<DataPack> data_pack(new DataPack()); | 158 scoped_ptr<DataPack> data_pack(new DataPack(ResourceHandle::kScaleFactor1x)); |
159 if (data_pack->Load(path)) | 159 if (data_pack->Load(path)) |
160 data_packs_.push_back(data_pack.release()); | 160 data_packs_.push_back(data_pack.release()); |
161 | 161 |
162 data_pack.reset(new DataPack()); | 162 data_pack.reset(new DataPack(ResourceHandle::kScaleFactor1x)); |
163 if (data_pack->Load(path)) | 163 if (data_pack->Load(path)) |
164 locale_resources_data_.reset(data_pack.release()); | 164 locale_resources_data_.reset(data_pack.release()); |
165 } | 165 } |
166 | 166 |
167 void ResourceBundle::UnloadLocaleResources() { | 167 void ResourceBundle::UnloadLocaleResources() { |
168 locale_resources_data_.reset(); | 168 locale_resources_data_.reset(); |
169 } | 169 } |
170 | 170 |
171 string16 ResourceBundle::GetLocalizedString(int message_id) { | 171 string16 ResourceBundle::GetLocalizedString(int message_id) { |
172 // Ensure that ReloadLocaleResources() doesn't drop the resources while | 172 // Ensure that ReloadLocaleResources() doesn't drop the resources while |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 SkBitmap* bitmap = new SkBitmap(); | 403 SkBitmap* bitmap = new SkBitmap(); |
404 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 32, 32); | 404 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 32, 32); |
405 bitmap->allocPixels(); | 405 bitmap->allocPixels(); |
406 bitmap->eraseARGB(255, 255, 0, 0); | 406 bitmap->eraseARGB(255, 255, 0, 0); |
407 empty_image = new gfx::Image(bitmap); | 407 empty_image = new gfx::Image(bitmap); |
408 } | 408 } |
409 return empty_image; | 409 return empty_image; |
410 } | 410 } |
411 | 411 |
412 } // namespace ui | 412 } // namespace ui |
OLD | NEW |