Issue #2736 - Part 8: Re-work <video> and <audio> src attribute.

Use subject principal as triggering principal in <video>/<audio> "src"
attribute. We deviate from Mozilla here because we do not worry
about content isolation principals in Page Info.
This commit is contained in:
Moonchild 2025-04-29 21:28:50 +02:00 • committed by roytam1
commit b6bdce6f98
3 changed files with 13 additions and 4 deletions

View file

@ -3734,6 +3734,9 @@ HTMLMediaElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
if (aNameSpaceID == kNameSpaceID_None) { if (aNameSpaceID == kNameSpaceID_None) {
if (aName == nsGkAtoms::src) { if (aName == nsGkAtoms::src) {
mSrcMediaSource = nullptr; mSrcMediaSource = nullptr;
mSrcAttrTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal(
this, aValue ? aValue->GetStringValue() : EmptyString(),
aMaybeScriptedPrincipal);
if (aValue) { if (aValue) {
nsString srcStr = aValue->GetStringValue(); nsString srcStr = aValue->GetStringValue();
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;

View file

@ -410,10 +410,13 @@ public:
MediaError* GetError() const; MediaError* GetError() const;
// XPCOM GetSrc() is OK void GetSrc(nsString& aSrc, nsIPrincipal&)
void SetSrc(const nsAString& aSrc, ErrorResult& aRv)
{ {
SetHTMLAttr(nsGkAtoms::src, aSrc, aRv); GetSrc(aSrc); // XPCOM
}
void SetSrc(const nsAString& aSrc, nsIPrincipal& aTriggeringPrincipal, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::src, aSrc, aTriggeringPrincipal, aRv);
} }
// XPCOM GetCurrentSrc() is OK // XPCOM GetCurrentSrc() is OK
@ -1326,6 +1329,9 @@ protected:
// set in the src attribute. // set in the src attribute.
RefPtr<DOMMediaStream> mSrcAttrStream; RefPtr<DOMMediaStream> mSrcAttrStream;
// Holds the triggering principal for the src attribute.
nsCOMPtr<nsIPrincipal> mSrcAttrTriggeringPrincipal;
// Holds a reference to the DOM wrapper for the MediaStream that we're // Holds a reference to the DOM wrapper for the MediaStream that we're
// actually playing. // actually playing.
// At most one of mDecoder and mSrcStream can be non-null. // At most one of mDecoder and mSrcStream can be non-null.

View file

@ -17,7 +17,7 @@ interface HTMLMediaElement : HTMLElement {
readonly attribute MediaError? error; readonly attribute MediaError? error;
// network state // network state
[CEReactions, SetterThrows] [CEReactions, NeedsSubjectPrincipal, SetterThrows]
attribute DOMString src; attribute DOMString src;
readonly attribute DOMString currentSrc; readonly attribute DOMString currentSrc;