Commit e0790171 authored by Kevin Marshall's avatar Kevin Marshall Committed by Commit Bot

[CastRunner] Allow Agent's enable-touch bindings to supercede the Runner's.

Prevents the CastRunner from clobbering the Agent's
setTouchSupportEnabled() platform API if it's already been installed.

Bug: 953796,953958
Change-Id: Ia1044a96209f04d792a8c671a8ac18eb98b2d9ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1728445Reviewed-by: default avatarFabrice de Gans-Riberi <fdegans@chromium.org>
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683227}
parent 086bfcee
......@@ -4,70 +4,73 @@
'use strict';
cast.__platform__.__touchInput__ = new class {
constructor() {
this.port_ = cast.__platform__.PortConnector.bind(
'cast.__platform__.__touchInput__');
// Don't supercede an Agent-provided API function.
if (!cast.__platform__.setTouchInputSupport) {
cast.__platform__.__touchInput__ = new class {
constructor() {
this.port_ = cast.__platform__.PortConnector.bind(
'cast.__platform__.__touchInput__');
this.port_.onmessage = function(message) {
var responseParsed = JSON.parse(message.data);
if (responseParsed) {
this.onAck(responseParsed.requestId,
responseParsed.displayControls);
}
}.bind(this);
}
// Receives an acknowledgement from the native bindings layer and relays the
// result to the Promise.
onAck(requestId, displayControls) {
if (!this.pendingRequests_.hasOwnProperty(requestId)) {
console.error('Received ack for unknown request ID: ' + requestId);
return;
this.port_.onmessage = function(message) {
var responseParsed = JSON.parse(message.data);
if (responseParsed) {
this.onAck(responseParsed.requestId,
responseParsed.displayControls);
}
}.bind(this);
}
var request = this.pendingRequests_[requestId];
delete this.pendingRequests_[requestId];
// Receives an acknowledgement from the native bindings layer and relays the
// result to the Promise.
onAck(requestId, displayControls) {
if (!this.pendingRequests_.hasOwnProperty(requestId)) {
console.error('Received ack for unknown request ID: ' + requestId);
return;
}
var request = this.pendingRequests_[requestId];
delete this.pendingRequests_[requestId];
if (displayControls === undefined) {
request.reject();
} else {
request.resolve({'displayControls': displayControls});
if (displayControls === undefined) {
request.reject();
} else {
request.resolve({'displayControls': displayControls});
}
}
}
// Requests touch input support from the native bindings layer and returns a
// Promise with the result.
// If the request was successful, the Promise will be resolved with a
// dictionary indicating whether onscreen controls should be shown for the
// application.
// If the request was rejected, then the Promise will be rejected.
setTouchInputSupport(touchEnabled) {
return new Promise((resolve, reject) => {
var requestId = this.currentRequestId_++;
this.pendingRequests_[requestId] = {
'resolve': resolve,
'reject': reject,
};
this.port_.postMessage(JSON.stringify({
'requestId': requestId,
'touchEnabled': touchEnabled,
}));
});
}
// Requests touch input support from the native bindings layer and returns a
// Promise with the result.
// If the request was successful, the Promise will be resolved with a
// dictionary indicating whether onscreen controls should be shown for the
// application.
// If the request was rejected, then the Promise will be rejected.
setTouchInputSupport(touchEnabled) {
return new Promise((resolve, reject) => {
var requestId = this.currentRequestId_++;
this.pendingRequests_[requestId] = {
'resolve': resolve,
'reject': reject,
};
this.port_.postMessage(JSON.stringify({
'requestId': requestId,
'touchEnabled': touchEnabled,
}));
});
}
// Port for sending requests and receiving acknowledgements with the native
// bindings layer.
port_ = null;
// Port for sending requests and receiving acknowledgements with the native
// bindings layer.
port_ = null;
// A dictionary relating inflight request IDs to their Promise resolve/reject
// functions.
pendingRequests_ = {};
// A dictionary relating inflight request IDs to their Promise
// resolve/reject functions.
pendingRequests_ = {};
// Unique ID of the next request.
currentRequestId_ = 0;
};
// Unique ID of the next request.
currentRequestId_ = 0;
};
cast.__platform__.setTouchInputSupport =
cast.__platform__.__touchInput__.setTouchInputSupport.bind(
cast.__platform__.__touchInput__);
cast.__platform__.setTouchInputSupport =
cast.__platform__.__touchInput__.setTouchInputSupport.bind(
cast.__platform__.__touchInput__);
}
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