<!-- Please describe your changes on the following line: --> This implements the [Permissions API](https://w3c.github.io/permissions/) spec. Also includes the WebBluetooth related implementation for this. There are some know issues: - [ ] If the descriptor name is invalid [this](https://gist.github.com/dati91/7a6a0a563d90f49ba5a351e48c5b626b#file-permissionstatusbindings-rs-L323) will throw an error, rather that return it and we could handle it. - [x] The [environment settings object](https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object) is not implemented in servo and the spec rely on it. - [x] There is a popup in the implementation which prevent us to add wpt test, we should figure out a way to make it work - [ ] The allowedDevice's allowed_services attribute is not used in our implementation, because we store these in the lower level, not in the dom side. - [ ] We think the bluetooth revoke function will need some more work, but the problem is the spec needs clarifications on that part. --- <!-- 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 - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because <!-- 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: a537cf48b18d9bba3453b924a4453f5e19dea4ed
63 lines
2.2 KiB
Rust
63 lines
2.2 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::EventHandlerBinding::EventHandlerNonNull;
|
|
use dom::bindings::codegen::Bindings::PermissionStatusBinding::{self, PermissionDescriptor, PermissionName};
|
|
use dom::bindings::codegen::Bindings::PermissionStatusBinding::{PermissionNameValues, PermissionState};
|
|
use dom::bindings::codegen::Bindings::PermissionStatusBinding::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;
|
|
use std::fmt::{self, Display, Formatter};
|
|
|
|
// https://w3c.github.io/permissions/#permissionstatus
|
|
#[dom_struct]
|
|
pub struct PermissionStatus {
|
|
eventtarget: EventTarget,
|
|
state: Cell<PermissionState>,
|
|
query: Cell<PermissionName>,
|
|
}
|
|
|
|
impl PermissionStatus {
|
|
pub fn new_inherited(query: PermissionName) -> PermissionStatus {
|
|
PermissionStatus {
|
|
eventtarget: EventTarget::new_inherited(),
|
|
state: Cell::new(PermissionState::Denied),
|
|
query: Cell::new(query),
|
|
}
|
|
}
|
|
|
|
pub fn new(global: &GlobalScope, query: &PermissionDescriptor) -> Root<PermissionStatus> {
|
|
reflect_dom_object(box PermissionStatus::new_inherited(query.name),
|
|
global,
|
|
PermissionStatusBinding::Wrap)
|
|
}
|
|
|
|
pub fn set_state(&self, state: PermissionState) {
|
|
self.state.set(state);
|
|
}
|
|
|
|
pub fn get_query(&self) -> PermissionName {
|
|
self.query.get()
|
|
}
|
|
}
|
|
|
|
impl PermissionStatusMethods for PermissionStatus {
|
|
// https://w3c.github.io/permissions/#dom-permissionstatus-state
|
|
fn State(&self) -> PermissionState {
|
|
self.state.get()
|
|
}
|
|
|
|
// https://w3c.github.io/permissions/#dom-permissionstatus-onchange
|
|
event_handler!(onchange, GetOnchange, SetOnchange);
|
|
}
|
|
|
|
impl Display for PermissionName {
|
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
|
write!(f, "{}", PermissionNameValues::strings[*self as usize].to_string())
|
|
}
|
|
}
|