Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: Source/core/dom/ContainerNode.cpp

Issue 375293002: Node.insertBefore and Node.appendChild do not use custom binding anymore (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Take review comment into consideration Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 bool ContainerNode::checkAcceptChildGuaranteedNodeTypes(const Node& newChild, Ex ceptionState& exceptionState) const 170 bool ContainerNode::checkAcceptChildGuaranteedNodeTypes(const Node& newChild, Ex ceptionState& exceptionState) const
171 { 171 {
172 ASSERT(isChildTypeAllowed(newChild)); 172 ASSERT(isChildTypeAllowed(newChild));
173 if (newChild.contains(this)) { 173 if (newChild.contains(this)) {
174 exceptionState.throwDOMException(HierarchyRequestError, "The new child e lement contains the parent."); 174 exceptionState.throwDOMException(HierarchyRequestError, "The new child e lement contains the parent.");
175 return false; 175 return false;
176 } 176 }
177 return true; 177 return true;
178 } 178 }
179 179
180 void ContainerNode::insertBefore(PassRefPtrWillBeRawPtr<Node> newChild, Node* re fChild, ExceptionState& exceptionState) 180 PassRefPtrWillBeRawPtr<Node> ContainerNode::insertBefore(PassRefPtrWillBeRawPtr< Node> newChild, Node* refChild, ExceptionState& exceptionState)
181 { 181 {
182 #if !ENABLE(OILPAN) 182 #if !ENABLE(OILPAN)
183 // Check that this node is not "floating". 183 // Check that this node is not "floating".
184 // If it is, it can be deleted as a side effect of sending mutation events. 184 // If it is, it can be deleted as a side effect of sending mutation events.
185 ASSERT(refCount() || parentOrShadowHostNode()); 185 ASSERT(refCount() || parentOrShadowHostNode());
186 #endif 186 #endif
187 187
188 RefPtrWillBeRawPtr<Node> protect(this); 188 RefPtrWillBeRawPtr<Node> protect(this);
189 189
190 // insertBefore(node, 0) is equivalent to appendChild(node) 190 // insertBefore(node, 0) is equivalent to appendChild(node)
191 if (!refChild) { 191 if (!refChild) {
192 appendChild(newChild, exceptionState); 192 return appendChild(newChild, exceptionState);
193 return;
194 } 193 }
195 194
196 // Make sure adding the new child is OK. 195 // Make sure adding the new child is OK.
197 if (!checkAcceptChild(newChild.get(), 0, exceptionState)) 196 if (!checkAcceptChild(newChild.get(), 0, exceptionState))
198 return; 197 return nullptr;
haraken 2014/07/11 02:18:23 Shall we add ASSERT(exceptionState.hadException())
kangil_ 2014/07/11 02:39:42 Done.
199 ASSERT(newChild); 198 ASSERT(newChild);
200 199
201 // NotFoundError: Raised if refChild is not a child of this node 200 // NotFoundError: Raised if refChild is not a child of this node
202 if (refChild->parentNode() != this) { 201 if (refChild->parentNode() != this) {
203 exceptionState.throwDOMException(NotFoundError, "The node before which t he new node is to be inserted is not a child of this node."); 202 exceptionState.throwDOMException(NotFoundError, "The node before which t he new node is to be inserted is not a child of this node.");
204 return; 203 return nullptr;
205 } 204 }
206 205
207 if (refChild->previousSibling() == newChild || refChild == newChild) // noth ing to do 206 // nothing to do
208 return; 207 if (refChild->previousSibling() == newChild || refChild == newChild)
208 return newChild;
209 209
210 RefPtrWillBeRawPtr<Node> next = refChild; 210 RefPtrWillBeRawPtr<Node> next = refChild;
211 211
212 NodeVector targets; 212 NodeVector targets;
213 collectChildrenAndRemoveFromOldParent(*newChild, targets, exceptionState); 213 collectChildrenAndRemoveFromOldParent(*newChild, targets, exceptionState);
214 if (exceptionState.hadException()) 214 if (exceptionState.hadException())
215 return; 215 return nullptr;
216 if (targets.isEmpty()) 216 if (targets.isEmpty())
217 return; 217 return newChild;
218 218
219 // We need this extra check because collectChildrenAndRemoveFromOldParent() can fire mutation events. 219 // We need this extra check because collectChildrenAndRemoveFromOldParent() can fire mutation events.
220 if (!checkAcceptChildGuaranteedNodeTypes(*newChild, exceptionState)) 220 if (!checkAcceptChildGuaranteedNodeTypes(*newChild, exceptionState))
221 return; 221 return nullptr;
haraken 2014/07/11 02:18:23 Add ASSERT(exceptionState.hadException()).
kangil_ 2014/07/11 02:39:42 Done.
222 222
223 InspectorInstrumentation::willInsertDOMNode(this); 223 InspectorInstrumentation::willInsertDOMNode(this);
224 224
225 ChildListMutationScope mutation(*this); 225 ChildListMutationScope mutation(*this);
226 for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); + +it) { 226 for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); + +it) {
227 ASSERT(*it); 227 ASSERT(*it);
228 Node& child = **it; 228 Node& child = **it;
229 229
230 // Due to arbitrary code running in response to a DOM mutation event it' s 230 // Due to arbitrary code running in response to a DOM mutation event it' s
231 // possible that "next" is no longer a child of "this". 231 // possible that "next" is no longer a child of "this".
232 // It's also possible that "child" has been inserted elsewhere. 232 // It's also possible that "child" has been inserted elsewhere.
233 // In either of those cases, we'll just stop. 233 // In either of those cases, we'll just stop.
234 if (next->parentNode() != this) 234 if (next->parentNode() != this)
235 break; 235 break;
236 if (child.parentNode()) 236 if (child.parentNode())
237 break; 237 break;
238 238
239 treeScope().adoptIfNeeded(child); 239 treeScope().adoptIfNeeded(child);
240 240
241 insertBeforeCommon(*next, child); 241 insertBeforeCommon(*next, child);
242 242
243 updateTreeAfterInsertion(child); 243 updateTreeAfterInsertion(child);
244 } 244 }
245 245
246 dispatchSubtreeModifiedEvent(); 246 dispatchSubtreeModifiedEvent();
247
248 return newChild;
247 } 249 }
248 250
249 void ContainerNode::insertBeforeCommon(Node& nextChild, Node& newChild) 251 void ContainerNode::insertBeforeCommon(Node& nextChild, Node& newChild)
250 { 252 {
251 NoEventDispatchAssertion assertNoEventDispatch; 253 NoEventDispatchAssertion assertNoEventDispatch;
252 ScriptForbiddenScope forbidScript; 254 ScriptForbiddenScope forbidScript;
253 255
254 ASSERT(!newChild.parentNode()); // Use insertBefore if you need to handle re parenting (and want DOM mutation events). 256 ASSERT(!newChild.parentNode()); // Use insertBefore if you need to handle re parenting (and want DOM mutation events).
255 ASSERT(!newChild.nextSibling()); 257 ASSERT(!newChild.nextSibling());
256 ASSERT(!newChild.previousSibling()); 258 ASSERT(!newChild.previousSibling());
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 ChildrenChange change = {AllChildrenRemoved, nullptr, nullptr, ChildrenC hangeSourceAPI}; 587 ChildrenChange change = {AllChildrenRemoved, nullptr, nullptr, ChildrenC hangeSourceAPI};
586 childrenChanged(change); 588 childrenChanged(change);
587 589
588 for (size_t i = 0; i < removedChildren.size(); ++i) 590 for (size_t i = 0; i < removedChildren.size(); ++i)
589 notifyNodeRemoved(*removedChildren[i]); 591 notifyNodeRemoved(*removedChildren[i]);
590 } 592 }
591 593
592 dispatchSubtreeModifiedEvent(); 594 dispatchSubtreeModifiedEvent();
593 } 595 }
594 596
595 void ContainerNode::appendChild(PassRefPtrWillBeRawPtr<Node> newChild, Exception State& exceptionState) 597 PassRefPtrWillBeRawPtr<Node> ContainerNode::appendChild(PassRefPtrWillBeRawPtr<N ode> newChild, ExceptionState& exceptionState)
596 { 598 {
597 RefPtrWillBeRawPtr<ContainerNode> protect(this); 599 RefPtrWillBeRawPtr<ContainerNode> protect(this);
598 600
599 #if !ENABLE(OILPAN) 601 #if !ENABLE(OILPAN)
600 // Check that this node is not "floating". 602 // Check that this node is not "floating".
601 // If it is, it can be deleted as a side effect of sending mutation events. 603 // If it is, it can be deleted as a side effect of sending mutation events.
602 ASSERT(refCount() || parentOrShadowHostNode()); 604 ASSERT(refCount() || parentOrShadowHostNode());
603 #endif 605 #endif
604 606
605 // Make sure adding the new child is ok 607 // Make sure adding the new child is ok
606 if (!checkAcceptChild(newChild.get(), 0, exceptionState)) 608 if (!checkAcceptChild(newChild.get(), 0, exceptionState))
607 return; 609 return nullptr;
haraken 2014/07/11 02:18:23 Add ASSERT(exceptionState.hadException()).
kangil_ 2014/07/11 02:39:42 Done.
608 ASSERT(newChild); 610 ASSERT(newChild);
609 611
610 if (newChild == m_lastChild) // nothing to do 612 if (newChild == m_lastChild) // nothing to do
611 return; 613 return newChild;
612 614
613 NodeVector targets; 615 NodeVector targets;
614 collectChildrenAndRemoveFromOldParent(*newChild, targets, exceptionState); 616 collectChildrenAndRemoveFromOldParent(*newChild, targets, exceptionState);
615 if (exceptionState.hadException()) 617 if (exceptionState.hadException())
616 return; 618 return nullptr;
617 619
618 if (targets.isEmpty()) 620 if (targets.isEmpty())
619 return; 621 return newChild;
620 622
621 // We need this extra check because collectChildrenAndRemoveFromOldParent() can fire mutation events. 623 // We need this extra check because collectChildrenAndRemoveFromOldParent() can fire mutation events.
622 if (!checkAcceptChildGuaranteedNodeTypes(*newChild, exceptionState)) 624 if (!checkAcceptChildGuaranteedNodeTypes(*newChild, exceptionState))
623 return; 625 return nullptr;
haraken 2014/07/11 02:18:23 Add ASSERT(exceptionState.hadException()).
kangil_ 2014/07/11 02:39:42 Done.
624 626
625 InspectorInstrumentation::willInsertDOMNode(this); 627 InspectorInstrumentation::willInsertDOMNode(this);
626 628
627 // Now actually add the child(ren) 629 // Now actually add the child(ren)
628 ChildListMutationScope mutation(*this); 630 ChildListMutationScope mutation(*this);
629 for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); + +it) { 631 for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); + +it) {
630 ASSERT(*it); 632 ASSERT(*it);
631 Node& child = **it; 633 Node& child = **it;
632 634
633 // If the child has a parent again, just stop what we're doing, because 635 // If the child has a parent again, just stop what we're doing, because
634 // that means someone is doing something with DOM mutation -- can't re-p arent 636 // that means someone is doing something with DOM mutation -- can't re-p arent
635 // a child that already has a parent. 637 // a child that already has a parent.
636 if (child.parentNode()) 638 if (child.parentNode())
637 break; 639 break;
638 640
639 { 641 {
640 NoEventDispatchAssertion assertNoEventDispatch; 642 NoEventDispatchAssertion assertNoEventDispatch;
641 ScriptForbiddenScope forbidScript; 643 ScriptForbiddenScope forbidScript;
642 644
643 treeScope().adoptIfNeeded(child); 645 treeScope().adoptIfNeeded(child);
644 appendChildCommon(child); 646 appendChildCommon(child);
645 } 647 }
646 648
647 updateTreeAfterInsertion(child); 649 updateTreeAfterInsertion(child);
648 } 650 }
649 651
650 dispatchSubtreeModifiedEvent(); 652 dispatchSubtreeModifiedEvent();
653 return newChild;
651 } 654 }
652 655
653 void ContainerNode::parserAppendChild(PassRefPtrWillBeRawPtr<Node> newChild) 656 void ContainerNode::parserAppendChild(PassRefPtrWillBeRawPtr<Node> newChild)
654 { 657 {
655 ASSERT(newChild); 658 ASSERT(newChild);
656 ASSERT(!newChild->parentNode()); // Use appendChild if you need to handle re parenting (and want DOM mutation events). 659 ASSERT(!newChild->parentNode()); // Use appendChild if you need to handle re parenting (and want DOM mutation events).
657 ASSERT(!newChild->isDocumentFragment()); 660 ASSERT(!newChild->isDocumentFragment());
658 ASSERT(!isHTMLTemplateElement(this)); 661 ASSERT(!isHTMLTemplateElement(this));
659 662
660 if (document() != newChild->document()) 663 if (document() != newChild->document())
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 return true; 1297 return true;
1295 1298
1296 if (node->isElementNode() && toElement(node)->shadow()) 1299 if (node->isElementNode() && toElement(node)->shadow())
1297 return true; 1300 return true;
1298 1301
1299 return false; 1302 return false;
1300 } 1303 }
1301 #endif 1304 #endif
1302 1305
1303 } // namespace WebCore 1306 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698