This source file includes following definitions.
- add
- remove
- elementWasDestroyed
- removeCommon
- elementDidFinishParsingChildren
- moveToEnd
- takeUpgradeCandidatesFor
#include "config.h"
#include "core/dom/custom/CustomElementUpgradeCandidateMap.h"
#include "core/dom/Element.h"
namespace WebCore {
CustomElementUpgradeCandidateMap::~CustomElementUpgradeCandidateMap()
{
UpgradeCandidateMap::const_iterator::Keys end = m_upgradeCandidates.end().keys();
for (UpgradeCandidateMap::const_iterator::Keys it = m_upgradeCandidates.begin().keys(); it != end; ++it)
unobserve(*it);
}
void CustomElementUpgradeCandidateMap::add(const CustomElementDescriptor& descriptor, Element* element)
{
observe(element);
UpgradeCandidateMap::AddResult result = m_upgradeCandidates.add(element, descriptor);
ASSERT_UNUSED(result, result.isNewEntry);
UnresolvedDefinitionMap::iterator it = m_unresolvedDefinitions.find(descriptor);
ElementSet* elements;
if (it == m_unresolvedDefinitions.end())
elements = &m_unresolvedDefinitions.add(descriptor, ElementSet()).storedValue->value;
else
elements = &it->value;
elements->add(element);
}
void CustomElementUpgradeCandidateMap::remove(Element* element)
{
unobserve(element);
removeCommon(element);
}
void CustomElementUpgradeCandidateMap::elementWasDestroyed(Element* element)
{
CustomElementObserver::elementWasDestroyed(element);
removeCommon(element);
}
void CustomElementUpgradeCandidateMap::removeCommon(Element* element)
{
UpgradeCandidateMap::iterator candidate = m_upgradeCandidates.find(element);
ASSERT_WITH_SECURITY_IMPLICATION(candidate != m_upgradeCandidates.end());
UnresolvedDefinitionMap::iterator elements = m_unresolvedDefinitions.find(candidate->value);
ASSERT_WITH_SECURITY_IMPLICATION(elements != m_unresolvedDefinitions.end());
elements->value.remove(element);
m_upgradeCandidates.remove(candidate);
}
void CustomElementUpgradeCandidateMap::elementDidFinishParsingChildren(Element* element)
{
moveToEnd(element);
}
void CustomElementUpgradeCandidateMap::moveToEnd(Element* element)
{
UpgradeCandidateMap::iterator candidate = m_upgradeCandidates.find(element);
ASSERT_WITH_SECURITY_IMPLICATION(candidate != m_upgradeCandidates.end());
UnresolvedDefinitionMap::iterator elements = m_unresolvedDefinitions.find(candidate->value);
ASSERT_WITH_SECURITY_IMPLICATION(elements != m_unresolvedDefinitions.end());
elements->value.appendOrMoveToLast(element);
}
ListHashSet<Element*> CustomElementUpgradeCandidateMap::takeUpgradeCandidatesFor(const CustomElementDescriptor& descriptor)
{
const ListHashSet<Element*>& candidates = m_unresolvedDefinitions.take(descriptor);
for (ElementSet::const_iterator candidate = candidates.begin(); candidate != candidates.end(); ++candidate) {
unobserve(*candidate);
m_upgradeCandidates.remove(*candidate);
}
return candidates;
}
}