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 // This class implements a simplified and much stripped down version of | 5 // This class implements a simplified and much stripped down version of |
6 // Chrome's app/resource_bundle machinery. It notably avoids unwanted | 6 // Chrome's app/resource_bundle machinery. It notably avoids unwanted |
7 // dependencies on things like Skia. | 7 // dependencies on things like Skia. |
8 // | 8 // |
9 | 9 |
10 #ifndef CHROME_FRAME_SIMPLE_RESOURCE_LOADER_H_ | 10 #ifndef CHROME_FRAME_SIMPLE_RESOURCE_LOADER_H_ |
11 #define CHROME_FRAME_SIMPLE_RESOURCE_LOADER_H_ | 11 #define CHROME_FRAME_SIMPLE_RESOURCE_LOADER_H_ |
12 | 12 |
13 #include <windows.h> | 13 #include <windows.h> |
14 #include <string> | 14 #include <string> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/file_path.h" | 17 #include "base/file_path.h" |
18 #include "base/gtest_prod_util.h" | 18 #include "base/gtest_prod_util.h" |
19 #include "base/memory/singleton.h" | 19 #include "base/memory/singleton.h" |
20 | 20 |
| 21 namespace ui { |
| 22 class DataPack; |
| 23 } // namespace ui |
| 24 |
21 class SimpleResourceLoader { | 25 class SimpleResourceLoader { |
22 public: | 26 public: |
23 | 27 |
24 static SimpleResourceLoader* GetInstance(); | 28 static SimpleResourceLoader* GetInstance(); |
25 | 29 |
26 // Returns the language tag for the active language. | 30 // Returns the language tag for the active language. |
27 static std::wstring GetLanguage(); | 31 static std::wstring GetLanguage(); |
28 | 32 |
29 // Helper method to return the string resource identified by message_id | 33 // Helper method to return the string resource identified by message_id |
30 // from the currently loaded locale dll. | 34 // from the currently loaded locale dll. |
(...skipping 10 matching lines...) Expand all Loading... |
41 // Populates |locales_path| with the path to the "Locales" directory. | 45 // Populates |locales_path| with the path to the "Locales" directory. |
42 static void DetermineLocalesDirectory(FilePath* locales_path); | 46 static void DetermineLocalesDirectory(FilePath* locales_path); |
43 | 47 |
44 // Returns false if |language_tag| is malformed. | 48 // Returns false if |language_tag| is malformed. |
45 static bool IsValidLanguageTag(const std::wstring& language_tag); | 49 static bool IsValidLanguageTag(const std::wstring& language_tag); |
46 | 50 |
47 private: | 51 private: |
48 SimpleResourceLoader(); | 52 SimpleResourceLoader(); |
49 ~SimpleResourceLoader(); | 53 ~SimpleResourceLoader(); |
50 | 54 |
51 // Finds the most-preferred resource DLL for the laguages in |language_tags| | 55 // Finds the most-preferred resource dll and language pack for the laguages |
| 56 // in |language_tags| |
52 // in |locales_path|. | 57 // in |locales_path|. |
53 // | 58 // |
54 // Returns true on success with a handle to the DLL that was loaded in | 59 // Returns true on success with a handle to the DLL that was loaded in |
55 // |dll_handle| and its path in |file_path|. | 60 // |dll_handle|, the data pack in |data_pack| and the locale language in |
56 static bool LoadLocaleDll(const std::vector<std::wstring>& language_tags, | 61 // the |language| parameter. |
57 const FilePath& locales_path, | 62 static bool LoadLocalePack(const std::vector<std::wstring>& language_tags, |
58 HMODULE* dll_handle, | 63 const FilePath& locales_path, |
59 FilePath* file_path); | 64 HMODULE* dll_handle, |
| 65 ui::DataPack** data_pack, |
| 66 std::wstring* language); |
60 | 67 |
61 // Returns the string resource identified by message_id from the currently | 68 // Returns the string resource identified by message_id from the currently |
62 // loaded locale dll. | 69 // loaded locale dll. |
63 std::wstring GetLocalizedResource(int message_id); | 70 std::wstring GetLocalizedResource(int message_id); |
64 | 71 |
65 friend struct DefaultSingletonTraits<SimpleResourceLoader>; | 72 friend struct DefaultSingletonTraits<SimpleResourceLoader>; |
66 | 73 |
67 FRIEND_TEST_ALL_PREFIXES(SimpleResourceLoaderTest, LoadLocaleDll); | 74 FRIEND_TEST_ALL_PREFIXES(SimpleResourceLoaderTest, LoadLocaleDll); |
68 | 75 |
69 std::wstring language_; | 76 std::wstring language_; |
| 77 ui::DataPack* data_pack_; |
| 78 |
70 HINSTANCE locale_dll_handle_; | 79 HINSTANCE locale_dll_handle_; |
71 }; | 80 }; |
72 | 81 |
73 #endif // CHROME_FRAME_SIMPLE_RESOURCE_LOADER_H_ | 82 #endif // CHROME_FRAME_SIMPLE_RESOURCE_LOADER_H_ |
OLD | NEW |