Title: [217876] trunk/Source/WebCore
Revision
217876
Author
rn...@webkit.org
Date
2017-06-07 01:02:46 -0700 (Wed, 07 Jun 2017)

Log Message

Merge TreeScopeAdopter into TreeScope
https://bugs.webkit.org/show_bug.cgi?id=173040

Reviewed by Antti Koivisto.

Merged TreeScopeAdopter into TreeScope since it's used by TreeScope::adoptIfNeeded.

Most of code changes are for didMoveToNewDocument taking the new document as an argument,
which is used by ShadowRoot::didMoveToNewDocument to update its document scope.

No new tests since there should be no behavioral change.

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:
* dom/Element.cpp:
(WebCore::Element::didMoveToNewDocument):
* dom/Element.h:
* dom/Node.cpp:
(WebCore::Node::didMoveToNewDocument): Moved the code to moves the node lists and node iterators here
from TreeScopeAdopter::moveNodeToNewDocument.
* dom/Node.h:
* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::didMoveToNewDocument): Moved the code to update the document scope here
from TreeScopeAdopter::moveNodeToNewDocument.
* dom/ShadowRoot.h:
* dom/TreeScope.cpp:
(WebCore::TreeScope::adoptIfNeeded):
(WebCore::TreeScope::moveTreeToNewScope): Moved from TreeScopeAdopter. Now takes the old tree scope and
the new tree scope as arguments (they used to be members of TreeScopeAdopter). Also merged updateTreeScope
into this function.
(WebCore::TreeScope::ensureDidMoveToNewDocumentWasCalled): Moved from TreeScopeAdopter.
(WebCore::TreeScope::moveNodeToNewDocument): Ditto. The code to adopt node lists and node iterators have
been moved to Node::didMoveToNewDocument.
(WebCore::TreeScope::moveShadowTreeToNewDocument): Moved from TreeScopeAdopter.
* dom/TreeScope.h:
(WebCore::TreeScope::ensureDidMoveToNewDocumentWasCalled):
* dom/TreeScopeAdopter.cpp: Removed.
* dom/TreeScopeAdopter.h: Removed.
* html/HTMLFieldSetElement.cpp:
(WebCore::HTMLFieldSetElement::didMoveToNewDocument):
* html/HTMLFieldSetElement.h:
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::didMoveToNewDocument):
* html/HTMLFormControlElement.h:
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::didMoveToNewDocument):
* html/HTMLFormElement.h:
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::didMoveToNewDocument):
* html/HTMLImageElement.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::didMoveToNewDocument): Grouped related function calls on new/old documents.
* html/HTMLInputElement.h:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::didMoveToNewDocument):
* html/HTMLMediaElement.h:
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::didMoveToNewDocument):
* html/HTMLObjectElement.h:
* html/HTMLPictureElement.cpp:
(WebCore::HTMLPictureElement::didMoveToNewDocument):
* html/HTMLPictureElement.h:
* html/HTMLPlugInImageElement.cpp:
(WebCore::HTMLPlugInImageElement::didMoveToNewDocument):
* html/HTMLPlugInImageElement.h:
* html/HTMLTemplateElement.cpp:
(WebCore::HTMLTemplateElement::didMoveToNewDocument):
* html/HTMLTemplateElement.h:
* html/HTMLVideoElement.cpp:
(WebCore::HTMLVideoElement::didMoveToNewDocument):
* html/HTMLVideoElement.h:
* html/ImageDocument.cpp:
(WebCore::ImageDocumentElement::didMoveToNewDocument):
* svg/SVGImageElement.cpp:
(WebCore::SVGImageElement::didMoveToNewDocument):
* svg/SVGImageElement.h:
* svg/SVGSVGElement.cpp:
(WebCore::SVGSVGElement::didMoveToNewDocument):
* svg/SVGSVGElement.h:

Modified Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (217875 => 217876)


--- trunk/Source/WebCore/CMakeLists.txt	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/CMakeLists.txt	2017-06-07 08:02:46 UTC (rev 217876)
@@ -1567,7 +1567,6 @@
     dom/TransitionEvent.cpp
     dom/Traversal.cpp
     dom/TreeScope.cpp
-    dom/TreeScopeAdopter.cpp
     dom/TreeWalker.cpp
     dom/UIEvent.cpp
     dom/UIEventWithKeyState.cpp

Modified: trunk/Source/WebCore/ChangeLog (217875 => 217876)


