Merge remote-tracking branch 'origin/tracking' into custom

This commit is contained in:
roytam1 2025-05-14 14:36:05 +08:00
commit e72f8a3a81
140 changed files with 1117 additions and 466 deletions

View file

@ -386,7 +386,9 @@ HTMLAnchorElement::BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
nsresult
HTMLAnchorElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
if (aNamespaceID == kNameSpaceID_None) {
if (aName == nsGkAtoms::href) {
@ -398,7 +400,8 @@ HTMLAnchorElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
}
return nsGenericHTMLElement::AfterSetAttr(aNamespaceID, aName,
aValue, aOldValue, aNotify);
aValue, aOldValue,
aSubjectPrincipal, aNotify);
}
EventStates

View file

@ -71,6 +71,7 @@ public:
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override;

View file

@ -142,7 +142,9 @@ HTMLAreaElement::UnbindFromTree(bool aDeep, bool aNullParent)
nsresult
HTMLAreaElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
if (aNamespaceID == kNameSpaceID_None) {
// This must happen after the attribute is set. We will need the updated
@ -155,7 +157,7 @@ HTMLAreaElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
}
return nsGenericHTMLElement::AfterSetAttr(aNamespaceID, aName, aValue,
aOldValue, aNotify);
aOldValue, aSubjectPrincipal, aNotify);
}
#define IMPL_URI_PART(_part) \

View file

@ -178,6 +178,7 @@ protected:
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
RefPtr<nsDOMTokenList > mRelList;

View file

@ -438,7 +438,9 @@ HTMLButtonElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
nsresult
HTMLButtonElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
if (aNameSpaceID == kNameSpaceID_None) {
if (aName == nsGkAtoms::type) {
@ -454,7 +456,7 @@ HTMLButtonElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
return nsGenericHTMLFormElementWithState::AfterSetAttr(aNameSpaceID, aName,
aValue, aOldValue,
aNotify);
aSubjectPrincipal, aNotify);
}
NS_IMETHODIMP

View file

@ -88,6 +88,7 @@ public:
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
virtual bool ParseAttribute(int32_t aNamespaceID,
nsIAtom* aAttribute,

View file

@ -443,12 +443,14 @@ NS_IMPL_BOOL_ATTR(HTMLCanvasElement, MozOpaque, moz_opaque)
nsresult
HTMLCanvasElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
AfterMaybeChangeAttr(aNamespaceID, aName, aNotify);
return nsGenericHTMLElement::AfterSetAttr(aNamespaceID, aName, aValue,
aOldValue, aNotify);
aOldValue, aSubjectPrincipal, aNotify);
}
nsresult

View file

@ -361,6 +361,7 @@ protected:
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValueOrString& aValue,

View file

@ -83,7 +83,9 @@ HTMLFieldSetElement::GetEventTargetParent(EventChainPreVisitor& aVisitor)
nsresult
HTMLFieldSetElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::disabled &&
nsINode::GetFirstChild()) {
@ -100,7 +102,8 @@ HTMLFieldSetElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
return nsGenericHTMLFormElement::AfterSetAttr(aNameSpaceID, aName,
aValue, aOldValue, aNotify);
aValue, aOldValue,
aSubjectPrincipal, aNotify);
}
// nsIDOMHTMLFieldSetElement

View file

@ -44,6 +44,7 @@ public:
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
virtual nsresult InsertChildAt(nsIContent* aChild, uint32_t aIndex,

View file

@ -218,7 +218,9 @@ HTMLFormElement::BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
nsresult
HTMLFormElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
if (aName == nsGkAtoms::novalidate && aNameSpaceID == kNameSpaceID_None) {
// Update all form elements states because they might be [no longer]
@ -235,7 +237,7 @@ HTMLFormElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
aOldValue, aNotify);
aOldValue, aSubjectPrincipal, aNotify);
}
NS_IMPL_STRING_ATTR(HTMLFormElement, AcceptCharset, acceptcharset)

View file

