mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-02 22:37:50 +00:00
Backed out changeset 1ea661280632 (bug 1757218) for causing mochitest failures on test_midi_permission_gated.html
This commit is contained in:
parent
24a8666518
commit
8adcbead72
@ -3798,8 +3798,8 @@ bool nsContentUtils::IsExactSitePermDeny(nsIPrincipal* aPrincipal,
|
||||
true);
|
||||
}
|
||||
|
||||
bool nsContentUtils::HasSitePerm(nsIPrincipal* aPrincipal,
|
||||
const nsACString& aType) {
|
||||
bool nsContentUtils::HasExactSitePerm(nsIPrincipal* aPrincipal,
|
||||
const nsACString& aType) {
|
||||
if (!aPrincipal) {
|
||||
return false;
|
||||
}
|
||||
@ -3809,7 +3809,8 @@ bool nsContentUtils::HasSitePerm(nsIPrincipal* aPrincipal,
|
||||
NS_ENSURE_TRUE(permMgr, false);
|
||||
|
||||
uint32_t perm;
|
||||
nsresult rv = permMgr->TestPermissionFromPrincipal(aPrincipal, aType, &perm);
|
||||
nsresult rv =
|
||||
permMgr->TestExactPermissionFromPrincipal(aPrincipal, aType, &perm);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
return perm != nsIPermissionManager::UNKNOWN_ACTION;
|
||||
|
@ -899,7 +899,8 @@ class nsContentUtils {
|
||||
const nsACString& aType);
|
||||
|
||||
// Returns true if the pref exists and is not UNKNOWN_ACTION.
|
||||
static bool HasSitePerm(nsIPrincipal* aPrincipal, const nsACString& aType);
|
||||
static bool HasExactSitePerm(nsIPrincipal* aPrincipal,
|
||||
const nsACString& aType);
|
||||
|
||||
// Returns true if aDoc1 and aDoc2 have equal NodePrincipal()s.
|
||||
static bool HaveEqualPrincipals(Document* aDoc1, Document* aDoc2);
|
||||
|
@ -49,9 +49,9 @@ NS_IMETHODIMP
|
||||
MIDIPermissionRequest::GetTypes(nsIArray** aTypes) {
|
||||
NS_ENSURE_ARG_POINTER(aTypes);
|
||||
nsTArray<nsString> options;
|
||||
// NB: We always request midi-sysex, and the base |midi| permission is unused.
|
||||
// This could be cleaned up at some point.
|
||||
options.AppendElement(u"sysex"_ns);
|
||||
if (mNeedsSysex) {
|
||||
options.AppendElement(u"sysex"_ns);
|
||||
}
|
||||
return nsContentPermissionUtils::CreatePermissionArray(mType, options,
|
||||
aTypes);
|
||||
}
|
||||
@ -84,36 +84,27 @@ MIDIPermissionRequest::Run() {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Both the spec and our original implementation of WebMIDI have two
|
||||
// conceptual permission levels: with and without sysex functionality.
|
||||
// However, our current implementation just has one level, and requires the
|
||||
// more-powerful |midi-sysex| permission irrespective of the mode requested in
|
||||
// requestMIDIAccess.
|
||||
constexpr auto kPermName = "midi-sysex"_ns;
|
||||
|
||||
// First, check for an explicit allow/deny. Note that we want to support
|
||||
// granting a permission on the base domain and then using it on a subdomain,
|
||||
// which is why we use the non-"Exact" variants of these APIs. See bug
|
||||
// 1757218.
|
||||
if (nsContentUtils::IsSitePermAllow(mPrincipal, kPermName)) {
|
||||
// If we already have sysex perms, allow.
|
||||
if (nsContentUtils::IsExactSitePermAllow(mPrincipal, "midi-sysex"_ns)) {
|
||||
Allow(JS::UndefinedHandleValue);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (nsContentUtils::IsSitePermDeny(mPrincipal, kPermName)) {
|
||||
// If midi is addon-gated, the we only pass through to ask permission if
|
||||
// the permission already exists. This allows for the user possibly changing
|
||||
// the permission to ask, or deny and having the existing UX properly handle
|
||||
// the outcome.
|
||||
if (
|
||||
#ifndef RELEASE_OR_BETA
|
||||
StaticPrefs::dom_webmidi_gated() &&
|
||||
#endif
|
||||
!nsContentUtils::HasExactSitePerm(mPrincipal, "midi"_ns) &&
|
||||
!nsContentUtils::HasExactSitePerm(mPrincipal, "midi-sysex"_ns)) {
|
||||
Cancel();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// If the add-on is not installed, auto-deny.
|
||||
if (!nsContentUtils::HasSitePerm(mPrincipal, kPermName)) {
|
||||
Cancel();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// We can only get here if the add-on is installed, but the user has
|
||||
// subsequently changed the permission from ALLOW to ASK. In that unusual
|
||||
// case, throw up a prompt.
|
||||
// If we have no perms, or only have midi and are asking for sysex, pop dialog
|
||||
if (NS_FAILED(nsContentPermissionUtils::AskPermission(this, mWindow))) {
|
||||
Cancel();
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -1 +0,0 @@
|
||||
<!DOCTYPE html><html><body></body></html>
|
@ -1,7 +1,6 @@
|
||||
[DEFAULT]
|
||||
support-files =
|
||||
MIDITestUtils.js
|
||||
file_empty.html
|
||||
scheme = https
|
||||
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
</head>
|
||||
|
||||
<body onload="runTests()">
|
||||
<iframe id="ifr" src="https://www.example.com/tests/dom/midi/tests/file_empty.html"></iframe>
|
||||
<script class="testbody" type="application/javascript">
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
@ -14,6 +13,14 @@
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["dom.webmidi.enabled", true]],
|
||||
});
|
||||
ok(
|
||||
await SpecialPowers.testPermission(
|
||||
"midi",
|
||||
SpecialPowers.Services.perms.UNKNOWN_ACTION,
|
||||
document
|
||||
),
|
||||
"midi value should have UNKNOWN permission"
|
||||
);
|
||||
ok(
|
||||
await SpecialPowers.testPermission(
|
||||
"midi-sysex",
|
||||
@ -22,55 +29,33 @@
|
||||
),
|
||||
"midi-sysex value should have UNKNOWN permission"
|
||||
);
|
||||
ok(
|
||||
await SpecialPowers.testPermission(
|
||||
"midi-sysex",
|
||||
SpecialPowers.Services.perms.UNKNOWN_ACTION,
|
||||
SpecialPowers.wrap($("ifr")).contentDocument
|
||||
),
|
||||
"permission should also not be set for iframe"
|
||||
);
|
||||
|
||||
// Gated permission should fail without addon installed.
|
||||
for (let sysex of [false, true]) {
|
||||
try {
|
||||
await navigator.requestMIDIAccess({ sysex });
|
||||
ok(false, "MIDI Access Request gate failed");
|
||||
} catch (ex) {
|
||||
ok(true, "MIDI Access Request denied by default");
|
||||
}
|
||||
try {
|
||||
await navigator.requestMIDIAccess({ sysex: false });
|
||||
ok(false, "MIDI Access Request gate failed");
|
||||
} catch (ex) {
|
||||
ok(true, "MIDI Access Request denied by default");
|
||||
}
|
||||
|
||||
// When an addon is installed, the permission is inserted. Test
|
||||
// that the request succeeds after we insert the permission.
|
||||
await SpecialPowers.addPermission(
|
||||
"midi-sysex",
|
||||
"midi",
|
||||
SpecialPowers.Services.perms.ALLOW_ACTION,
|
||||
document
|
||||
);
|
||||
|
||||
// Gated permission should allow access after addon inserted permission.
|
||||
for (let sysex of [false, true]) {
|
||||
try {
|
||||
await navigator.requestMIDIAccess({ sysex });
|
||||
ok(true, "MIDI Access Request allowed");
|
||||
} catch (ex) {
|
||||
ok(false, "MIDI Access Request failed");
|
||||
}
|
||||
try {
|
||||
await navigator.requestMIDIAccess({ sysex: false });
|
||||
ok(true, "MIDI Access Request allowed");
|
||||
} catch (ex) {
|
||||
ok(false, "MIDI Access Request failed");
|
||||
}
|
||||
|
||||
// Gated permission should also apply to subdomains.
|
||||
for (let sysex of [false, true]) {
|
||||
try {
|
||||
await SpecialPowers.wrap($("ifr")).contentWindow.navigator.requestMIDIAccess({ sysex });
|
||||
ok(true, "MIDI Access Request allowed for subdomain");
|
||||
} catch (ex) {
|
||||
ok(false, "MIDI Access Request failed for subdomain");
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the permission.
|
||||
await SpecialPowers.removePermission("midi-sysex", document);
|
||||
// Remove the permission
|
||||
await SpecialPowers.removePermission("midi", document);
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user