Add some bindings-related bookkeeping to UndoManager and UndoItem
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Jan 2019 02:06:53 +0000 (02:06 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Jan 2019 02:06:53 +0000 (02:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193111
<rdar://problem/44807048>

Reviewed by Ryosuke Niwa.

This patch is work in progress towards supporting `UndoManager.addItem()`. Here, we add helper methods to
UndoItem and UndoManager which later patches will exercise, as well as introduce some custom bindings to
properly handle the case where UndoItems are given anonymous JavaScript functions (see below for more details).

No new tests, because there is no script-observable change in behavior yet. When `addItems()` is hooked up, I
will write a test to verify that the undo and redo JavaScript functions survive garbage collection.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSUndoItemCustom.cpp:
(WebCore::JSUndoItem::visitAdditionalChildren):

Have each JSUndoItem visit its undo and redo callback functions to ensure that the JavaScript wrapper objects
for these functions are not garbage collected underneath the item.

(WebCore::JSUndoItemOwner::isReachableFromOpaqueRoots):

Consider the undo item wrapper reachable from opaque roots if it is associated with its UndoManager's Document.
This ensures that if script isn't holding on to a reference to the wrapper (for instance, by calling
`UndoManager.addItem(new UndoItem({ ... }))`), we still protect the corresponding JSUndoItem as long as the
UndoManager's Document is alive. In the case where the undo item is not associated with a document, either (1)
script is keeping a reference to it, in which case it will be trivially reachable, or (2) script won't be able
to observe the destruction of the wrapper anyways (e.g. calling `new UndoItem({ ... })` by itself).

* dom/Document.cpp:
(WebCore::Document::prepareForDestruction):

Invalidate all undo items when the document is about to go away.

* page/UndoItem.cpp:
(WebCore::UndoItem::setUndoManager):
(WebCore::UndoItem::invalidate):
(WebCore::UndoItem::isValid const):

Add a few helpers, to be used in a future patch. We consider an UndoItem valid if it has been added to an
UndoManager, and is thus associated with a document.

(WebCore::UndoItem::document const):
* page/UndoItem.h:
* page/UndoItem.idl:
* page/UndoManager.cpp:
(WebCore::UndoManager::UndoManager):
(WebCore::UndoManager::addItem):

Have an UndoManager keep its UndoItems alive. These UndoItems remain in this set until either the document will
be destroyed, or the corresponding undo action is no longer needed because the platform undo stack has changed
(this latter behavior is yet to be implemented).

(WebCore::UndoManager::removeItem):
(WebCore::UndoManager::removeAllItems):
* page/UndoManager.h:
(WebCore::UndoManager::UndoManager): Deleted.
* page/scrolling/ScrollingTreeScrollingNode.cpp:

Unified build fix.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240315 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSUndoItemCustom.cpp [new file with mode: 0644]
Source/WebCore/dom/Document.cpp
Source/WebCore/page/UndoItem.cpp [new file with mode: 0644]
Source/WebCore/page/UndoItem.h
Source/WebCore/page/UndoItem.idl
Source/WebCore/page/UndoManager.cpp
Source/WebCore/page/UndoManager.h

index 757c0fa..9aaabb0 100644 (file)
@@ -1,3 +1,67 @@
+2019-01-22  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Add some bindings-related bookkeeping to UndoManager and UndoItem
+        https://bugs.webkit.org/show_bug.cgi?id=193111
+        <rdar://problem/44807048>
+
+        Reviewed by Ryosuke Niwa.
+
+        This patch is work in progress towards supporting `UndoManager.addItem()`. Here, we add helper methods to
+        UndoItem and UndoManager which later patches will exercise, as well as introduce some custom bindings to
+        properly handle the case where UndoItems are given anonymous JavaScript functions (see below for more details).
+
+        No new tests, because there is no script-observable change in behavior yet. When `addItems()` is hooked up, I
+        will write a test to verify that the undo and redo JavaScript functions survive garbage collection.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSUndoItemCustom.cpp:
+        (WebCore::JSUndoItem::visitAdditionalChildren):
+
+        Have each JSUndoItem visit its undo and redo callback functions to ensure that the JavaScript wrapper objects
+        for these functions are not garbage collected underneath the item.
+
+        (WebCore::JSUndoItemOwner::isReachableFromOpaqueRoots):
+
+        Consider the undo item wrapper reachable from opaque roots if it is associated with its UndoManager's Document.
+        This ensures that if script isn't holding on to a reference to the wrapper (for instance, by calling
+        `UndoManager.addItem(new UndoItem({ ... }))`), we still protect the corresponding JSUndoItem as long as the
+        UndoManager's Document is alive. In the case where the undo item is not associated with a document, either (1)
+        script is keeping a reference to it, in which case it will be trivially reachable, or (2) script won't be able
+        to observe the destruction of the wrapper anyways (e.g. calling `new UndoItem({ ... })` by itself).
+
+        * dom/Document.cpp:
+        (WebCore::Document::prepareForDestruction):
+
+        Invalidate all undo items when the document is about to go away.
+
+        * page/UndoItem.cpp:
+        (WebCore::UndoItem::setUndoManager):
+        (WebCore::UndoItem::invalidate):
+        (WebCore::UndoItem::isValid const):
+
+        Add a few helpers, to be used in a future patch. We consider an UndoItem valid if it has been added to an
+        UndoManager, and is thus associated with a document.
+
+        (WebCore::UndoItem::document const):
+        * page/UndoItem.h:
+        * page/UndoItem.idl:
+        * page/UndoManager.cpp:
+        (WebCore::UndoManager::UndoManager):
+        (WebCore::UndoManager::addItem):
+
+        Have an UndoManager keep its UndoItems alive. These UndoItems remain in this set until either the document will
+        be destroyed, or the corresponding undo action is no longer needed because the platform undo stack has changed
+        (this latter behavior is yet to be implemented).
+
+        (WebCore::UndoManager::removeItem):
+        (WebCore::UndoManager::removeAllItems):
+        * page/UndoManager.h:
+        (WebCore::UndoManager::UndoManager): Deleted.
+        * page/scrolling/ScrollingTreeScrollingNode.cpp:
+
+        Unified build fix.
+
 2019-01-22  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         [WinCairo][WebKitTestRunner] Null dereference of GraphicsContext::m_data in GraphicsContext::releaseWindowsContext