@ -110,6 +110,7 @@ public:
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
/**

View file

@ -82,10 +82,13 @@ public:
SetHTMLAttr(nsGkAtoms::scrolling, aScrolling, aError);
}
// The XPCOM GetSrc is OK for us
void SetSrc(const nsAString& aSrc, ErrorResult& aError)
void GetSrc(nsString& aSrc, nsIPrincipal&)
{
SetAttrHelper(nsGkAtoms::src, aSrc);
GetURIAttr(nsGkAtoms::src, nullptr, aSrc);
}
void SetSrc(const nsAString& aSrc, nsIPrincipal& aTriggeringPrincipal, ErrorResult& aError)
{
SetHTMLAttr(nsGkAtoms::src, aSrc, aTriggeringPrincipal, aError);
}
using nsGenericHTMLFrameElement::GetContentDocument;

View file

@ -183,7 +183,9 @@ HTMLIFrameElement::GetAttributeMappingFunction() const
nsresult
HTMLIFrameElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify)
{
AfterMaybeChangeAttr(aNameSpaceID, aName, aNotify);
@ -197,8 +199,10 @@ HTMLIFrameElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
}
}
return nsGenericHTMLFrameElement::AfterSetAttr(aNameSpaceID, aName, aValue,
aOldValue, aNotify);
return nsGenericHTMLFrameElement::AfterSetAttr(aNameSpaceID, aName,
aValue, aOldValue,
aMaybeScriptedPrincipal,
aNotify);
}
nsresult

View file

@ -48,10 +48,13 @@ public:
uint32_t GetSandboxFlags();
// Web IDL binding methods
// The XPCOM GetSrc is fine for our purposes
void SetSrc(const nsAString& aSrc, ErrorResult& aError)
void GetSrc(nsString& aSrc, nsIPrincipal&) const
{
SetHTMLAttr(nsGkAtoms::src, aSrc, aError);
GetURIAttr(nsGkAtoms::src, nullptr, aSrc);
}
void SetSrc(const nsAString& aSrc, nsIPrincipal& aTriggeringPrincipal, ErrorResult& aError)
{
SetHTMLAttr(nsGkAtoms::src, aSrc, aTriggeringPrincipal, aError);
}
void GetSrcdoc(DOMString& aSrcdoc)
{
@ -184,6 +187,7 @@ protected:
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify) override;
virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValueOrString& aValue,

View file

@ -109,7 +109,6 @@ private:
HTMLImageElement::HTMLImageElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
: nsGenericHTMLElement(aNodeInfo)
, mForm(nullptr)
, mForceReload(false)
, mInDocResponsiveContent(false)
, mCurrentDensity(1.0)
{
@ -370,10 +369,6 @@ HTMLImageElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValueOrString* aValue,
bool aNotify)
{
if (aValue) {
BeforeMaybeChangeAttr(aNameSpaceID, aName, *aValue, aNotify);
}
if (aNameSpaceID == kNameSpaceID_None && mForm &&
(aName == nsGkAtoms::name || aName == nsGkAtoms::id)) {
// remove the image from the hashtable as needed
@ -393,10 +388,15 @@ HTMLImageElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
nsresult
HTMLImageElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify)
{
nsAttrValueOrString attrVal(aValue);
if (aValue) {
AfterMaybeChangeAttr(aNameSpaceID, aName, aNotify);
AfterMaybeChangeAttr(aNameSpaceID, aName, attrVal, aOldValue, true,
aMaybeScriptedPrincipal, aNotify);
}
if (aNameSpaceID == kNameSpaceID_None && mForm &&
@ -413,8 +413,6 @@ HTMLImageElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
// parser or some such place; we'll get bound after all the attributes have
// been set, so we'll do the image load from BindToTree.
nsAttrValueOrString attrVal(aValue);
if (aName == nsGkAtoms::src &&
aNameSpaceID == kNameSpaceID_None &&
!aValue) {
@ -432,6 +430,7 @@ HTMLImageElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
} else if (aName == nsGkAtoms::srcset &&
aNameSpaceID == kNameSpaceID_None) {
mSrcsetTriggeringPrincipal = aMaybeScriptedPrincipal;
PictureSourceSrcsetChanged(this, attrVal.String(), aNotify);
} else if (aName == nsGkAtoms::sizes &&
aNameSpaceID == kNameSpaceID_None) {
@ -439,7 +438,9 @@ HTMLImageElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
aValue, aOldValue, aNotify);
aValue, aOldValue,
aMaybeScriptedPrincipal,
aNotify);
}
nsresult
@ -447,18 +448,21 @@ HTMLImageElement::OnAttrSetButNotChanged(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValueOrString& aValue,
bool aNotify)
{
BeforeMaybeChangeAttr(aNamespaceID, aName, aValue, aNotify);
AfterMaybeChangeAttr(aNamespaceID, aName, aNotify);
AfterMaybeChangeAttr(aNamespaceID, aName, aValue, nullptr, false, nullptr, aNotify);
return nsGenericHTMLElement::OnAttrSetButNotChanged(aNamespaceID, aName,
aValue, aNotify);
}
void
HTMLImageElement::BeforeMaybeChangeAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValueOrString& aValue,
bool aNotify)
HTMLImageElement::AfterMaybeChangeAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValueOrString& aValue,
const nsAttrValue* aOldValue,
bool aValueMaybeChanged,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify)
{
bool forceReload = false;
// We need to force our image to reload. This must be done here, not in
// AfterSetAttr or BeforeSetAttr, because we want to do it even if the attr is
// being set to its existing value, which is normally optimized away as a
@ -469,16 +473,16 @@ HTMLImageElement::BeforeMaybeChangeAttr(int32_t aNamespaceID, nsIAtom* aName,
// spec.
//
// Both cases handle unsetting src in AfterSetAttr
//
// Much of this should probably happen in AfterMaybeChangeAttr.
// See Bug 1370705
if (aNamespaceID == kNameSpaceID_None &&
aName == nsGkAtoms::src) {
mSrcTriggeringPrincipal =
nsContentUtils::GetAttrTriggeringPrincipal(this, aValue.String(), aMaybeScriptedPrincipal);
if (InResponsiveMode()) {
if (mResponsiveSelector &&
mResponsiveSelector->Content() == this) {
mResponsiveSelector->SetDefaultSource(aValue.String());
mResponsiveSelector->SetDefaultSource(aValue.String(), mSrcTriggeringPrincipal);
}
QueueImageLoadTask(true);
} else if (aNotify && OwnerDoc()->IsCurrentActiveDocument()) {
@ -492,52 +496,46 @@ HTMLImageElement::BeforeMaybeChangeAttr(int32_t aNamespaceID, nsIAtom* aName,
mNewRequestsWillNeedAnimationReset = true;
// Force image loading here, so that we'll try to load the image from
// network if it's set to be not cacheable... If we change things so that
// the state gets in Element's attr-setting happen around this
// LoadImage call, we could start passing false instead of aNotify
// here.
LoadImage(aValue.String(), true, aNotify, eImageLoadType_Normal);
// network if it's set to be not cacheable.
// Potentially, false could be passed here rather than aNotify since
// UpdateState will be called by SetAttrAndNotify, but there are two
// obstacles to this: 1) LoadImage will end up calling
// UpdateState(aNotify), and we do not want it to call UpdateState(false)
// when aNotify is true, and 2) When this function is called by
// OnAttrSetButNotChanged, SetAttrAndNotify will not subsequently call
// UpdateState.
LoadImage(aValue.String(), true, aNotify, eImageLoadType_Normal, mSrcTriggeringPrincipal);
mNewRequestsWillNeedAnimationReset = false;
}
} else if (aNamespaceID == kNameSpaceID_None &&
aName == nsGkAtoms::crossorigin &&
aNotify) {
nsAttrValue attrValue;
ParseCORSValue(aValue.String(), attrValue);
if (GetCORSMode() != AttrValueToCORSMode(&attrValue)) {
if (aValueMaybeChanged && GetCORSMode() != AttrValueToCORSMode(aOldValue)) {
// Force a new load of the image with the new cross origin policy.
mForceReload = true;
forceReload = true;
}
} else if (aName == nsGkAtoms::referrerpolicy &&
aNamespaceID == kNameSpaceID_None &&
aNotify) {
ReferrerPolicy referrerPolicy = AttributeReferrerPolicyFromString(aValue.String());
ReferrerPolicy referrerPolicy = GetImageReferrerPolicy();
if (!InResponsiveMode() &&
referrerPolicy != RP_Unset &&
referrerPolicy != GetImageReferrerPolicy()) {
aValueMaybeChanged &&
referrerPolicy != ReferrerPolicyFromAttr(aOldValue)) {
// XXX: Bug 1076583 - We still use the older synchronous algorithm
// Because referrerPolicy is not treated as relevant mutations, setting
// the attribute will neither trigger a reload nor update the referrer
// policy of the loading channel (whether it has previously completed or
// not). Force a new load of the image with the new referrerpolicy.
mForceReload = true;
forceReload = true;
}
}
return;
}
void
HTMLImageElement::AfterMaybeChangeAttr(int32_t aNamespaceID, nsIAtom* aName,
bool aNotify)
{
// Because we load image synchronously in non-responsive-mode, we need to do
// reload after the attribute has been set if the reload is triggerred by
// cross origin changing.
if (mForceReload) {
mForceReload = false;
if (forceReload) {
if (InResponsiveMode()) {
// per spec, full selection runs when this changes, even though
// it doesn't directly affect the source selection
@ -549,8 +547,6 @@ HTMLImageElement::AfterMaybeChangeAttr(int32_t aNamespaceID, nsIAtom* aName,
ForceReload(aNotify);
}
}
return;
}
nsresult
@ -1005,13 +1001,14 @@ HTMLImageElement::LoadSelectedImage(bool aForce, bool aNotify, bool aAlwaysLoad)
double currentDensity = 1.0; // default to 1.0 for the src attribute case
if (mResponsiveSelector) {
nsCOMPtr<nsIURI> url = mResponsiveSelector->GetSelectedImageURL();
nsCOMPtr<nsIPrincipal> triggeringPrincipal = mResponsiveSelector->GetSelectedImageTriggeringPrincipal();
selectedSource = url;
currentDensity = mResponsiveSelector->GetSelectedImageDensity();
if (!aAlwaysLoad && SelectedSourceMatchesLast(selectedSource, currentDensity)) {
return NS_OK;
}
if (url) {
rv = LoadImage(url, aForce, aNotify, eImageLoadType_Imageset);
rv = LoadImage(url, aForce, aNotify, eImageLoadType_Imageset, triggeringPrincipal);
}
} else {
nsAutoString src;
@ -1032,7 +1029,8 @@ HTMLImageElement::LoadSelectedImage(bool aForce, bool aNotify, bool aAlwaysLoad)
// valid responsive sources from either, per spec.
rv = LoadImage(src, aForce, aNotify,
HaveSrcsetOrInPicture() ? eImageLoadType_Imageset
: eImageLoadType_Normal);
: eImageLoadType_Normal,
mSrcTriggeringPrincipal);
}
}
mLastSelectedSource = selectedSource;
@ -1059,7 +1057,13 @@ HTMLImageElement::PictureSourceSrcsetChanged(nsIContent *aSourceNode,
if (aSourceNode == currentSrc) {
// We're currently using this node as our responsive selector
// source.
mResponsiveSelector->SetCandidatesFromSourceSet(aNewValue);
nsCOMPtr<nsIPrincipal> principal;
if (aSourceNode == this) {
principal = mSrcsetTriggeringPrincipal;
} else if (auto* source = HTMLSourceElement::FromContent(aSourceNode)) {
principal = source->GetSrcsetTriggeringPrincipal();
}
mResponsiveSelector->SetCandidatesFromSourceSet(aNewValue, principal);
}
if (!mInDocResponsiveContent && IsInComposedDoc()) {
@ -1244,15 +1248,20 @@ HTMLImageElement::SourceElementMatches(nsIContent* aSourceNode)
bool
HTMLImageElement::TryCreateResponsiveSelector(nsIContent *aSourceNode)
{
nsCOMPtr<nsIPrincipal> principal;
// Skip if this is not a <source> with matching media query
bool isSourceTag = aSourceNode->IsHTMLElement(nsGkAtoms::source);
if (isSourceTag) {
if (!SourceElementMatches(aSourceNode)) {
return false;
}
auto* source = HTMLSourceElement::FromContent(aSourceNode);
principal = source->GetSrcsetTriggeringPrincipal();
} else if (aSourceNode->IsHTMLElement(nsGkAtoms::img)) {
// Otherwise this is the <img> tag itself
MOZ_ASSERT(aSourceNode == this);
principal = mSrcsetTriggeringPrincipal;
}
// Skip if has no srcset or an empty srcset
@ -1268,8 +1277,8 @@ HTMLImageElement::TryCreateResponsiveSelector(nsIContent *aSourceNode)
// Try to parse
RefPtr<ResponsiveImageSelector> sel = new ResponsiveImageSelector(aSourceNode);
if (!sel->SetCandidatesFromSourceSet(srcset)) {
// No possible candidates, don't need to bother parsing sizes
if (!sel->SetCandidatesFromSourceSet(srcset, principal)) {
// No possible candidates; no need to bother parsing sizes
return false;
}
@ -1282,7 +1291,7 @@ HTMLImageElement::TryCreateResponsiveSelector(nsIContent *aSourceNode)
MOZ_ASSERT(aSourceNode == this);
nsAutoString src;
if (GetAttr(kNameSpaceID_None, nsGkAtoms::src, src) && !src.IsEmpty()) {
sel->SetDefaultSource(src);
sel->SetDefaultSource(src, mSrcTriggeringPrincipal);
}
}

View file

@ -137,13 +137,21 @@ public:
{
SetHTMLAttr(nsGkAtoms::alt, aAlt, aError);
}
void SetSrc(const nsAString& aSrc, ErrorResult& aError)
void GetSrc(nsAString& aSrc, nsIPrincipal&)
{
SetHTMLAttr(nsGkAtoms::src, aSrc, aError);
GetURIAttr(nsGkAtoms::src, nullptr, aSrc);
}
void SetSrcset(const nsAString& aSrcset, ErrorResult& aError)
void SetSrc(const nsAString& aSrc, nsIPrincipal& aTriggeringPrincipal, ErrorResult& aError)
{
SetHTMLAttr(nsGkAtoms::srcset, aSrcset, aError);
SetHTMLAttr(nsGkAtoms::src, aSrc, aTriggeringPrincipal, aError);
}
void GetSrcset(nsAString& aSrcset, nsIPrincipal&)
{
GetHTMLAttr(nsGkAtoms::srcset, aSrcset);
}
void SetSrcset(const nsAString& aSrcset, nsIPrincipal& aTriggeringPrincipal, ErrorResult& aError)
{
SetHTMLAttr(nsGkAtoms::srcset, aSrcset, aTriggeringPrincipal, aError);
}
void GetCrossOrigin(nsAString& aResult)
{
@ -337,6 +345,7 @@ protected:
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify) override;
virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsIAtom* aName,
@ -364,30 +373,25 @@ private:
* @param aName the localname of the attribute being set
* @param aValue the value it's being set to represented as either a string or
* a parsed nsAttrValue.
* @param aNotify Whether we plan to notify document observers.
*/
void BeforeMaybeChangeAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValueOrString& aValue,
bool aNotify);
/**
* This function is called by AfterSetAttr and OnAttrSetButNotChanged.
* It will not be called if the value is being unset.
*
* @param aNamespaceID the namespace of the attr being set
* @param aName the localname of the attribute being set
* @param aOldValue the value previously set. Will be null if no value was
* previously set. This value should only be used when
* aValueMaybeChanged is true; when aValueMaybeChanged is false,
* aOldValue should be considered unreliable.
* @param aValueMaybeChanged will be false when this function is called from
* OnAttrSetButNotChanged to indicate that the value was not changed.
* @param aNotify Whether we plan to notify document observers.
*/
void AfterMaybeChangeAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValueOrString& aValue,
const nsAttrValue* aOldValue,
bool aValueMaybeChanged,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify);
/**
* Used by BeforeMaybeChangeAttr and AfterMaybeChangeAttr to keep track of
* whether a reload needs to be forced after an attribute change that is
* currently in progress.
*/
bool mForceReload;
bool mInDocResponsiveContent;
RefPtr<ImageLoadTask> mPendingImageLoadTask;
nsCOMPtr<nsIPrincipal> mSrcTriggeringPrincipal;
nsCOMPtr<nsIPrincipal> mSrcsetTriggeringPrincipal;
// Last URL that was attempted to load by this element.
nsCOMPtr<nsIURI> mLastSelectedSource;

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) {
@ -1285,7 +1277,9 @@ HTMLInputElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
nsresult
HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
if (aNameSpaceID == kNameSpaceID_None) {
//
@ -1301,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
@ -1436,6 +1445,7 @@ HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
return nsGenericHTMLFormElementWithState::AfterSetAttr(aNameSpaceID, aName,
aValue, aOldValue,
aSubjectPrincipal,
aNotify);
}
@ -4958,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);
}
@ -5162,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
@ -966,6 +969,7 @@ protected:
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
virtual void ResultForDialogSubmit(nsAString& aResult) override;
@ -1558,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

@ -357,7 +357,9 @@ HTMLLinkElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
nsresult
HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
// It's safe to call ResetLinkState here because our new attr value has
// already been set or unset. ResetLinkState needs the updated attribute
@ -372,6 +374,12 @@ HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
}
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::href) {
mTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal(
this, aValue ? aValue->GetStringValue() : EmptyString(),
aSubjectPrincipal);
}
if (aValue) {
if (aNameSpaceID == kNameSpaceID_None &&
(aName == nsGkAtoms::href ||
@ -451,7 +459,8 @@ HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
aOldValue, aNotify);
aOldValue, aSubjectPrincipal,
aNotify);
}
nsresult
@ -517,14 +526,20 @@ HTMLLinkElement::GetHrefURI() const
}
already_AddRefed<nsIURI>
HTMLLinkElement::GetStyleSheetURL(bool* aIsInline)
HTMLLinkElement::GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal)
{
*aIsInline = false;
*aTriggeringPrincipal = nullptr;
nsAutoString href;
GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
if (href.IsEmpty()) {
return nullptr;
}
nsCOMPtr<nsIPrincipal> prin = mTriggeringPrincipal;
prin.forget(aTriggeringPrincipal);
nsCOMPtr<nsIURI> uri = Link::GetURI();
return uri.forget();
}