--- trunk/Source/WebCore/ChangeLog	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/ChangeLog	2017-06-07 08:02:46 UTC (rev 217876)
@@ -1,3 +1,85 @@
+2017-06-07  Ryosuke Niwa  <rn...@webkit.org>
+
+        Merge TreeScopeAdopter into TreeScope
+        https://bugs.webkit.org/show_bug.cgi?id=173040
+
+        Reviewed by Antti Koivisto.
+
+        Merged TreeScopeAdopter into TreeScope since it's used by TreeScope::adoptIfNeeded.
+
+        Most of code changes are for didMoveToNewDocument taking the new document as an argument,
+        which is used by ShadowRoot::didMoveToNewDocument to update its document scope.
+
+        No new tests since there should be no behavioral change.
+
+        * CMakeLists.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * dom/Element.cpp:
+        (WebCore::Element::didMoveToNewDocument):
+        * dom/Element.h:
+        * dom/Node.cpp:
+        (WebCore::Node::didMoveToNewDocument): Moved the code to moves the node lists and node iterators here
+        from TreeScopeAdopter::moveNodeToNewDocument.
+        * dom/Node.h:
+        * dom/ShadowRoot.cpp:
+        (WebCore::ShadowRoot::didMoveToNewDocument): Moved the code to update the document scope here
+        from TreeScopeAdopter::moveNodeToNewDocument.
+        * dom/ShadowRoot.h:
+        * dom/TreeScope.cpp:
+        (WebCore::TreeScope::adoptIfNeeded):
+        (WebCore::TreeScope::moveTreeToNewScope): Moved from TreeScopeAdopter. Now takes the old tree scope and
+        the new tree scope as arguments (they used to be members of TreeScopeAdopter). Also merged updateTreeScope
+        into this function.
+        (WebCore::TreeScope::ensureDidMoveToNewDocumentWasCalled): Moved from TreeScopeAdopter.
+        (WebCore::TreeScope::moveNodeToNewDocument): Ditto. The code to adopt node lists and node iterators have
+        been moved to Node::didMoveToNewDocument.
+        (WebCore::TreeScope::moveShadowTreeToNewDocument): Moved from TreeScopeAdopter.
+        * dom/TreeScope.h:
+        (WebCore::TreeScope::ensureDidMoveToNewDocumentWasCalled):
+        * dom/TreeScopeAdopter.cpp: Removed.
+        * dom/TreeScopeAdopter.h: Removed.
+        * html/HTMLFieldSetElement.cpp:
+        (WebCore::HTMLFieldSetElement::didMoveToNewDocument):
+        * html/HTMLFieldSetElement.h:
+        * html/HTMLFormControlElement.cpp:
+        (WebCore::HTMLFormControlElement::didMoveToNewDocument):
+        * html/HTMLFormControlElement.h:
+        * html/HTMLFormElement.cpp:
+        (WebCore::HTMLFormElement::didMoveToNewDocument):
+        * html/HTMLFormElement.h:
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::didMoveToNewDocument):
+        * html/HTMLImageElement.h:
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::didMoveToNewDocument): Grouped related function calls on new/old documents.
+        * html/HTMLInputElement.h:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::didMoveToNewDocument):
+        * html/HTMLMediaElement.h:
+        * html/HTMLObjectElement.cpp:
+        (WebCore::HTMLObjectElement::didMoveToNewDocument):
+        * html/HTMLObjectElement.h:
+        * html/HTMLPictureElement.cpp:
+        (WebCore::HTMLPictureElement::didMoveToNewDocument):
+        * html/HTMLPictureElement.h:
+        * html/HTMLPlugInImageElement.cpp:
+        (WebCore::HTMLPlugInImageElement::didMoveToNewDocument):
+        * html/HTMLPlugInImageElement.h:
+        * html/HTMLTemplateElement.cpp:
+        (WebCore::HTMLTemplateElement::didMoveToNewDocument):
+        * html/HTMLTemplateElement.h:
+        * html/HTMLVideoElement.cpp:
+        (WebCore::HTMLVideoElement::didMoveToNewDocument):
+        * html/HTMLVideoElement.h:
+        * html/ImageDocument.cpp:
+        (WebCore::ImageDocumentElement::didMoveToNewDocument):
+        * svg/SVGImageElement.cpp:
+        (WebCore::SVGImageElement::didMoveToNewDocument):
+        * svg/SVGImageElement.h:
+        * svg/SVGSVGElement.cpp:
+        (WebCore::SVGSVGElement::didMoveToNewDocument):
+        * svg/SVGSVGElement.h:
+
 2017-06-06  Ryosuke Niwa  <rn...@webkit.org>
 
         Use a dedicated node flag to identify a Document node

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (217875 => 217876)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-06-07 08:02:46 UTC (rev 217876)
@@ -4491,8 +4491,6 @@
 		A77979290D6B9E64003851B9 /* JSImageData.h in Headers */ = {isa = PBXBuildFile; fileRef = A77979250D6B9E64003851B9 /* JSImageData.h */; };
 		A77B41A012E675A90054343D /* TextEventInputType.h in Headers */ = {isa = PBXBuildFile; fileRef = A77B419F12E675A90054343D /* TextEventInputType.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A77D0012133B0AEB00D6658C /* TextChecking.h in Headers */ = {isa = PBXBuildFile; fileRef = A77D0011133B0AEB00D6658C /* TextChecking.h */; settings = {ATTRIBUTES = (Private, ); }; };
-		A77E1FEF14AACB6E005B7CB6 /* TreeScopeAdopter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A77E1FED14AACB6E005B7CB6 /* TreeScopeAdopter.cpp */; };
-		A77E1FF014AACB6E005B7CB6 /* TreeScopeAdopter.h in Headers */ = {isa = PBXBuildFile; fileRef = A77E1FEE14AACB6E005B7CB6 /* TreeScopeAdopter.h */; };
 		A784941B0B5FE507001E237A /* DataTransfer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A784941A0B5FE507001E237A /* DataTransfer.cpp */; };
 		A78FE13B12366B1000ACE8D0 /* SpellChecker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A78FE13912366B1000ACE8D0 /* SpellChecker.cpp */; };
 		A78FE13C12366B1000ACE8D0 /* SpellChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = A78FE13A12366B1000ACE8D0 /* SpellChecker.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -12771,8 +12769,6 @@
 		A77979250D6B9E64003851B9 /* JSImageData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSImageData.h; sourceTree = "<group>"; };
 		A77B419F12E675A90054343D /* TextEventInputType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextEventInputType.h; sourceTree = "<group>"; };
 		A77D0011133B0AEB00D6658C /* TextChecking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextChecking.h; sourceTree = "<group>"; };
-		A77E1FED14AACB6E005B7CB6 /* TreeScopeAdopter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TreeScopeAdopter.cpp; sourceTree = "<group>"; };
-		A77E1FEE14AACB6E005B7CB6 /* TreeScopeAdopter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TreeScopeAdopter.h; sourceTree = "<group>"; };
 		A784941A0B5FE507001E237A /* DataTransfer.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = DataTransfer.cpp; sourceTree = "<group>"; };
 		A78FE13912366B1000ACE8D0 /* SpellChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SpellChecker.cpp; sourceTree = "<group>"; };
 		A78FE13A12366B1000ACE8D0 /* SpellChecker.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = SpellChecker.h; sourceTree = "<group>"; };
@@ -26011,8 +26007,6 @@
 				37FD4297118368460093C029 /* TreeDepthLimit.h */,
 				14D64B5A134A5B6B00E58FDA /* TreeScope.cpp */,
 				14D64B5B134A5B6B00E58FDA /* TreeScope.h */,
-				A77E1FED14AACB6E005B7CB6 /* TreeScopeAdopter.cpp */,
-				A77E1FEE14AACB6E005B7CB6 /* TreeScopeAdopter.h */,
 				854FE72E0A2297BE0058D7AD /* TreeWalker.cpp */,
 				854FE72F0A2297BE0058D7AD /* TreeWalker.h */,
 				1A750D3C0A90DE35000FF215 /* TreeWalker.idl */,
@@ -29972,7 +29966,6 @@
 				854FE7370A2297BE0058D7AD /* Traversal.h in Headers */,
 				37FD4298118368460093C029 /* TreeDepthLimit.h in Headers */,
 				14D64B5D134A5B6B00E58FDA /* TreeScope.h in Headers */,
-				A77E1FF014AACB6E005B7CB6 /* TreeScopeAdopter.h in Headers */,
 				854FE7390A2297BE0058D7AD /* TreeWalker.h in Headers */,
 				2D232C001A326F02006BF2DB /* TUCallSPI.h in Headers */,
 				C375D7FE16639519006184AB /* TypeAhead.h in Headers */,
@@ -33702,7 +33695,6 @@
 				49E911D10EF86D47009D0CAF /* TranslateTransformOperation.cpp in Sources */,
 				854FE7360A2297BE0058D7AD /* Traversal.cpp in Sources */,
 				14D64B5C134A5B6B00E58FDA /* TreeScope.cpp in Sources */,
-				A77E1FEF14AACB6E005B7CB6 /* TreeScopeAdopter.cpp in Sources */,
 				854FE7380A2297BE0058D7AD /* TreeWalker.cpp in Sources */,
 				C375D7FD16639519006184AB /* TypeAhead.cpp in Sources */,
 				93309E19099E64920056E581 /* TypingCommand.cpp in Sources */,

