Bug 1495358 - FeaturePolicy: vr, r=kip
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 03 Oct 2018 12:39:44 +0200
changeset 495114 a1855d696e1ca886a4ed8f3668bc6830a8d1ccd6
parent 495113 9d0ccdab956d9037b083d2576cc54e587fb70f71
child 495115 6ed1e83038877539749f73b32c83ec887ae36681
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskip
bugs1495358
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1495358 - FeaturePolicy: vr, r=kip
dom/base/Navigator.cpp
dom/security/featurepolicy/FeaturePolicyUtils.cpp
testing/web-platform/meta/webvr/__dir__.ini
testing/web-platform/meta/webvr/webvr-disabled-by-feature-policy.https.sub.html.ini
testing/web-platform/meta/webvr/webvr-enabled-by-feature-policy-attribute-redirect-on-load.https.sub.html.ini
testing/web-platform/meta/webvr/webvr-enabled-by-feature-policy-attribute.https.sub.html.ini
testing/web-platform/meta/webvr/webvr-enabled-on-self-origin-by-feature-policy.https.sub.html.ini
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -1269,21 +1269,27 @@ Navigator::RequestGamepadServiceTest()
     mGamepadServiceTest = GamepadServiceTest::CreateTestService(mWindow);
   }
   return mGamepadServiceTest;
 }
 
 already_AddRefed<Promise>
 Navigator::GetVRDisplays(ErrorResult& aRv)
 {
-  if (!mWindow || !mWindow->GetDocShell()) {
+  if (!mWindow || !mWindow->GetDocShell() || !mWindow->GetExtantDoc()) {
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return nullptr;
   }
 
+  if (!FeaturePolicyUtils::IsFeatureAllowed(mWindow->GetExtantDoc(),
+                                            NS_LITERAL_STRING("vr"))) {
+    aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
+    return nullptr;
+  }
+
   nsGlobalWindowInner* win = nsGlobalWindowInner::Cast(mWindow);
   win->NotifyVREventListenerAdded();
 
   RefPtr<Promise> p = Promise::Create(mWindow->AsGlobal(), aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
 
--- a/dom/security/featurepolicy/FeaturePolicyUtils.cpp
+++ b/dom/security/featurepolicy/FeaturePolicyUtils.cpp
@@ -35,17 +35,16 @@ static FeatureMap sSupportedFeatures[] =
   // TODO: not supported yet!!!
   { "geolocation", FeatureMap::eSelf  },
   // TODO: not supported yet!!!
   { "microphone", FeatureMap::eSelf  },
   { "midi", FeatureMap::eSelf  },
   { "payment", FeatureMap::eSelf  },
   // TODO: not supported yet!!!
   { "speaker", FeatureMap::eSelf  },
-  // TODO: not supported yet!!!
   { "vr", FeatureMap::eSelf  },
 };
 
 /* static */ bool
 FeaturePolicyUtils::IsSupportedFeature(const nsAString& aFeatureName)
 {
   uint32_t numFeatures = (sizeof(sSupportedFeatures) / sizeof(sSupportedFeatures[0]));
   for (uint32_t i = 0; i < numFeatures; ++i) {
--- a/testing/web-platform/meta/webvr/__dir__.ini
+++ b/testing/web-platform/meta/webvr/__dir__.ini
@@ -1,1 +1,1 @@
-prefs: [dom.vr.enabled:true]
+prefs: [dom.vr.enabled:true,dom.security.featurePolicy.enabled:true]
deleted file mode 100644
--- a/testing/web-platform/meta/webvr/webvr-disabled-by-feature-policy.https.sub.html.ini
+++ /dev/null
@@ -1,10 +0,0 @@
-[webvr-disabled-by-feature-policy.https.sub.html]
-  [Feature-Policy header vr "none" disallows the top-level document.]
-    expected: FAIL
-
-  [Feature-Policy header vr "none" disallows same-origin iframes.]
-    expected: FAIL
-
-  [Feature-Policy header vr "none" disallows cross-origin iframes.]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/webvr/webvr-enabled-by-feature-policy-attribute-redirect-on-load.https.sub.html.ini
+++ /dev/null
@@ -1,7 +0,0 @@
-[webvr-enabled-by-feature-policy-attribute-redirect-on-load.https.sub.html]
-  [Feature-Policy allow="vr" attribute allows same-origin relocation]
-    expected: FAIL
-
-  [Feature-Policy allow="vr" attribute disallows cross-origin relocation]
-    expected: FAIL
-
--- a/testing/web-platform/meta/webvr/webvr-enabled-by-feature-policy-attribute.https.sub.html.ini
+++ b/testing/web-platform/meta/webvr/webvr-enabled-by-feature-policy-attribute.https.sub.html.ini
@@ -1,7 +1,4 @@
 [webvr-enabled-by-feature-policy-attribute.https.sub.html]
-  [Feature-Policy allow="vr" attribute allows same-origin iframe]
-    expected: FAIL
-
   [Feature-Policy allow="vr" attribute allows cross-origin iframe]
     expected: FAIL
 
deleted file mode 100644
--- a/testing/web-platform/meta/webvr/webvr-enabled-on-self-origin-by-feature-policy.https.sub.html.ini
+++ /dev/null
@@ -1,4 +0,0 @@
-[webvr-enabled-on-self-origin-by-feature-policy.https.sub.html]
-  [Feature-Policy header vr "self" disallows cross-origin iframes.]
-    expected: FAIL
-