Bug 1350076 - Add a preference to allow proximity sensor triggering of vrdisplayactivate and vrdisplaydeactivate draft
authorKearwood Gilbert <kgilbert@mozilla.com>
Tue, 04 Apr 2017 11:28:56 -0700
changeset 558688 42140395e710d8c33c2829b2b2771216f91a9668
parent 558406 22df0c5cfbf8a2aa2822bf9c763e6c1c5a3f69de
child 623252 8a0eac3568d63a453a312171f018e455b60aec0d
push id52936
push userkgilbert@mozilla.com
push dateFri, 07 Apr 2017 22:44:33 +0000
bugs1350076
milestone55.0a1
Bug 1350076 - Add a preference to allow proximity sensor triggering of vrdisplayactivate and vrdisplaydeactivate MozReview-Commit-ID: CIPwXAofYhD
gfx/thebes/gfxPrefs.h
gfx/vr/VRDisplayClient.cpp
modules/libpref/init/all.js
--- a/gfx/thebes/gfxPrefs.h
+++ b/gfx/thebes/gfxPrefs.h
@@ -342,16 +342,17 @@ private:
   DECL_GFX_PREF(Live, "apz.scale_repaint_delay_ms",            APZScaleRepaintDelay, int32_t, 500);
 
   DECL_GFX_PREF(Live, "browser.ui.zoom.force-user-scalable",   ForceUserScalable, bool, false);
   DECL_GFX_PREF(Live, "browser.viewport.desktopWidth",         DesktopViewportWidth, int32_t, 980);
 
   DECL_GFX_PREF(Live, "dom.ipc.plugins.asyncdrawing.enabled",  PluginAsyncDrawingEnabled, bool, false);
   DECL_GFX_PREF(Live, "dom.meta-viewport.enabled",             MetaViewportEnabled, bool, false);
   DECL_GFX_PREF(Once, "dom.vr.enabled",                        VREnabled, bool, false);
+  DECL_GFX_PREF(Live, "dom.vr.autoactivate.enabled",           VRAutoActivateEnabled, bool, false);
   DECL_GFX_PREF(Live, "dom.vr.navigation.timeout",             VRNavigationTimeout, int32_t, 1000);
   DECL_GFX_PREF(Once, "dom.vr.oculus.enabled",                 VROculusEnabled, bool, true);
   DECL_GFX_PREF(Once, "dom.vr.openvr.enabled",                 VROpenVREnabled, bool, false);
   DECL_GFX_PREF(Once, "dom.vr.osvr.enabled",                   VROSVREnabled, bool, false);
   DECL_GFX_PREF(Live, "dom.vr.poseprediction.enabled",         VRPosePredictionEnabled, bool, true);
   DECL_GFX_PREF(Live, "dom.vr.require-gesture",                VRRequireGesture, bool, true);
   DECL_GFX_PREF(Live, "dom.vr.puppet.enabled",                 VRPuppetEnabled, bool, false);
   DECL_GFX_PREF(Live, "dom.w3c_pointer_events.enabled",        PointerEventsEnabled, bool, false);
--- a/gfx/vr/VRDisplayClient.cpp
+++ b/gfx/vr/VRDisplayClient.cpp
@@ -104,23 +104,27 @@ VRDisplayClient::NotifyVsync()
   if (bLastEventWasPresenting != isPresenting) {
     bLastEventWasPresenting = isPresenting;
     vm->FireDOMVRDisplayPresentChangeEvent(mDisplayInfo.mDisplayID);
   }
 
   // Check if we need to trigger onvrdisplayactivate event
   if (!bLastEventWasMounted && mDisplayInfo.mIsMounted) {
     bLastEventWasMounted = true;
-    vm->FireDOMVRDisplayMountedEvent(mDisplayInfo.mDisplayID);
+    if (gfxPrefs::VRAutoActivateEnabled()) {
+      vm->FireDOMVRDisplayMountedEvent(mDisplayInfo.mDisplayID);
+    }
   }
 
   // Check if we need to trigger onvrdisplaydeactivate event
   if (bLastEventWasMounted && !mDisplayInfo.mIsMounted) {
     bLastEventWasMounted = false;
-    vm->FireDOMVRDisplayUnmountedEvent(mDisplayInfo.mDisplayID);
+    if (gfxPrefs::VRAutoActivateEnabled()) {
+      vm->FireDOMVRDisplayUnmountedEvent(mDisplayInfo.mDisplayID);
+    }
   }
 }
 
 void
 VRDisplayClient::NotifyVRVsync()
 {
   VRManagerChild *vm = VRManagerChild::Get();
   vm->RunFrameRequestCallbacks();
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5023,16 +5023,24 @@ pref("dom.browserElement.maxScreenshotDe
 pref("dom.placeholder.show_on_focus", true);
 
 // VR is disabled by default in release and enabled for nightly and aurora
 #ifdef RELEASE_OR_BETA
 pref("dom.vr.enabled", false);
 #else
 pref("dom.vr.enabled", true);
 #endif
+// It is often desirable to automatically start vr presentation when
+// a user puts on the VR headset.  This is done by emitting the
+// Window.vrdisplayactivate event when the headset's sensors detect it
+// being worn.  This can result in WebVR content taking over the headset
+// when the user is using it outside the browser or inadvertent start of
+// presentation due to the high sensitivity of the proximity sensor in some
+// headsets, so it is off by default.
+pref("dom.vr.autoactivate.enabled", false);
 // Maximum number of milliseconds the browser will wait for content to call
 // VRDisplay.requestPresent after emitting vrdisplayactivate during VR
 // link traversal.  This prevents a long running event handler for
 // vrdisplayactivate from later calling VRDisplay.requestPresent, which would
 // result in a non-responsive browser in the VR headset.
 pref("dom.vr.navigation.timeout", 5000);
 // Oculus device
 pref("dom.vr.oculus.enabled", true);