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

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

Issue 443103002: Range.insertNode should verify parent before setting end to it (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 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 * (C) 1999 Lars Knoll (knoll@kde.org) 2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no) 3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no)
4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no) 4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no)
5 * (C) 2001 Peter Kelly (pmk@post.com) 5 * (C) 2001 Peter Kelly (pmk@post.com)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
7 * Copyright (C) 2011 Motorola Mobility. All rights reserved. 7 * Copyright (C) 2011 Motorola Mobility. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 container = m_start.container(); 887 container = m_start.container();
888 RefPtrWillBeRawPtr<Text> newText = toText(container)->splitText(m_start. offset(), exceptionState); 888 RefPtrWillBeRawPtr<Text> newText = toText(container)->splitText(m_start. offset(), exceptionState);
889 if (exceptionState.hadException()) 889 if (exceptionState.hadException())
890 return; 890 return;
891 891
892 container = m_start.container(); 892 container = m_start.container();
893 container->parentNode()->insertBefore(newNode.release(), newText.get(), exceptionState); 893 container->parentNode()->insertBefore(newNode.release(), newText.get(), exceptionState);
894 if (exceptionState.hadException()) 894 if (exceptionState.hadException())
895 return; 895 return;
896 896
897 if (collapsed) 897 if (collapsed) {
898 if (!newText->parentNode()) {
Yuta Kitamura 2014/08/07 09:30:41 I wonder how newText->parentNode() becomes null.
kangil_ 2014/08/07 09:59:50 insertBefore() will trigger Container::insertBefor
Yuta Kitamura 2014/08/08 04:27:55 That's weird. We are within a scope of EventQueueS
kangil_ 2014/08/08 04:52:25 load event is fired. When range.surroundContents(
Yuta Kitamura 2014/08/08 05:25:07 I'm lost somewhere between ContainerNode::notifyNo
899 exceptionState.throwDOMException(HierarchyRequestError, "This op eration would set range's end to parent with new offset, but there's no parent i nto which to continue.");
900 return;
901 }
898 m_end.setToBeforeChild(*newText); 902 m_end.setToBeforeChild(*newText);
903 }
899 } else { 904 } else {
900 RefPtrWillBeRawPtr<Node> lastChild = (newNodeType == Node::DOCUMENT_FRAG MENT_NODE) ? toDocumentFragment(newNode)->lastChild() : newNode.get(); 905 RefPtrWillBeRawPtr<Node> lastChild = (newNodeType == Node::DOCUMENT_FRAG MENT_NODE) ? toDocumentFragment(newNode)->lastChild() : newNode.get();
901 if (lastChild && lastChild == m_start.childBefore()) { 906 if (lastChild && lastChild == m_start.childBefore()) {
902 // The insertion will do nothing, but we need to extend the range to include 907 // The insertion will do nothing, but we need to extend the range to include
903 // the inserted nodes. 908 // the inserted nodes.
904 Node* firstChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? t oDocumentFragment(newNode)->firstChild() : newNode.get(); 909 Node* firstChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? t oDocumentFragment(newNode)->firstChild() : newNode.get();
905 ASSERT(firstChild); 910 ASSERT(firstChild);
906 m_start.setToBeforeChild(*firstChild); 911 m_start.setToBeforeChild(*firstChild);
907 return; 912 return;
908 } 913 }
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 1707
1703 void showTree(const blink::Range* range) 1708 void showTree(const blink::Range* range)
1704 { 1709 {
1705 if (range && range->boundaryPointsValid()) { 1710 if (range && range->boundaryPointsValid()) {
1706 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); 1711 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E");
1707 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); 1712 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset());
1708 } 1713 }
1709 } 1714 }
1710 1715
1711 #endif 1716 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698