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

Changeset 239987 in webkit


Ignore:
Timestamp:
Jan 15, 2019, 8:31:05 AM (8 years ago)
Author:
Devin Rousso
Message:

Web Inspector: Audit: provide a way to determine whether a give node has event listeners
​https://bugs.webkit.org/show_bug.cgi?id=193226
<rdar://problem/46800005>

Reviewed by Joseph Pecoraro.

Source/WebCore:

Test: inspector/audit/run-dom.html

  • inspector/InspectorAuditDOMObject.idl:
  • inspector/InspectorAuditDOMObject.h:
  • inspector/InspectorAuditDOMObject.cpp:

(WebCore::InspectorAuditDOMObject::hasEventListeners): Added.

LayoutTests:

  • inspector/audit/run-dom.html: Added.
  • inspector/audit/run-dom-expected.txt: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r239986 r239987  
     12019-01-15  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Audit: provide a way to determine whether a give node has event listeners
     4        https://bugs.webkit.org/show_bug.cgi?id=193226
     5        <rdar://problem/46800005>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        * inspector/audit/run-dom.html: Added.
     10        * inspector/audit/run-dom-expected.txt: Added.
     11
    1122019-01-15  Devin Rousso  <drousso@apple.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r239986 r239987  
     12019-01-15  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Audit: provide a way to determine whether a give node has event listeners
     4        https://bugs.webkit.org/show_bug.cgi?id=193226
     5        <rdar://problem/46800005>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        Test: inspector/audit/run-dom.html
     10
     11        * inspector/InspectorAuditDOMObject.idl:
     12        * inspector/InspectorAuditDOMObject.h:
     13        * inspector/InspectorAuditDOMObject.cpp:
     14        (WebCore::InspectorAuditDOMObject::hasEventListeners): Added.
     15
    1162019-01-15  Devin Rousso  <drousso@apple.com>
    217
  • trunk/Source/WebCore/inspector/InspectorAuditDOMObject.cpp

    r239976 r239987  
    2828#include "InspectorAuditDOMObject.h"
    2929
     30#include "Node.h"
     31#include <wtf/text/AtomicString.h>
     32#include <wtf/text/WTFString.h>
     33
    3034namespace WebCore {
    3135
    3236using namespace Inspector;
    3337
    34 InspectorAuditDOMObject::InspectorAuditDOMObject()
     38#define ERROR_IF_NO_ACTIVE_AUDIT() \
     39    if (!m_auditAgent.hasActiveAudit()) \
     40        return Exception { NotAllowedError, "Cannot be called outside of a Web Inspector Audit"_s };
     41
     42InspectorAuditDOMObject::InspectorAuditDOMObject(InspectorAuditAgent& auditAgent)
     43    : m_auditAgent(auditAgent)
    3544{
    3645}
    3746
     47ExceptionOr<bool> InspectorAuditDOMObject::hasEventListeners(Node& node, const String& type)
     48{
     49    ERROR_IF_NO_ACTIVE_AUDIT();
     50
     51    if (EventTargetData* eventTargetData = node.eventTargetData()) {
     52        Vector<AtomicString> eventTypes;
     53        if (type.isNull())
     54            eventTypes = eventTargetData->eventListenerMap.eventTypes();
     55        else
     56            eventTypes.append(type);
     57
     58        for (AtomicString& type : eventTypes) {
     59            for (const RefPtr<RegisteredEventListener>& listener : node.eventListeners(type)) {
     60                if (listener->callback().type() == EventListener::JSEventListenerType)
     61                    return true;
     62            }
     63        }
     64    }
     65
     66    return false;
     67}
     68
    3869} // namespace WebCore
  • trunk/Source/WebCore/inspector/InspectorAuditDOMObject.h

    r239976 r239987  
    2626#pragma once
    2727
     28#include "ExceptionOr.h"
    2829#include <JavaScriptCore/InspectorAuditAgent.h>
    2930#include <wtf/Ref.h>
    … …  
    3233namespace WebCore {
    3334
     35class Node;
     36
    3437class InspectorAuditDOMObject : public RefCounted<InspectorAuditDOMObject> {
    3538public:
    36     static Ref<InspectorAuditDOMObject> create(Inspector::InspectorAuditAgent&)
     39    static Ref<InspectorAuditDOMObject> create(Inspector::InspectorAuditAgent& auditAgent)
    3740    {
    38         return adoptRef(*new InspectorAuditDOMObject());
     41        return adoptRef(*new InspectorAuditDOMObject(auditAgent));
    3942    }
    4043
     44    ExceptionOr<bool> hasEventListeners(Node&, const String& type);
     45
    4146private:
    42     explicit InspectorAuditDOMObject();
     47    explicit InspectorAuditDOMObject(Inspector::InspectorAuditAgent&);
     48
     49    Inspector::InspectorAuditAgent& m_auditAgent;
    4350};
    4451
  • trunk/Source/WebCore/inspector/InspectorAuditDOMObject.idl

    r239976 r239987  
    2929    NoInterfaceObject,
    3030] interface InspectorAuditDOMObject {
     31    [MayThrowException] boolean hasEventListeners(Node node, optional DOMString type);
    3132};
Note: See TracChangeset for help on using the changeset viewer.