Bug 1365092 - Move side effects of SetAttr, UnsetAttr, and ParseAttribute functions to BeforeSetAttr and AfterSetAttr r=bz

This is necessary to facilitate the transition to cloning attributes instead of reparsing them.

MozReview-Commit-ID: Gyd1tD6ldly
This commit is contained in:
Kirk Steuber
2017-06-07 10:28:20 -07:00
parent 8f7a03110f
commit 6684b17554
32 changed files with 604 additions and 670 deletions

View File

@@ -230,52 +230,33 @@ SetBaseTargetUsingFirstBaseWithTarget(nsIDocument* aDocument,
}
nsresult
HTMLSharedElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
nsIAtom* aPrefix, const nsAString& aValue,
bool aNotify)
HTMLSharedElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue, bool aNotify)
{
nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix,
aValue, aNotify);
NS_ENSURE_SUCCESS(rv, rv);
// If the href attribute of a <base> tag is changing, we may need to update
// the document's base URI, which will cause all the links on the page to be
// re-resolved given the new base. If the target attribute is changing, we
// similarly need to change the base target.
if (mNodeInfo->Equals(nsGkAtoms::base) &&
aNameSpaceID == kNameSpaceID_None &&
IsInUncomposedDoc()) {
if (aNamespaceID == kNameSpaceID_None) {
if (aName == nsGkAtoms::href) {
SetBaseURIUsingFirstBaseWithHref(GetUncomposedDoc(), this);
// If the href attribute of a <base> tag is changing, we may need to
// update the document's base URI, which will cause all the links on the
// page to be re-resolved given the new base.
// If the href is being unset (aValue is null), we will need to find a new
// <base>.
if (mNodeInfo->Equals(nsGkAtoms::base) && IsInUncomposedDoc()) {
SetBaseURIUsingFirstBaseWithHref(GetUncomposedDoc(),
aValue ? this : nullptr);
}
} else if (aName == nsGkAtoms::target) {
SetBaseTargetUsingFirstBaseWithTarget(GetUncomposedDoc(), this);
// The target attribute is in pretty much the same situation as the href
// attribute, above.
if (mNodeInfo->Equals(nsGkAtoms::base) && IsInUncomposedDoc()) {
SetBaseTargetUsingFirstBaseWithTarget(GetUncomposedDoc(),
aValue ? this : nullptr);
}
}
}
return NS_OK;
}
nsresult
HTMLSharedElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aName,
bool aNotify)
{
nsresult rv = nsGenericHTMLElement::UnsetAttr(aNameSpaceID, aName, aNotify);
NS_ENSURE_SUCCESS(rv, rv);
// If we're the first <base> with an href and our href attribute is being
// unset, then we're no longer the first <base> with an href, and we need to
// find the new one. Similar for target.
if (mNodeInfo->Equals(nsGkAtoms::base) &&
aNameSpaceID == kNameSpaceID_None &&
IsInUncomposedDoc()) {
if (aName == nsGkAtoms::href) {
SetBaseURIUsingFirstBaseWithHref(GetUncomposedDoc(), nullptr);
} else if (aName == nsGkAtoms::target) {
SetBaseTargetUsingFirstBaseWithTarget(GetUncomposedDoc(), nullptr);
}
}
return NS_OK;
return nsGenericHTMLElement::AfterSetAttr(aNamespaceID, aName, aValue,
aOldValue, aNotify);
}
nsresult