Bug 1318576. Remove entries from a form's past names map when an element is removed from the form, even if that element doesn't have a name or id anymore. r=baku
This commit is contained in:
@@ -1346,6 +1346,8 @@ nsresult
|
||||
HTMLFormElement::RemoveElement(nsGenericHTMLFormElement* aChild,
|
||||
bool aUpdateValidity)
|
||||
{
|
||||
RemoveElementFromPastNamesMap(aChild);
|
||||
|
||||
//
|
||||
// Remove it from the radio group if it's a radio button
|
||||
//
|
||||
@@ -1496,23 +1498,8 @@ HTMLFormElement::RemoveElementFromTableInternal(
|
||||
|
||||
nsresult
|
||||
HTMLFormElement::RemoveElementFromTable(nsGenericHTMLFormElement* aElement,
|
||||
const nsAString& aName,
|
||||
RemoveElementReason aRemoveReason)
|
||||
const nsAString& aName)
|
||||
{
|
||||
// If the element is being removed from the form, we have to remove it from
|
||||
// the past names map.
|
||||
if (aRemoveReason == ElementRemoved) {
|
||||
uint32_t oldCount = mPastNameLookupTable.Count();
|
||||
for (auto iter = mPastNameLookupTable.Iter(); !iter.Done(); iter.Next()) {
|
||||
if (static_cast<void*>(aElement) == iter.Data()) {
|
||||
iter.Remove();
|
||||
}
|
||||
}
|
||||
if (oldCount != mPastNameLookupTable.Count()) {
|
||||
++mExpandoAndGeneration.generation;
|
||||
}
|
||||
}
|
||||
|
||||
return mControls->RemoveElementFromTable(aElement, aName);
|
||||
}
|
||||
|
||||
@@ -2537,6 +2524,8 @@ HTMLFormElement::AddImageElementToTable(HTMLImageElement* aChild,
|
||||
nsresult
|
||||
HTMLFormElement::RemoveImageElement(HTMLImageElement* aChild)
|
||||
{
|
||||
RemoveElementFromPastNamesMap(aChild);
|
||||
|
||||
size_t index = mImageElements.IndexOf(aChild);
|
||||
NS_ENSURE_STATE(index != mImageElements.NoIndex);
|
||||
|
||||
@@ -2546,19 +2535,8 @@ HTMLFormElement::RemoveImageElement(HTMLImageElement* aChild)
|
||||
|
||||
nsresult
|
||||
HTMLFormElement::RemoveImageElementFromTable(HTMLImageElement* aElement,
|
||||
const nsAString& aName,
|
||||
RemoveElementReason aRemoveReason)
|
||||
const nsAString& aName)
|
||||
{
|
||||
// If the element is being removed from the form, we have to remove it from
|
||||
// the past names map.
|
||||
if (aRemoveReason == ElementRemoved) {
|
||||
for (auto iter = mPastNameLookupTable.Iter(); !iter.Done(); iter.Next()) {
|
||||
if (static_cast<void*>(aElement) == iter.Data()) {
|
||||
iter.Remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return RemoveElementFromTableInternal(mImageNameLookupTable, aElement, aName);
|
||||
}
|
||||
|
||||
@@ -2571,7 +2549,28 @@ HTMLFormElement::AddToPastNamesMap(const nsAString& aName,
|
||||
// previous entry with the same name, if any.
|
||||
nsCOMPtr<nsIContent> node = do_QueryInterface(aChild);
|
||||
if (node) {
|
||||
mPastNameLookupTable.Put(aName, aChild);
|
||||
mPastNameLookupTable.Put(aName, node);
|
||||
node->SetFlags(MAY_BE_IN_PAST_NAMES_MAP);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
HTMLFormElement::RemoveElementFromPastNamesMap(Element* aElement)
|
||||
{
|
||||
if (!aElement->HasFlag(MAY_BE_IN_PAST_NAMES_MAP)) {
|
||||
return;
|
||||
}
|
||||
|
||||
aElement->UnsetFlags(MAY_BE_IN_PAST_NAMES_MAP);
|
||||
|
||||
uint32_t oldCount = mPastNameLookupTable.Count();
|
||||
for (auto iter = mPastNameLookupTable.Iter(); !iter.Done(); iter.Next()) {
|
||||
if (aElement == iter.Data()) {
|
||||
iter.Remove();
|
||||
}
|
||||
}
|
||||
if (oldCount != mPastNameLookupTable.Count()) {
|
||||
++mExpandoAndGeneration.generation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user