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 14 matching lines...) Expand all Loading... | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef MutationObserver_h | 31 #ifndef MutationObserver_h |
| 32 #define MutationObserver_h | 32 #define MutationObserver_h |
| 33 | 33 |
| 34 #include "bindings/v8/ScriptWrappable.h" | 34 #include "bindings/v8/ScriptWrappable.h" |
| 35 #include "platform/heap/Handle.h" | |
| 35 #include "wtf/HashSet.h" | 36 #include "wtf/HashSet.h" |
| 36 #include "wtf/PassOwnPtr.h" | 37 #include "wtf/PassOwnPtr.h" |
| 37 #include "wtf/PassRefPtr.h" | 38 #include "wtf/PassRefPtr.h" |
| 38 #include "wtf/RefCounted.h" | 39 #include "wtf/RefCounted.h" |
| 39 #include "wtf/RefPtr.h" | 40 #include "wtf/RefPtr.h" |
| 40 #include "wtf/Vector.h" | 41 #include "wtf/Vector.h" |
| 41 | 42 |
| 42 namespace WebCore { | 43 namespace WebCore { |
| 43 | 44 |
| 44 class Dictionary; | 45 class Dictionary; |
| 45 class ExceptionState; | 46 class ExceptionState; |
| 46 class MutationCallback; | 47 class MutationCallback; |
| 47 class MutationObserverRegistration; | 48 class MutationObserverRegistration; |
| 48 class MutationRecord; | 49 class MutationRecord; |
| 49 class Node; | 50 class Node; |
| 50 | 51 |
| 51 typedef unsigned char MutationObserverOptions; | 52 typedef unsigned char MutationObserverOptions; |
| 52 typedef unsigned char MutationRecordDeliveryOptions; | 53 typedef unsigned char MutationRecordDeliveryOptions; |
| 53 | 54 |
| 54 class MutationObserver : public RefCounted<MutationObserver>, public ScriptWrapp able { | 55 class MutationObserver FINAL : public RefCountedWillBeGarbageCollectedFinalized< MutationObserver>, public ScriptWrappable { |
| 55 public: | 56 public: |
| 56 enum MutationType { | 57 enum MutationType { |
| 57 ChildList = 1 << 0, | 58 ChildList = 1 << 0, |
| 58 Attributes = 1 << 1, | 59 Attributes = 1 << 1, |
| 59 CharacterData = 1 << 2, | 60 CharacterData = 1 << 2, |
| 60 | 61 |
| 61 AllMutationTypes = ChildList | Attributes | CharacterData | 62 AllMutationTypes = ChildList | Attributes | CharacterData |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 enum ObservationFlags { | 65 enum ObservationFlags { |
| 65 Subtree = 1 << 3, | 66 Subtree = 1 << 3, |
| 66 AttributeFilter = 1 << 4 | 67 AttributeFilter = 1 << 4 |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 enum DeliveryFlags { | 70 enum DeliveryFlags { |
| 70 AttributeOldValue = 1 << 5, | 71 AttributeOldValue = 1 << 5, |
| 71 CharacterDataOldValue = 1 << 6, | 72 CharacterDataOldValue = 1 << 6, |
| 72 }; | 73 }; |
| 73 | 74 |
| 74 static PassRefPtr<MutationObserver> create(PassOwnPtr<MutationCallback>); | 75 static PassRefPtrWillBeRawPtr<MutationObserver> create(PassOwnPtr<MutationCa llback>); |
| 75 static void resumeSuspendedObservers(); | 76 static void resumeSuspendedObservers(); |
| 76 static void deliverMutations(); | 77 static void deliverMutations(); |
| 77 | 78 |
| 78 ~MutationObserver(); | 79 ~MutationObserver(); |
| 79 | 80 |
| 80 void observe(Node*, const Dictionary&, ExceptionState&); | 81 void observe(Node*, const Dictionary&, ExceptionState&); |
| 81 Vector<RefPtr<MutationRecord> > takeRecords(); | 82 WillBeHeapVector<RefPtrWillBeMember<MutationRecord> > takeRecords(); |
| 82 void disconnect(); | 83 void disconnect(); |
| 83 void observationStarted(MutationObserverRegistration*); | 84 void observationStarted(MutationObserverRegistration*); |
| 84 void observationEnded(MutationObserverRegistration*); | 85 void observationEnded(MutationObserverRegistration*); |
| 85 void enqueueMutationRecord(PassRefPtr<MutationRecord>); | 86 void enqueueMutationRecord(PassRefPtrWillBeRawPtr<MutationRecord>); |
| 86 void setHasTransientRegistration(); | 87 void setHasTransientRegistration(); |
| 87 bool canDeliver(); | 88 bool canDeliver(); |
| 88 | 89 |
| 89 HashSet<Node*> getObservedNodes() const; | 90 HashSet<Node*> getObservedNodes() const; |
| 90 | 91 |
| 92 void trace(Visitor*); | |
| 93 | |
| 91 private: | 94 private: |
| 92 struct ObserverLessThan; | 95 struct ObserverLessThan; |
| 93 | 96 |
| 94 explicit MutationObserver(PassOwnPtr<MutationCallback>); | 97 explicit MutationObserver(PassOwnPtr<MutationCallback>); |
| 95 void deliver(); | 98 void deliver(); |
| 96 | 99 |
| 97 OwnPtr<MutationCallback> m_callback; | 100 OwnPtr<MutationCallback> m_callback; |
| 98 Vector<RefPtr<MutationRecord> > m_records; | 101 WillBeHeapVector<RefPtrWillBeMember<MutationRecord> > m_records; |
| 99 HashSet<MutationObserverRegistration*> m_registrations; | 102 WillBeHeapHashSet<RawPtrWillBeWeakMember<MutationObserverRegistration> > m_r egistrations; |
|
haraken
2014/04/21 06:00:34
Does this need to be a hash set of weak members? I
sof
2014/04/21 07:34:05
Doesn't have to be, but it was requested it be so
haraken
2014/04/21 07:41:31
Or can we keep it a weak member and comment out Mu
sof
2014/04/21 07:43:51
No, that won't work. Please see comments earlier,
haraken
2014/04/21 07:45:46
ah, remembered, sorry about the confusion. Then it
sof
2014/04/21 12:45:16
I've switched away from weak members on MutationOb
| |
| 100 unsigned m_priority; | 103 unsigned m_priority; |
| 101 }; | 104 }; |
| 102 | 105 |
| 103 } | 106 } |
| 104 | 107 |
| 105 #endif // MutationObserver_h | 108 #endif // MutationObserver_h |
| OLD | NEW |