Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Unified Diff: mojo/public/js/lib/pipe_control_message_handler.js

Issue 2744963002: Introduce InterfaceEndpointClient(IEC), InterfaceEndpointHandle and (Closed)
Patch Set: Throw the error with the string being the stack trace needed to debug layouts which don't output an… Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/js/lib/interface_endpoint_handle.js ('k') | mojo/public/js/lib/pipe_control_message_proxy.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/js/lib/pipe_control_message_handler.js
diff --git a/mojo/public/js/lib/pipe_control_message_handler.js b/mojo/public/js/lib/pipe_control_message_handler.js
new file mode 100644
index 0000000000000000000000000000000000000000..2eb45d16266fe8fddf19696af797d683a28d4efd
--- /dev/null
+++ b/mojo/public/js/lib/pipe_control_message_handler.js
@@ -0,0 +1,61 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+define("mojo/public/js/lib/pipe_control_message_handler", [
+ "mojo/public/interfaces/bindings/pipe_control_messages.mojom",
+ "mojo/public/js/codec",
+ "mojo/public/js/interface_types",
+ "mojo/public/js/validator",
+], function(pipeControlMessages, codec, types, validator) {
+
+ var Validator = validator.Validator;
+
+ function validateControlRequestWithoutResponse(message) {
+ var messageValidator = new Validator(message);
+ var error = messageValidator.validateMessageIsRequestWithoutResponse();
+ if (error != validator.validationError.NONE) {
+ throw error;
+ }
+
+ if (message.getName() != pipeControlMessages.kRunOrClosePipeMessageId) {
+ throw new Error("Control message name is not kRunOrClosePipeMessageId");
+ }
+
+ // Validate payload.
+ error = pipeControlMessages.RunOrClosePipeMessageParams.validate(
+ messageValidator, message.getHeaderNumBytes());
+ if (error != validator.validationError.NONE) {
+ throw error;
+ }
+ }
+
+ function runOrClosePipe(message, delegate) {
+ var reader = new codec.MessageReader(message);
+ var runOrClosePipeMessageParams = reader.decodeStruct(
+ pipeControlMessages.RunOrClosePipeMessageParams);
+ var event = runOrClosePipeMessageParams.input
+ .peer_associated_endpoint_closed_event;
+ return delegate.onPeerAssociatedEndpointClosed(event.id,
+ event.disconnect_reason);
+ }
+
+ function isPipeControlMessage(message) {
+ return !types.isValidInterfaceId(message.getInterfaceId());
+ }
+
+ function PipeControlMessageHandler(delegate) {
+ this.delegate_ = delegate;
+ }
+
+ PipeControlMessageHandler.prototype.accept = function(message) {
+ validateControlRequestWithoutResponse(message);
+ return runOrClosePipe(message, this.delegate_);
+ };
+
+ var exports = {};
+ exports.PipeControlMessageHandler = PipeControlMessageHandler;
+ exports.isPipeControlMessage = isPipeControlMessage;
+
+ return exports;
+});
« no previous file with comments | « mojo/public/js/lib/interface_endpoint_handle.js ('k') | mojo/public/js/lib/pipe_control_message_proxy.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698