index 274b088..7c48444 100644 (file)
@@ -526,6 +526,7 @@ bindings/js/JSTextTrackListCustom.cpp
 bindings/js/JSTrackCustom.cpp
 bindings/js/JSTreeWalkerCustom.cpp
 bindings/js/JSTypedOMCSSStyleValueCustom.cpp
+bindings/js/JSUndoItemCustom.cpp
 bindings/js/JSVideoTrackCustom.cpp
 bindings/js/JSVideoTrackListCustom.cpp
 bindings/js/JSWebAnimationCustom.cpp
@@ -1536,6 +1537,7 @@ page/SocketProvider.cpp
 page/SpatialNavigation.cpp
 page/SuspendableTimer.cpp
 page/TextIndicator.cpp
+page/UndoItem.cpp
 page/UndoManager.cpp
 page/UserContentProvider.cpp
 page/UserContentController.cpp
index 2c46b3d..d1851eb 100644 (file)
                319BDE531E7A86C100BA296C /* JSRTCIceTransportState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSRTCIceTransportState.h; sourceTree = "<group>"; };
                319BDE531E7A86C100BA296D /* JSRTCPeerConnectionState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSRTCPeerConnectionState.h; sourceTree = "<group>"; };
                319FBD5D15D2F444009640A6 /* CachedImageClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedImageClient.h; sourceTree = "<group>"; };
-               31A088C41E737B2C003B6609 /* JSWebGPURenderingContextCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebGPURenderingContextCustom.cpp; sourceTree = "<group>"; };
-               31A088C51E737B2C003B6609 /* JSWebGPURenderPassAttachmentDescriptorCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebGPURenderPassAttachmentDescriptorCustom.cpp; sourceTree = "<group>"; };
                31A0891B1E738D59003B6609 /* JSWebGPUBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebGPUBuffer.cpp; sourceTree = "<group>"; };
                31A0891D1E738D59003B6609 /* JSWebGPUBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebGPUBuffer.h; sourceTree = "<group>"; };
                31A0891E1E738D59003B6609 /* JSWebGPUCommandBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebGPUCommandBuffer.cpp; sourceTree = "<group>"; };
                F4D43D64218802E600ECECAC /* SerializedAttachmentData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SerializedAttachmentData.h; sourceTree = "<group>"; };
                F4D9817D2195FBF6008230FC /* ChangeListTypeCommand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ChangeListTypeCommand.h; sourceTree = "<group>"; };
                F4D9817E2195FBF6008230FC /* ChangeListTypeCommand.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ChangeListTypeCommand.cpp; sourceTree = "<group>"; };
+               F4E1965A21F2395000285078 /* JSUndoItemCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSUndoItemCustom.cpp; sourceTree = "<group>"; };
+               F4E1965F21F26E4E00285078 /* UndoItem.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = UndoItem.cpp; sourceTree = "<group>"; };
                F4E57EDA213F3F5F004EA98E /* FontAttributeChanges.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontAttributeChanges.h; sourceTree = "<group>"; };
                F4E57EDF213F434A004EA98E /* WebCoreNSFontManagerExtras.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebCoreNSFontManagerExtras.h; sourceTree = "<group>"; };
                F4E57EE0213F434A004EA98E /* WebCoreNSFontManagerExtras.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreNSFontManagerExtras.mm; sourceTree = "<group>"; };
                                1CECB3B621F50AC700F44542 /* WHLSLMetalCodeGenerator.h */,
                                1CECB3B821F50D1000F44542 /* WHLSLNativeFunctionWriter.cpp */,
                                1CECB3B921F50D1000F44542 /* WHLSLNativeFunctionWriter.h */,
