Bug 48372 - Fix direct event type querying by using a generic event wrapper function
Summary: Fix direct event type querying by using a generic event wrapper function
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-26 13:52 PDT by Abhishek Arya
Modified: 2022-08-19 19:53 PDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Abhishek Arya 2010-10-26 13:52:02 PDT
As per Dimitri's comments on bug https://bugs.webkit.org/show_bug.cgi?id=48345, we should prevent direct event-type() querying in various places e.g.

void ImageEventListener::handleEvent(ScriptExecutionContext*, Event* event)
{
    if (event->type() == eventNames().resizeEvent)
        m_doc->windowSizeChanged();
    else if (event->type() == eventNames().clickEvent) {
        MouseEvent* mouseEvent = static_cast<MouseEvent*>(event);

And replace with a generic wrapper like isMouseClickEvent(event) which does the
1) event type check - event->type() == eventNames().clickEvent
2) event cast check - event->isMouseEvent
Comment 1 Ahmad Saleem 2022-08-11 14:54:59 PDT
When searching for "ImageEventListener", I can only find single source in Webkit Github:

https://github.com/WebKit/WebKit/blob/50d7e0b0b808afca93e5ede9cd7c0d44b1ed8130/Source/WebCore/html/ImageDocument.cpp#L62

Is this in relation to above? Or this is no longer applicable. Thanks!
Comment 2 Alexey Proskuryakov 2022-08-19 19:53:42 PDT
We don't have this idea implemented, but we use safer casting. I'll leave it to others to decide if this is still worth tracking. Currently, the code looks like this:

void ImageEventListener::handleEvent(ScriptExecutionContext&, Event& event)
{
    if (event.type() == eventNames().resizeEvent)
        m_document.windowSizeChanged();
    else if (event.type() == eventNames().clickEvent && is<MouseEvent>(event)) {
        MouseEvent& mouseEvent = downcast<MouseEvent>(event);