diff --git a/dom/midi/MIDIAccessManager.cpp b/dom/midi/MIDIAccessManager.cpp index 31c5ad6e4a0d..c0556f1ffd47 100644 --- a/dom/midi/MIDIAccessManager.cpp +++ b/dom/midi/MIDIAccessManager.cpp @@ -16,7 +16,7 @@ #include "mozilla/ipc/Endpoint.h" #include "mozilla/ipc/PBackgroundChild.h" #include "mozilla/ipc/BackgroundChild.h" -#include "mozilla/Preferences.h" +#include "mozilla/StaticPrefs_midi.h" using namespace mozilla::ipc; @@ -59,6 +59,18 @@ already_AddRefed MIDIAccessManager::RequestMIDIAccess( return nullptr; } +#ifndef MOZ_WEBMIDI_MIDIR_IMPL + if (!StaticPrefs::midi_testing()) { + // If we don't have a MIDI implementation and testing is disabled we can't + // allow accessing WebMIDI. However we don't want to return something + // different from a normal rejection because we don't want websites to use + // the error as a way to fingerprint users, so we throw a security error + // as if the request had been rejected by the user. + aRv.ThrowSecurityError("Access not allowed"); + return nullptr; + } +#endif + if (!FeaturePolicyUtils::IsFeatureAllowed(doc, u"midi"_ns)) { aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); return nullptr;