Skip to content

Commit

Permalink
Fix comments, and lesser modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Zakor Gyula authored and dati91 committed Feb 13, 2017
1 parent 0b713fd commit 3ec9f0b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 29 deletions.
15 changes: 7 additions & 8 deletions components/script/dom/bluetooth.rs
Expand Up @@ -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));
Expand Down Expand Up @@ -615,19 +614,20 @@ 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),
Err(error) => return promise.reject_error(cx, error),
}
}

// 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();
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions components/script/dom/bluetoothpermissionresult.rs
Expand Up @@ -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()),
Expand Down Expand Up @@ -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)));

Expand All @@ -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 {
Expand All @@ -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)));

Expand Down
6 changes: 2 additions & 4 deletions components/script/dom/bluetoothremotegattserver.rs
Expand Up @@ -103,17 +103,15 @@ 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)
}

#[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)

Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/permissions.rs
Expand Up @@ -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"))]
Expand Down
17 changes: 8 additions & 9 deletions components/script/dom/permissionstatus.rs
Expand Up @@ -2,30 +2,29 @@
* 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};
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),
}
}

Expand All @@ -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
Expand Down

0 comments on commit 3ec9f0b

Please sign in to comment.