| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/string_piece.h" | 12 #include "base/string_piece.h" |
| 13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "base/utf_string_conversions.h" | |
| 15 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/resource/data_pack.h" | 17 #include "ui/base/resource/data_pack.h" |
| 19 #include "ui/base/ui_base_paths.h" | 18 #include "ui/base/ui_base_paths.h" |
| 20 #include "ui/base/ui_base_switches.h" | 19 #include "ui/base/ui_base_switches.h" |
| 21 #include "ui/gfx/codec/png_codec.h" | 20 #include "ui/gfx/codec/png_codec.h" |
| 22 #include "ui/gfx/font.h" | 21 #include "ui/gfx/font.h" |
| 23 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
| 24 | 23 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 if (!locale_resources_data_->GetStringPiece(message_id, &data)) { | 180 if (!locale_resources_data_->GetStringPiece(message_id, &data)) { |
| 182 // Fall back on the main data pack (shouldn't be any strings here except in | 181 // Fall back on the main data pack (shouldn't be any strings here except in |
| 183 // unittests). | 182 // unittests). |
| 184 data = GetRawDataResource(message_id); | 183 data = GetRawDataResource(message_id); |
| 185 if (data.empty()) { | 184 if (data.empty()) { |
| 186 NOTREACHED() << "unable to find resource: " << message_id; | 185 NOTREACHED() << "unable to find resource: " << message_id; |
| 187 return string16(); | 186 return string16(); |
| 188 } | 187 } |
| 189 } | 188 } |
| 190 | 189 |
| 191 // Strings should not be loaded from a data pack that contains binary data. | 190 // Data pack encodes strings as UTF16. |
| 192 DCHECK(locale_resources_data_->GetTextEncodingType() == DataPack::UTF16 || | 191 DCHECK_EQ(data.length() % 2, 0U); |
| 193 locale_resources_data_->GetTextEncodingType() == DataPack::UTF8) | 192 string16 msg(reinterpret_cast<const char16*>(data.data()), |
| 194 << "requested localized string from binary pack file"; | 193 data.length() / 2); |
| 195 | |
| 196 // Data pack encodes strings as either UTF8 or UTF16. | |
| 197 string16 msg; | |
| 198 if (locale_resources_data_->GetTextEncodingType() == DataPack::UTF16) { | |
| 199 msg = string16(reinterpret_cast<const char16*>(data.data()), | |
| 200 data.length() / 2); | |
| 201 } else if (locale_resources_data_->GetTextEncodingType() == DataPack::UTF8) { | |
| 202 msg = UTF8ToUTF16(data); | |
| 203 } | |
| 204 return msg; | 194 return msg; |
| 205 } | 195 } |
| 206 | 196 |
| 207 void ResourceBundle::OverrideLocalePakForTest(const FilePath& pak_path) { | 197 void ResourceBundle::OverrideLocalePakForTest(const FilePath& pak_path) { |
| 208 overridden_pak_path_ = pak_path; | 198 overridden_pak_path_ = pak_path; |
| 209 } | 199 } |
| 210 | 200 |
| 211 const FilePath& ResourceBundle::GetOverriddenPakPath() { | 201 const FilePath& ResourceBundle::GetOverriddenPakPath() { |
| 212 return overridden_pak_path_; | 202 return overridden_pak_path_; |
| 213 } | 203 } |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 } | 394 } |
| 405 | 395 |
| 406 RefCountedStaticMemory* ResourceBundle::LoadedDataPack::GetStaticMemory( | 396 RefCountedStaticMemory* ResourceBundle::LoadedDataPack::GetStaticMemory( |
| 407 int resource_id) const { | 397 int resource_id) const { |
| 408 if (!data_pack_.get()) | 398 if (!data_pack_.get()) |
| 409 return NULL; | 399 return NULL; |
| 410 return data_pack_->GetStaticMemory(resource_id); | 400 return data_pack_->GetStaticMemory(resource_id); |
| 411 } | 401 } |
| 412 | 402 |
| 413 } // namespace ui | 403 } // namespace ui |
| OLD | NEW |