Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Use the <code>chrome.bluetooth</code> API to connect to a Bluetooth | 5 // Use the <code>chrome.bluetooth</code> API to connect to a Bluetooth |
| 6 // device. All functions report failures via chrome.runtime.lastError. | 6 // device. All functions report failures via chrome.runtime.lastError. |
| 7 namespace bluetooth { | 7 namespace bluetooth { |
| 8 // Allocation authorities for Vendor IDs. | 8 // Allocation authorities for Vendor IDs. |
| 9 enum VendorIdSource {bluetooth, usb}; | 9 enum VendorIdSource {bluetooth, usb}; |
| 10 | 10 |
| 11 // Common device types recognized by Chrome. | 11 // Common device types recognized by Chrome. |
| 12 enum DeviceType {computer, phone, modem, audio, carAudio, video, peripheral, | 12 enum DeviceType {computer, phone, modem, audio, carAudio, video, peripheral, |
| 13 joystick, gamepad, keyboard, mouse, tablet, | 13 joystick, gamepad, keyboard, mouse, tablet, |
| 14 keyboardMouseCombo}; | 14 keyboardMouseCombo}; |
| 15 | 15 |
| 16 // Information about the state of the Bluetooth adapater. | |
| 16 dictionary AdapterState { | 17 dictionary AdapterState { |
| 17 // The address of the adapter, in the format 'XX:XX:XX:XX:XX:XX'. | 18 // The address of the adapter, in the format 'XX:XX:XX:XX:XX:XX'. |
| 18 DOMString address; | 19 DOMString address; |
| 19 | 20 |
| 20 // The human-readable name of the adapter. | 21 // The human-readable name of the adapter. |
| 21 DOMString name; | 22 DOMString name; |
| 22 | 23 |
| 23 // Indicates whether or not the adapter has power. | 24 // Indicates whether or not the adapter has power. |
| 24 boolean powered; | 25 boolean powered; |
| 25 | 26 |
| 26 // Indicates whether or not the adapter is available (i.e. enabled). | 27 // Indicates whether or not the adapter is available (i.e. enabled). |
| 27 boolean available; | 28 boolean available; |
| 28 | 29 |
| 29 // Indicates whether or not the adapter is currently discovering. | 30 // Indicates whether or not the adapter is currently discovering. |
| 30 boolean discovering; | 31 boolean discovering; |
| 31 }; | 32 }; |
| 32 | 33 |
| 34 // Information about the state of a known Bluetooth device. | |
| 33 dictionary Device { | 35 dictionary Device { |
| 34 // The address of the device, in the format 'XX:XX:XX:XX:XX:XX'. | 36 // The address of the device, in the format 'XX:XX:XX:XX:XX:XX'. |
| 35 DOMString address; | 37 DOMString address; |
| 36 | 38 |
| 37 // The human-readable name of the device. | 39 // The human-readable name of the device. |
| 38 DOMString? name; | 40 DOMString? name; |
| 39 | 41 |
| 40 // The class of the device, a bit-field defined by | 42 // The class of the device, a bit-field defined by |
| 41 // http://www.bluetooth.org/en-us/specification/assigned-numbers/baseband. | 43 // http://www.bluetooth.org/en-us/specification/assigned-numbers/baseband. |
| 42 long? deviceClass; | 44 long? deviceClass; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 60 boolean? connected; | 62 boolean? connected; |
| 61 | 63 |
| 62 // UUIDs of protocols, profiles and services advertised by the device. | 64 // UUIDs of protocols, profiles and services advertised by the device. |
| 63 // For classic Bluetooth devices, this list is obtained from EIR data and | 65 // For classic Bluetooth devices, this list is obtained from EIR data and |
| 64 // SDP tables. For Low Energy devices, this list is obtained from AD and | 66 // SDP tables. For Low Energy devices, this list is obtained from AD and |
| 65 // GATT primary services. For dual mode devices this may be obtained from | 67 // GATT primary services. For dual mode devices this may be obtained from |
| 66 // both. | 68 // both. |
| 67 DOMString[]? uuids; | 69 DOMString[]? uuids; |
| 68 }; | 70 }; |
| 69 | 71 |
| 72 // Information about a Bluetooth profile. | |
| 70 dictionary Profile { | 73 dictionary Profile { |
| 71 // Unique profile identifier, e.g. 00001401-0000-1000-8000-00805F9B23FB | 74 // Unique profile identifier, e.g. 00001401-0000-1000-8000-00805F9B23FB |
| 72 DOMString uuid; | 75 DOMString uuid; |
| 73 | 76 |
| 74 // Human-readable name of the Profile, e.g. "Health Device" | 77 // Human-readable name of the Profile, e.g. "Health Device" |
| 75 DOMString? name; | 78 DOMString? name; |
| 76 | 79 |
| 77 // The RFCOMM channel id, used when the profile is to be exported to remote | 80 // The RFCOMM channel id, used when the profile is to be exported to remote |
| 78 // devices. | 81 // devices. |
| 79 long? channel; | 82 long? channel; |
| 80 | 83 |
| 81 // The LS2CAP PSM number, used when the profile is to be exported to remote | 84 // The LS2CAP PSM number, used when the profile is to be exported to remote |
| 82 // deviecs. | 85 // devices. |
| 83 long? psm; | 86 long? psm; |
| 84 | 87 |
| 85 // Specifies whether pairing (and encryption) is required to be able to | 88 // Specifies whether pairing (and encryption) is required to be able to |
| 86 // connect. | 89 // connect. |
| 87 boolean? requireAuthentication; | 90 boolean? requireAuthentication; |
| 88 | 91 |
| 89 // Specifies whether user authorization is required to be able to connect. | 92 // Specifies whether user authorization is required to be able to connect. |
| 90 boolean? requireAuthorization; | 93 boolean? requireAuthorization; |
| 91 | 94 |
| 92 // Specifies whether this profile will be automatically connected if any | 95 // Specifies whether this profile will be automatically connected if any |
| 93 // other profile of device also exporting this profile connects to the host. | 96 // other profile of device also exporting this profile connects to the host. |
| 94 boolean? autoConnect; | 97 boolean? autoConnect; |
| 95 | 98 |
| 96 // Specifies the implemented version of the profile. | 99 // Specifies the implemented version of the profile. |
| 97 long? version; | 100 long? version; |
| 98 | 101 |
| 99 // Specifies the profile-specific bit field of features the implementation | 102 // Specifies the profile-specific bit field of features the implementation |
| 100 // supports. | 103 // supports. |
| 101 long? features; | 104 long? features; |
| 102 }; | 105 }; |
| 103 | 106 |
| 104 dictionary ServiceRecord { | 107 // The socket properties specified in the $ref:update function. Each property |
| 105 // The name of the service. | 108 // is optional. If a property value is not specified, the existing value if |
| 106 DOMString name; | 109 // preserved when calling $ref:update. |
| 110 dictionary SocketProperties { | |
| 111 // Flag indicating if the socket is left open when the event page of the | |
|
miket_OOO
2014/03/28 20:48:43
Meggin will change "if" to whether, so might as we
rpaquay
2014/03/31 15:39:19
Done.
| |
| 112 // application is unloaded (see <a | |
| 113 // href="http://developer.chrome.com/apps/app_lifecycle.html">Manage App | |
| 114 // Lifecycle</a>). The default value is "false." When the application is | |
| 115 // loaded, any sockets previously opened with persistent=true can be fetched | |
| 116 // with $ref:getSockets. | |
| 117 boolean? persistent; | |
| 107 | 118 |
| 108 // The UUID of the service. | 119 // An application-defined string associated with the socket. |
| 109 DOMString? uuid; | 120 DOMString? name; |
| 121 | |
| 122 // The size of the buffer used to receive data. The default value is 4096. | |
| 123 long? bufferSize; | |
| 110 }; | 124 }; |
| 111 | 125 |
| 112 dictionary Socket { | 126 dictionary Socket { |
| 127 // The socket identifier. | |
| 128 long id; | |
| 129 | |
| 113 // The remote Bluetooth device associated with this socket. | 130 // The remote Bluetooth device associated with this socket. |
| 114 Device device; | 131 Device device; |
| 115 | 132 |
| 116 // The remote Bluetooth profile associated with this socket. | 133 // The remote Bluetooth uuid associated with this socket. |
| 117 Profile profile; | 134 DOMString uuid; |
| 118 | 135 |
| 119 // An identifier for this socket that should be used with the | 136 // Flag indicating whether the socket is left open when the application is |
|
miket_OOO
2014/03/28 20:48:43
good!
rpaquay
2014/03/31 15:39:19
Done.
| |
| 120 // read/write/disconnect methods. | 137 // suspended (see <code>SocketProperties.persistent</code>). |
| 121 long id; | 138 boolean persistent; |
| 139 | |
| 140 // Application-defined string associated with the socket. | |
| 141 DOMString? name; | |
| 142 | |
| 143 // The size of the buffer used to receive data. If no buffer size has been | |
| 144 // specified explictly, the value is not provided. | |
|
miket_OOO
2014/03/28 20:48:43
Nit: I wonder whether "field" is more accurate tha
rpaquay
2014/03/31 15:39:19
Done.
| |
| 145 long? bufferSize; | |
| 146 | |
| 147 // Flag indicating whether a connected socket blocks its peer from sending | |
| 148 // more data (see <code>setPaused</code>). | |
| 149 boolean paused; | |
| 122 }; | 150 }; |
| 123 | 151 |
| 124 dictionary OutOfBandPairingData { | 152 dictionary OutOfBandPairingData { |
| 125 // Simple Pairing Hash C. | 153 // Simple Pairing Hash C. |
| 126 // Always 16 octets long. | 154 // Always 16 octets long. |
| 127 ArrayBuffer hash; | 155 ArrayBuffer hash; |
| 128 | 156 |
| 129 // Simple Pairing Randomizer R. | 157 // Simple Pairing Randomizer R. |
| 130 // Always 16 octets long. | 158 // Always 16 octets long. |
| 131 ArrayBuffer randomizer; | 159 ArrayBuffer randomizer; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 147 dictionary ConnectOptions { | 175 dictionary ConnectOptions { |
| 148 // The connection is made to |device|. | 176 // The connection is made to |device|. |
| 149 Device device; | 177 Device device; |
| 150 | 178 |
| 151 // The connection is made to |profile|. | 179 // The connection is made to |profile|. |
| 152 Profile profile; | 180 Profile profile; |
| 153 }; | 181 }; |
| 154 | 182 |
| 155 // Options for the disconnect function. | 183 // Options for the disconnect function. |
| 156 dictionary DisconnectOptions { | 184 dictionary DisconnectOptions { |
| 157 // The socket to disconnect. | 185 // The socket identifier. |
| 158 Socket socket; | 186 long socketId; |
| 159 }; | |
| 160 | |
| 161 // Options for the read function. | |
| 162 dictionary ReadOptions { | |
| 163 // The socket to read from. | |
| 164 Socket socket; | |
| 165 }; | |
| 166 | |
| 167 // Options for the write function. | |
| 168 dictionary WriteOptions { | |
| 169 // The socket to write to. | |
| 170 Socket socket; | |
| 171 | |
| 172 // The data to write. | |
| 173 ArrayBuffer data; | |
| 174 }; | 187 }; |
| 175 | 188 |
| 176 // Options for the setOutOfBandPairingData function. | 189 // Options for the setOutOfBandPairingData function. |
| 177 dictionary SetOutOfBandPairingDataOptions { | 190 dictionary SetOutOfBandPairingDataOptions { |
| 178 // The address of the remote device that the data should be associated | 191 // The address of the remote device that the data should be associated |
| 179 // with. |deviceAddress| should be in the format 'XX:XX:XX:XX:XX:XX'. | 192 // with. |deviceAddress| should be in the format 'XX:XX:XX:XX:XX:XX'. |
| 180 DOMString address; | 193 DOMString address; |
| 181 | 194 |
| 182 // The Out Of Band Pairing Data. If this is omitted, the data for the | 195 // The Out Of Band Pairing Data. If this is omitted, the data for the |
| 183 // device is cleared instead. | 196 // device is cleared instead. |
| 184 OutOfBandPairingData? data; | 197 OutOfBandPairingData? data; |
| 185 }; | 198 }; |
| 186 | 199 |
| 200 // Callback from the <code>getSocket</code> method. | |
| 201 // |socket| : Object containing the socket information. | |
| 202 callback GetSocketCallback = void (Socket socket); | |
| 203 | |
| 204 // Callback from the <code>getSockets</code> method. | |
| 205 // |sockets| : Array of object containing socket information. | |
| 206 callback GetSocketsCallback = void (Socket[] sockets); | |
| 207 | |
| 208 // Data from an <code>onReceive</code> event. | |
| 209 dictionary ReceiveInfo { | |
| 210 // The socket identifier. | |
| 211 long socketId; | |
| 212 | |
| 213 // The data received, with a maxium size of <code>bufferSize</code>. | |
|
miket_OOO
2014/03/28 20:48:43
maximum (spelling)
rpaquay
2014/03/31 15:39:19
Done.
| |
| 214 ArrayBuffer data; | |
| 215 }; | |
| 216 | |
| 217 enum ReceiveError { | |
| 218 // The connection was disconnected. | |
| 219 disconnected, | |
| 220 | |
| 221 // A system error occurred and the connection may be unrecoverable. | |
| 222 system_error | |
| 223 }; | |
| 224 | |
| 225 // Data from an <code>onReceiveError</code> event. | |
| 226 dictionary ReceiveErrorInfo { | |
| 227 // The socket identifier. | |
| 228 long socketId; | |
| 229 | |
| 230 // The error message. | |
| 231 DOMString errorMessage; | |
| 232 | |
| 233 // An error code indicating what went wrong. | |
| 234 ReceiveError error; | |
| 235 }; | |
| 236 | |
| 187 // These functions all report failures via chrome.runtime.lastError. | 237 // These functions all report failures via chrome.runtime.lastError. |
| 188 interface Functions { | 238 interface Functions { |
| 189 // Registers the JavaScript application as an implementation for the given | |
| 190 // Profile; if a channel or PSM is specified, the profile will be exported | |
| 191 // in the host's SDP and GATT tables and advertised to other devices. | |
| 192 static void addProfile(Profile profile, ResultCallback callback); | |
| 193 | |
| 194 // Unregisters the JavaScript application as an implementation for the given | |
| 195 // Profile; only the uuid field of the Profile object is used. | |
| 196 static void removeProfile(Profile profile, ResultCallback callback); | |
| 197 | |
| 198 // Get information about the Bluetooth adapter. | 239 // Get information about the Bluetooth adapter. |
| 199 // |callback| : Called with an AdapterState object describing the adapter | 240 // |callback| : Called with an AdapterState object describing the adapter |
| 200 // state. | 241 // state. |
| 201 static void getAdapterState(AdapterStateCallback callback); | 242 static void getAdapterState(AdapterStateCallback callback); |
| 202 | 243 |
| 203 // Get a list of Bluetooth devices known to the system, including paired | 244 // Get a list of Bluetooth devices known to the system, including paired |
| 204 // and recently discovered devices. | 245 // and recently discovered devices. |
| 205 // |callback| : Called when the search is completed. | 246 // |callback| : Called when the search is completed. |
| 206 static void getDevices(DevicesCallback callback); | 247 static void getDevices(DevicesCallback callback); |
| 207 | 248 |
| 208 // Get information about a Bluetooth device known to the system. | 249 // Get information about a Bluetooth device known to the system. |
| 209 // |deviceAddress| : Address of device to get. | 250 // |deviceAddress| : Address of device to get. |
| 210 // |callback| : Called with the Device object describing the device. | 251 // |callback| : Called with the Device object describing the device. |
| 211 static void getDevice(DOMString deviceAddress, DeviceCallback callback); | 252 static void getDevice(DOMString deviceAddress, DeviceCallback callback); |
| 212 | 253 |
| 254 // Registers the JavaScript application as an implementation for the given | |
| 255 // Profile; if a channel or PSM is specified, the profile will be exported | |
| 256 // in the host's SDP and GATT tables and advertised to other devices. | |
| 257 static void addProfile(Profile profile, ResultCallback callback); | |
| 258 | |
| 259 // Unregisters the JavaScript application as an implementation for the given | |
| 260 // Profile; only the uuid field of the Profile object is used. | |
| 261 static void removeProfile(Profile profile, ResultCallback callback); | |
| 262 | |
| 213 // Connect to a service on a device. | 263 // Connect to a service on a device. |
| 214 // |options| : The options for the connection. | 264 // |options| : The options for the connection. |
| 215 // |callback| : Called to indicate success or failure. | 265 // |callback| : Called to indicate success or failure. |
| 216 static void connect(ConnectOptions options, | 266 static void connect(ConnectOptions options, |
| 217 ResultCallback callback); | 267 ResultCallback callback); |
| 218 | 268 |
| 219 // Close a Bluetooth connection. | 269 // Closes a Bluetooth connection. |
| 220 // |options| : The options for this function. | 270 // |options| : The options for this function. |
| 221 // |callback| : Called to indicate success or failure. | 271 // |callback| : Called to indicate success or failure. |
| 222 static void disconnect(DisconnectOptions options, | 272 static void disconnect(DisconnectOptions options, |
| 223 optional ResultCallback callback); | 273 optional ResultCallback callback); |
| 224 | 274 |
| 225 // Read data from a Bluetooth connection. The |callback| will be called | 275 // Sends data to a Bluetooth connection. |
| 226 // with the current data in the buffer even if it is empty. This function | 276 // |socketId| : The socket identifier. |
| 227 // should be polled to read incoming data. | 277 // |data| : The data to send. |
| 228 // |options| : The options for this function. | 278 // |callback| : Called with the number of bytes sent. |
| 229 // |callback| : Called with the data read from the socket buffer. | 279 static void send(long socketId, |
| 230 static void read(ReadOptions options, | 280 ArrayBuffer data, |
| 231 DataCallback callback); | 281 optional SizeCallback callback); |
| 232 | 282 |
| 233 // Write data to a Bluetooth connection. | 283 // Updates the socket properties. |
| 234 // |options| : The options for this function. | 284 // |socketId| : The socket identifier. |
| 235 // |callback| : Called with the number of bytes written. | 285 // |properties| : The properties to update. |
| 236 static void write(WriteOptions options, | 286 // |callback| : Called when the properties are updated. |
| 237 optional SizeCallback callback); | 287 static void updateSocket(long socketId, |
| 288 SocketProperties properties, | |
| 289 optional ResultCallback callback); | |
| 290 | |
| 291 // Enables or disables the application from receiving messages from its | |
| 292 // peer. The default value is "false". Pausing a socket is typically used by | |
|
miket_OOO
2014/03/28 20:48:43
Convention seems to be to wrap in <code>
rpaquay
2014/03/31 15:39:19
Done.
| |
| 293 // an application to throttle data sent by its peer. When a socket is | |
| 294 // paused, no $ref:onReceive event is raised. When a socket is connected and | |
| 295 // un-paused, $ref:onReceive events are raised again when messages are | |
| 296 // received. | |
| 297 static void setSocketPaused(long socketId, | |
| 298 boolean paused, | |
| 299 optional ResultCallback callback); | |
| 300 | |
| 301 // Retrieves the state of the given socket. | |
| 302 // |socketId| : The socket identifier. | |
| 303 // |callback| : Called when the socket state is available. | |
| 304 static void getSocket(long socketId, | |
| 305 GetSocketCallback callback); | |
| 306 | |
| 307 // Retrieves the list of currently opened sockets owned by the application. | |
| 308 // |callback| : Called when the list of sockets is available. | |
| 309 static void getSockets(GetSocketsCallback callback); | |
| 238 | 310 |
| 239 // Get the local Out of Band Pairing data. | 311 // Get the local Out of Band Pairing data. |
| 240 // |callback| : Called with the data. | 312 // |callback| : Called with the data. |
| 241 static void getLocalOutOfBandPairingData( | 313 static void getLocalOutOfBandPairingData( |
| 242 OutOfBandPairingDataCallback callback); | 314 OutOfBandPairingDataCallback callback); |
| 243 | 315 |
| 244 // Set the Out of Band Pairing data for a remote device. | 316 // Set the Out of Band Pairing data for a remote device. |
| 245 // Any previous Out Of Band Pairing Data for this device is overwritten. | 317 // Any previous Out Of Band Pairing Data for this device is overwritten. |
| 246 // |options| : The options for this function. | 318 // |options| : The options for this function. |
| 247 // |callback| : Called to indicate success or failure. | 319 // |callback| : Called to indicate success or failure. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 278 static void onDeviceChanged(Device device); | 350 static void onDeviceChanged(Device device); |
| 279 | 351 |
| 280 // Fired when a Bluetooth device that was previously discovered has been | 352 // Fired when a Bluetooth device that was previously discovered has been |
| 281 // out of range for long enough to be considered unavailable again, and | 353 // out of range for long enough to be considered unavailable again, and |
| 282 // when a paired device is removed. | 354 // when a paired device is removed. |
| 283 static void onDeviceRemoved(Device device); | 355 static void onDeviceRemoved(Device device); |
| 284 | 356 |
| 285 // Fired when a connection has been made for a registered profile. | 357 // Fired when a connection has been made for a registered profile. |
| 286 // |socket| : The socket for the connection. | 358 // |socket| : The socket for the connection. |
| 287 static void onConnection(Socket socket); | 359 static void onConnection(Socket socket); |
| 360 | |
| 361 // Event raised when data has been received for a given socket. | |
| 362 // |info| : The event data. | |
| 363 static void onReceive(ReceiveInfo info); | |
| 364 | |
| 365 // Event raised when a network error occured while the runtime was waiting | |
| 366 // for data on the socket. Once this event is raised, the socket is set to | |
| 367 // <code>paused</code> and no more <code>onReceive</code> events are raised | |
| 368 // for this socket. | |
| 369 // |info| : The event data. | |
| 370 static void onReceiveError(ReceiveErrorInfo info); | |
| 288 }; | 371 }; |
| 289 }; | 372 }; |
| OLD | NEW |