diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 1fbcbcdf889e..d4cecdcca747 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -2211,7 +2211,7 @@ nsresult Document::Init() { // we need to create a policy here so getting the policy within // ::Policy() can *always* return a non null policy - mFeaturePolicy = new mozilla::dom::FeaturePolicy(this); + mFeaturePolicy = new FeaturePolicy(this); mFeaturePolicy->SetDefaultOrigin(NodePrincipal()); mStyleSet = MakeUnique(*this); @@ -3275,14 +3275,14 @@ nsresult Document::InitFeaturePolicy(nsIChannel* aChannel) { mFeaturePolicy->SetDefaultOrigin(NodePrincipal()); - RefPtr parentPolicy = nullptr; + RefPtr parentPolicy = nullptr; if (mDocumentContainer) { nsPIDOMWindowOuter* containerWindow = mDocumentContainer->GetWindow(); if (containerWindow) { nsCOMPtr node = containerWindow->GetFrameElementInternal(); HTMLIFrameElement* iframe = HTMLIFrameElement::FromNodeOrNull(node); if (iframe) { - parentPolicy = iframe->FeaturePolicy(); + parentPolicy = iframe->Policy(); } } } @@ -12573,10 +12573,10 @@ void Document::MaybeResolveReadyForIdle() { } } -mozilla::dom::FeaturePolicy* Document::FeaturePolicy() const { +FeaturePolicy* Document::Policy() const { // The policy is created when the document is initialized. We _must_ have a // policy here even if the featurePolicy pref is off. If this assertion fails, - // it means that ::FeaturePolicy() is called before ::StartDocumentLoad(). + // it means that ::Policy() is called before ::StartDocumentLoad(). MOZ_ASSERT(mFeaturePolicy); return mFeaturePolicy; } diff --git a/dom/base/Document.h b/dom/base/Document.h index 0894527faeb1..d5fa04eead2b 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -4052,7 +4052,7 @@ class Document : public nsINode, mAllowPaymentRequest = aAllowPaymentRequest; } - mozilla::dom::FeaturePolicy* FeaturePolicy() const; + FeaturePolicy* Policy() const; bool ModuleScriptsEnabled(); @@ -4474,7 +4474,7 @@ class Document : public nsINode, RefPtr mReadyForIdle; - RefPtr mFeaturePolicy; + RefPtr mFeaturePolicy; UniquePtr mResizeObserverController; diff --git a/dom/html/HTMLIFrameElement.cpp b/dom/html/HTMLIFrameElement.cpp index 11f138c27e21..6064c102242d 100644 --- a/dom/html/HTMLIFrameElement.cpp +++ b/dom/html/HTMLIFrameElement.cpp @@ -54,7 +54,7 @@ HTMLIFrameElement::HTMLIFrameElement( FromParser aFromParser) : nsGenericHTMLFrameElement(std::move(aNodeInfo), aFromParser) { // We always need a featurePolicy, even if not exposed. - mFeaturePolicy = new mozilla::dom::FeaturePolicy(this); + mFeaturePolicy = new FeaturePolicy(this); nsCOMPtr origin = GetFeaturePolicyDefaultOrigin(); MOZ_ASSERT(origin); @@ -224,9 +224,7 @@ JSObject* HTMLIFrameElement::WrapNode(JSContext* aCx, return HTMLIFrameElement_Binding::Wrap(aCx, this, aGivenProto); } -mozilla::dom::FeaturePolicy* HTMLIFrameElement::FeaturePolicy() const { - return mFeaturePolicy; -} +FeaturePolicy* HTMLIFrameElement::Policy() const { return mFeaturePolicy; } already_AddRefed HTMLIFrameElement::GetFeaturePolicyDefaultOrigin() const { @@ -270,7 +268,7 @@ void HTMLIFrameElement::RefreshFeaturePolicy(bool aParseAllowAttribute) { origin); } - mFeaturePolicy->InheritPolicy(OwnerDoc()->FeaturePolicy()); + mFeaturePolicy->InheritPolicy(OwnerDoc()->Policy()); } if (AllowPaymentRequest()) { diff --git a/dom/html/HTMLIFrameElement.h b/dom/html/HTMLIFrameElement.h index ff1d6b2b9b66..87f58e1ad0da 100644 --- a/dom/html/HTMLIFrameElement.h +++ b/dom/html/HTMLIFrameElement.h @@ -154,7 +154,7 @@ class HTMLIFrameElement final : public nsGenericHTMLFrameElement { bool FullscreenFlag() const { return mFullscreenFlag; } void SetFullscreenFlag(bool aValue) { mFullscreenFlag = aValue; } - mozilla::dom::FeaturePolicy* FeaturePolicy() const; + FeaturePolicy* Policy() const; protected: virtual ~HTMLIFrameElement(); diff --git a/dom/security/featurepolicy/FeaturePolicy.cpp b/dom/security/featurepolicy/FeaturePolicy.cpp index 1bd546e3b61c..9af99ae9b054 100644 --- a/dom/security/featurepolicy/FeaturePolicy.cpp +++ b/dom/security/featurepolicy/FeaturePolicy.cpp @@ -90,7 +90,7 @@ void FeaturePolicy::ResetDeclaredPolicy() { mFeatures.Clear(); } JSObject* FeaturePolicy::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - return FeaturePolicy_Binding::Wrap(aCx, this, aGivenProto); + return Policy_Binding::Wrap(aCx, this, aGivenProto); } bool FeaturePolicy::AllowsFeature(const nsAString& aFeatureName, @@ -148,16 +148,6 @@ bool FeaturePolicy::AllowsFeatureInternal(const nsAString& aFeatureName, return false; } -void FeaturePolicy::Features(nsTArray& aFeatures) { - RefPtr self = this; - FeaturePolicyUtils::ForEachFeature( - [self, &aFeatures](const char* aFeatureName) { - nsString featureName; - featureName.AppendASCII(aFeatureName); - aFeatures.AppendElement(featureName); - }); -} - void FeaturePolicy::AllowedFeatures(nsTArray& aAllowedFeatures) { RefPtr self = this; FeaturePolicyUtils::ForEachFeature( diff --git a/dom/security/featurepolicy/FeaturePolicy.h b/dom/security/featurepolicy/FeaturePolicy.h index 1fe517e3a3af..3856cd25d173 100644 --- a/dom/security/featurepolicy/FeaturePolicy.h +++ b/dom/security/featurepolicy/FeaturePolicy.h @@ -113,8 +113,6 @@ class FeaturePolicy final : public nsISupports, public nsWrapperCache { bool AllowsFeature(const nsAString& aFeatureName, const Optional& aOrigin) const; - void Features(nsTArray& aFeatures); - void AllowedFeatures(nsTArray& aAllowedFeatures); void GetAllowlistForFeature(const nsAString& aFeatureName, diff --git a/dom/security/featurepolicy/FeaturePolicyUtils.cpp b/dom/security/featurepolicy/FeaturePolicyUtils.cpp index 8c100993910e..b503a8370952 100644 --- a/dom/security/featurepolicy/FeaturePolicyUtils.cpp +++ b/dom/security/featurepolicy/FeaturePolicyUtils.cpp @@ -92,7 +92,7 @@ bool FeaturePolicyUtils::IsFeatureAllowed(Document* aDocument, return true; } - FeaturePolicy* policy = aDocument->FeaturePolicy(); + FeaturePolicy* policy = aDocument->Policy(); MOZ_ASSERT(policy); if (policy->AllowsFeatureInternal(aFeatureName, policy->DefaultOrigin())) { diff --git a/dom/security/featurepolicy/test/mochitest/mochitest.ini b/dom/security/featurepolicy/test/mochitest/mochitest.ini index a9598fd7ee39..3402c8662f4b 100644 --- a/dom/security/featurepolicy/test/mochitest/mochitest.ini +++ b/dom/security/featurepolicy/test/mochitest/mochitest.ini @@ -8,4 +8,3 @@ support-files = test_parser.html^headers^ [test_parser.html] -[test_featureList.html] diff --git a/dom/security/featurepolicy/test/mochitest/test_featureList.html b/dom/security/featurepolicy/test/mochitest/test_featureList.html deleted file mode 100644 index 73c9c4edef56..000000000000 --- a/dom/security/featurepolicy/test/mochitest/test_featureList.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - Test feature policy - list - - - - - - - - diff --git a/dom/security/featurepolicy/test/mochitest/test_parser.html b/dom/security/featurepolicy/test/mochitest/test_parser.html index 3cfbc96dd340..3c4ab7771c23 100644 --- a/dom/security/featurepolicy/test/mochitest/test_parser.html +++ b/dom/security/featurepolicy/test/mochitest/test_parser.html @@ -12,40 +12,40 @@ SimpleTest.waitForExplicitFinish(); function test_document() { - info("Checking document.featurePolicy"); - ok("featurePolicy" in document, "We have document.featurePolicy"); + info("Checking document.policy"); + ok("policy" in document, "We have document.policy"); - ok(!document.featurePolicy.allowsFeature("foobar"), "Random feature"); - ok(!document.featurePolicy.allowsFeature("foobar", "http://www.something.net"), "Random feature"); + ok(!document.policy.allowsFeature("foobar"), "Random feature"); + ok(!document.policy.allowsFeature("foobar", "http://www.something.net"), "Random feature"); - ok(document.featurePolicy.allowsFeature("camera"), "Camera is allowed for self"); - ok(document.featurePolicy.allowsFeature("camera", "http://foo.bar"), "Camera is always allowed"); - let allowed = document.featurePolicy.getAllowlistForFeature("camera"); + ok(document.policy.allowsFeature("camera"), "Camera is allowed for self"); + ok(document.policy.allowsFeature("camera", "http://foo.bar"), "Camera is always allowed"); + let allowed = document.policy.getAllowlistForFeature("camera"); is(allowed.length, 1, "Only 1 entry in allowlist for camera"); is(allowed[0], "*", "allowlist is *"); - ok(document.featurePolicy.allowsFeature("geolocation"), "Geolocation is allowed for self"); - ok(document.featurePolicy.allowsFeature("geolocation", location.origin), "Geolocation is allowed for self"); - ok(!document.featurePolicy.allowsFeature("geolocation", "http://foo.bar"), "Geolocation is not allowed for any random URL"); - allowed = document.featurePolicy.getAllowlistForFeature("geolocation"); + ok(document.policy.allowsFeature("geolocation"), "Geolocation is allowed for self"); + ok(document.policy.allowsFeature("geolocation", location.origin), "Geolocation is allowed for self"); + ok(!document.policy.allowsFeature("geolocation", "http://foo.bar"), "Geolocation is not allowed for any random URL"); + allowed = document.policy.getAllowlistForFeature("geolocation"); is(allowed.length, 1, "Only 1 entry in allowlist for geolocation"); is(allowed[0], location.origin, "allowlist is self"); - ok(!document.featurePolicy.allowsFeature("microphone"), "Microphone is disabled for self"); - ok(!document.featurePolicy.allowsFeature("microphone", location.origin), "Microphone is disabled for self"); - ok(!document.featurePolicy.allowsFeature("microphone", "http://foo.bar"), "Microphone is disabled for foo.bar"); - ok(document.featurePolicy.allowsFeature("microphone", "http://example.com"), "Microphone is allowed for example.com"); - ok(document.featurePolicy.allowsFeature("microphone", "http://example.org"), "Microphone is allowed for example.org"); - allowed = document.featurePolicy.getAllowlistForFeature("microphone"); + ok(!document.policy.allowsFeature("microphone"), "Microphone is disabled for self"); + ok(!document.policy.allowsFeature("microphone", location.origin), "Microphone is disabled for self"); + ok(!document.policy.allowsFeature("microphone", "http://foo.bar"), "Microphone is disabled for foo.bar"); + ok(document.policy.allowsFeature("microphone", "http://example.com"), "Microphone is allowed for example.com"); + ok(document.policy.allowsFeature("microphone", "http://example.org"), "Microphone is allowed for example.org"); + allowed = document.policy.getAllowlistForFeature("microphone"); is(allowed.length, 0, "No allowlist for microphone"); - ok(!document.featurePolicy.allowsFeature("vr"), "Vibrate is disabled for self"); - ok(!document.featurePolicy.allowsFeature("vr", location.origin), "Vibrate is disabled for self"); - ok(!document.featurePolicy.allowsFeature("vr", "http://foo.bar"), "Vibrate is disabled for foo.bar"); - allowed = document.featurePolicy.getAllowlistForFeature("vr"); + ok(!document.policy.allowsFeature("vr"), "Vibrate is disabled for self"); + ok(!document.policy.allowsFeature("vr", location.origin), "Vibrate is disabled for self"); + ok(!document.policy.allowsFeature("vr", "http://foo.bar"), "Vibrate is disabled for foo.bar"); + allowed = document.policy.getAllowlistForFeature("vr"); is(allowed.length, 0, "No allowlist for vr"); - allowed = document.featurePolicy.allowedFeatures(); + allowed = document.policy.allowedFeatures(); // microphone is disabled for this origin, vr is disabled everywhere. let camera = false; let geolocation = false; @@ -61,136 +61,136 @@ } function test_iframe_without_allow() { - info("Checking HTMLIFrameElement.featurePolicy"); + info("Checking HTMLIFrameElement.policy"); let ifr = document.getElementById("ifr"); - ok("featurePolicy" in ifr, "HTMLIFrameElement.featurePolicy exists"); + ok("policy" in ifr, "HTMLIFrameElement.policy exists"); - ok(!ifr.featurePolicy.allowsFeature("foobar"), "Random feature"); - ok(!ifr.featurePolicy.allowsFeature("foobar", "http://www.something.net"), "Random feature"); + ok(!ifr.policy.allowsFeature("foobar"), "Random feature"); + ok(!ifr.policy.allowsFeature("foobar", "http://www.something.net"), "Random feature"); - ok(ifr.featurePolicy.allowsFeature("camera"), "Camera is allowed for self"); - ok(ifr.featurePolicy.allowsFeature("camera", location.origin), "Camera is allowed for self"); - ok(!ifr.featurePolicy.allowsFeature("camera", "http://foo.bar"), "Camera is not allowed for a random URL"); - let allowed = ifr.featurePolicy.getAllowlistForFeature("camera"); + ok(ifr.policy.allowsFeature("camera"), "Camera is allowed for self"); + ok(ifr.policy.allowsFeature("camera", location.origin), "Camera is allowed for self"); + ok(!ifr.policy.allowsFeature("camera", "http://foo.bar"), "Camera is not allowed for a random URL"); + let allowed = ifr.policy.getAllowlistForFeature("camera"); is(allowed.length, 1, "Only 1 entry in allowlist for camera"); is(allowed[0], location.origin, "allowlist is 'self'"); - ok(ifr.featurePolicy.allowsFeature("geolocation"), "Geolocation is allowed for all"); - ok(ifr.featurePolicy.allowsFeature("geolocation", location.origin), "Geolocation is allowed for all"); - ok(ifr.featurePolicy.allowsFeature("geolocation", "http://foo.bar"), "Geolocation is allowed for any random URL"); - allowed = ifr.featurePolicy.getAllowlistForFeature("geolocation"); + ok(ifr.policy.allowsFeature("geolocation"), "Geolocation is allowed for all"); + ok(ifr.policy.allowsFeature("geolocation", location.origin), "Geolocation is allowed for all"); + ok(ifr.policy.allowsFeature("geolocation", "http://foo.bar"), "Geolocation is allowed for any random URL"); + allowed = ifr.policy.getAllowlistForFeature("geolocation"); is(allowed.length, 1, "Only 1 entry in allowlist for geolocation"); is(allowed[0], "*", "allowlist is '*'"); - ok(!ifr.featurePolicy.allowsFeature("microphone"), "Microphone is disabled for self"); - ok(!ifr.featurePolicy.allowsFeature("microphone", location.origin), "Microphone is disabled for self"); - ok(!ifr.featurePolicy.allowsFeature("microphone", "http://foo.bar"), "Microphone is disabled for foo.bar"); - ok(!ifr.featurePolicy.allowsFeature("microphone", "http://example.com"), "Microphone is disabled for example.com"); - ok(!ifr.featurePolicy.allowsFeature("microphone", "http://example.org"), "Microphone is disabled for example.org"); - allowed = ifr.featurePolicy.getAllowlistForFeature("microphone"); + ok(!ifr.policy.allowsFeature("microphone"), "Microphone is disabled for self"); + ok(!ifr.policy.allowsFeature("microphone", location.origin), "Microphone is disabled for self"); + ok(!ifr.policy.allowsFeature("microphone", "http://foo.bar"), "Microphone is disabled for foo.bar"); + ok(!ifr.policy.allowsFeature("microphone", "http://example.com"), "Microphone is disabled for example.com"); + ok(!ifr.policy.allowsFeature("microphone", "http://example.org"), "Microphone is disabled for example.org"); + allowed = ifr.policy.getAllowlistForFeature("microphone"); is(allowed.length, 0, "No allowlist for microphone"); - ok(!ifr.featurePolicy.allowsFeature("vr"), "Vibrate is disabled for self"); - ok(!ifr.featurePolicy.allowsFeature("vr", location.origin), "Vibrate is disabled for self"); - ok(!ifr.featurePolicy.allowsFeature("vr", "http://foo.bar"), "Vibrate is disabled for foo.bar"); - allowed = ifr.featurePolicy.getAllowlistForFeature("vr"); + ok(!ifr.policy.allowsFeature("vr"), "Vibrate is disabled for self"); + ok(!ifr.policy.allowsFeature("vr", location.origin), "Vibrate is disabled for self"); + ok(!ifr.policy.allowsFeature("vr", "http://foo.bar"), "Vibrate is disabled for foo.bar"); + allowed = ifr.policy.getAllowlistForFeature("vr"); is(allowed.length, 0, "No allowlist for vr"); - ok(ifr.featurePolicy.allowedFeatures().includes("camera"), "Camera is allowed"); - ok(ifr.featurePolicy.allowedFeatures().includes("geolocation"), "Geolocation is allowed"); + ok(ifr.policy.allowedFeatures().includes("camera"), "Camera is allowed"); + ok(ifr.policy.allowedFeatures().includes("geolocation"), "Geolocation is allowed"); // microphone is disabled for this origin - ok(!ifr.featurePolicy.allowedFeatures().includes("microphone"), "microphone is not allowed"); + ok(!ifr.policy.allowedFeatures().includes("microphone"), "microphone is not allowed"); // vr is disabled everywhere. - ok(!ifr.featurePolicy.allowedFeatures().includes("vr"), "VR is not allowed"); + ok(!ifr.policy.allowedFeatures().includes("vr"), "VR is not allowed"); next(); } function test_iframe_with_allow() { - info("Checking HTMLIFrameElement.featurePolicy"); + info("Checking HTMLIFrameElement.policy"); let ifr = document.getElementById("ifr"); - ok("featurePolicy" in ifr, "HTMLIFrameElement.featurePolicy exists"); + ok("policy" in ifr, "HTMLIFrameElement.policy exists"); ifr.setAttribute("allow", "camera 'none'"); - ok(!ifr.featurePolicy.allowsFeature("foobar"), "Random feature"); - ok(!ifr.featurePolicy.allowsFeature("foobar", "http://www.something.net"), "Random feature"); + ok(!ifr.policy.allowsFeature("foobar"), "Random feature"); + ok(!ifr.policy.allowsFeature("foobar", "http://www.something.net"), "Random feature"); - ok(!ifr.featurePolicy.allowsFeature("camera"), "Camera is not allowed"); - let allowed = ifr.featurePolicy.getAllowlistForFeature("camera"); + ok(!ifr.policy.allowsFeature("camera"), "Camera is not allowed"); + let allowed = ifr.policy.getAllowlistForFeature("camera"); is(allowed.length, 0, "Camera has an empty allowlist"); - ok(ifr.featurePolicy.allowsFeature("geolocation"), "Geolocation is allowed for all"); - ok(ifr.featurePolicy.allowsFeature("geolocation", location.origin), "Geolocation is allowed for all"); - ok(ifr.featurePolicy.allowsFeature("geolocation", "http://foo.bar"), "Geolocation is allowed for all"); - allowed = ifr.featurePolicy.getAllowlistForFeature("geolocation"); + ok(ifr.policy.allowsFeature("geolocation"), "Geolocation is allowed for all"); + ok(ifr.policy.allowsFeature("geolocation", location.origin), "Geolocation is allowed for all"); + ok(ifr.policy.allowsFeature("geolocation", "http://foo.bar"), "Geolocation is allowed for all"); + allowed = ifr.policy.getAllowlistForFeature("geolocation"); is(allowed.length, 1, "Only 1 entry in allowlist for geolocation"); is(allowed[0], "*", "allowlist is '*'"); - ok(!ifr.featurePolicy.allowsFeature("microphone"), "Microphone is disabled for self"); - ok(!ifr.featurePolicy.allowsFeature("microphone", location.origin), "Microphone is disabled for self"); - ok(!ifr.featurePolicy.allowsFeature("microphone", "http://foo.bar"), "Microphone is disabled for foo.bar"); - ok(!ifr.featurePolicy.allowsFeature("microphone", "http://example.com"), "Microphone is disabled for example.com"); - ok(!ifr.featurePolicy.allowsFeature("microphone", "http://example.org"), "Microphone is disabled for example.org"); - allowed = ifr.featurePolicy.getAllowlistForFeature("microphone"); + ok(!ifr.policy.allowsFeature("microphone"), "Microphone is disabled for self"); + ok(!ifr.policy.allowsFeature("microphone", location.origin), "Microphone is disabled for self"); + ok(!ifr.policy.allowsFeature("microphone", "http://foo.bar"), "Microphone is disabled for foo.bar"); + ok(!ifr.policy.allowsFeature("microphone", "http://example.com"), "Microphone is disabled for example.com"); + ok(!ifr.policy.allowsFeature("microphone", "http://example.org"), "Microphone is disabled for example.org"); + allowed = ifr.policy.getAllowlistForFeature("microphone"); is(allowed.length, 0, "No allowlist for microphone"); - ok(!ifr.featurePolicy.allowsFeature("vr"), "Vibrate is disabled for self"); - ok(!ifr.featurePolicy.allowsFeature("vr", location.origin), "Vibrate is disabled for self"); - ok(!ifr.featurePolicy.allowsFeature("vr", "http://foo.bar"), "Vibrate is disabled for foo.bar"); - allowed = ifr.featurePolicy.getAllowlistForFeature("vr"); + ok(!ifr.policy.allowsFeature("vr"), "Vibrate is disabled for self"); + ok(!ifr.policy.allowsFeature("vr", location.origin), "Vibrate is disabled for self"); + ok(!ifr.policy.allowsFeature("vr", "http://foo.bar"), "Vibrate is disabled for foo.bar"); + allowed = ifr.policy.getAllowlistForFeature("vr"); is(allowed.length, 0, "No allowlist for vr"); - ok(ifr.featurePolicy.allowedFeatures().includes("geolocation"), "Geolocation is allowed only for self"); + ok(ifr.policy.allowedFeatures().includes("geolocation"), "Geolocation is allowed only for self"); next(); } function test_iframe_contentDocument() { - info("Checking iframe document.featurePolicy"); + info("Checking iframe document.policy"); let ifr = document.createElement("iframe"); ifr.setAttribute("src", "empty.html"); ifr.onload = function() { - ok("featurePolicy" in ifr.contentDocument, "We have ifr.contentDocument.featurePolicy"); + ok("policy" in ifr.contentDocument, "We have ifr.contentDocument.policy"); - ok(!ifr.contentDocument.featurePolicy.allowsFeature("foobar"), "Random feature"); - ok(!ifr.contentDocument.featurePolicy.allowsFeature("foobar", "http://www.something.net"), "Random feature"); + ok(!ifr.contentDocument.policy.allowsFeature("foobar"), "Random feature"); + ok(!ifr.contentDocument.policy.allowsFeature("foobar", "http://www.something.net"), "Random feature"); - ok(ifr.contentDocument.featurePolicy.allowsFeature("camera"), "Camera is allowed for self"); - ok(ifr.contentDocument.featurePolicy.allowsFeature("camera", location.origin), "Camera is allowed for self"); - ok(!ifr.contentDocument.featurePolicy.allowsFeature("camera", "http://foo.bar"), "Camera is allowed for self"); - let allowed = ifr.contentDocument.featurePolicy.getAllowlistForFeature("camera"); + ok(ifr.contentDocument.policy.allowsFeature("camera"), "Camera is allowed for self"); + ok(ifr.contentDocument.policy.allowsFeature("camera", location.origin), "Camera is allowed for self"); + ok(!ifr.contentDocument.policy.allowsFeature("camera", "http://foo.bar"), "Camera is allowed for self"); + let allowed = ifr.contentDocument.policy.getAllowlistForFeature("camera"); is(allowed.length, 1, "Only 1 entry in allowlist for camera"); is(allowed[0], location.origin, "allowlist is 'self'"); - ok(ifr.contentDocument.featurePolicy.allowsFeature("geolocation"), "Geolocation is allowed for all"); - ok(ifr.contentDocument.featurePolicy.allowsFeature("geolocation", location.origin), "Geolocation is allowed for all"); - ok(ifr.contentDocument.featurePolicy.allowsFeature("geolocation", "http://foo.bar"), "Geolocation is allowed for any random URL"); - allowed = ifr.contentDocument.featurePolicy.getAllowlistForFeature("geolocation"); + ok(ifr.contentDocument.policy.allowsFeature("geolocation"), "Geolocation is allowed for all"); + ok(ifr.contentDocument.policy.allowsFeature("geolocation", location.origin), "Geolocation is allowed for all"); + ok(ifr.contentDocument.policy.allowsFeature("geolocation", "http://foo.bar"), "Geolocation is allowed for any random URL"); + allowed = ifr.contentDocument.policy.getAllowlistForFeature("geolocation"); is(allowed.length, 1, "Only 1 entry in allowlist for geolocation"); is(allowed[0], "*", "allowlist is '*'"); - ok(!ifr.contentDocument.featurePolicy.allowsFeature("microphone"), "Microphone is disabled for self"); - ok(!ifr.contentDocument.featurePolicy.allowsFeature("microphone", location.origin), "Microphone is disabled for self"); - ok(!ifr.contentDocument.featurePolicy.allowsFeature("microphone", "http://foo.bar"), "Microphone is disabled for foo.bar"); - ok(!ifr.contentDocument.featurePolicy.allowsFeature("microphone", "http://example.com"), "Microphone is allowed for example.com"); - ok(!ifr.contentDocument.featurePolicy.allowsFeature("microphone", "http://example.org"), "Microphone is allowed for example.org"); - allowed = ifr.contentDocument.featurePolicy.getAllowlistForFeature("microphone"); + ok(!ifr.contentDocument.policy.allowsFeature("microphone"), "Microphone is disabled for self"); + ok(!ifr.contentDocument.policy.allowsFeature("microphone", location.origin), "Microphone is disabled for self"); + ok(!ifr.contentDocument.policy.allowsFeature("microphone", "http://foo.bar"), "Microphone is disabled for foo.bar"); + ok(!ifr.contentDocument.policy.allowsFeature("microphone", "http://example.com"), "Microphone is allowed for example.com"); + ok(!ifr.contentDocument.policy.allowsFeature("microphone", "http://example.org"), "Microphone is allowed for example.org"); + allowed = ifr.contentDocument.policy.getAllowlistForFeature("microphone"); is(allowed.length, 0, "No allowlist for microphone"); - ok(!ifr.contentDocument.featurePolicy.allowsFeature("vr"), "Vibrate is disabled for self"); - ok(!ifr.contentDocument.featurePolicy.allowsFeature("vr", location.origin), "Vibrate is disabled for self"); - ok(!ifr.contentDocument.featurePolicy.allowsFeature("vr", "http://foo.bar"), "Vibrate is disabled for foo.bar"); - allowed = ifr.contentDocument.featurePolicy.getAllowlistForFeature("vr"); + ok(!ifr.contentDocument.policy.allowsFeature("vr"), "Vibrate is disabled for self"); + ok(!ifr.contentDocument.policy.allowsFeature("vr", location.origin), "Vibrate is disabled for self"); + ok(!ifr.contentDocument.policy.allowsFeature("vr", "http://foo.bar"), "Vibrate is disabled for foo.bar"); + allowed = ifr.contentDocument.policy.getAllowlistForFeature("vr"); is(allowed.length, 0, "No allowlist for vr"); - ok(ifr.contentDocument.featurePolicy.allowedFeatures().includes("camera"), "Camera is allowed"); - ok(ifr.contentDocument.featurePolicy.allowedFeatures().includes("geolocation"), "Geolocation is allowed"); + ok(ifr.contentDocument.policy.allowedFeatures().includes("camera"), "Camera is allowed"); + ok(ifr.contentDocument.policy.allowedFeatures().includes("geolocation"), "Geolocation is allowed"); // microphone is disabled for this origin - ok(!ifr.contentDocument.featurePolicy.allowedFeatures().includes("microphone"), "Microphone is not allowed"); + ok(!ifr.contentDocument.policy.allowedFeatures().includes("microphone"), "Microphone is not allowed"); // vr is disabled everywhere. - ok(!ifr.contentDocument.featurePolicy.allowedFeatures().includes("vr"), "VR is not allowed"); + ok(!ifr.contentDocument.policy.allowedFeatures().includes("vr"), "VR is not allowed"); next(); }; diff --git a/dom/webidl/Document.webidl b/dom/webidl/Document.webidl index 5d3f3e3e2f06..a18cdb3eb73a 100644 --- a/dom/webidl/Document.webidl +++ b/dom/webidl/Document.webidl @@ -601,10 +601,10 @@ Document implements GeometryUtils; Document implements FontFaceSource; Document implements DocumentOrShadowRoot; -// https://w3c.github.io/webappsec-feature-policy/#idl-index +// https://wicg.github.io/feature-policy/#policy partial interface Document { [SameObject, Pref="dom.security.featurePolicy.webidl.enabled"] - readonly attribute FeaturePolicy featurePolicy; + readonly attribute Policy policy; }; /** diff --git a/dom/webidl/FeaturePolicy.webidl b/dom/webidl/FeaturePolicy.webidl index e89f56b6ded8..cb5bb527a3d1 100644 --- a/dom/webidl/FeaturePolicy.webidl +++ b/dom/webidl/FeaturePolicy.webidl @@ -4,13 +4,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * For more information on this interface, please see - * https://w3c.github.io/webappsec-feature-policy/#idl-index + * https://wicg.github.io/feature-policy/#policy */ [NoInterfaceObject] -interface FeaturePolicy { +interface Policy { boolean allowsFeature(DOMString feature, optional DOMString origin); - sequence features(); sequence allowedFeatures(); sequence getAllowlistForFeature(DOMString feature); }; diff --git a/dom/webidl/HTMLIFrameElement.webidl b/dom/webidl/HTMLIFrameElement.webidl index 769954b801ec..615046c06598 100644 --- a/dom/webidl/HTMLIFrameElement.webidl +++ b/dom/webidl/HTMLIFrameElement.webidl @@ -70,10 +70,10 @@ partial interface HTMLIFrameElement { HTMLIFrameElement implements MozFrameLoaderOwner; HTMLIFrameElement implements BrowserElement; -// https://w3c.github.io/webappsec-feature-policy/#idl-index +// https://wicg.github.io/feature-policy/#policy partial interface HTMLIFrameElement { [SameObject, Pref="dom.security.featurePolicy.webidl.enabled"] - readonly attribute FeaturePolicy featurePolicy; + readonly attribute Policy policy; [CEReactions, SetterThrows, Pure, Pref="dom.security.featurePolicy.enabled"] attribute DOMString allow; diff --git a/testing/web-platform/meta/feature-policy/experimental-features/layout-animations-disabled-violation-report-js-tentative.html.ini b/testing/web-platform/meta/feature-policy/experimental-features/layout-animations-disabled-violation-report-js-tentative.html.ini index 5474dee81112..499f8eeb2149 100644 --- a/testing/web-platform/meta/feature-policy/experimental-features/layout-animations-disabled-violation-report-js-tentative.html.ini +++ b/testing/web-platform/meta/feature-policy/experimental-features/layout-animations-disabled-violation-report-js-tentative.html.ini @@ -9,3 +9,6 @@ [Verify that when 'layout-animations' is disabled, an 'element.animate' API including a keyframe that uses a blocked property generates violation report (inline scripts).] expected: NOTRUN + [Verify 'layout-animations' is not in document's feature list.] + expected: FAIL + diff --git a/testing/web-platform/meta/feature-policy/experimental-features/layout-animations-disabled-violation-report-keyframes-tentative.html.ini b/testing/web-platform/meta/feature-policy/experimental-features/layout-animations-disabled-violation-report-keyframes-tentative.html.ini index d6790044f23f..2517c9015cb0 100644 --- a/testing/web-platform/meta/feature-policy/experimental-features/layout-animations-disabled-violation-report-keyframes-tentative.html.ini +++ b/testing/web-platform/meta/feature-policy/experimental-features/layout-animations-disabled-violation-report-keyframes-tentative.html.ini @@ -5,3 +5,7 @@ [Verify that when 'layout-animations' is disabled, a keyframes which includes a blocked property generates violation report.] expected: TIMEOUT + + [Sanity-check: 'layout-animations' is not in document's feature list.] + expected: FAIL + diff --git a/testing/web-platform/meta/feature-policy/experimental-features/lazyload/lazyload-enabled-tentative.sub.html.ini b/testing/web-platform/meta/feature-policy/experimental-features/lazyload/lazyload-enabled-tentative.sub.html.ini index 6ab6d2e033c5..e017d8764522 100644 --- a/testing/web-platform/meta/feature-policy/experimental-features/lazyload/lazyload-enabled-tentative.sub.html.ini +++ b/testing/web-platform/meta/feature-policy/experimental-features/lazyload/lazyload-enabled-tentative.sub.html.ini @@ -11,5 +11,3 @@ [Sanity-check: Contents do not load immediately (no eager-loading) when the loading attribute is 'lazy' and frame is in viewport.] expected: FAIL - [When 'lazyload' feature is enabled, a frame can avoid lazyloading by setting 'loading' attribute to 'eager'] - expected: FAIL diff --git a/testing/web-platform/meta/feature-policy/feature-policy-for-sandbox/feature-propagation-to-auxiliary-context.html.ini b/testing/web-platform/meta/feature-policy/feature-policy-for-sandbox/feature-propagation-to-auxiliary-context.html.ini index b2f6c00f3da4..30b8aef716d8 100644 --- a/testing/web-platform/meta/feature-policy/feature-policy-for-sandbox/feature-propagation-to-auxiliary-context.html.ini +++ b/testing/web-platform/meta/feature-policy/feature-policy-for-sandbox/feature-propagation-to-auxiliary-context.html.ini @@ -2,5 +2,3 @@ [feature-propagation-to-auxiliary-context] expected: FAIL - [Verify feature policies are inherited by the auxiliary browsing context if opened from a non-sandboxed same-origin