Changeset 240315 in webkit
- Timestamp:
- Jan 22, 2019 6:06:53 PM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 8 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r240313 r240315 1 2019-01-22 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Add some bindings-related bookkeeping to UndoManager and UndoItem 4 https://bugs.webkit.org/show_bug.cgi?id=193111 5 <rdar://problem/44807048> 6 7 Reviewed by Ryosuke Niwa. 8 9 This patch is work in progress towards supporting `UndoManager.addItem()`. Here, we add helper methods to 10 UndoItem and UndoManager which later patches will exercise, as well as introduce some custom bindings to 11 properly handle the case where UndoItems are given anonymous JavaScript functions (see below for more details). 12 13 No new tests, because there is no script-observable change in behavior yet. When `addItems()` is hooked up, I 14 will write a test to verify that the undo and redo JavaScript functions survive garbage collection. 15 16 * Sources.txt: 17 * WebCore.xcodeproj/project.pbxproj: 18 * bindings/js/JSUndoItemCustom.cpp: 19 (WebCore::JSUndoItem::visitAdditionalChildren): 20 21 Have each JSUndoItem visit its undo and redo callback functions to ensure that the JavaScript wrapper objects 22 for these functions are not garbage collected underneath the item. 23 24 (WebCore::JSUndoItemOwner::isReachableFromOpaqueRoots): 25 26 Consider the undo item wrapper reachable from opaque roots if it is associated with its UndoManager's Document. 27 This ensures that if script isn't holding on to a reference to the wrapper (for instance, by calling 28 `UndoManager.addItem(new UndoItem({ ... }))`), we still protect the corresponding JSUndoItem as long as the 29 UndoManager's Document is alive. In the case where the undo item is not associated with a document, either (1) 30 script is keeping a reference to it, in which case it will be trivially reachable, or (2) script won't be able 31 to observe the destruction of the wrapper anyways (e.g. calling `new UndoItem({ ... })` by itself). 32 33 * dom/Document.cpp: 34 (WebCore::Document::prepareForDestruction): 35 36 Invalidate all undo items when the document is about to go away. 37 38 * page/UndoItem.cpp: 39 (WebCore::UndoItem::setUndoManager): 40 (WebCore::UndoItem::invalidate): 41 (WebCore::UndoItem::isValid const): 42 43 Add a few helpers, to be used in a future patch. We consider an UndoItem valid if it has been added to an 44 UndoManager, and is thus associated with a document. 45 46 (WebCore::UndoItem::document const): 47 * page/UndoItem.h: 48 * page/UndoItem.idl: 49 * page/UndoManager.cpp: 50 (WebCore::UndoManager::UndoManager): 51 (WebCore::UndoManager::addItem): 52 53 Have an UndoManager keep its UndoItems alive. These UndoItems remain in this set until either the document will 54 be destroyed, or the corresponding undo action is no longer needed because the platform undo stack has changed 55 (this latter behavior is yet to be implemented). 56 57 (WebCore::UndoManager::removeItem): 58 (WebCore::UndoManager::removeAllItems): 59 * page/UndoManager.h: 60 (WebCore::UndoManager::UndoManager): Deleted. 61 * page/scrolling/ScrollingTreeScrollingNode.cpp: 62 63 Unified build fix. 64 1 65 2019-01-22 Fujii Hironori <Hironori.Fujii@sony.com> 2 66 -
trunk/Source/WebCore/Sources.txt
r240230 r240315 527 527 bindings/js/JSTreeWalkerCustom.cpp 528 528 bindings/js/JSTypedOMCSSStyleValueCustom.cpp 529 bindings/js/JSUndoItemCustom.cpp 529 530 bindings/js/JSVideoTrackCustom.cpp 530 531 bindings/js/JSVideoTrackListCustom.cpp … … 1537 1538 page/SuspendableTimer.cpp 1538 1539 page/TextIndicator.cpp 1540 page/UndoItem.cpp 1539 1541 page/UndoManager.cpp 1540 1542 page/UserContentProvider.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r240272 r240315 7099 7099 319BDE531E7A86C100BA296D /* JSRTCPeerConnectionState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSRTCPeerConnectionState.h; sourceTree = "<group>"; }; 7100 7100 319FBD5D15D2F444009640A6 /* CachedImageClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedImageClient.h; sourceTree = "<group>"; }; 7101 31A088C41E737B2C003B6609 /* JSWebGPURenderingContextCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebGPURenderingContextCustom.cpp; sourceTree = "<group>"; };7102 31A088C51E737B2C003B6609 /* JSWebGPURenderPassAttachmentDescriptorCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebGPURenderPassAttachmentDescriptorCustom.cpp; sourceTree = "<group>"; };7103 7101 31A0891B1E738D59003B6609 /* JSWebGPUBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebGPUBuffer.cpp; sourceTree = "<group>"; }; 7104 7102 31A0891D1E738D59003B6609 /* JSWebGPUBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebGPUBuffer.h; sourceTree = "<group>"; }; … … 15132 15130 F4D9817D2195FBF6008230FC /* ChangeListTypeCommand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ChangeListTypeCommand.h; sourceTree = "<group>"; }; 15133 15131 F4D9817E2195FBF6008230FC /* ChangeListTypeCommand.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ChangeListTypeCommand.cpp; sourceTree = "<group>"; }; 15132 F4E1965A21F2395000285078 /* JSUndoItemCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSUndoItemCustom.cpp; sourceTree = "<group>"; }; 15133 F4E1965F21F26E4E00285078 /* UndoItem.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = UndoItem.cpp; sourceTree = "<group>"; }; 15134 15134 F4E57EDA213F3F5F004EA98E /* FontAttributeChanges.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontAttributeChanges.h; sourceTree = "<group>"; }; 15135 15135 F4E57EDF213F434A004EA98E /* WebCoreNSFontManagerExtras.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebCoreNSFontManagerExtras.h; sourceTree = "<group>"; }; … … 17170 17170 1CECB3B821F50D1000F44542 /* WHLSLNativeFunctionWriter.cpp */, 17171 17171 1CECB3B921F50D1000F44542 /* WHLSLNativeFunctionWriter.h */, 17172 1CECB3C621F59C8700F44542 /* WHLSLNativeTypeWriter.cpp */, 17173 1CECB3C721F59C8700F44542 /* WHLSLNativeTypeWriter.h */, 17172 17174 1CECB3B121F2B98500F44542 /* WHLSLTypeNamer.cpp */, 17173 17175 1CECB3B021F2B98500F44542 /* WHLSLTypeNamer.h */, 17174 1CECB3C621F59C8700F44542 /* WHLSLNativeTypeWriter.cpp */,17175 1CECB3C721F59C8700F44542 /* WHLSLNativeTypeWriter.h */,17176 17176 ); 17177 17177 path = Metal; … … 20435 20435 2D4F96F11A1ECC240098BF88 /* TextIndicator.cpp */, 20436 20436 2D4F96F21A1ECC240098BF88 /* TextIndicator.h */, 20437 F4E1965F21F26E4E00285078 /* UndoItem.cpp */, 20437 20438 2ECDBAD521D8906300F00ECD /* UndoItem.h */, 20438 20439 2ECDBAD721D8906300F00ECD /* UndoItem.idl */, … … 20803 20804 516BB7920CE91E6800512F79 /* JSTreeWalkerCustom.cpp */, 20804 20805 4BAFD0E22192604D00C0AB64 /* JSTypedOMCSSStyleValueCustom.cpp */, 20806 F4E1965A21F2395000285078 /* JSUndoItemCustom.cpp */, 20805 20807 BE6DF708171CA2C500DD52B8 /* JSVideoTrackCustom.cpp */, 20806 20808 BE6DF70A171CA2C500DD52B8 /* JSVideoTrackListCustom.cpp */, … … 20808 20810 D3F3D3591A69A3B00059FC2B /* JSWebGL2RenderingContextCustom.cpp */, 20809 20811 49EED14C1051971A00099FAB /* JSWebGLRenderingContextCustom.cpp */, 20810 31A088C41E737B2C003B6609 /* JSWebGPURenderingContextCustom.cpp */,20811 31A088C51E737B2C003B6609 /* JSWebGPURenderPassAttachmentDescriptorCustom.cpp */,20812 20812 E18258AB0EF3CD7000933242 /* JSWorkerGlobalScopeCustom.cpp */, 20813 20813 46F91BC91FCDD0FE001599C3 /* JSWorkerNavigatorCustom.cpp */, -
trunk/Source/WebCore/bindings/js/JSUndoItemCustom.cpp
r240314 r240315 25 25 26 26 #include "config.h" 27 #include "UndoManager.h" 28 29 #include "UndoItem.h" 30 #include <wtf/IsoMallocInlines.h> 27 #include "JSUndoItem.h" 31 28 32 29 namespace WebCore { 33 30 34 WTF_MAKE_ISO_ALLOCATED_IMPL(UndoManager); 31 void JSUndoItem::visitAdditionalChildren(JSC::SlotVisitor& visitor) 32 { 33 wrapped().undoHandler().visitJSFunction(visitor); 34 wrapped().redoHandler().visitJSFunction(visitor); 35 } 35 36 36 void UndoManager::addItem(Ref<UndoItem>&& item)37 bool JSUndoItemOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) 37 38 { 38 UNUSED_PARAM(item); 39 UNUSED_PARAM(m_document); 39 if (UNLIKELY(reason)) 40 *reason = "Document is an opaque root."; 41 42 auto* documentForUndoItem = jsCast<JSUndoItem*>(handle.slot()->asCell())->wrapped().document(); 43 return documentForUndoItem && visitor.containsOpaqueRoot(documentForUndoItem); 40 44 } 41 45 -
trunk/Source/WebCore/dom/Document.cpp
r240237 r240315 2502 2502 #endif 2503 2503 2504 m_undoManager->removeAllItems(); 2505 2504 2506 #if HAVE(ACCESSIBILITY) 2505 2507 if (this != &topDocument()) { -
trunk/Source/WebCore/page/UndoItem.cpp
r240314 r240315 25 25 26 26 #include "config.h" 27 #include "UndoItem.h" 28 27 29 #include "UndoManager.h" 28 29 #include "UndoItem.h"30 30 #include <wtf/IsoMallocInlines.h> 31 31 32 32 namespace WebCore { 33 33 34 WTF_MAKE_ISO_ALLOCATED_IMPL(Undo Manager);34 WTF_MAKE_ISO_ALLOCATED_IMPL(UndoItem); 35 35 36 void Undo Manager::addItem(Ref<UndoItem>&& item)36 void UndoItem::setUndoManager(UndoManager* undoManager) 37 37 { 38 UNUSED_PARAM(item); 39 UNUSED_PARAM(m_document); 38 m_undoManager = makeWeakPtr(undoManager); 39 } 40 41 void UndoItem::invalidate() 42 { 43 if (auto* undoManager = m_undoManager.get()) { 44 undoManager->removeItem(*this); 45 m_undoManager = nullptr; 46 } 47 } 48 49 bool UndoItem::isValid() const 50 { 51 return !!m_undoManager; 52 } 53 54 Document* UndoItem::document() const 55 { 56 if (!isValid()) 57 return nullptr; 58 59 return &m_undoManager->document(); 40 60 } 41 61 -
trunk/Source/WebCore/page/UndoItem.h
r239864 r240315 27 27 28 28 #include "VoidCallback.h" 29 #include <wtf/Function.h> 30 #include <wtf/IsoMallocInlines.h> 29 #include <wtf/IsoMalloc.h> 31 30 #include <wtf/RefCounted.h> 31 #include <wtf/WeakPtr.h> 32 32 #include <wtf/text/WTFString.h> 33 33 34 34 namespace WebCore { 35 35 36 class Document; 37 class UndoManager; 38 36 39 class UndoItem : public RefCounted<UndoItem> { 37 WTF_MAKE_ISO_ALLOCATED _INLINE(UndoItem);40 WTF_MAKE_ISO_ALLOCATED(UndoItem); 38 41 public: 39 42 struct Init { … … 47 50 return adoptRef(*new UndoItem(WTFMove(init))); 48 51 } 52 53 bool isValid() const; 54 void invalidate(); 55 56 Document* document() const; 57 58 void setUndoManager(UndoManager*); 49 59 50 60 const String& label() const { return m_label; } … … 63 73 Ref<VoidCallback> m_undoHandler; 64 74 Ref<VoidCallback> m_redoHandler; 75 WeakPtr<UndoManager> m_undoManager; 65 76 }; 66 77 -
trunk/Source/WebCore/page/UndoItem.idl
r239864 r240315 35 35 EnabledAtRuntime=UndoManagerAPI, 36 36 ImplementationLacksVTable, 37 JSCustomMarkFunction, 38 CustomIsReachable, 37 39 Constructor(UndoItemInit initDict), 38 40 ] interface UndoItem { -
trunk/Source/WebCore/page/UndoManager.cpp
r239864 r240315 34 34 WTF_MAKE_ISO_ALLOCATED_IMPL(UndoManager); 35 35 36 UndoManager::UndoManager(Document& document) 37 : m_document(document) 38 { 39 } 40 41 UndoManager::~UndoManager() = default; 42 36 43 void UndoManager::addItem(Ref<UndoItem>&& item) 37 44 { 38 UNUSED_PARAM(item);39 45 UNUSED_PARAM(m_document); 46 47 item->setUndoManager(this); 48 m_items.add(WTFMove(item)); 49 } 50 51 void UndoManager::removeItem(UndoItem& item) 52 { 53 if (auto foundItem = m_items.take(&item)) 54 foundItem->setUndoManager(nullptr); 55 } 56 57 void UndoManager::removeAllItems() 58 { 59 for (auto& item : m_items) 60 item->setUndoManager(nullptr); 61 m_items.clear(); 40 62 } 41 63 -
trunk/Source/WebCore/page/UndoManager.h
r239864 r240315 29 29 #include <wtf/Ref.h> 30 30 #include <wtf/RefCounted.h> 31 #include <wtf/RefPtr.h> 32 #include <wtf/WeakPtr.h> 31 33 32 34 namespace WebCore { … … 35 37 class UndoItem; 36 38 37 class UndoManager : public RefCounted<UndoManager> {39 class UndoManager : public RefCounted<UndoManager>, public CanMakeWeakPtr<UndoManager> { 38 40 WTF_MAKE_ISO_ALLOCATED(UndoManager); 39 41 public: … … 43 45 } 44 46 47 ~UndoManager(); 48 49 void removeItem(UndoItem&); 50 void removeAllItems(); 45 51 void addItem(Ref<UndoItem>&&); 46 52 Document& document() { return m_document; } 47 53 48 54 private: 49 UndoManager(Document& document) 50 : m_document(document) 51 { 52 } 55 UndoManager(Document&); 53 56 54 57 Document& m_document; 58 HashSet<RefPtr<UndoItem>> m_items; 55 59 }; 56 60
Note: See TracChangeset
for help on using the changeset viewer.