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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 , m_priority(s_observerPriority++) | 64 , m_priority(s_observerPriority++) |
65 { | 65 { |
66 } | 66 } |
67 | 67 |
68 MutationObserver::~MutationObserver() | 68 MutationObserver::~MutationObserver() |
69 { | 69 { |
70 #if !ENABLE(OILPAN) | 70 #if !ENABLE(OILPAN) |
71 ASSERT(m_registrations.isEmpty()); | 71 ASSERT(m_registrations.isEmpty()); |
72 #endif | 72 #endif |
73 if (!m_records.isEmpty()) | 73 if (!m_records.isEmpty()) |
74 InspectorInstrumentation::didClearAllMutationRecords(m_callback->executi
onContext(), this); | 74 InspectorInstrumentation::didClearAllMutationRecords(m_callback->getExec
utionContext(), this); |
75 } | 75 } |
76 | 76 |
77 void MutationObserver::observe(Node* node, const MutationObserverInit& observerI
nit, ExceptionState& exceptionState) | 77 void MutationObserver::observe(Node* node, const MutationObserverInit& observerI
nit, ExceptionState& exceptionState) |
78 { | 78 { |
79 ASSERT(node); | 79 ASSERT(node); |
80 | 80 |
81 MutationObserverOptions options = 0; | 81 MutationObserverOptions options = 0; |
82 | 82 |
83 if (observerInit.hasAttributeOldValue() && observerInit.attributeOldValue()) | 83 if (observerInit.hasAttributeOldValue() && observerInit.attributeOldValue()) |
84 options |= AttributeOldValue; | 84 options |= AttributeOldValue; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 return; | 128 return; |
129 } | 129 } |
130 | 130 |
131 node->registerMutationObserver(*this, options, attributeFilter); | 131 node->registerMutationObserver(*this, options, attributeFilter); |
132 } | 132 } |
133 | 133 |
134 MutationRecordVector MutationObserver::takeRecords() | 134 MutationRecordVector MutationObserver::takeRecords() |
135 { | 135 { |
136 MutationRecordVector records; | 136 MutationRecordVector records; |
137 records.swap(m_records); | 137 records.swap(m_records); |
138 InspectorInstrumentation::didClearAllMutationRecords(m_callback->executionCo
ntext(), this); | 138 InspectorInstrumentation::didClearAllMutationRecords(m_callback->getExecutio
nContext(), this); |
139 return records; | 139 return records; |
140 } | 140 } |
141 | 141 |
142 void MutationObserver::disconnect() | 142 void MutationObserver::disconnect() |
143 { | 143 { |
144 m_records.clear(); | 144 m_records.clear(); |
145 InspectorInstrumentation::didClearAllMutationRecords(m_callback->executionCo
ntext(), this); | 145 InspectorInstrumentation::didClearAllMutationRecords(m_callback->getExecutio
nContext(), this); |
146 MutationObserverRegistrationSet registrations(m_registrations); | 146 MutationObserverRegistrationSet registrations(m_registrations); |
147 for (auto& registration : registrations) { | 147 for (auto& registration : registrations) { |
148 // The registration may be already unregistered while iteration. | 148 // The registration may be already unregistered while iteration. |
149 // Only call unregister if it is still in the original set. | 149 // Only call unregister if it is still in the original set. |
150 if (m_registrations.contains(registration)) | 150 if (m_registrations.contains(registration)) |
151 registration->unregister(); | 151 registration->unregister(); |
152 } | 152 } |
153 ASSERT(m_registrations.isEmpty()); | 153 ASSERT(m_registrations.isEmpty()); |
154 } | 154 } |
155 | 155 |
(...skipping 27 matching lines...) Expand all Loading... |
183 Microtask::enqueueMicrotask(WTF::bind(&MutationObserver::deliverMutation
s)); | 183 Microtask::enqueueMicrotask(WTF::bind(&MutationObserver::deliverMutation
s)); |
184 | 184 |
185 activeMutationObservers().add(observer); | 185 activeMutationObservers().add(observer); |
186 } | 186 } |
187 | 187 |
188 void MutationObserver::enqueueMutationRecord(PassRefPtrWillBeRawPtr<MutationReco
rd> mutation) | 188 void MutationObserver::enqueueMutationRecord(PassRefPtrWillBeRawPtr<MutationReco
rd> mutation) |
189 { | 189 { |
190 ASSERT(isMainThread()); | 190 ASSERT(isMainThread()); |
191 m_records.append(mutation); | 191 m_records.append(mutation); |
192 activateObserver(this); | 192 activateObserver(this); |
193 InspectorInstrumentation::didEnqueueMutationRecord(m_callback->executionCont
ext(), this); | 193 InspectorInstrumentation::didEnqueueMutationRecord(m_callback->getExecutionC
ontext(), this); |
194 } | 194 } |
195 | 195 |
196 void MutationObserver::setHasTransientRegistration() | 196 void MutationObserver::setHasTransientRegistration() |
197 { | 197 { |
198 ASSERT(isMainThread()); | 198 ASSERT(isMainThread()); |
199 activateObserver(this); | 199 activateObserver(this); |
200 } | 200 } |
201 | 201 |
202 WillBeHeapHashSet<RawPtrWillBeMember<Node>> MutationObserver::getObservedNodes()
const | 202 WillBeHeapHashSet<RawPtrWillBeMember<Node>> MutationObserver::getObservedNodes()
const |
203 { | 203 { |
204 WillBeHeapHashSet<RawPtrWillBeMember<Node>> observedNodes; | 204 WillBeHeapHashSet<RawPtrWillBeMember<Node>> observedNodes; |
205 for (const auto& registration : m_registrations) | 205 for (const auto& registration : m_registrations) |
206 registration->addRegistrationNodesToSet(observedNodes); | 206 registration->addRegistrationNodesToSet(observedNodes); |
207 return observedNodes; | 207 return observedNodes; |
208 } | 208 } |
209 | 209 |
210 bool MutationObserver::shouldBeSuspended() const | 210 bool MutationObserver::shouldBeSuspended() const |
211 { | 211 { |
212 return m_callback->executionContext() && m_callback->executionContext()->act
iveDOMObjectsAreSuspended(); | 212 return m_callback->getExecutionContext() && m_callback->getExecutionContext(
)->activeDOMObjectsAreSuspended(); |
213 } | 213 } |
214 | 214 |
215 void MutationObserver::deliver() | 215 void MutationObserver::deliver() |
216 { | 216 { |
217 ASSERT(!shouldBeSuspended()); | 217 ASSERT(!shouldBeSuspended()); |
218 | 218 |
219 // Calling clearTransientRegistrations() can modify m_registrations, so it's
necessary | 219 // Calling clearTransientRegistrations() can modify m_registrations, so it's
necessary |
220 // to make a copy of the transient registrations before operating on them. | 220 // to make a copy of the transient registrations before operating on them. |
221 WillBeHeapVector<RawPtrWillBeMember<MutationObserverRegistration>, 1> transi
entRegistrations; | 221 WillBeHeapVector<RawPtrWillBeMember<MutationObserverRegistration>, 1> transi
entRegistrations; |
222 for (auto& registration : m_registrations) { | 222 for (auto& registration : m_registrations) { |
223 if (registration->hasTransientRegistrations()) | 223 if (registration->hasTransientRegistrations()) |
224 transientRegistrations.append(registration); | 224 transientRegistrations.append(registration); |
225 } | 225 } |
226 for (size_t i = 0; i < transientRegistrations.size(); ++i) | 226 for (size_t i = 0; i < transientRegistrations.size(); ++i) |
227 transientRegistrations[i]->clearTransientRegistrations(); | 227 transientRegistrations[i]->clearTransientRegistrations(); |
228 | 228 |
229 if (m_records.isEmpty()) | 229 if (m_records.isEmpty()) |
230 return; | 230 return; |
231 | 231 |
232 MutationRecordVector records; | 232 MutationRecordVector records; |
233 records.swap(m_records); | 233 records.swap(m_records); |
234 | 234 |
235 InspectorInstrumentation::willDeliverMutationRecords(m_callback->executionCo
ntext(), this); | 235 InspectorInstrumentation::willDeliverMutationRecords(m_callback->getExecutio
nContext(), this); |
236 m_callback->call(records, this); | 236 m_callback->call(records, this); |
237 InspectorInstrumentation::didDeliverMutationRecords(m_callback->executionCon
text()); | 237 InspectorInstrumentation::didDeliverMutationRecords(m_callback->getExecution
Context()); |
238 } | 238 } |
239 | 239 |
240 void MutationObserver::resumeSuspendedObservers() | 240 void MutationObserver::resumeSuspendedObservers() |
241 { | 241 { |
242 ASSERT(isMainThread()); | 242 ASSERT(isMainThread()); |
243 if (suspendedMutationObservers().isEmpty()) | 243 if (suspendedMutationObservers().isEmpty()) |
244 return; | 244 return; |
245 | 245 |
246 MutationObserverVector suspended; | 246 MutationObserverVector suspended; |
247 copyToVector(suspendedMutationObservers(), suspended); | 247 copyToVector(suspendedMutationObservers(), suspended); |
(...skipping 24 matching lines...) Expand all Loading... |
272 { | 272 { |
273 #if ENABLE(OILPAN) | 273 #if ENABLE(OILPAN) |
274 visitor->trace(m_callback); | 274 visitor->trace(m_callback); |
275 visitor->trace(m_records); | 275 visitor->trace(m_records); |
276 visitor->trace(m_registrations); | 276 visitor->trace(m_registrations); |
277 visitor->trace(m_callback); | 277 visitor->trace(m_callback); |
278 #endif | 278 #endif |
279 } | 279 } |
280 | 280 |
281 } // namespace blink | 281 } // namespace blink |
OLD | NEW |