• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5(function() {
6  var internal = mojo.internal;
7
8  function constructRunOrClosePipeMessage(runOrClosePipeInput) {
9    var runOrClosePipeMessageParams = new
10        mojo.pipeControl.RunOrClosePipeMessageParams();
11    runOrClosePipeMessageParams.input = runOrClosePipeInput;
12
13    var messageName = mojo.pipeControl.kRunOrClosePipeMessageId;
14    var payloadSize =
15        mojo.pipeControl.RunOrClosePipeMessageParams.encodedSize;
16
17    var builder = new internal.MessageV0Builder(messageName, payloadSize);
18    builder.encodeStruct(mojo.pipeControl.RunOrClosePipeMessageParams,
19                         runOrClosePipeMessageParams);
20    var message = builder.finish();
21    message.setInterfaceId(internal.kInvalidInterfaceId);
22    return message;
23  }
24
25  function PipeControlMessageProxy(receiver) {
26    this.receiver_ = receiver;
27  }
28
29  PipeControlMessageProxy.prototype.notifyPeerEndpointClosed = function(
30      interfaceId, reason) {
31    var message = this.constructPeerEndpointClosedMessage(interfaceId, reason);
32    this.receiver_.accept(message);
33  };
34
35  PipeControlMessageProxy.prototype.constructPeerEndpointClosedMessage =
36      function(interfaceId, reason) {
37    var event = new mojo.pipeControl.PeerAssociatedEndpointClosedEvent();
38    event.id = interfaceId;
39    if (reason) {
40      event.disconnectReason = new mojo.pipeControl.DisconnectReason({
41          customReason: reason.customReason,
42          description: reason.description});
43    }
44    var runOrClosePipeInput = new mojo.pipeControl.RunOrClosePipeInput();
45    runOrClosePipeInput.peerAssociatedEndpointClosedEvent = event;
46    return constructRunOrClosePipeMessage(runOrClosePipeInput);
47  };
48
49  internal.PipeControlMessageProxy = PipeControlMessageProxy;
50})();
51