aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-07-06 11:11:26 -0700
committerGitHub <noreply@github.com>2016-07-06 11:11:26 -0700
commit7da28b7ca63c7b4538aa1b81b7ad1182415c32f2 (patch)
tree5dd69e30c6ab9fadf1a43c77d105f8e79f88cecb /components/script/dom
parent3679b0a328aaf37e6086d7ee7161f2cceb999067 (diff)
parent52e1d8325f15498f16bc79d8e396ad4d377a6be9 (diff)
downloadservo-7da28b7ca63c7b4538aa1b81b7ad1182415c32f2.tar.gz
servo-7da28b7ca63c7b4538aa1b81b7ad1182415c32f2.zip
Auto merge of #12261 - szeged:gattcharacteristicfunctions, r=jdm
Missing steps of Characteristic's readValue, writeValue functions <!-- Please describe your changes on the following line: --> Add a check for the read property of the characteristic as described in https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-readvalue (Step 4.1) Add two missing steps to characteristic's WriteValue function. https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-writevalue (Step 4 and 5) --- <!-- 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 do not require tests because, there are no Web Bluetooth test API implementation yet. <!-- 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="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12261) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/bindings/error.rs3
-rw-r--r--components/script/dom/bluetoothremotegattcharacteristic.rs17
2 files changed, 19 insertions, 1 deletions
diff --git a/components/script/dom/bindings/error.rs b/components/script/dom/bindings/error.rs
index 161e477a85a..d0074335c23 100644
--- a/components/script/dom/bindings/error.rs
+++ b/components/script/dom/bindings/error.rs
@@ -57,6 +57,8 @@ pub enum Error {
QuotaExceeded,
/// TypeMismatchError DOMException
TypeMismatch,
+ /// InvalidModificationError DOMException
+ InvalidModification,
/// TypeError JavaScript Error
Type(String),
@@ -97,6 +99,7 @@ pub unsafe fn throw_dom_exception(cx: *mut JSContext, global: GlobalRef, result:
Error::NoModificationAllowed => DOMErrorName::NoModificationAllowedError,
Error::QuotaExceeded => DOMErrorName::QuotaExceededError,
Error::TypeMismatch => DOMErrorName::TypeMismatchError,
+ Error::InvalidModification => DOMErrorName::InvalidModificationError,
Error::Type(message) => {
assert!(!JS_IsExceptionPending(cx));
throw_type_error(cx, &message);
diff --git a/components/script/dom/bluetoothremotegattcharacteristic.rs b/components/script/dom/bluetoothremotegattcharacteristic.rs
index 2b3443f8a40..ebdd59ca689 100644
--- a/components/script/dom/bluetoothremotegattcharacteristic.rs
+++ b/components/script/dom/bluetoothremotegattcharacteristic.rs
@@ -4,13 +4,15 @@
use bluetooth_blacklist::{Blacklist, uuid_is_blacklisted};
use dom::bindings::cell::DOMRefCell;
+use dom::bindings::codegen::Bindings::BluetoothCharacteristicPropertiesBinding::
+ BluetoothCharacteristicPropertiesMethods;
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMethods;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTCharacteristicBinding;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTCharacteristicBinding::
BluetoothRemoteGATTCharacteristicMethods;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
-use dom::bindings::error::Error::{Network, Security, Type};
+use dom::bindings::error::Error::{InvalidModification, Network, NotSupported, Security, Type};
use dom::bindings::error::{Fallible, ErrorResult};
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, MutHeap, Root};
@@ -23,6 +25,10 @@ use dom::bluetoothuuid::{BluetoothDescriptorUUID, BluetoothUUID};
use ipc_channel::ipc::{self, IpcSender};
use net_traits::bluetooth_thread::BluetoothMethodMsg;
+// Maximum length of an attribute value.
+// https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=286439 (Vol. 3, page 2169)
+const MAXIMUM_ATTRIBUTE_LENGTH: usize = 512;
+
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattcharacteristic
#[dom_struct]
pub struct BluetoothRemoteGATTCharacteristic {
@@ -160,6 +166,9 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
if !self.Service().Device().Gatt().Connected() {
return Err(Network)
}
+ if !self.Properties().Read() {
+ return Err(NotSupported)
+ }
self.get_bluetooth_thread().send(
BluetoothMethodMsg::ReadValue(self.get_instance_id(), sender)).unwrap();
let result = receiver.recv().unwrap();
@@ -180,6 +189,12 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
if uuid_is_blacklisted(self.uuid.as_ref(), Blacklist::Writes) {
return Err(Security)
}
+ if value.len() > MAXIMUM_ATTRIBUTE_LENGTH {
+ return Err(InvalidModification)
+ }
+ if !self.Service().Device().Gatt().Connected() {
+ return Err(Network)
+ }
let (sender, receiver) = ipc::channel().unwrap();
self.get_bluetooth_thread().send(
BluetoothMethodMsg::WriteValue(self.get_instance_id(), value, sender)).unwrap();