Bug 1497034 - FeaturePolicy: autoplay, r=cpearce
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 09 Oct 2018 14:22:19 +0200
changeset 498684 f574c731fcb0e65e969a53e86ffd7ff57bbe2000
parent 498683 8b5926fac04e55e492e998b87920931cd32f3a73
child 498685 eaa627409f750ad32fa96b757a0d35d7601b47c3
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1497034
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 1497034 - FeaturePolicy: autoplay, r=cpearce
dom/media/AutoplayPolicy.cpp
dom/security/featurepolicy/FeaturePolicyUtils.cpp
testing/web-platform/meta/html/semantics/embedded-content/media-elements/__dir__.ini
testing/web-platform/meta/html/semantics/embedded-content/media-elements/autoplay-allowed-by-feature-policy-attribute-redirect-on-load.https.sub.html.ini
testing/web-platform/meta/html/semantics/embedded-content/media-elements/autoplay-allowed-by-feature-policy-attribute.https.sub.html.ini
--- a/dom/media/AutoplayPolicy.cpp
+++ b/dom/media/AutoplayPolicy.cpp
@@ -6,16 +6,17 @@
 
 #include "AutoplayPolicy.h"
 
 #include "mozilla/EventStateManager.h"
 #include "mozilla/Logging.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/dom/AudioContext.h"
 #include "mozilla/AutoplayPermissionManager.h"
+#include "mozilla/dom/FeaturePolicyUtils.h"
 #include "mozilla/dom/HTMLMediaElement.h"
 #include "mozilla/dom/HTMLMediaElementBinding.h"
 #include "nsGlobalWindowInner.h"
 #include "nsIAutoplay.h"
 #include "nsContentUtils.h"
 #include "nsIDocument.h"
 #include "MediaManager.h"
 #include "nsIDocShell.h"
@@ -74,16 +75,26 @@ IsWindowAllowedToPlay(nsPIDOMWindowInner
                  " permission.");
     return true;
   }
 
   if (!aWindow->GetExtantDoc()) {
     return false;
   }
 
+  // Here we are checking whether the current document is blocked via
+  // feature-policy, and further down we walk up the doc tree to the top level
+  // content document and check permissions etc on the top level content
+  // document. FeaturePolicy propagates the permission to any sub-documents if
+  // they don't have special directives.
+  if (!FeaturePolicyUtils::IsFeatureAllowed(aWindow->GetExtantDoc(),
+                                            NS_LITERAL_STRING("autoplay"))) {
+    return false;
+  }
+
   nsIDocument* approver = ApproverDocOf(*aWindow->GetExtantDoc());
   if (nsContentUtils::IsExactSitePermAllow(approver->NodePrincipal(),
                                            "autoplay-media")) {
     AUTOPLAY_LOG("Allow autoplay as document has autoplay permission.");
     return true;
   }
 
   if (approver->HasBeenUserGestureActivated()) {
--- a/dom/security/featurepolicy/FeaturePolicyUtils.cpp
+++ b/dom/security/featurepolicy/FeaturePolicyUtils.cpp
@@ -20,17 +20,16 @@ struct FeatureMap {
   } mDefaultAllowList;
 };
 
 /*
  * IMPORTANT: Do not change this list without review from a DOM peer _AND_ a
  * DOM Security peer!
  */
 static FeatureMap sSupportedFeatures[] = {
-  // TODO: not supported yet!!!
   { "autoplay", FeatureMap::eAll },
   // TODO: not supported yet!!!
   { "camera", FeatureMap::eAll  },
   { "encrypted-media", FeatureMap::eAll  },
   { "fullscreen", FeatureMap::eAll  },
   { "geolocation", FeatureMap::eAll  },
   // TODO: not supported yet!!!
   { "microphone", FeatureMap::eAll  },
--- a/testing/web-platform/meta/html/semantics/embedded-content/media-elements/__dir__.ini
+++ b/testing/web-platform/meta/html/semantics/embedded-content/media-elements/__dir__.ini
@@ -1,1 +1,2 @@
+prefs: [dom.security.featurePolicy.enabled:true]
 lsan-allowed: []
--- a/testing/web-platform/meta/html/semantics/embedded-content/media-elements/autoplay-allowed-by-feature-policy-attribute-redirect-on-load.https.sub.html.ini
+++ b/testing/web-platform/meta/html/semantics/embedded-content/media-elements/autoplay-allowed-by-feature-policy-attribute-redirect-on-load.https.sub.html.ini
@@ -1,8 +1,8 @@
 [autoplay-allowed-by-feature-policy-attribute-redirect-on-load.https.sub.html]
   expected: TIMEOUT
   [Feature-Policy allow="autoplay" disallows cross-origin navigation in an iframe.]
-    expected: TIMEOUT
+    expected: FAIL
 
   [Feature-Policy allow="autoplay" allows same-origin navigation in an iframe.]
     expected: TIMEOUT
 
--- a/testing/web-platform/meta/html/semantics/embedded-content/media-elements/autoplay-allowed-by-feature-policy-attribute.https.sub.html.ini
+++ b/testing/web-platform/meta/html/semantics/embedded-content/media-elements/autoplay-allowed-by-feature-policy-attribute.https.sub.html.ini
@@ -1,8 +1,5 @@
 [autoplay-allowed-by-feature-policy-attribute.https.sub.html]
   expected: TIMEOUT
-  [Feature policy "autoplay" can be enabled in cross-origin iframe using allow="autoplay" attribute]
-    expected: TIMEOUT
-
   [Feature policy "autoplay" can be enabled in same-origin iframe using allow="autoplay" attribute]
     expected: TIMEOUT