OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/extensions/input_method_api.h" | 5 #include "chrome/browser/chromeos/extensions/input_method_api.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" | 9 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" |
10 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 10 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 } // namespace | 24 } // namespace |
25 | 25 |
26 namespace extensions { | 26 namespace extensions { |
27 | 27 |
28 ExtensionFunction::ResponseAction GetCurrentInputMethodFunction::Run() { | 28 ExtensionFunction::ResponseAction GetCurrentInputMethodFunction::Run() { |
29 #if !defined(OS_CHROMEOS) | 29 #if !defined(OS_CHROMEOS) |
30 EXTENSION_FUNCTION_VALIDATE(false); | 30 EXTENSION_FUNCTION_VALIDATE(false); |
31 #else | 31 #else |
32 chromeos::input_method::InputMethodManager* manager = | 32 chromeos::input_method::InputMethodManager* manager = |
33 chromeos::input_method::InputMethodManager::Get(); | 33 chromeos::input_method::InputMethodManager::Get(); |
34 return RespondNow(OneArgument( | 34 return RespondNow(OneArgument(new base::StringValue( |
35 new base::StringValue(manager->GetCurrentInputMethod().id()))); | 35 manager->GetActiveIMEState()->GetCurrentInputMethod().id()))); |
36 #endif | 36 #endif |
37 } | 37 } |
38 | 38 |
39 ExtensionFunction::ResponseAction SetCurrentInputMethodFunction::Run() { | 39 ExtensionFunction::ResponseAction SetCurrentInputMethodFunction::Run() { |
40 #if !defined(OS_CHROMEOS) | 40 #if !defined(OS_CHROMEOS) |
41 EXTENSION_FUNCTION_VALIDATE(false); | 41 EXTENSION_FUNCTION_VALIDATE(false); |
42 #else | 42 #else |
43 std::string new_input_method; | 43 std::string new_input_method; |
44 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &new_input_method)); | 44 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &new_input_method)); |
45 chromeos::input_method::InputMethodManager* manager = | 45 scoped_refptr<chromeos::input_method::InputMethodManager::State> ime_state = |
46 chromeos::input_method::InputMethodManager::Get(); | 46 chromeos::input_method::InputMethodManager::Get()->GetActiveIMEState(); |
47 const std::vector<std::string>& input_methods = | 47 const std::vector<std::string>& input_methods = |
48 manager->GetActiveInputMethodIds(); | 48 ime_state->GetActiveInputMethodIds(); |
49 for (size_t i = 0; i < input_methods.size(); ++i) { | 49 for (size_t i = 0; i < input_methods.size(); ++i) { |
50 const std::string& input_method = input_methods[i]; | 50 const std::string& input_method = input_methods[i]; |
51 if (input_method == new_input_method) { | 51 if (input_method == new_input_method) { |
52 manager->ChangeInputMethod(new_input_method); | 52 ime_state->ChangeInputMethod(new_input_method, false /* show_message */); |
53 return RespondNow(NoArguments()); | 53 return RespondNow(NoArguments()); |
54 } | 54 } |
55 } | 55 } |
56 return RespondNow(Error("Invalid input method id.")); | 56 return RespondNow(Error("Invalid input method id.")); |
57 #endif | 57 #endif |
58 } | 58 } |
59 | 59 |
60 ExtensionFunction::ResponseAction GetInputMethodsFunction::Run() { | 60 ExtensionFunction::ResponseAction GetInputMethodsFunction::Run() { |
61 #if !defined(OS_CHROMEOS) | 61 #if !defined(OS_CHROMEOS) |
62 EXTENSION_FUNCTION_VALIDATE(false); | 62 EXTENSION_FUNCTION_VALIDATE(false); |
63 #else | 63 #else |
64 base::ListValue* output = new base::ListValue(); | 64 base::ListValue* output = new base::ListValue(); |
65 chromeos::input_method::InputMethodManager* manager = | 65 chromeos::input_method::InputMethodManager* manager = |
66 chromeos::input_method::InputMethodManager::Get(); | 66 chromeos::input_method::InputMethodManager::Get(); |
67 chromeos::input_method::InputMethodUtil* util = manager->GetInputMethodUtil(); | 67 chromeos::input_method::InputMethodUtil* util = manager->GetInputMethodUtil(); |
| 68 scoped_refptr<chromeos::input_method::InputMethodManager::State> ime_state = |
| 69 manager->GetActiveIMEState(); |
68 scoped_ptr<chromeos::input_method::InputMethodDescriptors> input_methods = | 70 scoped_ptr<chromeos::input_method::InputMethodDescriptors> input_methods = |
69 manager->GetActiveInputMethods(); | 71 ime_state->GetActiveInputMethods(); |
70 for (size_t i = 0; i < input_methods->size(); ++i) { | 72 for (size_t i = 0; i < input_methods->size(); ++i) { |
71 const chromeos::input_method::InputMethodDescriptor& input_method = | 73 const chromeos::input_method::InputMethodDescriptor& input_method = |
72 (*input_methods)[i]; | 74 (*input_methods)[i]; |
73 base::DictionaryValue* val = new base::DictionaryValue(); | 75 base::DictionaryValue* val = new base::DictionaryValue(); |
74 val->SetString("id", input_method.id()); | 76 val->SetString("id", input_method.id()); |
75 val->SetString("name", util->GetInputMethodLongName(input_method)); | 77 val->SetString("name", util->GetInputMethodLongName(input_method)); |
76 val->SetString("indicator", util->GetInputMethodShortName(input_method)); | 78 val->SetString("indicator", util->GetInputMethodShortName(input_method)); |
77 output->Append(val); | 79 output->Append(val); |
78 } | 80 } |
79 return RespondNow(OneArgument(output)); | 81 return RespondNow(OneArgument(output)); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > | 125 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > |
124 g_factory = LAZY_INSTANCE_INITIALIZER; | 126 g_factory = LAZY_INSTANCE_INITIALIZER; |
125 | 127 |
126 // static | 128 // static |
127 BrowserContextKeyedAPIFactory<InputMethodAPI>* | 129 BrowserContextKeyedAPIFactory<InputMethodAPI>* |
128 InputMethodAPI::GetFactoryInstance() { | 130 InputMethodAPI::GetFactoryInstance() { |
129 return g_factory.Pointer(); | 131 return g_factory.Pointer(); |
130 } | 132 } |
131 | 133 |
132 } // namespace extensions | 134 } // namespace extensions |
OLD | NEW |