mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Auto merge of #20422 - anthgur:issue_20345, r=emilio
Use BufferSource in bluetooth APIs <!-- Please describe your changes on the following line: --> Updates `RemoveGATTDescriptor.webidl`, `BluetoothDataFilterInit`, and `BluetoothRemoteGATTCharacteristic` to use `BufferSource`. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #20345 (github issue number if applicable). - [X] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20422) <!-- Reviewable:end -->
This commit is contained in:
commit
3ce3f39383
8 changed files with 36 additions and 21 deletions
|
@ -14,7 +14,7 @@ use dom::bindings::codegen::Bindings::BluetoothPermissionResultBinding::Bluetoot
|
|||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerBinding::
|
||||
BluetoothRemoteGATTServerMethods;
|
||||
use dom::bindings::codegen::Bindings::PermissionStatusBinding::{PermissionName, PermissionState};
|
||||
use dom::bindings::codegen::UnionTypes::StringOrUnsignedLong;
|
||||
use dom::bindings::codegen::UnionTypes::{ArrayBufferViewOrArrayBuffer, StringOrUnsignedLong};
|
||||
use dom::bindings::error::Error::{self, Network, Security, Type};
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::refcounted::{Trusted, TrustedPromise};
|
||||
|
@ -442,12 +442,20 @@ fn canonicalize_filter(filter: &BluetoothLEScanFilterInit) -> Fallible<Bluetooth
|
|||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothdatafilterinit-canonicalizing
|
||||
fn canonicalize_bluetooth_data_filter_init(bdfi: &BluetoothDataFilterInit) -> Fallible<(Vec<u8>, Vec<u8>)> {
|
||||
// Step 1.
|
||||
let data_prefix = bdfi.dataPrefix.clone().unwrap_or(vec![]);
|
||||
let data_prefix = match bdfi.dataPrefix {
|
||||
Some(ArrayBufferViewOrArrayBuffer::ArrayBufferView(ref avb)) => avb.to_vec(),
|
||||
Some(ArrayBufferViewOrArrayBuffer::ArrayBuffer(ref ab)) => ab.to_vec(),
|
||||
None => vec![]
|
||||
};
|
||||
|
||||
// Step 2.
|
||||
// If no mask present, mask will be a sequence of 0xFF bytes the same length as dataPrefix.
|
||||
// Masking dataPrefix with this, leaves dataPrefix untouched.
|
||||
let mask = bdfi.mask.clone().unwrap_or(vec![0xFF; data_prefix.len()]);
|
||||
let mask = match bdfi.mask {
|
||||
Some(ArrayBufferViewOrArrayBuffer::ArrayBufferView(ref avb)) => avb.to_vec(),
|
||||
Some(ArrayBufferViewOrArrayBuffer::ArrayBuffer(ref ab)) => ab.to_vec(),
|
||||
None => vec![0xFF; data_prefix.len()]
|
||||
};
|
||||
|
||||
// Step 3.
|
||||
if mask.len() != data_prefix.len() {
|
||||
|
|
|
@ -12,6 +12,7 @@ use dom::bindings::codegen::Bindings::BluetoothRemoteGATTCharacteristicBinding::
|
|||
BluetoothRemoteGATTCharacteristicMethods;
|
||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
|
||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
|
||||
use dom::bindings::codegen::UnionTypes::ArrayBufferViewOrArrayBuffer;
|
||||
use dom::bindings::error::Error::{self, InvalidModification, Network, NotSupported, Security};
|
||||
use dom::bindings::inheritance::Castable;
|
||||
use dom::bindings::reflector::{DomObject, reflect_dom_object};
|
||||
|
@ -155,7 +156,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
|
|||
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-writevalue
|
||||
fn WriteValue(&self, value: Vec<u8>) -> Rc<Promise> {
|
||||
fn WriteValue(&self, value: ArrayBufferViewOrArrayBuffer) -> Rc<Promise> {
|
||||
let p = Promise::new(&self.global());
|
||||
|
||||
// Step 1.
|
||||
|
@ -165,7 +166,12 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
|
|||
}
|
||||
|
||||
// Step 2 - 3.
|
||||
if value.len() > MAXIMUM_ATTRIBUTE_LENGTH {
|
||||
let vec = match value {
|
||||
ArrayBufferViewOrArrayBuffer::ArrayBufferView(avb) => avb.to_vec(),
|
||||
ArrayBufferViewOrArrayBuffer::ArrayBuffer(ab) => ab.to_vec(),
|
||||
};
|
||||
|
||||
if vec.len() > MAXIMUM_ATTRIBUTE_LENGTH {
|
||||
p.reject_error(InvalidModification);
|
||||
return p;
|
||||
}
|
||||
|
@ -190,7 +196,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
|
|||
// in writeValue function and in handle_response function.
|
||||
let sender = response_async(&p, self);
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothRequest::WriteValue(self.get_instance_id(), value, sender)).unwrap();
|
||||
BluetoothRequest::WriteValue(self.get_instance_id(), vec, sender)).unwrap();
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ use dom::bindings::codegen::Bindings::BluetoothRemoteGATTDescriptorBinding;
|
|||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTDescriptorBinding::BluetoothRemoteGATTDescriptorMethods;
|
||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
|
||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
|
||||
use dom::bindings::codegen::UnionTypes::ArrayBufferViewOrArrayBuffer;
|
||||
use dom::bindings::error::Error::{self, InvalidModification, Network, Security};
|
||||
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
||||
use dom::bindings::root::{Dom, DomRoot};
|
||||
|
@ -114,7 +115,7 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
|
|||
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-writevalue
|
||||
fn WriteValue(&self, value: Vec<u8>) -> Rc<Promise> {
|
||||
fn WriteValue(&self, value: ArrayBufferViewOrArrayBuffer) -> Rc<Promise> {
|
||||
let p = Promise::new(&self.global());
|
||||
|
||||
// Step 1.
|
||||
|
@ -124,7 +125,11 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
|
|||
}
|
||||
|
||||
// Step 2 - 3.
|
||||
if value.len() > MAXIMUM_ATTRIBUTE_LENGTH {
|
||||
let vec = match value {
|
||||
ArrayBufferViewOrArrayBuffer::ArrayBufferView(avb) => avb.to_vec(),
|
||||
ArrayBufferViewOrArrayBuffer::ArrayBuffer(ab) => ab.to_vec(),
|
||||
};
|
||||
if vec.len() > MAXIMUM_ATTRIBUTE_LENGTH {
|
||||
p.reject_error(InvalidModification);
|
||||
return p;
|
||||
}
|
||||
|
@ -140,7 +145,7 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
|
|||
// in writeValue function and in handle_response function.
|
||||
let sender = response_async(&p, self);
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothRequest::WriteValue(self.get_instance_id(), value, sender)).unwrap();
|
||||
BluetoothRequest::WriteValue(self.get_instance_id(), vec, sender)).unwrap();
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,8 @@
|
|||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetooth
|
||||
|
||||
dictionary BluetoothDataFilterInit {
|
||||
// BufferSource dataPrefix;
|
||||
sequence<octet> dataPrefix;
|
||||
// BufferSource mask;
|
||||
sequence<octet> mask;
|
||||
BufferSource dataPrefix;
|
||||
BufferSource mask;
|
||||
};
|
||||
|
||||
dictionary BluetoothLEScanFilterInit {
|
||||
|
|
|
@ -16,8 +16,7 @@ interface BluetoothRemoteGATTCharacteristic : EventTarget {
|
|||
getDescriptors(optional BluetoothDescriptorUUID descriptor);
|
||||
Promise<ByteString> readValue();
|
||||
//Promise<DataView> readValue();
|
||||
Promise<void> writeValue(sequence<octet> value);
|
||||
//Promise<void> writeValue(BufferSource value);
|
||||
Promise<void> writeValue(BufferSource value);
|
||||
Promise<BluetoothRemoteGATTCharacteristic> startNotifications();
|
||||
Promise<BluetoothRemoteGATTCharacteristic> stopNotifications();
|
||||
};
|
||||
|
|
|
@ -12,6 +12,5 @@ interface BluetoothRemoteGATTDescriptor {
|
|||
readonly attribute ByteString? value;
|
||||
Promise<ByteString> readValue();
|
||||
//Promise<DataView> readValue();
|
||||
Promise<void> writeValue(sequence<octet> value);
|
||||
//Promise<void> writeValue(BufferSource value);
|
||||
Promise<void> writeValue(BufferSource value);
|
||||
};
|
||||
|
|
|
@ -15,8 +15,8 @@ promise_test(() => {
|
|||
.then(service => service.getCharacteristic(device_name.name))
|
||||
.then(characteristic => {
|
||||
assert_equals(characteristic.value, null);
|
||||
return characteristic.writeValue(asciiToDecimal('foo'))
|
||||
.then(() => assert_equals(characteristic.value, 'foo'));
|
||||
return characteristic.writeValue(Uint8Array.of(1, 2))
|
||||
.then(() => assert_equals(characteristic.value, '\x01\x02'));
|
||||
});
|
||||
}, 'A regular write request to a writable characteristic should update value.');
|
||||
</script>
|
||||
|
|
|
@ -16,8 +16,8 @@ promise_test(() => {
|
|||
.then(characteristic => characteristic.getDescriptor(number_of_digitals.name))
|
||||
.then(descriptor => {
|
||||
assert_equals(descriptor.value, null);
|
||||
return descriptor.writeValue(asciiToDecimal('foo'))
|
||||
.then(() => assert_equals(descriptor.value, 'foo'));
|
||||
return descriptor.writeValue(Uint8Array.of(1, 2))
|
||||
.then(() => assert_equals(descriptor.value, '\x01\x02'));
|
||||
});
|
||||
}, 'A regular write request to a writable descriptor should update value.');
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue