Chromium Code Reviews| 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/command_line.h" | |
| 7 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "chromeos/chromeos_switches.h" | |
| 8 | 10 |
| 9 namespace chromeos { | 11 namespace chromeos { |
| 10 namespace { | 12 namespace { |
| 11 const char kExtensionIMEPrefix[] = "_ext_ime_"; | 13 const char kExtensionIMEPrefix[] = "_ext_ime_"; |
| 12 const int kExtensionIMEPrefixLength = | 14 const int kExtensionIMEPrefixLength = |
| 13 sizeof(kExtensionIMEPrefix) / sizeof(kExtensionIMEPrefix[0]) - 1; | 15 sizeof(kExtensionIMEPrefix) / sizeof(kExtensionIMEPrefix[0]) - 1; |
| 14 const char kComponentExtensionIMEPrefix[] = "_comp_ime_"; | 16 const char kComponentExtensionIMEPrefix[] = "_comp_ime_"; |
| 15 const char kExtensionXkbIdPrefix[] = | 17 const char kExtensionXkbIdPrefix[] = |
| 16 "_comp_ime_fgoepimhcoialccpbmpnnblemnepkkao"; | 18 "_comp_ime_fgoepimhcoialccpbmpnnblemnepkkao"; |
| 17 const int kComponentExtensionIMEPrefixLength = | 19 const int kComponentExtensionIMEPrefixLength = |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 45 } | 47 } |
| 46 if (IsComponentExtensionIME(input_method_id) && | 48 if (IsComponentExtensionIME(input_method_id) && |
| 47 input_method_id.size() >= kComponentExtensionIMEPrefixLength + | 49 input_method_id.size() >= kComponentExtensionIMEPrefixLength + |
| 48 kExtensionIdLength) { | 50 kExtensionIdLength) { |
| 49 return input_method_id.substr(kComponentExtensionIMEPrefixLength, | 51 return input_method_id.substr(kComponentExtensionIMEPrefixLength, |
| 50 kExtensionIdLength); | 52 kExtensionIdLength); |
| 51 } | 53 } |
| 52 return ""; | 54 return ""; |
| 53 } | 55 } |
| 54 | 56 |
| 57 std::string GetInputMethodIDByKeyboardLayout( | |
| 58 const std::string& keyboard_layout_id) { | |
| 59 bool migrate = IsMigrateXkbEnabled(); | |
| 60 if (IsKeyboardLayoutExtension(keyboard_layout_id)) { | |
| 61 if (migrate) | |
| 62 return keyboard_layout_id; | |
| 63 return keyboard_layout_id.substr(arraysize(kExtensionXkbIdPrefix) - 1); | |
| 64 } | |
| 65 if (migrate && StartsWithASCII(keyboard_layout_id, "xkb:", true)) | |
| 66 return kExtensionXkbIdPrefix + keyboard_layout_id; | |
| 67 return keyboard_layout_id; | |
| 68 } | |
| 69 | |
| 55 bool IsExtensionIME(const std::string& input_method_id) { | 70 bool IsExtensionIME(const std::string& input_method_id) { |
| 56 return StartsWithASCII(input_method_id, | 71 return StartsWithASCII(input_method_id, |
| 57 kExtensionIMEPrefix, | 72 kExtensionIMEPrefix, |
| 58 true); // Case sensitive. | 73 true); // Case sensitive. |
| 59 } | 74 } |
| 60 | 75 |
| 61 bool IsComponentExtensionIME(const std::string& input_method_id) { | 76 bool IsComponentExtensionIME(const std::string& input_method_id) { |
| 62 return StartsWithASCII(input_method_id, | 77 return StartsWithASCII(input_method_id, |
| 63 kComponentExtensionIMEPrefix, | 78 kComponentExtensionIMEPrefix, |
| 64 true); // Case sensitive. | 79 true); // Case sensitive. |
| 65 } | 80 } |
| 66 | 81 |
| 67 bool IsMemberOfExtension(const std::string& input_method_id, | 82 bool IsMemberOfExtension(const std::string& input_method_id, |
| 68 const std::string& extension_id) { | 83 const std::string& extension_id) { |
| 69 return StartsWithASCII(input_method_id, | 84 return StartsWithASCII(input_method_id, |
| 70 kExtensionIMEPrefix + extension_id, | 85 kExtensionIMEPrefix + extension_id, |
| 71 true); // Case sensitive. | 86 true); // Case sensitive. |
| 72 } | 87 } |
| 73 | 88 |
| 74 bool IsKeyboardLayoutExtension(const std::string& input_method_id) { | 89 bool IsKeyboardLayoutExtension(const std::string& input_method_id) { |
| 75 return StartsWithASCII(input_method_id, kExtensionXkbIdPrefix, true); | 90 return StartsWithASCII(input_method_id, kExtensionXkbIdPrefix, true); |
| 76 } | 91 } |
| 77 | 92 |
| 93 bool IsMigrateXkbEnabled() { | |
|
Seigo Nonaka
2014/02/28 06:14:07
Sounds "UseWrappedExtensionKeyboardLayouts" clear
Shu Chen
2014/02/28 07:32:50
Done.
| |
| 94 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kMigrateXkb); | |
| 95 } | |
| 96 | |
| 78 } // namespace extension_ime_util | 97 } // namespace extension_ime_util |
| 79 } // namespace chromeos | 98 } // namespace chromeos |
| OLD | NEW |