Commit d8f526f4 authored by Alexander Cooper's avatar Alexander Cooper Committed by Commit Bot

Update FocusChanged notifiers to operate on a copy

These focus changed calls ultimately trigger javascript events. These
events could potentially run code that would modify the list of items
that the FocusChanged notifiers are notifying, and thus invalidate their
in-use iterators.

Fix this by having these methods iterate over a copy instead of the
member list.

Fixed: 1107815
Change-Id: I03fa08eeadc60736f3a3fae079253dbd3ee26476
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2314158Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Auto-Submit: Alexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791261}
parent 0cd72d99
...@@ -1352,7 +1352,12 @@ void FocusController::RegisterFocusChangedObserver( ...@@ -1352,7 +1352,12 @@ void FocusController::RegisterFocusChangedObserver(
} }
void FocusController::NotifyFocusChangedObservers() const { void FocusController::NotifyFocusChangedObservers() const {
for (const auto& it : focus_changed_observers_) // Since this eventually dispatches an event to the page, the page could add
// new observer, which would invalidate our iterators; so iterate over a copy
// of the observer list.
HeapHashSet<WeakMember<FocusChangedObserver>> observers =
focus_changed_observers_;
for (const auto& it : observers)
it->FocusedFrameChanged(); it->FocusedFrameChanged();
} }
......
...@@ -732,7 +732,11 @@ XRSystem::XRSystem(LocalFrame& frame, int64_t ukm_source_id) ...@@ -732,7 +732,11 @@ XRSystem::XRSystem(LocalFrame& frame, int64_t ukm_source_id)
void XRSystem::FocusedFrameChanged() { void XRSystem::FocusedFrameChanged() {
// Tell all sessions that focus changed. // Tell all sessions that focus changed.
for (const auto& session : sessions_) { // Since this eventually dispatches an event to the page, the page could
// create a new session which would invalidate our iterators; so iterate over
// a copy of the session map.
HeapHashSet<WeakMember<XRSession>> processing_sessions = sessions_;
for (const auto& session : processing_sessions) {
session->OnFocusChanged(); session->OnFocusChanged();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment