mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1778959 - Don't expose requestMIDIAccess on file scheme. r=bholley.
This is done by adding Navigator::HasMidiSupport that we reference in the Navigator.webidl `Func` extented attribute for `requestMIDIAccess`. A test case is added to browser_midi_permission_gated.js to ensure this works as expected. Differential Revision: https://phabricator.services.mozilla.com/D157321
This commit is contained in:
parent
3d1ac4e0b7
commit
5d8ed083ca
@ -1894,6 +1894,16 @@ bool Navigator::HasShareSupport(JSContext* cx, JSObject* obj) {
|
||||
#endif
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool Navigator::HasMidiSupport(JSContext* cx, JSObject* obj) {
|
||||
nsIPrincipal* principal = nsContentUtils::SubjectPrincipal(cx);
|
||||
|
||||
// Enable on secure contexts but exclude file schemes.
|
||||
return StaticPrefs::dom_webmidi_enabled() &&
|
||||
IsSecureContextOrObjectIsFromSecureContext(cx, obj) &&
|
||||
!principal->SchemeIs("file");
|
||||
}
|
||||
|
||||
/* static */
|
||||
already_AddRefed<nsPIDOMWindowInner> Navigator::GetWindowFromGlobal(
|
||||
JSObject* aGlobal) {
|
||||
|
@ -231,6 +231,8 @@ class Navigator final : public nsISupports, public nsWrapperCache {
|
||||
JSObject* /* unused */);
|
||||
static bool HasShareSupport(JSContext* /* unused */, JSObject* /* unused */);
|
||||
|
||||
static bool HasMidiSupport(JSContext* /* unused */, JSObject* /* unused */);
|
||||
|
||||
nsPIDOMWindowInner* GetParentObject() const { return GetWindow(); }
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* cx,
|
||||
|
5
dom/midi/tests/blank.html
Normal file
5
dom/midi/tests/blank.html
Normal file
@ -0,0 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf8">
|
||||
<html>
|
||||
<body></body>
|
||||
</html>
|
@ -6,6 +6,9 @@ prefs =
|
||||
media.navigator.permission.disabled=true
|
||||
|
||||
[browser_midi_permission_gated.js]
|
||||
support-files =
|
||||
blank.html
|
||||
|
||||
[browser_stable_midi_port_ids.js]
|
||||
run-if = (os != 'android')
|
||||
support-files =
|
||||
|
@ -420,6 +420,29 @@ add_task(async function testRequestMIDIAccessLocalhost() {
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function testDisabledRequestMIDIAccessFile() {
|
||||
let dir = getChromeDir(getResolvedURI(gTestPath));
|
||||
dir.append("blank.html");
|
||||
const fileSchemeTestUri = Services.io.newFileURI(dir).spec;
|
||||
|
||||
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, fileSchemeTestUri);
|
||||
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
|
||||
|
||||
info("Check that requestMIDIAccess isn't set on navigator on file scheme");
|
||||
const isRequestMIDIAccessDefined = await SpecialPowers.spawn(
|
||||
gBrowser.selectedBrowser,
|
||||
[],
|
||||
() => {
|
||||
return "requestMIDIAccess" in content.wrappedJSObject.navigator;
|
||||
}
|
||||
);
|
||||
is(
|
||||
isRequestMIDIAccessDefined,
|
||||
false,
|
||||
"navigator.requestMIDIAccess is not defined on file scheme"
|
||||
);
|
||||
});
|
||||
|
||||
async function waitForInstallDialog(id = "addon-webext-permissions") {
|
||||
let panel = await waitForNotification(id);
|
||||
return panel.childNodes[0];
|
||||
|
@ -240,7 +240,7 @@ partial interface Navigator {
|
||||
|
||||
// http://webaudio.github.io/web-midi-api/#requestmidiaccess
|
||||
partial interface Navigator {
|
||||
[SecureContext, NewObject, Pref="dom.webmidi.enabled"]
|
||||
[NewObject, Func="Navigator::HasMidiSupport"]
|
||||
Promise<MIDIAccess> requestMIDIAccess(optional MIDIOptions options = {});
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user