Bug 232788 - [Live Text] Add a helper method to remove recognized text from an image element
Summary: [Live Text] Add a helper method to remove recognized text from an image element
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Wenson Hsieh
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-11-06 12:22 PDT by Wenson Hsieh
Modified: 2021-11-08 12:56 PST (History)
10 users (show)

See Also:


Attachments
Patch (4.26 KB, patch)
2021-11-06 12:24 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Wenson Hsieh 2021-11-06 12:22:17 PDT
.
Comment 1 Wenson Hsieh 2021-11-06 12:24:39 PDT
Created attachment 443490 [details]
Patch
Comment 2 Aditya Keerthi 2021-11-08 10:34:24 PST
Comment on attachment 443490 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=443490&action=review

> Source/WebCore/html/HTMLElement.cpp:1341
> +        RefPtr<HTMLDivElement> containerToRemove;

Is this variable necessary? Why not just remove the container in the loop?
Comment 3 Wenson Hsieh 2021-11-08 10:38:19 PST
Comment on attachment 443490 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=443490&action=review

Thanks for the review!

>> Source/WebCore/html/HTMLElement.cpp:1341
>> +        RefPtr<HTMLDivElement> containerToRemove;
> 
> Is this variable necessary? Why not just remove the container in the loop?

I'll need to double check, but IIRC mutating the DOM underneath the scope of a DOM iterator will fire debug assertions (though in this scenario, it is technically safe since we break immediately afterwards).
Comment 4 Wenson Hsieh 2021-11-08 11:49:29 PST
(In reply to Wenson Hsieh from comment #3)
> Comment on attachment 443490 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=443490&action=review
> 
> Thanks for the review!
> 
> >> Source/WebCore/html/HTMLElement.cpp:1341
> >> +        RefPtr<HTMLDivElement> containerToRemove;
> > 
> > Is this variable necessary? Why not just remove the container in the loop?
> 
> I'll need to double check, but IIRC mutating the DOM underneath the scope of
> a DOM iterator will fire debug assertions (though in this scenario, it is
> technically safe since we break immediately afterwards).

Yeah, directly removing the node underneath the iterator results in:

```
ASSERTION FAILED: ScriptDisallowedScope::InMainThread::isEventDispatchAllowedInSubtree(childToRemove)
dom/ContainerNode.cpp(146) : bool WebCore::ContainerNode::removeNodeWithScriptAssertion(WebCore::Node &, ChildChange::Source)
1   0x37c1f4199 WTFCrash
2   0x37c1f41b9 WTFCrashWithSecurityImplication
3   0x3920467c1 WebCore::ContainerNode::removeNodeWithScriptAssertion(WebCore::Node&, WebCore::ContainerNode::ChildChange::Source)
4   0x392042e22 WebCore::ContainerNode::removeChild(WebCore::Node&)
5   0x392221136 WebCore::Node::remove()
6   0x3925543cf WebCore::HTMLElement::removeImageOverlaySoonIfNeeded()::$_4::operator()() const
```

(I'll keep the code as-is, at least for now)
Comment 5 Aditya Keerthi 2021-11-08 12:08:48 PST
(In reply to Wenson Hsieh from comment #4)
> (In reply to Wenson Hsieh from comment #3)
> > Comment on attachment 443490 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=443490&action=review
> > 
> > Thanks for the review!
> > 
> > >> Source/WebCore/html/HTMLElement.cpp:1341
> > >> +        RefPtr<HTMLDivElement> containerToRemove;
> > > 
> > > Is this variable necessary? Why not just remove the container in the loop?
> > 
> > I'll need to double check, but IIRC mutating the DOM underneath the scope of
> > a DOM iterator will fire debug assertions (though in this scenario, it is
> > technically safe since we break immediately afterwards).
> 
> Yeah, directly removing the node underneath the iterator results in:
> 
> ```
> ASSERTION FAILED:
> ScriptDisallowedScope::InMainThread::
> isEventDispatchAllowedInSubtree(childToRemove)
> dom/ContainerNode.cpp(146) : bool
> WebCore::ContainerNode::removeNodeWithScriptAssertion(WebCore::Node &,
> ChildChange::Source)
> 1   0x37c1f4199 WTFCrash
> 2   0x37c1f41b9 WTFCrashWithSecurityImplication
> 3   0x3920467c1
> WebCore::ContainerNode::removeNodeWithScriptAssertion(WebCore::Node&,
> WebCore::ContainerNode::ChildChange::Source)
> 4   0x392042e22 WebCore::ContainerNode::removeChild(WebCore::Node&)
> 5   0x392221136 WebCore::Node::remove()
> 6   0x3925543cf
> WebCore::HTMLElement::removeImageOverlaySoonIfNeeded()::$_4::operator()()
> const
> ```
> 
> (I'll keep the code as-is, at least for now)

👍
Comment 6 EWS 2021-11-08 12:55:34 PST
Committed r285425 (243981@main): <https://commits.webkit.org/243981@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 443490 [details].
Comment 7 Radar WebKit Bug Importer 2021-11-08 12:56:20 PST
<rdar://problem/85169058>