OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_L10N_UTIL_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_L10N_UTIL_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_L10N_UTIL_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_L10N_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/strings/string16.h" | |
14 #include "chrome/browser/chromeos/base/locale_util.h" | |
15 | 13 |
16 namespace base { | 14 namespace base { |
17 class DictionaryValue; | 15 class DictionaryValue; |
18 class ListValue; | 16 class ListValue; |
19 } | 17 } |
20 | 18 |
21 namespace chromeos { | 19 namespace chromeos { |
22 | 20 |
23 typedef base::Callback<void(scoped_ptr<base::ListValue> /* new_language_list */, | |
24 std::string /* new_language_list_locale */, | |
25 std::string /* new_selected_language */)> | |
26 UILanguageListResolvedCallback; | |
27 | |
28 // GetUILanguageList() returns a concatenated list of the most relevant | 21 // GetUILanguageList() returns a concatenated list of the most relevant |
29 // languages followed by all others. An entry with its "code" attribute set to | 22 // languages followed by all others. An entry with its "code" attribute set to |
30 // this value is inserted in between. | 23 // this value is inserted in between. |
31 extern const char kMostRelevantLanguagesDivider[]; | 24 extern const char kMostRelevantLanguagesDivider[]; |
32 | 25 |
33 // Utility methods for retrieving lists of supported locales and input methods / | 26 // Utility methods for retrieving lists of supported locales and input methods / |
34 // keyboard layouts during OOBE and on the login screen. | 27 // keyboard layouts during OOBE and on the login screen. |
35 | 28 |
36 // Return a list of languages in which the UI can be shown. Each list entry is a | 29 // Return a list of languages in which the UI can be shown. Each list entry is a |
37 // dictionary that contains data such as the language's locale code and a | 30 // dictionary that contains data such as the language's locale code and a |
38 // display name. The list will consist of the |most_relevant_language_codes|, | 31 // display name. The list will consist of the |most_relevant_language_codes|, |
39 // followed by a divider and all other supported languages after that. If | 32 // followed by a divider and all other supported languages after that. If |
40 // |most_relevant_language_codes| is NULL, the most relevant languages are read | 33 // |most_relevant_language_codes| is NULL, the most relevant languages are read |
41 // from initial_locale in VPD. If |selected| matches the locale code of any | 34 // from initial_locale in VPD. If |selected| matches the locale code of any |
42 // entry in the resulting list, that entry will be marked as selected. | 35 // entry in the resulting list, that entry will be marked as selected. |
43 scoped_ptr<base::ListValue> GetUILanguageList( | 36 scoped_ptr<base::ListValue> GetUILanguageList( |
44 const std::vector<std::string>* most_relevant_language_codes, | 37 const std::vector<std::string>* most_relevant_language_codes, |
45 const std::string& selected); | 38 const std::string& selected); |
46 | 39 |
47 // Must be called on UI thread. Runs GetUILanguageList(), on Blocking Pool, | |
48 // and calls |callback| on UI thread with result. | |
49 // If |language_switch_result| is null, assume current browser locale is already | |
50 // correct and has been successfully loaded. | |
51 void ResolveUILanguageList( | |
52 scoped_ptr<locale_util::LanguageSwitchResult> language_switch_result, | |
53 UILanguageListResolvedCallback callback); | |
54 | |
55 // Returns a minimal list of UI languages, which consists of active language | |
56 // only. It is used as a placeholder until ResolveUILanguageList() finishes | |
57 // on BlockingPool. | |
58 scoped_ptr<base::ListValue> GetMinimalUILanguageList(); | |
59 | |
60 // Returns the most first entry of |most_relevant_language_codes| that is | 40 // Returns the most first entry of |most_relevant_language_codes| that is |
61 // actually available (present in |available_locales|). If none of the entries | 41 // actually available (present in |available_locales|). If none of the entries |
62 // are present in |available_locales|, returns the |fallback_locale|. | 42 // are present in |available_locales|, returns the |fallback_locale|. |
63 std::string FindMostRelevantLocale( | 43 std::string FindMostRelevantLocale( |
64 const std::vector<std::string>& most_relevant_language_codes, | 44 const std::vector<std::string>& most_relevant_language_codes, |
65 const base::ListValue& available_locales, | 45 const base::ListValue& available_locales, |
66 const std::string& fallback_locale); | 46 const std::string& fallback_locale); |
67 | 47 |
68 // Return a list of supported accept languages. The listed languages can be used | 48 // Return a list of supported accept languages. The listed languages can be used |
69 // in the Accept-Language header. The return value will look like: | 49 // in the Accept-Language header. The return value will look like: |
70 // [{'code': 'fi', 'displayName': 'Finnish', 'nativeDisplayName': 'suomi'}, ...] | 50 // [{'code': 'fi', 'displayName': 'Finnish', 'nativeDisplayName': 'suomi'}, ...] |
71 // The most relevant languages, read from initial_locale in VPD, will be first | 51 // The most relevant languages, read from initial_locale in VPD, will be first |
72 // in the list. | 52 // in the list. |
73 scoped_ptr<base::ListValue> GetAcceptLanguageList(); | 53 scoped_ptr<base::ListValue> GetAcceptLanguageList(); |
74 | 54 |
75 // Return a list of keyboard layouts that can be used for |locale| on the login | 55 // Return a list of keyboard layouts that can be used for |locale| on the login |
76 // screen. Each list entry is a dictionary that contains data such as an ID and | 56 // screen. Each list entry is a dictionary that contains data such as an ID and |
77 // a display name. The list will consist of the device's hardware layouts, | 57 // a display name. The list will consist of the device's hardware layouts, |
78 // followed by a divider and locale-specific keyboard layouts, if any. The list | 58 // followed by a divider and locale-specific keyboard layouts, if any. The list |
79 // will also always contain the US keyboard layout. If |selected| matches the ID | 59 // will also always contain the US keyboard layout. If |selected| matches the ID |
80 // of any entry in the resulting list, that entry will be marked as selected. | 60 // of any entry in the resulting list, that entry will be marked as selected. |
81 // In addition to returning the list of keyboard layouts, this function also | 61 // In addition to returning the list of keyboard layouts, this function also |
82 // activates them if |activate_keyboards| is true, so that they can be selected | 62 // activates them so that they can be selected by the user (e.g. by cycling |
83 // by the user (e.g. by cycling through keyboard layouts via keyboard | 63 // through keyboard layouts via keyboard shortcuts). |
84 // shortcuts). | |
85 scoped_ptr<base::ListValue> GetAndActivateLoginKeyboardLayouts( | 64 scoped_ptr<base::ListValue> GetAndActivateLoginKeyboardLayouts( |
86 const std::string& locale, | 65 const std::string& locale, |
87 const std::string& selected, | 66 const std::string& selected); |
88 bool activate_keyboards); | |
89 | 67 |
90 // Invokes |callback| with a list of keyboard layouts that can be used for | 68 // Invokes |callback| with a list of keyboard layouts that can be used for |
91 // |locale|. Each list entry is a dictionary that contains data such as an ID | 69 // |locale|. Each list entry is a dictionary that contains data such as an ID |
92 // and a display name. The list will consist of the device's hardware layouts, | 70 // and a display name. The list will consist of the device's hardware layouts, |
93 // followed by a divider and locale-specific keyboard layouts, if any. All | 71 // followed by a divider and locale-specific keyboard layouts, if any. All |
94 // layouts supported for |locale| are returned, including those that produce | 72 // layouts supported for |locale| are returned, including those that produce |
95 // non-Latin characters by default. | 73 // non-Latin characters by default. |
96 typedef base::Callback<void(scoped_ptr<base::ListValue>)> | 74 typedef base::Callback<void(scoped_ptr<base::ListValue>)> |
97 GetKeyboardLayoutsForLocaleCallback; | 75 GetKeyboardLayoutsForLocaleCallback; |
98 void GetKeyboardLayoutsForLocale( | 76 void GetKeyboardLayoutsForLocale( |
99 const GetKeyboardLayoutsForLocaleCallback& callback, | 77 const GetKeyboardLayoutsForLocaleCallback& callback, |
100 const std::string& locale); | 78 const std::string& locale); |
101 | 79 |
102 // Returns the current keyboard layout, expressed as a dictionary that contains | 80 // Returns the current keyboard layout, expressed as a dictionary that contains |
103 // data such as an ID and a display name. | 81 // data such as an ID and a display name. |
104 scoped_ptr<base::DictionaryValue> GetCurrentKeyboardLayout(); | 82 scoped_ptr<base::DictionaryValue> GetCurrentKeyboardLayout(); |
105 | 83 |
106 } // namespace chromeos | 84 } // namespace chromeos |
107 | 85 |
108 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_L10N_UTIL_H_ | 86 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_L10N_UTIL_H_ |
OLD | NEW |