| Index: ui/base/resource/data_pack.cc
|
| diff --git a/ui/base/resource/data_pack.cc b/ui/base/resource/data_pack.cc
|
| index c4b1594c80dd7b45abc07e4f429e730ad1968624..5a0dcf1a24670d5231e00f111f6d6f10f43ebb1e 100644
|
| --- a/ui/base/resource/data_pack.cc
|
| +++ b/ui/base/resource/data_pack.cc
|
| @@ -17,9 +17,9 @@
|
|
|
| namespace {
|
|
|
| -static const uint32 kFileFormatVersion = 3;
|
| -// Length of file header: version and entry count.
|
| -static const size_t kHeaderLength = 2 * sizeof(uint32);
|
| +static const uint32 kFileFormatVersion = 4;
|
| +// Length of file header: version, entry count and text encoding type.
|
| +static const size_t kHeaderLength = 2 * sizeof(uint32) + sizeof(uint8);
|
|
|
| #pragma pack(push,2)
|
| struct DataPackEntry {
|
| @@ -60,7 +60,7 @@ enum LoadErrors {
|
| namespace ui {
|
|
|
| // In .cc for MemoryMappedFile dtor.
|
| -DataPack::DataPack() : resource_count_(0) {
|
| +DataPack::DataPack() : resource_count_(0), text_encoding_type_(BINARY) {
|
| }
|
| DataPack::~DataPack() {
|
| }
|
| @@ -83,7 +83,7 @@ bool DataPack::Load(const FilePath& path) {
|
| }
|
|
|
| // Parse the header of the file.
|
| - // First uint32: version; second: resource count.
|
| + // First uint32: version; second: resource count;
|
| const uint32* ptr = reinterpret_cast<const uint32*>(mmap_->data());
|
| uint32 version = ptr[0];
|
| if (version != kFileFormatVersion) {
|
| @@ -96,6 +96,17 @@ bool DataPack::Load(const FilePath& path) {
|
| }
|
| resource_count_ = ptr[1];
|
|
|
| + // third: text encoding.
|
| + const uint8* ptr_encoding = reinterpret_cast<const uint8*>(ptr + 2);
|
| + text_encoding_type_ = static_cast<TextEncodingType>(*ptr_encoding);
|
| + if (text_encoding_type_ != UTF8 && text_encoding_type_ != UTF16 &&
|
| + text_encoding_type_ != BINARY) {
|
| + LOG(ERROR) << "Bad data pack text encoding: got " << text_encoding_type_
|
| + << ", expected between " << BINARY << " and " << UTF16;
|
| + mmap_.reset();
|
| + return false;
|
| + }
|
| +
|
| // Sanity check the file.
|
| // 1) Check we have enough entries.
|
| if (kHeaderLength + resource_count_ * sizeof(DataPackEntry) >
|
| @@ -163,7 +174,8 @@ RefCountedStaticMemory* DataPack::GetStaticMemory(uint16 resource_id) const {
|
|
|
| // static
|
| bool DataPack::WritePack(const FilePath& path,
|
| - const std::map<uint16, base::StringPiece>& resources) {
|
| + const std::map<uint16, base::StringPiece>& resources,
|
| + TextEncodingType textEncodingType) {
|
| FILE* file = file_util::OpenFile(path, "wb");
|
| if (!file)
|
| return false;
|
| @@ -183,6 +195,21 @@ bool DataPack::WritePack(const FilePath& path,
|
| return false;
|
| }
|
|
|
| + if (textEncodingType != UTF8 && textEncodingType != UTF16 &&
|
| + textEncodingType != BINARY) {
|
| + LOG(ERROR) << "Invalid text encoding type, got " << textEncodingType
|
| + << ", expected between " << BINARY << " and " << UTF16;
|
| + file_util::CloseFile(file);
|
| + return false;
|
| + }
|
| +
|
| + uint8 write_buffer = textEncodingType;
|
| + if (fwrite(&write_buffer, sizeof(uint8), 1, file) != 1) {
|
| + LOG(ERROR) << "Failed to write file text resources encoding";
|
| + file_util::CloseFile(file);
|
| + return false;
|
| + }
|
| +
|
| // Each entry is a uint16 + a uint32. We have an extra entry after the last
|
| // item so we can compute the size of the list item.
|
| uint32 index_length = (entry_count + 1) * sizeof(DataPackEntry);
|
|
|