Commit f686f9fe authored by Leo Zhang's avatar Leo Zhang Committed by Commit Bot

Fix the IME JS style and param.

Bug: 837156
Change-Id: I226459175c995b029f30932327f19124f33ac1d5
Reviewed-on: https://chromium-review.googlesource.com/c/1288152Reviewed-by: default avatarShu Chen <shuchen@chromium.org>
Commit-Queue: Leo Zhang <googleo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601066}
parent da513a4c
...@@ -76,9 +76,7 @@ class ImeExtensionChannel { ...@@ -76,9 +76,7 @@ class ImeExtensionChannel {
* @param {function(string):string} handler. * @param {function(string):string} handler.
*/ */
onTextMessage(handler) { onTextMessage(handler) {
if (typeof handler == 'function') { this.textHandler_ = handler;
this.textHandler_ = handler;
}
return this; return this;
} }
...@@ -88,9 +86,7 @@ class ImeExtensionChannel { ...@@ -88,9 +86,7 @@ class ImeExtensionChannel {
* @param {function(!Uint8Array):!Uint8Array} handler. * @param {function(!Uint8Array):!Uint8Array} handler.
*/ */
onProtobufMessage(handler) { onProtobufMessage(handler) {
if (typeof handler == 'function') { this.protobufHandler_ = handler;
this.protobufHandler_ = handler;
}
return this; return this;
} }
...@@ -114,7 +110,7 @@ class ImeExtensionChannel { ...@@ -114,7 +110,7 @@ class ImeExtensionChannel {
* *
* @type {function(Uint8Array):Promise<Uint8Array>} * @type {function(Uint8Array):Promise<Uint8Array>}
* @private * @private
* @param {string} message * @param {!Uint8Array} message
* @return {!Promise<!Uint8Array>} * @return {!Promise<!Uint8Array>}
*/ */
processMessage(message) { processMessage(message) {
...@@ -129,7 +125,7 @@ class ImeExtensionChannel { ...@@ -129,7 +125,7 @@ class ImeExtensionChannel {
* @param {function():void} handler. * @param {function():void} handler.
*/ */
setConnectionErrorHandler(handler) { setConnectionErrorHandler(handler) {
if (typeof handler == 'function') { if (handler) {
this.binding_.setConnectionErrorHandler(handler); this.binding_.setConnectionErrorHandler(handler);
} }
} }
...@@ -185,14 +181,20 @@ class ImeService { ...@@ -185,14 +181,20 @@ class ImeService {
* @param {function():void} callback. * @param {function():void} callback.
*/ */
setConnectionErrorHandler(callback) { setConnectionErrorHandler(callback) {
if (typeof callback == 'function' && this.isConnected()) { if (callback && this.isConnected()) {
this.manager_.ptr.setConnectionErrorHandler(callback); this.manager_.ptr.setConnectionErrorHandler(callback);
} }
} }
/** @return {boolean} True if there is connected active IME engine. */ /**
hasActiveEngine() { * @return {?chromeos.ime.mojom.InputChannelPtr} A bound IME engine instance
return this.activeEngine_ && this.activeEngine_.ptr.isBound(); * or null if no IME Engine is bound.
*/
getActiveEngine() {
if (this.activeEngine_ && this.activeEngine_.ptr.isBound()) {
return this.activeEngine_;
}
return null;
} }
/** /**
...@@ -220,26 +222,25 @@ class ImeService { ...@@ -220,26 +222,25 @@ class ImeService {
this.clientChannel_ = new ImeExtensionChannel(); this.clientChannel_ = new ImeExtensionChannel();
} }
this.manager_.connectToImeEngine( this.manager_
imeSpec, .connectToImeEngine(
mojo.makeRequest(this.activeEngine_), imeSpec, mojo.makeRequest(this.activeEngine_),
this.clientChannel_.getChannelPtr(), this.clientChannel_.getChannelPtr(), extra)
extra).then( .then((bound) => {
bound => { if (bound && onConnectionError) {
if (bound && typeof onConnectionError == 'function') { this.activeEngine_.ptr.setConnectionErrorHandler(
this.activeEngine_.ptr.setConnectionErrorHandler( onConnectionError);
onConnectionError); };
}; if (onConnection) {
if (typeof onConnection == 'function') { onConnection(bound);
onConnection(bound); };
}; });
});
} }
} }
/** Deactivate the IME engine if it is connected. */ /** Deactivate the IME engine if it is connected. */
deactivateIME() { deactivateIME() {
if (this.hasActiveEngine()) { if (this.getActiveEngine()) {
this.activeEngine_.ptr.reset(); this.activeEngine_.ptr.reset();
} }
this.activeEngine_ = null; this.activeEngine_ = null;
......
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