View file

@ -66,6 +66,7 @@ public:
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
virtual bool IsLink(nsIURI** aURI) const override;
virtual already_AddRefed<nsIURI> GetHrefURI() const override;
@ -87,10 +88,14 @@ public:
// WebIDL
bool Disabled() const;
void SetDisabled(bool aDisabled, ErrorResult& aRv);
// XPCOM GetHref is fine.
void SetHref(const nsAString& aHref, ErrorResult& aRv)
void GetHref(nsString& aValue, nsIPrincipal&)
{
SetHTMLAttr(nsGkAtoms::href, aHref, aRv);
GetHref(aValue);
}
void SetHref(const nsAString& aHref, nsIPrincipal& aTriggeringPrincipal, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::href, aHref, aTriggeringPrincipal, aRv);
}
void GetCrossOrigin(nsAString& aResult)
{
@ -188,7 +193,7 @@ protected:
virtual ~HTMLLinkElement();
// nsStyleLinkElement
virtual already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) override;
virtual already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal) override;
virtual void GetStyleSheetInfo(nsAString& aTitle,
nsAString& aType,
nsAString& aMedia,

View file

@ -3713,11 +3713,16 @@ int32_t HTMLMediaElement::TabIndexDefault()
nsresult
HTMLMediaElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify)
{
if (aNameSpaceID == kNameSpaceID_None) {
if (aName == nsGkAtoms::src) {
mSrcMediaSource = nullptr;
mSrcAttrTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal(
this, aValue ? aValue->GetStringValue() : EmptyString(),
aMaybeScriptedPrincipal);
if (aValue) {
nsString srcStr = aValue->GetStringValue();
nsCOMPtr<nsIURI> uri;
@ -3755,7 +3760,9 @@ HTMLMediaElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
aValue, aOldValue, aNotify);
aValue, aOldValue,
aMaybeScriptedPrincipal,
aNotify);
}
nsresult

View file

@ -410,10 +410,13 @@ public:
MediaError* GetError() const;
// XPCOM GetSrc() is OK
void SetSrc(const nsAString& aSrc, ErrorResult& aRv)
void GetSrc(nsString& aSrc, nsIPrincipal&)
{
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
@ -1301,6 +1304,7 @@ protected:
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify) override;
virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValueOrString& aValue,
@ -1325,6 +1329,9 @@ protected:
// set in the src attribute.
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
// actually playing.
// At most one of mDecoder and mSrcStream can be non-null.

View file

@ -389,7 +389,9 @@ HTMLMenuItemElement::GetText(nsAString& aText)
nsresult
HTMLMenuItemElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
if (aNameSpaceID == kNameSpaceID_None) {
if ((aName == nsGkAtoms::radiogroup || aName == nsGkAtoms::type) &&
@ -412,8 +414,10 @@ HTMLMenuItemElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
}
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
aOldValue, aNotify);
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
aValue, aOldValue,
aSubjectPrincipal,
aNotify);
}
void

