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