summaryrefslogtreecommitdiff
path: root/chromium/extensions/common/api/sockets_udp.idl
blob: 784a31d25d77573f467e6a703e519cad86c674f0 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
// 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.

// Use the <code>chrome.sockets.udp</code> API to send and receive data over the
// network using UDP connections. This API supersedes the UDP functionality
// previously found in the "socket" API.
namespace sockets.udp {
  // The socket properties specified in the <code>create</code> or
  // <code>update</code> function. Each property is optional. If a property
  // value is not specified, a default value is used when calling
  // <code>create</code>, or the existing value if preserved when calling
  // <code>update</code>.
  dictionary SocketProperties {
    // Flag indicating if the socket is left open when the event page of the
    // application is unloaded (see
    // <a href="http://developer.chrome.com/apps/app_lifecycle.html">Manage App
    // Lifecycle</a>). The default value is "false." When the application is
    // loaded, any sockets previously opened with persistent=true can be fetched
    // with <code>getSockets</code>.
    boolean? persistent;

    // An application-defined string associated with the socket.
    DOMString? name;

    // The size of the buffer used to receive data. If the buffer is too small
    // to receive the UDP packet, data is lost. The default value is 4096.
    long? bufferSize;
  };

  // Result of <code>create</code> call.
  dictionary CreateInfo {
    // The ID of the newly created socket. Note that socket IDs created from
    // this API are not compatible with socket IDs created from other APIs, such
    // as the deprecated <code>$(ref:socket)</code> API.
    long socketId;
  };

  // Callback from the <code>create</code> method.
  // |createInfo| : The result of the socket creation.
  callback CreateCallback = void (CreateInfo createInfo);

  // Callback from the <code>bind</code> method.
  // |result| : The result code returned from the underlying network call.
  // A negative value indicates an error.
  callback BindCallback = void (long result);

  // Result of the <code>send</code> method.
  dictionary SendInfo {
    // The result code returned from the underlying network call.
    // A negative value indicates an error.
    long resultCode;

    // The number of bytes sent (if result == 0)
    long? bytesSent;
  };

  // Callback from the <code>send</code> method.
  // |sendInfo| : Result of the <code>send</code> method.
  callback SendCallback = void (SendInfo sendInfo);

  // Callback from the <code>close</code> method.
  callback CloseCallback = void ();

  // Callback from the <code>update</code> method.
  callback UpdateCallback = void ();

  // Callback from the <code>setPaused</code> method.
  callback SetPausedCallback = void ();

  // Result of the <code>getInfo</code> method.
  dictionary SocketInfo {
    // The socket identifier.
    long socketId;

    // Flag indicating whether the socket is left open when the application is
    // suspended (see <code>SocketProperties.persistent</code>).
    boolean persistent;

    // Application-defined string associated with the socket.
    DOMString? name;

    // The size of the buffer used to receive data. If no buffer size has been
    // specified explictly, the value is not provided.
    long? bufferSize;

    // Flag indicating whether the socket is blocked from firing onReceive
    // events.
    boolean paused;

    // If the underlying socket is bound, contains its local
    // IPv4/6 address.
    DOMString? localAddress;

    // If the underlying socket is bound, contains its local port.
    long? localPort;
  };

  // Callback from the <code>getInfo</code> method.
  // |socketInfo| : Object containing the socket information.
  callback GetInfoCallback = void (SocketInfo socketInfo);

  // Callback from the <code>getSockets</code> method.
  // |socketInfos| : Array of object containing socket information.
  callback GetSocketsCallback = void (SocketInfo[] socketInfos);

  // Callback from the <code>joinGroup</code> method.
  // |result| : The result code returned from the underlying network call.
  // A negative value indicates an error.
  callback JoinGroupCallback = void (long result);

  // Callback from the <code>leaveGroup</code> method.
  // |result| : The result code returned from the underlying network call.
  // A negative value indicates an error.
  callback LeaveGroupCallback = void (long result);

  // Callback from the <code>setMulticastTimeToLive</code> method.
  // |result| : The result code returned from the underlying network call.
  // A negative value indicates an error.
  callback SetMulticastTimeToLiveCallback = void (long result);

  // Callback from the <code>setMulticastLoopbackMode</code> method.
  // |result| : The result code returned from the underlying network call.
  // A negative value indicates an error.
  callback SetMulticastLoopbackModeCallback = void (long result);

  // Callback from the <code>getJoinedGroupsCallback</code> method.
  // |groups| : Array of groups the socket joined.
  callback GetJoinedGroupsCallback = void (DOMString[] groups);

  // Callback from the <code>setBroadcast</code> method.
  // |result| : The result code returned from the underlying network call.
  callback SetBroadcastCallback = void (long result);

  // Data from an <code>onReceive</code> event.
  dictionary ReceiveInfo {
    // The socket ID.
    long socketId;

    // The UDP packet content (truncated to the current buffer size).
    ArrayBuffer data;

    // The address of the host the packet comes from.
    DOMString remoteAddress;

     // The port of the host the packet comes from.
    long remotePort;
  };

  // Data from an <code>onReceiveError</code> event.
  dictionary ReceiveErrorInfo {
    // The socket ID.
    long socketId;

     // The result code returned from the underlying recvfrom() call.
    long resultCode;
  };

  interface Functions {
    // Creates a UDP socket with the given properties.
    // |properties| : The socket properties (optional).
    // |callback| : Called when the socket has been created.
    static void create(optional SocketProperties properties,
                       CreateCallback callback);

    // Updates the socket properties.
    // |socketId| : The socket ID.
    // |properties| : The properties to update.
    // |callback| : Called when the properties are updated.
    static void update(long socketId,
                       SocketProperties properties,
                       optional UpdateCallback callback);

