Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: chromeos/ime/extension_ime_util.cc

Issue 309623005: Remove the flag g_use_wrapped_extension_keyboard_layouts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/ime/extension_ime_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 namespace { 11 namespace {
12
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 kPublicExtensionXkbIdPrefix[] =
16 "_comp_ime_fgoepimhcoialccpbmpnnblemnepkkao";
17 const char kInternalExtensionXkbIdPrefix[] =
18 "_comp_ime_jkghodnilhceideoidjikpgommlajknk";
19
20 const int kComponentExtensionIMEPrefixLength = 17 const int kComponentExtensionIMEPrefixLength =
21 sizeof(kComponentExtensionIMEPrefix) / 18 sizeof(kComponentExtensionIMEPrefix) /
22 sizeof(kComponentExtensionIMEPrefix[0]) - 1; 19 sizeof(kComponentExtensionIMEPrefix[0]) - 1;
23 const int kExtensionIdLength = 32; 20 const int kExtensionIdLength = 32;
24 // Hard coded to true. If the wrapped extension keyboards misbehaves, 21
25 // we can easily change this to false to switch back to legacy xkb keyboards.
26 bool g_use_wrapped_extension_keyboard_layouts = true;
27 } // namespace 22 } // namespace
28 23
29 namespace extension_ime_util { 24 namespace extension_ime_util {
25
30 std::string GetInputMethodID(const std::string& extension_id, 26 std::string GetInputMethodID(const std::string& extension_id,
31 const std::string& engine_id) { 27 const std::string& engine_id) {
32 DCHECK(!extension_id.empty()); 28 DCHECK(!extension_id.empty());
33 DCHECK(!engine_id.empty()); 29 DCHECK(!engine_id.empty());
34 return kExtensionIMEPrefix + extension_id + engine_id; 30 return kExtensionIMEPrefix + extension_id + engine_id;
35 } 31 }
36 32
37 std::string GetComponentInputMethodID(const std::string& extension_id, 33 std::string GetComponentInputMethodID(const std::string& extension_id,
38 const std::string& engine_id) { 34 const std::string& engine_id) {
39 DCHECK(!extension_id.empty()); 35 DCHECK(!extension_id.empty());
(...skipping 11 matching lines...) Expand all
51 } 47 }
52 if (IsComponentExtensionIME(input_method_id) && 48 if (IsComponentExtensionIME(input_method_id) &&
53 input_method_id.size() >= kComponentExtensionIMEPrefixLength + 49 input_method_id.size() >= kComponentExtensionIMEPrefixLength +
54 kExtensionIdLength) { 50 kExtensionIdLength) {
55 return input_method_id.substr(kComponentExtensionIMEPrefixLength, 51 return input_method_id.substr(kComponentExtensionIMEPrefixLength,
56 kExtensionIdLength); 52 kExtensionIdLength);
57 } 53 }
58 return ""; 54 return "";
59 } 55 }
60 56
61 std::string GetInputMethodIDByKeyboardLayout( 57 std::string GetInputMethodIDByEngineID(const std::string& engine_id) {
62 const std::string& keyboard_layout_id) { 58 if (StartsWithASCII(engine_id, kComponentExtensionIMEPrefix, true) ||
63 const char* kExtensionXkbIdPrefix = 59 StartsWithASCII(engine_id, kExtensionIMEPrefix, true)) {
64 #if defined(OFFICIAL_BUILD) 60 return engine_id;
65 kInternalExtensionXkbIdPrefix;
66 #else
67 kPublicExtensionXkbIdPrefix;
68 #endif
69 bool migrate = UseWrappedExtensionKeyboardLayouts();
70 if (IsKeyboardLayoutExtension(keyboard_layout_id)) {
71 std::string id = keyboard_layout_id.substr(
72 arraysize(kPublicExtensionXkbIdPrefix) - 1);
73 if (migrate)
74 return kExtensionXkbIdPrefix + id;
75 return id;
76 } 61 }
77 if (migrate && StartsWithASCII(keyboard_layout_id, "xkb:", true)) 62 if (StartsWithASCII(engine_id, "xkb:", true))
78 return kExtensionXkbIdPrefix + keyboard_layout_id; 63 return GetComponentInputMethodID(kXkbExtensionId, engine_id);
79 return keyboard_layout_id; 64 if (StartsWithASCII(engine_id, "vkd_", true))
65 return GetComponentInputMethodID(kM17nExtensionId, engine_id);
66 if (StartsWithASCII(engine_id, "nacl_mozc_", true))
67 return GetComponentInputMethodID(kMozcExtensionId, engine_id);
68 if (StartsWithASCII(engine_id, "hangul_", true))
69 return GetComponentInputMethodID(kHangulExtensionId, engine_id);
70
71 if (StartsWithASCII(engine_id, "zh-", true) &&
72 engine_id.find("pinyin") != std::string::npos) {
73 return GetComponentInputMethodID(kChinesePinyinExtensionId, engine_id);
74 }
75 if (StartsWithASCII(engine_id, "zh-", true) &&
76 engine_id.find("zhuyin") != std::string::npos) {
77 return GetComponentInputMethodID(kChineseZhuyinExtensionId, engine_id);
78 }
79 if (StartsWithASCII(engine_id, "zh-", true) &&
80 engine_id.find("cangjie") != std::string::npos) {
81 return GetComponentInputMethodID(kChineseCangjieExtensionId, engine_id);
82 }
83 if (engine_id.find("-t-i0-") != std::string::npos)
84 return GetComponentInputMethodID(kT13nExtensionId, engine_id);
85
86 return engine_id;
80 } 87 }
81 88
82 bool IsExtensionIME(const std::string& input_method_id) { 89 bool IsExtensionIME(const std::string& input_method_id) {
83 return StartsWithASCII(input_method_id, 90 return StartsWithASCII(input_method_id,
84 kExtensionIMEPrefix, 91 kExtensionIMEPrefix,
85 true); // Case sensitive. 92 true); // Case sensitive.
86 } 93 }
87 94
88 bool IsComponentExtensionIME(const std::string& input_method_id) { 95 bool IsComponentExtensionIME(const std::string& input_method_id) {
89 return StartsWithASCII(input_method_id, 96 return StartsWithASCII(input_method_id,
90 kComponentExtensionIMEPrefix, 97 kComponentExtensionIMEPrefix,
91 true); // Case sensitive. 98 true); // Case sensitive.
92 } 99 }
93 100
94 bool IsMemberOfExtension(const std::string& input_method_id, 101 bool IsMemberOfExtension(const std::string& input_method_id,
95 const std::string& extension_id) { 102 const std::string& extension_id) {
96 return StartsWithASCII(input_method_id, 103 return StartsWithASCII(input_method_id,
97 kExtensionIMEPrefix + extension_id, 104 kExtensionIMEPrefix + extension_id,
98 true); // Case sensitive. 105 true); // Case sensitive.
99 } 106 }
100 107
101 bool IsKeyboardLayoutExtension(const std::string& input_method_id) { 108 bool IsKeyboardLayoutExtension(const std::string& input_method_id) {
102 return StartsWithASCII(input_method_id, kPublicExtensionXkbIdPrefix, true) || 109 std::string prefix = kComponentExtensionIMEPrefix;
103 StartsWithASCII(input_method_id, kInternalExtensionXkbIdPrefix, true); 110 return StartsWithASCII(input_method_id, prefix + kXkbExtensionId, true);
104 }
105
106 bool UseWrappedExtensionKeyboardLayouts() {
107 return g_use_wrapped_extension_keyboard_layouts;
108 } 111 }
109 112
110 std::string MaybeGetLegacyXkbId(const std::string& input_method_id) { 113 std::string MaybeGetLegacyXkbId(const std::string& input_method_id) {
111 if (IsKeyboardLayoutExtension(input_method_id)) { 114 if (IsKeyboardLayoutExtension(input_method_id)) {
112 size_t pos = input_method_id.find("xkb:"); 115 size_t pos = input_method_id.find("xkb:");
113 if (pos != std::string::npos) 116 if (pos != std::string::npos)
114 return input_method_id.substr(pos); 117 return input_method_id.substr(pos);
115 } 118 }
116 return input_method_id; 119 return input_method_id;
117 } 120 }
118 121
119 ScopedUseExtensionKeyboardFlagForTesting::
120 ScopedUseExtensionKeyboardFlagForTesting(bool new_flag)
121 : auto_reset_(&g_use_wrapped_extension_keyboard_layouts, new_flag) {
122 }
123
124 ScopedUseExtensionKeyboardFlagForTesting::
125 ~ScopedUseExtensionKeyboardFlagForTesting() {
126 }
127
128 } // namespace extension_ime_util 122 } // namespace extension_ime_util
129 } // namespace chromeos 123 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/ime/extension_ime_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698