Bug 1811442 - Automatically reject requests for MIDI access when no implementation is present r=bholley

Differential Revision: https://phabricator.services.mozilla.com/D167452
This commit is contained in:
Gabriele Svelto 2023-01-23 13:41:47 +00:00
parent 8ee1c95687
commit ca827af9eb

View file

@ -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<Promise> 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;