roll skia to 3843
[chromium-blink-merge.git] / chrome_frame / simple_resource_loader.h
blobceaf7f2c85f0ea8d07de05afa8372cd648f8acca
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.
4 //
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.
8 //
10 #ifndef CHROME_FRAME_SIMPLE_RESOURCE_LOADER_H_
11 #define CHROME_FRAME_SIMPLE_RESOURCE_LOADER_H_
13 #include <windows.h>
14 #include <string>
15 #include <vector>
17 #include "base/file_path.h"
18 #include "base/gtest_prod_util.h"
19 #include "base/memory/singleton.h"
21 namespace ui {
22 class DataPack;
23 } // namespace ui
25 class SimpleResourceLoader {
26 public:
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
42 // |language_tags|.
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(FilePath* locales_path);
48 // Returns false if |language_tag| is malformed.
49 static bool IsValidLanguageTag(const std::wstring& language_tag);
51 private:
52 SimpleResourceLoader();
53 ~SimpleResourceLoader();
55 // Finds the most-preferred resource dll and language pack for the laguages
56 // in |language_tags|
57 // in |locales_path|.
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 FilePath& locales_path,
64 HMODULE* dll_handle,
65 ui::DataPack** data_pack,
66 std::wstring* language);
68 // Returns the string resource identified by message_id from the currently
69 // loaded locale dll.
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_