| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 81 } |
| 82 | 82 |
| 83 } // namespace | 83 } // namespace |
| 84 | 84 |
| 85 SimpleResourceLoader::SimpleResourceLoader() | 85 SimpleResourceLoader::SimpleResourceLoader() |
| 86 : locale_dll_handle_(NULL) { | 86 : locale_dll_handle_(NULL) { |
| 87 // Find and load the resource DLL. | 87 // Find and load the resource DLL. |
| 88 std::vector<std::wstring> language_tags; | 88 std::vector<std::wstring> language_tags; |
| 89 | 89 |
| 90 // First, try the locale dictated by policy and its fallback. | 90 // First, try the locale dictated by policy and its fallback. |
| 91 PushBackWithFallbackIfAbsent(Singleton<PolicySettings>()->ApplicationLocale(), | 91 PushBackWithFallbackIfAbsent( |
| 92 &language_tags); | 92 PolicySettings::GetInstance()->ApplicationLocale(), |
| 93 &language_tags); |
| 93 | 94 |
| 94 // Next, try the thread, process, user, system languages. | 95 // Next, try the thread, process, user, system languages. |
| 95 GetPreferredLanguages(&language_tags); | 96 GetPreferredLanguages(&language_tags); |
| 96 | 97 |
| 97 // Finally, fall-back on "en-US" (which may already be present in the vector, | 98 // Finally, fall-back on "en-US" (which may already be present in the vector, |
| 98 // but that's okay since we'll exit with success when the first is tried). | 99 // but that's okay since we'll exit with success when the first is tried). |
| 99 language_tags.push_back(L"en-US"); | 100 language_tags.push_back(L"en-US"); |
| 100 | 101 |
| 101 FilePath locales_path; | 102 FilePath locales_path; |
| 102 FilePath locale_dll_path; | 103 FilePath locale_dll_path; |
| 103 | 104 |
| 104 DetermineLocalesDirectory(&locales_path); | 105 DetermineLocalesDirectory(&locales_path); |
| 105 if (LoadLocaleDll(language_tags, locales_path, &locale_dll_handle_, | 106 if (LoadLocaleDll(language_tags, locales_path, &locale_dll_handle_, |
| 106 &locale_dll_path)) { | 107 &locale_dll_path)) { |
| 107 language_ = locale_dll_path.BaseName().RemoveExtension().value(); | 108 language_ = locale_dll_path.BaseName().RemoveExtension().value(); |
| 108 } else { | 109 } else { |
| 109 NOTREACHED() << "Failed loading any resource dll (even \"en-US\")."; | 110 NOTREACHED() << "Failed loading any resource dll (even \"en-US\")."; |
| 110 } | 111 } |
| 111 } | 112 } |
| 112 | 113 |
| 113 SimpleResourceLoader::~SimpleResourceLoader() { | 114 SimpleResourceLoader::~SimpleResourceLoader() { |
| 114 locale_dll_handle_ = NULL; | 115 locale_dll_handle_ = NULL; |
| 115 } | 116 } |
| 116 | 117 |
| 117 // static | 118 // static |
| 119 SimpleResourceLoader* SimpleResourceLoader::instance() { |
| 120 return Singleton<SimpleResourceLoader>::get(); |
| 121 } |
| 122 |
| 123 // static |
| 118 void SimpleResourceLoader::GetPreferredLanguages( | 124 void SimpleResourceLoader::GetPreferredLanguages( |
| 119 std::vector<std::wstring>* language_tags) { | 125 std::vector<std::wstring>* language_tags) { |
| 120 DCHECK(language_tags); | 126 DCHECK(language_tags); |
| 121 // The full set of preferred languages and their fallbacks are given priority. | 127 // The full set of preferred languages and their fallbacks are given priority. |
| 122 std::vector<std::wstring> languages; | 128 std::vector<std::wstring> languages; |
| 123 if (base::win::i18n::GetThreadPreferredUILanguageList(&languages)) { | 129 if (base::win::i18n::GetThreadPreferredUILanguageList(&languages)) { |
| 124 for (std::vector<std::wstring>::const_iterator scan = languages.begin(), | 130 for (std::vector<std::wstring>::const_iterator scan = languages.begin(), |
| 125 end = languages.end(); scan != end; ++scan) { | 131 end = languages.end(); scan != end; ++scan) { |
| 126 PushBackIfAbsent(*scan, language_tags); | 132 PushBackIfAbsent(*scan, language_tags); |
| 127 } | 133 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 245 |
| 240 // static | 246 // static |
| 241 std::wstring SimpleResourceLoader::Get(int message_id) { | 247 std::wstring SimpleResourceLoader::Get(int message_id) { |
| 242 SimpleResourceLoader* loader = SimpleResourceLoader::instance(); | 248 SimpleResourceLoader* loader = SimpleResourceLoader::instance(); |
| 243 return loader->GetLocalizedResource(message_id); | 249 return loader->GetLocalizedResource(message_id); |
| 244 } | 250 } |
| 245 | 251 |
| 246 HMODULE SimpleResourceLoader::GetResourceModuleHandle() { | 252 HMODULE SimpleResourceLoader::GetResourceModuleHandle() { |
| 247 return locale_dll_handle_; | 253 return locale_dll_handle_; |
| 248 } | 254 } |
| OLD | NEW |