Chromium Code Reviews| Index: chrome/browser/chromeos/extensions/input_method_api.cc |
| diff --git a/chrome/browser/chromeos/extensions/input_method_api.cc b/chrome/browser/chromeos/extensions/input_method_api.cc |
| index 582f8e13195e70b3f2dfad791fb5729c53d45b24..3802bee492bba1622ee7e1ae1ed324e75245d564 100644 |
| --- a/chrome/browser/chromeos/extensions/input_method_api.cc |
| +++ b/chrome/browser/chromeos/extensions/input_method_api.cc |
| @@ -9,9 +9,11 @@ |
| #include "chrome/browser/chromeos/extensions/input_method_event_router.h" |
| #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" |
| #include "chromeos/ime/extension_ime_util.h" |
| +#include "chromeos/ime/input_method_descriptor.h" |
| #include "chromeos/ime/input_method_manager.h" |
| #include "extensions/browser/extension_function_registry.h" |
| #include "extensions/browser/extension_system.h" |
| +#include "extensions/common/value_builder.h" |
| namespace { |
| @@ -22,23 +24,57 @@ const char kXkbPrefix[] = "xkb:"; |
| namespace extensions { |
| -GetInputMethodFunction::GetInputMethodFunction() { |
| +ExtensionFunction::ResponseAction GetCurrentInputMethodFunction::Run() { |
| +#if !defined(OS_CHROMEOS) |
| + EXTENSION_FUNCTION_VALIDATE(false); |
| +#else |
| + chromeos::input_method::InputMethodManager* manager = |
| + chromeos::input_method::InputMethodManager::Get(); |
| + return RespondNow(OneArgument( |
| + new base::StringValue(manager->GetCurrentInputMethod().id()))); |
| +#endif |
| } |
| -GetInputMethodFunction::~GetInputMethodFunction() { |
| +ExtensionFunction::ResponseAction SetCurrentInputMethodFunction::Run() { |
| +#if !defined(OS_CHROMEOS) |
| + EXTENSION_FUNCTION_VALIDATE(false); |
| +#else |
| + std::string new_input_method; |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &new_input_method)); |
| + chromeos::input_method::InputMethodManager* manager = |
| + chromeos::input_method::InputMethodManager::Get(); |
| + const std::vector<std::string>& input_methods = |
| + manager->GetActiveInputMethodIds(); |
| + for (size_t i = 0; i < input_methods.size(); ++i) { |
| + const std::string& input_method = input_methods[i]; |
| + if (input_method == new_input_method) { |
| + manager->ChangeInputMethod(new_input_method); |
| + return RespondNow(NoArguments()); |
| + } |
| + } |
| + return RespondNow(Error("Invalid input method id.")); |
| +#endif |
| } |
| -bool GetInputMethodFunction::RunSync() { |
| +ExtensionFunction::ResponseAction GetInputMethodsFunction::Run() { |
| #if !defined(OS_CHROMEOS) |
| - NOTREACHED(); |
| - return false; |
| + EXTENSION_FUNCTION_VALIDATE(false); |
| #else |
| + base::ListValue* output = new base::ListValue(); |
| chromeos::input_method::InputMethodManager* manager = |
| chromeos::input_method::InputMethodManager::Get(); |
| - const std::string input_method = InputMethodAPI::GetInputMethodForXkb( |
| - manager->GetCurrentInputMethod().id()); |
| - SetResult(base::Value::CreateStringValue(input_method)); |
| - return true; |
| + scoped_ptr<chromeos::input_method::InputMethodDescriptors> input_methods = |
| + manager->GetActiveInputMethods(); |
| + for (size_t i = 0; i < input_methods->size(); ++i) { |
| + const chromeos::input_method::InputMethodDescriptor& input_method = |
| + (*input_methods)[i]; |
| + base::DictionaryValue* val = new base::DictionaryValue(); |
| + val->SetString("id", input_method.id()); |
| + val->SetString("name", input_method.name()); |
| + val->SetString("indicator", input_method.indicator()); |
| + output->Append(val); |
| + } |
| + return RespondNow(OneArgument(output)); |
| #endif |
| } |
| @@ -48,16 +84,15 @@ StartImeFunction::StartImeFunction() { |
| StartImeFunction::~StartImeFunction() { |
| } |
| -bool StartImeFunction::RunSync() { |
| +ExtensionFunction::ResponseAction StartImeFunction::Run() { |
|
Seigo Nonaka
2014/06/11 03:18:04
I guess this function is no longer necessary.
This
Shu Chen
2014/06/11 03:31:15
Done.
|
| #if !defined(OS_CHROMEOS) |
| - NOTREACHED(); |
| - return false; |
| + EXTENSION_FUNCTION_VALIDATE(false); |
|
Seigo Nonaka
2014/06/11 03:18:04
I think NOTREACHED is still fine since this is Pri
Shu Chen
2014/06/11 03:31:15
The return value changed. EXTENSION_FUNCTION_VALID
Seigo Nonaka
2014/06/11 05:53:36
Oh, I didn't know NOTREACHED does not always cause
|
| #else |
| chromeos::InputMethodEngineInterface* engine = |
| InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); |
| if (engine) |
| engine->NotifyImeReady(); |
| - return true; |
| + return RespondNow(NoArguments()); |
| #endif |
| } |
| @@ -70,7 +105,9 @@ InputMethodAPI::InputMethodAPI(content::BrowserContext* context) |
| EventRouter::Get(context_)->RegisterObserver(this, kOnInputMethodChanged); |
| ExtensionFunctionRegistry* registry = |
| ExtensionFunctionRegistry::GetInstance(); |
| - registry->RegisterFunction<GetInputMethodFunction>(); |
| + registry->RegisterFunction<GetCurrentInputMethodFunction>(); |
| + registry->RegisterFunction<SetCurrentInputMethodFunction>(); |
| + registry->RegisterFunction<GetInputMethodsFunction>(); |
| registry->RegisterFunction<StartImeFunction>(); |
| } |