Modified: trunk/Source/WebCore/dom/DOMAllInOne.cpp (217875 => 217876)


--- trunk/Source/WebCore/dom/DOMAllInOne.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/dom/DOMAllInOne.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -152,7 +152,6 @@
 #include "TransitionEvent.cpp"
 #include "Traversal.cpp"
 #include "TreeScope.cpp"
-#include "TreeScopeAdopter.cpp"
 #include "TreeWalker.cpp"
 #include "UIEvent.cpp"
 #include "UIEventWithKeyState.cpp"

Modified: trunk/Source/WebCore/dom/Element.cpp (217875 => 217876)


--- trunk/Source/WebCore/dom/Element.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/dom/Element.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -1530,9 +1530,10 @@
 {
 }
 
-void Element::didMoveToNewDocument(Document& oldDocument)
+void Element::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
-    Node::didMoveToNewDocument(oldDocument);
+    ASSERT_WITH_SECURITY_IMPLICATION(&document() == &newDocument);
+    Node::didMoveToNewDocument(oldDocument, newDocument);
 
     if (oldDocument.inQuirksMode() != document().inQuirksMode()) {
         // ElementData::m_classNames or ElementData::m_idForStyleResolution need to be updated with the right case.
@@ -1543,7 +1544,7 @@
     }
 
     if (UNLIKELY(isDefinedCustomElement()))
-        CustomElementReactionQueue::enqueueAdoptedCallbackIfNeeded(*this, oldDocument, document());
+        CustomElementReactionQueue::enqueueAdoptedCallbackIfNeeded(*this, oldDocument, newDocument);
 }
 
 bool Element::hasAttributes() const

Modified: trunk/Source/WebCore/dom/Element.h (217875 => 217876)


--- trunk/Source/WebCore/dom/Element.h	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/dom/Element.h	2017-06-07 08:02:46 UTC (rev 217876)
@@ -567,7 +567,7 @@
     void childrenChanged(const ChildChange&) override;
     void removeAllEventListeners() final;
     virtual void parserDidSetAttributes();
-    void didMoveToNewDocument(Document&) override;
+    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) override;
 
     void clearTabIndexExplicitlyIfNeeded();
     void setTabIndexExplicitly(int);

Modified: trunk/Source/WebCore/dom/Node.cpp (217875 => 217876)


--- trunk/Source/WebCore/dom/Node.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/dom/Node.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -68,7 +68,6 @@
 #include "TemplateContentDocumentFragment.h"
 #include "TextEvent.h"
 #include "TouchEvent.h"
-#include "TreeScopeAdopter.h"
 #include "WheelEvent.h"
 #include "XMLNSNames.h"
 #include "XMLNames.h"
@@ -1925,14 +1924,22 @@
     return NodeEventTargetInterfaceType;
 }
 
-void Node::didMoveToNewDocument(Document& oldDocument)
+void Node::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
-    TreeScopeAdopter::ensureDidMoveToNewDocumentWasCalled(oldDocument);
+    ASSERT_WITH_SECURITY_IMPLICATION(&document() == &newDocument);
+    TreeScope::ensureDidMoveToNewDocumentWasCalled(oldDocument);
 
+    if (hasRareData()) {
+        if (auto* nodeLists = rareData()->nodeLists())
+            nodeLists->adoptDocument(oldDocument, newDocument);
+    }
+
+    oldDocument.moveNodeIteratorsToNewDocument(*this, newDocument);
+
     if (auto* eventTargetData = this->eventTargetData()) {
         if (!eventTargetData->eventListenerMap.isEmpty()) {
             for (auto& type : eventTargetData->eventListenerMap.eventTypes())
-                document().addListenerTypeIfNeeded(type);
+                newDocument.addListenerTypeIfNeeded(type);
         }
     }
 
@@ -1944,7 +1951,7 @@
     unsigned numWheelEventHandlers = eventListeners(eventNames().mousewheelEvent).size() + eventListeners(eventNames().wheelEvent).size();
     for (unsigned i = 0; i < numWheelEventHandlers; ++i) {
         oldDocument.didRemoveWheelEventHandler(*this);
-        document().didAddWheelEventHandler(*this);
+        newDocument.didAddWheelEventHandler(*this);
     }
 
     unsigned numTouchEventListeners = 0;
@@ -1953,11 +1960,11 @@
 
     for (unsigned i = 0; i < numTouchEventListeners; ++i) {
         oldDocument.didRemoveTouchEventHandler(*this);
-        document().didAddTouchEventHandler(*this);
+        newDocument.didAddTouchEventHandler(*this);
 
 #if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS)
         oldDocument.removeTouchEventListener(*this);
-        document().addTouchEventListener(*this);
+        newDocument.addTouchEventListener(*this);
 #endif
     }
 
@@ -1968,18 +1975,18 @@
 
     for (unsigned i = 0; i < numGestureEventListeners; ++i) {
         oldDocument.removeTouchEventHandler(*this);
-        document().addTouchEventHandler(*this);
+        newDocument.addTouchEventHandler(*this);
     }
 #endif
 
     if (auto* registry = mutationObserverRegistry()) {
         for (auto& registration : *registry)
-            document().addMutationObserverTypes(registration->mutationTypes());
+            newDocument.addMutationObserverTypes(registration->mutationTypes());
     }
 
     if (auto* transientRegistry = transientMutationObserverRegistry()) {
         for (auto& registration : *transientRegistry)
-            document().addMutationObserverTypes(registration->mutationTypes());
+            newDocument.addMutationObserverTypes(registration->mutationTypes());
     }
 
 #if !ASSERT_DISABLED || ENABLE(SECURITY_ASSERTIONS)

Modified: trunk/Source/WebCore/dom/Node.h (217875 => 217876)


--- trunk/Source/WebCore/dom/Node.h	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/dom/Node.h	2017-06-07 08:02:46 UTC (rev 217876)
@@ -83,7 +83,6 @@
 
     friend class Document;
     friend class TreeScope;
-    friend class TreeScopeAdopter;
 public:
     enum NodeType {
         ELEMENT_NODE = 1,
@@ -632,7 +631,7 @@
     };
     Node(Document&, ConstructionType);
 
-    virtual void didMoveToNewDocument(Document& oldDocument);
+    virtual void didMoveToNewDocument(Document& oldDocument, Document& newDocument);
     
     virtual void addSubresourceAttributeURLs(ListHashSet<URL>&) const { }
 

Modified: trunk/Source/WebCore/dom/ShadowRoot.cpp (217875 => 217876)


--- trunk/Source/WebCore/dom/ShadowRoot.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/dom/ShadowRoot.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -81,7 +81,7 @@
     willBeDeletedFrom(document());
 
     // We must remove all of our children first before the TreeScope destructor