-                               1CECB3B121F2B98500F44542 /* WHLSLTypeNamer.cpp */,
-                               1CECB3B021F2B98500F44542 /* WHLSLTypeNamer.h */,
                                1CECB3C621F59C8700F44542 /* WHLSLNativeTypeWriter.cpp */,
                                1CECB3C721F59C8700F44542 /* WHLSLNativeTypeWriter.h */,
+                               1CECB3B121F2B98500F44542 /* WHLSLTypeNamer.cpp */,
+                               1CECB3B021F2B98500F44542 /* WHLSLTypeNamer.h */,
                        );
                        path = Metal;
                        sourceTree = "<group>";
                                62C1217B11AB9E77003C462C /* SuspendableTimer.h */,
                                2D4F96F11A1ECC240098BF88 /* TextIndicator.cpp */,
                                2D4F96F21A1ECC240098BF88 /* TextIndicator.h */,
+                               F4E1965F21F26E4E00285078 /* UndoItem.cpp */,
                                2ECDBAD521D8906300F00ECD /* UndoItem.h */,
                                2ECDBAD721D8906300F00ECD /* UndoItem.idl */,
                                2ECDBACF21D8903400F00ECD /* UndoManager.cpp */,
                                07846384145B1B8E00A58DF1 /* JSTrackCustom.h */,
                                516BB7920CE91E6800512F79 /* JSTreeWalkerCustom.cpp */,
                                4BAFD0E22192604D00C0AB64 /* JSTypedOMCSSStyleValueCustom.cpp */,
+                               F4E1965A21F2395000285078 /* JSUndoItemCustom.cpp */,
                                BE6DF708171CA2C500DD52B8 /* JSVideoTrackCustom.cpp */,
                                BE6DF70A171CA2C500DD52B8 /* JSVideoTrackListCustom.cpp */,
                                715DA5D3201BB902002EF2B0 /* JSWebAnimationCustom.cpp */,
                                D3F3D3591A69A3B00059FC2B /* JSWebGL2RenderingContextCustom.cpp */,
                                49EED14C1051971A00099FAB /* JSWebGLRenderingContextCustom.cpp */,
-                               31A088C41E737B2C003B6609 /* JSWebGPURenderingContextCustom.cpp */,
-                               31A088C51E737B2C003B6609 /* JSWebGPURenderPassAttachmentDescriptorCustom.cpp */,
                                E18258AB0EF3CD7000933242 /* JSWorkerGlobalScopeCustom.cpp */,
                                46F91BC91FCDD0FE001599C3 /* JSWorkerNavigatorCustom.cpp */,
                                83A4A9F81CE7FD7E00709B00 /* JSXMLDocumentCustom.cpp */,
diff --git a/Source/WebCore/bindings/js/JSUndoItemCustom.cpp b/Source/WebCore/bindings/js/JSUndoItemCustom.cpp
new file mode 100644 (file)
index 0000000..cfaa028
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSUndoItem.h"
+
+namespace WebCore {
+
+void JSUndoItem::visitAdditionalChildren(JSC::SlotVisitor& visitor)
+{
+    wrapped().undoHandler().visitJSFunction(visitor);
+    wrapped().redoHandler().visitJSFunction(visitor);
+}
+
+bool JSUndoItemOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
+{
+    if (UNLIKELY(reason))
+        *reason = "Document is an opaque root.";
+
+    auto* documentForUndoItem = jsCast<JSUndoItem*>(handle.slot()->asCell())->wrapped().document();
+    return documentForUndoItem && visitor.containsOpaqueRoot(documentForUndoItem);
+}
+
+} // namespace WebCore
index c067174..5db71f5 100644 (file)
@@ -2501,6 +2501,8 @@ void Document::prepareForDestruction()
     clearTouchEventHandlersAndListeners();
 #endif
 
