| 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 224 |
| 225 static String atomizeIfAllWhitespace(const String& string, WhitespaceMode whites
paceMode) | 225 static String atomizeIfAllWhitespace(const String& string, WhitespaceMode whites
paceMode) |
| 226 { | 226 { |
| 227 // Strings composed entirely of whitespace are likely to be repeated. | 227 // Strings composed entirely of whitespace are likely to be repeated. |
| 228 // Turn them into AtomicString so we share a single string for each. | 228 // Turn them into AtomicString so we share a single string for each. |
| 229 if (whitespaceMode == AllWhitespace || (whitespaceMode == WhitespaceUnknown
&& isAllWhitespace(string))) | 229 if (whitespaceMode == AllWhitespace || (whitespaceMode == WhitespaceUnknown
&& isAllWhitespace(string))) |
| 230 return AtomicString(string).string(); | 230 return AtomicString(string).string(); |
| 231 return string; | 231 return string; |
| 232 } | 232 } |
| 233 | 233 |
| 234 void HTMLConstructionSite::flushPendingText(FlushMode mode) | 234 void HTMLConstructionSite::flushPendingText() |
| 235 { | 235 { |
| 236 if (m_pendingText.isEmpty()) | 236 if (m_pendingText.isEmpty()) |
| 237 return; | 237 return; |
| 238 | 238 |
| 239 if (mode == FlushIfAtTextLimit | |
| 240 && !shouldUseLengthLimit(*m_pendingText.parent)) | |
| 241 return; | |
| 242 | |
| 243 PendingText pendingText; | 239 PendingText pendingText; |
| 244 // Hold onto the current pending text on the stack so that queueTask doesn't
recurse infinitely. | 240 // Hold onto the current pending text on the stack so that queueTask doesn't
recurse infinitely. |
| 245 m_pendingText.swap(pendingText); | 241 m_pendingText.swap(pendingText); |
| 246 ASSERT(m_pendingText.isEmpty()); | 242 ASSERT(m_pendingText.isEmpty()); |
| 247 | 243 |
| 248 // Splitting text nodes into smaller chunks contradicts HTML5 spec, but is n
ecessary | 244 // Splitting text nodes into smaller chunks contradicts HTML5 spec, but is n
ecessary |
| 249 // for performance, see: https://bugs.webkit.org/show_bug.cgi?id=55898 | 245 // for performance, see: https://bugs.webkit.org/show_bug.cgi?id=55898 |
| 250 unsigned lengthLimit = textLengthLimitForContainer(*pendingText.parent); | 246 unsigned lengthLimit = textLengthLimitForContainer(*pendingText.parent); |
| 251 | 247 |
| 252 unsigned currentPosition = 0; | 248 unsigned currentPosition = 0; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 266 | 262 |
| 267 ASSERT(breakIndex > currentPosition); | 263 ASSERT(breakIndex > currentPosition); |
| 268 ASSERT(breakIndex - currentPosition == substring.length()); | 264 ASSERT(breakIndex - currentPosition == substring.length()); |
| 269 ASSERT(toText(task.child.get())->length() == substring.length()); | 265 ASSERT(toText(task.child.get())->length() == substring.length()); |
| 270 currentPosition = breakIndex; | 266 currentPosition = breakIndex; |
| 271 } | 267 } |
| 272 } | 268 } |
| 273 | 269 |
| 274 void HTMLConstructionSite::queueTask(const HTMLConstructionSiteTask& task) | 270 void HTMLConstructionSite::queueTask(const HTMLConstructionSiteTask& task) |
| 275 { | 271 { |
| 276 flushPendingText(FlushAlways); | 272 flushPendingText(); |
| 277 ASSERT(m_pendingText.isEmpty()); | 273 ASSERT(m_pendingText.isEmpty()); |
| 278 m_taskQueue.append(task); | 274 m_taskQueue.append(task); |
| 279 } | 275 } |
| 280 | 276 |
| 281 void HTMLConstructionSite::attachLater(ContainerNode* parent, PassRefPtrWillBeRa
wPtr<Node> prpChild, bool selfClosing) | 277 void HTMLConstructionSite::attachLater(ContainerNode* parent, PassRefPtrWillBeRa
wPtr<Node> prpChild, bool selfClosing) |
| 282 { | 278 { |
| 283 ASSERT(scriptingContentIsAllowed(m_parserContentPolicy) || !prpChild.get()->
isElementNode() || !toScriptLoaderIfPossible(toElement(prpChild.get()))); | 279 ASSERT(scriptingContentIsAllowed(m_parserContentPolicy) || !prpChild.get()->
isElementNode() || !toScriptLoaderIfPossible(toElement(prpChild.get()))); |
| 284 ASSERT(pluginContentIsAllowed(m_parserContentPolicy) || !isHTMLPlugInElement
(prpChild)); | 280 ASSERT(pluginContentIsAllowed(m_parserContentPolicy) || !isHTMLPlugInElement
(prpChild)); |
| 285 | 281 |
| 286 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert); | 282 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 return; | 526 return; |
| 531 } | 527 } |
| 532 | 528 |
| 533 // Otherwise we are No Quirks Mode. | 529 // Otherwise we are No Quirks Mode. |
| 534 setCompatibilityMode(Document::NoQuirksMode); | 530 setCompatibilityMode(Document::NoQuirksMode); |
| 535 } | 531 } |
| 536 | 532 |
| 537 void HTMLConstructionSite::processEndOfFile() | 533 void HTMLConstructionSite::processEndOfFile() |
| 538 { | 534 { |
| 539 ASSERT(currentNode()); | 535 ASSERT(currentNode()); |
| 540 flush(FlushAlways); | 536 flush(); |
| 541 openElements()->popAll(); | 537 openElements()->popAll(); |
| 542 } | 538 } |
| 543 | 539 |
| 544 void HTMLConstructionSite::finishedParsing() | 540 void HTMLConstructionSite::finishedParsing() |
| 545 { | 541 { |
| 546 // We shouldn't have any queued tasks but we might have pending text which w
e need to promote to tasks and execute. | 542 // We shouldn't have any queued tasks but we might have pending text which w
e need to promote to tasks and execute. |
| 547 ASSERT(m_taskQueue.isEmpty()); | 543 ASSERT(m_taskQueue.isEmpty()); |
| 548 flush(FlushAlways); | 544 flush(); |
| 549 m_document->finishedParsing(); | 545 m_document->finishedParsing(); |
| 550 } | 546 } |
| 551 | 547 |
| 552 void HTMLConstructionSite::insertDoctype(AtomicHTMLToken* token) | 548 void HTMLConstructionSite::insertDoctype(AtomicHTMLToken* token) |
| 553 { | 549 { |
| 554 ASSERT(token->type() == HTMLToken::DOCTYPE); | 550 ASSERT(token->type() == HTMLToken::DOCTYPE); |
| 555 | 551 |
| 556 const String& publicId = StringImpl::create8BitIfPossible(token->publicIdent
ifier()); | 552 const String& publicId = StringImpl::create8BitIfPossible(token->publicIdent
ifier()); |
| 557 const String& systemId = StringImpl::create8BitIfPossible(token->systemIdent
ifier()); | 553 const String& systemId = StringImpl::create8BitIfPossible(token->systemIdent
ifier()); |
| 558 RefPtrWillBeRawPtr<DocumentType> doctype = DocumentType::create(m_document,
token->name(), publicId, systemId); | 554 RefPtrWillBeRawPtr<DocumentType> doctype = DocumentType::create(m_document,
token->name(), publicId, systemId); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 findFosterSite(dummyTask); | 682 findFosterSite(dummyTask); |
| 687 | 683 |
| 688 // FIXME: This probably doesn't need to be done both here and in insert(Task
). | 684 // FIXME: This probably doesn't need to be done both here and in insert(Task
). |
| 689 if (isHTMLTemplateElement(*dummyTask.parent)) | 685 if (isHTMLTemplateElement(*dummyTask.parent)) |
| 690 dummyTask.parent = toHTMLTemplateElement(dummyTask.parent.get())->conten
t(); | 686 dummyTask.parent = toHTMLTemplateElement(dummyTask.parent.get())->conten
t(); |
| 691 | 687 |
| 692 // Unclear when parent != case occurs. Somehow we insert text into two separ
ate nodes while processing the same Token. | 688 // Unclear when parent != case occurs. Somehow we insert text into two separ
ate nodes while processing the same Token. |
| 693 // The nextChild != dummy.nextChild case occurs whenever foster parenting ha
ppened and we hit a new text node "<table>a</table>b" | 689 // The nextChild != dummy.nextChild case occurs whenever foster parenting ha
ppened and we hit a new text node "<table>a</table>b" |
| 694 // In either case we have to flush the pending text into the task queue befo
re making more. | 690 // In either case we have to flush the pending text into the task queue befo
re making more. |
| 695 if (!m_pendingText.isEmpty() && (m_pendingText.parent != dummyTask.parent ||
m_pendingText.nextChild != dummyTask.nextChild)) | 691 if (!m_pendingText.isEmpty() && (m_pendingText.parent != dummyTask.parent ||
m_pendingText.nextChild != dummyTask.nextChild)) |
| 696 flushPendingText(FlushAlways); | 692 flushPendingText(); |
| 697 m_pendingText.append(dummyTask.parent, dummyTask.nextChild, string, whitespa
ceMode); | 693 m_pendingText.append(dummyTask.parent, dummyTask.nextChild, string, whitespa
ceMode); |
| 698 } | 694 } |
| 699 | 695 |
| 700 void HTMLConstructionSite::reparent(HTMLElementStack::ElementRecord* newParent,
HTMLElementStack::ElementRecord* child) | 696 void HTMLConstructionSite::reparent(HTMLElementStack::ElementRecord* newParent,
HTMLElementStack::ElementRecord* child) |
| 701 { | 697 { |
| 702 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Reparent); | 698 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Reparent); |
| 703 task.parent = newParent->node(); | 699 task.parent = newParent->node(); |
| 704 task.child = child->node(); | 700 task.child = child->node(); |
| 705 queueTask(task); | 701 queueTask(task); |
| 706 } | 702 } |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 } | 871 } |
| 876 | 872 |
| 877 void HTMLConstructionSite::PendingText::trace(Visitor* visitor) | 873 void HTMLConstructionSite::PendingText::trace(Visitor* visitor) |
| 878 { | 874 { |
| 879 visitor->trace(parent); | 875 visitor->trace(parent); |
| 880 visitor->trace(nextChild); | 876 visitor->trace(nextChild); |
| 881 } | 877 } |
| 882 | 878 |
| 883 | 879 |
| 884 } | 880 } |
| OLD | NEW |