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