Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Unified Diff: chrome/browser/chromeos/extensions/input_method_api.cc

Issue 305533002: Adds IME switching private APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..587d2b66dc2a0ce99f93f829722146639544f79d 100644
--- a/chrome/browser/chromeos/extensions/input_method_api.cc
+++ b/chrome/browser/chromeos/extensions/input_method_api.cc
@@ -9,6 +9,7 @@
#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"
@@ -22,22 +23,63 @@ const char kXkbPrefix[] = "xkb:";
namespace extensions {
-GetInputMethodFunction::GetInputMethodFunction() {
+bool GetCurrentInputMethodFunction::RunSync() {
+#if !defined(OS_CHROMEOS)
+ NOTREACHED();
+ return false;
+#else
+ chromeos::input_method::InputMethodManager* manager =
+ chromeos::input_method::InputMethodManager::Get();
+ SetResult(
+ base::Value::CreateStringValue(manager->GetCurrentInputMethod().id()));
not at google - send to devlin 2014/06/06 16:36:04 use new base::StringValue not CreateStringValue
Shu Chen 2014/06/07 05:31:09 Done.
+ return true;
+#endif
}
-GetInputMethodFunction::~GetInputMethodFunction() {
+bool SetCurrentInputMethodFunction::RunSync() {
+#if !defined(OS_CHROMEOS)
not at google - send to devlin 2014/06/06 16:36:04 better here (and everywhere) is just EXTENSION_FUN
Shu Chen 2014/06/07 05:31:09 Done.
+ NOTREACHED();
+ return 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);
+ SetResult(new base::FundamentalValue(true));
not at google - send to devlin 2014/06/06 16:36:04 i.e. just return true here
Shu Chen 2014/06/07 05:31:09 Done.
+ return true;
+ }
+ }
+ SetResult(new base::FundamentalValue(false));
+ return true;
not at google - send to devlin 2014/06/06 16:36:04 then here set _error (like "cannot find ime with i
Shu Chen 2014/06/07 05:31:09 Done.
+#endif
}
-bool GetInputMethodFunction::RunSync() {
+bool GetInputMethodsFunction::RunSync() {
#if !defined(OS_CHROMEOS)
NOTREACHED();
return 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));
+ 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);
not at google - send to devlin 2014/06/06 16:36:04 what you have here is totally fine. but a fun clas
Shu Chen 2014/06/07 05:31:09 Just found that value_builder.cc is only for test
not at google - send to devlin 2014/06/10 19:48:27 bummer. ok, there's actually no reason that should
+ }
+ SetResult(output);
return true;
#endif
}
@@ -70,7 +112,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>();
not at google - send to devlin 2014/06/06 16:36:04 you shouldn't actually need these RegisterFunction
not at google - send to devlin 2014/06/06 16:38:11 never mind, looks like the ime private API doesn't
}

Powered by Google App Engine
This is Rietveld 408576698