Bug 1514474 - Implement FeaturePolicy.features(), r=ckerschb

Differential Revision: https://phabricator.services.mozilla.com/D35802

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-07-08 02:03:18 +00:00
Родитель e87202df68
Коммит f9e570ba21
5 изменённых файлов: 56 добавлений и 0 удалений

Просмотреть файл

@ -148,6 +148,16 @@ bool FeaturePolicy::AllowsFeatureInternal(const nsAString& aFeatureName,
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(

Просмотреть файл

@ -113,6 +113,8 @@ class FeaturePolicy final : public nsISupports, public nsWrapperCache {
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,

Просмотреть файл

@ -8,3 +8,4 @@ support-files =
test_parser.html^headers^
[test_parser.html]
[test_featureList.html]

Просмотреть файл

@ -0,0 +1,42 @@
<!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",
"display-capture",
"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>

Просмотреть файл

@ -10,6 +10,7 @@
[NoInterfaceObject]
interface FeaturePolicy {
boolean allowsFeature(DOMString feature, optional DOMString origin);
sequence<DOMString> features();
sequence<DOMString> allowedFeatures();
sequence<DOMString> getAllowlistForFeature(DOMString feature);
};