View file

@ -126,6 +126,7 @@ protected:
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
void WalkRadioGroup(Visitor* aVisitor);

View file

@ -61,7 +61,9 @@ HTMLMetaElement::SetMetaReferrer(nsIDocument* aDocument)
nsresult
HTMLMetaElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
if (aNameSpaceID == kNameSpaceID_None) {
nsIDocument *document = GetUncomposedDoc();
@ -82,8 +84,10 @@ HTMLMetaElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
}
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
aOldValue, aNotify);
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
aValue, aOldValue,
aSubjectPrincipal,
aNotify);
}
nsresult

View file

@ -34,6 +34,7 @@ public:
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
void CreateAndDispatchEvent(nsIDocument* aDoc, const nsAString& aEventName);

View file

@ -299,13 +299,16 @@ HTMLObjectElement::UnbindFromTree(bool aDeep,
nsresult
HTMLObjectElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
nsresult rv = AfterMaybeChangeAttr(aNamespaceID, aName, aNotify);
NS_ENSURE_SUCCESS(rv, rv);
return nsGenericHTMLFormElement::AfterSetAttr(aNamespaceID, aName, aValue,
aOldValue, aNotify);
aOldValue, aSubjectPrincipal,
aNotify);
}
nsresult

View file

@ -245,6 +245,7 @@ public:
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValueOrString& aValue,

View file

@ -106,7 +106,9 @@ HTMLOptGroupElement::RemoveChildAt(uint32_t aIndex, bool aNotify)
nsresult
HTMLOptGroupElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::disabled) {
// All our children <option> have their :disabled state depending on our
@ -121,7 +123,8 @@ HTMLOptGroupElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
aOldValue, aNotify);
aOldValue, aSubjectPrincipal,
aNotify);
}
EventStates

View file

@ -44,6 +44,7 @@ public:
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
virtual nsIDOMNode* AsDOMNode() override { return this; }

View file

@ -244,7 +244,9 @@ HTMLOptionElement::BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
nsresult
HTMLOptionElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
if (aNameSpaceID == kNameSpaceID_None &&
aName == nsGkAtoms::value && Selected()) {
@ -258,7 +260,9 @@ HTMLOptionElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
aValue, aOldValue, aNotify);
aValue, aOldValue,
aSubjectPrincipal,
aNotify);
}
NS_IMETHODIMP

View file

@ -51,6 +51,7 @@ public:
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
void SetSelectedInternal(bool aValue, bool aNotify);

View file

@ -166,9 +166,9 @@ HTMLScriptElement::Defer()
}
void
HTMLScriptElement::SetSrc(const nsAString& aSrc, ErrorResult& rv)
HTMLScriptElement::SetSrc(const nsAString& aSrc, nsIPrincipal& aTriggeringPrincipal, ErrorResult& rv)
{
rv = SetAttrHelper(nsGkAtoms::src, aSrc);
SetHTMLAttr(nsGkAtoms::src, aSrc, aTriggeringPrincipal, rv);
}
void
@ -230,15 +230,24 @@ HTMLScriptElement::SetNoModule(bool aValue, ErrorResult& aRv)
}
nsresult
HTMLScriptElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
HTMLScriptElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify)
{
if (nsGkAtoms::async == aName && kNameSpaceID_None == aNamespaceID) {
if (aName == nsGkAtoms::async && aNameSpaceID == kNameSpaceID_None) {
mForceAsync = false;
}
return nsGenericHTMLElement::AfterSetAttr(aNamespaceID, aName, aValue,
aOldValue, aNotify);
if (aName == nsGkAtoms::src && aNameSpaceID == kNameSpaceID_None) {
mSrcTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal(
this, aValue ? aValue->GetStringValue() : EmptyString(),
aMaybeScriptedPrincipal);
}
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
aValue, aOldValue,
aMaybeScriptedPrincipal,
aNotify);
}
NS_IMETHODIMP

View file

@ -59,6 +59,7 @@ public:
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify) override;
// WebIDL
@ -66,7 +67,11 @@ public:
void SetCharset(const nsAString& aCharset, ErrorResult& rv);
void SetDefer(bool aDefer, ErrorResult& rv);
bool Defer();
void SetSrc(const nsAString& aSrc, ErrorResult& rv);
void GetSrc(nsString& aSrc, nsIPrincipal&)
{
GetSrc(aSrc);
};
void SetSrc(const nsAString& aSrc, nsIPrincipal& aTriggeringPrincipal, ErrorResult& rv);
void SetType(const nsAString& aType, ErrorResult& rv);
void SetHtmlFor(const nsAString& aHtmlFor, ErrorResult& rv);
void SetEvent(const nsAString& aEvent, ErrorResult& rv);

View file

@ -1296,7 +1296,9 @@ HTMLSelectElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
nsresult
HTMLSelectElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
if (aNameSpaceID == kNameSpaceID_None) {
if (aName == nsGkAtoms::disabled) {
@ -1317,6 +1319,7 @@ HTMLSelectElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
return nsGenericHTMLFormElementWithState::AfterSetAttr(aNameSpaceID, aName,
aValue, aOldValue,
aSubjectPrincipal,
aNotify);
}

View file

@ -379,6 +379,7 @@ public:
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
virtual void DoneAddingChildren(bool aHaveNotified) override;

View file

@ -233,7 +233,9 @@ SetBaseTargetUsingFirstBaseWithTarget(nsIDocument* aDocument,
nsresult
HTMLSharedElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
if (aNamespaceID == kNameSpaceID_None) {
if (aName == nsGkAtoms::href) {
@ -256,7 +258,8 @@ HTMLSharedElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
}
}
return nsGenericHTMLElement::AfterSetAttr(aNamespaceID, aName, aValue,
aOldValue, aNotify);
aOldValue, aSubjectPrincipal,
aNotify);
}
nsresult

View file

@ -173,6 +173,7 @@ protected:
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
};

View file

@ -164,6 +164,7 @@ nsresult
HTMLSharedObjectElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
if (aValue) {
@ -172,7 +173,7 @@ HTMLSharedObjectElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
}
return nsGenericHTMLElement::AfterSetAttr(aNamespaceID, aName, aValue,
aOldValue, aNotify);
aOldValue, aSubjectPrincipal, aNotify);
}
nsresult

View file

@ -201,6 +201,7 @@ protected:
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValueOrString& aValue,

View file