+    m_undoManager->removeAllItems();
+
 #if HAVE(ACCESSIBILITY)
     if (this != &topDocument()) {
         // Let the ax cache know that this subframe goes out of scope.
diff --git a/Source/WebCore/page/UndoItem.cpp b/Source/WebCore/page/UndoItem.cpp
new file mode 100644 (file)
index 0000000..2b32137
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "UndoItem.h"
+
+#include "UndoManager.h"
+#include <wtf/IsoMallocInlines.h>
+
+namespace WebCore {
+
+WTF_MAKE_ISO_ALLOCATED_IMPL(UndoItem);
+
+void UndoItem::setUndoManager(UndoManager* undoManager)
+{
+    m_undoManager = makeWeakPtr(undoManager);
+}
+
+void UndoItem::invalidate()
+{
+    if (auto* undoManager = m_undoManager.get()) {
+        undoManager->removeItem(*this);
+        m_undoManager = nullptr;
+    }
+}
+
+bool UndoItem::isValid() const
+{
+    return !!m_undoManager;
+}
+
+Document* UndoItem::document() const
+{
+    if (!isValid())
+        return nullptr;
+
+    return &m_undoManager->document();
+}
+
+} // namespace WebCore
index 019bb9a..29c102d 100644 (file)
 #pragma once
 
 #include "VoidCallback.h"
-#include <wtf/Function.h>
-#include <wtf/IsoMallocInlines.h>
+#include <wtf/IsoMalloc.h>
 #include <wtf/RefCounted.h>
+#include <wtf/WeakPtr.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
+class Document;
+class UndoManager;
+
 class UndoItem : public RefCounted<UndoItem> {
-    WTF_MAKE_ISO_ALLOCATED_INLINE(UndoItem);
+    WTF_MAKE_ISO_ALLOCATED(UndoItem);
 public:
     struct Init {
         String label;
@@ -47,6 +50,13 @@ public:
         return adoptRef(*new UndoItem(WTFMove(init)));
     }
 
+    bool isValid() const;
+    void invalidate();
+
+    Document* document() const;
+
+    void setUndoManager(UndoManager*);
+
     const String& label() const { return m_label; }
     VoidCallback& undoHandler() const { return m_undoHandler.get(); }
     VoidCallback& redoHandler() const { return m_redoHandler.get(); }
@@ -62,6 +72,7 @@ private:
     String m_label;
     Ref<VoidCallback> m_undoHandler;
     Ref<VoidCallback> m_redoHandler;
+    WeakPtr<UndoManager> m_undoManager;
 };
 
 } // namespace WebCore
index 09b97c8..190f9bb 100644 (file)
@@ -34,6 +34,8 @@
 [
     EnabledAtRuntime=UndoManagerAPI,
     ImplementationLacksVTable,
+    JSCustomMarkFunction,
+    CustomIsReachable,
     Constructor(UndoItemInit initDict),
 ] interface UndoItem {
     readonly attribute DOMString label;
index 221bf28..c168aca 100644 (file)
@@ -33,10 +33,32 @@ namespace WebCore {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(UndoManager);
 
+UndoManager::UndoManager(Document& document)
+    : m_document(document)
+{
+}
+
+UndoManager::~UndoManager() = default;
+
 void UndoManager::addItem(Ref<UndoItem>&& item)
 {
-    UNUSED_PARAM(item);
     UNUSED_PARAM(m_document);
+
+    item->setUndoManager(this);
+    m_items.add(WTFMove(item));
+}
+
+void UndoManager::removeItem(UndoItem& item)
+{
+    if (auto foundItem = m_items.take(&item))
+        foundItem->setUndoManager(nullptr);
+}
+
+void UndoManager::removeAllItems()
+{
+    for (auto& item : m_items)
+        item->setUndoManager(nullptr);
+    m_items.clear();
 }
 
 } // namespace WebCore
index 49604f0..78fa720 100644 (file)
 #include <wtf/IsoMalloc.h>
 #include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+#include <wtf/WeakPtr.h>
 
 namespace WebCore {
 
 class Document;
 class UndoItem;
 
-class UndoManager : public RefCounted<UndoManager> {
+class UndoManager : public RefCounted<UndoManager>, public CanMakeWeakPtr<UndoManager> {
     WTF_MAKE_ISO_ALLOCATED(UndoManager);
 public:
     static Ref<UndoManager> create(Document& document)
@@ -42,16 +44,18 @@ public:
         return adoptRef(*new UndoManager(document));
     }
 
+    ~UndoManager();
+
+    void removeItem(UndoItem&);
+    void removeAllItems();
     void addItem(Ref<UndoItem>&&);
     Document& document() { return m_document; }
 
 private:
-    UndoManager(Document& document)
-        : m_document(document)
-    {
-    }
+    UndoManager(Document&);
 
     Document& m_document;
+    HashSet<RefPtr<UndoItem>> m_items;
 };
 
 } // namespace WebCore