mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Fix comments, and lesser modifications
This commit is contained in:
parent
0b713fd689
commit
3ec9f0bab9
5 changed files with 25 additions and 29 deletions
|
@ -580,8 +580,7 @@ impl PermissionAlgorithm for Bluetooth {
|
|||
fn permission_query(cx: *mut JSContext, promise: &Rc<Promise>,
|
||||
descriptor: &BluetoothPermissionDescriptor,
|
||||
status: &BluetoothPermissionResult) {
|
||||
// Step 1.
|
||||
// TODO: `environment settings object` is not implemented in Servo yet.
|
||||
// Step 1: We are not using the `global` variable.
|
||||
|
||||
// Step 2.
|
||||
status.set_state(get_descriptor_permission_state(status.get_query(), None));
|
||||
|
@ -615,11 +614,12 @@ impl PermissionAlgorithm for Bluetooth {
|
|||
}
|
||||
}
|
||||
let device_id = String::from(allowed_device.deviceId.as_ref());
|
||||
|
||||
// Step 6.2.
|
||||
if let Some(ref filters) = descriptor.filters {
|
||||
let mut scan_filters: Vec<BluetoothScanfilter> = Vec::new();
|
||||
|
||||
// NOTE(zakorgy): This canonicalizing step is missing from the specification.
|
||||
// But there is an issue for this: https://github.com/WebBluetoothCG/web-bluetooth/issues/347
|
||||
// Step 6.2.1.
|
||||
for filter in filters {
|
||||
match canonicalize_filter(&filter) {
|
||||
Ok(f) => scan_filters.push(f),
|
||||
|
@ -627,7 +627,7 @@ impl PermissionAlgorithm for Bluetooth {
|
|||
}
|
||||
}
|
||||
|
||||
// Step 6.2.
|
||||
// Step 6.2.2.
|
||||
// Instead of creating an internal slot we send an ipc message to the Bluetooth thread
|
||||
// to check if one of the filters matches.
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
|
@ -643,7 +643,7 @@ impl PermissionAlgorithm for Bluetooth {
|
|||
};
|
||||
}
|
||||
|
||||
// Step 6.4.
|
||||
// Step 6.3.
|
||||
// TODO: Implement this correctly, not just using device ids here.
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#get-the-bluetoothdevice-representing
|
||||
if let Some(ref device) = device_map.get(&device_id) {
|
||||
|
@ -659,8 +659,7 @@ impl PermissionAlgorithm for Bluetooth {
|
|||
promise.resolve_native(cx, status);
|
||||
}
|
||||
|
||||
// NOTE(zakorgy): There is no link for this algorithm until this PR for the spec is pending:
|
||||
// https://github.com/WebBluetoothCG/web-bluetooth/pull/349
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#request-the-bluetooth-permission
|
||||
fn permission_request(cx: *mut JSContext, promise: &Rc<Promise>,
|
||||
descriptor: &BluetoothPermissionDescriptor,
|
||||
status: &BluetoothPermissionResult) {
|
||||
|
|
|
@ -33,7 +33,7 @@ pub struct BluetoothPermissionResult {
|
|||
|
||||
impl BluetoothPermissionResult {
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new_inherited(status: &PermissionStatus) -> BluetoothPermissionResult {
|
||||
fn new_inherited(status: &PermissionStatus) -> BluetoothPermissionResult {
|
||||
let result = BluetoothPermissionResult {
|
||||
status: PermissionStatus::new_inherited(status.get_query()),
|
||||
devices: DOMRefCell::new(Vec::new()),
|
||||
|
@ -89,10 +89,10 @@ impl AsyncBluetoothListener for BluetoothPermissionResult {
|
|||
// https://webbluetoothcg.github.io/web-bluetooth/#request-bluetooth-devices
|
||||
// Step 11, 13 - 14.
|
||||
BluetoothResponse::RequestDevice(device) => {
|
||||
let bluetooth = &self.get_bluetooth();
|
||||
let bluetooth = self.get_bluetooth();
|
||||
let mut device_instance_map = bluetooth.get_device_map().borrow_mut();
|
||||
if let Some(ref existing_device) = device_instance_map.get(&device.id) {
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothpermissionresult
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#request-the-bluetooth-permission
|
||||
// Step 3.
|
||||
self.set_devices(vec!(JS::from_ref(&*existing_device)));
|
||||
|
||||
|
@ -103,7 +103,7 @@ impl AsyncBluetoothListener for BluetoothPermissionResult {
|
|||
let bt_device = BluetoothDevice::new(&self.global(),
|
||||
DOMString::from(device.id.clone()),
|
||||
device.name.map(DOMString::from),
|
||||
bluetooth);
|
||||
&bluetooth);
|
||||
device_instance_map.insert(device.id.clone(), JS::from_ref(&bt_device));
|
||||
add_new_allowed_device(
|
||||
AllowedBluetoothDevice {
|
||||
|
@ -114,7 +114,7 @@ impl AsyncBluetoothListener for BluetoothPermissionResult {
|
|||
mayUseGATT: true,
|
||||
}
|
||||
);
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothpermissionresult
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#request-the-bluetooth-permission
|
||||
// Step 3.
|
||||
self.set_devices(vec!(JS::from_ref(&bt_device)));
|
||||
|
||||
|
|
|
@ -103,8 +103,7 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
|
|||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservice
|
||||
fn GetPrimaryService(&self, service: BluetoothServiceUUID) -> Rc<Promise> {
|
||||
// Step 1. is in get_gatt_children
|
||||
// Step 2.
|
||||
// Step 1 - 2.
|
||||
get_gatt_children(self, true, BluetoothUUID::service, Some(service), String::from(self.Device().Id()),
|
||||
self.Device().get_gatt().Connected(), GATTType::PrimaryService)
|
||||
}
|
||||
|
@ -112,8 +111,7 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
|
|||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservices
|
||||
fn GetPrimaryServices(&self, service: Option<BluetoothServiceUUID>) -> Rc<Promise> {
|
||||
// Step 1. is in get_gatt_children
|
||||
// Step 2.
|
||||
// Step 1 - 2.
|
||||
get_gatt_children(self, false, BluetoothUUID::service, service, String::from(self.Device().Id()),
|
||||
self.Connected(), GATTType::PrimaryService)
|
||||
|
||||
|
|
|
@ -247,9 +247,9 @@ fn prompt_user(permission_name: PermissionName) -> PermissionState {
|
|||
&format!("{} {:?} ?", QUERY_DIALOG_MESSAGE, permission_name),
|
||||
MessageBoxIcon::Question,
|
||||
YesNo::No) {
|
||||
YesNo::Yes => return PermissionState::Granted,
|
||||
YesNo::No => return PermissionState::Denied,
|
||||
};
|
||||
YesNo::Yes => PermissionState::Granted,
|
||||
YesNo::No => PermissionState::Denied,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
* 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 core::clone::Clone;
|
||||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||
use dom::bindings::codegen::Bindings::PermissionStatusBinding::{self, PermissionDescriptor, PermissionName};
|
||||
use dom::bindings::codegen::Bindings::PermissionStatusBinding::{PermissionState, PermissionStatusMethods};
|
||||
|
@ -11,21 +9,22 @@ use dom::bindings::js::Root;
|
|||
use dom::bindings::reflector::reflect_dom_object;
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::globalscope::GlobalScope;
|
||||
use std::cell::Cell;
|
||||
|
||||
// https://w3c.github.io/permissions/#permissionstatus
|
||||
#[dom_struct]
|
||||
pub struct PermissionStatus {
|
||||
eventtarget: EventTarget,
|
||||
state: DOMRefCell<PermissionState>,
|
||||
query: DOMRefCell<PermissionName>,
|
||||
state: Cell<PermissionState>,
|
||||
query: Cell<PermissionName>,
|
||||
}
|
||||
|
||||
impl PermissionStatus {
|
||||
pub fn new_inherited(query: PermissionName) -> PermissionStatus {
|
||||
PermissionStatus {
|
||||
eventtarget: EventTarget::new_inherited(),
|
||||
state: DOMRefCell::new(PermissionState::Denied),
|
||||
query: DOMRefCell::new(query),
|
||||
state: Cell::new(PermissionState::Denied),
|
||||
query: Cell::new(query),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,18 +35,18 @@ impl PermissionStatus {
|
|||
}
|
||||
|
||||
pub fn set_state(&self, state: PermissionState) {
|
||||
*self.state.borrow_mut() = state;
|
||||
self.state.set(state);
|
||||
}
|
||||
|
||||
pub fn get_query(&self) -> PermissionName {
|
||||
self.query.borrow().clone()
|
||||
self.query.get()
|
||||
}
|
||||
}
|
||||
|
||||
impl PermissionStatusMethods for PermissionStatus {
|
||||
// https://w3c.github.io/permissions/#dom-permissionstatus-state
|
||||
fn State(&self) -> PermissionState {
|
||||
self.state.borrow().clone()
|
||||
self.state.get()
|
||||
}
|
||||
|
||||
// https://w3c.github.io/permissions/#dom-permissionstatus-onchange
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue