Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / l10n_util.h
blobcf8cc5e20d0a59c62d5c3ec1e404a9b9bf70a244
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_L10N_UTIL_H_
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_L10N_UTIL_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string16.h"
14 #include "chrome/browser/chromeos/base/locale_util.h"
16 namespace base {
17 class DictionaryValue;
18 class ListValue;
21 namespace chromeos {
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;
28 // GetUILanguageList() returns a concatenated list of the most relevant
29 // languages followed by all others. An entry with its "code" attribute set to
30 // this value is inserted in between.
31 extern const char kMostRelevantLanguagesDivider[];
33 // Utility methods for retrieving lists of supported locales and input methods /
34 // keyboard layouts during OOBE and on the login screen.
36 // 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
38 // 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
40 // |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
42 // entry in the resulting list, that entry will be marked as selected.
43 scoped_ptr<base::ListValue> GetUILanguageList(
44 const std::vector<std::string>* most_relevant_language_codes,
45 const std::string& selected);
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);
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();
60 // Returns the most first entry of |most_relevant_language_codes| that is
61 // actually available (present in |available_locales|). If none of the entries
62 // are present in |available_locales|, returns the |fallback_locale|.
63 std::string FindMostRelevantLocale(
64 const std::vector<std::string>& most_relevant_language_codes,
65 const base::ListValue& available_locales,
66 const std::string& fallback_locale);
68 // 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:
70 // [{'code': 'fi', 'displayName': 'Finnish', 'nativeDisplayName': 'suomi'}, ...]
71 // The most relevant languages, read from initial_locale in VPD, will be first
72 // in the list.
73 scoped_ptr<base::ListValue> GetAcceptLanguageList();
75 // 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
77 // 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
79 // 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.
81 // 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
83 // by the user (e.g. by cycling through keyboard layouts via keyboard
84 // shortcuts).
85 scoped_ptr<base::ListValue> GetAndActivateLoginKeyboardLayouts(
86 const std::string& locale,
87 const std::string& selected,
88 bool activate_keyboards);
90 // 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
92 // 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
94 // layouts supported for |locale| are returned, including those that produce
95 // non-Latin characters by default.
96 typedef base::Callback<void(scoped_ptr<base::ListValue>)>
97 GetKeyboardLayoutsForLocaleCallback;
98 void GetKeyboardLayoutsForLocale(
99 const GetKeyboardLayoutsForLocaleCallback& callback,
100 const std::string& locale);
102 // Returns the current keyboard layout, expressed as a dictionary that contains
103 // data such as an ID and a display name.
104 scoped_ptr<base::DictionaryValue> GetCurrentKeyboardLayout();
106 } // namespace chromeos
108 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_L10N_UTIL_H_