Bug 1514474 - Implement FeaturePolicy.features(), r=ckerschb
☠☠ backed out by f78b95447137 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 03 Jul 2019 13:16:36 +0000
changeset 543944 e74168e44dd7230e8ac5fc2b6faf1d350f283cde
parent 543943 a43f3aa0ea77d373c5fa6a4c84b23535c8747fe0
child 543945 52ae606e4cfa4334c1ea549298f37efe10bdb414
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1514474
milestone69.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 1514474 - Implement FeaturePolicy.features(), r=ckerschb Depends on D35801 Differential Revision: https://phabricator.services.mozilla.com/D35802
dom/security/featurepolicy/FeaturePolicy.cpp
dom/security/featurepolicy/FeaturePolicy.h
dom/security/featurepolicy/test/mochitest/mochitest.ini
dom/security/featurepolicy/test/mochitest/test_featureList.html
dom/webidl/FeaturePolicy.webidl
--- a/dom/security/featurepolicy/FeaturePolicy.cpp
+++ b/dom/security/featurepolicy/FeaturePolicy.cpp
@@ -143,16 +143,26 @@ bool FeaturePolicy::AllowsFeatureInterna
 
     default:
       MOZ_CRASH("Unknown default value");
   }
 
   return false;
 }
 
+void FeaturePolicy::Features(nsTArray<nsString>& aFeatures) {
+  RefPtr<FeaturePolicy> self = this;
+  FeaturePolicyUtils::ForEachFeature(
+      [self, &aFeatures](const char* aFeatureName) {
+        nsString featureName;
+        featureName.AppendASCII(aFeatureName);
+        aFeatures.AppendElement(featureName);
+      });
+}
+
 void FeaturePolicy::AllowedFeatures(nsTArray<nsString>& aAllowedFeatures) {
   RefPtr<FeaturePolicy> self = this;
   FeaturePolicyUtils::ForEachFeature(
       [self, &aAllowedFeatures](const char* aFeatureName) {
         nsString featureName;
         featureName.AppendASCII(aFeatureName);
 
         if (self->AllowsFeatureInternal(featureName, self->mDefaultOrigin)) {
--- a/dom/security/featurepolicy/FeaturePolicy.h
+++ b/dom/security/featurepolicy/FeaturePolicy.h
@@ -108,16 +108,18 @@ class FeaturePolicy final : public nsISu
 
   nsINode* GetParentObject() const { return mParentNode; }
 
   // WebIDL explosed methods.
 
   bool AllowsFeature(const nsAString& aFeatureName,
                      const Optional<nsAString>& aOrigin) const;
 
+  void Features(nsTArray<nsString>& aFeatures);
+
   void AllowedFeatures(nsTArray<nsString>& aAllowedFeatures);
 
   void GetAllowlistForFeature(const nsAString& aFeatureName,
                               nsTArray<nsString>& aList) const;
 
  private:
   ~FeaturePolicy() = default;
 
--- a/dom/security/featurepolicy/test/mochitest/mochitest.ini
+++ b/dom/security/featurepolicy/test/mochitest/mochitest.ini
@@ -3,8 +3,9 @@ prefs =
   dom.security.featurePolicy.enabled=true
   dom.security.featurePolicy.header.enabled=true
   dom.security.featurePolicy.webidl.enabled=true
 support-files =
   empty.html
   test_parser.html^headers^
 
 [test_parser.html]
+[test_featureList.html]
new file mode 100644
--- /dev/null
+++ b/dom/security/featurepolicy/test/mochitest/test_featureList.html
@@ -0,0 +1,41 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test feature policy - list</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<iframe src="empty.html" id="ifr"></iframe>
+<script type="text/javascript">
+
+let supportedFeatures = [
+  "autoplay",
+  "camera",
+  "encrypted-media",
+  "fullscreen",
+  "geolocation",
+  "microphone",
+  "midi",
+  "payment",
+  "document-domain",
+  "speaker",
+  "vr",
+];
+
+function checkFeatures(features) {
+  features.forEach(feature => {
+    ok(supportedFeatures.includes(feature), "Feature: " + feature);
+  });
+}
+
+ok("featurePolicy" in document, "We have document.featurePolicy");
+checkFeatures(document.featurePolicy.features());
+
+let ifr = document.getElementById("ifr");
+ok("featurePolicy" in ifr, "We have HTMLIFrameElement.featurePolicy");
+checkFeatures(ifr.featurePolicy.features());
+
+</script>
+</body>
+</html>
--- a/dom/webidl/FeaturePolicy.webidl
+++ b/dom/webidl/FeaturePolicy.webidl
@@ -5,16 +5,17 @@
  *
  * For more information on this interface, please see
  * https://w3c.github.io/webappsec-feature-policy/#idl-index
  */
 
 [NoInterfaceObject]
 interface FeaturePolicy {
   boolean allowsFeature(DOMString feature, optional DOMString origin);
+  sequence<DOMString> features();
   sequence<DOMString> allowedFeatures();
   sequence<DOMString> getAllowlistForFeature(DOMString feature);
 };
 
 [Pref="dom.reporting.featurePolicy.enabled"]
 interface FeaturePolicyViolationReportBody : ReportBody {
   readonly attribute DOMString featureId;
   readonly attribute DOMString? sourceFile;