Issue #2736 - Part 11: Re-work <input> src attribute.

Use subject principal as triggering principal in <input> "src" attribute.
This commit is contained in:
Moonchild 2025-05-04 15:36:51 +02:00 committed by roytam1
commit dde21838de
3 changed files with 29 additions and 14 deletions

View file

@ -1255,14 +1255,6 @@ HTMLInputElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
mType == NS_FORM_INPUT_RADIO &&
(mForm || mDoneCreating)) {
WillRemoveFromRadioGroup();
} else if (aNotify && aName == nsGkAtoms::src &&
mType == NS_FORM_INPUT_IMAGE) {
if (aValue) {
LoadImage(aValue->String(), true, aNotify, eImageLoadType_Normal);
} else {
// Null value means the attr got unset; drop the image
CancelImageRequests(aNotify);
}
} else if (aNotify && aName == nsGkAtoms::disabled) {
mDisabledChanged = true;
} else if (mType == NS_FORM_INPUT_RADIO && aName == nsGkAtoms::required) {
@ -1303,6 +1295,21 @@ HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
UpdateValueMissingValidityStateForRadio(false);
}
if (aName == nsGkAtoms::src) {
mSrcTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal(
this, aValue ? aValue->GetStringValue() : EmptyString(),
aSubjectPrincipal);
if (aNotify && mType == NS_FORM_INPUT_IMAGE) {
if (aValue) {
LoadImage(aValue->GetStringValue(), true, aNotify, eImageLoadType_Normal,
mSrcTriggeringPrincipal);
} else {
// Null value means the attr got unset; drop the image
CancelImageRequests(aNotify);
}
}
}
// If @value is changed and BF_VALUE_CHANGED is false, @value is the value
// of the element so, if the value of the element is different than @value,
// we have to re-set it. This is only the case when GetValueMode() returns
@ -4961,7 +4968,7 @@ HTMLInputElement::MaybeLoadImage()
nsAutoString uri;
if (mType == NS_FORM_INPUT_IMAGE &&
GetAttr(kNameSpaceID_None, nsGkAtoms::src, uri) &&
(NS_FAILED(LoadImage(uri, false, true, eImageLoadType_Normal)) ||
(NS_FAILED(LoadImage(uri, false, true, eImageLoadType_Normal, mSrcTriggeringPrincipal)) ||
!LoadingEnabled())) {
CancelImageRequests(true);
}
@ -5165,7 +5172,7 @@ HTMLInputElement::HandleTypeChange(uint8_t aNewType, bool aNotify)
// whether we have an image to load;
nsAutoString src;
if (GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) {
LoadImage(src, false, aNotify, eImageLoadType_Normal);
LoadImage(src, false, aNotify, eImageLoadType_Normal, mSrcTriggeringPrincipal);
}
}

View file

@ -638,10 +638,13 @@ public:
SetUnsignedIntAttr(nsGkAtoms::size, aValue, DEFAULT_COLS, aRv);
}
// XPCOM GetSrc() is OK
void SetSrc(const nsAString& aValue, ErrorResult& aRv)
void GetSrc(nsAString& aValue, nsIPrincipal&)
{
SetHTMLAttr(nsGkAtoms::src, aValue, aRv);
GetURIAttr(nsGkAtoms::src, nullptr, aValue);
}
void SetSrc(const nsAString& aValue, nsIPrincipal& aTriggeringPrincipal, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::src, aValue, aTriggeringPrincipal, aRv);
}
// XPCOM GetStep() is OK
@ -1559,6 +1562,11 @@ protected:
*/
nsTextEditorState::SelectionProperties mSelectionProperties;
/**
* The triggering principal for the src attribute.
*/
nsCOMPtr<nsIPrincipal> mSrcTriggeringPrincipal;
// Step scale factor values, for input types that have one.
static const Decimal kStepScaleFactorDate;
static const Decimal kStepScaleFactorNumberRange;

View file

@ -81,7 +81,7 @@ interface HTMLInputElement : HTMLElement {
attribute boolean required;
[CEReactions, Pure, SetterThrows]
attribute unsigned long size;
[CEReactions, Pure, SetterThrows]
[CEReactions, Pure, NeedsSubjectPrincipal, SetterThrows]
attribute DOMString src;
[CEReactions, Pure, SetterThrows]
attribute DOMString step;