aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/script/dom/mod.rs2
-rw-r--r--components/script/dom/navigator.rs17
-rw-r--r--components/script/dom/webidls/VR.webidl11
-rw-r--r--components/script/dom/webidls/XR.webidl30
-rw-r--r--components/script/dom/xr.rs (renamed from components/script/dom/vr.rs)32
-rw-r--r--components/script/script_thread.rs5
6 files changed, 55 insertions, 42 deletions
diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs
index e38a5e924ac..cc734b2543e 100644
--- a/components/script/dom/mod.rs
+++ b/components/script/dom/mod.rs
@@ -479,7 +479,6 @@ pub mod validation;
pub mod validitystate;
pub mod values;
pub mod virtualmethods;
-pub mod vr;
pub mod vrdisplay;
pub mod vrdisplaycapabilities;
pub mod vrdisplayevent;
@@ -518,3 +517,4 @@ pub mod xmldocument;
pub mod xmlhttprequest;
pub mod xmlhttprequesteventtarget;
pub mod xmlhttprequestupload;
+pub mod xr;
diff --git a/components/script/dom/navigator.rs b/components/script/dom/navigator.rs
index 04669ca25d9..fccc49aac9d 100644
--- a/components/script/dom/navigator.rs
+++ b/components/script/dom/navigator.rs
@@ -4,7 +4,6 @@
use crate::dom::bindings::codegen::Bindings::NavigatorBinding;
use crate::dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorMethods;
-use crate::dom::bindings::codegen::Bindings::VRBinding::VRBinding::VRMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::bindings::str::DOMString;
@@ -16,8 +15,8 @@ use crate::dom::permissions::Permissions;
use crate::dom::pluginarray::PluginArray;
use crate::dom::promise::Promise;
use crate::dom::serviceworkercontainer::ServiceWorkerContainer;
-use crate::dom::vr::VR;
use crate::dom::window::Window;
+use crate::dom::xr::XR;
use dom_struct::dom_struct;
use std::rc::Rc;
@@ -28,7 +27,7 @@ pub struct Navigator {
plugins: MutNullableDom<PluginArray>,
mime_types: MutNullableDom<MimeTypeArray>,
service_worker: MutNullableDom<ServiceWorkerContainer>,
- vr: MutNullableDom<VR>,
+ xr: MutNullableDom<XR>,
gamepads: MutNullableDom<GamepadList>,
permissions: MutNullableDom<Permissions>,
}
@@ -41,7 +40,7 @@ impl Navigator {
plugins: Default::default(),
mime_types: Default::default(),
service_worker: Default::default(),
- vr: Default::default(),
+ xr: Default::default(),
gamepads: Default::default(),
permissions: Default::default(),
}
@@ -135,7 +134,7 @@ impl NavigatorMethods for Navigator {
.gamepads
.or_init(|| GamepadList::new(&self.global(), &[]));
- let vr_gamepads = self.Vr().get_gamepads();
+ let vr_gamepads = self.Xr().get_gamepads();
root.add_if_not_exists(&vr_gamepads);
// TODO: Add not VR related gamepads
root
@@ -149,12 +148,10 @@ impl NavigatorMethods for Navigator {
// https://w3c.github.io/webvr/spec/1.1/#navigator-getvrdisplays-attribute
#[allow(unrooted_must_root)]
fn GetVRDisplays(&self) -> Rc<Promise> {
- self.Vr().GetDisplays()
+ self.Xr().get_displays()
}
-}
-impl Navigator {
- pub fn Vr(&self) -> DomRoot<VR> {
- self.vr.or_init(|| VR::new(&self.global()))
+ fn Xr(&self) -> DomRoot<XR> {
+ self.xr.or_init(|| XR::new(&self.global()))
}
}
diff --git a/components/script/dom/webidls/VR.webidl b/components/script/dom/webidls/VR.webidl
deleted file mode 100644
index 536bce29338..00000000000
--- a/components/script/dom/webidls/VR.webidl
+++ /dev/null
@@ -1,11 +0,0 @@
-/* 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 https://mozilla.org/MPL/2.0/. */
-
-// https://w3c.github.io/webvr/#interface-navigator
-[NoInterfaceObject]
-interface VR {
- [Pref="dom.webvr.enabled"]
- Promise<sequence<VRDisplay>> getDisplays();
- //readonly attribute FrozenArray<VRDisplay> activeVRDisplays;
-};
diff --git a/components/script/dom/webidls/XR.webidl b/components/script/dom/webidls/XR.webidl
new file mode 100644
index 00000000000..9c973c39f6f
--- /dev/null
+++ b/components/script/dom/webidls/XR.webidl
@@ -0,0 +1,30 @@
+/* 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 https://mozilla.org/MPL/2.0/. */
+
+// https://immersive-web.github.io/webxr/#xr-interface
+[SecureContext, Exposed=Window]
+interface XR: EventTarget {
+ // Methods
+ // Promise<void> supportsSessionMode(XRSessionMode mode);
+ // Promise<XRSession> requestSession(optional XRSessionCreationOptions parameters);
+
+ // Events
+ // attribute EventHandler ondevicechange;
+};
+
+[SecureContext]
+partial interface Navigator {
+ [SameObject, Pref="dom.webvr.enabled"] readonly attribute XR xr;
+};
+
+enum XRSessionMode {
+ "inline",
+ "immersive-vr",
+ "immersive-ar"
+};
+
+dictionary XRSessionCreationOptions {
+ XRSessionMode mode = "inline";
+ // XRPresentationContext outputContext;
+};
diff --git a/components/script/dom/vr.rs b/components/script/dom/xr.rs
index 6686e0d917e..29d77b38a67 100644
--- a/components/script/dom/vr.rs
+++ b/components/script/dom/xr.rs
@@ -3,12 +3,11 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::cell::DomRefCell;
-use crate::dom::bindings::codegen::Bindings::VRBinding;
-use crate::dom::bindings::codegen::Bindings::VRBinding::VRMethods;
+use crate::dom::bindings::codegen::Bindings::XRBinding;
use crate::dom::bindings::codegen::Bindings::VRDisplayBinding::VRDisplayMethods;
use crate::dom::bindings::error::Error;
use crate::dom::bindings::inheritance::Castable;
-use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
+use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::event::Event;
use crate::dom::eventtarget::EventTarget;
@@ -26,38 +25,37 @@ use webvr_traits::{WebVRDisplayData, WebVRDisplayEvent, WebVREvent, WebVRMsg};
use webvr_traits::{WebVRGamepadData, WebVRGamepadEvent, WebVRGamepadState};
#[dom_struct]
-pub struct VR {
- reflector_: Reflector,
+pub struct XR {
+ eventtarget: EventTarget,
displays: DomRefCell<Vec<Dom<VRDisplay>>>,
gamepads: DomRefCell<Vec<Dom<Gamepad>>>,
}
-impl VR {
- fn new_inherited() -> VR {
- VR {
- reflector_: Reflector::new(),
+impl XR {
+ fn new_inherited() -> XR {
+ XR {
+ eventtarget: EventTarget::new_inherited(),
displays: DomRefCell::new(Vec::new()),
gamepads: DomRefCell::new(Vec::new()),
}
}
- pub fn new(global: &GlobalScope) -> DomRoot<VR> {
- let root = reflect_dom_object(Box::new(VR::new_inherited()), global, VRBinding::Wrap);
+ pub fn new(global: &GlobalScope) -> DomRoot<XR> {
+ let root = reflect_dom_object(Box::new(XR::new_inherited()), global, XRBinding::Wrap);
root.register();
root
}
}
-impl Drop for VR {
+impl Drop for XR {
fn drop(&mut self) {
self.unregister();
}
}
-impl VRMethods for VR {
+impl XR {
#[allow(unrooted_must_root)]
- // https://w3c.github.io/webvr/#interface-navigator
- fn GetDisplays(&self) -> Rc<Promise> {
+ pub fn get_displays(&self) -> Rc<Promise> {
let promise = Promise::new(&self.global());
if let Some(webvr_thread) = self.webvr_thread() {
@@ -93,9 +91,7 @@ impl VRMethods for VR {
promise
}
-}
-impl VR {
fn webvr_thread(&self) -> Option<IpcSender<WebVRMsg>> {
self.global().as_window().webvr_thread()
}
@@ -209,7 +205,7 @@ impl VR {
}
// Gamepad
-impl VR {
+impl XR {
fn find_gamepad(&self, gamepad_id: u32) -> Option<DomRoot<Gamepad>> {
self.gamepads
.borrow()
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index 50f6135ff52..2da35702834 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -26,6 +26,7 @@ use crate::dom::bindings::codegen::Bindings::DocumentBinding::{
DocumentMethods, DocumentReadyState,
};
use crate::dom::bindings::codegen::Bindings::EventBinding::EventInit;
+use crate::dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorMethods;
use crate::dom::bindings::codegen::Bindings::TransitionEventBinding::TransitionEventInit;
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use crate::dom::bindings::conversions::{
@@ -3278,8 +3279,8 @@ impl ScriptThread {
fn handle_webvr_events(&self, pipeline_id: PipelineId, events: Vec<WebVREvent>) {
let window = self.documents.borrow().find_window(pipeline_id);
if let Some(window) = window {
- let vr = window.Navigator().Vr();
- vr.handle_webvr_events(events);
+ let xr = window.Navigator().Xr();
+ xr.handle_webvr_events(events);
}
}