Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 26 matching lines...) Expand all Loading... | |
| 37 | 37 |
| 38 namespace WebCore { | 38 namespace WebCore { |
| 39 | 39 |
| 40 PassOwnPtrWillBeRawPtr<MutationObserverRegistration> MutationObserverRegistratio n::create(MutationObserver& observer, Node& registrationNode, MutationObserverOp tions options, const HashSet<AtomicString>& attributeFilter) | 40 PassOwnPtrWillBeRawPtr<MutationObserverRegistration> MutationObserverRegistratio n::create(MutationObserver& observer, Node& registrationNode, MutationObserverOp tions options, const HashSet<AtomicString>& attributeFilter) |
| 41 { | 41 { |
| 42 return adoptPtrWillBeNoop(new MutationObserverRegistration(observer, registr ationNode, options, attributeFilter)); | 42 return adoptPtrWillBeNoop(new MutationObserverRegistration(observer, registr ationNode, options, attributeFilter)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 MutationObserverRegistration::MutationObserverRegistration(MutationObserver& obs erver, Node& registrationNode, MutationObserverOptions options, const HashSet<At omicString>& attributeFilter) | 45 MutationObserverRegistration::MutationObserverRegistration(MutationObserver& obs erver, Node& registrationNode, MutationObserverOptions options, const HashSet<At omicString>& attributeFilter) |
| 46 : m_observer(observer) | 46 : m_observer(observer) |
| 47 , m_registrationNode(registrationNode) | 47 , m_registrationNode(®istrationNode) |
|
Erik Corry
2014/05/05 14:28:46
This is called in exactly one place where we have
sof
2014/05/05 15:36:03
Yes, impedance matching now done.
| |
| 48 , m_options(options) | 48 , m_options(options) |
| 49 , m_attributeFilter(attributeFilter) | 49 , m_attributeFilter(attributeFilter) |
| 50 { | 50 { |
| 51 m_observer->observationStarted(this); | 51 m_observer->observationStarted(this); |
| 52 } | 52 } |
| 53 | 53 |
| 54 MutationObserverRegistration::~MutationObserverRegistration() | 54 MutationObserverRegistration::~MutationObserverRegistration() |
| 55 { | 55 { |
| 56 // dispose() hasn't been called if this assert triggers. | 56 #if !ENABLE(OILPAN) |
| 57 ASSERT(!m_observer); | 57 dispose(); |
| 58 #endif | |
| 58 } | 59 } |
| 59 | 60 |
| 60 void MutationObserverRegistration::dispose() | 61 void MutationObserverRegistration::dispose() |
| 61 { | 62 { |
| 62 clearTransientRegistrations(); | 63 clearTransientRegistrations(); |
| 63 m_observer->observationEnded(this); | 64 if (m_observer) { |
|
Erik Corry
2014/05/05 14:28:46
I wonder why we did not need this 'if' before?
sof
2014/05/05 14:57:36
We explicitly dispose() in Node::unregisterMutatio
Erik Corry
2014/05/05 14:58:43
I think it's cool as it is.
sof
2014/05/05 15:36:03
Thinking about it a bit more, it is preferable to
| |
| 64 m_observer.clear(); | 65 m_observer->observationEnded(this); |
| 66 m_observer.clear(); | |
| 67 } | |
| 65 } | 68 } |
| 66 | 69 |
| 67 void MutationObserverRegistration::resetObservation(MutationObserverOptions opti ons, const HashSet<AtomicString>& attributeFilter) | 70 void MutationObserverRegistration::resetObservation(MutationObserverOptions opti ons, const HashSet<AtomicString>& attributeFilter) |
| 68 { | 71 { |
| 69 clearTransientRegistrations(); | 72 clearTransientRegistrations(); |
| 70 m_options = options; | 73 m_options = options; |
| 71 m_attributeFilter = attributeFilter; | 74 m_attributeFilter = attributeFilter; |
| 72 } | 75 } |
| 73 | 76 |
| 74 void MutationObserverRegistration::observedSubtreeNodeWillDetach(Node& node) | 77 void MutationObserverRegistration::observedSubtreeNodeWillDetach(Node& node) |
| 75 { | 78 { |
| 76 if (!isSubtree()) | 79 if (!isSubtree()) |
| 77 return; | 80 return; |
| 78 | 81 |
| 79 node.registerTransientMutationObserver(this); | 82 node.registerTransientMutationObserver(this); |
| 80 m_observer->setHasTransientRegistration(); | 83 m_observer->setHasTransientRegistration(); |
| 81 | 84 |
| 82 if (!m_transientRegistrationNodes) { | 85 if (!m_transientRegistrationNodes) { |
| 83 m_transientRegistrationNodes = adoptPtr(new NodeHashSet); | 86 m_transientRegistrationNodes = adoptPtr(new NodeHashSet); |
| 84 | 87 |
| 85 ASSERT(!m_registrationNodeKeepAlive); | 88 ASSERT(!m_registrationNodeKeepAlive); |
| 86 m_registrationNodeKeepAlive = PassRefPtr<Node>(m_registrationNode); // B alanced in clearTransientRegistrations. | 89 m_registrationNodeKeepAlive = PassRefPtr<Node>(m_registrationNode.get()) ; // Balanced in clearTransientRegistrations. |
| 87 } | 90 } |
| 88 m_transientRegistrationNodes->add(&node); | 91 m_transientRegistrationNodes->add(&node); |
| 89 } | 92 } |
| 90 | 93 |
| 91 void MutationObserverRegistration::clearTransientRegistrations() | 94 void MutationObserverRegistration::clearTransientRegistrations() |
| 92 { | 95 { |
| 93 if (!m_transientRegistrationNodes) { | 96 if (!m_transientRegistrationNodes) { |
| 94 ASSERT(!m_registrationNodeKeepAlive); | 97 ASSERT(!m_registrationNodeKeepAlive); |
| 95 return; | 98 return; |
| 96 } | 99 } |
| 97 | 100 |
| 98 for (NodeHashSet::iterator iter = m_transientRegistrationNodes->begin(); ite r != m_transientRegistrationNodes->end(); ++iter) | 101 for (NodeHashSet::iterator iter = m_transientRegistrationNodes->begin(); ite r != m_transientRegistrationNodes->end(); ++iter) |
| 99 (*iter)->unregisterTransientMutationObserver(this); | 102 (*iter)->unregisterTransientMutationObserver(this); |
| 100 | 103 |
| 101 m_transientRegistrationNodes.clear(); | 104 m_transientRegistrationNodes.clear(); |
| 102 | 105 |
| 103 ASSERT(m_registrationNodeKeepAlive); | 106 ASSERT(m_registrationNodeKeepAlive); |
| 104 m_registrationNodeKeepAlive = nullptr; // Balanced in observeSubtreeNodeWill Detach. | 107 m_registrationNodeKeepAlive = nullptr; // Balanced in observeSubtreeNodeWill Detach. |
| 105 } | 108 } |
| 106 | 109 |
| 107 void MutationObserverRegistration::unregister() | 110 void MutationObserverRegistration::unregister() |
| 108 { | 111 { |
| 109 m_registrationNode.unregisterMutationObserver(this); | 112 m_registrationNode->unregisterMutationObserver(this); |
| 110 // The above line will cause this object to be deleted, so don't do any more in this function. | 113 // The above line will cause this object to be deleted, so don't do any more in this function. |
| 111 } | 114 } |
| 112 | 115 |
| 113 bool MutationObserverRegistration::shouldReceiveMutationFrom(Node& node, Mutatio nObserver::MutationType type, const QualifiedName* attributeName) const | 116 bool MutationObserverRegistration::shouldReceiveMutationFrom(Node& node, Mutatio nObserver::MutationType type, const QualifiedName* attributeName) const |
| 114 { | 117 { |
| 115 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute Name); | 118 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute Name); |
| 116 if (!(m_options & type)) | 119 if (!(m_options & type)) |
| 117 return false; | 120 return false; |
| 118 | 121 |
| 119 if (m_registrationNode != node && !isSubtree()) | 122 if (m_registrationNode != &node && !isSubtree()) |
| 120 return false; | 123 return false; |
| 121 | 124 |
| 122 if (type != MutationObserver::Attributes || !(m_options & MutationObserver:: AttributeFilter)) | 125 if (type != MutationObserver::Attributes || !(m_options & MutationObserver:: AttributeFilter)) |
| 123 return true; | 126 return true; |
| 124 | 127 |
| 125 if (!attributeName->namespaceURI().isNull()) | 128 if (!attributeName->namespaceURI().isNull()) |
| 126 return false; | 129 return false; |
| 127 | 130 |
| 128 return m_attributeFilter.contains(attributeName->localName()); | 131 return m_attributeFilter.contains(attributeName->localName()); |
| 129 } | 132 } |
| 130 | 133 |
| 131 void MutationObserverRegistration::addRegistrationNodesToSet(HashSet<Node*>& nod es) const | 134 void MutationObserverRegistration::addRegistrationNodesToSet(HashSet<Node*>& nod es) const |
| 132 { | 135 { |
| 133 nodes.add(&m_registrationNode); | 136 nodes.add(m_registrationNode.get()); |
| 134 if (!m_transientRegistrationNodes) | 137 if (!m_transientRegistrationNodes) |
| 135 return; | 138 return; |
| 136 for (NodeHashSet::const_iterator iter = m_transientRegistrationNodes->begin( ); iter != m_transientRegistrationNodes->end(); ++iter) | 139 for (NodeHashSet::const_iterator iter = m_transientRegistrationNodes->begin( ); iter != m_transientRegistrationNodes->end(); ++iter) |
| 137 nodes.add(iter->get()); | 140 nodes.add(iter->get()); |
| 138 } | 141 } |
| 139 | 142 |
| 140 void MutationObserverRegistration::trace(Visitor* visitor) | 143 void MutationObserverRegistration::trace(Visitor* visitor) |
| 141 { | 144 { |
| 142 visitor->trace(m_observer); | 145 visitor->trace(m_observer); |
| 146 visitor->trace(m_registrationNode); | |
| 143 } | 147 } |
| 144 | 148 |
| 145 } // namespace WebCore | 149 } // namespace WebCore |
| OLD | NEW |