-    // runs so we don't go through TreeScopeAdopter for each child with a
+    // runs so we don't go through TreeScope::adoptIfNeeded for each child with a
     // destructed tree scope in each descendant.
     removeDetachedChildren();
 }
@@ -102,15 +102,17 @@
         document().didRemoveInDocumentShadowRoot(*this);
 }
 
-void ShadowRoot::didMoveToNewDocument(Document& oldDocument)
+void ShadowRoot::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
-    ASSERT(&document() != &oldDocument);
-    ASSERT(&m_styleScope->document() == &oldDocument);
+    ASSERT_WITH_SECURITY_IMPLICATION(&document() == &oldDocument || &document() == &newDocument);
+    setDocumentScope(newDocument);
+    ASSERT_WITH_SECURITY_IMPLICATION(&document() == &newDocument);
+    ASSERT_WITH_SECURITY_IMPLICATION(&m_styleScope->document() == &oldDocument);
 
     // Style scopes are document specific.
     m_styleScope = std::make_unique<Style::Scope>(*this);
 
-    DocumentFragment::didMoveToNewDocument(oldDocument);
+    DocumentFragment::didMoveToNewDocument(oldDocument, newDocument);
 }
 
 Style::Scope& ShadowRoot::styleScope()

Modified: trunk/Source/WebCore/dom/ShadowRoot.h (217875 => 217876)


--- trunk/Source/WebCore/dom/ShadowRoot.h	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/dom/ShadowRoot.h	2017-06-07 08:02:46 UTC (rev 217876)
@@ -96,7 +96,7 @@
 
     Node::InsertionNotificationRequest insertedInto(ContainerNode& insertionPoint) override;
     void removedFrom(ContainerNode& insertionPoint) override;
-    void didMoveToNewDocument(Document& oldDocument) override;
+    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) override;
 
     bool m_resetStyleInheritance { false };
     ShadowRootMode m_type { ShadowRootMode::UserAgent };

Modified: trunk/Source/WebCore/dom/TreeScope.cpp (217875 => 217876)


--- trunk/Source/WebCore/dom/TreeScope.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/dom/TreeScope.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -27,6 +27,7 @@
 #include "config.h"
 #include "TreeScope.h"
 
+#include "Attr.h"
 #include "DOMWindow.h"
 #include "ElementIterator.h"
 #include "FocusController.h"
@@ -38,12 +39,12 @@
 #include "HTMLMapElement.h"
 #include "HitTestResult.h"
 #include "IdTargetObserverRegistry.h"
+#include "NodeRareData.h"
 #include "Page.h"
 #include "PointerLockController.h"
 #include "RenderView.h"
 #include "RuntimeEnabledFeatures.h"
 #include "ShadowRoot.h"
