Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. |
| 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) | 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) |
| 8 * Copyright (C) 2011 Google Inc. All rights reserved. | 8 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 9 * | 9 * |
| 10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 #include "core/dom/NodeTraversal.h" | 31 #include "core/dom/NodeTraversal.h" |
| 32 #include "core/dom/shadow/ElementShadow.h" | 32 #include "core/dom/shadow/ElementShadow.h" |
| 33 #include "core/dom/shadow/ShadowRoot.h" | 33 #include "core/dom/shadow/ShadowRoot.h" |
| 34 | 34 |
| 35 namespace WebCore { | 35 namespace WebCore { |
| 36 | 36 |
| 37 void TreeScopeAdopter::moveTreeToNewScope(Node& root) const | 37 void TreeScopeAdopter::moveTreeToNewScope(Node& root) const |
| 38 { | 38 { |
| 39 ASSERT(needsScopeChange()); | 39 ASSERT(needsScopeChange()); |
| 40 | 40 |
| 41 #if !ENABLE(OILPAN) | |
| 41 m_oldScope.guardRef(); | 42 m_oldScope.guardRef(); |
|
haraken
2014/04/24 04:18:43
In a follow-up, you might want to move TreeScopeAd
Mads Ager (chromium)
2014/04/24 10:57:36
Agreed.
| |
| 43 #endif | |
| 42 | 44 |
| 43 // If an element is moved from a document and then eventually back again the collection cache for | 45 // If an element is moved from a document and then eventually back again the collection cache for |
| 44 // that element may contain stale data as changes made to it will have updat ed the DOMTreeVersion | 46 // that element may contain stale data as changes made to it will have updat ed the DOMTreeVersion |
| 45 // of the document it was moved to. By increasing the DOMTreeVersion of the donating document here | 47 // of the document it was moved to. By increasing the DOMTreeVersion of the donating document here |
| 46 // we ensure that the collection cache will be invalidated as needed when th e element is moved back. | 48 // we ensure that the collection cache will be invalidated as needed when th e element is moved back. |
| 47 Document& oldDocument = m_oldScope.document(); | 49 Document& oldDocument = m_oldScope.document(); |
| 48 Document& newDocument = m_newScope.document(); | 50 Document& newDocument = m_newScope.document(); |
| 49 bool willMoveToNewDocument = oldDocument != newDocument; | 51 bool willMoveToNewDocument = oldDocument != newDocument; |
| 50 if (willMoveToNewDocument) | 52 if (willMoveToNewDocument) |
| 51 oldDocument.incDOMTreeVersion(); | 53 oldDocument.incDOMTreeVersion(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 70 moveTreeToNewScope(*attrs[i]); | 72 moveTreeToNewScope(*attrs[i]); |
| 71 } | 73 } |
| 72 | 74 |
| 73 for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = s hadow->olderShadowRoot()) { | 75 for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = s hadow->olderShadowRoot()) { |
| 74 shadow->setParentTreeScope(m_newScope); | 76 shadow->setParentTreeScope(m_newScope); |
| 75 if (willMoveToNewDocument) | 77 if (willMoveToNewDocument) |
| 76 moveTreeToNewDocument(*shadow, oldDocument, newDocument); | 78 moveTreeToNewDocument(*shadow, oldDocument, newDocument); |
| 77 } | 79 } |
| 78 } | 80 } |
| 79 | 81 |
| 82 #if !ENABLE(OILPAN) | |
| 80 m_oldScope.guardDeref(); | 83 m_oldScope.guardDeref(); |
| 84 #endif | |
| 81 } | 85 } |
| 82 | 86 |
| 83 void TreeScopeAdopter::moveTreeToNewDocument(Node& root, Document& oldDocument, Document& newDocument) const | 87 void TreeScopeAdopter::moveTreeToNewDocument(Node& root, Document& oldDocument, Document& newDocument) const |
| 84 { | 88 { |
| 85 ASSERT(oldDocument != newDocument); | 89 ASSERT(oldDocument != newDocument); |
| 86 for (Node* node = &root; node; node = NodeTraversal::next(*node, &root)) { | 90 for (Node* node = &root; node; node = NodeTraversal::next(*node, &root)) { |
| 87 moveNodeToNewDocument(*node, oldDocument, newDocument); | 91 moveNodeToNewDocument(*node, oldDocument, newDocument); |
| 88 for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = s hadow->olderShadowRoot()) | 92 for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = s hadow->olderShadowRoot()) |
| 89 moveTreeToNewDocument(*shadow, oldDocument, newDocument); | 93 moveTreeToNewDocument(*shadow, oldDocument, newDocument); |
| 90 } | 94 } |
| 91 } | 95 } |
| 92 | 96 |
| 93 #ifndef NDEBUG | 97 #ifndef NDEBUG |
| 94 static bool didMoveToNewDocumentWasCalled = false; | 98 static bool didMoveToNewDocumentWasCalled = false; |
| 95 static Document* oldDocumentDidMoveToNewDocumentWasCalledWith = 0; | 99 static Document* oldDocumentDidMoveToNewDocumentWasCalledWith = 0; |
| 96 | 100 |
| 97 void TreeScopeAdopter::ensureDidMoveToNewDocumentWasCalled(Document& oldDocument ) | 101 void TreeScopeAdopter::ensureDidMoveToNewDocumentWasCalled(Document& oldDocument ) |
| 98 { | 102 { |
| 99 ASSERT(!didMoveToNewDocumentWasCalled); | 103 ASSERT(!didMoveToNewDocumentWasCalled); |
| 100 ASSERT_UNUSED(oldDocument, oldDocument == oldDocumentDidMoveToNewDocumentWas CalledWith); | 104 ASSERT_UNUSED(oldDocument, oldDocument == oldDocumentDidMoveToNewDocumentWas CalledWith); |
| 101 didMoveToNewDocumentWasCalled = true; | 105 didMoveToNewDocumentWasCalled = true; |
| 102 } | 106 } |
| 103 #endif | 107 #endif |
| 104 | 108 |
| 105 inline void TreeScopeAdopter::updateTreeScope(Node& node) const | 109 inline void TreeScopeAdopter::updateTreeScope(Node& node) const |
| 106 { | 110 { |
| 107 ASSERT(!node.isTreeScope()); | 111 ASSERT(!node.isTreeScope()); |
| 108 ASSERT(node.treeScope() == m_oldScope); | 112 ASSERT(node.treeScope() == m_oldScope); |
| 113 #if !ENABLE(OILPAN) | |
| 109 m_newScope.guardRef(); | 114 m_newScope.guardRef(); |
| 110 m_oldScope.guardDeref(); | 115 m_oldScope.guardDeref(); |
| 116 #endif | |
| 111 node.setTreeScope(&m_newScope); | 117 node.setTreeScope(&m_newScope); |
| 112 } | 118 } |
| 113 | 119 |
| 114 inline void TreeScopeAdopter::moveNodeToNewDocument(Node& node, Document& oldDoc ument, Document& newDocument) const | 120 inline void TreeScopeAdopter::moveNodeToNewDocument(Node& node, Document& oldDoc ument, Document& newDocument) const |
| 115 { | 121 { |
| 116 ASSERT(oldDocument != newDocument); | 122 ASSERT(oldDocument != newDocument); |
| 117 | 123 |
| 118 if (node.hasRareData()) { | 124 if (node.hasRareData()) { |
| 119 NodeRareData* rareData = node.rareData(); | 125 NodeRareData* rareData = node.rareData(); |
| 120 if (rareData->nodeLists()) | 126 if (rareData->nodeLists()) |
| 121 rareData->nodeLists()->adoptDocument(oldDocument, newDocument); | 127 rareData->nodeLists()->adoptDocument(oldDocument, newDocument); |
| 122 } | 128 } |
| 123 | 129 |
| 124 oldDocument.moveNodeIteratorsToNewDocument(node, newDocument); | 130 oldDocument.moveNodeIteratorsToNewDocument(node, newDocument); |
| 125 | 131 |
| 126 if (node.isShadowRoot()) | 132 if (node.isShadowRoot()) |
| 127 toShadowRoot(node).setDocument(newDocument); | 133 toShadowRoot(node).setDocument(newDocument); |
| 128 | 134 |
| 129 #ifndef NDEBUG | 135 #ifndef NDEBUG |
| 130 didMoveToNewDocumentWasCalled = false; | 136 didMoveToNewDocumentWasCalled = false; |
| 131 oldDocumentDidMoveToNewDocumentWasCalledWith = &oldDocument; | 137 oldDocumentDidMoveToNewDocumentWasCalledWith = &oldDocument; |
| 132 #endif | 138 #endif |
| 133 | 139 |
| 134 node.didMoveToNewDocument(oldDocument); | 140 node.didMoveToNewDocument(oldDocument); |
| 135 ASSERT(didMoveToNewDocumentWasCalled); | 141 ASSERT(didMoveToNewDocumentWasCalled); |
| 136 } | 142 } |
| 137 | 143 |
| 138 } | 144 } |
| OLD | NEW |