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

Unified Diff: chromeos/ime/component_extension_ime_manager.cc

Issue 178343005: [IME] migrate the xkb ID to extension based xkb ID. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix browser_tests failures. Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chromeos/ime/component_extension_ime_manager.cc
diff --git a/chromeos/ime/component_extension_ime_manager.cc b/chromeos/ime/component_extension_ime_manager.cc
index b31470b52089e1fb9d39477b89327f2b5ff435d2..8dc4d26ec6a6a1a041c197473c44ea836fdb9aad 100644
--- a/chromeos/ime/component_extension_ime_manager.cc
+++ b/chromeos/ime/component_extension_ime_manager.cc
@@ -10,6 +10,76 @@
namespace chromeos {
+namespace {
+
+// The whitelist for enabling extension based xkb keyboards at login session.
+const char* kLoginLayoutWhitelist[] = {
+ "be",
+ "br",
+ "ca",
+ "ca(eng)",
+ "ca(multix)",
+ "ch",
+ "ch(fr)",
+ "cz",
+ "cz(qwerty)",
+ "de",
+ "de(neo)",
+ "dk",
+ "ee",
+ "es",
+ "es(cat)",
+ "fi",
+ "fr",
+ "gb(dvorak)",
+ "gb(extd)",
+ "hr",
+ "hu",
+ "is",
+ "it",
+ "jp",
+ "latam",
+ "lt",
+ "lv(apostrophe)",
+ "no",
+ "pl",
+ "pt",
+ "ro",
+ "se",
+ "si",
+ "tr",
+ "us",
+ "us(altgr-intl)",
+ "us(colemak)",
+ "us(dvorak)",
+ "us(intl)"
+};
+
+bool WhitelistContains(const char* s) {
Yuki 2014/03/03 05:59:06 Why don't you use std::set and its find() instead
Shu Chen 2014/03/03 08:24:37 At the time of writing this code, I didn't find a
+ int from = 0, to = arraysize(kLoginLayoutWhitelist);
+ while (from < to) {
+ int mid = from + (to - from) / 2;
+ int cmp = strcmp(s, kLoginLayoutWhitelist[mid]);
+ if (cmp > 0)
+ from = mid + 1;
+ else if (cmp < 0)
+ to = mid;
+ else
+ return true;
+ }
+ return false;
+}
+
+bool IsInLoginLayoutWhitelist(std::vector<std::string>& layouts) {
Yuki 2014/03/03 05:59:06 Use a const reference, otherwise a pointer type.
Shu Chen 2014/03/03 08:24:37 Done.
+ for (size_t i = 0; i < layouts.size(); ++i) {
+ if (WhitelistContains(layouts[i].c_str()))
+ return true;
+ }
+ return false;
+}
+
+} // namespace
+
ComponentExtensionEngine::ComponentExtensionEngine() {
}
@@ -134,19 +204,34 @@ input_method::InputMethodDescriptors
extension_ime_util::GetComponentInputMethodID(
component_extension_imes_[i].id,
component_extension_imes_[i].engines[j].engine_id);
+ std::vector<std::string>& layouts =
Yuki 2014/03/03 05:59:06 Can you make this a const reference? If you cannot
Shu Chen 2014/03/03 08:24:37 Done.
+ component_extension_imes_[i].engines[j].layouts;
result.push_back(
input_method::InputMethodDescriptor(
input_method_id,
component_extension_imes_[i].engines[j].display_name,
std::string(), // TODO(uekawa): Set short name.
- component_extension_imes_[i].engines[j].layouts,
+ layouts,
component_extension_imes_[i].engines[j].language_codes,
// Enables extension based xkb keyboards on login screen.
- extension_ime_util::IsKeyboardLayoutExtension(input_method_id),
+ extension_ime_util::IsKeyboardLayoutExtension(
+ input_method_id) && IsInLoginLayoutWhitelist(layouts),
component_extension_imes_[i].options_page_url,
component_extension_imes_[i].input_view_url));
}
}
+ if (result.size() == 0) {
+ // Testing environment won't install component extensions, so insert the
+ // fallback InputMethodDescriptor to the result for testing purpose.
Yuki 2014/03/03 05:59:06 Could you add a TODO comment? This code block shou
+ std::vector<std::string> layouts;
+ layouts.push_back("us");
+ std::vector<std::string> languages;
+ languages.push_back("en-US");
+ result.push_back(
+ input_method::InputMethodDescriptor(
+ extension_ime_util::GetInputMethodIDByKeyboardLayout("xkb:us::eng"),
+ "", "US", layouts, languages, true, GURL(), GURL()));
+ }
return result;
}

Powered by Google App Engine
This is Rietveld 408576698