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

Side by Side Diff: Source/core/editing/markup.cpp

Issue 115693010: Fix Range.createContextualFragment for non-Element contexts. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressed 3rd round of feedback. Created 6 years, 6 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
« Source/core/dom/Range.cpp ('K') | « Source/core/editing/markup.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved.
4 * Copyright (C) 2011 Igalia S.L. 4 * Copyright (C) 2011 Igalia S.L.
5 * Copyright (C) 2011 Motorola Mobility. All rights reserved. 5 * Copyright (C) 2011 Motorola Mobility. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 { 968 {
969 RefPtr<Node> nextChild; 969 RefPtr<Node> nextChild;
970 for (RefPtr<Node> child = element->firstChild(); child; child = nextChild) { 970 for (RefPtr<Node> child = element->firstChild(); child; child = nextChild) {
971 nextChild = child->nextSibling(); 971 nextChild = child->nextSibling();
972 element->removeChild(child.get()); 972 element->removeChild(child.get());
973 fragment->insertBefore(child, element); 973 fragment->insertBefore(child, element);
974 } 974 }
975 fragment->removeChild(element); 975 fragment->removeChild(element);
976 } 976 }
977 977
978 PassRefPtrWillBeRawPtr<DocumentFragment> createContextualFragment(const String& markup, HTMLElement* element, ParserContentPolicy parserContentPolicy, Exception State& exceptionState) 978 static inline bool isSupportedContainer(Element* element)
979 { 979 {
980 ASSERT(element); 980 ASSERT(element);
981 if (element->ieForbidsInsertHTML() || element->hasLocalName(colTag) || eleme nt->hasLocalName(colgroupTag) || element->hasLocalName(framesetTag) 981 if (!element->isHTMLElement())
982 return true;
983
984 if (element->hasLocalName(colTag) || element->hasLocalName(colgroupTag) || e lement->hasLocalName(framesetTag)
982 || element->hasLocalName(headTag) || element->hasLocalName(styleTag) || element->hasLocalName(titleTag)) { 985 || element->hasLocalName(headTag) || element->hasLocalName(styleTag) || element->hasLocalName(titleTag)) {
986 return false;
987 }
988 return !toHTMLElement(element)->ieForbidsInsertHTML();
989 }
990
991 PassRefPtrWillBeRawPtr<DocumentFragment> createContextualFragment(const String& markup, Element* element, ParserContentPolicy parserContentPolicy, ExceptionStat e& exceptionState)
992 {
993 ASSERT(element);
994 if (!isSupportedContainer(element)) {
983 exceptionState.throwDOMException(NotSupportedError, "The range's contain er is '" + element->localName() + "', which is not supported."); 995 exceptionState.throwDOMException(NotSupportedError, "The range's contain er is '" + element->localName() + "', which is not supported.");
984 return nullptr; 996 return nullptr;
985 } 997 }
986 998
987 RefPtrWillBeRawPtr<DocumentFragment> fragment = createFragmentForInnerOuterH TML(markup, element, parserContentPolicy, "createContextualFragment", exceptionS tate); 999 RefPtrWillBeRawPtr<DocumentFragment> fragment = createFragmentForInnerOuterH TML(markup, element, parserContentPolicy, "createContextualFragment", exceptionS tate);
988 if (!fragment) 1000 if (!fragment)
989 return nullptr; 1001 return nullptr;
990 1002
991 // We need to pop <html> and <body> elements and remove <head> to 1003 // We need to pop <html> and <body> elements and remove <head> to
992 // accommodate folks passing complete HTML documents to make the 1004 // accommodate folks passing complete HTML documents to make the
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 return; 1088 return;
1077 1089
1078 RefPtrWillBeRawPtr<Text> textNode = toText(node.get()); 1090 RefPtrWillBeRawPtr<Text> textNode = toText(node.get());
1079 RefPtrWillBeRawPtr<Text> textNext = toText(next); 1091 RefPtrWillBeRawPtr<Text> textNext = toText(next);
1080 textNode->appendData(textNext->data()); 1092 textNode->appendData(textNext->data());
1081 if (textNext->parentNode()) // Might have been removed by mutation event. 1093 if (textNext->parentNode()) // Might have been removed by mutation event.
1082 textNext->remove(exceptionState); 1094 textNext->remove(exceptionState);
1083 } 1095 }
1084 1096
1085 } 1097 }
OLDNEW
« Source/core/dom/Range.cpp ('K') | « Source/core/editing/markup.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698