| 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 15 matching lines...) Expand all Loading... |
| 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 <algorithm> | 34 #include <algorithm> |
| 35 #include "bindings/v8/Dictionary.h" | 35 #include "bindings/v8/Dictionary.h" |
| 36 #include "bindings/v8/ExceptionMessages.h" | |
| 37 #include "bindings/v8/ExceptionState.h" | 36 #include "bindings/v8/ExceptionState.h" |
| 38 #include "core/dom/Document.h" | 37 #include "core/dom/Document.h" |
| 39 #include "core/dom/ExceptionCode.h" | 38 #include "core/dom/ExceptionCode.h" |
| 40 #include "core/dom/MutationCallback.h" | 39 #include "core/dom/MutationCallback.h" |
| 41 #include "core/dom/MutationObserverRegistration.h" | 40 #include "core/dom/MutationObserverRegistration.h" |
| 42 #include "core/dom/MutationRecord.h" | 41 #include "core/dom/MutationRecord.h" |
| 43 #include "core/dom/Node.h" | 42 #include "core/dom/Node.h" |
| 44 #include "wtf/MainThread.h" | 43 #include "wtf/MainThread.h" |
| 45 | 44 |
| 46 namespace WebCore { | 45 namespace WebCore { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 68 } | 67 } |
| 69 | 68 |
| 70 MutationObserver::~MutationObserver() | 69 MutationObserver::~MutationObserver() |
| 71 { | 70 { |
| 72 ASSERT(m_registrations.isEmpty()); | 71 ASSERT(m_registrations.isEmpty()); |
| 73 } | 72 } |
| 74 | 73 |
| 75 void MutationObserver::observe(Node* node, const Dictionary& optionsDictionary,
ExceptionState& exceptionState) | 74 void MutationObserver::observe(Node* node, const Dictionary& optionsDictionary,
ExceptionState& exceptionState) |
| 76 { | 75 { |
| 77 if (!node) { | 76 if (!node) { |
| 78 exceptionState.throwDOMException(NotFoundError, ExceptionMessages::faile
dToExecute("observe", "MutationObserver", "The provided node was null.")); | 77 exceptionState.throwDOMException(NotFoundError, "The provided node was n
ull."); |
| 79 return; | 78 return; |
| 80 } | 79 } |
| 81 | 80 |
| 82 MutationObserverOptions options = 0; | 81 MutationObserverOptions options = 0; |
| 83 | 82 |
| 84 bool attributeOldValue = false; | 83 bool attributeOldValue = false; |
| 85 bool attributeOldValuePresent = optionsDictionary.get("attributeOldValue", a
ttributeOldValue); | 84 bool attributeOldValuePresent = optionsDictionary.get("attributeOldValue", a
ttributeOldValue); |
| 86 if (attributeOldValue) | 85 if (attributeOldValue) |
| 87 options |= AttributeOldValue; | 86 options |= AttributeOldValue; |
| 88 | 87 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 109 bool childListValue = false; | 108 bool childListValue = false; |
| 110 if (optionsDictionary.get("childList", childListValue) && childListValue) | 109 if (optionsDictionary.get("childList", childListValue) && childListValue) |
| 111 options |= ChildList; | 110 options |= ChildList; |
| 112 | 111 |
| 113 bool subtreeValue = false; | 112 bool subtreeValue = false; |
| 114 if (optionsDictionary.get("subtree", subtreeValue) && subtreeValue) | 113 if (optionsDictionary.get("subtree", subtreeValue) && subtreeValue) |
| 115 options |= Subtree; | 114 options |= Subtree; |
| 116 | 115 |
| 117 if (!(options & Attributes)) { | 116 if (!(options & Attributes)) { |
| 118 if (options & AttributeOldValue) { | 117 if (options & AttributeOldValue) { |
| 119 exceptionState.throwDOMException(TypeError, ExceptionMessages::faile
dToExecute("observe", "MutationObserver", "The options object may only set 'attr
ibuteOldValue' to true when 'attributes' is true or not present.")); | 118 exceptionState.throwDOMException(TypeError, "The options object may
only set 'attributeOldValue' to true when 'attributes' is true or not present.")
; |
| 120 return; | 119 return; |
| 121 } | 120 } |
| 122 if (options & AttributeFilter) { | 121 if (options & AttributeFilter) { |
| 123 exceptionState.throwDOMException(TypeError, ExceptionMessages::faile
dToExecute("observe", "MutationObserver", "The options object may only set 'attr
ibuteFilter' when 'attributes' is true or not present.")); | 122 exceptionState.throwDOMException(TypeError, "The options object may
only set 'attributeFilter' when 'attributes' is true or not present."); |
| 124 return; | 123 return; |
| 125 } | 124 } |
| 126 } | 125 } |
| 127 if (!((options & CharacterData) || !(options & CharacterDataOldValue))) { | 126 if (!((options & CharacterData) || !(options & CharacterDataOldValue))) { |
| 128 exceptionState.throwDOMException(TypeError, ExceptionMessages::failedToE
xecute("observe", "MutationObserver", "The options object may only set 'characte
rDataOldValue' to true when 'characterData' is true or not present.")); | 127 exceptionState.throwDOMException(TypeError, "The options object may only
set 'characterDataOldValue' to true when 'characterData' is true or not present
."); |
| 129 return; | 128 return; |
| 130 } | 129 } |
| 131 | 130 |
| 132 if (!(options & (Attributes | CharacterData | ChildList))) { | 131 if (!(options & (Attributes | CharacterData | ChildList))) { |
| 133 exceptionState.throwDOMException(TypeError, ExceptionMessages::failedToE
xecute("observe", "MutationObserver", "The options object must set at least one
of 'attributes', 'characterData', or 'childList' to true.")); | 132 exceptionState.throwDOMException(TypeError, "The options object must set
at least one of 'attributes', 'characterData', or 'childList' to true."); |
| 134 return; | 133 return; |
| 135 } | 134 } |
| 136 | 135 |
| 137 node->registerMutationObserver(this, options, attributeFilter); | 136 node->registerMutationObserver(this, options, attributeFilter); |
| 138 } | 137 } |
| 139 | 138 |
| 140 Vector<RefPtr<MutationRecord> > MutationObserver::takeRecords() | 139 Vector<RefPtr<MutationRecord> > MutationObserver::takeRecords() |
| 141 { | 140 { |
| 142 Vector<RefPtr<MutationRecord> > records; | 141 Vector<RefPtr<MutationRecord> > records; |
| 143 records.swap(m_records); | 142 records.swap(m_records); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 observers[i]->deliver(); | 256 observers[i]->deliver(); |
| 258 else | 257 else |
| 259 suspendedMutationObservers().add(observers[i]); | 258 suspendedMutationObservers().add(observers[i]); |
| 260 } | 259 } |
| 261 } | 260 } |
| 262 | 261 |
| 263 deliveryInProgress = false; | 262 deliveryInProgress = false; |
| 264 } | 263 } |
| 265 | 264 |
| 266 } // namespace WebCore | 265 } // namespace WebCore |
| OLD | NEW |