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 10 matching lines...) Expand all Loading... | |
| 53 // field directly. | 55 // field directly. |
| 54 DeviceType? type; | 56 DeviceType? type; |
| 55 | 57 |
| 56 // Indicates whether or not the device is paired with the system. | 58 // Indicates whether or not the device is paired with the system. |
| 57 boolean? paired; | 59 boolean? paired; |
| 58 | 60 |
| 59 // Indicates whether the device is currently connected to the system. | 61 // Indicates whether the device is currently connected to the system. |
| 60 boolean? connected; | 62 boolean? connected; |
| 61 }; | 63 }; |
| 62 | 64 |
| 65 // Information about a Bluetooth profile. | |
| 63 dictionary Profile { | 66 dictionary Profile { |
| 64 // Unique profile identifier, e.g. 00001401-0000-1000-8000-00805F9B23FB | 67 // Unique profile identifier, e.g. 00001401-0000-1000-8000-00805F9B23FB |
| 65 DOMString uuid; | 68 DOMString uuid; |
| 66 | 69 |
| 67 // Human-readable name of the Profile, e.g. "Health Device" | 70 // Human-readable name of the Profile, e.g. "Health Device" |
| 68 DOMString? name; | 71 DOMString? name; |
| 69 | 72 |
| 70 // The RFCOMM channel id, used when the profile is to be exported to remote | 73 // The RFCOMM channel id, used when the profile is to be exported to remote |
| 71 // devices. | 74 // devices. |
| 72 long? channel; | 75 long? channel; |
| 73 | 76 |
| 74 // The LS2CAP PSM number, used when the profile is to be exported to remote | 77 // The LS2CAP PSM number, used when the profile is to be exported to remote |
| 75 // deviecs. | 78 // devices. |
| 76 long? psm; | 79 long? psm; |
| 77 | 80 |
| 78 // Specifies whether pairing (and encryption) is required to be able to | 81 // Specifies whether pairing (and encryption) is required to be able to |
| 79 // connect. | 82 // connect. |
| 80 boolean? requireAuthentication; | 83 boolean? requireAuthentication; |
| 81 | 84 |
| 82 // Specifies whether user authorization is required to be able to connect. | 85 // Specifies whether user authorization is required to be able to connect. |
| 83 boolean? requireAuthorization; | 86 boolean? requireAuthorization; |
| 84 | 87 |
| 85 // Specifies whether this profile will be automatically connected if any | 88 // Specifies whether this profile will be automatically connected if any |
| 86 // other profile of device also exporting this profile connects to the host. | 89 // other profile of device also exporting this profile connects to the host. |
| 87 boolean? autoConnect; | 90 boolean? autoConnect; |
| 88 | 91 |
| 89 // Specifies the implemented version of the profile. | 92 // Specifies the implemented version of the profile. |
| 90 long? version; | 93 long? version; |
| 91 | 94 |
| 92 // Specifies the profile-specific bit field of features the implementation | 95 // Specifies the profile-specific bit field of features the implementation |
| 93 // supports. | 96 // supports. |
| 94 long? features; | 97 long? features; |
| 95 }; | 98 }; |
| 96 | 99 |
| 97 dictionary ServiceRecord { | 100 // The socket properties specified in the $ref:update function. Each property |
| 98 // The name of the service. | 101 // is optional. If a property value is not specified, the existing value if |
| 99 DOMString name; | 102 // preserved when calling $ref:update. |
| 103 dictionary SocketProperties { | |
| 104 // Flag indicating if the socket is left open when the event page of the | |
| 105 // application is unloaded (see <a | |
| 106 // href="http://developer.chrome.com/apps/app_lifecycle.html">Manage App | |
| 107 // Lifecycle</a>). The default value is "false." When the application is | |
| 108 // loaded, any sockets previously opened with persistent=true can be fetched | |
| 109 // with $ref:getSockets. | |
| 110 boolean? persistent; | |
| 100 | 111 |
| 101 // The UUID of the service. | 112 // An application-defined string associated with the socket. |
| 102 DOMString? uuid; | 113 DOMString? name; |
| 114 | |
| 115 // The size of the buffer used to receive data. The default value is 4096. | |
| 116 long? bufferSize; | |
| 103 }; | 117 }; |
| 104 | 118 |
| 105 dictionary Socket { | 119 dictionary Socket { |
| 120 // The socket identifier. | |
| 121 long id; | |
| 122 | |
| 106 // The remote Bluetooth device associated with this socket. | 123 // The remote Bluetooth device associated with this socket. |
| 107 Device device; | 124 Device device; |
| 108 | 125 |
| 109 // The remote Bluetooth profile associated with this socket. | 126 // The remote Bluetooth uuid associated with this socket. |
| 110 Profile profile; | 127 DOMString uuid; |
| 111 | 128 |
| 112 // An identifier for this socket that should be used with the | 129 // Flag indicating whether the socket is left open when the application is |
| 113 // read/write/disconnect methods. | 130 // suspended (see <code>SocketProperties.persistent</code>). |
| 114 long id; | 131 boolean persistent; |
| 132 | |
| 133 // Application-defined string associated with the socket. | |
| 134 DOMString? name; | |
| 135 | |
| 136 // The size of the buffer used to receive data. If no buffer size has been | |
| 137 // specified explictly, the value is not provided. | |
| 138 long? bufferSize; | |
| 139 | |
| 140 // Flag indicating whether a connected socket blocks its peer from sending | |
| 141 // more data (see <code>setPaused</code>). | |
| 142 boolean paused; | |
| 115 }; | 143 }; |
| 116 | 144 |
| 117 dictionary OutOfBandPairingData { | 145 dictionary OutOfBandPairingData { |
| 118 // Simple Pairing Hash C. | 146 // Simple Pairing Hash C. |
| 119 // Always 16 octets long. | 147 // Always 16 octets long. |
| 120 ArrayBuffer hash; | 148 ArrayBuffer hash; |
| 121 | 149 |
| 122 // Simple Pairing Randomizer R. | 150 // Simple Pairing Randomizer R. |
| 123 // Always 16 octets long. | 151 // Always 16 octets long. |
| 124 ArrayBuffer randomizer; | 152 ArrayBuffer randomizer; |
| 125 }; | 153 }; |
| 126 | 154 |
| 127 callback AdapterStateCallback = void(AdapterState result); | 155 callback AdapterStateCallback = void(AdapterState result); |
| 128 callback AddressCallback = void (DOMString result); | 156 callback AddressCallback = void (DOMString result); |
| 129 callback BooleanCallback = void (boolean result); | 157 callback BooleanCallback = void (boolean result); |
| 130 callback DataCallback = void (optional ArrayBuffer result); | |
| 131 callback DevicesCallback = void (Device[] result); | 158 callback DevicesCallback = void (Device[] result); |
| 132 callback NameCallback = void (DOMString result); | |
| 133 callback OutOfBandPairingDataCallback = void (OutOfBandPairingData data); | 159 callback OutOfBandPairingDataCallback = void (OutOfBandPairingData data); |
| 134 callback ProfilesCallback = void(Profile[] result); | 160 callback ProfilesCallback = void(Profile[] result); |
| 135 callback ResultCallback = void (); | 161 callback ResultCallback = void (); |
| 136 callback ServicesCallback = void(ServiceRecord[] result); | |
| 137 callback SizeCallback = void (long result); | 162 callback SizeCallback = void (long result); |
| 138 callback SocketCallback = void (Socket result); | |
| 139 | 163 |
| 140 // Options for the getProfiles function. | 164 // Options for the getProfiles function. |
| 141 dictionary GetProfilesOptions { | 165 dictionary GetProfilesOptions { |
| 142 // The remote Bluetooth device to retrieve the exported profiles list from. | 166 // The remote Bluetooth device to retrieve the exported profiles list from. |
| 143 Device device; | 167 Device device; |
| 144 }; | 168 }; |
| 145 | 169 |
| 146 // Options for the getServices function. | |
| 147 dictionary GetServicesOptions { | |
| 148 // The address of the device to inquire about. |deviceAddress| should be | |
| 149 // in the format 'XX:XX:XX:XX:XX:XX'. | |
| 150 DOMString deviceAddress; | |
| 151 }; | |
| 152 | |
| 153 // Options for the connect function. | 170 // Options for the connect function. |
| 154 dictionary ConnectOptions { | 171 dictionary ConnectOptions { |
| 155 // The connection is made to |device|. | 172 // The connection is made to |device|. |
| 156 Device device; | 173 Device device; |
| 157 | 174 |
| 158 // The connection is made to |profile|. | 175 // The connection is made to |profile|. |
| 159 Profile profile; | 176 Profile profile; |
| 160 }; | 177 }; |
| 161 | 178 |
| 162 // Options for the disconnect function. | 179 // Options for the disconnect function. |
| 163 dictionary DisconnectOptions { | 180 dictionary DisconnectOptions { |
| 164 // The socket to disconnect. | 181 // The socket identifier. |
| 165 Socket socket; | 182 long socketId; |
| 166 }; | |
| 167 | |
| 168 // Options for the read function. | |
| 169 dictionary ReadOptions { | |
| 170 // The socket to read from. | |
| 171 Socket socket; | |
| 172 }; | |
| 173 | |
| 174 // Options for the write function. | |
| 175 dictionary WriteOptions { | |
| 176 // The socket to write to. | |
| 177 Socket socket; | |
| 178 | |
| 179 // The data to write. | |
| 180 ArrayBuffer data; | |
| 181 }; | 183 }; |
| 182 | 184 |
| 183 // Options for the setOutOfBandPairingData function. | 185 // Options for the setOutOfBandPairingData function. |
| 184 dictionary SetOutOfBandPairingDataOptions { | 186 dictionary SetOutOfBandPairingDataOptions { |
| 185 // The address of the remote device that the data should be associated | 187 // The address of the remote device that the data should be associated |
| 186 // with. |deviceAddress| should be in the format 'XX:XX:XX:XX:XX:XX'. | 188 // with. |deviceAddress| should be in the format 'XX:XX:XX:XX:XX:XX'. |
| 187 DOMString address; | 189 DOMString address; |
| 188 | 190 |
| 189 // The Out Of Band Pairing Data. If this is omitted, the data for the | 191 // The Out Of Band Pairing Data. If this is omitted, the data for the |
| 190 // device is cleared instead. | 192 // device is cleared instead. |
| 191 OutOfBandPairingData? data; | 193 OutOfBandPairingData? data; |
| 192 }; | 194 }; |
| 193 | 195 |
| 196 // Callback from the <code>getSocket</code> method. | |
| 197 // |socket| : Object containing the socket information. | |
| 198 callback GetSocketCallback = void (Socket socket); | |
| 199 | |
| 200 // Callback from the <code>getSockets</code> method. | |
| 201 // |sockets| : Array of object containing socket information. | |
| 202 callback GetSocketsCallback = void (Socket[] sockets); | |
| 203 | |
| 204 // Data from an <code>onReceive</code> event. | |
| 205 dictionary ReceiveInfo { | |
| 206 // The socket identifier. | |
| 207 long socketId; | |
| 208 | |
| 209 // The data received, with a maxium size of <code>bufferSize</code>. | |
| 210 ArrayBuffer data; | |
| 211 }; | |
| 212 | |
| 213 enum ReceiveError { | |
| 214 // The connection was disconnected. | |
| 215 disconnected, | |
| 216 | |
| 217 // A system error occurred and the connection may be unrecoverable. | |
| 218 system_error | |
| 219 }; | |
| 220 | |
| 221 // Data from an <code>onReceiveError</code> event. | |
| 222 dictionary ReceiveErrorInfo { | |
| 223 // The socket identifier. | |
| 224 long socketId; | |
| 225 | |
| 226 // The error message. | |
| 227 DOMString errorMessage; | |
| 228 | |
| 229 // An error code indicating what went wrong. | |
| 230 ReceiveError error; | |
| 231 }; | |
| 232 | |
| 194 // These functions all report failures via chrome.runtime.lastError. | 233 // These functions all report failures via chrome.runtime.lastError. |
| 195 interface Functions { | 234 interface Functions { |
| 196 // Registers the JavaScript application as an implementation for the given | |
| 197 // Profile; if a channel or PSM is specified, the profile will be exported | |
| 198 // in the host's SDP and GATT tables and advertised to other devices. | |
| 199 static void addProfile(Profile profile, ResultCallback callback); | |
| 200 | |
| 201 // Unregisters the JavaScript application as an implementation for the given | |
| 202 // Profile; only the uuid field of the Profile object is used. | |
| 203 static void removeProfile(Profile profile, ResultCallback callback); | |
| 204 | |
| 205 // Get information about the Bluetooth adapter. | 235 // Get information about the Bluetooth adapter. |
| 206 // |callback| : Called with an AdapterState object describing the adapter | 236 // |callback| : Called with an AdapterState object describing the adapter |
| 207 // state. | 237 // state. |
| 208 static void getAdapterState(AdapterStateCallback callback); | 238 static void getAdapterState(AdapterStateCallback callback); |
| 209 | 239 |
| 210 // Get a list of Bluetooth devices known to the system, including paired | 240 // Get a list of Bluetooth devices known to the system, including paired |
| 211 // and recently discovered devices. | 241 // and recently discovered devices. |
| 212 // |callback| : Called when the search is completed. | 242 // |callback| : Called when the search is completed. |
| 213 static void getDevices(DevicesCallback callback); | 243 static void getDevices(DevicesCallback callback); |
| 214 | 244 |
| 245 // Registers the JavaScript application as an implementation for the given | |
| 246 // Profile; if a channel or PSM is specified, the profile will be exported | |
| 247 // in the host's SDP and GATT tables and advertised to other devices. | |
| 248 static void addProfile(Profile profile, ResultCallback callback); | |
| 249 | |
| 250 // Unregisters the JavaScript application as an implementation for the given | |
| 251 // Profile; only the uuid field of the Profile object is used. | |
| 252 static void removeProfile(Profile profile, ResultCallback callback); | |
| 253 | |
| 215 // Returns the set of exported profiles for the device specified in options. | 254 // Returns the set of exported profiles for the device specified in options. |
| 216 // This function will not initiate a connection to the remote device. | 255 // This function will not initiate a connection to the remote device. |
| 217 static void getProfiles(GetProfilesOptions options, | 256 static void getProfiles(GetProfilesOptions options, |
| 218 ProfilesCallback callback); | 257 ProfilesCallback callback); |
| 219 | 258 |
| 220 // Get a list of services provided by a device. | 259 // Connects to a profile on a device. |
| 221 static void getServices(GetServicesOptions options, | |
| 222 ServicesCallback callback); | |
| 223 | |
| 224 // Connect to a service on a device. | |
| 225 // |options| : The options for the connection. | 260 // |options| : The options for the connection. |
| 226 // |callback| : Called to indicate success or failure. | 261 // |callback| : Called to indicate success or failure. |
| 227 static void connect(ConnectOptions options, | 262 static void connect(ConnectOptions options, |
| 228 ResultCallback callback); | 263 ResultCallback callback); |
| 229 | 264 |
| 230 // Close a Bluetooth connection. | 265 // Closes a Bluetooth connection. |
| 231 // |options| : The options for this function. | 266 // |options| : The options for this function. |
| 232 // |callback| : Called to indicate success or failure. | 267 // |callback| : Called to indicate success or failure. |
| 233 static void disconnect(DisconnectOptions options, | 268 static void disconnect(DisconnectOptions options, |
| 234 optional ResultCallback callback); | 269 optional ResultCallback callback); |
|
keybuk
2014/03/27 20:20:07
TODO or Bug for changing disconnect to:
chrome.b
rpaquay
2014/03/27 22:00:01
Done: crbug/357328
| |
| 235 | 270 |
| 236 // Read data from a Bluetooth connection. The |callback| will be called | 271 // Sends data to a Bluetooth connection. |
| 237 // with the current data in the buffer even if it is empty. This function | 272 // |socketId| : The socket identifier. |
| 238 // should be polled to read incoming data. | 273 // |data| : The data to send. |
| 239 // |options| : The options for this function. | 274 // |callback| : Called with the number of bytes sent. |
| 240 // |callback| : Called with the data read from the socket buffer. | 275 static void send(long socketId, |
| 241 static void read(ReadOptions options, | 276 ArrayBuffer data, |
| 242 DataCallback callback); | 277 optional SizeCallback callback); |
| 243 | 278 |
| 244 // Write data to a Bluetooth connection. | 279 // Updates the socket properties. |
| 245 // |options| : The options for this function. | 280 // |socketId| : The socket identifier. |
| 246 // |callback| : Called with the number of bytes written. | 281 // |properties| : The properties to update. |
| 247 static void write(WriteOptions options, | 282 // |callback| : Called when the properties are updated. |
| 248 optional SizeCallback callback); | 283 static void updateSocket(long socketId, |
| 284 SocketProperties properties, | |
| 285 optional ResultCallback callback); | |
| 286 | |
| 287 // Enables or disables the application from receiving messages from its | |
| 288 // peer. The default value is "false". Pausing a socket is typically used by | |
| 289 // an application to throttle data sent by its peer. When a socket is | |
| 290 // paused, no $ref:onReceive event is raised. When a socket is connected and | |
| 291 // un-paused, $ref:onReceive events are raised again when messages are | |
| 292 // received. | |
| 293 static void setSocketPaused(long socketId, | |
| 294 boolean paused, | |
| 295 optional ResultCallback callback); | |
| 296 | |
| 297 // Retrieves the state of the given socket. | |
| 298 // |socketId| : The socket identifier. | |
| 299 // |callback| : Called when the socket state is available. | |
| 300 static void getSocket(long socketId, | |
| 301 GetSocketCallback callback); | |
| 302 | |
| 303 // Retrieves the list of currently opened sockets owned by the application. | |
| 304 // |callback| : Called when the list of sockets is available. | |
| 305 static void getSockets(GetSocketsCallback callback); | |
| 249 | 306 |
| 250 // Get the local Out of Band Pairing data. | 307 // Get the local Out of Band Pairing data. |
| 251 // |callback| : Called with the data. | 308 // |callback| : Called with the data. |
| 252 static void getLocalOutOfBandPairingData( | 309 static void getLocalOutOfBandPairingData( |
| 253 OutOfBandPairingDataCallback callback); | 310 OutOfBandPairingDataCallback callback); |
| 254 | 311 |
| 255 // Set the Out of Band Pairing data for a remote device. | 312 // Set the Out of Band Pairing data for a remote device. |
| 256 // Any previous Out Of Band Pairing Data for this device is overwritten. | 313 // Any previous Out Of Band Pairing Data for this device is overwritten. |
| 257 // |options| : The options for this function. | 314 // |options| : The options for this function. |
| 258 // |callback| : Called to indicate success or failure. | 315 // |callback| : Called to indicate success or failure. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 289 static void onDeviceChanged(Device device); | 346 static void onDeviceChanged(Device device); |
| 290 | 347 |
| 291 // Fired when a Bluetooth device that was previously discovered has been | 348 // Fired when a Bluetooth device that was previously discovered has been |
| 292 // out of range for long enough to be considered unavailable again, and | 349 // out of range for long enough to be considered unavailable again, and |
| 293 // when a paired device is removed. | 350 // when a paired device is removed. |
| 294 static void onDeviceRemoved(Device device); | 351 static void onDeviceRemoved(Device device); |
| 295 | 352 |
| 296 // Fired when a connection has been made for a registered profile. | 353 // Fired when a connection has been made for a registered profile. |
| 297 // |socket| : The socket for the connection. | 354 // |socket| : The socket for the connection. |
| 298 static void onConnection(Socket socket); | 355 static void onConnection(Socket socket); |
| 356 | |
| 357 // Event raised when data has been received for a given socket. | |
| 358 // |info| : The event data. | |
| 359 static void onReceive(ReceiveInfo info); | |
| 360 | |
| 361 // Event raised when a network error occured while the runtime was waiting | |
| 362 // for data on the socket. Once this event is raised, the socket is set to | |
| 363 // <code>paused</code> and no more <code>onReceive</code> events are raised | |
| 364 // for this socket. | |
| 365 // |info| : The event data. | |
| 366 static void onReceiveError(ReceiveErrorInfo info); | |
| 299 }; | 367 }; |
| 300 }; | 368 }; |
| OLD | NEW |