• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chromeos/ime/input_method_whitelist.h"
6 
7 #include <vector>
8 
9 #include "base/strings/string_util.h"
10 #include "chromeos/ime/extension_ime_util.h"
11 #include "chromeos/ime/input_method_descriptor.h"
12 #include "chromeos/ime/input_methods.h"
13 
14 namespace chromeos {
15 namespace input_method {
16 
17 const char kLanguageDelimiter[] = ",";
18 
InputMethodWhitelist()19 InputMethodWhitelist::InputMethodWhitelist() {
20   for (size_t i = 0; i < arraysize(kInputMethods); ++i) {
21     supported_input_methods_.insert(kInputMethods[i].input_method_id);
22   }
23 }
24 
~InputMethodWhitelist()25 InputMethodWhitelist::~InputMethodWhitelist() {
26 }
27 
InputMethodIdIsWhitelisted(const std::string & input_method_id) const28 bool InputMethodWhitelist::InputMethodIdIsWhitelisted(
29     const std::string& input_method_id) const {
30   return supported_input_methods_.count(input_method_id) > 0;
31 }
32 
33 scoped_ptr<InputMethodDescriptors>
GetSupportedInputMethods() const34 InputMethodWhitelist::GetSupportedInputMethods() const {
35   scoped_ptr<InputMethodDescriptors> input_methods(new InputMethodDescriptors);
36   input_methods->reserve(arraysize(kInputMethods));
37   for (size_t i = 0; i < arraysize(kInputMethods); ++i) {
38     std::vector<std::string> layouts;
39     layouts.push_back(kInputMethods[i].xkb_layout_id);
40 
41     std::vector<std::string> languages;
42     Tokenize(kInputMethods[i].language_code, kLanguageDelimiter, &languages);
43     DCHECK(!languages.empty());
44 
45     input_methods->push_back(InputMethodDescriptor(
46         extension_ime_util::GetInputMethodIDByEngineID(
47             kInputMethods[i].input_method_id),
48         "",
49         kInputMethods[i].indicator,
50         layouts,
51         languages,
52         kInputMethods[i].is_login_keyboard,
53         GURL(), // options page url.
54         GURL() // input view page url.
55         ));
56   }
57   return input_methods.Pass();
58 }
59 
60 }  // namespace input_method
61 }  // namespace chromeos
62