-#include "TreeScopeAdopter.h"
 #include <wtf/text/CString.h>
 
 namespace WebCore {
@@ -371,11 +372,97 @@
 {
     ASSERT(!node.isDocumentNode());
     ASSERT(!node.m_deletionHasBegun);
-    TreeScopeAdopter adopter(node, *this);
-    if (adopter.needsScopeChange())
-        adopter.execute();
+    TreeScope& treeScopeOfNode = node.treeScope();
+    if (this != &treeScopeOfNode)
+        moveTreeToNewScope(node, treeScopeOfNode, *this);
 }
 
+void TreeScope::moveTreeToNewScope(Node& root, TreeScope& oldScope, TreeScope& newScope)
+{
+    ASSERT(&oldScope != &newScope);
+    ASSERT_WITH_SECURITY_IMPLICATION(&root.treeScope() == &oldScope);
+
+    // If an element is moved from a document and then eventually back again the collection cache for
+    // that element may contain stale data as changes made to it will have updated the DOMTreeVersion
+    // of the document it was moved to. By increasing the DOMTreeVersion of the donating document here
+    // we ensure that the collection cache will be invalidated as needed when the element is moved back.
+    Document& oldDocument = oldScope.documentScope();
+    Document& newDocument = newScope.documentScope();
+    bool willMoveToNewDocument = &oldDocument != &newDocument;
+    if (willMoveToNewDocument) {
+        oldDocument.incrementReferencingNodeCount();
+        oldDocument.incDOMTreeVersion();
+    }
+
+    for (Node* node = &root; node; node = NodeTraversal::next(*node, &root)) {
+        ASSERT(!node->isTreeScope());
+        ASSERT(&node->treeScope() == &oldScope);
+        node->setTreeScope(newScope);
+
+        if (willMoveToNewDocument)
+            moveNodeToNewDocument(*node, oldDocument, newDocument);
+        else if (node->hasRareData()) {
+            if (auto* nodeLists = node->rareData()->nodeLists())
+                nodeLists->adoptTreeScope();
+        }
+
+        if (!is<Element>(*node))
+            continue;
+
+        if (node->hasSyntheticAttrChildNodes()) {
+            for (auto& attr : downcast<Element>(*node).attrNodeList())
+                moveTreeToNewScope(*attr, oldScope, newScope);
+        }
+
+        if (auto* shadow = node->shadowRoot()) {
+            ASSERT_WITH_SECURITY_IMPLICATION(&shadow->document() == &oldDocument);
+            shadow->setParentTreeScope(newScope);
+            if (willMoveToNewDocument)
+                moveShadowTreeToNewDocument(*shadow, oldDocument, newDocument);
+        }
+    }
+
+    if (willMoveToNewDocument)
+        oldDocument.decrementReferencingNodeCount();
+}
+
+#if !ASSERT_DISABLED || ENABLE(SECURITY_ASSERTIONS)
+static bool didMoveToNewDocumentWasCalled = false;
+static Document* oldDocumentDidMoveToNewDocumentWasCalledWith = nullptr;
+
+void TreeScope::ensureDidMoveToNewDocumentWasCalled(Document& oldDocument)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(!didMoveToNewDocumentWasCalled);
+    ASSERT_WITH_SECURITY_IMPLICATION(&oldDocument == oldDocumentDidMoveToNewDocumentWasCalledWith);
+    didMoveToNewDocumentWasCalled = true;
+}
+#endif
+
+void TreeScope::moveNodeToNewDocument(Node& node, Document& oldDocument, Document& newDocument)
+{
+    ASSERT(!node.isConnected() || &oldDocument != &newDocument);
+
+    newDocument.incrementReferencingNodeCount();
+    oldDocument.decrementReferencingNodeCount();
+
+#if !ASSERT_DISABLED || ENABLE(SECURITY_ASSERTIONS)
+    didMoveToNewDocumentWasCalled = false;
+    oldDocumentDidMoveToNewDocumentWasCalledWith = &oldDocument;
+#endif
+
+    node.didMoveToNewDocument(oldDocument, newDocument);
+    ASSERT_WITH_SECURITY_IMPLICATION(didMoveToNewDocumentWasCalled);
+}
+
+void TreeScope::moveShadowTreeToNewDocument(ShadowRoot& shadowRoot, Document& oldDocument, Document& newDocument)
+{
+    for (Node* node = &shadowRoot; node; node = NodeTraversal::next(*node, &shadowRoot)) {
+        moveNodeToNewDocument(*node, oldDocument, newDocument);
+        if (auto* shadow = node->shadowRoot())
+            moveShadowTreeToNewDocument(*shadow, oldDocument, newDocument);
+    }
+}
+
 static Element* focusedFrameOwnerElement(Frame* focusedFrame, Frame* currentFrame)
 {
     for (; focusedFrame; focusedFrame = focusedFrame->tree().parent()) {

Modified: trunk/Source/WebCore/dom/TreeScope.h (217875 => 217876)


--- trunk/Source/WebCore/dom/TreeScope.h	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/dom/TreeScope.h	2017-06-07 08:02:46 UTC (rev 217876)
@@ -45,7 +45,6 @@
 
 class TreeScope {
     friend class Document;
-    friend class TreeScopeAdopter;
 
 public:
     TreeScope* parentTreeScope() const { return m_parentTreeScope; }
@@ -99,6 +98,11 @@
 
     // Used by the basic DOM mutation methods (e.g., appendChild()).
     void adoptIfNeeded(Node&);
+#if !ASSERT_DISABLED || ENABLE(SECURITY_ASSERTIONS)
+    static void ensureDidMoveToNewDocumentWasCalled(Document& oldDocument);
+#else
+    static void ensureDidMoveToNewDocumentWasCalled(Document&) { }
+#endif
 
     ContainerNode& rootNode() const { return m_rootNode; }
 
@@ -118,6 +122,10 @@
     Node* nodeFromPoint(const LayoutPoint& clientPoint, LayoutPoint* localPoint);
 
 private:
+    void moveTreeToNewScope(Node&, TreeScope& oldScope, TreeScope& newScope);
+    void moveNodeToNewDocument(Node&, Document& oldDocument, Document& newDocument);
+    void moveShadowTreeToNewDocument(ShadowRoot&, Document& oldDocument, Document& newDocument);
+
     ContainerNode& m_rootNode;
     std::reference_wrapper<Document> m_documentScope;
     TreeScope* m_parentTreeScope;

Deleted: trunk/Source/WebCore/dom/TreeScopeAdopter.cpp (217875 => 217876)


--- trunk/Source/WebCore/dom/TreeScopeAdopter.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/dom/TreeScopeAdopter.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -1,137 +0,0 @@
-/*
- * Copyright (C) 1999 Lars Knoll (kn...@kde.org)
- *           (C) 1999 Antti Koivisto (koivi...@kde.org)
- *           (C) 2001 Dirk Mueller (muel...@kde.org)
- * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
- * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
- * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
- * Copyright (C) 2011 Google Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include "TreeScopeAdopter.h"
-
-#include "Attr.h"
-#include "ElementRareData.h"
-#include "NodeTraversal.h"
-
-namespace WebCore {
-
-// FIXME: Do we ever change tree scopes except between documents?
-void TreeScopeAdopter::moveTreeToNewScope(Node& root) const
-{
-    ASSERT(needsScopeChange());
-
-    // If an element is moved from a document and then eventually back again the collection cache for
-    // that element may contain stale data as changes made to it will have updated the DOMTreeVersion
-    // of the document it was moved to. By increasing the DOMTreeVersion of the donating document here
-    // we ensure that the collection cache will be invalidated as needed when the element is moved back.
-    Document& oldDocument = m_oldScope.documentScope();
-    Document& newDocument = m_newScope.documentScope();
-    bool willMoveToNewDocument = &oldDocument != &newDocument;
-    if (willMoveToNewDocument) {
-        oldDocument.incrementReferencingNodeCount();
-        oldDocument.incDOMTreeVersion();
-    }
-
-    for (Node* node = &root; node; node = NodeTraversal::next(*node, &root)) {
-        updateTreeScope(*node);
-
-        if (willMoveToNewDocument)
-            moveNodeToNewDocument(*node, oldDocument, newDocument);
-        else if (node->hasRareData()) {
-            NodeRareData* rareData = node->rareData();
-            if (rareData->nodeLists())
-                rareData->nodeLists()->adoptTreeScope();
-        }
-
-        if (!is<Element>(*node))
-            continue;
-
-        if (node->hasSyntheticAttrChildNodes()) {
-            for (auto& attr : downcast<Element>(*node).attrNodeList())
-                moveTreeToNewScope(*attr);
-        }
-
-        if (auto* shadow = node->shadowRoot()) {
-            shadow->setParentTreeScope(m_newScope);
-            if (willMoveToNewDocument)
-                moveShadowTreeToNewDocument(*shadow, oldDocument, newDocument);
-        }
-    }
-
-    if (willMoveToNewDocument)
-        oldDocument.decrementReferencingNodeCount();
-}
-
-void TreeScopeAdopter::moveShadowTreeToNewDocument(ShadowRoot& shadowRoot, Document& oldDocument, Document& newDocument) const
-{
-    for (Node* node = &shadowRoot; node; node = NodeTraversal::next(*node, &shadowRoot)) {
-        moveNodeToNewDocument(*node, oldDocument, newDocument);
-        if (auto* shadow = node->shadowRoot())
-            moveShadowTreeToNewDocument(*shadow, oldDocument, newDocument);
-    }
-}
-
-#ifndef NDEBUG
-static bool didMoveToNewDocumentWasCalled = false;
-static Document* oldDocumentDidMoveToNewDocumentWasCalledWith = nullptr;
-
-void TreeScopeAdopter::ensureDidMoveToNewDocumentWasCalled(Document& oldDocument)
-{
-    ASSERT(!didMoveToNewDocumentWasCalled);
-    ASSERT_UNUSED(oldDocument, &oldDocument == oldDocumentDidMoveToNewDocumentWasCalledWith);
-    didMoveToNewDocumentWasCalled = true;
-}
-#endif
-
-inline void TreeScopeAdopter::updateTreeScope(Node& node) const
-{
-    ASSERT(!node.isTreeScope());
-    ASSERT(&node.treeScope() == &m_oldScope);
-    node.setTreeScope(m_newScope);
-}
-
-inline void TreeScopeAdopter::moveNodeToNewDocument(Node& node, Document& oldDocument, Document& newDocument) const
-{
-    ASSERT(!node.isConnected() || &oldDocument != &newDocument);
-
-    newDocument.incrementReferencingNodeCount();
-    oldDocument.decrementReferencingNodeCount();
-
-    if (node.hasRareData()) {
-        NodeRareData* rareData = node.rareData();
-        if (auto* nodeLists = rareData->nodeLists())
-            nodeLists->adoptDocument(oldDocument, newDocument);
-    }
-
-    oldDocument.moveNodeIteratorsToNewDocument(node, newDocument);
-
-    if (is<ShadowRoot>(node))
-        downcast<ShadowRoot>(node).setDocumentScope(newDocument);
-
-#ifndef NDEBUG
-    didMoveToNewDocumentWasCalled = false;
-    oldDocumentDidMoveToNewDocumentWasCalledWith = &oldDocument;
-#endif
-
-    node.didMoveToNewDocument(oldDocument);
-    ASSERT(didMoveToNewDocumentWasCalled);
-}
-
-}

Deleted: trunk/Source/WebCore/dom/TreeScopeAdopter.h (217875 => 217876)


--- trunk/Source/WebCore/dom/TreeScopeAdopter.h	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/dom/TreeScopeAdopter.h	2017-06-07 08:02:46 UTC (rev 217876)
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 1999 Lars Knoll (kn...@kde.org)
- *           (C) 1999 Antti Koivisto (koivi...@kde.org)
- *           (C) 2001 Dirk Mueller (muel...@kde.org)
- * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
- * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
- * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
- * Copyright (C) 2011 Google Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#pragma once
-
-#include "Node.h"
-
-namespace WebCore {
-
-class TreeScope;
-
-class TreeScopeAdopter {
-public:
-    explicit TreeScopeAdopter(Node& toAdopt, TreeScope& newScope);
-
-    void execute() const { moveTreeToNewScope(m_toAdopt); }
-    bool needsScopeChange() const { return &m_oldScope != &m_newScope; }
-
-#ifdef NDEBUG
-    static void ensureDidMoveToNewDocumentWasCalled(Document&) { }
-#else
-    static void ensureDidMoveToNewDocumentWasCalled(Document&);
-#endif
-
-private:
-    void updateTreeScope(Node&) const;
-    void moveTreeToNewScope(Node&) const;
-    void moveShadowTreeToNewDocument(ShadowRoot&, Document& oldDocument, Document& newDocument) const;
-    void moveNodeToNewDocument(Node&, Document& oldDocument, Document& newDocument) const;
-
-    Node& m_toAdopt;
-    TreeScope& m_newScope;
-    TreeScope& m_oldScope;
-};
-
-inline TreeScopeAdopter::TreeScopeAdopter(Node& toAdopt, TreeScope& newScope)
-    : m_toAdopt(toAdopt)
-    , m_newScope(newScope)
-    , m_oldScope(toAdopt.treeScope())
-{
-}
-
-} // namespace WebCore

Modified: trunk/Source/WebCore/html/HTMLFieldSetElement.cpp (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLFieldSetElement.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLFieldSetElement.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -122,12 +122,13 @@
         updateFromControlElementsAncestorDisabledStateUnder(*legend, true);
 }
 
-void HTMLFieldSetElement::didMoveToNewDocument(Document& oldDocument)
+void HTMLFieldSetElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
-    HTMLFormControlElement::didMoveToNewDocument(oldDocument);
+    ASSERT_WITH_SECURITY_IMPLICATION(&document() == &newDocument);
+    HTMLFormControlElement::didMoveToNewDocument(oldDocument, newDocument);
     if (m_hasDisabledAttribute) {
         oldDocument.removeDisabledFieldsetElement();
-        document().addDisabledFieldsetElement();
+        newDocument.addDisabledFieldsetElement();
     }
 }
 

Modified: trunk/Source/WebCore/html/HTMLFieldSetElement.h (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLFieldSetElement.h	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLFieldSetElement.h	2017-06-07 08:02:46 UTC (rev 217876)
@@ -58,7 +58,7 @@
     void disabledAttributeChanged() final;
     void disabledStateChanged() final;
     void childrenChanged(const ChildChange&) final;
-    void didMoveToNewDocument(Document& oldDocument) final;
+    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) final;
 
     bool matchesValidPseudoClass() const final;
     bool matchesInvalidPseudoClass() const final;

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.cpp (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -250,10 +250,10 @@
     }
 }
 
-void HTMLFormControlElement::didMoveToNewDocument(Document& oldDocument)
+void HTMLFormControlElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
     FormAssociatedElement::didMoveToNewDocument(oldDocument);
-    HTMLElement::didMoveToNewDocument(oldDocument);
+    HTMLElement::didMoveToNewDocument(oldDocument, newDocument);
 }
 
 static void addInvalidElementToAncestorFromInsertionPoint(const HTMLFormControlElement& element, ContainerNode* insertionPoint)

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.h (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLFormControlElement.h	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.h	2017-06-07 08:02:46 UTC (rev 217876)
@@ -138,7 +138,7 @@
     InsertionNotificationRequest insertedInto(ContainerNode&) override;
     void finishedInsertingSubtree() override;
     void removedFrom(ContainerNode&) override;
-    void didMoveToNewDocument(Document& oldDocument) override;
+    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) override;
 
     bool supportsFocus() const override;
     bool isKeyboardFocusable(KeyboardEvent&) const override;

Modified: trunk/Source/WebCore/html/HTMLFormElement.cpp (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLFormElement.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLFormElement.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -859,7 +859,7 @@
     resetAssociatedFormControlElements();
 }
 
-void HTMLFormElement::didMoveToNewDocument(Document& oldDocument)
+void HTMLFormElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
     if (!shouldAutocomplete()) {
         oldDocument.unregisterForDocumentSuspensionCallbacks(this);
@@ -866,7 +866,7 @@
         document().registerForDocumentSuspensionCallbacks(this);
     }
 
-    HTMLElement::didMoveToNewDocument(oldDocument);
+    HTMLElement::didMoveToNewDocument(oldDocument, newDocument);
 }
 
 bool HTMLFormElement::shouldAutocomplete() const

Modified: trunk/Source/WebCore/html/HTMLFormElement.h (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLFormElement.h	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLFormElement.h	2017-06-07 08:02:46 UTC (rev 217876)
@@ -147,7 +147,7 @@
 
     void resumeFromDocumentSuspension() final;
 
-    void didMoveToNewDocument(Document& oldDocument) final;
+    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) final;
 
     void copyNonAttributePropertiesFromElement(const Element&) final;
 

Modified: trunk/Source/WebCore/html/HTMLImageElement.cpp (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLImageElement.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLImageElement.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -545,10 +545,10 @@
     addSubresourceURL(urls, document().completeURL(attributeWithoutSynchronization(usemapAttr)));
 }
 
-void HTMLImageElement::didMoveToNewDocument(Document& oldDocument)
+void HTMLImageElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
     m_imageLoader.elementDidMoveToNewDocument();
-    HTMLElement::didMoveToNewDocument(oldDocument);
+    HTMLElement::didMoveToNewDocument(oldDocument, newDocument);
 }
 
 bool HTMLImageElement::isServerMap() const

Modified: trunk/Source/WebCore/html/HTMLImageElement.h (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLImageElement.h	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLImageElement.h	2017-06-07 08:02:46 UTC (rev 217876)
@@ -97,7 +97,7 @@
 protected:
     HTMLImageElement(const QualifiedName&, Document&, HTMLFormElement* = 0);
 
-    void didMoveToNewDocument(Document& oldDocument) override;
+    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) override;
 
 private:
     void parseAttribute(const QualifiedName&, const AtomicString&) override;

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -1521,31 +1521,26 @@
 #endif
 }
 
-void HTMLInputElement::didMoveToNewDocument(Document& oldDocument)
+void HTMLInputElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
     if (imageLoader())
         imageLoader()->elementDidMoveToNewDocument();
 
-    bool needsSuspensionCallback = this->needsSuspensionCallback();
     // Always unregister for cache callbacks when leaving a document, even if we would otherwise like to be registered
-    if (needsSuspensionCallback)
+    if (needsSuspensionCallback()) {
         oldDocument.unregisterForDocumentSuspensionCallbacks(this);
+        newDocument.registerForDocumentSuspensionCallbacks(this);
+    }
     if (isRadioButton())
         oldDocument.formController().radioButtonGroups().removeButton(this);
 #if ENABLE(TOUCH_EVENTS)
-    if (m_hasTouchEventHandler)
+    if (m_hasTouchEventHandler) {
         oldDocument.didRemoveEventTargetNode(*this);
+        newDocument.didAddTouchEventHandler(*this);
+    }
 #endif
 
-    if (needsSuspensionCallback)
-        document().registerForDocumentSuspensionCallbacks(this);
-
-#if ENABLE(TOUCH_EVENTS)
-    if (m_hasTouchEventHandler)
-        document().didAddTouchEventHandler(*this);
-#endif
-
-    HTMLTextFormControlElement::didMoveToNewDocument(oldDocument);
+    HTMLTextFormControlElement::didMoveToNewDocument(oldDocument, newDocument);
 }
 
 void HTMLInputElement::addSubresourceAttributeURLs(ListHashSet<URL>& urls) const

Modified: trunk/Source/WebCore/html/HTMLInputElement.h (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLInputElement.h	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLInputElement.h	2017-06-07 08:02:46 UTC (rev 217876)
@@ -348,7 +348,7 @@
     InsertionNotificationRequest insertedInto(ContainerNode&) final;
     void finishedInsertingSubtree() final;
     void removedFrom(ContainerNode&) final;
-    void didMoveToNewDocument(Document& oldDocument) final;
+    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) final;
 
     bool hasCustomFocusLogic() const final;
     bool isKeyboardFocusable(KeyboardEvent&) const final;

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -712,18 +712,18 @@
 
 }
 
-void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument)
+void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
+    ASSERT_WITH_SECURITY_IMPLICATION(&document() == &newDocument);
     if (m_shouldDelayLoadEvent) {
         oldDocument.decrementLoadEventDelayCount();
-        document().incrementLoadEventDelayCount();
+        newDocument.incrementLoadEventDelayCount();
     }
 
     unregisterWithDocument(oldDocument);
+    registerWithDocument(newDocument);
 
-    registerWithDocument(document());
-
-    HTMLElement::didMoveToNewDocument(oldDocument);
+    HTMLElement::didMoveToNewDocument(oldDocument, newDocument);
     updateShouldAutoplay();
 }
 

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2017-06-07 08:02:46 UTC (rev 217876)
@@ -532,7 +532,7 @@
     void willDetachRenderers() override;
     void didDetachRenderers() override;
 
-    void didMoveToNewDocument(Document& oldDocument) override;
+    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) override;
 
     enum DisplayMode { Unknown, None, Poster, PosterWaitingForVideo, Video };
     DisplayMode displayMode() const { return m_displayMode; }

Modified: trunk/Source/WebCore/html/HTMLObjectElement.cpp (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLObjectElement.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLObjectElement.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -495,10 +495,10 @@
         addSubresourceURL(urls, document().completeURL(useMap));
 }
 
-void HTMLObjectElement::didMoveToNewDocument(Document& oldDocument)
+void HTMLObjectElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
     FormAssociatedElement::didMoveToNewDocument(oldDocument);
-    HTMLPlugInImageElement::didMoveToNewDocument(oldDocument);
+    HTMLPlugInImageElement::didMoveToNewDocument(oldDocument, newDocument);
 }
 
 bool HTMLObjectElement::appendFormData(FormDataList& encoding, bool)

Modified: trunk/Source/WebCore/html/HTMLObjectElement.h (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLObjectElement.h	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLObjectElement.h	2017-06-07 08:02:46 UTC (rev 217876)
@@ -67,7 +67,7 @@
     void finishedInsertingSubtree() final;
     void removedFrom(ContainerNode&) final;
 
-    void didMoveToNewDocument(Document& oldDocument) final;
+    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) final;
 
     void childrenChanged(const ChildChange&) final;
 

Modified: trunk/Source/WebCore/html/HTMLPictureElement.cpp (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLPictureElement.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLPictureElement.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -41,10 +41,10 @@
     document().removeViewportDependentPicture(*this);
 }
 
-void HTMLPictureElement::didMoveToNewDocument(Document& oldDocument)
+void HTMLPictureElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
     oldDocument.removeViewportDependentPicture(*this);
-    HTMLElement::didMoveToNewDocument(oldDocument);
+    HTMLElement::didMoveToNewDocument(oldDocument, newDocument);
     sourcesChanged();
 }
 

Modified: trunk/Source/WebCore/html/HTMLPictureElement.h (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLPictureElement.h	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLPictureElement.h	2017-06-07 08:02:46 UTC (rev 217876)
@@ -48,7 +48,7 @@
 private:
     HTMLPictureElement(const QualifiedName&, Document&);
 
-    void didMoveToNewDocument(Document& oldDocument) final;
+    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) final;
 
     WeakPtrFactory<HTMLPictureElement> m_weakFactory { this };
     Vector<MediaQueryResult> m_viewportDependentMediaQueryResults;

Modified: trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -266,17 +266,18 @@
         invalidateStyleForSubtree();
 }
 
-void HTMLPlugInImageElement::didMoveToNewDocument(Document& oldDocument)
+void HTMLPlugInImageElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
+    ASSERT_WITH_SECURITY_IMPLICATION(&document() == &newDocument);
     if (m_needsDocumentActivationCallbacks) {
         oldDocument.unregisterForDocumentSuspensionCallbacks(this);
-        document().registerForDocumentSuspensionCallbacks(this);
+        newDocument.registerForDocumentSuspensionCallbacks(this);
     }
 
     if (m_imageLoader)
         m_imageLoader->elementDidMoveToNewDocument();
 
-    HTMLPlugInElement::didMoveToNewDocument(oldDocument);
+    HTMLPlugInElement::didMoveToNewDocument(oldDocument, newDocument);
 }
 
 void HTMLPlugInImageElement::prepareForDocumentSuspension()

Modified: trunk/Source/WebCore/html/HTMLPlugInImageElement.h (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLPlugInImageElement.h	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLPlugInImageElement.h	2017-06-07 08:02:46 UTC (rev 217876)
@@ -83,7 +83,7 @@
 protected:
     HTMLPlugInImageElement(const QualifiedName& tagName, Document&, bool createdByParser);
 
-    void didMoveToNewDocument(Document& oldDocument) override;
+    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) override;
     bool requestObject(const String& url, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues) final;
 
     bool isImageType();

Modified: trunk/Source/WebCore/html/HTMLTemplateElement.cpp (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLTemplateElement.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLTemplateElement.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -82,12 +82,13 @@
     return clone.releaseNonNull();
 }
 
-void HTMLTemplateElement::didMoveToNewDocument(Document& oldDocument)
+void HTMLTemplateElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
-    HTMLElement::didMoveToNewDocument(oldDocument);
+    HTMLElement::didMoveToNewDocument(oldDocument, newDocument);
     if (!m_content)
         return;
-    document().ensureTemplateDocument().adoptIfNeeded(*m_content);
+    ASSERT_WITH_SECURITY_IMPLICATION(&document() == &newDocument);
+    newDocument.ensureTemplateDocument().adoptIfNeeded(*m_content);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/HTMLTemplateElement.h (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLTemplateElement.h	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLTemplateElement.h	2017-06-07 08:02:46 UTC (rev 217876)
@@ -48,7 +48,7 @@
     HTMLTemplateElement(const QualifiedName&, Document&);
 
     Ref<Node> cloneNodeInternal(Document&, CloningOperation) final;
-    void didMoveToNewDocument(Document& oldDocument) final;
+    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) final;
 
     mutable RefPtr<TemplateContentDocumentFragment> m_content;
 };

Modified: trunk/Source/WebCore/html/HTMLVideoElement.cpp (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLVideoElement.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLVideoElement.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -360,11 +360,11 @@
 }
 #endif
 
-void HTMLVideoElement::didMoveToNewDocument(Document& oldDocument)
+void HTMLVideoElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
     if (m_imageLoader)
         m_imageLoader->elementDidMoveToNewDocument();
-    HTMLMediaElement::didMoveToNewDocument(oldDocument);
+    HTMLMediaElement::didMoveToNewDocument(oldDocument, newDocument);
 }
 
 #if ENABLE(MEDIA_STATISTICS)

Modified: trunk/Source/WebCore/html/HTMLVideoElement.h (217875 => 217876)


--- trunk/Source/WebCore/html/HTMLVideoElement.h	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/HTMLVideoElement.h	2017-06-07 08:02:46 UTC (rev 217876)
@@ -107,7 +107,7 @@
 
     bool hasAvailableVideoFrame() const;
     void updateDisplayState() final;
-    void didMoveToNewDocument(Document& oldDocument) final;
+    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) final;
     void setDisplayMode(DisplayMode) final;
 
     PlatformMediaSession::MediaType presentationType() const final { return PlatformMediaSession::Video; }

Modified: trunk/Source/WebCore/html/ImageDocument.cpp (217875 => 217876)


--- trunk/Source/WebCore/html/ImageDocument.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/html/ImageDocument.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -102,7 +102,7 @@
     }
 
     virtual ~ImageDocumentElement();
-    void didMoveToNewDocument(Document& oldDocument) override;
+    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) override;
 
     ImageDocument* m_imageDocument;
 };
@@ -426,13 +426,13 @@
         m_imageDocument->disconnectImageElement();
 }
 
-void ImageDocumentElement::didMoveToNewDocument(Document& oldDocument)
+void ImageDocumentElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
     if (m_imageDocument) {
         m_imageDocument->disconnectImageElement();
         m_imageDocument = nullptr;
     }
-    HTMLImageElement::didMoveToNewDocument(oldDocument);
+    HTMLImageElement::didMoveToNewDocument(oldDocument, newDocument);
 }
 
 }

Modified: trunk/Source/WebCore/svg/SVGImageElement.cpp (217875 => 217876)


--- trunk/Source/WebCore/svg/SVGImageElement.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/svg/SVGImageElement.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -212,10 +212,10 @@
     addSubresourceURL(urls, document().completeURL(href()));
 }
 
-void SVGImageElement::didMoveToNewDocument(Document& oldDocument)
+void SVGImageElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
     m_imageLoader.elementDidMoveToNewDocument();
-    SVGGraphicsElement::didMoveToNewDocument(oldDocument);
+    SVGGraphicsElement::didMoveToNewDocument(oldDocument, newDocument);
 }
 
 }

Modified: trunk/Source/WebCore/svg/SVGImageElement.h (217875 => 217876)


--- trunk/Source/WebCore/svg/SVGImageElement.h	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/svg/SVGImageElement.h	2017-06-07 08:02:46 UTC (rev 217876)
@@ -58,7 +58,7 @@
     bool haveLoadedRequiredResources() final;
 
     bool selfHasRelativeLengths() const final { return true; }
-    void didMoveToNewDocument(Document& oldDocument) final;
+    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) final;
 
     BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGImageElement)
         DECLARE_ANIMATED_LENGTH(X, x)

Modified: trunk/Source/WebCore/svg/SVGSVGElement.cpp (217875 => 217876)


--- trunk/Source/WebCore/svg/SVGSVGElement.cpp	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/svg/SVGSVGElement.cpp	2017-06-07 08:02:46 UTC (rev 217876)
@@ -99,11 +99,11 @@
     document().accessSVGExtensions().removeTimeContainer(this);
 }
 
-void SVGSVGElement::didMoveToNewDocument(Document& oldDocument)
+void SVGSVGElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
     oldDocument.unregisterForDocumentSuspensionCallbacks(this);
     document().registerForDocumentSuspensionCallbacks(this);
-    SVGGraphicsElement::didMoveToNewDocument(oldDocument);
+    SVGGraphicsElement::didMoveToNewDocument(oldDocument, newDocument);
 }
 
 const AtomicString& SVGSVGElement::contentScriptType() const

Modified: trunk/Source/WebCore/svg/SVGSVGElement.h (217875 => 217876)


--- trunk/Source/WebCore/svg/SVGSVGElement.h	2017-06-07 06:49:51 UTC (rev 217875)
+++ trunk/Source/WebCore/svg/SVGSVGElement.h	2017-06-07 08:02:46 UTC (rev 217876)
@@ -139,7 +139,7 @@
     virtual ~SVGSVGElement();
 
     bool isValid() const override;
-    void didMoveToNewDocument(Document& oldDocument) override;
+    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) override;
     void parseAttribute(const QualifiedName&, const AtomicString&) override;
     bool rendererIsNeeded(const RenderStyle&) override;
     RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to