diff --git a/components/script/dom/bluetooth.rs b/components/script/dom/bluetooth.rs index e0dd0f00e10..b980562c46d 100644 --- a/components/script/dom/bluetooth.rs +++ b/components/script/dom/bluetooth.rs @@ -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 Fallible<(Vec, Vec)> { // 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() { diff --git a/components/script/dom/bluetoothremotegattcharacteristic.rs b/components/script/dom/bluetoothremotegattcharacteristic.rs index 20037c9920c..8034623ff5c 100644 --- a/components/script/dom/bluetoothremotegattcharacteristic.rs +++ b/components/script/dom/bluetoothremotegattcharacteristic.rs @@ -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) -> Rc { + fn WriteValue(&self, value: ArrayBufferViewOrArrayBuffer) -> Rc { 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; } diff --git a/components/script/dom/bluetoothremotegattdescriptor.rs b/components/script/dom/bluetoothremotegattdescriptor.rs index 94023d6ffa0..493550ee91b 100644 --- a/components/script/dom/bluetoothremotegattdescriptor.rs +++ b/components/script/dom/bluetoothremotegattdescriptor.rs @@ -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) -> Rc { + fn WriteValue(&self, value: ArrayBufferViewOrArrayBuffer) -> Rc { 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; } } diff --git a/components/script/dom/webidls/Bluetooth.webidl b/components/script/dom/webidls/Bluetooth.webidl index 7fc4c7392ad..f891b5f38a5 100644 --- a/components/script/dom/webidls/Bluetooth.webidl +++ b/components/script/dom/webidls/Bluetooth.webidl @@ -5,10 +5,8 @@ // https://webbluetoothcg.github.io/web-bluetooth/#bluetooth dictionary BluetoothDataFilterInit { - // BufferSource dataPrefix; - sequence dataPrefix; - // BufferSource mask; - sequence mask; + BufferSource dataPrefix; + BufferSource mask; }; dictionary BluetoothLEScanFilterInit { diff --git a/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl b/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl index 3e086fc21ca..07cedd97421 100644 --- a/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl +++ b/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl @@ -16,8 +16,7 @@ interface BluetoothRemoteGATTCharacteristic : EventTarget { getDescriptors(optional BluetoothDescriptorUUID descriptor); Promise readValue(); //Promise readValue(); - Promise writeValue(sequence value); - //Promise writeValue(BufferSource value); + Promise writeValue(BufferSource value); Promise startNotifications(); Promise stopNotifications(); }; diff --git a/components/script/dom/webidls/BluetoothRemoteGATTDescriptor.webidl b/components/script/dom/webidls/BluetoothRemoteGATTDescriptor.webidl index a202975013c..243b86fe155 100644 --- a/components/script/dom/webidls/BluetoothRemoteGATTDescriptor.webidl +++ b/components/script/dom/webidls/BluetoothRemoteGATTDescriptor.webidl @@ -12,6 +12,5 @@ interface BluetoothRemoteGATTDescriptor { readonly attribute ByteString? value; Promise readValue(); //Promise readValue(); - Promise writeValue(sequence value); - //Promise writeValue(BufferSource value); + Promise writeValue(BufferSource value); }; diff --git a/tests/wpt/mozilla/tests/bluetooth/writeValue/characteristic/write-updates-value.html b/tests/wpt/mozilla/tests/bluetooth/writeValue/characteristic/write-updates-value.html index a504a49f2d8..23851862a23 100644 --- a/tests/wpt/mozilla/tests/bluetooth/writeValue/characteristic/write-updates-value.html +++ b/tests/wpt/mozilla/tests/bluetooth/writeValue/characteristic/write-updates-value.html @@ -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.'); diff --git a/tests/wpt/mozilla/tests/bluetooth/writeValue/descriptor/write-updates-value.html b/tests/wpt/mozilla/tests/bluetooth/writeValue/descriptor/write-updates-value.html index cfc2fde1c21..14dc5b027e4 100644 --- a/tests/wpt/mozilla/tests/bluetooth/writeValue/descriptor/write-updates-value.html +++ b/tests/wpt/mozilla/tests/bluetooth/writeValue/descriptor/write-updates-value.html @@ -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.');