Skip to content

Commit 21a2174

Browse files
committed
Bug 2007071 - Align MIDI errors with the web-midi-api spec. Deprecated SecurityError and InvalidAccessError in favor of NotAllowedError r?gsvelto,bholley
= `InvalidAccessError` replaced by `NotAllowedError`: The change in spec: [WebAudio/web-midi-api@3795f22](WebAudio/web-midi-api@3795f22) According PR: [WebAudio/web-midi-api#278](WebAudio/web-midi-api#278) MDN update PR: [mdn/content#42334](mdn/content#42334) == Affected APIs 1. `.send` method of output MIDI ports 2. `.open` method of MIDI ports = `SecurityError` replaced by `NotAllowedError`: The change in spec: [WebAudio/web-midi-api@b7806b8](WebAudio/web-midi-api@b7806b8) According PR: [WebAudio/web-midi-api#267](WebAudio/web-midi-api#267) MDN update PR: [mdn/content#41956](mdn/content#41956) == Affected APIs 1. `navigator.requestMIDIAccess` method
1 parent c746416 commit 21a2174

6 files changed

Lines changed: 11 additions & 11 deletions

dom/midi/MIDIAccessManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ already_AddRefed<Promise> MIDIAccessManager::RequestMIDIAccess(
6767
// different from a normal rejection because we don't want websites to use
6868
// the error as a way to fingerprint users, so we throw a security error
6969
// as if the request had been rejected by the user.
70-
aRv.ThrowSecurityError("Access not allowed");
70+
aRv.ThrowNotAllowedError("Access not allowed");
7171
return nullptr;
7272
}
7373
#endif
7474

7575
if (!FeaturePolicyUtils::IsFeatureAllowed(doc, u"midi"_ns)) {
76-
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
76+
aRv.Throw(NS_ERROR_DOM_NOT_ALLOWED_ERR);
7777
return nullptr;
7878
}
7979

dom/midi/MIDIOutput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void MIDIOutput::Send(const Sequence<uint8_t>& aData,
8787
if (!SysexEnabled()) {
8888
for (auto& msg : msgArray) {
8989
if (MIDIUtils::IsSysexMessage(msg)) {
90-
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
90+
aRv.Throw(NS_ERROR_DOM_NOT_ALLOWED_ERR);
9191
return;
9292
}
9393
}

dom/midi/MIDIPermissionRequest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ MIDIPermissionRequest::GetTypes(nsIArray** aTypes) {
6868
NS_IMETHODIMP
6969
MIDIPermissionRequest::Cancel() {
7070
mCancelTimer = nullptr;
71-
mPromise->MaybeRejectWithSecurityError(
71+
mPromise->MaybeRejectWithNotAllowedError(
7272
"WebMIDI requires a site permission add-on to activate");
7373
return NS_OK;
7474
}

dom/midi/MIDIPort.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void MIDIPort::FireStateChangeEvent() {
196196
}
197197
} else if (Port()->ConnectionState() == MIDIPortConnectionState::Closed) {
198198
if (mOpeningPromise) {
199-
mOpeningPromise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR);
199+
mOpeningPromise->MaybeReject(NS_ERROR_DOM_NOT_ALLOWED_ERR);
200200
mOpeningPromise = nullptr;
201201
}
202202
if (mClosingPromise) {

dom/midi/tests/browser_midi_permission_gated.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ add_task(async function testRequestMIDIAccess() {
131131
);
132132
is(
133133
rejectionMessage,
134-
"SecurityError: WebMIDI requires a site permission add-on to activate"
134+
"NotAllowedError: WebMIDI requires a site permission add-on to activate"
135135
);
136136

137137
assertSitePermissionInstallTelemetryEvents(["site_warning", "cancelled"]);
@@ -185,7 +185,7 @@ add_task(async function testRequestMIDIAccess() {
185185
);
186186
is(
187187
rejectionMessage,
188-
"SecurityError: WebMIDI requires a site permission add-on to activate"
188+
"NotAllowedError: WebMIDI requires a site permission add-on to activate"
189189
);
190190

191191
assertSitePermissionInstallTelemetryEvents([
@@ -386,7 +386,7 @@ add_task(async function testRequestMIDIAccess() {
386386
return errorMessage;
387387
}
388388
);
389-
is(rejectionMessage, "SecurityError", "requestMIDIAccess was rejected");
389+
is(rejectionMessage, "NotAllowedError", "requestMIDIAccess was rejected");
390390

391391
info("Request midi-sysex access again");
392392
let denyIntervalStart = performance.now();
@@ -407,7 +407,7 @@ add_task(async function testRequestMIDIAccess() {
407407
);
408408
is(
409409
rejectionMessage,
410-
"SecurityError",
410+
"NotAllowedError",
411411
"requestMIDIAccess was rejected without user prompt"
412412
);
413413
let denyIntervalElapsed = performance.now() - denyIntervalStart;
@@ -560,7 +560,7 @@ add_task(async function testIframeRequestMIDIAccess() {
560560

561561
is(
562562
rejectionMessage,
563-
"SecurityError",
563+
"NotAllowedError",
564564
"requestMIDIAccess from the remote iframe was rejected"
565565
);
566566

dom/midi/tests/test_midi_device_explicit_open_close.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
await output_opened.open();
7070
ok(false, "Should've failed to open port!");
7171
} catch(err) {
72-
is(err.name, "InvalidAccessError", "error name " + err.name + " should be InvalidAccessError");
72+
is(err.name, "NotAllowedError", "error name " + err.name + " should be NotAllowedError");
7373
ok(output_opened.connection == "closed", "connection registered as closed");
7474
ok(true, "Port not opened, test succeeded");
7575
} finally {

0 commit comments

Comments
 (0)