• Chris Lu's avatar
    [ios] Fix Overlay Presenter dismiss logic for detached WebStates · 68280952
    Chris Lu authored
    When a WebState is detached from a WebStateList, the Overlay Presenter
    removes itself as the OverlayRequestQueue's delegate. If an overlay
    was being presented, the queue then removes the request. However,
    the OverlayWasDismissed() callback of the request is still executed,
    causing bad behavior given that the request is now null.
    
    Two new codepaths are introduced to managed this newly discovered scenario
    best reproduced with using the Crash Restore Infobar:
    
    1) The presenter remains the delegate of a queue when its WebState
    is detached and an overlay is being presented. That way if the queue is
    destroyed and the requests are cancelled,
    | removed_request_awaiting_dismissal_| can be used to extend its lifetime
    until dismissal callbacks are finished.
    
    2) If the presenter is replaced as the queue's delegate, there is no
    way to guarantee the validity of |presenting_request_| from then on.
    This can technically also occur separately from WebState detachment.
    Thus, upon replacement, the presenter will do early DidHideOverlay()
    calls, reset |presenting_request_| and mark
    |detached_queue_replaced_delegate_| as true so that
    it knows to early return in OverlayWasDismissed since the request
    is likely to be invalid at that point.
    
    
    Bug: 1071914
    Change-Id: Ie7d7d7e67849323ac482b83680f7e35853b8c284
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2207509
    Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
    Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#774292}
    68280952
overlay_request_queue_impl.mm 5.58 KB