Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: ui/base/resource/resource_bundle_posix.cc

Issue 7744017: Updated *.pak file format to support both UTF8 and UTF16 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up comments/ Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_path.h" 8 #include "base/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/string16.h" 11 #include "base/string16.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 "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/data_pack.h" 16 #include "ui/base/resource/data_pack.h"
16 #include "ui/base/ui_base_switches.h" 17 #include "ui/base/ui_base_switches.h"
17 #include "ui/gfx/font.h" 18 #include "ui/gfx/font.h"
18 19
19 namespace ui { 20 namespace ui {
20 21
21 namespace { 22 namespace {
22 23
23 DataPack* LoadResourcesDataPak(FilePath resources_pak_path) { 24 DataPack* LoadResourcesDataPak(FilePath resources_pak_path) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 if (!locale_resources_data_->GetStringPiece(message_id, &data)) { 82 if (!locale_resources_data_->GetStringPiece(message_id, &data)) {
82 // Fall back on the main data pack (shouldn't be any strings here except in 83 // Fall back on the main data pack (shouldn't be any strings here except in
83 // unittests). 84 // unittests).
84 data = GetRawDataResource(message_id); 85 data = GetRawDataResource(message_id);
85 if (data.empty()) { 86 if (data.empty()) {
86 NOTREACHED() << "unable to find resource: " << message_id; 87 NOTREACHED() << "unable to find resource: " << message_id;
87 return string16(); 88 return string16();
88 } 89 }
89 } 90 }
90 91
91 // Data pack encodes strings as UTF16. 92 // Strings should not be loaded from data back that contain binary data.
92 DCHECK_EQ(data.length() % 2, 0U); 93 DCHECK(locale_resources_data_->GetTextEncodingType() == DataPack::UTF16 ||
93 string16 msg(reinterpret_cast<const char16*>(data.data()), 94 locale_resources_data_->GetTextEncodingType() == DataPack::UTF8)
94 data.length() / 2); 95 << "requested localized string from binary pack file";
96
97 // Data pack encodes strings as either UTF8 or UTF16.
98 string16 msg;
99 if (locale_resources_data_->GetTextEncodingType() == DataPack::UTF16) {
100 msg = string16(reinterpret_cast<const char16*>(data.data()),
101 data.length() / 2);
102 } else if (locale_resources_data_->GetTextEncodingType() == DataPack::UTF8) {
103 msg = UTF8ToUTF16(data);
tony 2011/08/29 21:24:39 This is fine for now. We'll want to probably fix
marcvs 2011/08/30 07:58:55 Yes, since GTK uses UTF8 I was saving this for lat
104 }
95 return msg; 105 return msg;
96 } 106 }
97 107
98 void ResourceBundle::LoadCommonResources() { 108 void ResourceBundle::LoadCommonResources() {
99 DCHECK(!resources_data_) << "chrome.pak already loaded"; 109 DCHECK(!resources_data_) << "chrome.pak already loaded";
100 FilePath resources_file_path = GetResourcesFilePath(); 110 FilePath resources_file_path = GetResourcesFilePath();
101 CHECK(!resources_file_path.empty()) << "chrome.pak not found"; 111 CHECK(!resources_file_path.empty()) << "chrome.pak not found";
102 resources_data_ = LoadResourcesDataPak(resources_file_path); 112 resources_data_ = LoadResourcesDataPak(resources_file_path);
103 CHECK(resources_data_) << "failed to load chrome.pak"; 113 CHECK(resources_data_) << "failed to load chrome.pak";
104 114
(...skipping 30 matching lines...) Expand all
135 145
136 void ResourceBundle::LoadTestResources(const FilePath& path) { 146 void ResourceBundle::LoadTestResources(const FilePath& path) {
137 DCHECK(!resources_data_) << "resource already loaded"; 147 DCHECK(!resources_data_) << "resource already loaded";
138 148
139 // Use the given resource pak for both common and localized resources. 149 // Use the given resource pak for both common and localized resources.
140 resources_data_ = LoadResourcesDataPak(path); 150 resources_data_ = LoadResourcesDataPak(path);
141 locale_resources_data_ = LoadResourcesDataPak(path); 151 locale_resources_data_ = LoadResourcesDataPak(path);
142 } 152 }
143 153
144 } // namespace ui 154 } // namespace ui
OLDNEW
« ui/base/resource/data_pack_unittest.cc ('K') | « ui/base/resource/data_pack_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698