@ -102,6 +102,7 @@ nsresult
HTMLSlotElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
@ -119,7 +120,8 @@ HTMLSlotElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
aOldValue, aNotify);
aOldValue, aSubjectPrincipal,
aNotify);
}
/**

View file

@ -38,6 +38,7 @@ public:
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
// WebIDL

View file

@ -98,8 +98,15 @@ HTMLSourceElement::UpdateMediaList(const nsAttrValue* aValue)
nsresult
HTMLSourceElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify)
{
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::srcset) {
mSrcsetTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal(
this, aValue ? aValue->GetStringValue() : EmptyString(),
aMaybeScriptedPrincipal);
}
// If we are associated with a <picture> with a valid <img>, notify it of
// responsive parameter changes
Element *parent = nsINode::GetParentElement();
@ -131,6 +138,9 @@ HTMLSourceElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
} else if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::media) {
UpdateMediaList(aValue);
} else if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::src) {
mSrcTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal(
this, aValue ? aValue->GetStringValue() : EmptyString(),
aMaybeScriptedPrincipal);
mSrcMediaSource = nullptr;
if (aValue) {
nsString srcStr = aValue->GetStringValue();
@ -143,7 +153,9 @@ HTMLSourceElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
aValue, aOldValue, aNotify);
aValue, aOldValue,
aMaybeScriptedPrincipal,
aNotify);
}
nsresult

View file

@ -56,13 +56,22 @@ public:
MediaSource* GetSrcMediaSource() { return mSrcMediaSource; };
// WebIDL
void GetSrc(nsString& aSrc)
void GetSrc(nsString& aSrc, nsIPrincipal&)
{
GetURIAttr(nsGkAtoms::src, nullptr, aSrc);
}
void SetSrc(const nsAString& aSrc, mozilla::ErrorResult& rv)
void SetSrc(const nsAString& aSrc, nsIPrincipal& aTriggeringPrincipal, mozilla::ErrorResult& rv)
{
SetHTMLAttr(nsGkAtoms::src, aSrc, rv);
SetHTMLAttr(nsGkAtoms::src, aSrc, aTriggeringPrincipal, rv);
}
nsIPrincipal* GetSrcTriggeringPrincipal() const
{
return mSrcTriggeringPrincipal;
}
nsIPrincipal* GetSrcsetTriggeringPrincipal() const
{
return mSrcsetTriggeringPrincipal;
}
void GetType(DOMString& aType)
@ -74,13 +83,13 @@ public:
SetHTMLAttr(nsGkAtoms::type, aType, rv);
}
void GetSrcset(DOMString& aSrcset)
void GetSrcset(DOMString& aSrcset, nsIPrincipal&)
{
GetHTMLAttr(nsGkAtoms::srcset, aSrcset);
}
void SetSrcset(const nsAString& aSrcset, mozilla::ErrorResult& rv)
void SetSrcset(const nsAString& aSrcset, nsIPrincipal& aTriggeringPrincipal, mozilla::ErrorResult& rv)
{
SetHTMLAttr(nsGkAtoms::srcset, aSrcset, rv);
SetHTMLAttr(nsGkAtoms::srcset, aSrcset, aTriggeringPrincipal, rv);
}
void GetSizes(DOMString& aSizes)
@ -110,12 +119,19 @@ protected:
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify) override;
private:
RefPtr<nsMediaList> mMediaList;
RefPtr<MediaSource> mSrcMediaSource;
// The triggering principal for the src attribute.
nsCOMPtr<nsIPrincipal> mSrcTriggeringPrincipal;
// The triggering principal for the srcset attribute.
nsCOMPtr<nsIPrincipal> mSrcsetTriggeringPrincipal;
// Generates a new nsMediaList using the given input
void UpdateMediaList(const nsAttrValue* aValue);
};

View file

@ -171,7 +171,9 @@ HTMLStyleElement::UnbindFromTree(bool aDeep, bool aNullParent)
nsresult
HTMLStyleElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
if (aNameSpaceID == kNameSpaceID_None) {
if (aName == nsGkAtoms::title ||
@ -185,7 +187,8 @@ HTMLStyleElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
aOldValue, aNotify);
aOldValue, aSubjectPrincipal,
aNotify);
}
NS_IMETHODIMP
@ -211,9 +214,10 @@ HTMLStyleElement::SetInnerHTML(const nsAString& aInnerHTML,
}
already_AddRefed<nsIURI>
HTMLStyleElement::GetStyleSheetURL(bool* aIsInline)
HTMLStyleElement::GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal)
{
*aIsInline = true;
*aTriggeringPrincipal = nullptr;
return nullptr;
}

View file

@ -48,6 +48,7 @@ public:
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override;
@ -90,7 +91,7 @@ public:
protected:
virtual ~HTMLStyleElement();
already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) override;
already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal) override;
void GetStyleSheetInfo(nsAString& aTitle,
nsAString& aType,
nsAString& aMedia,

View file

@ -1005,13 +1005,16 @@ HTMLTableElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
nsresult
HTMLTableElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
if (aName == nsGkAtoms::cellpadding && aNameSpaceID == kNameSpaceID_None) {
BuildInheritedAttributes();
}
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
aOldValue, aNotify);
aOldValue, aSubjectPrincipal,
aNotify);
}
} // namespace dom

View file

@ -197,6 +197,7 @@ public:
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLTableElement,

View file

@ -1330,7 +1330,9 @@ HTMLTextAreaElement::ContentChanged(nsIContent* aContent)
nsresult
HTMLTextAreaElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify)
{
if (aNameSpaceID == kNameSpaceID_None) {
if (aName == nsGkAtoms::required || aName == nsGkAtoms::disabled ||
@ -1349,7 +1351,8 @@ HTMLTextAreaElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
return nsGenericHTMLFormElementWithState::AfterSetAttr(aNameSpaceID, aName, aValue,
aOldValue, aNotify);
aOldValue, aSubjectPrincipal,
aNotify);
}
nsresult

View file

@ -358,6 +358,7 @@ protected:
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom *aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
/**

View file

@ -97,11 +97,14 @@ ImageListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
if (secMan) {
secMan->GetChannelResultPrincipal(channel, getter_AddRefs(channelPrincipal));
}
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
int16_t decision = nsIContentPolicy::ACCEPT;
nsresult rv = NS_CheckContentProcessPolicy(nsIContentPolicy::TYPE_INTERNAL_IMAGE,
channelURI,
channelPrincipal,
loadInfo ? loadInfo->TriggeringPrincipal() : nullptr,
domWindow->GetFrameElementInternal(),
mimeType,
nullptr,

View file

@ -692,7 +692,9 @@ nsGenericHTMLElement::BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
nsresult
nsGenericHTMLElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify)
{
if (aNamespaceID == kNameSpaceID_None) {
if (IsEventAttributeName(aName) && aValue) {
@ -782,7 +784,9 @@ nsGenericHTMLElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
}
return nsGenericHTMLElementBase::AfterSetAttr(aNamespaceID, aName,
aValue, aOldValue, aNotify);
aValue, aOldValue,
aMaybeScriptedPrincipal,
aNotify);
}
EventListenerManager*
@ -2042,7 +2046,9 @@ nsGenericHTMLFormElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
nsresult
nsGenericHTMLFormElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify)
{
if (aNameSpaceID == kNameSpaceID_None) {
// add the control to the hashtable as needed
@ -2091,7 +2097,9 @@ nsGenericHTMLFormElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
aValue, aOldValue, aNotify);
aValue, aOldValue,
aMaybeScriptedPrincipal,
aNotify);
}
nsresult

View file

@ -914,6 +914,7 @@ protected:
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify) override;
virtual mozilla::EventListenerManager*
@ -959,6 +960,10 @@ protected:
{
mozilla::dom::Element::SetAttr(aName, aValue, aError);
}
void SetHTMLAttr(nsIAtom* aName, const nsAString& aValue, nsIPrincipal& aTriggeringPrincipal, mozilla::ErrorResult& aError)
{
mozilla::dom::Element::SetAttr(aName, aValue, aTriggeringPrincipal, aError);
}
void UnsetHTMLAttr(nsIAtom* aName, mozilla::ErrorResult& aError)
{
mozilla::dom::Element::UnsetAttr(aName, aError);
@ -1270,6 +1275,7 @@ protected:
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify) override;
/**

View file

@ -337,13 +337,15 @@ PrincipalAllowsBrowserFrame(nsIPrincipal* aPrincipal)
/* virtual */ nsresult
nsGenericHTMLFrameElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify)
{
if (aValue) {
nsAttrValueOrString value(aValue);
AfterMaybeChangeAttr(aNameSpaceID, aName, &value, aNotify);
AfterMaybeChangeAttr(aNameSpaceID, aName, &value, aMaybeScriptedPrincipal, aNotify);
} else {
AfterMaybeChangeAttr(aNameSpaceID, aName, nullptr, aNotify);
AfterMaybeChangeAttr(aNameSpaceID, aName, nullptr, aMaybeScriptedPrincipal, aNotify);
}
if (aNameSpaceID == kNameSpaceID_None) {
@ -376,7 +378,8 @@ nsGenericHTMLFrameElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
}
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
aOldValue, aNotify);
aOldValue, aMaybeScriptedPrincipal,
aNotify);
}
nsresult
@ -385,20 +388,23 @@ nsGenericHTMLFrameElement::OnAttrSetButNotChanged(int32_t aNamespaceID,
const nsAttrValueOrString& aValue,
bool aNotify)
{
AfterMaybeChangeAttr(aNamespaceID, aName, &aValue, aNotify);
AfterMaybeChangeAttr(aNamespaceID, aName, &aValue, nullptr, aNotify);
return nsGenericHTMLElement::OnAttrSetButNotChanged(aNamespaceID, aName,
aValue, aNotify);
}
void
nsGenericHTMLFrameElement::AfterMaybeChangeAttr(int32_t aNamespaceID,
nsGenericHTMLFrameElement::AfterMaybeChangeAttr(int32_t aNameSpaceID,
nsIAtom* aName,
const nsAttrValueOrString* aValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify)
{
if (aNamespaceID == kNameSpaceID_None) {
if (aNameSpaceID == kNameSpaceID_None) {
if (aName == nsGkAtoms::src) {
mSrcTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal(
this, aValue ? aValue->String() : EmptyString(), aMaybeScriptedPrincipal);
if (aValue && (!IsHTMLElement(nsGkAtoms::iframe) ||
!HasAttr(kNameSpaceID_None, nsGkAtoms::srcdoc))) {
// Don't propagate error here. The attribute was successfully set,

View file

@ -18,6 +18,10 @@
class nsXULElement;
#define NS_GENERICHTMLFRAMEELEMENT_IID \
{ 0x8190db72, 0xdab0, 0x4d72, \
{ 0x94, 0x26, 0x87, 0x5f, 0x5a, 0x8a, 0x2a, 0xe5 } }
/**
* A helper class for frame elements
*/
@ -45,6 +49,8 @@ public:
NS_DECL_NSIDOMMOZBROWSERFRAME
NS_DECL_NSIMOZBROWSERFRAME
NS_DECLARE_STATIC_IID_ACCESSOR(NS_GENERICHTMLFRAMEELEMENT_IID)
// nsIContent
virtual bool IsHTMLFocusable(bool aWithMouse, bool *aIsFocusable, int32_t *aTabIndex) override;
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
@ -86,6 +92,11 @@ public:
*/
static int32_t MapScrollingAttribute(const nsAttrValue* aValue);
nsIPrincipal* GetSrcTriggeringPrincipal() const
{
return mSrcTriggeringPrincipal;
}
protected:
virtual ~nsGenericHTMLFrameElement();
@ -100,6 +111,7 @@ protected:
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValueOrString& aValue,
@ -108,6 +120,8 @@ protected:
RefPtr<nsFrameLoader> mFrameLoader;
nsCOMPtr<nsPIDOMWindowOuter> mOpenerWindow;
nsCOMPtr<nsIPrincipal> mSrcTriggeringPrincipal;
/**
* True when the element is created by the parser using the
* NS_FROM_PARSER_NETWORK flag.
@ -138,7 +152,12 @@ private:
* @param aNotify Whether we plan to notify document observers.
*/
void AfterMaybeChangeAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValueOrString* aValue, bool aNotify);
const nsAttrValueOrString* aValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify);
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsGenericHTMLFrameElement,
NS_GENERICHTMLFRAMEELEMENT_IID)
#endif // nsGenericHTMLFrameElement_h