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