diff --git a/chrome/browser/chromeos/extensions/input_method_api.cc b/chrome/browser/chromeos/extensions/input_method_api.cc index 28d1811bd5ac8..11683fde36773 100644 --- a/chrome/browser/chromeos/extensions/input_method_api.cc +++ b/chrome/browser/chromeos/extensions/input_method_api.cc @@ -26,6 +26,7 @@ #include "extensions/browser/extension_function_registry.h" #include "extensions/browser/extension_system.h" #include "ui/base/ime/chromeos/extension_ime_util.h" +#include "ui/base/ime/chromeos/ime_keyboard.h" #include "ui/base/ime/chromeos/input_method_descriptor.h" #include "ui/base/ime/chromeos/input_method_manager.h" #include "ui/keyboard/keyboard_util.h" @@ -34,6 +35,7 @@ namespace AddWordToDictionary = extensions::api::input_method_private::AddWordToDictionary; namespace SetCurrentInputMethod = extensions::api::input_method_private::SetCurrentInputMethod; +namespace SetXkbLayout = extensions::api::input_method_private::SetXkbLayout; namespace OnChanged = extensions::api::input_method_private::OnChanged; namespace OnDictionaryChanged = extensions::api::input_method_private::OnDictionaryChanged; @@ -195,6 +197,21 @@ InputMethodPrivateGetEncryptSyncEnabledFunction::Run() { #endif } +ExtensionFunction::ResponseAction +InputMethodPrivateSetXkbLayoutFunction::Run() { +#if !defined(OS_CHROMEOS) + EXTENSION_FUNCTION_VALIDATE(false); +#else + scoped_ptr params(SetXkbLayout::Params::Create(*args_)); + EXTENSION_FUNCTION_VALIDATE(params.get()); + chromeos::input_method::InputMethodManager* manager = + chromeos::input_method::InputMethodManager::Get(); + chromeos::input_method::ImeKeyboard* keyboard = manager->GetImeKeyboard(); + keyboard->SetCurrentKeyboardLayoutByName(params->xkb_name); + return RespondNow(NoArguments()); +#endif +} + InputMethodAPI::InputMethodAPI(content::BrowserContext* context) : context_(context) { EventRouter::Get(context_)->RegisterObserver(this, OnChanged::kEventName); diff --git a/chrome/browser/chromeos/extensions/input_method_api.h b/chrome/browser/chromeos/extensions/input_method_api.h index 40b1e400f67b1..8b8b442e926d2 100644 --- a/chrome/browser/chromeos/extensions/input_method_api.h +++ b/chrome/browser/chromeos/extensions/input_method_api.h @@ -139,6 +139,23 @@ class InputMethodPrivateGetEncryptSyncEnabledFunction DISALLOW_COPY_AND_ASSIGN(InputMethodPrivateGetEncryptSyncEnabledFunction); }; +// Implements the inputMethodPrivate.setXkbLayout method. +class InputMethodPrivateSetXkbLayoutFunction + : public UIThreadExtensionFunction { + public: + InputMethodPrivateSetXkbLayoutFunction() {} + + protected: + ~InputMethodPrivateSetXkbLayoutFunction() override {} + + ResponseAction Run() override; + + private: + DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.setXkbLayout", + INPUTMETHODPRIVATE_SETXKBLAYOUT) + DISALLOW_COPY_AND_ASSIGN(InputMethodPrivateSetXkbLayoutFunction); +}; + class InputMethodAPI : public BrowserContextKeyedAPI, public extensions::EventRouter::Observer { public: diff --git a/chrome/common/extensions/api/input_method_private.json b/chrome/common/extensions/api/input_method_private.json index 5afd08f2daa01..69ca53ec65484 100644 --- a/chrome/common/extensions/api/input_method_private.json +++ b/chrome/common/extensions/api/input_method_private.json @@ -158,6 +158,24 @@ ] } ] + }, { + "name": "setXkbLayout", + "type": "function", + "description": "Sets the XKB layout for the given input method.", + "parameters": [ + { + "name": "xkb_name", + "type": "string", + "description": "The XKB layout name." + }, + { + "name": "callback", + "type": "function", + "optional": true, + "description": "Callback which is called when the layout is set.", + "parameters": [] + } + ] } ], "events": [ diff --git a/extensions/browser/extension_function_histogram_value.h b/extensions/browser/extension_function_histogram_value.h index 07c3391f72aef..438a1807567b5 100644 --- a/extensions/browser/extension_function_histogram_value.h +++ b/extensions/browser/extension_function_histogram_value.h @@ -1162,6 +1162,7 @@ enum HistogramValue { WEBRTCLOGGINGPRIVATE_STOPAUDIODEBUGRECORDINGS, TERMINALPRIVATE_ACKOUTPUT, ACCESSIBILITY_PRIVATE_SETKEYBOARDLISTENER, + INPUTMETHODPRIVATE_SETXKBLAYOUT, // Last entry: Add new entries above, then run: // python tools/metrics/histograms/update_extension_histograms.py ENUM_BOUNDARY diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index aa46f1790ce36..9ba3f26be7203 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml @@ -63540,6 +63540,7 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. +