Bug 196324

Summary: Web Inspector: Canvas: unbinding a canvas should always remove the agent as an observer
Product: WebKit Reporter: Devin Rousso <hi>
Component: Web InspectorAssignee: Devin Rousso <hi>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, commit-queue, esprehn+autocc, ews-watchlist, gyuyoung.kim, hi, inspector-bugzilla-changes, joepeck, mattbaker, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch none

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.