| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/dom/custom/CustomElementUpgradeCandidateMap.h" | 31 #include "core/dom/custom/CustomElementUpgradeCandidateMap.h" |
| 32 | 32 |
| 33 #include "core/dom/Element.h" | 33 #include "core/dom/Element.h" |
| 34 | 34 |
| 35 namespace blink { | 35 namespace blink { |
| 36 | 36 |
| 37 PassOwnPtrWillBeRawPtr<CustomElementUpgradeCandidateMap> CustomElementUpgradeCan
didateMap::create() | 37 RawPtr<CustomElementUpgradeCandidateMap> CustomElementUpgradeCandidateMap::creat
e() |
| 38 { | 38 { |
| 39 return adoptPtrWillBeNoop(new CustomElementUpgradeCandidateMap()); | 39 return new CustomElementUpgradeCandidateMap(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 CustomElementUpgradeCandidateMap::~CustomElementUpgradeCandidateMap() | 42 CustomElementUpgradeCandidateMap::~CustomElementUpgradeCandidateMap() |
| 43 { | 43 { |
| 44 #if !ENABLE(OILPAN) | 44 #if !ENABLE(OILPAN) |
| 45 // With Oilpan enabled, the observer table keeps a weak reference to the | 45 // With Oilpan enabled, the observer table keeps a weak reference to the |
| 46 // element; no need for explicit removal. | 46 // element; no need for explicit removal. |
| 47 UpgradeCandidateMap::const_iterator::KeysIterator end = m_upgradeCandidates.
end().keys(); | 47 UpgradeCandidateMap::const_iterator::KeysIterator end = m_upgradeCandidates.
end().keys(); |
| 48 for (UpgradeCandidateMap::const_iterator::KeysIterator it = m_upgradeCandida
tes.begin().keys(); it != end; ++it) | 48 for (UpgradeCandidateMap::const_iterator::KeysIterator it = m_upgradeCandida
tes.begin().keys(); it != end; ++it) |
| 49 unobserve(*it); | 49 unobserve(*it); |
| 50 #endif | 50 #endif |
| 51 } | 51 } |
| 52 | 52 |
| 53 void CustomElementUpgradeCandidateMap::add(const CustomElementDescriptor& descri
ptor, Element* element) | 53 void CustomElementUpgradeCandidateMap::add(const CustomElementDescriptor& descri
ptor, Element* element) |
| 54 { | 54 { |
| 55 observe(element); | 55 observe(element); |
| 56 | 56 |
| 57 UpgradeCandidateMap::AddResult result = m_upgradeCandidates.add(element, des
criptor); | 57 UpgradeCandidateMap::AddResult result = m_upgradeCandidates.add(element, des
criptor); |
| 58 ASSERT_UNUSED(result, result.isNewEntry); | 58 ASSERT_UNUSED(result, result.isNewEntry); |
| 59 | 59 |
| 60 UnresolvedDefinitionMap::iterator it = m_unresolvedDefinitions.find(descript
or); | 60 UnresolvedDefinitionMap::iterator it = m_unresolvedDefinitions.find(descript
or); |
| 61 ElementSet* elements; | 61 ElementSet* elements; |
| 62 if (it == m_unresolvedDefinitions.end()) | 62 if (it == m_unresolvedDefinitions.end()) |
| 63 elements = m_unresolvedDefinitions.add(descriptor, adoptPtrWillBeNoop(ne
w ElementSet())).storedValue->value.get(); | 63 elements = m_unresolvedDefinitions.add(descriptor, new ElementSet()).sto
redValue->value.get(); |
| 64 else | 64 else |
| 65 elements = it->value.get(); | 65 elements = it->value.get(); |
| 66 elements->add(element); | 66 elements->add(element); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void CustomElementUpgradeCandidateMap::elementWasDestroyed(Element* element) | 69 void CustomElementUpgradeCandidateMap::elementWasDestroyed(Element* element) |
| 70 { | 70 { |
| 71 CustomElementObserver::elementWasDestroyed(element); | 71 CustomElementObserver::elementWasDestroyed(element); |
| 72 UpgradeCandidateMap::iterator candidate = m_upgradeCandidates.find(element); | 72 UpgradeCandidateMap::iterator candidate = m_upgradeCandidates.find(element); |
| 73 ASSERT_WITH_SECURITY_IMPLICATION(candidate != m_upgradeCandidates.end()); | 73 ASSERT_WITH_SECURITY_IMPLICATION(candidate != m_upgradeCandidates.end()); |
| 74 | 74 |
| 75 UnresolvedDefinitionMap::iterator elements = m_unresolvedDefinitions.find(ca
ndidate->value); | 75 UnresolvedDefinitionMap::iterator elements = m_unresolvedDefinitions.find(ca
ndidate->value); |
| 76 ASSERT_WITH_SECURITY_IMPLICATION(elements != m_unresolvedDefinitions.end()); | 76 ASSERT_WITH_SECURITY_IMPLICATION(elements != m_unresolvedDefinitions.end()); |
| 77 elements->value->remove(element); | 77 elements->value->remove(element); |
| 78 m_upgradeCandidates.remove(candidate); | 78 m_upgradeCandidates.remove(candidate); |
| 79 } | 79 } |
| 80 | 80 |
| 81 PassOwnPtrWillBeRawPtr<CustomElementUpgradeCandidateMap::ElementSet> CustomEleme
ntUpgradeCandidateMap::takeUpgradeCandidatesFor(const CustomElementDescriptor& d
escriptor) | 81 RawPtr<CustomElementUpgradeCandidateMap::ElementSet> CustomElementUpgradeCandida
teMap::takeUpgradeCandidatesFor(const CustomElementDescriptor& descriptor) |
| 82 { | 82 { |
| 83 OwnPtrWillBeRawPtr<ElementSet> candidates = m_unresolvedDefinitions.take(des
criptor); | 83 RawPtr<ElementSet> candidates = m_unresolvedDefinitions.take(descriptor); |
| 84 | 84 |
| 85 if (!candidates) | 85 if (!candidates) |
| 86 return nullptr; | 86 return nullptr; |
| 87 | 87 |
| 88 for (const auto& candidate : *candidates) { | 88 for (const auto& candidate : *candidates) { |
| 89 unobserve(candidate); | 89 unobserve(candidate); |
| 90 m_upgradeCandidates.remove(candidate); | 90 m_upgradeCandidates.remove(candidate); |
| 91 } | 91 } |
| 92 return candidates.release(); | 92 return candidates.release(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 DEFINE_TRACE(CustomElementUpgradeCandidateMap) | 95 DEFINE_TRACE(CustomElementUpgradeCandidateMap) |
| 96 { | 96 { |
| 97 #if ENABLE(OILPAN) | 97 #if ENABLE(OILPAN) |
| 98 visitor->trace(m_upgradeCandidates); | 98 visitor->trace(m_upgradeCandidates); |
| 99 visitor->trace(m_unresolvedDefinitions); | 99 visitor->trace(m_unresolvedDefinitions); |
| 100 #endif | 100 #endif |
| 101 CustomElementObserver::trace(visitor); | 101 CustomElementObserver::trace(visitor); |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace blink | 104 } // namespace blink |
| OLD | NEW |