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) |
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) { |
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 |
| 88 #if !ENABLE(OILPAN) |
85 ASSERT(!m_registrationNodeKeepAlive); | 89 ASSERT(!m_registrationNodeKeepAlive); |
86 m_registrationNodeKeepAlive = PassRefPtr<Node>(m_registrationNode); // B
alanced in clearTransientRegistrations. | 90 m_registrationNodeKeepAlive = PassRefPtr<Node>(m_registrationNode.get())
; // Balanced in clearTransientRegistrations. |
| 91 #endif |
87 } | 92 } |
88 m_transientRegistrationNodes->add(&node); | 93 m_transientRegistrationNodes->add(&node); |
89 } | 94 } |
90 | 95 |
91 void MutationObserverRegistration::clearTransientRegistrations() | 96 void MutationObserverRegistration::clearTransientRegistrations() |
92 { | 97 { |
93 if (!m_transientRegistrationNodes) { | 98 if (!m_transientRegistrationNodes) { |
| 99 #if !ENABLE(OILPAN) |
94 ASSERT(!m_registrationNodeKeepAlive); | 100 ASSERT(!m_registrationNodeKeepAlive); |
| 101 #endif |
95 return; | 102 return; |
96 } | 103 } |
97 | 104 |
98 for (NodeHashSet::iterator iter = m_transientRegistrationNodes->begin(); ite
r != m_transientRegistrationNodes->end(); ++iter) | 105 for (NodeHashSet::iterator iter = m_transientRegistrationNodes->begin(); ite
r != m_transientRegistrationNodes->end(); ++iter) |
99 (*iter)->unregisterTransientMutationObserver(this); | 106 (*iter)->unregisterTransientMutationObserver(this); |
100 | 107 |
101 m_transientRegistrationNodes.clear(); | 108 m_transientRegistrationNodes.clear(); |
102 | 109 |
| 110 #if !ENABLE(OILPAN) |
103 ASSERT(m_registrationNodeKeepAlive); | 111 ASSERT(m_registrationNodeKeepAlive); |
104 m_registrationNodeKeepAlive = nullptr; // Balanced in observeSubtreeNodeWill
Detach. | 112 m_registrationNodeKeepAlive = nullptr; // Balanced in observeSubtreeNodeWill
Detach. |
| 113 #endif |
105 } | 114 } |
106 | 115 |
107 void MutationObserverRegistration::unregister() | 116 void MutationObserverRegistration::unregister() |
108 { | 117 { |
109 m_registrationNode.unregisterMutationObserver(this); | 118 m_registrationNode->unregisterMutationObserver(this); |
110 // The above line will cause this object to be deleted, so don't do any more
in this function. | 119 // The above line will cause this object to be deleted, so don't do any more
in this function. |
111 } | 120 } |
112 | 121 |
113 bool MutationObserverRegistration::shouldReceiveMutationFrom(Node& node, Mutatio
nObserver::MutationType type, const QualifiedName* attributeName) const | 122 bool MutationObserverRegistration::shouldReceiveMutationFrom(Node& node, Mutatio
nObserver::MutationType type, const QualifiedName* attributeName) const |
114 { | 123 { |
115 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute
Name); | 124 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute
Name); |
116 if (!(m_options & type)) | 125 if (!(m_options & type)) |
117 return false; | 126 return false; |
118 | 127 |
119 if (m_registrationNode != node && !isSubtree()) | 128 if (m_registrationNode != &node && !isSubtree()) |
120 return false; | 129 return false; |
121 | 130 |
122 if (type != MutationObserver::Attributes || !(m_options & MutationObserver::
AttributeFilter)) | 131 if (type != MutationObserver::Attributes || !(m_options & MutationObserver::
AttributeFilter)) |
123 return true; | 132 return true; |
124 | 133 |
125 if (!attributeName->namespaceURI().isNull()) | 134 if (!attributeName->namespaceURI().isNull()) |
126 return false; | 135 return false; |
127 | 136 |
128 return m_attributeFilter.contains(attributeName->localName()); | 137 return m_attributeFilter.contains(attributeName->localName()); |
129 } | 138 } |
130 | 139 |
131 void MutationObserverRegistration::addRegistrationNodesToSet(HashSet<Node*>& nod
es) const | 140 void MutationObserverRegistration::addRegistrationNodesToSet(HashSet<Node*>& nod
es) const |
132 { | 141 { |
133 nodes.add(&m_registrationNode); | 142 nodes.add(m_registrationNode.get()); |
134 if (!m_transientRegistrationNodes) | 143 if (!m_transientRegistrationNodes) |
135 return; | 144 return; |
136 for (NodeHashSet::const_iterator iter = m_transientRegistrationNodes->begin(
); iter != m_transientRegistrationNodes->end(); ++iter) | 145 for (NodeHashSet::const_iterator iter = m_transientRegistrationNodes->begin(
); iter != m_transientRegistrationNodes->end(); ++iter) |
137 nodes.add(iter->get()); | 146 nodes.add(iter->get()); |
138 } | 147 } |
139 | 148 |
140 void MutationObserverRegistration::trace(Visitor* visitor) | 149 void MutationObserverRegistration::trace(Visitor* visitor) |
141 { | 150 { |
142 visitor->trace(m_observer); | 151 visitor->trace(m_observer); |
| 152 visitor->trace(m_registrationNode); |
143 } | 153 } |
144 | 154 |
145 } // namespace WebCore | 155 } // namespace WebCore |
OLD | NEW |