diff options
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/bluetooth.rs | 48 | ||||
-rw-r--r-- | components/script/dom/bluetoothremotegattcharacteristic.rs | 85 | ||||
-rw-r--r-- | components/script/dom/bluetoothremotegattdescriptor.rs | 53 | ||||
-rw-r--r-- | components/script/dom/bluetoothremotegattserver.rs | 91 | ||||
-rw-r--r-- | components/script/dom/bluetoothremotegattservice.rs | 93 | ||||
-rw-r--r-- | components/script/dom/htmlscriptelement.rs | 2 | ||||
-rw-r--r-- | components/script/dom/request.rs | 31 | ||||
-rw-r--r-- | components/script/dom/webidls/Bluetooth.webidl | 4 | ||||
-rw-r--r-- | components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl | 16 | ||||
-rw-r--r-- | components/script/dom/webidls/BluetoothRemoteGATTDescriptor.webidl | 6 | ||||
-rw-r--r-- | components/script/dom/webidls/BluetoothRemoteGATTServer.webidl | 12 | ||||
-rw-r--r-- | components/script/dom/webidls/BluetoothRemoteGATTService.webidl | 19 | ||||
-rw-r--r-- | components/script/dom/window.rs | 1 | ||||
-rw-r--r-- | components/script/dom/xmlhttprequest.rs | 1 |
14 files changed, 277 insertions, 185 deletions
diff --git a/components/script/dom/bluetooth.rs b/components/script/dom/bluetooth.rs index 2940a211bf3..eecaf6489be 100644 --- a/components/script/dom/bluetooth.rs +++ b/components/script/dom/bluetooth.rs @@ -15,10 +15,13 @@ use dom::bindings::str::DOMString; use dom::bluetoothadvertisingdata::BluetoothAdvertisingData; use dom::bluetoothdevice::BluetoothDevice; use dom::bluetoothuuid::{BluetoothServiceUUID, BluetoothUUID}; +use dom::promise::Promise; use ipc_channel::ipc::{self, IpcSender}; +use js::conversions::ToJSValConvertible; use net_traits::bluetooth_scanfilter::{BluetoothScanfilter, BluetoothScanfilterSequence}; use net_traits::bluetooth_scanfilter::{RequestDeviceoptions, ServiceUUIDSequence}; use net_traits::bluetooth_thread::{BluetoothError, BluetoothMethodMsg}; +use std::rc::Rc; const FILTER_EMPTY_ERROR: &'static str = "'filters' member, if present, must be nonempty to find any devices."; const FILTER_ERROR: &'static str = "A filter must restrict the devices in some way."; @@ -61,6 +64,22 @@ impl Bluetooth { global_ref.as_window().bluetooth_thread() } + fn request_device(&self, option: &RequestDeviceOptions) -> Fallible<Root<BluetoothDevice>> { + // Step 1. + // TODO(#4282): Reject promise. + if (option.filters.is_some() && option.acceptAllDevices) || + (option.filters.is_none() && !option.acceptAllDevices) { + return Err(Type(OPTIONS_ERROR.to_owned())); + } + // Step 2. + if !option.acceptAllDevices { + return self.request_bluetooth_devices(&option.filters, &option.optionalServices); + } + + self.request_bluetooth_devices(&None, &option.optionalServices) + // TODO(#4282): Step 3-5: Reject and resolve promise. + } + // https://webbluetoothcg.github.io/web-bluetooth/#request-bluetooth-devices fn request_bluetooth_devices(&self, filters: &Option<Vec<BluetoothRequestDeviceFilter>>, @@ -252,6 +271,18 @@ fn canonicalize_filter(filter: &BluetoothRequestDeviceFilter, global: GlobalRef) service_data_uuid)) } +#[allow(unrooted_must_root)] +pub fn result_to_promise<T: ToJSValConvertible>(global_ref: GlobalRef, + bluetooth_result: Fallible<T>) + -> Rc<Promise> { + let p = Promise::new(global_ref); + match bluetooth_result { + Ok(v) => p.resolve_native(p.global().r().get_cx(), &v), + Err(e) => p.reject_error(p.global().r().get_cx(), e), + } + p +} + impl From<BluetoothError> for Error { fn from(error: BluetoothError) -> Self { match error { @@ -265,20 +296,9 @@ impl From<BluetoothError> for Error { } impl BluetoothMethods for Bluetooth { + #[allow(unrooted_must_root)] // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice - fn RequestDevice(&self, option: &RequestDeviceOptions) -> Fallible<Root<BluetoothDevice>> { - // Step 1. - // TODO(#4282): Reject promise. - if (option.filters.is_some() && option.acceptAllDevices) || - (option.filters.is_none() && !option.acceptAllDevices) { - return Err(Type(OPTIONS_ERROR.to_owned())); - } - // Step 2. - if !option.acceptAllDevices { - return self.request_bluetooth_devices(&option.filters, &option.optionalServices); - } - - self.request_bluetooth_devices(&None, &option.optionalServices) - // TODO(#4282): Step 3-5: Reject and resolve promise. + fn RequestDevice(&self, option: &RequestDeviceOptions) -> Rc<Promise> { + result_to_promise(self.global().r(), self.request_device(option)) } } diff --git a/components/script/dom/bluetoothremotegattcharacteristic.rs b/components/script/dom/bluetoothremotegattcharacteristic.rs index 15ca7af2235..633b0b060e2 100644 --- a/components/script/dom/bluetoothremotegattcharacteristic.rs +++ b/components/script/dom/bluetoothremotegattcharacteristic.rs @@ -18,12 +18,15 @@ use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutHeap, Root}; use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::str::{ByteString, DOMString}; +use dom::bluetooth::result_to_promise; use dom::bluetoothcharacteristicproperties::BluetoothCharacteristicProperties; use dom::bluetoothremotegattdescriptor::BluetoothRemoteGATTDescriptor; use dom::bluetoothremotegattservice::BluetoothRemoteGATTService; use dom::bluetoothuuid::{BluetoothDescriptorUUID, BluetoothUUID}; +use dom::promise::Promise; use ipc_channel::ipc::{self, IpcSender}; use net_traits::bluetooth_thread::BluetoothMethodMsg; +use std::rc::Rc; // Maximum length of an attribute value. // https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=286439 (Vol. 3, page 2169) @@ -79,26 +82,9 @@ impl BluetoothRemoteGATTCharacteristic { fn get_instance_id(&self) -> String { self.instance_id.clone() } -} - -impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteristic { - // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-properties - fn Properties(&self) -> Root<BluetoothCharacteristicProperties> { - self.properties.get() - } - - // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-service - fn Service(&self) -> Root<BluetoothRemoteGATTService> { - self.service.get() - } - - // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-uuid - fn Uuid(&self) -> DOMString { - self.uuid.clone() - } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-getdescriptor - fn GetDescriptor(&self, descriptor: BluetoothDescriptorUUID) -> Fallible<Root<BluetoothRemoteGATTDescriptor>> { + fn get_descriptor(&self, descriptor: BluetoothDescriptorUUID) -> Fallible<Root<BluetoothRemoteGATTDescriptor>> { let uuid = try!(BluetoothUUID::GetDescriptor(self.global().r(), descriptor)).to_string(); if uuid_is_blacklisted(uuid.as_ref(), Blacklist::All) { return Err(Security) @@ -121,9 +107,9 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-getdescriptors - fn GetDescriptors(&self, - descriptor: Option<BluetoothDescriptorUUID>) - -> Fallible<Vec<Root<BluetoothRemoteGATTDescriptor>>> { + fn get_descriptors(&self, + descriptor: Option<BluetoothDescriptorUUID>) + -> Fallible<Vec<Root<BluetoothRemoteGATTDescriptor>>> { let mut uuid: Option<String> = None; if let Some(d) = descriptor { uuid = Some(try!(BluetoothUUID::GetDescriptor(self.global().r(), d)).to_string()); @@ -152,13 +138,8 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris } } - // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-value - fn GetValue(&self) -> Option<ByteString> { - self.value.borrow().clone() - } - // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-readvalue - fn ReadValue(&self) -> Fallible<ByteString> { + fn read_value(&self) -> Fallible<ByteString> { if uuid_is_blacklisted(self.uuid.as_ref(), Blacklist::Reads) { return Err(Security) } @@ -185,7 +166,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-writevalue - fn WriteValue(&self, value: Vec<u8>) -> ErrorResult { + fn write_value(&self, value: Vec<u8>) -> ErrorResult { if uuid_is_blacklisted(self.uuid.as_ref(), Blacklist::Writes) { return Err(Security) } @@ -213,3 +194,51 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris } } } + +impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteristic { + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-properties + fn Properties(&self) -> Root<BluetoothCharacteristicProperties> { + self.properties.get() + } + + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-service + fn Service(&self) -> Root<BluetoothRemoteGATTService> { + self.service.get() + } + + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-uuid + fn Uuid(&self) -> DOMString { + self.uuid.clone() + } + + #[allow(unrooted_must_root)] + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-getdescriptor + fn GetDescriptor(&self, descriptor: BluetoothDescriptorUUID) -> Rc<Promise> { + result_to_promise(self.global().r(), self.get_descriptor(descriptor)) + } + + #[allow(unrooted_must_root)] + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-getdescriptors + fn GetDescriptors(&self, + descriptor: Option<BluetoothDescriptorUUID>) + -> Rc<Promise> { + result_to_promise(self.global().r(), self.get_descriptors(descriptor)) + } + + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-value + fn GetValue(&self) -> Option<ByteString> { + self.value.borrow().clone() + } + + #[allow(unrooted_must_root)] + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-readvalue + fn ReadValue(&self) -> Rc<Promise> { + result_to_promise(self.global().r(), self.read_value()) + } + + #[allow(unrooted_must_root)] + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-writevalue + fn WriteValue(&self, value: Vec<u8>) -> Rc<Promise> { + result_to_promise(self.global().r(), self.write_value(value)) + } +} diff --git a/components/script/dom/bluetoothremotegattdescriptor.rs b/components/script/dom/bluetoothremotegattdescriptor.rs index 99065a9aec0..d036f8bd9ea 100644 --- a/components/script/dom/bluetoothremotegattdescriptor.rs +++ b/components/script/dom/bluetoothremotegattdescriptor.rs @@ -17,9 +17,12 @@ use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutHeap, Root}; use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::str::{ByteString, DOMString}; +use dom::bluetooth::result_to_promise; use dom::bluetoothremotegattcharacteristic::{BluetoothRemoteGATTCharacteristic, MAXIMUM_ATTRIBUTE_LENGTH}; +use dom::promise::Promise; use ipc_channel::ipc::{self, IpcSender}; use net_traits::bluetooth_thread::BluetoothMethodMsg; +use std::rc::Rc; // http://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattdescriptor #[dom_struct] @@ -66,26 +69,9 @@ impl BluetoothRemoteGATTDescriptor { fn get_instance_id(&self) -> String { self.instance_id.clone() } -} - -impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor { - // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-characteristic - fn Characteristic(&self) -> Root<BluetoothRemoteGATTCharacteristic> { - self.characteristic.get() - } - - // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-uuid - fn Uuid(&self) -> DOMString { - self.uuid.clone() - } - - // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-value - fn GetValue(&self) -> Option<ByteString> { - self.value.borrow().clone() - } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-readvalue - fn ReadValue(&self) -> Fallible<ByteString> { + fn read_value(&self) -> Fallible<ByteString> { if uuid_is_blacklisted(self.uuid.as_ref(), Blacklist::Reads) { return Err(Security) } @@ -109,7 +95,7 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor { } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-writevalue - fn WriteValue(&self, value: Vec<u8>) -> ErrorResult { + fn write_value(&self, value: Vec<u8>) -> ErrorResult { if uuid_is_blacklisted(self.uuid.as_ref(), Blacklist::Writes) { return Err(Security) } @@ -131,3 +117,32 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor { } } } + +impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor { + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-characteristic + fn Characteristic(&self) -> Root<BluetoothRemoteGATTCharacteristic> { + self.characteristic.get() + } + + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-uuid + fn Uuid(&self) -> DOMString { + self.uuid.clone() + } + + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-value + fn GetValue(&self) -> Option<ByteString> { + self.value.borrow().clone() + } + + #[allow(unrooted_must_root)] + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-readvalue + fn ReadValue(&self) -> Rc<Promise> { + result_to_promise(self.global().r(), self.read_value()) + } + + #[allow(unrooted_must_root)] + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-writevalue + fn WriteValue(&self, value: Vec<u8>) -> Rc<Promise> { + result_to_promise(self.global().r(), self.write_value(value)) + } +} diff --git a/components/script/dom/bluetoothremotegattserver.rs b/components/script/dom/bluetoothremotegattserver.rs index 615094623e9..c9fa5477f3f 100644 --- a/components/script/dom/bluetoothremotegattserver.rs +++ b/components/script/dom/bluetoothremotegattserver.rs @@ -12,12 +12,15 @@ use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutHeap, Root}; use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::str::DOMString; +use dom::bluetooth::result_to_promise; use dom::bluetoothdevice::BluetoothDevice; use dom::bluetoothremotegattservice::BluetoothRemoteGATTService; use dom::bluetoothuuid::{BluetoothServiceUUID, BluetoothUUID}; +use dom::promise::Promise; use ipc_channel::ipc::{self, IpcSender}; use net_traits::bluetooth_thread::BluetoothMethodMsg; use std::cell::Cell; +use std::rc::Rc; // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattserver #[dom_struct] @@ -47,21 +50,9 @@ impl BluetoothRemoteGATTServer { let global_ref = global_root.r(); global_ref.as_window().bluetooth_thread() } -} - -impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer { - // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-device - fn Device(&self) -> Root<BluetoothDevice> { - self.device.get() - } - - // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connected - fn Connected(&self) -> bool { - self.connected.get() - } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect - fn Connect(&self) -> Fallible<Root<BluetoothRemoteGATTServer>> { + fn connect(&self) -> Fallible<Root<BluetoothRemoteGATTServer>> { let (sender, receiver) = ipc::channel().unwrap(); self.get_bluetooth_thread().send( BluetoothMethodMsg::GATTServerConnect(String::from(self.Device().Id()), sender)).unwrap(); @@ -77,25 +68,8 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer { } } - // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-disconnect - fn Disconnect(&self) -> ErrorResult { - let (sender, receiver) = ipc::channel().unwrap(); - self.get_bluetooth_thread().send( - BluetoothMethodMsg::GATTServerDisconnect(String::from(self.Device().Id()), sender)).unwrap(); - let server = receiver.recv().unwrap(); - match server { - Ok(connected) => { - self.connected.set(connected); - Ok(()) - }, - Err(error) => { - Err(Error::from(error)) - }, - } - } - // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservice - fn GetPrimaryService(&self, service: BluetoothServiceUUID) -> Fallible<Root<BluetoothRemoteGATTService>> { + fn get_primary_service(&self, service: BluetoothServiceUUID) -> Fallible<Root<BluetoothRemoteGATTService>> { let uuid = try!(BluetoothUUID::GetService(self.global().r(), service)).to_string(); if uuid_is_blacklisted(uuid.as_ref(), Blacklist::All) { return Err(Security) @@ -119,9 +93,9 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer { } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservices - fn GetPrimaryServices(&self, - service: Option<BluetoothServiceUUID>) - -> Fallible<Vec<Root<BluetoothRemoteGATTService>>> { + fn get_primary_services(&self, + service: Option<BluetoothServiceUUID>) + -> Fallible<Vec<Root<BluetoothRemoteGATTService>>> { let mut uuid: Option<String> = None; if let Some(s) = service { uuid = Some(try!(BluetoothUUID::GetService(self.global().r(), s)).to_string()); @@ -151,3 +125,52 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer { } } } + +impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer { + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-device + fn Device(&self) -> Root<BluetoothDevice> { + self.device.get() + } + + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connected + fn Connected(&self) -> bool { + self.connected.get() + } + + #[allow(unrooted_must_root)] + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect + fn Connect(&self) -> Rc<Promise> { + result_to_promise(self.global().r(), self.connect()) + } + + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-disconnect + fn Disconnect(&self) -> ErrorResult { + let (sender, receiver) = ipc::channel().unwrap(); + self.get_bluetooth_thread().send( + BluetoothMethodMsg::GATTServerDisconnect(String::from(self.Device().Id()), sender)).unwrap(); + let server = receiver.recv().unwrap(); + match server { + Ok(connected) => { + self.connected.set(connected); + Ok(()) + }, + Err(error) => { + Err(Error::from(error)) + }, + } + } + + #[allow(unrooted_must_root)] + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservice + fn GetPrimaryService(&self, service: BluetoothServiceUUID) -> Rc<Promise> { + result_to_promise(self.global().r(), self.get_primary_service(service)) + } + + #[allow(unrooted_must_root)] + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservices + fn GetPrimaryServices(&self, + service: Option<BluetoothServiceUUID>) + -> Rc<Promise> { + result_to_promise(self.global().r(), self.get_primary_services(service)) + } +} diff --git a/components/script/dom/bluetoothremotegattservice.rs b/components/script/dom/bluetoothremotegattservice.rs index a39bb4fdfd5..709de16cf5f 100644 --- a/components/script/dom/bluetoothremotegattservice.rs +++ b/components/script/dom/bluetoothremotegattservice.rs @@ -11,12 +11,15 @@ use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutHeap, Root}; use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::str::DOMString; +use dom::bluetooth::result_to_promise; use dom::bluetoothcharacteristicproperties::BluetoothCharacteristicProperties; use dom::bluetoothdevice::BluetoothDevice; use dom::bluetoothremotegattcharacteristic::BluetoothRemoteGATTCharacteristic; use dom::bluetoothuuid::{BluetoothCharacteristicUUID, BluetoothServiceUUID, BluetoothUUID}; +use dom::promise::Promise; use ipc_channel::ipc::{self, IpcSender}; use net_traits::bluetooth_thread::BluetoothMethodMsg; +use std::rc::Rc; // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattservice #[dom_struct] @@ -66,28 +69,11 @@ impl BluetoothRemoteGATTService { fn get_instance_id(&self) -> String { self.instance_id.clone() } -} - -impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService { - // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-device - fn Device(&self) -> Root<BluetoothDevice> { - self.device.get() - } - - // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-isprimary - fn IsPrimary(&self) -> bool { - self.is_primary - } - - // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-uuid - fn Uuid(&self) -> DOMString { - self.uuid.clone() - } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getcharacteristic - fn GetCharacteristic(&self, - characteristic: BluetoothCharacteristicUUID) - -> Fallible<Root<BluetoothRemoteGATTCharacteristic>> { + fn get_characteristic(&self, + characteristic: BluetoothCharacteristicUUID) + -> Fallible<Root<BluetoothRemoteGATTCharacteristic>> { let uuid = try!(BluetoothUUID::GetCharacteristic(self.global().r(), characteristic)).to_string(); if uuid_is_blacklisted(uuid.as_ref(), Blacklist::All) { return Err(Security) @@ -121,9 +107,9 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService { } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getcharacteristics - fn GetCharacteristics(&self, - characteristic: Option<BluetoothCharacteristicUUID>) - -> Fallible<Vec<Root<BluetoothRemoteGATTCharacteristic>>> { + fn get_characteristics(&self, + characteristic: Option<BluetoothCharacteristicUUID>) + -> Fallible<Vec<Root<BluetoothRemoteGATTCharacteristic>>> { let mut uuid: Option<String> = None; if let Some(c) = characteristic { uuid = Some(try!(BluetoothUUID::GetCharacteristic(self.global().r(), c)).to_string()); @@ -166,9 +152,9 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService { } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getincludedservice - fn GetIncludedService(&self, - service: BluetoothServiceUUID) - -> Fallible<Root<BluetoothRemoteGATTService>> { + fn get_included_service(&self, + service: BluetoothServiceUUID) + -> Fallible<Root<BluetoothRemoteGATTService>> { let uuid = try!(BluetoothUUID::GetService(self.global().r(), service)).to_string(); if uuid_is_blacklisted(uuid.as_ref(), Blacklist::All) { return Err(Security) @@ -194,9 +180,9 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService { } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getincludedservices - fn GetIncludedServices(&self, - service: Option<BluetoothServiceUUID>) - -> Fallible<Vec<Root<BluetoothRemoteGATTService>>> { + fn get_included_services(&self, + service: Option<BluetoothServiceUUID>) + -> Fallible<Vec<Root<BluetoothRemoteGATTService>>> { let mut uuid: Option<String> = None; if let Some(s) = service { uuid = Some(try!(BluetoothUUID::GetService(self.global().r(), s)).to_string()); @@ -228,3 +214,52 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService { } } } + +impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService { + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-device + fn Device(&self) -> Root<BluetoothDevice> { + self.device.get() + } + + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-isprimary + fn IsPrimary(&self) -> bool { + self.is_primary + } + + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-uuid + fn Uuid(&self) -> DOMString { + self.uuid.clone() + } + + #[allow(unrooted_must_root)] + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getcharacteristic + fn GetCharacteristic(&self, + characteristic: BluetoothCharacteristicUUID) + -> Rc<Promise> { + result_to_promise(self.global().r(), self.get_characteristic(characteristic)) + } + + #[allow(unrooted_must_root)] + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getcharacteristics + fn GetCharacteristics(&self, + characteristic: Option<BluetoothCharacteristicUUID>) + -> Rc<Promise> { + result_to_promise(self.global().r(), self.get_characteristics(characteristic)) + } + + #[allow(unrooted_must_root)] + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getincludedservice + fn GetIncludedService(&self, + service: BluetoothServiceUUID) + -> Rc<Promise> { + result_to_promise(self.global().r(), self.get_included_service(service)) + } + + #[allow(unrooted_must_root)] + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getincludedservices + fn GetIncludedServices(&self, + service: Option<BluetoothServiceUUID>) + -> Rc<Promise> { + result_to_promise(self.global().r(), self.get_included_services(service)) + } +} diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs index 4b16908968f..15df6ee4e33 100644 --- a/components/script/dom/htmlscriptelement.rs +++ b/components/script/dom/htmlscriptelement.rs @@ -244,8 +244,6 @@ fn fetch_a_classic_script(script: &HTMLScriptElement, }, origin: doc.url().clone(), pipeline_id: Some(script.global().r().pipeline_id()), - // FIXME: Set to true for now, discussion in https://github.com/whatwg/fetch/issues/381 - same_origin_data: true, referrer_url: Some(doc.url().clone()), referrer_policy: doc.get_referrer_policy(), .. RequestInit::default() diff --git a/components/script/dom/request.rs b/components/script/dom/request.rs index 4ffbeb2dcd1..ba15f565c27 100644 --- a/components/script/dom/request.rs +++ b/components/script/dom/request.rs @@ -24,7 +24,7 @@ use dom::bindings::str::{ByteString, DOMString, USVString}; use dom::headers::{Guard, Headers}; use dom::promise::Promise; use dom::xmlhttprequest::Extractable; -use hyper; +use hyper::method::Method as HttpMethod; use msg::constellation_msg::ReferrerPolicy as MsgReferrerPolicy; use net_traits::request::{Origin, Window}; use net_traits::request::CacheMode as NetTraitsRequestCache; @@ -159,7 +159,6 @@ impl Request { // TODO: `entry settings object` is not implemented in Servo yet. *request.origin.borrow_mut() = Origin::Client; request.omit_origin_header = temporary_request.omit_origin_header; - request.same_origin_data.set(true); request.referrer = temporary_request.referrer; request.referrer_policy = temporary_request.referrer_policy; request.mode = temporary_request.mode; @@ -360,9 +359,9 @@ impl Request { let req = r.request.borrow(); let req_method = req.method.borrow(); match &*req_method { - &hyper::method::Method::Get => return Err(Error::Type( + &HttpMethod::Get => return Err(Error::Type( "Init's body is non-null, and request method is GET".to_string())), - &hyper::method::Method::Head => return Err(Error::Type( + &HttpMethod::Head => return Err(Error::Type( "Init's body is non-null, and request method is HEAD".to_string())), _ => {}, } @@ -462,15 +461,15 @@ fn net_request_from_global(global: GlobalRef, Some(pipeline_id)) } -fn normalized_method_to_typed_method(m: &str) -> hyper::method::Method { +fn normalized_method_to_typed_method(m: &str) -> HttpMethod { match m { - "DELETE" => hyper::method::Method::Delete, - "GET" => hyper::method::Method::Get, - "HEAD" => hyper::method::Method::Head, - "OPTIONS" => hyper::method::Method::Options, - "POST" => hyper::method::Method::Post, - "PUT" => hyper::method::Method::Put, - a => hyper::method::Method::Extension(a.to_string()) + "DELETE" => HttpMethod::Delete, + "GET" => HttpMethod::Get, + "HEAD" => HttpMethod::Head, + "OPTIONS" => HttpMethod::Options, + "POST" => HttpMethod::Post, + "PUT" => HttpMethod::Put, + a => HttpMethod::Extension(a.to_string()) } } @@ -513,10 +512,10 @@ fn is_forbidden_method(m: &ByteString) -> bool { } // https://fetch.spec.whatwg.org/#cors-safelisted-method -fn is_cors_safelisted_method(m: &hyper::method::Method) -> bool { - m == &hyper::method::Method::Get || - m == &hyper::method::Method::Head || - m == &hyper::method::Method::Post +fn is_cors_safelisted_method(m: &HttpMethod) -> bool { + m == &HttpMethod::Get || + m == &HttpMethod::Head || + m == &HttpMethod::Post } // https://url.spec.whatwg.org/#include-credentials diff --git a/components/script/dom/webidls/Bluetooth.webidl b/components/script/dom/webidls/Bluetooth.webidl index 6c575db150c..16c30c770d4 100644 --- a/components/script/dom/webidls/Bluetooth.webidl +++ b/components/script/dom/webidls/Bluetooth.webidl @@ -23,9 +23,7 @@ interface Bluetooth { // [SecureContext] // readonly attribute BluetoothDevice? referringDevice; // [SecureContext] -// Promise<BluetoothDevice> requestDevice(RequestDeviceOptions options); - [Throws] - BluetoothDevice requestDevice(optional RequestDeviceOptions options); + Promise<BluetoothDevice> requestDevice(optional RequestDeviceOptions options); }; // Bluetooth implements EventTarget; diff --git a/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl b/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl index fdb3afa8b9a..293ac7f742c 100644 --- a/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl +++ b/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl @@ -10,18 +10,12 @@ interface BluetoothRemoteGATTCharacteristic { readonly attribute DOMString uuid; readonly attribute BluetoothCharacteristicProperties properties; readonly attribute ByteString? value; - [Throws] - BluetoothRemoteGATTDescriptor getDescriptor(BluetoothDescriptorUUID descriptor); - [Throws] - sequence<BluetoothRemoteGATTDescriptor> getDescriptors(optional BluetoothDescriptorUUID descriptor); - //Promise<BluetoothRemoteGATTDescriptor> getDescriptor(BluetoothDescriptorUUID descriptor); - //Promise<sequence<BluetoothRemoteGATTDescriptor>> - //getDescriptors(optional BluetoothDescriptorUUID descriptor); - [Throws] - ByteString readValue(); + Promise<BluetoothRemoteGATTDescriptor> getDescriptor(BluetoothDescriptorUUID descriptor); + Promise<sequence<BluetoothRemoteGATTDescriptor>> + getDescriptors(optional BluetoothDescriptorUUID descriptor); + Promise<ByteString> readValue(); //Promise<DataView> readValue(); - [Throws] - void writeValue(sequence<octet> value); + Promise<void> writeValue(sequence<octet> value); //Promise<void> writeValue(BufferSource value); //Promise<void> startNotifications(); //Promise<void> stopNotifications(); diff --git a/components/script/dom/webidls/BluetoothRemoteGATTDescriptor.webidl b/components/script/dom/webidls/BluetoothRemoteGATTDescriptor.webidl index 8c744929542..7ffd3f2ebb5 100644 --- a/components/script/dom/webidls/BluetoothRemoteGATTDescriptor.webidl +++ b/components/script/dom/webidls/BluetoothRemoteGATTDescriptor.webidl @@ -9,10 +9,8 @@ interface BluetoothRemoteGATTDescriptor { readonly attribute BluetoothRemoteGATTCharacteristic characteristic; readonly attribute DOMString uuid; readonly attribute ByteString? value; - [Throws] - ByteString readValue(); + Promise<ByteString> readValue(); //Promise<DataView> readValue(); - [Throws] - void writeValue(sequence<octet> value); + Promise<void> writeValue(sequence<octet> value); //Promise<void> writeValue(BufferSource value); }; diff --git a/components/script/dom/webidls/BluetoothRemoteGATTServer.webidl b/components/script/dom/webidls/BluetoothRemoteGATTServer.webidl index 13314d7c6e1..45e3df198fe 100644 --- a/components/script/dom/webidls/BluetoothRemoteGATTServer.webidl +++ b/components/script/dom/webidls/BluetoothRemoteGATTServer.webidl @@ -8,15 +8,9 @@ interface BluetoothRemoteGATTServer { readonly attribute BluetoothDevice device; readonly attribute boolean connected; - [Throws] - BluetoothRemoteGATTServer connect(); + Promise<BluetoothRemoteGATTServer> connect(); [Throws] void disconnect(); - [Throws] - BluetoothRemoteGATTService getPrimaryService(BluetoothServiceUUID service); - [Throws] - sequence<BluetoothRemoteGATTService> getPrimaryServices(optional BluetoothServiceUUID service); - //Promise<BluetoothRemoteGATTService> getPrimaryService(BluetoothServiceUUID service); - //Promise<sequence<BluetoothRemoteGATTService>>getPrimaryServices(optional BluetoothServiceUUID service); - //Promise<BluetoothRemoteGATTServer> connect(); + Promise<BluetoothRemoteGATTService> getPrimaryService(BluetoothServiceUUID service); + Promise<sequence<BluetoothRemoteGATTService>> getPrimaryServices(optional BluetoothServiceUUID service); }; diff --git a/components/script/dom/webidls/BluetoothRemoteGATTService.webidl b/components/script/dom/webidls/BluetoothRemoteGATTService.webidl index a7ee941232a..a484ae64f80 100644 --- a/components/script/dom/webidls/BluetoothRemoteGATTService.webidl +++ b/components/script/dom/webidls/BluetoothRemoteGATTService.webidl @@ -9,18 +9,9 @@ interface BluetoothRemoteGATTService { readonly attribute BluetoothDevice device; readonly attribute DOMString uuid; readonly attribute boolean isPrimary; - [Throws] - BluetoothRemoteGATTCharacteristic getCharacteristic(BluetoothCharacteristicUUID characteristic); - [Throws] - sequence<BluetoothRemoteGATTCharacteristic> getCharacteristics - (optional BluetoothCharacteristicUUID characteristic); - //Promise<BluetoothRemoteGATTCharacteristic>getCharacteristic(BluetoothCharacteristicUUID characteristic); - //Promise<sequence<BluetoothRemoteGATTCharacteristic>> - //getCharacteristics(optional BluetoothCharacteristicUUID characteristic); - [Throws] - BluetoothRemoteGATTService getIncludedService(BluetoothServiceUUID service); - [Throws] - sequence<BluetoothRemoteGATTService> getIncludedServices(optional BluetoothServiceUUID service); - //Promise<BluetoothRemoteGATTService>getIncludedService(BluetoothServiceUUID service); - //Promise<sequence<BluetoothRemoteGATTService>>getIncludedServices(optional BluetoothServiceUUID service); + Promise<BluetoothRemoteGATTCharacteristic> getCharacteristic(BluetoothCharacteristicUUID characteristic); + Promise<sequence<BluetoothRemoteGATTCharacteristic>> + getCharacteristics(optional BluetoothCharacteristicUUID characteristic); + Promise<BluetoothRemoteGATTService> getIncludedService(BluetoothServiceUUID service); + Promise<sequence<BluetoothRemoteGATTService>> getIncludedServices(optional BluetoothServiceUUID service); }; diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 30d51a31c4c..10d47f161be 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -195,7 +195,6 @@ pub struct Window { devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>, /// For sending timeline markers. Will be ignored if /// no devtools server - #[ignore_heap_size_of = "TODO(#6909) need to measure HashSet"] devtools_markers: DOMRefCell<HashSet<TimelineMarkerType>>, #[ignore_heap_size_of = "channels are hard"] devtools_marker_sender: DOMRefCell<Option<IpcSender<TimelineMarker>>>, diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 2a193cea77a..4643921bc2d 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -587,7 +587,6 @@ impl XMLHttpRequestMethods for XMLHttpRequest { url: self.request_url.borrow().clone().unwrap(), headers: (*self.request_headers.borrow()).clone(), unsafe_request: true, - same_origin_data: true, // XXXManishearth figure out how to avoid this clone body: extracted.as_ref().map(|e| e.0.clone()), // XXXManishearth actually "subresource", but it doesn't exist |