| 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 #include "ui/base/ime/chromeos/extension_ime_util.h" | 5 #include "ui/base/ime/chromeos/extension_ime_util.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 | 8 |
| 9 namespace chromeos { | 9 namespace chromeos { |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 if (IsComponentExtensionIME(input_method_id)) | 54 if (IsComponentExtensionIME(input_method_id)) |
| 55 return input_method_id.substr(kComponentExtensionIMEPrefixLength + | 55 return input_method_id.substr(kComponentExtensionIMEPrefixLength + |
| 56 kExtensionIdLength); | 56 kExtensionIdLength); |
| 57 if (IsExtensionIME(input_method_id)) | 57 if (IsExtensionIME(input_method_id)) |
| 58 return input_method_id.substr(kExtensionIMEPrefixLength + | 58 return input_method_id.substr(kExtensionIMEPrefixLength + |
| 59 kExtensionIdLength); | 59 kExtensionIdLength); |
| 60 return input_method_id; | 60 return input_method_id; |
| 61 } | 61 } |
| 62 | 62 |
| 63 std::string GetInputMethodIDByEngineID(const std::string& engine_id) { | 63 std::string GetInputMethodIDByEngineID(const std::string& engine_id) { |
| 64 if (StartsWithASCII(engine_id, kComponentExtensionIMEPrefix, true) || | 64 if (base::StartsWithASCII(engine_id, kComponentExtensionIMEPrefix, true) || |
| 65 StartsWithASCII(engine_id, kExtensionIMEPrefix, true)) { | 65 base::StartsWithASCII(engine_id, kExtensionIMEPrefix, true)) { |
| 66 return engine_id; | 66 return engine_id; |
| 67 } | 67 } |
| 68 if (StartsWithASCII(engine_id, "xkb:", true)) | 68 if (base::StartsWithASCII(engine_id, "xkb:", true)) |
| 69 return GetComponentInputMethodID(kXkbExtensionId, engine_id); | 69 return GetComponentInputMethodID(kXkbExtensionId, engine_id); |
| 70 if (StartsWithASCII(engine_id, "vkd_", true)) | 70 if (base::StartsWithASCII(engine_id, "vkd_", true)) |
| 71 return GetComponentInputMethodID(kM17nExtensionId, engine_id); | 71 return GetComponentInputMethodID(kM17nExtensionId, engine_id); |
| 72 if (StartsWithASCII(engine_id, "nacl_mozc_", true)) | 72 if (base::StartsWithASCII(engine_id, "nacl_mozc_", true)) |
| 73 return GetComponentInputMethodID(kMozcExtensionId, engine_id); | 73 return GetComponentInputMethodID(kMozcExtensionId, engine_id); |
| 74 if (StartsWithASCII(engine_id, "hangul_", true)) | 74 if (base::StartsWithASCII(engine_id, "hangul_", true)) |
| 75 return GetComponentInputMethodID(kHangulExtensionId, engine_id); | 75 return GetComponentInputMethodID(kHangulExtensionId, engine_id); |
| 76 | 76 |
| 77 if (StartsWithASCII(engine_id, "zh-", true) && | 77 if (base::StartsWithASCII(engine_id, "zh-", true) && |
| 78 engine_id.find("pinyin") != std::string::npos) { | 78 engine_id.find("pinyin") != std::string::npos) { |
| 79 return GetComponentInputMethodID(kChinesePinyinExtensionId, engine_id); | 79 return GetComponentInputMethodID(kChinesePinyinExtensionId, engine_id); |
| 80 } | 80 } |
| 81 if (StartsWithASCII(engine_id, "zh-", true) && | 81 if (base::StartsWithASCII(engine_id, "zh-", true) && |
| 82 engine_id.find("zhuyin") != std::string::npos) { | 82 engine_id.find("zhuyin") != std::string::npos) { |
| 83 return GetComponentInputMethodID(kChineseZhuyinExtensionId, engine_id); | 83 return GetComponentInputMethodID(kChineseZhuyinExtensionId, engine_id); |
| 84 } | 84 } |
| 85 if (StartsWithASCII(engine_id, "zh-", true) && | 85 if (base::StartsWithASCII(engine_id, "zh-", true) && |
| 86 engine_id.find("cangjie") != std::string::npos) { | 86 engine_id.find("cangjie") != std::string::npos) { |
| 87 return GetComponentInputMethodID(kChineseCangjieExtensionId, engine_id); | 87 return GetComponentInputMethodID(kChineseCangjieExtensionId, engine_id); |
| 88 } | 88 } |
| 89 if (engine_id.find("-t-i0-") != std::string::npos) | 89 if (engine_id.find("-t-i0-") != std::string::npos) |
| 90 return GetComponentInputMethodID(kT13nExtensionId, engine_id); | 90 return GetComponentInputMethodID(kT13nExtensionId, engine_id); |
| 91 | 91 |
| 92 return engine_id; | 92 return engine_id; |
| 93 } | 93 } |
| 94 | 94 |
| 95 bool IsExtensionIME(const std::string& input_method_id) { | 95 bool IsExtensionIME(const std::string& input_method_id) { |
| 96 return StartsWithASCII(input_method_id, | 96 return base::StartsWithASCII(input_method_id, kExtensionIMEPrefix, |
| 97 kExtensionIMEPrefix, | 97 true /* Case sensitive */) && |
| 98 true /* Case sensitive */) && | 98 input_method_id.size() > |
| 99 input_method_id.size() > kExtensionIMEPrefixLength + | 99 kExtensionIMEPrefixLength + kExtensionIdLength; |
| 100 kExtensionIdLength; | |
| 101 } | 100 } |
| 102 | 101 |
| 103 bool IsComponentExtensionIME(const std::string& input_method_id) { | 102 bool IsComponentExtensionIME(const std::string& input_method_id) { |
| 104 return StartsWithASCII(input_method_id, | 103 return base::StartsWithASCII(input_method_id, kComponentExtensionIMEPrefix, |
| 105 kComponentExtensionIMEPrefix, | 104 true /* Case sensitive */) && |
| 106 true /* Case sensitive */) && | 105 input_method_id.size() > |
| 107 input_method_id.size() > kComponentExtensionIMEPrefixLength + | 106 kComponentExtensionIMEPrefixLength + kExtensionIdLength; |
| 108 kExtensionIdLength; | |
| 109 } | 107 } |
| 110 | 108 |
| 111 bool IsMemberOfExtension(const std::string& input_method_id, | 109 bool IsMemberOfExtension(const std::string& input_method_id, |
| 112 const std::string& extension_id) { | 110 const std::string& extension_id) { |
| 113 return StartsWithASCII(input_method_id, | 111 return base::StartsWithASCII(input_method_id, |
| 114 kExtensionIMEPrefix + extension_id, | 112 kExtensionIMEPrefix + extension_id, |
| 115 true /* Case sensitive */); | 113 true /* Case sensitive */); |
| 116 } | 114 } |
| 117 | 115 |
| 118 bool IsKeyboardLayoutExtension(const std::string& input_method_id) { | 116 bool IsKeyboardLayoutExtension(const std::string& input_method_id) { |
| 119 if (IsComponentExtensionIME(input_method_id)) | 117 if (IsComponentExtensionIME(input_method_id)) |
| 120 return StartsWithASCII(GetComponentIDByInputMethodID(input_method_id), | 118 return base::StartsWithASCII(GetComponentIDByInputMethodID(input_method_id), |
| 121 "xkb:", true); | 119 "xkb:", true); |
| 122 return false; | 120 return false; |
| 123 } | 121 } |
| 124 | 122 |
| 125 std::string MaybeGetLegacyXkbId(const std::string& input_method_id) { | 123 std::string MaybeGetLegacyXkbId(const std::string& input_method_id) { |
| 126 if (IsKeyboardLayoutExtension(input_method_id)) | 124 if (IsKeyboardLayoutExtension(input_method_id)) |
| 127 return GetComponentIDByInputMethodID(input_method_id); | 125 return GetComponentIDByInputMethodID(input_method_id); |
| 128 return input_method_id; | 126 return input_method_id; |
| 129 } | 127 } |
| 130 | 128 |
| 131 } // namespace extension_ime_util | 129 } // namespace extension_ime_util |
| 132 } // namespace chromeos | 130 } // namespace chromeos |
| OLD | NEW |