| 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 "chromeos/ime/extension_ime_util.h" | 5 #include "chromeos/ime/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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 if (IsComponentExtensionIME(input_method_id) && | 48 if (IsComponentExtensionIME(input_method_id) && |
| 49 input_method_id.size() >= kComponentExtensionIMEPrefixLength + | 49 input_method_id.size() >= kComponentExtensionIMEPrefixLength + |
| 50 kExtensionIdLength) { | 50 kExtensionIdLength) { |
| 51 return input_method_id.substr(kComponentExtensionIMEPrefixLength, | 51 return input_method_id.substr(kComponentExtensionIMEPrefixLength, |
| 52 kExtensionIdLength); | 52 kExtensionIdLength); |
| 53 } | 53 } |
| 54 return ""; | 54 return ""; |
| 55 } | 55 } |
| 56 | 56 |
| 57 std::string GetEngineIDByInputMethodID(const std::string& input_method_id) { |
| 58 if (IsComponentExtensionIME(input_method_id)) |
| 59 return input_method_id.substr(kComponentExtensionIMEPrefixLength + |
| 60 kExtensionIdLength); |
| 61 if (IsExtensionIME(input_method_id)) |
| 62 return input_method_id.substr(kExtensionIMEPrefixLength + |
| 63 kExtensionIdLength); |
| 64 return input_method_id; |
| 65 } |
| 66 |
| 57 std::string GetInputMethodIDByEngineID(const std::string& engine_id) { | 67 std::string GetInputMethodIDByEngineID(const std::string& engine_id) { |
| 58 if (StartsWithASCII(engine_id, kComponentExtensionIMEPrefix, true) || | 68 if (StartsWithASCII(engine_id, kComponentExtensionIMEPrefix, true) || |
| 59 StartsWithASCII(engine_id, kExtensionIMEPrefix, true)) { | 69 StartsWithASCII(engine_id, kExtensionIMEPrefix, true)) { |
| 60 return engine_id; | 70 return engine_id; |
| 61 } | 71 } |
| 62 if (StartsWithASCII(engine_id, "xkb:", true)) | 72 if (StartsWithASCII(engine_id, "xkb:", true)) |
| 63 return GetComponentInputMethodID(kXkbExtensionId, engine_id); | 73 return GetComponentInputMethodID(kXkbExtensionId, engine_id); |
| 64 if (StartsWithASCII(engine_id, "vkd_", true)) | 74 if (StartsWithASCII(engine_id, "vkd_", true)) |
| 65 return GetComponentInputMethodID(kM17nExtensionId, engine_id); | 75 return GetComponentInputMethodID(kM17nExtensionId, engine_id); |
| 66 if (StartsWithASCII(engine_id, "nacl_mozc_", true)) | 76 if (StartsWithASCII(engine_id, "nacl_mozc_", true)) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 kExtensionIMEPrefix + extension_id, | 114 kExtensionIMEPrefix + extension_id, |
| 105 true); // Case sensitive. | 115 true); // Case sensitive. |
| 106 } | 116 } |
| 107 | 117 |
| 108 bool IsKeyboardLayoutExtension(const std::string& input_method_id) { | 118 bool IsKeyboardLayoutExtension(const std::string& input_method_id) { |
| 109 std::string prefix = kComponentExtensionIMEPrefix; | 119 std::string prefix = kComponentExtensionIMEPrefix; |
| 110 return StartsWithASCII(input_method_id, prefix + kXkbExtensionId, true); | 120 return StartsWithASCII(input_method_id, prefix + kXkbExtensionId, true); |
| 111 } | 121 } |
| 112 | 122 |
| 113 std::string MaybeGetLegacyXkbId(const std::string& input_method_id) { | 123 std::string MaybeGetLegacyXkbId(const std::string& input_method_id) { |
| 114 if (IsKeyboardLayoutExtension(input_method_id)) { | 124 if (IsKeyboardLayoutExtension(input_method_id)) |
| 115 size_t pos = input_method_id.find("xkb:"); | 125 return GetEngineIDByInputMethodID(input_method_id); |
| 116 if (pos != std::string::npos) | |
| 117 return input_method_id.substr(pos); | |
| 118 } | |
| 119 return input_method_id; | 126 return input_method_id; |
| 120 } | 127 } |
| 121 | 128 |
| 122 } // namespace extension_ime_util | 129 } // namespace extension_ime_util |
| 123 } // namespace chromeos | 130 } // namespace chromeos |
| OLD | NEW |