Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / base / ime / chromeos / input_method_whitelist.cc
blob8086ef9144677f8cb9fb87cdd8bbb35e2009f1f2
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
3 // found in the LICENSE file.
5 #include "ui/base/ime/chromeos/input_method_whitelist.h"
7 #include <vector>
9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h"
11 #include "chromeos/ime/input_methods.h"
12 #include "ui/base/ime/chromeos/extension_ime_util.h"
13 #include "ui/base/ime/chromeos/input_method_descriptor.h"
15 namespace chromeos {
16 namespace input_method {
18 const char kLanguageDelimiter[] = ",";
20 InputMethodWhitelist::InputMethodWhitelist() {
21 for (size_t i = 0; i < arraysize(kInputMethods); ++i) {
22 supported_input_methods_.insert(kInputMethods[i].input_method_id);
26 InputMethodWhitelist::~InputMethodWhitelist() {
29 bool InputMethodWhitelist::InputMethodIdIsWhitelisted(
30 const std::string& input_method_id) const {
31 return supported_input_methods_.count(input_method_id) > 0;
34 scoped_ptr<InputMethodDescriptors>
35 InputMethodWhitelist::GetSupportedInputMethods() const {
36 scoped_ptr<InputMethodDescriptors> input_methods(new InputMethodDescriptors);
37 input_methods->reserve(arraysize(kInputMethods));
38 for (size_t i = 0; i < arraysize(kInputMethods); ++i) {
39 std::vector<std::string> layouts;
40 layouts.push_back(kInputMethods[i].xkb_layout_id);
42 std::vector<std::string> languages = base::SplitString(
43 kInputMethods[i].language_code, kLanguageDelimiter,
44 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
45 DCHECK(!languages.empty());
47 input_methods->push_back(InputMethodDescriptor(
48 extension_ime_util::GetInputMethodIDByEngineID(
49 kInputMethods[i].input_method_id),
50 "",
51 kInputMethods[i].indicator,
52 layouts,
53 languages,
54 kInputMethods[i].is_login_keyboard,
55 GURL(), // options page url.
56 GURL() // input view page url.
57 ));
59 return input_methods.Pass();
62 } // namespace input_method
63 } // namespace chromeos