diff options
author | yvt <i@yvt.jp> | 2021-07-10 17:24:27 +0900 |
---|---|---|
committer | yvt <i@yvt.jp> | 2021-07-10 17:55:42 +0900 |
commit | 01a7de50ab1843d85295f9dccad7f4c099e7208c (patch) | |
tree | ee53fb6e8889deb7b880ee969e6c662e6128d210 /components/script/dom/bluetoothpermissionresult.rs | |
parent | ff8d2cdbbfc7a9dc7f38b7dd47cb350fde39388f (diff) | |
parent | 94b613fbdaa2b98f2179fc0bbda13c64e6fa0d38 (diff) | |
download | servo-01a7de50ab1843d85295f9dccad7f4c099e7208c.tar.gz servo-01a7de50ab1843d85295f9dccad7f4c099e7208c.zip |
Merge remote-tracking branch 'upstream/master' into feat-cow-infra
`tests/wpt/web-platform-tests/html/browsers/origin/cross-origin-objects/cross-origin-objects.html`
was reverted to the upstream version.
Diffstat (limited to 'components/script/dom/bluetoothpermissionresult.rs')
-rw-r--r-- | components/script/dom/bluetoothpermissionresult.rs | 98 |
1 files changed, 55 insertions, 43 deletions
diff --git a/components/script/dom/bluetoothpermissionresult.rs b/components/script/dom/bluetoothpermissionresult.rs index da5de4bf5b1..0f7266e0443 100644 --- a/components/script/dom/bluetoothpermissionresult.rs +++ b/components/script/dom/bluetoothpermissionresult.rs @@ -1,33 +1,34 @@ /* 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/. */ + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +use crate::dom::bindings::cell::DomRefCell; +use crate::dom::bindings::codegen::Bindings::BluetoothPermissionResultBinding::BluetoothPermissionResultMethods; +use crate::dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorBinding::NavigatorMethods; +use crate::dom::bindings::codegen::Bindings::PermissionStatusBinding::PermissionStatusBinding::PermissionStatusMethods; +use crate::dom::bindings::codegen::Bindings::PermissionStatusBinding::{ + PermissionName, PermissionState, +}; +use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods; +use crate::dom::bindings::error::Error; +use crate::dom::bindings::reflector::{reflect_dom_object, DomObject}; +use crate::dom::bindings::root::{Dom, DomRoot}; +use crate::dom::bindings::str::DOMString; +use crate::dom::bluetooth::{AllowedBluetoothDevice, AsyncBluetoothListener, Bluetooth}; +use crate::dom::bluetoothdevice::BluetoothDevice; +use crate::dom::globalscope::GlobalScope; +use crate::dom::permissionstatus::PermissionStatus; +use crate::dom::promise::Promise; use bluetooth_traits::{BluetoothRequest, BluetoothResponse}; -use dom::bindings::cell::DOMRefCell; -use dom::bindings::codegen::Bindings::BluetoothPermissionResultBinding::{self, BluetoothPermissionResultMethods}; -use dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorBinding::NavigatorMethods; -use dom::bindings::codegen::Bindings::PermissionStatusBinding::{PermissionName, PermissionState}; -use dom::bindings::codegen::Bindings::PermissionStatusBinding::PermissionStatusBinding::PermissionStatusMethods; -use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods; -use dom::bindings::error::Error; -use dom::bindings::js::{JS, Root}; -use dom::bindings::reflector::{DomObject, reflect_dom_object}; -use dom::bindings::str::DOMString; -use dom::bluetooth::{AsyncBluetoothListener, Bluetooth, AllowedBluetoothDevice}; -use dom::bluetoothdevice::BluetoothDevice; -use dom::globalscope::GlobalScope; -use dom::permissionstatus::PermissionStatus; -use dom::promise::Promise; use dom_struct::dom_struct; use ipc_channel::ipc::IpcSender; -use js::jsapi::JSContext; use std::rc::Rc; // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothpermissionresult #[dom_struct] pub struct BluetoothPermissionResult { status: PermissionStatus, - devices: DOMRefCell<Vec<JS<BluetoothDevice>>>, + devices: DomRefCell<Vec<Dom<BluetoothDevice>>>, } impl BluetoothPermissionResult { @@ -35,19 +36,23 @@ impl BluetoothPermissionResult { fn new_inherited(status: &PermissionStatus) -> BluetoothPermissionResult { let result = BluetoothPermissionResult { status: PermissionStatus::new_inherited(status.get_query()), - devices: DOMRefCell::new(Vec::new()), + devices: DomRefCell::new(Vec::new()), }; result.status.set_state(status.State()); result } - pub fn new(global: &GlobalScope, status: &PermissionStatus) -> Root<BluetoothPermissionResult> { - reflect_dom_object(box BluetoothPermissionResult::new_inherited(status), - global, - BluetoothPermissionResultBinding::Wrap) + pub fn new( + global: &GlobalScope, + status: &PermissionStatus, + ) -> DomRoot<BluetoothPermissionResult> { + reflect_dom_object( + Box::new(BluetoothPermissionResult::new_inherited(status)), + global, + ) } - pub fn get_bluetooth(&self) -> Root<Bluetooth> { + pub fn get_bluetooth(&self) -> DomRoot<Bluetooth> { self.global().as_window().Navigator().Bluetooth() } @@ -68,22 +73,26 @@ impl BluetoothPermissionResult { } #[allow(unrooted_must_root)] - pub fn set_devices(&self, devices: Vec<JS<BluetoothDevice>>) { + pub fn set_devices(&self, devices: Vec<Dom<BluetoothDevice>>) { *self.devices.borrow_mut() = devices; } } impl BluetoothPermissionResultMethods for BluetoothPermissionResult { // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothpermissionresult-devices - fn Devices(&self) -> Vec<Root<BluetoothDevice>> { - let device_vec: Vec<Root<BluetoothDevice>> = - self.devices.borrow().iter().map(|d| Root::from_ref(&**d)).collect(); + fn Devices(&self) -> Vec<DomRoot<BluetoothDevice>> { + let device_vec: Vec<DomRoot<BluetoothDevice>> = self + .devices + .borrow() + .iter() + .map(|d| DomRoot::from_ref(&**d)) + .collect(); device_vec } } impl AsyncBluetoothListener for BluetoothPermissionResult { - fn handle_response(&self, response: BluetoothResponse, promise_cx: *mut JSContext, promise: &Rc<Promise>) { + fn handle_response(&self, response: BluetoothResponse, promise: &Rc<Promise>) { match response { // https://webbluetoothcg.github.io/web-bluetooth/#request-bluetooth-devices // Step 3, 11, 13 - 14. @@ -94,32 +103,35 @@ impl AsyncBluetoothListener for BluetoothPermissionResult { if let Some(ref existing_device) = device_instance_map.get(&device.id) { // https://webbluetoothcg.github.io/web-bluetooth/#request-the-bluetooth-permission // Step 3. - self.set_devices(vec!(JS::from_ref(&*existing_device))); + self.set_devices(vec![Dom::from_ref(&*existing_device)]); // https://w3c.github.io/permissions/#dom-permissions-request // Step 8. - return promise.resolve_native(promise_cx, self); + return promise.resolve_native(self); } - let bt_device = BluetoothDevice::new(&self.global(), - DOMString::from(device.id.clone()), - device.name.map(DOMString::from), - &bluetooth); - device_instance_map.insert(device.id.clone(), JS::from_ref(&bt_device)); - self.global().as_window().bluetooth_extra_permission_data().add_new_allowed_device( - AllowedBluetoothDevice { + let bt_device = BluetoothDevice::new( + &self.global(), + DOMString::from(device.id.clone()), + device.name.map(DOMString::from), + &bluetooth, + ); + device_instance_map.insert(device.id.clone(), Dom::from_ref(&bt_device)); + self.global() + .as_window() + .bluetooth_extra_permission_data() + .add_new_allowed_device(AllowedBluetoothDevice { deviceId: DOMString::from(device.id), mayUseGATT: true, - } - ); + }); // https://webbluetoothcg.github.io/web-bluetooth/#request-the-bluetooth-permission // Step 3. - self.set_devices(vec!(JS::from_ref(&bt_device))); + self.set_devices(vec![Dom::from_ref(&bt_device)]); // https://w3c.github.io/permissions/#dom-permissions-request // Step 8. - promise.resolve_native(promise_cx, self); + promise.resolve_native(self); }, - _ => promise.reject_error(promise_cx, Error::Type("Something went wrong...".to_owned())), + _ => promise.reject_error(Error::Type("Something went wrong...".to_owned())), } } } |