Bug 1495302 - FeaturePolicy: midi, r=qdot
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 02 Oct 2018 11:54:58 +0200
changeset 494899 f7d61c61aa340208b4dc64f6b71fac2683750461
parent 494898 cdd5b0bde9c1cc29213e1fb82ce3688799cb8af8
child 494900 902c00aa8bbeec7bf28df9785b20062f8cba278b
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1495302
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 1495302 - FeaturePolicy: midi, r=qdot
dom/midi/MIDIAccessManager.cpp
dom/security/featurepolicy/FeaturePolicyUtils.cpp
--- a/dom/midi/MIDIAccessManager.cpp
+++ b/dom/midi/MIDIAccessManager.cpp
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/MIDIAccessManager.h"
 #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"
 #include "mozilla/ipc/PBackgroundChild.h"
 #include "mozilla/ipc/BackgroundChild.h"
 #include "mozilla/Preferences.h"
 
 using namespace mozilla::ipc;
@@ -65,16 +66,22 @@ MIDIAccessManager::RequestMIDIAccess(nsP
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
   nsCOMPtr<nsIDocument> doc = aWindow->GetDoc();
   if (NS_WARN_IF(!doc)) {
     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<nsIRunnable> permRunnable = new MIDIPermissionRequest(aWindow, p, aOptions);
   aRv = NS_DispatchToMainThread(permRunnable);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
   return p.forget();
 }
 
--- a/dom/security/featurepolicy/FeaturePolicyUtils.cpp
+++ b/dom/security/featurepolicy/FeaturePolicyUtils.cpp
@@ -40,17 +40,16 @@ static FeatureMap sSupportedFeatures[] =
   // TODO: not supported yet!!!
   { "geolocation", FeatureMap::eSelf  },
   // TODO: not supported yet!!!
   { "gyroscope", FeatureMap::eSelf  },
   // TODO: not supported yet!!!
   { "magnetometer", FeatureMap::eSelf  },
   // TODO: not supported yet!!!
   { "microphone", FeatureMap::eSelf  },
-  // TODO: not supported yet!!!
   { "midi", FeatureMap::eSelf  },
   { "payment", FeatureMap::eSelf  },
   // TODO: not supported yet!!!
   { "picture-in-picture", FeatureMap::eAll  },
   // TODO: not supported yet!!!
   { "speaker", FeatureMap::eSelf  },
   // TODO: not supported yet!!!
   { "usb", FeatureMap::eSelf  },