diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index 5761b12e68..374fb14ef1 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -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); } } diff --git a/dom/html/HTMLInputElement.h b/dom/html/HTMLInputElement.h index 45464f638b..e46be30ea7 100644 --- a/dom/html/HTMLInputElement.h +++ b/dom/html/HTMLInputElement.h @@ -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 mSrcTriggeringPrincipal; + // Step scale factor values, for input types that have one. static const Decimal kStepScaleFactorDate; static const Decimal kStepScaleFactorNumberRange; diff --git a/dom/webidl/HTMLInputElement.webidl b/dom/webidl/HTMLInputElement.webidl index 528689bbd1..1eefaea61e 100644 --- a/dom/webidl/HTMLInputElement.webidl +++ b/dom/webidl/HTMLInputElement.webidl @@ -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;