cros_language_options_handler.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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. 4 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_ 7 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" 12 13namespace chromeos { 14namespace options { 15 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. 19extern const char kVendorOtherLanguagesListDivider[]; 20 21// Language options page UI handler for Chrome OS. For non-Chrome OS, 22// see LanguageOptionsHnadler. 23class CrosLanguageOptionsHandler 24 : public ::options::LanguageOptionsHandlerCommon, 25 public ComponentExtensionIMEManager::Observer { 26 public: 27 CrosLanguageOptionsHandler(); 28 virtual ~CrosLanguageOptionsHandler(); 29 30 // OptionsPageUIHandler implementation. 31 virtual void GetLocalizedValues( 32 base::DictionaryValue* localized_strings) OVERRIDE; 33 34 // DOMMessageHandler implementation. 35 virtual void RegisterMessages() OVERRIDE; 36 37 // The following static methods are public for ease of testing. 38 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}}, ...] 43 // 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); 48 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'}, 53 // ...] 54 // "most relevant" languages, as set in initial_locale in VPD, will be first 55 // in the list. 56 static base::ListValue* GetAcceptLanguageList( 57 const input_method::InputMethodDescriptors& descriptors); 58 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'}, 62 // ...] 63 // "most relevant" languages, as set in initial_locale in VPD, will be first 64 // in the list. 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); 69 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); 76 77 private: 78 // LanguageOptionsHandlerCommon implementation. 79 virtual base::string16 GetProductName() OVERRIDE; 80 virtual void SetApplicationLocale(const std::string& language_code) OVERRIDE; 81 82 // Called when the sign-out button is clicked. 83 void RestartCallback(const base::ListValue* args); 84 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); 88 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); 92 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); 96 97 // ComponentExtensionIMEManager::Observer override. 98 virtual void OnImeComponentExtensionInitialized() OVERRIDE; 99 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 104 // other. 105 static base::ListValue* GetLanguageListInternal( 106 const input_method::InputMethodDescriptors& descriptors, 107 const std::vector<std::string>& base_language_codes, 108 bool insert_divider); 109 110 // OptionsPageUIHandler implementation. 111 virtual void InitializePage() OVERRIDE; 112 113 // True if the component extension list was appended into input method list. 114 bool composition_extension_appended_; 115 116 // True if this page was initialized. 117 bool is_page_initialized_; 118 119 DISALLOW_COPY_AND_ASSIGN(CrosLanguageOptionsHandler); 120}; 121 122} // namespace options 123} // namespace chromeos 124 125#endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_CROS_LANGUAGE_OPTIONS_HANDLER_H_ 126