| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 ExceptionState& exceptionState) { | 68 ExceptionState& exceptionState) { |
| 69 DCHECK(node); | 69 DCHECK(node); |
| 70 | 70 |
| 71 MutationObserverOptions options = 0; | 71 MutationObserverOptions options = 0; |
| 72 | 72 |
| 73 if (observerInit.hasAttributeOldValue() && observerInit.attributeOldValue()) | 73 if (observerInit.hasAttributeOldValue() && observerInit.attributeOldValue()) |
| 74 options |= AttributeOldValue; | 74 options |= AttributeOldValue; |
| 75 | 75 |
| 76 HashSet<AtomicString> attributeFilter; | 76 HashSet<AtomicString> attributeFilter; |
| 77 if (observerInit.hasAttributeFilter()) { | 77 if (observerInit.hasAttributeFilter()) { |
| 78 const Vector<String>& sequence = observerInit.attributeFilter(); | 78 for (const auto& name : observerInit.attributeFilter()) |
| 79 for (unsigned i = 0; i < sequence.size(); ++i) | 79 attributeFilter.add(AtomicString(name)); |
| 80 attributeFilter.add(AtomicString(sequence[i])); | |
| 81 options |= AttributeFilter; | 80 options |= AttributeFilter; |
| 82 } | 81 } |
| 83 | 82 |
| 84 bool attributes = observerInit.hasAttributes() && observerInit.attributes(); | 83 bool attributes = observerInit.hasAttributes() && observerInit.attributes(); |
| 85 if (attributes || | 84 if (attributes || |
| 86 (!observerInit.hasAttributes() && (observerInit.hasAttributeOldValue() || | 85 (!observerInit.hasAttributes() && (observerInit.hasAttributeOldValue() || |
| 87 observerInit.hasAttributeFilter()))) | 86 observerInit.hasAttributeFilter()))) |
| 88 options |= Attributes; | 87 options |= Attributes; |
| 89 | 88 |
| 90 if (observerInit.hasCharacterDataOldValue() && | 89 if (observerInit.hasCharacterDataOldValue() && |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 DCHECK(!shouldBeSuspended()); | 219 DCHECK(!shouldBeSuspended()); |
| 221 | 220 |
| 222 // Calling clearTransientRegistrations() can modify m_registrations, so it's | 221 // Calling clearTransientRegistrations() can modify m_registrations, so it's |
| 223 // necessary to make a copy of the transient registrations before operating on | 222 // necessary to make a copy of the transient registrations before operating on |
| 224 // them. | 223 // them. |
| 225 HeapVector<Member<MutationObserverRegistration>, 1> transientRegistrations; | 224 HeapVector<Member<MutationObserverRegistration>, 1> transientRegistrations; |
| 226 for (auto& registration : m_registrations) { | 225 for (auto& registration : m_registrations) { |
| 227 if (registration->hasTransientRegistrations()) | 226 if (registration->hasTransientRegistrations()) |
| 228 transientRegistrations.append(registration); | 227 transientRegistrations.append(registration); |
| 229 } | 228 } |
| 230 for (size_t i = 0; i < transientRegistrations.size(); ++i) | 229 for (const auto& registration : transientRegistrations) |
| 231 transientRegistrations[i]->clearTransientRegistrations(); | 230 registration->clearTransientRegistrations(); |
| 232 | 231 |
| 233 if (m_records.isEmpty()) | 232 if (m_records.isEmpty()) |
| 234 return; | 233 return; |
| 235 | 234 |
| 236 MutationRecordVector records; | 235 MutationRecordVector records; |
| 237 records.swap(m_records); | 236 records.swap(m_records); |
| 238 | 237 |
| 239 // Report the first (earliest) stack as the async cause. | 238 // Report the first (earliest) stack as the async cause. |
| 240 InspectorInstrumentation::AsyncTask asyncTask( | 239 InspectorInstrumentation::AsyncTask asyncTask( |
| 241 m_callback->getExecutionContext(), records.front()); | 240 m_callback->getExecutionContext(), records.front()); |
| 242 m_callback->call(records, this); | 241 m_callback->call(records, this); |
| 243 } | 242 } |
| 244 | 243 |
| 245 void MutationObserver::resumeSuspendedObservers() { | 244 void MutationObserver::resumeSuspendedObservers() { |
| 246 DCHECK(isMainThread()); | 245 DCHECK(isMainThread()); |
| 247 if (suspendedMutationObservers().isEmpty()) | 246 if (suspendedMutationObservers().isEmpty()) |
| 248 return; | 247 return; |
| 249 | 248 |
| 250 MutationObserverVector suspended; | 249 MutationObserverVector suspended; |
| 251 copyToVector(suspendedMutationObservers(), suspended); | 250 copyToVector(suspendedMutationObservers(), suspended); |
| 252 for (size_t i = 0; i < suspended.size(); ++i) { | 251 for (const auto& observer : suspended) { |
| 253 if (!suspended[i]->shouldBeSuspended()) { | 252 if (!observer->shouldBeSuspended()) { |
| 254 suspendedMutationObservers().remove(suspended[i]); | 253 suspendedMutationObservers().remove(observer); |
| 255 activateObserver(suspended[i]); | 254 activateObserver(observer); |
| 256 } | 255 } |
| 257 } | 256 } |
| 258 } | 257 } |
| 259 | 258 |
| 260 void MutationObserver::deliverMutations() { | 259 void MutationObserver::deliverMutations() { |
| 261 DCHECK(isMainThread()); | 260 DCHECK(isMainThread()); |
| 262 MutationObserverVector observers; | 261 MutationObserverVector observers; |
| 263 copyToVector(activeMutationObservers(), observers); | 262 copyToVector(activeMutationObservers(), observers); |
| 264 activeMutationObservers().clear(); | 263 activeMutationObservers().clear(); |
| 265 std::sort(observers.begin(), observers.end(), ObserverLessThan()); | 264 std::sort(observers.begin(), observers.end(), ObserverLessThan()); |
| 266 for (size_t i = 0; i < observers.size(); ++i) { | 265 for (const auto& observer : observers) { |
| 267 if (observers[i]->shouldBeSuspended()) | 266 if (observer->shouldBeSuspended()) |
| 268 suspendedMutationObservers().add(observers[i]); | 267 suspendedMutationObservers().add(observer); |
| 269 else | 268 else |
| 270 observers[i]->deliver(); | 269 observer->deliver(); |
| 271 } | 270 } |
| 272 } | 271 } |
| 273 | 272 |
| 274 DEFINE_TRACE(MutationObserver) { | 273 DEFINE_TRACE(MutationObserver) { |
| 275 visitor->trace(m_callback); | 274 visitor->trace(m_callback); |
| 276 visitor->trace(m_records); | 275 visitor->trace(m_records); |
| 277 visitor->trace(m_registrations); | 276 visitor->trace(m_registrations); |
| 278 visitor->trace(m_callback); | 277 visitor->trace(m_callback); |
| 279 } | 278 } |
| 280 | 279 |
| 281 } // namespace blink | 280 } // namespace blink |
| OLD | NEW |