summaryrefslogtreecommitdiffstats
path: root/mojo/services/public/interfaces/network/web_socket.mojom
blob: d96fb26dee59fd9b2f71fb7f477130d654cd788c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2014 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.

import "mojo/services/public/interfaces/network/network_error.mojom"

module mojo {

interface WebSocket {
  enum MessageType {
    CONTINUATION,
    TEXT,
    BINARY
  };
  const uint16 kAbnormalCloseCode = 1006;  // stolen from websocket_bridge

  // Initiates a WebSocket connection to the given url. |send_stream| is a data
  // pipe which should remain open for the lifetime of the WebSocket. Data
  // to send over the WebSocket should be written to the producer end of the
  // |send_stream|.
  Connect(string url,
          array<string> protocols,
          string origin,
          handle<data_pipe_consumer> send_stream,
          WebSocketClient client);

  // Called after writing |num_bytes| worth of data to the WebSocket's
  // |send_stream|.
  Send(bool fin, MessageType type, uint32 num_bytes);

  FlowControl(int64 quota);

  Close(uint16 code, string reason);
};

interface WebSocketClient {
  // Called in response to a WebSocket.Connect call to indicate success or
  // failure. |receive_stream| is a data pipe which where incoming data from
  // the server is written.
  DidConnect(bool fail,
             string selected_subprotocol,
             string extensions,
             handle<data_pipe_consumer> receive_stream);

  // Called when there is |num_bytes| worth of incoming data available on the
  // |receive_stream|.
  DidReceiveData(bool fin, WebSocket.MessageType type, uint32 num_bytes);

  DidReceiveFlowControl(int64 quota);

  DidFail(string message);

  DidClose(bool was_clean, uint16 code, string reason);

  // Blink has 3 extra methods that we don't implement, because they are used
  // for the inspector:
  // didStartOpeningHandshake
  // didFinishOpeningHandshake
  // didStartClosingHandshake
};

}