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

Side by Side Diff: chrome_frame/simple_resource_loader.cc

Issue 12211108: Rename FilePath -> base::FilePath in various toplevel directories (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
« no previous file with comments | « chrome_frame/simple_resource_loader.h ('k') | chrome_frame/test/automation_client_mock.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome_frame/simple_resource_loader.h" 5 #include "chrome_frame/simple_resource_loader.h"
6 6
7 #include <atlbase.h> 7 #include <atlbase.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 PolicySettings::GetInstance()->ApplicationLocale(), 93 PolicySettings::GetInstance()->ApplicationLocale(),
94 &language_tags); 94 &language_tags);
95 95
96 // Next, try the thread, process, user, system languages. 96 // Next, try the thread, process, user, system languages.
97 GetPreferredLanguages(&language_tags); 97 GetPreferredLanguages(&language_tags);
98 98
99 // Finally, fall-back on "en-US" (which may already be present in the vector, 99 // Finally, fall-back on "en-US" (which may already be present in the vector,
100 // but that's okay since we'll exit with success when the first is tried). 100 // but that's okay since we'll exit with success when the first is tried).
101 language_tags.push_back(L"en-US"); 101 language_tags.push_back(L"en-US");
102 102
103 FilePath locales_path; 103 base::FilePath locales_path;
104 104
105 DetermineLocalesDirectory(&locales_path); 105 DetermineLocalesDirectory(&locales_path);
106 if (!LoadLocalePack(language_tags, locales_path, &locale_dll_handle_, 106 if (!LoadLocalePack(language_tags, locales_path, &locale_dll_handle_,
107 &data_pack_, &language_)) { 107 &data_pack_, &language_)) {
108 NOTREACHED() << "Failed loading any resource dll (even \"en-US\")."; 108 NOTREACHED() << "Failed loading any resource dll (even \"en-US\").";
109 } 109 }
110 } 110 }
111 111
112 SimpleResourceLoader::~SimpleResourceLoader() { 112 SimpleResourceLoader::~SimpleResourceLoader() {
113 delete data_pack_; 113 delete data_pack_;
(...skipping 16 matching lines...) Expand all
130 PushBackIfAbsent(*scan, language_tags); 130 PushBackIfAbsent(*scan, language_tags);
131 } 131 }
132 } 132 }
133 // Use the base i18n routines (i.e., ICU) as a last, best hope for something 133 // Use the base i18n routines (i.e., ICU) as a last, best hope for something
134 // meaningful for the user. 134 // meaningful for the user.
135 PushBackWithFallbackIfAbsent(ASCIIToWide(base::i18n::GetConfiguredLocale()), 135 PushBackWithFallbackIfAbsent(ASCIIToWide(base::i18n::GetConfiguredLocale()),
136 language_tags); 136 language_tags);
137 } 137 }
138 138
139 // static 139 // static
140 void SimpleResourceLoader::DetermineLocalesDirectory(FilePath* locales_path) { 140 void SimpleResourceLoader::DetermineLocalesDirectory(
141 base::FilePath* locales_path) {
141 DCHECK(locales_path); 142 DCHECK(locales_path);
142 143
143 FilePath module_path; 144 base::FilePath module_path;
144 PathService::Get(base::DIR_MODULE, &module_path); 145 PathService::Get(base::DIR_MODULE, &module_path);
145 *locales_path = module_path.Append(kLocalesDirName); 146 *locales_path = module_path.Append(kLocalesDirName);
146 147
147 // We may be residing in the "locales" directory's parent, or we might be 148 // We may be residing in the "locales" directory's parent, or we might be
148 // in a sibling directory. Move up one and look for Locales again in the 149 // in a sibling directory. Move up one and look for Locales again in the
149 // latter case. 150 // latter case.
150 if (!file_util::DirectoryExists(*locales_path)) { 151 if (!file_util::DirectoryExists(*locales_path)) {
151 *locales_path = module_path.DirName(); 152 *locales_path = module_path.DirName();
152 *locales_path = locales_path->Append(kLocalesDirName); 153 *locales_path = locales_path->Append(kLocalesDirName);
153 } 154 }
(...skipping 10 matching lines...) Expand all
164 // character that isn't in the above set. This will at least weed out 165 // character that isn't in the above set. This will at least weed out
165 // attempts at "../../EvilBinary". 166 // attempts at "../../EvilBinary".
166 return language_tag.end() == std::find_if(language_tag.begin(), 167 return language_tag.end() == std::find_if(language_tag.begin(),
167 language_tag.end(), 168 language_tag.end(),
168 &IsInvalidTagCharacter); 169 &IsInvalidTagCharacter);
169 } 170 }
170 171
171 // static 172 // static
172 bool SimpleResourceLoader::LoadLocalePack( 173 bool SimpleResourceLoader::LoadLocalePack(
173 const std::vector<std::wstring>& language_tags, 174 const std::vector<std::wstring>& language_tags,
174 const FilePath& locales_path, 175 const base::FilePath& locales_path,
175 HMODULE* dll_handle, 176 HMODULE* dll_handle,
176 ui::DataPack** data_pack, 177 ui::DataPack** data_pack,
177 std::wstring* language) { 178 std::wstring* language) {
178 DCHECK(language); 179 DCHECK(language);
179 180
180 // The dll should only have resources, not executable code. 181 // The dll should only have resources, not executable code.
181 const DWORD load_flags = 182 const DWORD load_flags =
182 (base::win::GetVersion() >= base::win::VERSION_VISTA ? 183 (base::win::GetVersion() >= base::win::VERSION_VISTA ?
183 LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE | LOAD_LIBRARY_AS_IMAGE_RESOURCE : 184 LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE | LOAD_LIBRARY_AS_IMAGE_RESOURCE :
184 DONT_RESOLVE_DLL_REFERENCES); 185 DONT_RESOLVE_DLL_REFERENCES);
185 186
186 const std::wstring dll_suffix(L".dll"); 187 const std::wstring dll_suffix(L".dll");
187 const std::wstring pack_suffix(L".pak"); 188 const std::wstring pack_suffix(L".pak");
188 189
189 bool found_pack = false; 190 bool found_pack = false;
190 191
191 for (std::vector<std::wstring>::const_iterator scan = language_tags.begin(), 192 for (std::vector<std::wstring>::const_iterator scan = language_tags.begin(),
192 end = language_tags.end(); 193 end = language_tags.end();
193 scan != end; 194 scan != end;
194 ++scan) { 195 ++scan) {
195 if (!IsValidLanguageTag(*scan)) { 196 if (!IsValidLanguageTag(*scan)) {
196 LOG(WARNING) << "Invalid language tag supplied while locating resources:" 197 LOG(WARNING) << "Invalid language tag supplied while locating resources:"
197 " \"" << *scan << "\""; 198 " \"" << *scan << "\"";
198 continue; 199 continue;
199 } 200 }
200 201
201 // Attempt to load both the resource pack and the dll. We return success 202 // Attempt to load both the resource pack and the dll. We return success
202 // only we load both. 203 // only we load both.
203 FilePath resource_pack_path = locales_path.Append(*scan + pack_suffix); 204 base::FilePath resource_pack_path =
204 FilePath dll_path = locales_path.Append(*scan + dll_suffix); 205 locales_path.Append(*scan + pack_suffix);
206 base::FilePath dll_path = locales_path.Append(*scan + dll_suffix);
205 207
206 if (file_util::PathExists(resource_pack_path) && 208 if (file_util::PathExists(resource_pack_path) &&
207 file_util::PathExists(dll_path)) { 209 file_util::PathExists(dll_path)) {
208 scoped_ptr<ui::DataPack> cur_data_pack( 210 scoped_ptr<ui::DataPack> cur_data_pack(
209 new ui::DataPack(ui::SCALE_FACTOR_100P)); 211 new ui::DataPack(ui::SCALE_FACTOR_100P));
210 if (!cur_data_pack->LoadFromPath(resource_pack_path)) 212 if (!cur_data_pack->LoadFromPath(resource_pack_path))
211 continue; 213 continue;
212 214
213 HMODULE locale_dll_handle = LoadLibraryEx(dll_path.value().c_str(), NULL, 215 HMODULE locale_dll_handle = LoadLibraryEx(dll_path.value().c_str(), NULL,
214 load_flags); 216 load_flags);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 262
261 // static 263 // static
262 std::wstring SimpleResourceLoader::Get(int message_id) { 264 std::wstring SimpleResourceLoader::Get(int message_id) {
263 SimpleResourceLoader* loader = SimpleResourceLoader::GetInstance(); 265 SimpleResourceLoader* loader = SimpleResourceLoader::GetInstance();
264 return loader->GetLocalizedResource(message_id); 266 return loader->GetLocalizedResource(message_id);
265 } 267 }
266 268
267 HMODULE SimpleResourceLoader::GetResourceModuleHandle() { 269 HMODULE SimpleResourceLoader::GetResourceModuleHandle() {
268 return locale_dll_handle_; 270 return locale_dll_handle_;
269 } 271 }
OLDNEW
« no previous file with comments | « chrome_frame/simple_resource_loader.h ('k') | chrome_frame/test/automation_client_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698