Commit 746c878c authored by Leo Zhang's avatar Leo Zhang

Set delegate handlers for IME extension.

Export 2 functions so the XKB extension can handle messages in text or
protobuf format from Engine side.

Bug:837156
TBR=shuchen

Change-Id: I5cdd77818f4e0692d99743d02436f0e00d63edd0
Reviewed-on: https://chromium-review.googlesource.com/c/1448082Reviewed-by: default avatarLeo Zhang <googleo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#629810}
parent f8b2af3a
...@@ -64,6 +64,7 @@ class ImeExtensionChannel { ...@@ -64,6 +64,7 @@ class ImeExtensionChannel {
/** /**
* Get a cached bound InterfacePtr for this InputChannel impl. * Get a cached bound InterfacePtr for this InputChannel impl.
* Create one the ptr if it's not bound yet. * Create one the ptr if it's not bound yet.
*
* @return {!chromeos.ime.mojom.InputChannelPtr}. * @return {!chromeos.ime.mojom.InputChannelPtr}.
*/ */
getChannelPtr() { getChannelPtr() {
...@@ -73,6 +74,7 @@ class ImeExtensionChannel { ...@@ -73,6 +74,7 @@ class ImeExtensionChannel {
/** /**
* Set a handler for processing text message. The handler must return a * Set a handler for processing text message. The handler must return a
* nonnull string, otherwise it will lead to disconnection. * nonnull string, otherwise it will lead to disconnection.
*
* @param {function(string):string} handler. * @param {function(string):string} handler.
*/ */
onTextMessage(handler) { onTextMessage(handler) {
...@@ -83,6 +85,7 @@ class ImeExtensionChannel { ...@@ -83,6 +85,7 @@ class ImeExtensionChannel {
/** /**
* Set a handler for processing protobuf message. The handler must return a * Set a handler for processing protobuf message. The handler must return a
* nonnull Uint8Array, otherwise it will lead to disconnection. * nonnull Uint8Array, otherwise it will lead to disconnection.
*
* @param {function(!Uint8Array):!Uint8Array} handler. * @param {function(!Uint8Array):!Uint8Array} handler.
*/ */
onProtobufMessage(handler) { onProtobufMessage(handler) {
...@@ -122,6 +125,7 @@ class ImeExtensionChannel { ...@@ -122,6 +125,7 @@ class ImeExtensionChannel {
/** /**
* Set the error handler when the channel Mojo pipe is disconnected. * Set the error handler when the channel Mojo pipe is disconnected.
*
* @param {function():void} handler. * @param {function():void} handler.
*/ */
setConnectionErrorHandler(handler) { setConnectionErrorHandler(handler) {
...@@ -178,6 +182,7 @@ class ImeService { ...@@ -178,6 +182,7 @@ class ImeService {
/** /**
* Set the error handler when the IME Mojo service is disconnected. * Set the error handler when the IME Mojo service is disconnected.
*
* @param {function():void} callback. * @param {function():void} callback.
*/ */
setConnectionErrorHandler(callback) { setConnectionErrorHandler(callback) {
...@@ -197,8 +202,34 @@ class ImeService { ...@@ -197,8 +202,34 @@ class ImeService {
return null; return null;
} }
/**
* Set a handler for the bound client delegate to process messages in text
* format. This should be called after an IME engine is activated.
*
* @param {!function(string):string} callback Callback on text message.
*/
setDelegateTextHandler(callback) {
if (this.clientChannel_ && this.clientChannel_.ptr.isBound()) {
this.clientChannel_.onTextMessage(callback);
}
}
/**
* Set a handler for the bound client delegate to process messages in protobuf
* format. This should be called after an IME engine is activated.
*
* @param {!function(!Uint8Array):!Uint8Array} callback Callback on protobuf
* message.
*/
setDelegateProtobufHandler(callback) {
if (this.clientChannel_ && this.clientChannel_.ptr.isBound()) {
this.clientChannel_.onProtobufMessage(callback);
}
}
/** /**
* Activates an input method based on its specification. * Activates an input method based on its specification.
*
* @param {string} imeSpec The specification of an IME (e.g. the engine ID). * @param {string} imeSpec The specification of an IME (e.g. the engine ID).
* @param {!Uint8Array} extra The extra data (e.g. initial tasks to run). * @param {!Uint8Array} extra The extra data (e.g. initial tasks to run).
* @param {function(boolean):void} onConnection The callback function to * @param {function(boolean):void} onConnection The callback function to
...@@ -244,6 +275,7 @@ class ImeService { ...@@ -244,6 +275,7 @@ class ImeService {
this.activeEngine_.ptr.reset(); this.activeEngine_.ptr.reset();
} }
this.activeEngine_ = null; this.activeEngine_ = null;
// TODO(crbug.com/837156): Release client channel?
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment