OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
3 * Copyright (C) 2011 Apple Inc. All rights reserved. | 3 * Copyright (C) 2011 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include "core/html/parser/HTMLParserIdioms.h" | 44 #include "core/html/parser/HTMLParserIdioms.h" |
45 #include "core/html/parser/HTMLStackItem.h" | 45 #include "core/html/parser/HTMLStackItem.h" |
46 #include "core/html/parser/HTMLToken.h" | 46 #include "core/html/parser/HTMLToken.h" |
47 #include "core/html/parser/HTMLTokenizer.h" | 47 #include "core/html/parser/HTMLTokenizer.h" |
48 #include "core/loader/FrameLoader.h" | 48 #include "core/loader/FrameLoader.h" |
49 #include "core/loader/FrameLoaderClient.h" | 49 #include "core/loader/FrameLoaderClient.h" |
50 #include "core/page/Frame.h" | 50 #include "core/page/Frame.h" |
51 #include "core/page/Settings.h" | 51 #include "core/page/Settings.h" |
52 #include "core/platform/LocalizedStrings.h" | 52 #include "core/platform/LocalizedStrings.h" |
53 #include "core/platform/NotImplemented.h" | 53 #include "core/platform/NotImplemented.h" |
54 #include <wtf/UnusedParam.h> | 54 #include "wtf/UnusedParam.h" |
| 55 #include <limits> |
55 | 56 |
56 namespace WebCore { | 57 namespace WebCore { |
57 | 58 |
58 using namespace HTMLNames; | 59 using namespace HTMLNames; |
59 | 60 |
60 static const unsigned maximumHTMLParserDOMTreeDepth = 512; | 61 static const unsigned maximumHTMLParserDOMTreeDepth = 512; |
61 | 62 |
62 static inline void setAttributes(Element* element, AtomicHTMLToken* token, Parse
rContentPolicy parserContentPolicy) | 63 static inline void setAttributes(Element* element, AtomicHTMLToken* token, Parse
rContentPolicy parserContentPolicy) |
63 { | 64 { |
64 if (!scriptingContentIsAllowed(parserContentPolicy)) | 65 if (!scriptingContentIsAllowed(parserContentPolicy)) |
65 element->stripScriptingAttributes(token->attributes()); | 66 element->stripScriptingAttributes(token->attributes()); |
66 element->parserSetAttributes(token->attributes()); | 67 element->parserSetAttributes(token->attributes()); |
67 } | 68 } |
68 | 69 |
69 static bool hasImpliedEndTag(const HTMLStackItem* item) | 70 static bool hasImpliedEndTag(const HTMLStackItem* item) |
70 { | 71 { |
71 return item->hasTagName(ddTag) | 72 return item->hasTagName(ddTag) |
72 || item->hasTagName(dtTag) | 73 || item->hasTagName(dtTag) |
73 || item->hasTagName(liTag) | 74 || item->hasTagName(liTag) |
74 || item->hasTagName(optionTag) | 75 || item->hasTagName(optionTag) |
75 || item->hasTagName(optgroupTag) | 76 || item->hasTagName(optgroupTag) |
76 || item->hasTagName(pTag) | 77 || item->hasTagName(pTag) |
77 || item->hasTagName(rpTag) | 78 || item->hasTagName(rpTag) |
78 || item->hasTagName(rtTag); | 79 || item->hasTagName(rtTag); |
79 } | 80 } |
80 | 81 |
| 82 static bool shouldUseLengthLimit(const ContainerNode* node) |
| 83 { |
| 84 return !node->hasTagName(scriptTag) |
| 85 && !node->hasTagName(styleTag) |
| 86 && !node->hasTagName(SVGNames::scriptTag); |
| 87 } |
| 88 |
81 static inline bool isAllWhitespace(const String& string) | 89 static inline bool isAllWhitespace(const String& string) |
82 { | 90 { |
83 return string.isAllSpecialCharacters<isHTMLSpace>(); | 91 return string.isAllSpecialCharacters<isHTMLSpace>(); |
84 } | 92 } |
85 | 93 |
86 // The |lazyAttach| parameter to this function exists for historical reasons. | 94 // The |lazyAttach| parameter to this function exists for historical reasons. |
87 // There used to be two code paths, one that used lazyAttach and one that | 95 // There used to be two code paths, one that used lazyAttach and one that |
88 // didn't. We should make the two code paths consistent and either use | 96 // didn't. We should make the two code paths consistent and either use |
89 // lazyAttach or non-lazyAttach, but we wanted to make that change separately. | 97 // lazyAttach or non-lazyAttach, but we wanted to make that change separately. |
90 static inline void insert(HTMLConstructionSiteTask& task, bool lazyAttach) | 98 static inline void insert(HTMLConstructionSiteTask& task, bool lazyAttach) |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 | 554 |
547 if (task.parent->hasTagName(templateTag)) | 555 if (task.parent->hasTagName(templateTag)) |
548 task.parent = toHTMLTemplateElement(task.parent.get())->content(); | 556 task.parent = toHTMLTemplateElement(task.parent.get())->content(); |
549 | 557 |
550 // Strings composed entirely of whitespace are likely to be repeated. | 558 // Strings composed entirely of whitespace are likely to be repeated. |
551 // Turn them into AtomicString so we share a single string for each. | 559 // Turn them into AtomicString so we share a single string for each. |
552 bool shouldUseAtomicString = whitespaceMode == AllWhitespace | 560 bool shouldUseAtomicString = whitespaceMode == AllWhitespace |
553 || (whitespaceMode == WhitespaceUnknown && isAllWhitespace(characters)); | 561 || (whitespaceMode == WhitespaceUnknown && isAllWhitespace(characters)); |
554 | 562 |
555 unsigned currentPosition = 0; | 563 unsigned currentPosition = 0; |
| 564 unsigned lengthLimit = shouldUseLengthLimit(task.parent.get()) ? Text::defau
ltLengthLimit : std::numeric_limits<unsigned>::max(); |
556 | 565 |
557 // FIXME: Splitting text nodes into smaller chunks contradicts HTML5 spec, b
ut is currently necessary | 566 // FIXME: Splitting text nodes into smaller chunks contradicts HTML5 spec, b
ut is currently necessary |
558 // for performance, see <https://bugs.webkit.org/show_bug.cgi?id=55898>. | 567 // for performance, see <https://bugs.webkit.org/show_bug.cgi?id=55898>. |
559 | 568 |
560 Node* previousChild = task.nextChild ? task.nextChild->previousSibling() : t
ask.parent->lastChild(); | 569 Node* previousChild = task.nextChild ? task.nextChild->previousSibling() : t
ask.parent->lastChild(); |
561 if (previousChild && previousChild->isTextNode()) { | 570 if (previousChild && previousChild->isTextNode()) { |
562 // FIXME: We're only supposed to append to this text node if it | 571 // FIXME: We're only supposed to append to this text node if it |
563 // was the last text node inserted by the parser. | 572 // was the last text node inserted by the parser. |
564 CharacterData* textNode = static_cast<CharacterData*>(previousChild); | 573 CharacterData* textNode = static_cast<CharacterData*>(previousChild); |
565 currentPosition = textNode->parserAppendData(characters, 0, Text::defaul
tLengthLimit); | 574 currentPosition = textNode->parserAppendData(characters, 0, lengthLimit)
; |
566 } | 575 } |
567 | 576 |
568 while (currentPosition < characters.length()) { | 577 while (currentPosition < characters.length()) { |
569 RefPtr<Text> textNode = Text::createWithLengthLimit(task.parent->documen
t(), shouldUseAtomicString ? AtomicString(characters).string() : characters, cur
rentPosition); | 578 RefPtr<Text> textNode = Text::createWithLengthLimit(task.parent->documen
t(), shouldUseAtomicString ? AtomicString(characters).string() : characters, cur
rentPosition, lengthLimit); |
570 // If we have a whole string of unbreakable characters the above could l
ead to an infinite loop. Exceeding the length limit is the lesser evil. | 579 // If we have a whole string of unbreakable characters the above could l
ead to an infinite loop. Exceeding the length limit is the lesser evil. |
571 if (!textNode->length()) { | 580 if (!textNode->length()) { |
572 String substring = characters.substring(currentPosition); | 581 String substring = characters.substring(currentPosition); |
573 textNode = Text::create(task.parent->document(), shouldUseAtomicStri
ng ? AtomicString(substring).string() : substring); | 582 textNode = Text::create(task.parent->document(), shouldUseAtomicStri
ng ? AtomicString(substring).string() : substring); |
574 } | 583 } |
575 | 584 |
576 currentPosition += textNode->length(); | 585 currentPosition += textNode->length(); |
577 ASSERT(currentPosition <= characters.length()); | 586 ASSERT(currentPosition <= characters.length()); |
578 task.child = textNode.release(); | 587 task.child = textNode.release(); |
579 | 588 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 { | 760 { |
752 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert); | 761 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert); |
753 findFosterSite(task); | 762 findFosterSite(task); |
754 task.child = node; | 763 task.child = node; |
755 ASSERT(task.parent); | 764 ASSERT(task.parent); |
756 | 765 |
757 m_taskQueue.append(task); | 766 m_taskQueue.append(task); |
758 } | 767 } |
759 | 768 |
760 } | 769 } |
OLD | NEW |