Bug 196324 - Web Inspector: Canvas: unbinding a canvas should always remove the agent as an observer
Summary: Web Inspector: Canvas: unbinding a canvas should always remove the agent as a...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Devin Rousso
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-03-27 15:42 PDT by Devin Rousso
Modified: 2019-03-28 11:08 PDT (History)
10 users (show)

See Also:


Attachments
Patch (3.80 KB, patch)
2019-03-27 15:51 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Devin Rousso 2019-03-27 15:42:58 PDT
`InspectorCanvasAgent::unbindCanvas` is currently called in two places:
 - `InspectorCanvasAgent::frameNavigated`, right after the `InspectorCanvasAgent` removes itself as an observer from the canvas in question
 - `InspectorCanvasAgent::canvasDestroyed`, which is called on all observers when the canvas is about to be destructed
Previously, in order to avoid modification-while-iterating, we wouldn't remove the `InspectorCanvasAgent` from the canvas inside `InspectorCanvasAgent::canvasDestroyed`, since the canvas is about to be destructed anyways.  This isn't a very good practice, and should be "corrected" (e.g. the observer shouldn't have any idea about the specifics of how the canvas treats/notifies its observers).
Comment 1 Radar WebKit Bug Importer 2019-03-27 15:47:57 PDT
<rdar://problem/49357109>
Comment 2 Devin Rousso 2019-03-27 15:51:48 PDT
Created attachment 366119 [details]
Patch
Comment 3 Matt Baker 2019-03-27 18:10:24 PDT
Comment on attachment 366119 [details]
Patch

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

r=me

> Source/WebCore/html/CanvasBase.cpp:74
>          observer->canvasChanged(*this, rect);

I noticed this is a widely used pattern in WebKit. Is it to safeguard against m_observers mutating during iteration?
Comment 4 Devin Rousso 2019-03-28 10:38:41 PDT
Comment on attachment 366119 [details]
Patch

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

>> Source/WebCore/html/CanvasBase.cpp:74
>>          observer->canvasChanged(*this, rect);
> 
> I noticed this is a widely used pattern in WebKit. Is it to safeguard against m_observers mutating during iteration?

Yup!
Comment 5 WebKit Commit Bot 2019-03-28 11:08:10 PDT
Comment on attachment 366119 [details]
Patch

Clearing flags on attachment: 366119

Committed r243611: <https://trac.webkit.org/changeset/243611>
Comment 6 WebKit Commit Bot 2019-03-28 11:08:11 PDT
All reviewed patches have been landed.  Closing bug.