⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 269321 in webkit


Ignore:
Timestamp:
Nov 3, 2020, 11:36:08 AM (6 years ago)
Author:
jer.noble@apple.com
Message:

Protect against HTMLMediaElement being destroyed during disptachEvent().
https://bugs.webkit.org/show_bug.cgi?id=218398
<rdar://problem/67613836>

Reviewed by Chris Dumez.

Make the MainThreadGenericEventQueue protect the target as well as the owner of the queue.

Drive-by fix: Create the scoped eventFiringScope object after the protect object, to ensure
that the member variable set by the first scope will safely occur.

Drive-by fix #2: Also null-check the result of document().page() within HTMLMediaElement::dispatchEvent().

  • dom/GenericEventQueue.cpp:

(WebCore::MainThreadGenericEventQueue::dispatchOneEvent):

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::dispatchEvent):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r269314 r269321  
     12020-11-03  Jer Noble  <jer.noble@apple.com>
     2
     3        Protect against HTMLMediaElement being destroyed during disptachEvent().
     4        https://bugs.webkit.org/show_bug.cgi?id=218398
     5        <rdar://problem/67613836>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Make the MainThreadGenericEventQueue protect the target as well as the owner of the queue.
     10
     11        Drive-by fix: Create the scoped `eventFiringScope` object after the `protect` object, to ensure
     12        that the member variable set by the first scope will safely occur.
     13
     14        Drive-by fix #2: Also null-check the result of document().page() within HTMLMediaElement::dispatchEvent().
     15
     16        * dom/GenericEventQueue.cpp:
     17        (WebCore::MainThreadGenericEventQueue::dispatchOneEvent):
     18        * html/HTMLMediaElement.cpp:
     19        (WebCore::HTMLMediaElement::dispatchEvent):
     20
    1212020-11-03  Commit Queue  <commit-queue@webkit.org>
    222
  • trunk/Source/WebCore/dom/GenericEventQueue.cpp

    r259299 r269321  
    6565    ASSERT(!m_pendingEvents.isEmpty());
    6666
     67    Ref<EventTarget> protect(m_owner);
    6768    SetForScope<bool> eventFiringScope(m_isFiringEvent, true);
    68     Ref<EventTarget> protect(m_owner);
    6969
    7070    RefPtr<Event> event = m_pendingEvents.takeFirst();
    71     EventTarget& target = event->target() ? *event->target() : m_owner;
    72     ASSERT_WITH_MESSAGE(!target.scriptExecutionContext()->activeDOMObjectsAreStopped(),
     71    Ref<EventTarget> target = event->target() ? *event->target() : m_owner;
     72    ASSERT_WITH_MESSAGE(!target->scriptExecutionContext()->activeDOMObjectsAreStopped(),
    7373        "An attempt to dispatch an event on a stopped target by EventTargetInterface=%d (nodeName=%s target=%p owner=%p)",
    74         m_owner.eventTargetInterface(), m_owner.isNode() ? static_cast<Node&>(m_owner).nodeName().ascii().data() : "", &target, &m_owner);
    75     target.dispatchEvent(*event);
     74        m_owner.eventTargetInterface(), m_owner.isNode() ? static_cast<Node&>(m_owner).nodeName().ascii().data() : "", target.ptr(), &m_owner);
     75    target->dispatchEvent(*event);
    7676}
    7777
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r268865 r269321  
    60206020
    60216021        setFullscreenMode(VideoFullscreenModeNone);
    6022         document().page()->chrome().client().exitVideoFullscreenForVideoElement(downcast<HTMLVideoElement>(*this));
     6022        if (auto* page = document().page())
     6023            page->chrome().client().exitVideoFullscreenForVideoElement(downcast<HTMLVideoElement>(*this));
    60236024    }
    60246025}
Note: See TracChangeset for help on using the changeset viewer.