Skip to content

Commit

Permalink
Bug 1925952 - Implement attribute waitingforkey on audio/video elemen…
Browse files Browse the repository at this point in the history
…ts. r=smaug

IDL attribute was added in bug 1304247 but we are missing corresponding
content attribute: https://w3c.github.io/encrypted-media/#attributes-3

Differential Revision: https://phabricator.services.mozilla.com/D226298
  • Loading branch information
fred-wang committed Oct 22, 2024
1 parent 14391a2 commit 2b4cba4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions dom/base/nsContentUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ enum EventNameType {
EventNameType_SVGSVG = 0x0008, // the svg element
EventNameType_SMIL = 0x0010, // smil elements
EventNameType_HTMLBodyOrFramesetOnly = 0x0020,
EventNameType_HTMLMedia = 0x0040,

EventNameType_HTMLXUL = 0x0003,
EventNameType_All = 0xFFFF
Expand Down
2 changes: 2 additions & 0 deletions dom/events/EventNameList.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ EVENT(dragstart, eDragStart, EventNameType_HTMLXUL, eDragEventClass)
EVENT(drop, eDrop, EventNameType_HTMLXUL, eDragEventClass)
EVENT(durationchange, eDurationChange, EventNameType_HTML, eBasicEventClass)
EVENT(emptied, eEmptied, EventNameType_HTML, eBasicEventClass)
EVENT(encrypted, eEncrypted, EventNameType_HTMLMedia, eBasicEventClass)
EVENT(ended, eEnded, EventNameType_HTML, eBasicEventClass)
EVENT(formdata, eFormData, EventNameType_HTML, eBasicEventClass)
EVENT(fullscreenchange, eFullscreenChange, EventNameType_HTML, eBasicEventClass)
Expand Down Expand Up @@ -254,6 +255,7 @@ EVENT(timeupdate, eTimeUpdate, EventNameType_HTML, eBasicEventClass)
EVENT(toggle, eToggle, EventNameType_HTML, eBasicEventClass)
EVENT(volumechange, eVolumeChange, EventNameType_HTML, eBasicEventClass)
EVENT(waiting, eWaiting, EventNameType_HTML, eBasicEventClass)
EVENT(waitingforkey, eWaitingForKey, EventNameType_HTMLMedia, eBasicEventClass)
EVENT(wheel, eWheel, EventNameType_All, eWheelEventClass)
EVENT(copy, eCopy, EventNameType_HTMLXUL | EventNameType_SVGGraphic,
eClipboardEventClass)
Expand Down
4 changes: 2 additions & 2 deletions dom/html/HTMLMediaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7340,8 +7340,8 @@ void HTMLMediaElement::DispatchEncrypted(const nsTArray<uint8_t>& aInitData,
}

bool HTMLMediaElement::IsEventAttributeNameInternal(nsAtom* aName) {
return aName == nsGkAtoms::onencrypted ||
nsGenericHTMLElement::IsEventAttributeNameInternal(aName);
return nsContentUtils::IsEventAttributeName(
aName, EventNameType_HTML | EventNameType_HTMLMedia);
}

void HTMLMediaElement::NotifyWaitingForKey() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test setting EventHandler attributes</title>
<link rel="help" href="https://w3c.github.io/encrypted-media/#attributes-3">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<body>
<audio id="testElement"
onencrypted="window.onencryptedHandlerSetFromParserWasFired()"
onwaitingforkey="window.onwaitingforkeyHandlerSetFromParserWasFired()">
</audio>
<script>
["encrypted", "waitingforkey"].forEach(eventName => {
promise_test(() => {
return new Promise(resolve => {
window[`on${eventName}HandlerSetFromParserWasFired`] = resolve;
testElement.dispatchEvent(new Event(eventName));
});
}, `on${eventName} handler set from parser`);

promise_test(() => {
const el = document.createElement("audio");
el.setAttribute(`on${eventName}`, `window.on${eventName}HandlerSetViaSetAttributeWasFired()`);
document.body.append(el);

return new Promise(resolve => {
window[`on${eventName}HandlerSetViaSetAttributeWasFired`] = resolve;
el.dispatchEvent(new Event(eventName));
});
}, `on${eventName} handler set via setAttribute()`);
});
</script>
4 changes: 4 additions & 0 deletions widget/EventMessageList.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ NS_EVENT_MESSAGE(eToggle)
NS_EVENT_MESSAGE(eClose)
NS_EVENT_MESSAGE(eCancel)

// Media element events.
NS_EVENT_MESSAGE(eEncrypted)
NS_EVENT_MESSAGE(eWaitingForKey)

NS_EVENT_MESSAGE(eScrollend)

#ifdef UNDEF_NS_EVENT_MESSAGE_FIRST_LAST
Expand Down

0 comments on commit 2b4cba4

Please sign in to comment.