Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Adds the input method private API to allow the component IME extensio…
Browse files Browse the repository at this point in the history
…n to change the XKB layout.

BUG=170601

Review URL: https://codereview.chromium.org/1608163002

Cr-Commit-Position: refs/heads/master@{#370410}
  • Loading branch information
shuchen authored and Commit bot committed Jan 20, 2016
1 parent a31b8aa commit 78d3f5f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
17 changes: 17 additions & 0 deletions chrome/browser/chromeos/extensions/input_method_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -195,6 +197,21 @@ InputMethodPrivateGetEncryptSyncEnabledFunction::Run() {
#endif
}

ExtensionFunction::ResponseAction
InputMethodPrivateSetXkbLayoutFunction::Run() {
#if !defined(OS_CHROMEOS)
EXTENSION_FUNCTION_VALIDATE(false);
#else
scoped_ptr<SetXkbLayout::Params> 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);
Expand Down
17 changes: 17 additions & 0 deletions chrome/browser/chromeos/extensions/input_method_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions chrome/common/extensions/api/input_method_private.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
1 change: 1 addition & 0 deletions extensions/browser/extension_function_histogram_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,7 @@ enum HistogramValue {
WEBRTCLOGGINGPRIVATE_STOPAUDIODEBUGRECORDINGS,
TERMINALPRIVATE_ACKOUTPUT,
INPUT_IME_CREATEWINDOW,
INPUTMETHODPRIVATE_SETXKBLAYOUT,
// Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY
Expand Down
1 change: 1 addition & 0 deletions tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63770,6 +63770,7 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
<int value="1101" label="WEBRTCLOGGINGPRIVATE_STOPAUDIODEBUGRECORDINGS"/>
<int value="1102" label="TERMINALPRIVATE_ACKOUTPUT"/>
<int value="1103" label="INPUT_IME_CREATEWINDOW"/>
<int value="1104" label="INPUTMETHODPRIVATE_SETXKBLAYOUT"/>
</enum>

<enum name="ExtensionInstallCause" type="int">
Expand Down

0 comments on commit 78d3f5f

Please sign in to comment.