| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CHROMEOS_IME_EXTENSION_IME_UTIL_H_ | 5 #ifndef CHROMEOS_IME_EXTENSION_IME_UTIL_H_ |
| 6 #define CHROMEOS_IME_EXTENSION_IME_UTIL_H_ | 6 #define CHROMEOS_IME_EXTENSION_IME_UTIL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| 11 #include "chromeos/chromeos_export.h" | 11 #include "chromeos/chromeos_export.h" |
| 12 | 12 |
| 13 namespace chromeos { | 13 namespace chromeos { |
| 14 | 14 |
| 15 // Extension IME related utilities. | 15 // Extension IME related utilities. |
| 16 namespace extension_ime_util { | 16 namespace extension_ime_util { |
| 17 | 17 |
| 18 #if defined(OFFICIAL_BUILD) |
| 19 const char kXkbExtensionId[] = "jkghodnilhceideoidjikpgommlajknk"; |
| 20 const char kM17nExtensionId[] = "habcdindjejkmepknlhkkloncjcpcnbf"; |
| 21 const char kHangulExtensionId[] = "bdgdidmhaijohebebipajioienkglgfo"; |
| 22 const char kMozcExtensionId[] = "gjaehgfemfahhmlgpdfknkhdnemmolop"; |
| 23 const char kT13nExtensionId[] = "gjaehgfemfahhmlgpdfknkhdnemmolop"; |
| 24 const char kChinesePinyinExtensionId[] = "gjaehgfemfahhmlgpdfknkhdnemmolop"; |
| 25 const char kChineseZhuyinExtensionId[] = "gjaehgfemfahhmlgpdfknkhdnemmolop"; |
| 26 const char kChineseCangjieExtensionId[] = "gjaehgfemfahhmlgpdfknkhdnemmolop"; |
| 27 #else |
| 28 const char kXkbExtensionId[] = "fgoepimhcoialccpbmpnnblemnepkkao"; |
| 29 const char kM17nExtensionId[] = "jhffeifommiaekmbkkjlpmilogcfdohp"; |
| 30 const char kHangulExtensionId[] = "bdgdidmhaijohebebipajioienkglgfo"; |
| 31 const char kMozcExtensionId[] = "bbaiamgfapehflhememkfglaehiobjnk"; |
| 32 const char kT13nExtensionId[] = "gjaehgfemfahhmlgpdfknkhdnemmolop"; |
| 33 const char kChinesePinyinExtensionId[] = "cpgalbafkoofkjmaeonnfijgpfennjjn"; |
| 34 const char kChineseZhuyinExtensionId[] = "ekbifjdfhkmdeeajnolmgdlmkllopefi"; |
| 35 const char kChineseCangjieExtensionId[] = "aeebooiibjahgpgmhkeocbeekccfknbj"; |
| 36 #endif |
| 37 |
| 18 // Returns InputMethodID for |engine_id| in |extension_id| of extension IME. | 38 // Returns InputMethodID for |engine_id| in |extension_id| of extension IME. |
| 19 // This function does not check |extension_id| is installed extension IME nor | 39 // This function does not check |extension_id| is installed extension IME nor |
| 20 // |engine_id| is really a member of |extension_id|. | 40 // |engine_id| is really a member of |extension_id|. |
| 21 std::string CHROMEOS_EXPORT GetInputMethodID(const std::string& extension_id, | 41 std::string CHROMEOS_EXPORT GetInputMethodID(const std::string& extension_id, |
| 22 const std::string& engine_id); | 42 const std::string& engine_id); |
| 23 | 43 |
| 24 // Returns InputMethodID for |engine_id| in |extension_id| of component | 44 // Returns InputMethodID for |engine_id| in |extension_id| of component |
| 25 // extension IME, This function does not check |extension_id| is component one | 45 // extension IME, This function does not check |extension_id| is component one |
| 26 // nor |engine_id| is really a member of |extension_id|. | 46 // nor |engine_id| is really a member of |extension_id|. |
| 27 std::string CHROMEOS_EXPORT GetComponentInputMethodID( | 47 std::string CHROMEOS_EXPORT GetComponentInputMethodID( |
| 28 const std::string& extension_id, | 48 const std::string& extension_id, |
| 29 const std::string& engine_id); | 49 const std::string& engine_id); |
| 30 | 50 |
| 31 // Returns extension ID if |input_method_id| is extension IME ID or component | 51 // Returns extension ID if |input_method_id| is extension IME ID or component |
| 32 // extension IME ID. Otherwise returns an empty string (""). | 52 // extension IME ID. Otherwise returns an empty string (""). |
| 33 std::string CHROMEOS_EXPORT GetExtensionIDFromInputMethodID( | 53 std::string CHROMEOS_EXPORT GetExtensionIDFromInputMethodID( |
| 34 const std::string& input_method_id); | 54 const std::string& input_method_id); |
| 35 | 55 |
| 36 // Returns InputMethodID from keyboard layout (xkb) id (e.g. xkb:fr:fra). | 56 // Returns InputMethodID from engine id (e.g. xkb:fr:fra), or returns itself if |
| 37 std::string CHROMEOS_EXPORT GetInputMethodIDByKeyboardLayout( | 57 // the |engine_id| is not a known engine id. |
| 38 const std::string& keyboard_layout_id); | 58 // The caller must make sure the |engine_id| is from system input methods |
| 59 // instead of 3rd party input methods. |
| 60 std::string CHROMEOS_EXPORT GetInputMethodIDByEngineID( |
| 61 const std::string& engine_id); |
| 39 | 62 |
| 40 // Returns true if |input_method_id| is extension IME ID. This function does not | 63 // Returns true if |input_method_id| is extension IME ID. This function does not |
| 41 // check |input_method_id| is installed extension IME. | 64 // check |input_method_id| is installed extension IME. |
| 42 bool CHROMEOS_EXPORT IsExtensionIME(const std::string& input_method_id); | 65 bool CHROMEOS_EXPORT IsExtensionIME(const std::string& input_method_id); |
| 43 | 66 |
| 44 // Returns true if |input_method_id| is component extension IME ID. This | 67 // Returns true if |input_method_id| is component extension IME ID. This |
| 45 // function does not check |input_method_id| is really whitelisted one or not. | 68 // function does not check |input_method_id| is really whitelisted one or not. |
| 46 // If you want to check |input_method_id| is whitelisted component extension | 69 // If you want to check |input_method_id| is whitelisted component extension |
| 47 // IME, please use ComponentExtensionIMEManager::IsWhitelisted instead. | 70 // IME, please use ComponentExtensionIMEManager::IsWhitelisted instead. |
| 48 bool CHROMEOS_EXPORT IsComponentExtensionIME( | 71 bool CHROMEOS_EXPORT IsComponentExtensionIME( |
| 49 const std::string& input_method_id); | 72 const std::string& input_method_id); |
| 50 | 73 |
| 51 // Returns true if the |input_method| is a member of |extension_id| of extension | 74 // Returns true if the |input_method| is a member of |extension_id| of extension |
| 52 // IME, otherwise returns false. | 75 // IME, otherwise returns false. |
| 53 bool CHROMEOS_EXPORT IsMemberOfExtension(const std::string& input_method_id, | 76 bool CHROMEOS_EXPORT IsMemberOfExtension(const std::string& input_method_id, |
| 54 const std::string& extension_id); | 77 const std::string& extension_id); |
| 55 | 78 |
| 56 // Returns true if the |input_method_id| is the extension based xkb keyboard, | 79 // Returns true if the |input_method_id| is the extension based xkb keyboard, |
| 57 // otherwise returns false. | 80 // otherwise returns false. |
| 58 bool CHROMEOS_EXPORT IsKeyboardLayoutExtension( | 81 bool CHROMEOS_EXPORT IsKeyboardLayoutExtension( |
| 59 const std::string& input_method_id); | 82 const std::string& input_method_id); |
| 60 | 83 |
| 61 // Returns true to use the wrapped extension keyboards instead of the legacy | |
| 62 // xkb keyboards, returns false otherwise. | |
| 63 bool CHROMEOS_EXPORT UseWrappedExtensionKeyboardLayouts(); | |
| 64 | |
| 65 // Gets legacy xkb id (e.g. xkb:us::eng) from the new extension based xkb id | 84 // Gets legacy xkb id (e.g. xkb:us::eng) from the new extension based xkb id |
| 66 // (e.g. _comp_ime_...xkb:us::eng). If the given id is not prefixed with | 85 // (e.g. _comp_ime_...xkb:us::eng). If the given id is not prefixed with |
| 67 // 'xkb:', just return the same as the given id. | 86 // 'xkb:', just return the same as the given id. |
| 68 std::string CHROMEOS_EXPORT MaybeGetLegacyXkbId( | 87 std::string CHROMEOS_EXPORT MaybeGetLegacyXkbId( |
| 69 const std::string& input_method_id); | 88 const std::string& input_method_id); |
| 70 | 89 |
| 71 // The scoped class to temporarily set the flag to use extension based xkb | |
| 72 // keyboards for testing. | |
| 73 class CHROMEOS_EXPORT ScopedUseExtensionKeyboardFlagForTesting { | |
| 74 public: | |
| 75 explicit ScopedUseExtensionKeyboardFlagForTesting(bool new_flag); | |
| 76 ~ScopedUseExtensionKeyboardFlagForTesting(); | |
| 77 | |
| 78 private: | |
| 79 base::AutoReset<bool> auto_reset_; | |
| 80 }; | |
| 81 | |
| 82 } // namespace extension_ime_util | 90 } // namespace extension_ime_util |
| 83 | 91 |
| 84 } // namespace chromeos | 92 } // namespace chromeos |
| 85 | 93 |
| 86 #endif // CHROMEOS_IME_EXTENSION_IME_UTIL_H_ | 94 #endif // CHROMEOS_IME_EXTENSION_IME_UTIL_H_ |
| OLD | NEW |