    // Pauses or unpauses a socket. A paused socket is blocked from firing
    // <code>onReceive</code> events.
    // |connectionId| : The socket ID.
    // |paused| : Flag to indicate whether to pause or unpause.
    // |callback| : Called when the socket has been successfully paused or
    // unpaused.
    static void setPaused(long socketId,
                          boolean paused,
                          optional SetPausedCallback callback);

    // Binds the local address and port for the socket. For a client socket, it
    // is recommended to use port 0 to let the platform pick a free port.
    //
    // Once the <code>bind</code> operation completes successfully,
    // <code>onReceive</code> events are raised when UDP packets arrive on the
    // address/port specified -- unless the socket is paused.
    //
    // |socketId| : The socket ID.
    // |address| : The address of the local machine. DNS name, IPv4 and IPv6
    // formats are supported. Use "0.0.0.0" to accept packets from all local
    // available network interfaces.
    // |port| : The port of the local machine. Use "0" to bind to a free port.
    // |callback| : Called when the <code>bind</code> operation completes.
    static void bind(long socketId,
                     DOMString address,
                     long port,
                     BindCallback callback);

    // Sends data on the given socket to the given address and port. The socket
    // must be bound to a local port before calling this method.
    // |socketId| : The socket ID.
    // |data| : The data to send.
    // |address| : The address of the remote machine.
    // |port| : The port of the remote machine.
    // |callback| : Called when the <code>send</code> operation completes.
    static void send(long socketId,
                     ArrayBuffer data,
                     DOMString address,
                     long port,
                     SendCallback callback);

    // Closes the socket and releases the address/port the socket is bound to.
    // Each socket created should be closed after use. The socket id is no
    // longer valid as soon at the function is called. However, the socket is
    // guaranteed to be closed only when the callback is invoked.
    // |socketId| : The socket ID.
    // |callback| : Called when the <code>close</code> operation completes.
    static void close(long socketId,
                      optional CloseCallback callback);

    // Retrieves the state of the given socket.
    // |socketId| : The socket ID.
    // |callback| : Called when the socket state is available.
    static void getInfo(long socketId,
                        GetInfoCallback callback);

    // Retrieves the list of currently opened sockets owned by the application.
    // |callback| : Called when the list of sockets is available.
    static void getSockets(GetSocketsCallback callback);

    // Joins the multicast group and starts to receive packets from that group.
    // The socket must be bound to a local port before calling this method.
    // |socketId| : The socket ID.
    // |address| : The group address to join. Domain names are not supported.
    // |callback| : Called when the <code>joinGroup</code> operation completes.
    static void joinGroup(long socketId,
                          DOMString address,
                          JoinGroupCallback callback);

    // Leaves the multicast group previously joined using
    // <code>joinGroup</code>. This is only necessary to call if you plan to
    // keep using the socketafterwards, since it will be done automatically by
    // the OS when the socket is closed.
    //
    // Leaving the group will prevent the router from sending multicast
    // datagrams to the local host, presuming no other process on the host is
    // still joined to the group.
    //
    // |socketId| : The socket ID.
    // |address| : The group address to leave. Domain names are not supported.
    // |callback| : Called when the <code>leaveGroup</code> operation completes.
    static void leaveGroup(long socketId,
                           DOMString address,
                           LeaveGroupCallback callback);

    // Sets the time-to-live of multicast packets sent to the multicast group.
    //
    // Calling this method does not require multicast permissions.
    //
    // |socketId| : The socket ID.
    // |ttl| : The time-to-live value.
    // |callback| : Called when the configuration operation completes.
    static void setMulticastTimeToLive(
        long socketId,
        long ttl,
        SetMulticastTimeToLiveCallback callback);

    // Sets whether multicast packets sent from the host to the multicast group
    // will be looped back to the host.
    //
    // Note: the behavior of <code>setMulticastLoopbackMode</code> is slightly
    // different between Windows and Unix-like systems. The inconsistency
    // happens only when there is more than one application on the same host
    // joined to the same multicast group while having different settings on
    // multicast loopback mode. On Windows, the applications with loopback off
    // will not RECEIVE the loopback packets; while on Unix-like systems, the
    // applications with loopback off will not SEND the loopback packets to
    // other applications on the same host. See MSDN: http://goo.gl/6vqbj
    //
    // Calling this method does not require multicast permissions.
    //
    // |socketId| : The socket ID.
    // |enabled| : Indicate whether to enable loopback mode.
    // |callback| : Called when the configuration operation completes.
    static void setMulticastLoopbackMode(
        long socketId,
        boolean enabled,
        SetMulticastLoopbackModeCallback callback);

    // Gets the multicast group addresses the socket is currently joined to.
    // |socketId| : The socket ID.
    // |callback| : Called with an array of strings of the result.
    static void getJoinedGroups(long socketId,
                                GetJoinedGroupsCallback callback);

    // Enables or disables broadcast packets on this socket.
    //
    // |socketId| : The socket ID.
    // |enabled| : <code>true</code> to enable broadcast packets,
    // <code>false</code> to disable them.
    static void setBroadcast(long socketId,
                             boolean enabled,
                             SetBroadcastCallback callback);
  };

  interface Events {
    // Event raised when a UDP packet has been received for the given socket.
    // |info| : The event data.
    static void onReceive(ReceiveInfo info);

    // Event raised when a network error occured while the runtime was waiting
    // for data on the socket address and port. Once this event is raised, the
    // socket is paused and no more <code>onReceive</code> events will be raised
    // for this socket until the socket is resumed.
    // |info| : The event data.
    static void onReceiveError(ReceiveErrorInfo info);
  };
};