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 23 matching lines...) Expand all Loading... |
34 | 34 |
35 #include "WebKitMutationObserver.h" | 35 #include "WebKitMutationObserver.h" |
36 | 36 |
37 #include "Document.h" | 37 #include "Document.h" |
38 #include "ExceptionCode.h" | 38 #include "ExceptionCode.h" |
39 #include "MutationCallback.h" | 39 #include "MutationCallback.h" |
40 #include "MutationObserverRegistration.h" | 40 #include "MutationObserverRegistration.h" |
41 #include "MutationRecord.h" | 41 #include "MutationRecord.h" |
42 #include "Node.h" | 42 #include "Node.h" |
43 #include <wtf/ListHashSet.h> | 43 #include <wtf/ListHashSet.h> |
| 44 #include <wtf/MainThread.h> |
44 | 45 |
45 namespace WebCore { | 46 namespace WebCore { |
46 | 47 |
47 PassRefPtr<WebKitMutationObserver> WebKitMutationObserver::create(PassRefPtr<Mut
ationCallback> callback) | 48 PassRefPtr<WebKitMutationObserver> WebKitMutationObserver::create(PassRefPtr<Mut
ationCallback> callback) |
48 { | 49 { |
49 return adoptRef(new WebKitMutationObserver(callback)); | 50 return adoptRef(new WebKitMutationObserver(callback)); |
50 } | 51 } |
51 | 52 |
52 WebKitMutationObserver::WebKitMutationObserver(PassRefPtr<MutationCallback> call
back) | 53 WebKitMutationObserver::WebKitMutationObserver(PassRefPtr<MutationCallback> call
back) |
53 : m_callback(callback) | 54 : m_callback(callback) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 typedef ListHashSet<RefPtr<WebKitMutationObserver> > MutationObserverSet; | 109 typedef ListHashSet<RefPtr<WebKitMutationObserver> > MutationObserverSet; |
109 | 110 |
110 static MutationObserverSet& activeMutationObservers() | 111 static MutationObserverSet& activeMutationObservers() |
111 { | 112 { |
112 DEFINE_STATIC_LOCAL(MutationObserverSet, activeObservers, ()); | 113 DEFINE_STATIC_LOCAL(MutationObserverSet, activeObservers, ()); |
113 return activeObservers; | 114 return activeObservers; |
114 } | 115 } |
115 | 116 |
116 void WebKitMutationObserver::enqueueMutationRecord(PassRefPtr<MutationRecord> mu
tation) | 117 void WebKitMutationObserver::enqueueMutationRecord(PassRefPtr<MutationRecord> mu
tation) |
117 { | 118 { |
| 119 ASSERT(isMainThread()); |
118 m_records.append(mutation); | 120 m_records.append(mutation); |
119 activeMutationObservers().add(this); | 121 activeMutationObservers().add(this); |
120 } | 122 } |
121 | 123 |
122 void WebKitMutationObserver::deliver() | 124 void WebKitMutationObserver::deliver() |
123 { | 125 { |
124 MutationRecordArray records; | 126 MutationRecordArray records; |
125 records.swap(m_records); | 127 records.swap(m_records); |
126 | 128 |
127 for (HashSet<MutationObserverRegistration*>::iterator iter = m_registrations
.begin(); iter != m_registrations.end(); ++iter) | 129 for (HashSet<MutationObserverRegistration*>::iterator iter = m_registrations
.begin(); iter != m_registrations.end(); ++iter) |
128 (*iter)->clearTransientRegistrations(); | 130 (*iter)->clearTransientRegistrations(); |
129 | 131 |
130 m_callback->handleEvent(&records, this); | 132 m_callback->handleEvent(&records, this); |
131 } | 133 } |
132 | 134 |
133 void WebKitMutationObserver::deliverAllMutations() | 135 void WebKitMutationObserver::deliverAllMutations() |
134 { | 136 { |
| 137 ASSERT(isMainThread()); |
135 static bool deliveryInProgress = false; | 138 static bool deliveryInProgress = false; |
136 if (deliveryInProgress) | 139 if (deliveryInProgress) |
137 return; | 140 return; |
138 deliveryInProgress = true; | 141 deliveryInProgress = true; |
139 | 142 |
140 while (!activeMutationObservers().isEmpty()) { | 143 while (!activeMutationObservers().isEmpty()) { |
141 MutationObserverSet::iterator iter = activeMutationObservers().begin(); | 144 MutationObserverSet::iterator iter = activeMutationObservers().begin(); |
142 RefPtr<WebKitMutationObserver> observer = *iter; | 145 RefPtr<WebKitMutationObserver> observer = *iter; |
143 activeMutationObservers().remove(iter); | 146 activeMutationObservers().remove(iter); |
144 observer->deliver(); | 147 observer->deliver(); |
145 } | 148 } |
146 | 149 |
147 deliveryInProgress = false; | 150 deliveryInProgress = false; |
148 } | 151 } |
149 | 152 |
150 } // namespace WebCore | 153 } // namespace WebCore |
151 | 154 |
152 #endif // ENABLE(MUTATION_OBSERVERS) | 155 #endif // ENABLE(MUTATION_OBSERVERS) |
OLD | NEW |