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
3 // found in the LICENSE file.
5 // This class implements a simplified and much stripped down version of
6 // Chrome's app/resource_bundle machinery. It notably avoids unwanted
7 // dependencies on things like Skia.
10 #ifndef CHROME_FRAME_SIMPLE_RESOURCE_LOADER_H_
11 #define CHROME_FRAME_SIMPLE_RESOURCE_LOADER_H_
17 #include "base/files/file_path.h"
18 #include "base/gtest_prod_util.h"
19 #include "base/memory/singleton.h"
25 class SimpleResourceLoader
{
28 static SimpleResourceLoader
* GetInstance();
30 // Returns the language tag for the active language.
31 static std::wstring
GetLanguage();
33 // Helper method to return the string resource identified by message_id
34 // from the currently loaded locale dll.
35 static std::wstring
Get(int message_id
);
37 // Retrieves the HINSTANCE of the loaded module handle. May be NULL if a
38 // resource DLL could not be loaded.
39 HMODULE
GetResourceModuleHandle();
41 // Retrieves the preferred languages for the current thread, adding them to
43 static void GetPreferredLanguages(std::vector
<std::wstring
>* language_tags
);
45 // Populates |locales_path| with the path to the "Locales" directory.
46 static void DetermineLocalesDirectory(base::FilePath
* locales_path
);
48 // Returns false if |language_tag| is malformed.
49 static bool IsValidLanguageTag(const std::wstring
& language_tag
);
52 SimpleResourceLoader();
53 ~SimpleResourceLoader();
55 // Finds the most-preferred resource dll and language pack for the laguages
59 // Returns true on success with a handle to the DLL that was loaded in
60 // |dll_handle|, the data pack in |data_pack| and the locale language in
61 // the |language| parameter.
62 static bool LoadLocalePack(const std::vector
<std::wstring
>& language_tags
,
63 const base::FilePath
& locales_path
,
65 ui::DataPack
** data_pack
,
66 std::wstring
* language
);
68 // Returns the string resource identified by message_id from the currently
70 std::wstring
GetLocalizedResource(int message_id
);
72 friend struct DefaultSingletonTraits
<SimpleResourceLoader
>;
74 FRIEND_TEST_ALL_PREFIXES(SimpleResourceLoaderTest
, LoadLocaleDll
);
76 std::wstring language_
;
77 ui::DataPack
* data_pack_
;
79 HINSTANCE locale_dll_handle_
;
82 #endif // CHROME_FRAME_SIMPLE_RESOURCE_LOADER_H_