Skip to content

Commit

Permalink
Cherry-pick c09328b. rdar://problem/111271905
Browse files Browse the repository at this point in the history
    Occasional crashes under WebWheelEventCoalescer::takeOldestEventBeingProcessed()
    https://bugs.webkit.org/show_bug.cgi?id=258653
    rdar://111271905

    Reviewed by Jer Noble.

    Crash data suggest that we can reach WebWheelEventCoalescer::takeOldestEventBeingProcessed() with
    m_eventsBeingProcessed being empty. We get here after one or more trips to the web process for wheel
    event handling, so it's possible there's some code path where we can get here with an empty m_eventsBeingProcessed,
    but I have not figured out how, so do a defensive fix of returning a std::optional<NativeWebWheelEvent>.

    * Source/WebKit/Shared/WebWheelEventCoalescer.cpp:
    (WebKit::WebWheelEventCoalescer::takeOldestEventBeingProcessed):
    * Source/WebKit/Shared/WebWheelEventCoalescer.h:
    * Source/WebKit/UIProcess/WebPageProxy.cpp:
    (WebKit::WebPageProxy::wheelEventHandlingCompleted):

    Canonical link: https://commits.webkit.org/265625@main

Identifier: 263823.1687@safari-7616.1.21-branch
  • Loading branch information
smfr authored and MyahCobbs committed Jun 30, 2023
1 parent d4e3f05 commit 9aeecb6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 4 additions & 2 deletions Source/WebKit/Shared/WebWheelEventCoalescer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ bool WebWheelEventCoalescer::shouldDispatchEvent(const NativeWebWheelEvent& even
return true;
}

NativeWebWheelEvent WebWheelEventCoalescer::takeOldestEventBeingProcessed()
std::optional<NativeWebWheelEvent> WebWheelEventCoalescer::takeOldestEventBeingProcessed()
{
ASSERT(hasEventsBeingProcessed());
if (m_eventsBeingProcessed.isEmpty())
return { };

auto oldestSequence = m_eventsBeingProcessed.takeFirst();
return oldestSequence->last();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/Shared/WebWheelEventCoalescer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class WebWheelEventCoalescer {
bool shouldDispatchEvent(const NativeWebWheelEvent&);
std::optional<WebWheelEvent> nextEventToDispatch();

NativeWebWheelEvent takeOldestEventBeingProcessed();
std::optional<NativeWebWheelEvent> takeOldestEventBeingProcessed();

bool hasEventsBeingProcessed() const { return !m_eventsBeingProcessed.isEmpty(); }

Expand Down
11 changes: 7 additions & 4 deletions Source/WebKit/UIProcess/WebPageProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3373,11 +3373,14 @@ void WebPageProxy::wheelEventHandlingCompleted(bool wasHandled)
{
auto oldestProcessedEvent = wheelEventCoalescer().takeOldestEventBeingProcessed();

LOG_WITH_STREAM(WheelEvents, stream << "WebPageProxy::wheelEventHandlingCompleted - finished handling " << platform(oldestProcessedEvent) << " handled " << wasHandled);
if (oldestProcessedEvent)
LOG_WITH_STREAM(WheelEvents, stream << "WebPageProxy::wheelEventHandlingCompleted - finished handling " << platform(*oldestProcessedEvent) << " handled " << wasHandled);
else
LOG_WITH_STREAM(WheelEvents, stream << "WebPageProxy::wheelEventHandlingCompleted - no event, handled " << wasHandled);

if (!wasHandled) {
m_uiClient->didNotHandleWheelEvent(this, oldestProcessedEvent);
pageClient().wheelEventWasNotHandledByWebCore(oldestProcessedEvent);
if (oldestProcessedEvent && !wasHandled) {
m_uiClient->didNotHandleWheelEvent(this, *oldestProcessedEvent);
pageClient().wheelEventWasNotHandledByWebCore(*oldestProcessedEvent);
}

if (auto eventToSend = wheelEventCoalescer().nextEventToDispatch()) {
Expand Down

0 comments on commit 9aeecb6

Please sign in to comment.