Blink roll 4c8283bce6eabb7c55b4f97e105ac8ad36e6d0b8:1c9fc9d2d9015e265ecc3ec60cd83ad74...
[chromium-blink-merge.git] / chromeos / ime / input_method_descriptor.cc
blob6b9f42b0a51174d586b25999f8674728c88ae403
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 "chromeos/ime/input_method_descriptor.h"
7 #include <sstream>
9 #include "base/logging.h"
10 #include "base/strings/string_split.h"
11 #include "base/strings/string_util.h"
12 #include "chromeos/ime/extension_ime_util.h"
13 #include "url/gurl.h"
15 namespace chromeos {
16 namespace input_method {
18 InputMethodDescriptor::InputMethodDescriptor(
19 const std::string& id,
20 const std::string& name,
21 const std::string& indicator,
22 const std::vector<std::string>& keyboard_layouts,
23 const std::vector<std::string>& language_codes,
24 bool is_login_keyboard,
25 const GURL& options_page_url,
26 const GURL& input_view_url)
27 : id_(id),
28 name_(name),
29 keyboard_layouts_(keyboard_layouts),
30 language_codes_(language_codes),
31 indicator_(indicator),
32 is_login_keyboard_(is_login_keyboard),
33 options_page_url_(options_page_url),
34 input_view_url_(input_view_url) {
37 std::string InputMethodDescriptor::GetPreferredKeyboardLayout() const {
38 // TODO(nona): Investigate better way to guess the preferred layout
39 // http://crbug.com/170601.
40 return keyboard_layouts_.empty() ? "us" : keyboard_layouts_[0];
43 std::string InputMethodDescriptor::GetIndicator() const {
44 // If indicator is empty, use the first two character in its preferred
45 // keyboard layout or language code.
46 if (indicator_.empty()) {
47 if (extension_ime_util::IsKeyboardLayoutExtension(id_))
48 return StringToUpperASCII(GetPreferredKeyboardLayout().substr(0, 2));
49 DCHECK(language_codes_.size() > 0);
50 return StringToUpperASCII(language_codes_[0].substr(0, 2));
52 return indicator_;
55 InputMethodDescriptor::InputMethodDescriptor() {
58 InputMethodDescriptor::~InputMethodDescriptor() {
61 } // namespace input_method
62 } // namespace chromeos