1 // Copyright (c) 2012 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_OPTIONS_CHROMEOS_CROS_LANGUAGE_OPTIONS_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_CROS_LANGUAGE_OPTIONS_HANDLER_H_
8 #include "base/compiler_specific.h"
9 #include "chrome/browser/ui/webui/options/language_options_handler.h"
10 #include "chromeos/ime/component_extension_ime_manager.h"
11 #include "chromeos/ime/input_method_descriptor.h"
16 // GetUILanguageList() returns concatenated list of list of vendor languages
17 // followed by other languages. An entry with "code" attribute set to this value
18 // is inserted in between.
19 extern const char kVendorOtherLanguagesListDivider
[];
21 // Language options page UI handler for Chrome OS. For non-Chrome OS,
22 // see LanguageOptionsHnadler.
23 class CrosLanguageOptionsHandler
24 : public ::options::LanguageOptionsHandlerCommon
,
25 public ComponentExtensionIMEManager::Observer
{
27 CrosLanguageOptionsHandler();
28 virtual ~CrosLanguageOptionsHandler();
30 // OptionsPageUIHandler implementation.
31 virtual void GetLocalizedValues(
32 base::DictionaryValue
* localized_strings
) OVERRIDE
;
34 // DOMMessageHandler implementation.
35 virtual void RegisterMessages() OVERRIDE
;
37 // The following static methods are public for ease of testing.
39 // Gets the list of input methods from the given input descriptors.
40 // The return value will look like:
41 // [{'id': 'pinyin', 'displayName': 'Pinyin',
42 // 'languageCodeSet': {'zh-CW': true}}, ...]
44 // Note that true in languageCodeSet does not mean anything. We just use
45 // the dictionary as a set.
46 static base::ListValue
* GetInputMethodList(
47 const input_method::InputMethodDescriptors
& descriptors
);
49 // Gets the list of accept languages with the given input descriptors.
50 // Listed languages will be used as Accept-Language header.
51 // The return value will look like:
52 // [{'code': 'fi', 'displayName': 'Finnish', 'nativeDisplayName': 'suomi'},
54 // "most relevant" languages, as set in initial_locale in VPD, will be first
56 static base::ListValue
* GetAcceptLanguageList(
57 const input_method::InputMethodDescriptors
& descriptors
);
59 // Gets the list of UI languages with the given input descriptors.
60 // The return value will look like:
61 // [{'code': 'fi', 'displayName': 'Finnish', 'nativeDisplayName': 'suomi'},
63 // "most relevant" languages, as set in initial_locale in VPD, will be first
65 // An entry with "code" attribute set to kVendorOtherLanguagesListDivider is
66 // used as a divider to separate "most relevant" languages against other.
67 static base::ListValue
* GetUILanguageList(
68 const input_method::InputMethodDescriptors
& descriptors
);
70 // Converts input method descriptors to the list of input methods.
71 // The return value will look like:
72 // [{'id': '_ext_ime_nejguenhnsnjnwychcnsdsdjketest',
73 // 'displayName': 'Sample IME'}, ...]
74 static base::ListValue
* ConvertInputMethodDescriptosToIMEList(
75 const input_method::InputMethodDescriptors
& descriptors
);
78 // LanguageOptionsHandlerCommon implementation.
79 virtual base::string16
GetProductName() OVERRIDE
;
80 virtual void SetApplicationLocale(const std::string
& language_code
) OVERRIDE
;
82 // Called when the sign-out button is clicked.
83 void RestartCallback(const base::ListValue
* args
);
85 // Called when the input method is disabled.
86 // |args| will contain the input method ID as string (ex. "mozc").
87 void InputMethodDisableCallback(const base::ListValue
* args
);
89 // Called when the input method is enabled.
90 // |args| will contain the input method ID as string (ex. "mozc").
91 void InputMethodEnableCallback(const base::ListValue
* args
);
93 // Called when the input method options page is opened.
94 // |args| will contain the input method ID as string (ex. "mozc").
95 void InputMethodOptionsOpenCallback(const base::ListValue
* args
);
97 // ComponentExtensionIMEManager::Observer override.
98 virtual void OnImeComponentExtensionInitialized() OVERRIDE
;
100 // Gets the list of languages with |descriptors| based on
101 // |base_language_codes|.
102 // |insert_divider| means to insert entry with "code" attribute set to
103 // kVendorOtherLanguagesListDivider between "most relevant" languages and
105 static base::ListValue
* GetLanguageListInternal(
106 const input_method::InputMethodDescriptors
& descriptors
,
107 const std::vector
<std::string
>& base_language_codes
,
108 bool insert_divider
);
110 // OptionsPageUIHandler implementation.
111 virtual void InitializePage() OVERRIDE
;
113 // True if the component extension list was appended into input method list.
114 bool composition_extension_appended_
;
116 // True if this page was initialized.
117 bool is_page_initialized_
;
119 DISALLOW_COPY_AND_ASSIGN(CrosLanguageOptionsHandler
);
122 } // namespace options
123 } // namespace chromeos
125 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_CROS_LANGUAGE_OPTIONS_HANDLER_H_