From 7b93c4f163df4b28e47dc7237b4156e863034cc5 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Tue, 2 Oct 2018 11:54:58 +0200 Subject: [PATCH] Bug 1495302 - FeaturePolicy: midi, r=qdot --- dom/midi/MIDIAccessManager.cpp | 7 +++++++ dom/security/featurepolicy/FeaturePolicyUtils.cpp | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/dom/midi/MIDIAccessManager.cpp b/dom/midi/MIDIAccessManager.cpp index e518aed37d40..b0f9de4ca842 100644 --- a/dom/midi/MIDIAccessManager.cpp +++ b/dom/midi/MIDIAccessManager.cpp @@ -8,6 +8,7 @@ #include "mozilla/dom/MIDIAccess.h" #include "mozilla/dom/MIDIManagerChild.h" #include "mozilla/dom/MIDIPermissionRequest.h" +#include "mozilla/dom/FeaturePolicyUtils.h" #include "mozilla/dom/Promise.h" #include "nsIGlobalObject.h" #include "mozilla/ClearOnShutdown.h" @@ -70,6 +71,12 @@ MIDIAccessManager::RequestMIDIAccess(nsPIDOMWindowInner* aWindow, aRv.Throw(NS_ERROR_FAILURE); return nullptr; } + + if (!FeaturePolicyUtils::IsFeatureAllowed(doc, NS_LITERAL_STRING("midi"))) { + aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); + return nullptr; + } + nsCOMPtr permRunnable = new MIDIPermissionRequest(aWindow, p, aOptions); aRv = NS_DispatchToMainThread(permRunnable); if (NS_WARN_IF(aRv.Failed())) { diff --git a/dom/security/featurepolicy/FeaturePolicyUtils.cpp b/dom/security/featurepolicy/FeaturePolicyUtils.cpp index b6d2a5f0637c..ebcdfdc2c37c 100644 --- a/dom/security/featurepolicy/FeaturePolicyUtils.cpp +++ b/dom/security/featurepolicy/FeaturePolicyUtils.cpp @@ -45,7 +45,6 @@ static FeatureMap sSupportedFeatures[] = { { "magnetometer", FeatureMap::eSelf }, // TODO: not supported yet!!! { "microphone", FeatureMap::eSelf }, - // TODO: not supported yet!!! { "midi", FeatureMap::eSelf }, { "payment", FeatureMap::eSelf }, // TODO: not supported yet!!!