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 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 #include "config.h" | 31 #include "config.h" |
32 #include "core/dom/MutationObserver.h" | 32 #include "core/dom/MutationObserver.h" |
33 | 33 |
34 #include "bindings/core/v8/Dictionary.h" | |
35 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
36 #include "core/dom/ExceptionCode.h" | 35 #include "core/dom/ExceptionCode.h" |
37 #include "core/dom/Microtask.h" | 36 #include "core/dom/Microtask.h" |
38 #include "core/dom/MutationCallback.h" | 37 #include "core/dom/MutationCallback.h" |
| 38 #include "core/dom/MutationObserverInit.h" |
39 #include "core/dom/MutationObserverRegistration.h" | 39 #include "core/dom/MutationObserverRegistration.h" |
40 #include "core/dom/MutationRecord.h" | 40 #include "core/dom/MutationRecord.h" |
41 #include "core/dom/Node.h" | 41 #include "core/dom/Node.h" |
42 #include "core/inspector/InspectorInstrumentation.h" | 42 #include "core/inspector/InspectorInstrumentation.h" |
43 #include "wtf/MainThread.h" | 43 #include "wtf/MainThread.h" |
44 #include <algorithm> | 44 #include <algorithm> |
45 | 45 |
46 namespace blink { | 46 namespace blink { |
47 | 47 |
48 static unsigned s_observerPriority = 0; | 48 static unsigned s_observerPriority = 0; |
(...skipping 19 matching lines...) Expand all Loading... |
68 | 68 |
69 MutationObserver::~MutationObserver() | 69 MutationObserver::~MutationObserver() |
70 { | 70 { |
71 #if !ENABLE(OILPAN) | 71 #if !ENABLE(OILPAN) |
72 ASSERT(m_registrations.isEmpty()); | 72 ASSERT(m_registrations.isEmpty()); |
73 #endif | 73 #endif |
74 if (!m_records.isEmpty()) | 74 if (!m_records.isEmpty()) |
75 InspectorInstrumentation::didClearAllMutationRecords(m_callback->executi
onContext(), this); | 75 InspectorInstrumentation::didClearAllMutationRecords(m_callback->executi
onContext(), this); |
76 } | 76 } |
77 | 77 |
78 void MutationObserver::observe(Node* node, const Dictionary& optionsDictionary,
ExceptionState& exceptionState) | 78 void MutationObserver::observe(Node* node, const MutationObserverInit& observerI
nit, ExceptionState& exceptionState) |
79 { | 79 { |
80 if (!node) { | 80 if (!node) { |
81 exceptionState.throwDOMException(NotFoundError, "The provided node was n
ull."); | 81 exceptionState.throwDOMException(NotFoundError, "The provided node was n
ull."); |
82 return; | 82 return; |
83 } | 83 } |
84 | 84 |
85 MutationObserverOptions options = 0; | 85 MutationObserverOptions options = 0; |
86 | 86 |
87 bool attributeOldValue = false; | 87 if (observerInit.hasAttributeOldValue() && observerInit.attributeOldValue()) |
88 bool attributeOldValuePresent = DictionaryHelper::get(optionsDictionary, "at
tributeOldValue", attributeOldValue); | |
89 if (attributeOldValue) | |
90 options |= AttributeOldValue; | 88 options |= AttributeOldValue; |
91 | 89 |
92 HashSet<AtomicString> attributeFilter; | 90 HashSet<AtomicString> attributeFilter; |
93 bool attributeFilterPresent = DictionaryHelper::get(optionsDictionary, "attr
ibuteFilter", attributeFilter); | 91 if (observerInit.hasAttributeFilter()) { |
94 if (attributeFilterPresent) | 92 const Vector<String>& sequence = observerInit.attributeFilter(); |
| 93 for (unsigned i = 0; i < sequence.size(); ++i) |
| 94 attributeFilter.add(AtomicString(sequence[i])); |
95 options |= AttributeFilter; | 95 options |= AttributeFilter; |
| 96 } |
96 | 97 |
97 bool attributes = false; | 98 bool attributes = observerInit.hasAttributes() && observerInit.attributes(); |
98 bool attributesPresent = DictionaryHelper::get(optionsDictionary, "attribute
s", attributes); | 99 if (attributes || (!observerInit.hasAttributes() && (observerInit.hasAttribu
teOldValue() || observerInit.hasAttributeFilter()))) |
99 if (attributes || (!attributesPresent && (attributeOldValuePresent || attrib
uteFilterPresent))) | |
100 options |= Attributes; | 100 options |= Attributes; |
101 | 101 |
102 bool characterDataOldValue = false; | 102 if (observerInit.hasCharacterDataOldValue() && observerInit.characterDataOld
Value()) |
103 bool characterDataOldValuePresent = DictionaryHelper::get(optionsDictionary,
"characterDataOldValue", characterDataOldValue); | |
104 if (characterDataOldValue) | |
105 options |= CharacterDataOldValue; | 103 options |= CharacterDataOldValue; |
106 | 104 |
107 bool characterData = false; | 105 bool characterData = observerInit.hasCharacterData() && observerInit.charact
erData(); |
108 bool characterDataPresent = DictionaryHelper::get(optionsDictionary, "charac
terData", characterData); | 106 if (characterData || (!observerInit.hasCharacterData() && observerInit.hasCh
aracterDataOldValue())) |
109 if (characterData || (!characterDataPresent && characterDataOldValuePresent)
) | |
110 options |= CharacterData; | 107 options |= CharacterData; |
111 | 108 |
112 bool childListValue = false; | 109 if (observerInit.childList()) |
113 if (DictionaryHelper::get(optionsDictionary, "childList", childListValue) &&
childListValue) | |
114 options |= ChildList; | 110 options |= ChildList; |
115 | 111 |
116 bool subtreeValue = false; | 112 if (observerInit.subtree()) |
117 if (DictionaryHelper::get(optionsDictionary, "subtree", subtreeValue) && sub
treeValue) | |
118 options |= Subtree; | 113 options |= Subtree; |
119 | 114 |
120 if (!(options & Attributes)) { | 115 if (!(options & Attributes)) { |
121 if (options & AttributeOldValue) { | 116 if (options & AttributeOldValue) { |
122 exceptionState.throwTypeError("The options object may only set 'attr
ibuteOldValue' to true when 'attributes' is true or not present."); | 117 exceptionState.throwTypeError("The options object may only set 'attr
ibuteOldValue' to true when 'attributes' is true or not present."); |
123 return; | 118 return; |
124 } | 119 } |
125 if (options & AttributeFilter) { | 120 if (options & AttributeFilter) { |
126 exceptionState.throwTypeError("The options object may only set 'attr
ibuteFilter' when 'attributes' is true or not present."); | 121 exceptionState.throwTypeError("The options object may only set 'attr
ibuteFilter' when 'attributes' is true or not present."); |
127 return; | 122 return; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 270 |
276 void MutationObserver::trace(Visitor* visitor) | 271 void MutationObserver::trace(Visitor* visitor) |
277 { | 272 { |
278 #if ENABLE(OILPAN) | 273 #if ENABLE(OILPAN) |
279 visitor->trace(m_records); | 274 visitor->trace(m_records); |
280 visitor->trace(m_registrations); | 275 visitor->trace(m_registrations); |
281 #endif | 276 #endif |
282 } | 277 } |
283 | 278 |
284 } // namespace blink | 279 } // namespace blink |
OLD | NEW |