OLD | NEW |
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 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 if (!document) | 637 if (!document) |
638 return emptyString(); | 638 return emptyString(); |
639 | 639 |
640 const Range* updatedRange = range; | 640 const Range* updatedRange = range; |
641 | 641 |
642 return createMarkupInternal(document, range, updatedRange, nodes, shouldAnno
tate, convertBlocksToInlines, shouldResolveURLs, constrainingAncestor); | 642 return createMarkupInternal(document, range, updatedRange, nodes, shouldAnno
tate, convertBlocksToInlines, shouldResolveURLs, constrainingAncestor); |
643 } | 643 } |
644 | 644 |
645 PassRefPtr<DocumentFragment> createFragmentFromMarkup(Document* document, const
String& markup, const String& baseURL, ParserContentPolicy parserContentPolicy) | 645 PassRefPtr<DocumentFragment> createFragmentFromMarkup(Document* document, const
String& markup, const String& baseURL, ParserContentPolicy parserContentPolicy) |
646 { | 646 { |
| 647 ASSERT(document); |
647 // We use a fake body element here to trick the HTML parser to using the InB
ody insertion mode. | 648 // We use a fake body element here to trick the HTML parser to using the InB
ody insertion mode. |
648 RefPtr<HTMLBodyElement> fakeBody = HTMLBodyElement::create(document); | 649 RefPtr<HTMLBodyElement> fakeBody = HTMLBodyElement::create(*document); |
649 RefPtr<DocumentFragment> fragment = DocumentFragment::create(document); | 650 RefPtr<DocumentFragment> fragment = DocumentFragment::create(document); |
650 | 651 |
651 fragment->parseHTML(markup, fakeBody.get(), parserContentPolicy); | 652 fragment->parseHTML(markup, fakeBody.get(), parserContentPolicy); |
652 | 653 |
653 if (!baseURL.isEmpty() && baseURL != blankURL() && baseURL != document->base
URL()) | 654 if (!baseURL.isEmpty() && baseURL != blankURL() && baseURL != document->base
URL()) |
654 completeURLs(fragment.get(), baseURL); | 655 completeURLs(fragment.get(), baseURL); |
655 | 656 |
656 return fragment.release(); | 657 return fragment.release(); |
657 } | 658 } |
658 | 659 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 } | 955 } |
955 | 956 |
956 bool wasValid = fragment->parseXML(markup, contextElement, parserContentPoli
cy); | 957 bool wasValid = fragment->parseXML(markup, contextElement, parserContentPoli
cy); |
957 if (!wasValid) { | 958 if (!wasValid) { |
958 es.throwDOMException(SyntaxError); | 959 es.throwDOMException(SyntaxError); |
959 return 0; | 960 return 0; |
960 } | 961 } |
961 return fragment.release(); | 962 return fragment.release(); |
962 } | 963 } |
963 | 964 |
964 PassRefPtr<DocumentFragment> createFragmentForTransformToFragment(const String&
sourceString, const String& sourceMIMEType, Document* outputDoc) | 965 PassRefPtr<DocumentFragment> createFragmentForTransformToFragment(const String&
sourceString, const String& sourceMIMEType, Document& outputDoc) |
965 { | 966 { |
966 RefPtr<DocumentFragment> fragment = outputDoc->createDocumentFragment(); | 967 RefPtr<DocumentFragment> fragment = outputDoc.createDocumentFragment(); |
967 | 968 |
968 if (sourceMIMEType == "text/html") { | 969 if (sourceMIMEType == "text/html") { |
969 // As far as I can tell, there isn't a spec for how transformToFragment
is supposed to work. | 970 // As far as I can tell, there isn't a spec for how transformToFragment
is supposed to work. |
970 // Based on the documentation I can find, it looks like we want to start
parsing the fragment in the InBody insertion mode. | 971 // Based on the documentation I can find, it looks like we want to start
parsing the fragment in the InBody insertion mode. |
971 // Unfortunately, that's an implementation detail of the parser. | 972 // Unfortunately, that's an implementation detail of the parser. |
972 // We achieve that effect here by passing in a fake body element as cont
ext for the fragment. | 973 // We achieve that effect here by passing in a fake body element as cont
ext for the fragment. |
973 RefPtr<HTMLBodyElement> fakeBody = HTMLBodyElement::create(outputDoc); | 974 RefPtr<HTMLBodyElement> fakeBody = HTMLBodyElement::create(outputDoc); |
974 fragment->parseHTML(sourceString, fakeBody.get()); | 975 fragment->parseHTML(sourceString, fakeBody.get()); |
975 } else if (sourceMIMEType == "text/plain") | 976 } else if (sourceMIMEType == "text/plain") { |
976 fragment->parserAppendChild(Text::create(outputDoc, sourceString)); | 977 fragment->parserAppendChild(Text::create(&outputDoc, sourceString)); |
977 else { | 978 } else { |
978 bool successfulParse = fragment->parseXML(sourceString, 0); | 979 bool successfulParse = fragment->parseXML(sourceString, 0); |
979 if (!successfulParse) | 980 if (!successfulParse) |
980 return 0; | 981 return 0; |
981 } | 982 } |
982 | 983 |
983 // FIXME: Do we need to mess with URLs here? | 984 // FIXME: Do we need to mess with URLs here? |
984 | 985 |
985 return fragment.release(); | 986 return fragment.release(); |
986 } | 987 } |
987 | 988 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 if (containerNode->hasOneChild()) { | 1073 if (containerNode->hasOneChild()) { |
1073 containerNode->replaceChild(textNode.release(), containerNode->firstChil
d(), es); | 1074 containerNode->replaceChild(textNode.release(), containerNode->firstChil
d(), es); |
1074 return; | 1075 return; |
1075 } | 1076 } |
1076 | 1077 |
1077 containerNode->removeChildren(); | 1078 containerNode->removeChildren(); |
1078 containerNode->appendChild(textNode.release(), es); | 1079 containerNode->appendChild(textNode.release(), es); |
1079 } | 1080 } |
1080 | 1081 |
1081 } | 1082 } |
OLD | NEW |