Fix LazyLoad crash when multiple navigations are queued
Putting `loading=lazy` on an out-of-view iframe creates an internal LazyLoadFrameObserver owned by the HTMLFrameOwnerElement associated with the iframe element. Before this CL, `src` mutations reset the HTMLFrameOwnerElement's LazyLoadFrameObserver member, however old observers may hang around until they are garbage collected. Until this happens, they are technically active observers and still reference the HTMLFrameOwnerElement. This means if you queue multiple lazy loaded navigations via `src` attribute mutations, there may be multiple LazyLoadFrameObservers that are "active" and referencing the element. When the iframe is scrolled into view, the old still-alive LazyLoadFrameObserver's LoadImmediately() method may is called before the observer is GC'd. In that case, we start to navigate the iframe. This calls Frame::Navigate, which is expected to call LazyLoadFrameObserver::CancelPendingLazyLoad(), which is ensured by this CHECK [1]. However, the "old" LazyLoadFrameObserver::LoadImmediately() method invokes Frame::Navigate(), which invokes the "new" LazyLoadFrameObserver::CancelPendingLazyLoad() method. Therefore the CHECK mentioned above actually fails, because the "old" LazyLoadFrameObserver was not cancelled correctly during the navigation flow. After this CL, upon creating a new LazyLoadFrameObserver for the HTMLFrameOwnerElement we reset old LazyLoadFrameObservers by calling CancelPendingLazyLoad() on them. Then they are effectively disabled until they are GC'd. This CL also includes a test which crashes Chrome's renderer before the fix. [1]: https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/core/html/lazy_load_frame_observer.cc;l=197;drc=6e8b6ca4b8f8f7ff0b41ba613edd47453bb3aafe R=dcheng@chromium.org, sclittle@chromium.org Bug: 1137708, 1126127 Change-Id: I0a7eef854bed3e192a5ef68b9cec18c95353298a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2497424 Commit-Queue: Dominic Farolino <dom@chromium.org> Reviewed-by:Daniel Cheng <dcheng@chromium.org> Cr-Commit-Position: refs/heads/master@{#821313}
Showing
Please register or sign in to comment