Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 module blink.mojom; | 5 module blink.mojom; |
| 6 | 6 |
| 7 import "device/bluetooth/public/interfaces/uuid.mojom"; | 7 import "device/bluetooth/public/interfaces/uuid.mojom"; |
| 8 | 8 |
| 9 // Result codes that can occur during Web Bluetooth execution, which are | 9 // Instance ID Note: |
| 10 // transformed to a DOMException in Source/modules/bluetooth/BluetoothError.cpp. | 10 // |
| 11 // Structs and parameters use 'instance_id' string values as unique identifiers | |
| 12 // for GATT objects. Subsequent calls from and to the client code use the ids | |
| 13 // to refer to previously disclosed objects. | |
|
dcheng
2017/01/14 10:23:45
Nit: Perhaps expand GATT the first time it's writt
scheib
2017/01/17 19:20:43
Done.
| |
| 14 // | |
| 15 // Device IDs are exposed to web content, valid to persist, and have a dedicated | |
| 16 // type, WebBluetoothDeviceId. See comments on that struct. | |
| 17 // | |
| 18 // Service, characteristic, and descriptor IDs are simply strings not exposed to | |
| 19 // web content and use platform specific values. They are only used for | |
| 20 // comparison and not intended to be parsed by code, serialized, or exposed to | |
| 21 // web content. | |
| 22 // | |
| 23 // For example: | |
| 24 // RemoteServerGetPrimaryServices() may return a struct of type | |
| 25 // WebBluetoothRemoteGATTService with an instance_id of "service1". | |
| 26 // To retrieve characteristics of that service use that id when calling | |
| 27 // RemoteServiceGetCharacteristics("service1", ...). | |
| 28 | |
| 29 // Result codes that can occur during Web Bluetooth execution. | |
| 30 // Transformed to a DOMException in Source/modules/bluetooth/BluetoothError.cpp. | |
| 11 // | 31 // |
| 12 // These errors all produce constant message strings. If a particular message | 32 // These errors all produce constant message strings. If a particular message |
| 13 // needs a dynamic component, we should add a separate enum so type-checking the | 33 // needs a dynamic component, we should add a separate enum so type-checking the |
| 14 // IPC ensures the dynamic component is passed. | 34 // IPC ensures the dynamic component is passed. |
| 15 enum WebBluetoothResult { | 35 enum WebBluetoothResult { |
| 16 SUCCESS, | 36 SUCCESS, |
| 17 // AbortError: | 37 // AbortError: |
| 18 // InvalidModificationError: | 38 // InvalidModificationError: |
| 19 GATT_INVALID_ATTRIBUTE_LENGTH, | 39 GATT_INVALID_ATTRIBUTE_LENGTH, |
| 20 // InvalidStateError: | 40 // InvalidStateError: |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 bool accept_all_devices; | 106 bool accept_all_devices; |
| 87 }; | 107 }; |
| 88 | 108 |
| 89 // Indicates if the function will return a single or multiple | 109 // Indicates if the function will return a single or multiple |
| 90 // GATT objects. | 110 // GATT objects. |
| 91 enum WebBluetoothGATTQueryQuantity { | 111 enum WebBluetoothGATTQueryQuantity { |
| 92 SINGLE, | 112 SINGLE, |
| 93 MULTIPLE | 113 MULTIPLE |
| 94 }; | 114 }; |
| 95 | 115 |
| 116 // An identifier uniquely identifying a Bluetooth device. This identifier is | |
| 117 // safe to provide to web content and is unique per origin, even if referring | |
| 118 // to a common device. Web content may persist this identifier for future | |
| 119 // sessions to identify the same device. | |
| 96 struct WebBluetoothDeviceId { | 120 struct WebBluetoothDeviceId { |
| 97 string device_id; | 121 string device_id; |
| 98 }; | 122 }; |
| 99 | 123 |
| 100 struct WebBluetoothDevice { | 124 struct WebBluetoothDevice { |
| 101 WebBluetoothDeviceId id; | 125 WebBluetoothDeviceId id; |
| 102 string? name; | 126 string? name; |
| 103 }; | 127 }; |
| 104 | 128 |
| 105 struct WebBluetoothRemoteGATTService { | 129 struct WebBluetoothRemoteGATTService { |
| 106 string instance_id; | 130 string instance_id; // See Instance ID Note above. |
| 107 string uuid; | 131 string uuid; |
|
dcheng
2017/01/14 10:23:45
Why does this need both uuid and instance_id? Also
scheib
2017/01/17 19:20:43
I added comments.
| |
| 108 }; | 132 }; |
| 109 | 133 |
| 110 struct WebBluetoothRemoteGATTCharacteristic { | 134 struct WebBluetoothRemoteGATTCharacteristic { |
| 111 string instance_id; | 135 string instance_id; // See Instance ID Note above. |
| 112 string uuid; | 136 string uuid; |
| 113 uint32 properties; | 137 uint32 properties; |
| 114 }; | 138 }; |
| 115 | 139 |
| 116 struct WebBluetoothRemoteGATTDescriptor { | 140 struct WebBluetoothRemoteGATTDescriptor { |
| 117 string instance_id; | 141 string instance_id; // See Instance ID Note above. |
| 118 string uuid; | 142 string uuid; |
| 119 }; | 143 }; |
| 120 | 144 |
| 121 // Web Bluetooth Interface that Blink can use to perform | 145 // Web Bluetooth Interface that Blink can use to perform |
| 122 // Bluetooth GATT Operations on Bluetooth Devices. | 146 // Bluetooth GATT Operations on Bluetooth Devices. |
| 123 interface WebBluetoothService { | 147 interface WebBluetoothService { |
| 124 // Sets the client for this WebBluetoothService. The service will notify the | 148 // Sets the client for this WebBluetoothService. The service will notify the |
| 125 // client of device events e.g. when a Characteristic's value changes or when | 149 // client of device events e.g. when a Characteristic's value changes or when |
| 126 // a device disconnects. | 150 // a device disconnects. |
| 127 SetClient(associated WebBluetoothServiceClient client); | 151 SetClient(associated WebBluetoothServiceClient client); |
| 128 | 152 |
| 129 RequestDevice(WebBluetoothRequestDeviceOptions options) | 153 RequestDevice(WebBluetoothRequestDeviceOptions options) |
| 130 => (WebBluetoothResult result, WebBluetoothDevice? device); | 154 => (WebBluetoothResult result, WebBluetoothDevice? device); |
| 131 | 155 |
| 132 // Creates a GATT Connection to a Bluetooth Device with |device_id| if a | 156 // Creates a GATT Connection to a Bluetooth Device identified by |device_id| |
| 133 // connection to the device didn't exist already. If a GATT connection existed | 157 // if a connection to the device didn't exist already. If a GATT connection |
| 134 // already then this function increases the ref count to keep that connection | 158 // existed already then this function increases the ref count to keep that |
| 135 // alive. | 159 // connection alive. |
| 136 RemoteServerConnect(WebBluetoothDeviceId device_id) => (WebBluetoothResult res ult); | 160 RemoteServerConnect(WebBluetoothDeviceId device_id) => (WebBluetoothResult res ult); |
| 137 | 161 |
| 138 // If a GATT connection exists for Device with |device_id| then decreases | 162 // If a GATT connection exists for Device identified by |device_id| then |
| 139 // the ref count for that connection. | 163 // decreases the ref count for that connection. |
| 140 RemoteServerDisconnect(WebBluetoothDeviceId device_id); | 164 RemoteServerDisconnect(WebBluetoothDeviceId device_id); |
| 141 | 165 |
| 142 // If |services_uuid| is present, returns services with |services_uuid|. | 166 // Returns the Services of a GATT Device identified by |device_id|. |
| 167 // If |services_uuid| is present, filters services by |services_uuid|. | |
| 143 // Otherwise returns all non-blocklisted services. | 168 // Otherwise returns all non-blocklisted services. |
| 144 // If |quantity| == WebBluetoothGATTQueryQuantity::SINGLE, only one | 169 // If |quantity| == WebBluetoothGATTQueryQuantity::SINGLE, at most one |
| 145 // service will be returned. | 170 // service will be returned. |
| 146 RemoteServerGetPrimaryServices( | 171 RemoteServerGetPrimaryServices( |
| 147 WebBluetoothDeviceId device_id, | 172 WebBluetoothDeviceId device_id, |
| 148 WebBluetoothGATTQueryQuantity quantity, | 173 WebBluetoothGATTQueryQuantity quantity, |
| 149 bluetooth.mojom.UUID? services_uuid) => ( | 174 bluetooth.mojom.UUID? services_uuid) => ( |
| 150 WebBluetoothResult result, | 175 WebBluetoothResult result, |
| 151 array<WebBluetoothRemoteGATTService>? services); | 176 array<WebBluetoothRemoteGATTService>? services); |
| 152 | 177 |
| 153 // Returns the Characteristics of a GATT Service with |service_instance_id|. | 178 // Returns the Characteristics of a GATT Service identified by |
| 154 // If |quantity| == WebBluetoothGATTQueryQuantity::SINGLE, only one | 179 // |service_instance_id|. |
| 180 // If |characteristics_uuid| is present, filters characteristics by | |
| 181 // |characteristics_uuid|. Otherwise returns all non-blocklisted services. | |
| 182 // If |quantity| == WebBluetoothGATTQueryQuantity::SINGLE, at most one | |
| 155 // characteristic will be returned. | 183 // characteristic will be returned. |
| 156 RemoteServiceGetCharacteristics( | 184 RemoteServiceGetCharacteristics( |
| 157 string service_instance_id, | 185 string service_instance_id, |
| 158 WebBluetoothGATTQueryQuantity quantity, | 186 WebBluetoothGATTQueryQuantity quantity, |
| 159 bluetooth.mojom.UUID? characteristics_uuid) => ( | 187 bluetooth.mojom.UUID? characteristics_uuid) => ( |
| 160 WebBluetoothResult result, | 188 WebBluetoothResult result, |
| 161 array<WebBluetoothRemoteGATTCharacteristic>? characteristics); | 189 array<WebBluetoothRemoteGATTCharacteristic>? characteristics); |
| 162 | 190 |
| 163 // Reads the value for characteristic with | 191 // Reads the value for the characteristic identified by |
| 164 // |characteristic_instance_id|. If the value is successfully read the | 192 // |characteristic_instance_id|. If the value is successfully read the |
| 165 // callback will be run with WebBluetoothResult::SUCCESS and the | 193 // callback will be run with WebBluetoothResult::SUCCESS and the |
| 166 // characteristic's value. If the value is not successfully read the | 194 // characteristic's value. If the value is not successfully read the |
| 167 // callback with be run with the corresponding error and nullptr for value. | 195 // callback with be run with the corresponding error and nullptr for value. |
| 168 RemoteCharacteristicReadValue( | 196 RemoteCharacteristicReadValue( |
| 169 string characteristic_instance_id) => ( | 197 string characteristic_instance_id) => ( |
| 170 WebBluetoothResult result, | 198 WebBluetoothResult result, |
| 171 array<uint8>? value); | 199 array<uint8>? value); |
| 172 | 200 |
| 173 // Writes a value to the characteristic with | 201 // Writes a value to the characteristic identified by |
| 174 // |characteristic_instance_id|. The callback is run with | 202 // |characteristic_instance_id|. The callback is run with |
| 175 // WebBluetoothResult::SUCCESS if the value was successfully | 203 // WebBluetoothResult::SUCCESS if the value was successfully |
| 176 // written. | 204 // written. |
| 177 RemoteCharacteristicWriteValue( | 205 RemoteCharacteristicWriteValue( |
| 178 string characteristic_instance_id, | 206 string characteristic_instance_id, |
| 179 array<uint8> value) => (WebBluetoothResult result); | 207 array<uint8> value) => (WebBluetoothResult result); |
| 180 | 208 |
| 181 // Starts notifications for the characteristic with | 209 // Starts notifications for the characteristic identified by |
| 182 // |characteristic_instance_id|. | 210 // |characteristic_instance_id|. |
| 183 RemoteCharacteristicStartNotifications( | 211 RemoteCharacteristicStartNotifications( |
| 184 string characteristic_instance_id) => (WebBluetoothResult result); | 212 string characteristic_instance_id) => (WebBluetoothResult result); |
| 185 | 213 |
| 186 // Stops notifications for the characteristic with | 214 // Stops notifications for the characteristic identified by |
| 187 // |characteristic_instance_id|. | 215 // |characteristic_instance_id|. |
| 188 RemoteCharacteristicStopNotifications( | 216 RemoteCharacteristicStopNotifications( |
| 189 string characteristic_instance_id) => (); | 217 string characteristic_instance_id) => (); |
| 190 | 218 |
| 191 // Returns the Descriptors of a GATT Characteristic with | 219 // Returns the Descriptors of a GATT Characteristic identified by |
| 192 // |characteristics_instance_id|. | 220 // |characteristics_instance_id|. |
| 193 // If |quantity| == WebBluetoothGATTQueryQuantity::SINGLE, only one descriptor | 221 // If |descriptor_uuid| is present, filters descriptors by |
| 194 // will be returned. | 222 // |descriptor_uuid|. Otherwise returns all non-blocklisted descriptors. |
| 223 // If |quantity| == WebBluetoothGATTQueryQuantity::SINGLE, at most one | |
| 224 // characteristic will be returned. | |
| 195 RemoteCharacteristicGetDescriptors( | 225 RemoteCharacteristicGetDescriptors( |
| 196 string characteristics_instance_id, | 226 string characteristics_instance_id, |
| 197 WebBluetoothGATTQueryQuantity quantity, | 227 WebBluetoothGATTQueryQuantity quantity, |
| 198 bluetooth.mojom.UUID? descriptor_uuid) => ( | 228 bluetooth.mojom.UUID? descriptor_uuid) => ( |
| 199 WebBluetoothResult result, | 229 WebBluetoothResult result, |
| 200 array<WebBluetoothRemoteGATTDescriptor>? descriptors); | 230 array<WebBluetoothRemoteGATTDescriptor>? descriptors); |
| 201 }; | 231 }; |
| 202 | 232 |
| 203 // Classes should implement this interface and pass an associated pointer | 233 // Classes should implement this interface and pass an associated pointer |
| 204 // bound to them to the WebBluetoothService by using SetClient. Classes | 234 // bound to them to the WebBluetoothService by using SetClient. Classes |
| 205 // that do this will be notified of device events e.g. device disconnection. | 235 // that do this will be notified of device events e.g. device disconnection. |
|
dcheng
2017/01/14 10:23:45
Btw, is it expected this will be a 1:1 sort of rel
scheib
2017/01/17 19:20:43
1:1,
WebBluetoothServiceClient is only used in in
dcheng
2017/01/17 23:39:15
If it's always 1:1, would you be willing to file a
| |
| 206 interface WebBluetoothServiceClient { | 236 interface WebBluetoothServiceClient { |
| 237 // The characteristic identified by |characteristic_instance_id| has received | |
| 238 // a notification of value change. | |
| 207 RemoteCharacteristicValueChanged(string characteristic_instance_id, | 239 RemoteCharacteristicValueChanged(string characteristic_instance_id, |
| 208 array<uint8> value); | 240 array<uint8> value); |
| 241 | |
| 242 // The device identified by |device_id| has been disconnected. | |
| 209 GattServerDisconnected(WebBluetoothDeviceId device_id); | 243 GattServerDisconnected(WebBluetoothDeviceId device_id); |
| 210 }; | 244 }; |
| OLD | NEW |