RESOLVED FIXED Bug 213333
Text manipulation should observe adjacent elements with new renderer together
https://bugs.webkit.org/show_bug.cgi?id=213333
Summary Text manipulation should observe adjacent elements with new renderer together
Sihui Liu
Reported 2020-06-17 23:52:55 PDT
...
Attachments
Patch (18.09 KB, patch)
2020-06-18 00:26 PDT, Sihui Liu
no flags
Patch (19.84 KB, patch)
2020-06-18 10:52 PDT, Sihui Liu
no flags
Patch (18.41 KB, patch)
2020-06-22 14:04 PDT, Sihui Liu
no flags
Patch for landing (18.50 KB, patch)
2020-06-26 09:18 PDT, Sihui Liu
no flags
Sihui Liu
Comment 1 2020-06-18 00:26:48 PDT
Wenson Hsieh
Comment 2 2020-06-18 09:03:58 PDT
Comment on attachment 402190 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=402190&action=review > Source/WebCore/dom/Node.h:675 > + bool m_isManipulated { false }; This overall approach seems reasonable to me, but we should avoid making Node larger (dump-class-layout on WebCore::Node with release shows 72 bytes with no padding). We should probably put it in NodeRareData instead.
Darin Adler
Comment 3 2020-06-18 10:35:22 PDT
Comment on attachment 402190 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=402190&action=review >> Source/WebCore/dom/Node.h:675 >> + bool m_isManipulated { false }; > > This overall approach seems reasonable to me, but we should avoid making Node larger (dump-class-layout on WebCore::Node with release shows 72 bytes with no padding). We should probably put it in NodeRareData instead. That’s right. We must not add this bool to Node.
Sihui Liu
Comment 4 2020-06-18 10:52:05 PDT
Sihui Liu
Comment 5 2020-06-18 10:55:29 PDT
Moved m_isManipulated to NodeRareData and reduced size of m_connectedFrameCount.
Ryosuke Niwa
Comment 6 2020-06-19 23:56:12 PDT
Comment on attachment 402216 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=402216&action=review > Source/WebCore/ChangeLog:15 > + To fix this issue completely, this patch adds a property isManipulated to NodeRareData. Now > + TextManipulationController can know the state of all types of Nodes and thus can skip the manipulated Nodes > + during observation. Hm... using a bit in NodeRareData isn't great because allocating NodeRareData would consume quite a bit of memory for each element. Why not just replace m_manipulatedElements with m_manipulatedNodes? Since we never de-reference objects in m_manipulatedElements, it's okay to store a stale pointer. We could also make it void* or some kind of a new smart pointer type that disallows dereferencing if we wanted.
Darin Adler
Comment 7 2020-06-21 12:36:05 PDT
(In reply to Ryosuke Niwa from comment #6) > Hm... using a bit in NodeRareData isn't great because > allocating NodeRareData would consume quite a bit of memory for each element. > Why not just replace m_manipulatedElements with m_manipulatedNodes? That sounds smart. > Since we never de-reference objects in m_manipulatedElements, it's okay to > store a stale pointer. I don’t think that’s right. As far as I know, there is *nothing* safe you can do with pointers to deleted objects, even if they are not dereferenced, except maybe comparing to null. For example, comparing a pointer to a deleted object with a pointer to another object could give an incorrect result. A stale pointer can happen to be equal to a pointer to a new object that is allocated re-using the same memory.
Ryosuke Niwa
Comment 8 2020-06-21 13:39:31 PDT
(In reply to Darin Adler from comment #7) > (In reply to Ryosuke Niwa from comment #6) > > Since we never de-reference objects in m_manipulatedElements, it's okay to > > store a stale pointer. > > I don’t think that’s right. > > As far as I know, there is *nothing* safe you can do with pointers to > deleted objects, even if they are not dereferenced, except maybe comparing > to null. For example, comparing a pointer to a deleted object with a pointer > to another object could give an incorrect result. A stale pointer can happen > to be equal to a pointer to a new object that is allocated re-using the same > memory. Sure, but that's still safe in this case. The worst thing that could happen is that we'd mistakenly think the content had already been manipulated and fail to notify the client. It's still safe in the sense of security guarantee although the program may still misbehave (by not reacting to newly inserted content) if we had such a bug.
Darin Adler
Comment 9 2020-06-21 13:42:46 PDT
(In reply to Ryosuke Niwa from comment #8) > It's still safe in the sense of security > guarantee although the program may still misbehave (by not reacting to newly > inserted content) if we had such a bug. OK, but could we use something like WeakPtr and have predictable behavior instead?
Sihui Liu
Comment 10 2020-06-22 14:04:18 PDT
Sihui Liu
Comment 11 2020-06-22 14:07:00 PDT
Uploaded a new patch using m_manipulatedNodes and removing node from set when node is destroyed.
Geoffrey Garen
Comment 12 2020-06-25 14:02:22 PDT
Comment on attachment 402511 [details] Patch r=me I slightly prefer the rare data solution, since I like it when you don't have to worry about doing interesting pointer safety things in your destructor. Also, you only pay the memory cost when you use the feature, which won't happen on most pages. That said, I think this approach works, and resolves all review comments so far. We can always discuss the rare data approach more when we have a chance, and reconsider it.
Ryosuke Niwa
Comment 13 2020-06-25 17:40:52 PDT
I think the long term solution is to add more bit flags directly on Node and/or make it possible to create a WeakPtr to Node. I have vague plans for both.
Sihui Liu
Comment 14 2020-06-26 09:18:12 PDT
Created attachment 402873 [details] Patch for landing
EWS
Comment 15 2020-06-26 09:41:19 PDT
Committed r263563: <https://trac.webkit.org/changeset/263563> All reviewed patches have been landed. Closing bug and clearing flags on attachment 402873 [details].
Radar WebKit Bug Importer
Comment 16 2020-06-26 09:42:19 PDT
Radar WebKit Bug Importer
Comment 17 2020-06-26 09:42:22 PDT
Note You need to log in before you can comment on or make changes to this bug.