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 #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" | 34 #include "bindings/core/v8/Dictionary.h" |
| 35 #include "bindings/core/v8/DictionaryHelper.h" |
35 #include "bindings/core/v8/ExceptionState.h" | 36 #include "bindings/core/v8/ExceptionState.h" |
36 #include "core/dom/ExceptionCode.h" | 37 #include "core/dom/ExceptionCode.h" |
37 #include "core/dom/Microtask.h" | 38 #include "core/dom/Microtask.h" |
38 #include "core/dom/MutationCallback.h" | 39 #include "core/dom/MutationCallback.h" |
39 #include "core/dom/MutationObserverRegistration.h" | 40 #include "core/dom/MutationObserverRegistration.h" |
40 #include "core/dom/MutationRecord.h" | 41 #include "core/dom/MutationRecord.h" |
41 #include "core/dom/Node.h" | 42 #include "core/dom/Node.h" |
42 #include "core/inspector/InspectorInstrumentation.h" | 43 #include "core/inspector/InspectorInstrumentation.h" |
43 #include "wtf/MainThread.h" | 44 #include "wtf/MainThread.h" |
44 #include <algorithm> | 45 #include <algorithm> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 void MutationObserver::observe(Node* node, const Dictionary& optionsDictionary,
ExceptionState& exceptionState) | 80 void MutationObserver::observe(Node* node, const Dictionary& optionsDictionary,
ExceptionState& exceptionState) |
80 { | 81 { |
81 if (!node) { | 82 if (!node) { |
82 exceptionState.throwDOMException(NotFoundError, "The provided node was n
ull."); | 83 exceptionState.throwDOMException(NotFoundError, "The provided node was n
ull."); |
83 return; | 84 return; |
84 } | 85 } |
85 | 86 |
86 MutationObserverOptions options = 0; | 87 MutationObserverOptions options = 0; |
87 | 88 |
88 bool attributeOldValue = false; | 89 bool attributeOldValue = false; |
89 bool attributeOldValuePresent = optionsDictionary.get("attributeOldValue", a
ttributeOldValue); | 90 bool attributeOldValuePresent = DictionaryHelper::get(optionsDictionary, "at
tributeOldValue", attributeOldValue); |
90 if (attributeOldValue) | 91 if (attributeOldValue) |
91 options |= AttributeOldValue; | 92 options |= AttributeOldValue; |
92 | 93 |
93 HashSet<AtomicString> attributeFilter; | 94 HashSet<AtomicString> attributeFilter; |
94 bool attributeFilterPresent = optionsDictionary.get("attributeFilter", attri
buteFilter); | 95 bool attributeFilterPresent = DictionaryHelper::get(optionsDictionary, "attr
ibuteFilter", attributeFilter); |
95 if (attributeFilterPresent) | 96 if (attributeFilterPresent) |
96 options |= AttributeFilter; | 97 options |= AttributeFilter; |
97 | 98 |
98 bool attributes = false; | 99 bool attributes = false; |
99 bool attributesPresent = optionsDictionary.get("attributes", attributes); | 100 bool attributesPresent = DictionaryHelper::get(optionsDictionary, "attribute
s", attributes); |
100 if (attributes || (!attributesPresent && (attributeOldValuePresent || attrib
uteFilterPresent))) | 101 if (attributes || (!attributesPresent && (attributeOldValuePresent || attrib
uteFilterPresent))) |
101 options |= Attributes; | 102 options |= Attributes; |
102 | 103 |
103 bool characterDataOldValue = false; | 104 bool characterDataOldValue = false; |
104 bool characterDataOldValuePresent = optionsDictionary.get("characterDataOldV
alue", characterDataOldValue); | 105 bool characterDataOldValuePresent = DictionaryHelper::get(optionsDictionary,
"characterDataOldValue", characterDataOldValue); |
105 if (characterDataOldValue) | 106 if (characterDataOldValue) |
106 options |= CharacterDataOldValue; | 107 options |= CharacterDataOldValue; |
107 | 108 |
108 bool characterData = false; | 109 bool characterData = false; |
109 bool characterDataPresent = optionsDictionary.get("characterData", character
Data); | 110 bool characterDataPresent = DictionaryHelper::get(optionsDictionary, "charac
terData", characterData); |
110 if (characterData || (!characterDataPresent && characterDataOldValuePresent)
) | 111 if (characterData || (!characterDataPresent && characterDataOldValuePresent)
) |
111 options |= CharacterData; | 112 options |= CharacterData; |
112 | 113 |
113 bool childListValue = false; | 114 bool childListValue = false; |
114 if (optionsDictionary.get("childList", childListValue) && childListValue) | 115 if (DictionaryHelper::get(optionsDictionary, "childList", childListValue) &&
childListValue) |
115 options |= ChildList; | 116 options |= ChildList; |
116 | 117 |
117 bool subtreeValue = false; | 118 bool subtreeValue = false; |
118 if (optionsDictionary.get("subtree", subtreeValue) && subtreeValue) | 119 if (DictionaryHelper::get(optionsDictionary, "subtree", subtreeValue) && sub
treeValue) |
119 options |= Subtree; | 120 options |= Subtree; |
120 | 121 |
121 if (!(options & Attributes)) { | 122 if (!(options & Attributes)) { |
122 if (options & AttributeOldValue) { | 123 if (options & AttributeOldValue) { |
123 exceptionState.throwTypeError("The options object may only set 'attr
ibuteOldValue' to true when 'attributes' is true or not present."); | 124 exceptionState.throwTypeError("The options object may only set 'attr
ibuteOldValue' to true when 'attributes' is true or not present."); |
124 return; | 125 return; |
125 } | 126 } |
126 if (options & AttributeFilter) { | 127 if (options & AttributeFilter) { |
127 exceptionState.throwTypeError("The options object may only set 'attr
ibuteFilter' when 'attributes' is true or not present."); | 128 exceptionState.throwTypeError("The options object may only set 'attr
ibuteFilter' when 'attributes' is true or not present."); |
128 return; | 129 return; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 } | 275 } |
275 } | 276 } |
276 | 277 |
277 void MutationObserver::trace(Visitor* visitor) | 278 void MutationObserver::trace(Visitor* visitor) |
278 { | 279 { |
279 visitor->trace(m_records); | 280 visitor->trace(m_records); |
280 visitor->trace(m_registrations); | 281 visitor->trace(m_registrations); |
281 } | 282 } |
282 | 283 |
283 } // namespace WebCore | 284 } // namespace WebCore |
OLD | NEW |