forked from mirrors/gecko-dev
<!-- 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 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 50bc944e75966879ab6aca2a6cc229212e733d64
141 lines
4.6 KiB
Rust
141 lines
4.6 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::NavigatorBinding;
|
|
use dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorMethods;
|
|
use dom::bindings::js::{MutNullableJS, Root};
|
|
use dom::bindings::reflector::{Reflector, DomObject, reflect_dom_object};
|
|
use dom::bindings::str::DOMString;
|
|
use dom::bluetooth::Bluetooth;
|
|
use dom::mimetypearray::MimeTypeArray;
|
|
use dom::navigatorinfo;
|
|
use dom::permissions::Permissions;
|
|
use dom::pluginarray::PluginArray;
|
|
use dom::serviceworkercontainer::ServiceWorkerContainer;
|
|
use dom::vr::VR;
|
|
use dom::window::Window;
|
|
use script_traits::WebVREventMsg;
|
|
|
|
#[dom_struct]
|
|
pub struct Navigator {
|
|
reflector_: Reflector,
|
|
bluetooth: MutNullableJS<Bluetooth>,
|
|
plugins: MutNullableJS<PluginArray>,
|
|
mime_types: MutNullableJS<MimeTypeArray>,
|
|
service_worker: MutNullableJS<ServiceWorkerContainer>,
|
|
vr: MutNullableJS<VR>,
|
|
permissions: MutNullableJS<Permissions>,
|
|
}
|
|
|
|
impl Navigator {
|
|
fn new_inherited() -> Navigator {
|
|
Navigator {
|
|
reflector_: Reflector::new(),
|
|
bluetooth: Default::default(),
|
|
plugins: Default::default(),
|
|
mime_types: Default::default(),
|
|
service_worker: Default::default(),
|
|
vr: Default::default(),
|
|
permissions: Default::default(),
|
|
}
|
|
}
|
|
|
|
pub fn new(window: &Window) -> Root<Navigator> {
|
|
reflect_dom_object(box Navigator::new_inherited(),
|
|
window,
|
|
NavigatorBinding::Wrap)
|
|
}
|
|
}
|
|
|
|
impl NavigatorMethods for Navigator {
|
|
// https://html.spec.whatwg.org/multipage/#dom-navigator-product
|
|
fn Product(&self) -> DOMString {
|
|
navigatorinfo::Product()
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-navigator-taintenabled
|
|
fn TaintEnabled(&self) -> bool {
|
|
navigatorinfo::TaintEnabled()
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-navigator-appname
|
|
fn AppName(&self) -> DOMString {
|
|
navigatorinfo::AppName()
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-navigator-appcodename
|
|
fn AppCodeName(&self) -> DOMString {
|
|
navigatorinfo::AppCodeName()
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-navigator-platform
|
|
fn Platform(&self) -> DOMString {
|
|
navigatorinfo::Platform()
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-navigator-useragent
|
|
fn UserAgent(&self) -> DOMString {
|
|
navigatorinfo::UserAgent()
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-navigator-appversion
|
|
fn AppVersion(&self) -> DOMString {
|
|
navigatorinfo::AppVersion()
|
|
}
|
|
|
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-navigator-bluetooth
|
|
fn Bluetooth(&self) -> Root<Bluetooth> {
|
|
self.bluetooth.or_init(|| Bluetooth::new(&self.global()))
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#navigatorlanguage
|
|
fn Language(&self) -> DOMString {
|
|
navigatorinfo::Language()
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-navigator-plugins
|
|
fn Plugins(&self) -> Root<PluginArray> {
|
|
self.plugins.or_init(|| PluginArray::new(&self.global()))
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-navigator-mimetypes
|
|
fn MimeTypes(&self) -> Root<MimeTypeArray> {
|
|
self.mime_types.or_init(|| MimeTypeArray::new(&self.global()))
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-navigator-javaenabled
|
|
fn JavaEnabled(&self) -> bool {
|
|
false
|
|
}
|
|
|
|
// https://w3c.github.io/ServiceWorker/#navigator-service-worker-attribute
|
|
fn ServiceWorker(&self) -> Root<ServiceWorkerContainer> {
|
|
self.service_worker.or_init(|| {
|
|
ServiceWorkerContainer::new(&self.global())
|
|
})
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-navigator-cookieenabled
|
|
fn CookieEnabled(&self) -> bool {
|
|
true
|
|
}
|
|
|
|
#[allow(unrooted_must_root)]
|
|
// https://w3c.github.io/webvr/#interface-navigator
|
|
fn Vr(&self) -> Root<VR> {
|
|
self.vr.or_init(|| VR::new(&self.global()))
|
|
}
|
|
|
|
// https://w3c.github.io/permissions/#navigator-and-workernavigator-extension
|
|
fn Permissions(&self) -> Root<Permissions> {
|
|
self.permissions.or_init(|| Permissions::new(&self.global()))
|
|
}
|
|
}
|
|
|
|
impl Navigator {
|
|
pub fn handle_webvr_event(&self, event: WebVREventMsg) {
|
|
self.vr.get().expect("Shouldn't arrive here with an empty VR instance")
|
|
.handle_webvr_event(event);
|
|
}
|
|
}
|