2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "core/dom/custom/CustomElementUpgradeCandidateMap.h"
34 #include "core/dom/Element.h"
38 PassOwnPtrWillBeRawPtr<CustomElementUpgradeCandidateMap> CustomElementUpgradeCandidateMap::create()
40 return adoptPtrWillBeNoop(new CustomElementUpgradeCandidateMap());
43 CustomElementUpgradeCandidateMap::~CustomElementUpgradeCandidateMap()
46 // With Oilpan enabled, the observer table keeps a weak reference to the
47 // element; no need for explicit removal.
48 UpgradeCandidateMap::const_iterator::Keys end = m_upgradeCandidates.end().keys();
49 for (UpgradeCandidateMap::const_iterator::Keys it = m_upgradeCandidates.begin().keys(); it != end; ++it)
54 void CustomElementUpgradeCandidateMap::add(const CustomElementDescriptor& descriptor, Element* element)
58 UpgradeCandidateMap::AddResult result = m_upgradeCandidates.add(element, descriptor);
59 ASSERT_UNUSED(result, result.isNewEntry);
61 UnresolvedDefinitionMap::iterator it = m_unresolvedDefinitions.find(descriptor);
63 if (it == m_unresolvedDefinitions.end())
64 elements = m_unresolvedDefinitions.add(descriptor, adoptPtrWillBeNoop(new ElementSet())).storedValue->value.get();
66 elements = it->value.get();
67 elements->add(element);
70 void CustomElementUpgradeCandidateMap::elementWasDestroyed(Element* element)
72 CustomElementObserver::elementWasDestroyed(element);
73 UpgradeCandidateMap::iterator candidate = m_upgradeCandidates.find(element);
74 ASSERT_WITH_SECURITY_IMPLICATION(candidate != m_upgradeCandidates.end());
76 UnresolvedDefinitionMap::iterator elements = m_unresolvedDefinitions.find(candidate->value);
77 ASSERT_WITH_SECURITY_IMPLICATION(elements != m_unresolvedDefinitions.end());
78 elements->value->remove(element);
79 m_upgradeCandidates.remove(candidate);
82 void CustomElementUpgradeCandidateMap::elementDidFinishParsingChildren(Element* element)
84 // An upgrade candidate finished parsing; reorder so that eventual
85 // upgrade order matches finished-parsing order.
89 void CustomElementUpgradeCandidateMap::moveToEnd(Element* element)
91 UpgradeCandidateMap::iterator candidate = m_upgradeCandidates.find(element);
92 ASSERT_WITH_SECURITY_IMPLICATION(candidate != m_upgradeCandidates.end());
94 UnresolvedDefinitionMap::iterator elements = m_unresolvedDefinitions.find(candidate->value);
95 ASSERT_WITH_SECURITY_IMPLICATION(elements != m_unresolvedDefinitions.end());
96 elements->value->appendOrMoveToLast(element);
99 PassOwnPtrWillBeRawPtr<CustomElementUpgradeCandidateMap::ElementSet> CustomElementUpgradeCandidateMap::takeUpgradeCandidatesFor(const CustomElementDescriptor& descriptor)
101 OwnPtrWillBeRawPtr<ElementSet> candidates = m_unresolvedDefinitions.take(descriptor);
106 for (ElementSet::const_iterator candidate = candidates->begin(); candidate != candidates->end(); ++candidate) {
107 unobserve(*candidate);
108 m_upgradeCandidates.remove(*candidate);
110 return candidates.release();
113 void CustomElementUpgradeCandidateMap::trace(Visitor* visitor)
116 visitor->trace(m_upgradeCandidates);
117 visitor->trace(m_unresolvedDefinitions);
119 CustomElementObserver::trace(visitor);