<!-- Please describe your changes on the following line: --> 1. Moved the `convert_request_device_options` function steps into `request_bluetooth_devices` function, to stay consistent with the current specification. 2. Updated the existing step annotations for the requestDevice and related methods. 3. Added step annotations for the implemented WebBluetooth methods. --- <!-- 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 #14324, #12614 <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 16199b498367702561d4cae8eefb6e77f3fced3f
90 lines
3.4 KiB
Rust
90 lines
3.4 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding;
|
|
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMethods;
|
|
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
|
use dom::bindings::js::{JS, Root, MutHeap, MutNullableHeap};
|
|
use dom::bindings::reflector::{Reflectable, reflect_dom_object};
|
|
use dom::bindings::str::DOMString;
|
|
use dom::bluetooth::Bluetooth;
|
|
use dom::bluetoothadvertisingdata::BluetoothAdvertisingData;
|
|
use dom::bluetoothremotegattserver::BluetoothRemoteGATTServer;
|
|
use dom::eventtarget::EventTarget;
|
|
use dom::globalscope::GlobalScope;
|
|
|
|
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothdevice
|
|
#[dom_struct]
|
|
pub struct BluetoothDevice {
|
|
eventtarget: EventTarget,
|
|
id: DOMString,
|
|
name: Option<DOMString>,
|
|
ad_data: MutHeap<JS<BluetoothAdvertisingData>>,
|
|
gatt: MutNullableHeap<JS<BluetoothRemoteGATTServer>>,
|
|
context: MutHeap<JS<Bluetooth>>,
|
|
}
|
|
|
|
impl BluetoothDevice {
|
|
pub fn new_inherited(id: DOMString,
|
|
name: Option<DOMString>,
|
|
ad_data: &BluetoothAdvertisingData,
|
|
context: &Bluetooth)
|
|
-> BluetoothDevice {
|
|
BluetoothDevice {
|
|
eventtarget: EventTarget::new_inherited(),
|
|
id: id,
|
|
name: name,
|
|
ad_data: MutHeap::new(ad_data),
|
|
gatt: Default::default(),
|
|
context: MutHeap::new(context),
|
|
}
|
|
}
|
|
|
|
pub fn new(global: &GlobalScope,
|
|
id: DOMString,
|
|
name: Option<DOMString>,
|
|
adData: &BluetoothAdvertisingData,
|
|
context: &Bluetooth)
|
|
-> Root<BluetoothDevice> {
|
|
reflect_dom_object(box BluetoothDevice::new_inherited(id,
|
|
name,
|
|
adData,
|
|
context),
|
|
global,
|
|
BluetoothDeviceBinding::Wrap)
|
|
}
|
|
|
|
pub fn get_context(&self) -> Root<Bluetooth> {
|
|
self.context.get()
|
|
}
|
|
}
|
|
|
|
impl BluetoothDeviceMethods for BluetoothDevice {
|
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-id
|
|
fn Id(&self) -> DOMString {
|
|
self.id.clone()
|
|
}
|
|
|
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-name
|
|
fn GetName(&self) -> Option<DOMString> {
|
|
self.name.clone()
|
|
}
|
|
|
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-addata
|
|
fn AdData(&self) -> Root<BluetoothAdvertisingData> {
|
|
self.ad_data.get()
|
|
}
|
|
|
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-gatt
|
|
fn Gatt(&self) -> Root<BluetoothRemoteGATTServer> {
|
|
// TODO: Step 1 - 2: Implement the Permission API.
|
|
self.gatt.or_init(|| {
|
|
BluetoothRemoteGATTServer::new(&self.global(), self)
|
|
})
|
|
}
|
|
|
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdeviceeventhandlers-ongattserverdisconnected
|
|
event_handler!(gattserverdisconnected, GetOngattserverdisconnected, SetOngattserverdisconnected);
|
|
}
|