| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 || item->hasTagName(pTag) | 76 || item->hasTagName(pTag) |
| 77 || item->hasTagName(rpTag) | 77 || item->hasTagName(rpTag) |
| 78 || item->hasTagName(rtTag); | 78 || item->hasTagName(rtTag); |
| 79 } | 79 } |
| 80 | 80 |
| 81 static inline bool isAllWhitespace(const String& string) | 81 static inline bool isAllWhitespace(const String& string) |
| 82 { | 82 { |
| 83 return string.isAllSpecialCharacters<isHTMLSpace>(); | 83 return string.isAllSpecialCharacters<isHTMLSpace>(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 static inline void executeInsertTask(HTMLConstructionSiteTask& task) | 86 // 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 |
| 88 // 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. |
| 90 static inline void insert(HTMLConstructionSiteTask& task, bool lazyAttach) |
| 87 { | 91 { |
| 88 ASSERT(task.operation == HTMLConstructionSiteTask::Insert); | |
| 89 | |
| 90 if (task.parent->hasTagName(templateTag)) | 92 if (task.parent->hasTagName(templateTag)) |
| 91 task.parent = toHTMLTemplateElement(task.parent.get())->content(); | 93 task.parent = toHTMLTemplateElement(task.parent.get())->content(); |
| 92 | 94 |
| 95 if (ContainerNode* parent = task.child->parentNode()) |
| 96 parent->parserRemoveChild(task.child.get()); |
| 97 |
| 93 if (task.nextChild) | 98 if (task.nextChild) |
| 94 task.parent->parserInsertBefore(task.child.get(), task.nextChild.get()); | 99 task.parent->parserInsertBefore(task.child.get(), task.nextChild.get()); |
| 95 else | 100 else |
| 96 task.parent->parserAppendChild(task.child.get()); | 101 task.parent->parserAppendChild(task.child.get()); |
| 97 | 102 |
| 98 // JavaScript run from beforeload (or DOM Mutation or event handlers) | 103 // JavaScript run from beforeload (or DOM Mutation or event handlers) |
| 99 // might have removed the child, in which case we should not attach it. | 104 // might have removed the child, in which case we should not attach it. |
| 100 | 105 |
| 101 if (task.child->parentNode() && task.parent->attached() && !task.child->atta
ched()) | 106 if (task.child->parentNode() && task.parent->attached() && !task.child->atta
ched()) { |
| 102 task.child->attach(); | 107 if (lazyAttach) |
| 108 task.child->lazyAttach(); |
| 109 else |
| 110 task.child->attach(); |
| 111 } |
| 112 } |
| 113 |
| 114 static inline void executeInsertTask(HTMLConstructionSiteTask& task) |
| 115 { |
| 116 ASSERT(task.operation == HTMLConstructionSiteTask::Insert); |
| 117 |
| 118 insert(task, false); |
| 103 | 119 |
| 104 task.child->beginParsingChildren(); | 120 task.child->beginParsingChildren(); |
| 105 | 121 |
| 106 if (task.selfClosing) | 122 if (task.selfClosing) |
| 107 task.child->finishParsingChildren(); | 123 task.child->finishParsingChildren(); |
| 108 } | 124 } |
| 109 | 125 |
| 110 static inline void executeReparentTask(HTMLConstructionSiteTask& task) | 126 static inline void executeReparentTask(HTMLConstructionSiteTask& task) |
| 111 { | 127 { |
| 112 ASSERT(task.operation == HTMLConstructionSiteTask::Reparent); | 128 ASSERT(task.operation == HTMLConstructionSiteTask::Reparent); |
| 113 | 129 |
| 114 if (ContainerNode* parent = task.child->parentNode()) | 130 if (ContainerNode* parent = task.child->parentNode()) |
| 115 parent->parserRemoveChild(task.child.get()); | 131 parent->parserRemoveChild(task.child.get()); |
| 116 | 132 |
| 117 task.parent->parserAppendChild(task.child); | 133 task.parent->parserAppendChild(task.child); |
| 118 | 134 |
| 119 if (task.child->parentElement()->attached() && !task.child->attached()) | 135 if (task.child->parentElement()->attached() && !task.child->attached()) |
| 120 task.child->lazyAttach(); | 136 task.child->lazyAttach(); |
| 121 } | 137 } |
| 122 | 138 |
| 139 static inline void executeInsertAlreadyParsedChildTask(HTMLConstructionSiteTask&
task) |
| 140 { |
| 141 ASSERT(task.operation == HTMLConstructionSiteTask::InsertAlreadyParsedChild)
; |
| 142 |
| 143 insert(task, true); |
| 144 } |
| 145 |
| 146 static inline void executeTakeAllChildrenTask(HTMLConstructionSiteTask& task) |
| 147 { |
| 148 ASSERT(task.operation == HTMLConstructionSiteTask::TakeAllChildren); |
| 149 |
| 150 task.parent->takeAllChildrenFrom(task.oldParent()); |
| 151 // Notice that we don't need to manually attach the moved children |
| 152 // because takeAllChildrenFrom does that work for us. |
| 153 } |
| 154 |
| 123 static inline void executeTask(HTMLConstructionSiteTask& task) | 155 static inline void executeTask(HTMLConstructionSiteTask& task) |
| 124 { | 156 { |
| 125 if (task.operation == HTMLConstructionSiteTask::Insert) | 157 if (task.operation == HTMLConstructionSiteTask::Insert) |
| 126 return executeInsertTask(task); | 158 return executeInsertTask(task); |
| 127 | 159 |
| 160 // All the cases below this point are only used by the adoption agency. |
| 161 |
| 162 if (task.operation == HTMLConstructionSiteTask::InsertAlreadyParsedChild) |
| 163 return executeInsertAlreadyParsedChildTask(task); |
| 164 |
| 128 if (task.operation == HTMLConstructionSiteTask::Reparent) | 165 if (task.operation == HTMLConstructionSiteTask::Reparent) |
| 129 return executeReparentTask(task); | 166 return executeReparentTask(task); |
| 130 | 167 |
| 168 if (task.operation == HTMLConstructionSiteTask::TakeAllChildren) |
| 169 return executeTakeAllChildrenTask(task); |
| 170 |
| 131 ASSERT_NOT_REACHED(); | 171 ASSERT_NOT_REACHED(); |
| 132 } | 172 } |
| 133 | 173 |
| 134 void HTMLConstructionSite::attachLater(ContainerNode* parent, PassRefPtr<Node> p
rpChild, bool selfClosing) | 174 void HTMLConstructionSite::attachLater(ContainerNode* parent, PassRefPtr<Node> p
rpChild, bool selfClosing) |
| 135 { | 175 { |
| 136 ASSERT(scriptingContentIsAllowed(m_parserContentPolicy) || !prpChild.get()->
isElementNode() || !toScriptElementIfPossible(toElement(prpChild.get()))); | 176 ASSERT(scriptingContentIsAllowed(m_parserContentPolicy) || !prpChild.get()->
isElementNode() || !toScriptElementIfPossible(toElement(prpChild.get()))); |
| 137 ASSERT(pluginContentIsAllowed(m_parserContentPolicy) || !prpChild->isPluginE
lement()); | 177 ASSERT(pluginContentIsAllowed(m_parserContentPolicy) || !prpChild->isPluginE
lement()); |
| 138 | 178 |
| 139 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert); | 179 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert); |
| 140 task.parent = parent; | 180 task.parent = parent; |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 } | 582 } |
| 543 | 583 |
| 544 void HTMLConstructionSite::reparent(HTMLElementStack::ElementRecord* newParent,
HTMLElementStack::ElementRecord* child) | 584 void HTMLConstructionSite::reparent(HTMLElementStack::ElementRecord* newParent,
HTMLElementStack::ElementRecord* child) |
| 545 { | 585 { |
| 546 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Reparent); | 586 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Reparent); |
| 547 task.parent = newParent->element(); | 587 task.parent = newParent->element(); |
| 548 task.child = child->element(); | 588 task.child = child->element(); |
| 549 m_taskQueue.append(task); | 589 m_taskQueue.append(task); |
| 550 } | 590 } |
| 551 | 591 |
| 592 void HTMLConstructionSite::reparent(HTMLElementStack::ElementRecord* newParent,
HTMLStackItem* child) |
| 593 { |
| 594 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Reparent); |
| 595 task.parent = newParent->element(); |
| 596 task.child = child->element(); |
| 597 m_taskQueue.append(task); |
| 598 } |
| 599 |
| 600 void HTMLConstructionSite::insertAlreadyParsedChild(HTMLStackItem* newParent, HT
MLElementStack::ElementRecord* child) |
| 601 { |
| 602 if (newParent->causesFosterParenting()) { |
| 603 fosterParent(child->element()); |
| 604 return; |
| 605 } |
| 606 |
| 607 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::InsertAlreadyParsedC
hild); |
| 608 task.parent = newParent->element(); |
| 609 task.child = child->element(); |
| 610 m_taskQueue.append(task); |
| 611 } |
| 612 |
| 613 void HTMLConstructionSite::takeAllChildren(HTMLStackItem* newParent, HTMLElement
Stack::ElementRecord* oldParent) |
| 614 { |
| 615 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::TakeAllChildren); |
| 616 task.parent = newParent->element(); |
| 617 task.child = oldParent->element(); |
| 618 m_taskQueue.append(task); |
| 619 } |
| 620 |
| 552 PassRefPtr<Element> HTMLConstructionSite::createElement(AtomicHTMLToken* token,
const AtomicString& namespaceURI) | 621 PassRefPtr<Element> HTMLConstructionSite::createElement(AtomicHTMLToken* token,
const AtomicString& namespaceURI) |
| 553 { | 622 { |
| 554 QualifiedName tagName(nullAtom, token->name(), namespaceURI); | 623 QualifiedName tagName(nullAtom, token->name(), namespaceURI); |
| 555 RefPtr<Element> element = ownerDocumentForCurrentNode()->createElement(tagNa
me, true); | 624 RefPtr<Element> element = ownerDocumentForCurrentNode()->createElement(tagNa
me, true); |
| 556 setAttributes(element.get(), token, m_parserContentPolicy); | 625 setAttributes(element.get(), token, m_parserContentPolicy); |
| 557 return element.release(); | 626 return element.release(); |
| 558 } | 627 } |
| 559 | 628 |
| 560 inline Document* HTMLConstructionSite::ownerDocumentForCurrentNode() | 629 inline Document* HTMLConstructionSite::ownerDocumentForCurrentNode() |
| 561 { | 630 { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 { | 751 { |
| 683 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert); | 752 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert); |
| 684 findFosterSite(task); | 753 findFosterSite(task); |
| 685 task.child = node; | 754 task.child = node; |
| 686 ASSERT(task.parent); | 755 ASSERT(task.parent); |
| 687 | 756 |
| 688 m_taskQueue.append(task); | 757 m_taskQueue.append(task); |
| 689 } | 758 } |
| 690 | 759 |
| 691 } | 760 } |
| OLD | NEW |