Use more references in event dispatch code
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Jul 2017 21:16:29 +0000 (21:16 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Jul 2017 21:16:29 +0000 (21:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174681

Reviewed by Geoffrey Garen.

Source/WebCore:

Make EventListener::handleEvent() take a ScriptExecutionContext&, Event&.
Then make everything build again. Various null checks and assertions
disappear in the process.

* bindings/js/JSErrorHandler.cpp:
(WebCore::JSErrorHandler::handleEvent):
* bindings/js/JSErrorHandler.h:
* bindings/js/JSEventListener.cpp:
(WebCore::JSEventListener::initializeJSFunction):
(WebCore::JSEventListener::handleEvent):
(WebCore::eventHandlerAttribute):
* bindings/js/JSEventListener.h:
(WebCore::JSEventListener::jsFunction):
* bindings/js/JSLazyEventListener.cpp:
(WebCore::JSLazyEventListener::initializeJSFunction):
* bindings/js/JSLazyEventListener.h:
* dom/EventListener.h:
* dom/EventTarget.cpp:
(WebCore::EventTarget::fireEventListeners):
* html/HTMLPlugInElement.cpp:
(WebCore::HTMLPlugInElement::defaultEventHandler):
* html/ImageDocument.cpp:
(WebCore::ImageEventListener::handleEvent):
* inspector/CommandLineAPIHost.cpp:
(WebCore::listenerEntriesFromListenerInfo):
* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::buildObjectForEventListener):
* inspector/InspectorIndexedDBAgent.cpp:
* platform/Widget.h:
(WebCore::Widget::handleEvent):
* platform/cocoa/WebPlaybackSessionModelMediaElement.h:
* platform/cocoa/WebPlaybackSessionModelMediaElement.mm:
(WebCore::WebPlaybackSessionModelMediaElement::handleEvent):
* platform/cocoa/WebVideoFullscreenModelVideoElement.h:
* platform/cocoa/WebVideoFullscreenModelVideoElement.mm:
(WebVideoFullscreenModelVideoElement::handleEvent):
* svg/SVGTRefElement.cpp:
(WebCore::SVGTRefTargetEventListener::handleEvent):
* svg/animation/SVGSMILElement.cpp:
(WebCore::ConditionEventListener::handleEvent):
(WebCore::SVGSMILElement::handleConditionEvent):
* svg/animation/SVGSMILElement.h:

Source/WebKit:

* WebProcess/Plugins/PDF/PDFPluginAnnotation.h:
* WebProcess/Plugins/PDF/PDFPluginAnnotation.mm:
(WebKit::PDFPluginAnnotation::handleEvent):
(WebKit::PDFPluginAnnotation::PDFPluginAnnotationEventListener::handleEvent):
* WebProcess/Plugins/PDF/PDFPluginPasswordField.h:
* WebProcess/Plugins/PDF/PDFPluginPasswordField.mm:
(WebKit::PDFPluginPasswordField::handleEvent):
* WebProcess/Plugins/PDF/PDFPluginTextAnnotation.h:
* WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm:
(WebKit::PDFPluginTextAnnotation::handleEvent):
* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::createWebEvent):
(WebKit::PluginView::handleEvent):
* WebProcess/Plugins/PluginView.h:

Source/WebKitLegacy/mac:

* DOM/ObjCEventListener.h:
* DOM/ObjCEventListener.mm:
(WebCore::ObjCEventListener::handleEvent):
* WebCoreSupport/WebFrameLoaderClient.mm:
(NetscapePluginWidget::handleEvent):

Source/WebKitLegacy/win:

* DOMEventsClasses.cpp:
(WebEventListener::handleEvent):
* DOMEventsClasses.h:
* Plugins/PluginView.cpp:
(WebCore::PluginView::handleEvent):
* Plugins/PluginView.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@219743 268f45cc-cd09-0410-ab3c-d52691b4dbfc

43 files changed:
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSErrorHandler.cpp
Source/WebCore/bindings/js/JSErrorHandler.h
Source/WebCore/bindings/js/JSEventListener.cpp
Source/WebCore/bindings/js/JSEventListener.h
Source/WebCore/bindings/js/JSLazyEventListener.cpp
Source/WebCore/bindings/js/JSLazyEventListener.h
Source/WebCore/dom/EventListener.h
Source/WebCore/dom/EventTarget.cpp
Source/WebCore/html/HTMLPlugInElement.cpp
Source/WebCore/html/ImageDocument.cpp
Source/WebCore/inspector/CommandLineAPIHost.cpp
Source/WebCore/inspector/InspectorDOMAgent.cpp
Source/WebCore/inspector/InspectorIndexedDBAgent.cpp
Source/WebCore/platform/Widget.h
Source/WebCore/platform/cocoa/WebPlaybackSessionModelMediaElement.h
Source/WebCore/platform/cocoa/WebPlaybackSessionModelMediaElement.mm
Source/WebCore/platform/cocoa/WebVideoFullscreenModelVideoElement.h
Source/WebCore/platform/cocoa/WebVideoFullscreenModelVideoElement.mm
Source/WebCore/svg/SVGTRefElement.cpp
Source/WebCore/svg/animation/SVGSMILElement.cpp
Source/WebCore/svg/animation/SVGSMILElement.h
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/GObjectEventListener.cpp
Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/GObjectEventListener.h
Source/WebKit/WebProcess/Plugins/PDF/PDFPluginAnnotation.h
Source/WebKit/WebProcess/Plugins/PDF/PDFPluginAnnotation.mm
Source/WebKit/WebProcess/Plugins/PDF/PDFPluginPasswordField.h
Source/WebKit/WebProcess/Plugins/PDF/PDFPluginPasswordField.mm
Source/WebKit/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.h
Source/WebKit/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm
Source/WebKit/WebProcess/Plugins/PluginView.cpp
Source/WebKit/WebProcess/Plugins/PluginView.h
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/DOM/ObjCEventListener.h
Source/WebKitLegacy/mac/DOM/ObjCEventListener.mm
Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm
Source/WebKitLegacy/win/ChangeLog
Source/WebKitLegacy/win/DOMEventsClasses.cpp
Source/WebKitLegacy/win/DOMEventsClasses.h
Source/WebKitLegacy/win/Plugins/PluginView.cpp
Source/WebKitLegacy/win/Plugins/PluginView.h
Source/WebKitLegacy/win/Plugins/PluginViewWin.cpp

index c986cab..804ec82 100644 (file)
@@ -1,3 +1,53 @@
+2017-07-21  Andreas Kling  <akling@apple.com>
+
+        Use more references in event dispatch code
+        https://bugs.webkit.org/show_bug.cgi?id=174681
+
+        Reviewed by Geoffrey Garen.
+
+        Make EventListener::handleEvent() take a ScriptExecutionContext&, Event&.
+        Then make everything build again. Various null checks and assertions
+        disappear in the process.
+
+        * bindings/js/JSErrorHandler.cpp:
+        (WebCore::JSErrorHandler::handleEvent):
+        * bindings/js/JSErrorHandler.h:
+        * bindings/js/JSEventListener.cpp:
+        (WebCore::JSEventListener::initializeJSFunction):
+        (WebCore::JSEventListener::handleEvent):
+        (WebCore::eventHandlerAttribute):
+        * bindings/js/JSEventListener.h:
+        (WebCore::JSEventListener::jsFunction):
+        * bindings/js/JSLazyEventListener.cpp:
+        (WebCore::JSLazyEventListener::initializeJSFunction):
+        * bindings/js/JSLazyEventListener.h:
+        * dom/EventListener.h:
+        * dom/EventTarget.cpp:
+        (WebCore::EventTarget::fireEventListeners):
+        * html/HTMLPlugInElement.cpp:
+        (WebCore::HTMLPlugInElement::defaultEventHandler):
+        * html/ImageDocument.cpp:
+        (WebCore::ImageEventListener::handleEvent):
+        * inspector/CommandLineAPIHost.cpp:
+        (WebCore::listenerEntriesFromListenerInfo):
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::buildObjectForEventListener):
+        * inspector/InspectorIndexedDBAgent.cpp:
+        * platform/Widget.h:
+        (WebCore::Widget::handleEvent):
+        * platform/cocoa/WebPlaybackSessionModelMediaElement.h:
+        * platform/cocoa/WebPlaybackSessionModelMediaElement.mm:
+        (WebCore::WebPlaybackSessionModelMediaElement::handleEvent):
+        * platform/cocoa/WebVideoFullscreenModelVideoElement.h:
+        * platform/cocoa/WebVideoFullscreenModelVideoElement.mm:
+        (WebVideoFullscreenModelVideoElement::handleEvent):
+        * svg/SVGTRefElement.cpp:
+        (WebCore::SVGTRefTargetEventListener::handleEvent):
+        * svg/animation/SVGSMILElement.cpp:
+        (WebCore::ConditionEventListener::handleEvent):
+        (WebCore::SVGSMILElement::handleConditionEvent):
+        * svg/animation/SVGSMILElement.h:
+
 2017-07-21  Zalan Bujtas  <zalan@apple.com>
 
         iBooks: Overlapping/missing content at beginning/end of paragraph.
index ed2f0e0..431e3b2 100644 (file)
@@ -57,24 +57,20 @@ JSErrorHandler::~JSErrorHandler()
 {
 }
 
-void JSErrorHandler::handleEvent(ScriptExecutionContext* scriptExecutionContext, Event* event)
+void JSErrorHandler::handleEvent(ScriptExecutionContext& scriptExecutionContext, Event& event)
 {
-    if (!is<ErrorEvent>(*event))
+    if (!is<ErrorEvent>(event))
         return JSEventListener::handleEvent(scriptExecutionContext, event);
 
-    ASSERT(scriptExecutionContext);
-    if (!scriptExecutionContext)
-        return;
-
-    ErrorEvent& errorEvent = downcast<ErrorEvent>(*event);
+    ErrorEvent& errorEvent = downcast<ErrorEvent>(event);
 
-    JSLockHolder lock(scriptExecutionContext->vm());
+    JSLockHolder lock(scriptExecutionContext.vm());
 
     JSObject* jsFunction = this->jsFunction(scriptExecutionContext);
     if (!jsFunction)
         return;
 
-    JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(scriptExecutionContext, isolatedWorld());
+    JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(&scriptExecutionContext, isolatedWorld());
     if (!globalObject)
         return;
 
@@ -87,7 +83,7 @@ void JSErrorHandler::handleEvent(ScriptExecutionContext* scriptExecutionContext,
         Ref<JSErrorHandler> protectedThis(*this);
 
         Event* savedEvent = globalObject->currentEvent();
-        globalObject->setCurrentEvent(event);
+        globalObject->setCurrentEvent(&event);
 
         MarkedArgumentBuffer args;
         args.append(toJS<IDLDOMString>(*exec, errorEvent.message()));
@@ -99,14 +95,14 @@ void JSErrorHandler::handleEvent(ScriptExecutionContext* scriptExecutionContext,
         VM& vm = globalObject->vm();
         VMEntryScope entryScope(vm, vm.entryScope ? vm.entryScope->globalObject() : globalObject);
 
-        InspectorInstrumentationCookie cookie = JSMainThreadExecState::instrumentFunctionCall(scriptExecutionContext, callType, callData);
+        InspectorInstrumentationCookie cookie = JSMainThreadExecState::instrumentFunctionCall(&scriptExecutionContext, callType, callData);
 
         NakedPtr<JSC::Exception> exception;
-        JSValue returnValue = scriptExecutionContext->isDocument()
+        JSValue returnValue = scriptExecutionContext.isDocument()
             ? JSMainThreadExecState::profiledCall(exec, JSC::ProfilingReason::Other, jsFunction, callType, callData, globalObject, args, exception)
             : JSC::profiledCall(exec, JSC::ProfilingReason::Other, jsFunction, callType, callData, globalObject, args, exception);
 
-        InspectorInstrumentation::didCallFunction(cookie, scriptExecutionContext);
+        InspectorInstrumentation::didCallFunction(cookie, &scriptExecutionContext);
 
         globalObject->setCurrentEvent(savedEvent);
 
@@ -114,7 +110,7 @@ void JSErrorHandler::handleEvent(ScriptExecutionContext* scriptExecutionContext,
             reportException(exec, exception);
         else {
             if (returnValue.isTrue())
-                event->preventDefault();
+                event.preventDefault();
         }
     }
 }
index ba01c0e..b5627e2 100644 (file)
@@ -45,7 +45,7 @@ public:
 
 private:
     JSErrorHandler(JSC::JSObject* function, JSC::JSObject* wrapper, bool isAttribute, DOMWrapperWorld&);
-    void handleEvent(ScriptExecutionContext*, Event*) final;
+    void handleEvent(ScriptExecutionContext&, Event&) final;
 };
 
 // Creates a JS EventListener for "onerror" event handler in worker context. It has custom implementation because
index f9139a2..d6d6336 100644 (file)
@@ -60,7 +60,7 @@ JSEventListener::~JSEventListener()
 {
 }
 
-JSObject* JSEventListener::initializeJSFunction(ScriptExecutionContext*) const
+JSObject* JSEventListener::initializeJSFunction(ScriptExecutionContext&) const
 {
     return nullptr;
 }
@@ -84,13 +84,12 @@ static void handleBeforeUnloadEventReturnValue(BeforeUnloadEvent& event, const S
         event.setReturnValue(returnValue);
 }
 
-void JSEventListener::handleEvent(ScriptExecutionContext* scriptExecutionContext, Event* event)
+void JSEventListener::handleEvent(ScriptExecutionContext& scriptExecutionContext, Event& event)
 {
-    ASSERT(scriptExecutionContext);
-    if (!scriptExecutionContext || scriptExecutionContext->isJSExecutionForbidden())
+    if (scriptExecutionContext.isJSExecutionForbidden())
         return;
 
-    VM& vm = scriptExecutionContext->vm();
+    VM& vm = scriptExecutionContext.vm();
     JSLockHolder lock(vm);
     auto scope = DECLARE_CATCH_SCOPE(vm);
     // See https://dom.spec.whatwg.org/#dispatching-events spec on calling handleEvent.
@@ -101,15 +100,15 @@ void JSEventListener::handleEvent(ScriptExecutionContext* scriptExecutionContext
     if (!jsFunction)
         return;
 
-    JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(scriptExecutionContext, m_isolatedWorld);
+    JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(&scriptExecutionContext, m_isolatedWorld);
     if (!globalObject)
         return;
 
-    if (scriptExecutionContext->isDocument()) {
+    if (scriptExecutionContext.isDocument()) {
         JSDOMWindow* window = jsCast<JSDOMWindow*>(globalObject);
         if (!window->wrapped().isCurrentlyDisplayedInFrame())
             return;
-        if (wasCreatedFromMarkup() && !scriptExecutionContext->contentSecurityPolicy()->allowInlineEventHandlers(sourceURL(), sourcePosition().m_line))
+        if (wasCreatedFromMarkup() && !scriptExecutionContext.contentSecurityPolicy()->allowInlineEventHandlers(sourceURL(), sourcePosition().m_line))
             return;
         // FIXME: Is this check needed for other contexts?
         ScriptController& script = window->wrapped().frame()->script();
@@ -129,7 +128,7 @@ void JSEventListener::handleEvent(ScriptExecutionContext* scriptExecutionContext
             auto* exception = scope.exception();
             scope.clearException();
 
-            event->target()->uncaughtExceptionInEventHandler();
+            event.target()->uncaughtExceptionInEventHandler();
             reportException(exec, exception);
             return;
         }
@@ -140,42 +139,42 @@ void JSEventListener::handleEvent(ScriptExecutionContext* scriptExecutionContext
         Ref<JSEventListener> protectedThis(*this);
 
         MarkedArgumentBuffer args;
-        args.append(toJS(exec, globalObject, event));
+        args.append(toJS(exec, globalObject, &event));
 
         Event* savedEvent = globalObject->currentEvent();
-        globalObject->setCurrentEvent(event);
+        globalObject->setCurrentEvent(&event);
 
         VMEntryScope entryScope(vm, vm.entryScope ? vm.entryScope->globalObject() : globalObject);
 
-        InspectorInstrumentationCookie cookie = JSMainThreadExecState::instrumentFunctionCall(scriptExecutionContext, callType, callData);
+        InspectorInstrumentationCookie cookie = JSMainThreadExecState::instrumentFunctionCall(&scriptExecutionContext, callType, callData);
 
-        JSValue thisValue = handleEventFunction == jsFunction ? toJS(exec, globalObject, event->currentTarget()) : jsFunction;
+        JSValue thisValue = handleEventFunction == jsFunction ? toJS(exec, globalObject, event.currentTarget()) : jsFunction;
         NakedPtr<JSC::Exception> exception;
-        JSValue retval = scriptExecutionContext->isDocument()
+        JSValue retval = scriptExecutionContext.isDocument()
             ? JSMainThreadExecState::profiledCall(exec, JSC::ProfilingReason::Other, handleEventFunction, callType, callData, thisValue, args, exception)
             : JSC::profiledCall(exec, JSC::ProfilingReason::Other, handleEventFunction, callType, callData, thisValue, args, exception);
 
-        InspectorInstrumentation::didCallFunction(cookie, scriptExecutionContext);
+        InspectorInstrumentation::didCallFunction(cookie, &scriptExecutionContext);
 
         globalObject->setCurrentEvent(savedEvent);
 
-        if (is<WorkerGlobalScope>(*scriptExecutionContext)) {
-            auto scriptController = downcast<WorkerGlobalScope>(*scriptExecutionContext).script();
+        if (is<WorkerGlobalScope>(scriptExecutionContext)) {
+            auto scriptController = downcast<WorkerGlobalScope>(scriptExecutionContext).script();
             bool terminatorCausedException = (scope.exception() && isTerminatedExecutionException(vm, scope.exception()));
             if (terminatorCausedException || scriptController->isTerminatingExecution())
                 scriptController->forbidExecution();
         }
 
         if (exception) {
-            event->target()->uncaughtExceptionInEventHandler();
+            event.target()->uncaughtExceptionInEventHandler();
             reportException(exec, exception);
         } else {
-            if (is<BeforeUnloadEvent>(*event))
-                handleBeforeUnloadEventReturnValue(downcast<BeforeUnloadEvent>(*event), convert<IDLNullable<IDLDOMString>>(*exec, retval));
+            if (is<BeforeUnloadEvent>(event))
+                handleBeforeUnloadEventReturnValue(downcast<BeforeUnloadEvent>(event), convert<IDLNullable<IDLDOMString>>(*exec, retval));
 
             if (m_isAttribute) {
                 if (retval.isFalse())
-                    event->preventDefault();
+                    event.preventDefault();
             }
         }
     }
@@ -202,7 +201,7 @@ static inline JSC::JSValue eventHandlerAttribute(EventListener* abstractListener
     if (!listener)
         return jsNull();
 
-    auto* function = listener->jsFunction(&context);
+    auto* function = listener->jsFunction(context);
     if (!function)
         return jsNull();
 
index 693853a..56b0e69 100644 (file)
@@ -65,7 +65,7 @@ public:
     // Returns true if this event listener was created for an event handler attribute, like "onload" or "onclick".
     bool isAttribute() const { return m_isAttribute; }
 
-    JSC::JSObject* jsFunction(ScriptExecutionContext*) const;
+    JSC::JSObject* jsFunction(ScriptExecutionContext&) const;
     DOMWrapperWorld& isolatedWorld() const { return m_isolatedWorld; }
 
     JSC::JSObject* wrapper() const { return m_wrapper.get(); }
@@ -75,13 +75,13 @@ public:
     virtual TextPosition sourcePosition() const { return TextPosition(); }
 
 private:
-    virtual JSC::JSObject* initializeJSFunction(ScriptExecutionContext*) const;
+    virtual JSC::JSObject* initializeJSFunction(ScriptExecutionContext&) const;
     void visitJSFunction(JSC::SlotVisitor&) override;
     bool virtualisAttribute() const override;
 
 protected:
     JSEventListener(JSC::JSObject* function, JSC::JSObject* wrapper, bool isAttribute, DOMWrapperWorld&);
-    void handleEvent(ScriptExecutionContext*, Event*) override;
+    void handleEvent(ScriptExecutionContext&, Event&) override;
 
 private:
     mutable JSC::Weak<JSC::JSObject> m_jsFunction;
@@ -107,7 +107,7 @@ void setDocumentEventHandlerAttribute(JSC::ExecState&, JSC::JSObject&, HTMLEleme
 JSC::JSValue documentEventHandlerAttribute(Document&, const AtomicString& eventType, DOMWrapperWorld&);
 void setDocumentEventHandlerAttribute(JSC::ExecState&, JSC::JSObject&, Document&, const AtomicString& eventType, JSC::JSValue);
 
-inline JSC::JSObject* JSEventListener::jsFunction(ScriptExecutionContext* scriptExecutionContext) const
+inline JSC::JSObject* JSEventListener::jsFunction(ScriptExecutionContext& scriptExecutionContext) const
 {
     // initializeJSFunction can trigger code that deletes this event listener
     // before we're done. It should always return 0 in this case.
index e738aff..9a2f472 100644 (file)
@@ -76,12 +76,9 @@ JSLazyEventListener::~JSLazyEventListener()
 #endif
 }
 
-JSObject* JSLazyEventListener::initializeJSFunction(ScriptExecutionContext* executionContext) const
+JSObject* JSLazyEventListener::initializeJSFunction(ScriptExecutionContext& executionContext) const
 {
     ASSERT(is<Document>(executionContext));
-    if (!executionContext)
-        return nullptr;
-
     ASSERT(!m_code.isNull());
     ASSERT(!m_eventParameterName.isNull());
     if (m_code.isNull() || m_eventParameterName.isNull())
@@ -91,7 +88,7 @@ JSObject* JSLazyEventListener::initializeJSFunction(ScriptExecutionContext* exec
     // element's document. The script execution context may be different from the node's document if the
     // node's document was created by JavaScript.
     // [1] https://html.spec.whatwg.org/multipage/webappapis.html#getting-the-current-value-of-the-event-handler
-    Document& document = m_originalNode ? m_originalNode->document() : downcast<Document>(*executionContext);
+    Document& document = m_originalNode ? m_originalNode->document() : downcast<Document>(executionContext);
 
     if (!document.frame())
         return nullptr;
@@ -103,7 +100,7 @@ JSObject* JSLazyEventListener::initializeJSFunction(ScriptExecutionContext* exec
     if (!script.canExecuteScripts(AboutToExecuteScript) || script.isPaused())
         return nullptr;
 
-    JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(executionContext, isolatedWorld());
+    JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(&executionContext, isolatedWorld());
     if (!globalObject)
         return nullptr;
 
index 9c2849e..c25d5cb 100644 (file)
@@ -46,7 +46,7 @@ private:
 
     JSLazyEventListener(const String& functionName, const String& eventParameterName, const String& code, ContainerNode*, const String& sourceURL, const TextPosition&, JSC::JSObject* wrapper, DOMWrapperWorld& isolatedWorld);
 
-    JSC::JSObject* initializeJSFunction(ScriptExecutionContext*) const override;
+    JSC::JSObject* initializeJSFunction(ScriptExecutionContext&) const override;
     bool wasCreatedFromMarkup() const override { return true; }
 
     String m_functionName;
index b23c380..74295cd 100644 (file)
@@ -47,7 +47,7 @@ public:
 
     virtual ~EventListener() { }
     virtual bool operator==(const EventListener&) const = 0;
-    virtual void handleEvent(ScriptExecutionContext*, Event*) = 0;
+    virtual void handleEvent(ScriptExecutionContext&, Event&) = 0;
     virtual bool wasCreatedFromMarkup() const { return false; }
 
     virtual void visitJSFunction(JSC::SlotVisitor&) { }
index 7f7dc03..a363755 100644 (file)
@@ -232,12 +232,13 @@ void EventTarget::fireEventListeners(Event& event, EventListenerVector listeners
 {
     Ref<EventTarget> protectedThis(*this);
     ASSERT(!listeners.isEmpty());
+    ASSERT(scriptExecutionContext());
 
-    auto* context = scriptExecutionContext();
+    auto& context = *scriptExecutionContext();
     bool contextIsDocument = is<Document>(context);
     InspectorInstrumentationCookie willDispatchEventCookie;
     if (contextIsDocument)
-        willDispatchEventCookie = InspectorInstrumentation::willDispatchEvent(downcast<Document>(*context), event, true);
+        willDispatchEventCookie = InspectorInstrumentation::willDispatchEvent(downcast<Document>(context), event, true);
 
     for (auto& registeredListener : listeners) {
         if (UNLIKELY(registeredListener->wasRemoved()))
@@ -260,8 +261,8 @@ void EventTarget::fireEventListeners(Event& event, EventListenerVector listeners
         if (registeredListener->isPassive())
             event.setInPassiveListener(true);
 
-        InspectorInstrumentation::willHandleEvent(context, event);
-        registeredListener->callback().handleEvent(context, &event);
+        InspectorInstrumentation::willHandleEvent(&context, event);
+        registeredListener->callback().handleEvent(context, event);
 
         if (registeredListener->isPassive())
             event.setInPassiveListener(false);
index 26122ec..e2e31a1 100644 (file)
@@ -213,7 +213,7 @@ void HTMLPlugInElement::defaultEventHandler(Event& event)
         RefPtr<Widget> widget = downcast<RenderWidget>(*renderer).widget();
         if (!widget)
             return;
-        widget->handleEvent(&event);
+        widget->handleEvent(event);
         if (event.defaultHandled())
             return;
     }
index 718c648..5e6289d 100644 (file)
@@ -65,7 +65,7 @@ private:
     }
 
     bool operator==(const EventListener&) const override;
-    void handleEvent(ScriptExecutionContext*, Event*) override;
+    void handleEvent(ScriptExecutionContext&, Event&) override;
 
     ImageDocument& m_document;
 };
@@ -401,12 +401,12 @@ void ImageDocument::imageClicked(int x, int y)
     }
 }
 
-void ImageEventListener::handleEvent(ScriptExecutionContext*, Event* event)
+void ImageEventListener::handleEvent(ScriptExecutionContext&, Event& event)
 {
-    if (event->type() == eventNames().resizeEvent)
+    if (event.type() == eventNames().resizeEvent)
         m_document.windowSizeChanged();
-    else if (event->type() == eventNames().clickEvent && is<MouseEvent>(*event)) {
-        MouseEvent& mouseEvent = downcast<MouseEvent>(*event);
+    else if (event.type() == eventNames().clickEvent && is<MouseEvent>(event)) {
+        MouseEvent& mouseEvent = downcast<MouseEvent>(event);
         m_document.imageClicked(mouseEvent.offsetX(), mouseEvent.offsetY());
     }
 }
index bbf5fba..97a3e43 100644 (file)
@@ -107,7 +107,7 @@ static Vector<CommandLineAPIHost::ListenerEntry> listenerEntriesFromListenerInfo
         if (&jsListener->isolatedWorld() != &currentWorld(&state))
             continue;
 
-        auto function = jsListener->jsFunction(&document);
+        auto function = jsListener->jsFunction(document);
         if (!function)
             continue;
 
index 9a4ad16..255a778 100644 (file)
@@ -1543,7 +1543,7 @@ Ref<Inspector::Protocol::DOM::EventListener> InspectorDOMAgent::buildObjectForEv
     if (auto scriptListener = JSEventListener::cast(eventListener.ptr())) {
         JSC::JSLockHolder lock(scriptListener->isolatedWorld().vm());
         state = execStateFromNode(scriptListener->isolatedWorld(), &node->document());
-        handler = scriptListener->jsFunction(&node->document());
+        handler = scriptListener->jsFunction(node->document());
         if (handler && state) {
             body = handler->toString(state)->value(state);
             if (auto function = jsDynamicDowncast<JSC::JSFunction*>(state->vm(), handler)) {
index 4644cd0..6697e01 100644 (file)
@@ -115,14 +115,14 @@ public:
         return this == &other;
     }
 
-    void handleEvent(ScriptExecutionContext*, Event* event) final
+    void handleEvent(ScriptExecutionContext&, Event& event) final
     {
-        if (event->type() != eventNames().successEvent) {
+        if (event.type() != eventNames().successEvent) {
             m_executableWithDatabase->requestCallback().sendFailure("Unexpected event type.");
             return;
         }
 
-        auto& request = static_cast<IDBOpenDBRequest&>(*event->target());
+        auto& request = static_cast<IDBOpenDBRequest&>(*event.target());
 
         auto result = request.result();
         if (result.hasException()) {
@@ -357,14 +357,14 @@ public:
         return this == &other;
     }
 
-    void handleEvent(ScriptExecutionContext* context, Event* event) override
+    void handleEvent(ScriptExecutionContext&, Event& event) override
     {
-        if (event->type() != eventNames().successEvent) {
+        if (event.type() != eventNames().successEvent) {
             m_requestCallback->sendFailure("Unexpected event type.");
             return;
         }
 
-        auto& request = static_cast<IDBRequest&>(*event->target());
+        auto& request = static_cast<IDBRequest&>(*event.target());
 
         auto result = request.result();
         if (result.hasException()) {
@@ -398,10 +398,6 @@ public:
             return;
         }
 
-        auto* state = context ? context->execState() : nullptr;
-        if (!state)
-            return;
-
         auto dataEntry = DataEntry::create()
             .setKey(m_injectedScript.wrapObject(cursor->key(), String(), true))
             .setPrimaryKey(m_injectedScript.wrapObject(cursor->primaryKey(), String(), true))
@@ -646,11 +642,11 @@ public:
         return this == &other;
     }
 
-    void handleEvent(ScriptExecutionContext*, Event* event) override
+    void handleEvent(ScriptExecutionContext&, Event& event) override
     {
         if (!m_requestCallback->isActive())
             return;
-        if (event->type() != eventNames().completeEvent) {
+        if (event.type() != eventNames().completeEvent) {
             m_requestCallback->sendFailure("Unexpected event type.");
             return;
         }
index e2e8e93..710ef7b 100644 (file)
@@ -149,7 +149,7 @@ public:
     ScrollView* parent() const { return m_parent; }
     FrameView* root() const;
 
-    virtual void handleEvent(Event*) { }
+    virtual void handleEvent(Event&) { }
 
     virtual void notifyWidget(WidgetNotification) { }
 
index ad89513..e284694 100644 (file)
@@ -51,7 +51,7 @@ public:
     WEBCORE_EXPORT void setMediaElement(HTMLMediaElement*);
     HTMLMediaElement* mediaElement() const { return m_mediaElement.get(); }
 
-    WEBCORE_EXPORT void handleEvent(WebCore::ScriptExecutionContext*, WebCore::Event*) final;
+    WEBCORE_EXPORT void handleEvent(WebCore::ScriptExecutionContext&, WebCore::Event&) final;
     void updateForEventName(const WTF::AtomicString&);
     bool operator==(const EventListener& rhs) const final { return static_cast<const WebCore::EventListener*>(this) == &rhs; }
 
index cfcde43..15add49 100644 (file)
@@ -85,9 +85,9 @@ void WebPlaybackSessionModelMediaElement::setMediaElement(HTMLMediaElement* medi
     updateForEventName(eventNameAll());
 }
 
-void WebPlaybackSessionModelMediaElement::handleEvent(WebCore::ScriptExecutionContext*, WebCore::Event* event)
+void WebPlaybackSessionModelMediaElement::handleEvent(WebCore::ScriptExecutionContext&, WebCore::Event& event)
 {
-    updateForEventName(event->type());
+    updateForEventName(event.type());
 }
 
 void WebPlaybackSessionModelMediaElement::updateForEventName(const WTF::AtomicString& eventName)
index 962529e..9a0fb17 100644 (file)
@@ -57,7 +57,7 @@ public:
     WEBCORE_EXPORT void setVideoFullscreenLayer(PlatformLayer*, WTF::Function<void()>&& completionHandler = [] { });
     WEBCORE_EXPORT void waitForPreparedForInlineThen(WTF::Function<void()>&& completionHandler = [] { });
     
-    WEBCORE_EXPORT void handleEvent(WebCore::ScriptExecutionContext*, WebCore::Event*) override;
+    WEBCORE_EXPORT void handleEvent(WebCore::ScriptExecutionContext&, WebCore::Event&) override;
     void updateForEventName(const WTF::AtomicString&);
     bool operator==(const EventListener& rhs) const override { return static_cast<const WebCore::EventListener*>(this) == &rhs; }
 
index 9b8078c..b0bf47c 100644 (file)
@@ -81,9 +81,9 @@ void WebVideoFullscreenModelVideoElement::setVideoElement(HTMLVideoElement* vide
     updateForEventName(eventNameAll());
 }
 
-void WebVideoFullscreenModelVideoElement::handleEvent(WebCore::ScriptExecutionContext*, WebCore::Event* event)
+void WebVideoFullscreenModelVideoElement::handleEvent(WebCore::ScriptExecutionContext&, WebCore::Event& event)
 {
-    updateForEventName(event->type());
+    updateForEventName(event.type());
 }
 
 void WebVideoFullscreenModelVideoElement::updateForEventName(const WTF::AtomicString& eventName)
index 3262aac..b083736 100644 (file)
@@ -72,7 +72,7 @@ public:
 private:
     explicit SVGTRefTargetEventListener(SVGTRefElement& trefElement);
 
-    void handleEvent(ScriptExecutionContext*, Event*) final;
+    void handleEvent(ScriptExecutionContext&, Event&) final;
     bool operator==(const EventListener&) const final;
 
     SVGTRefElement& m_trefElement;
@@ -114,13 +114,13 @@ bool SVGTRefTargetEventListener::operator==(const EventListener& listener) const
     return false;
 }
 
-void SVGTRefTargetEventListener::handleEvent(ScriptExecutionContext*, Event* event)
+void SVGTRefTargetEventListener::handleEvent(ScriptExecutionContext&, Event& event)
 {
     ASSERT(isAttached());
 
-    if (event->type() == eventNames().DOMSubtreeModifiedEvent && &m_trefElement != event->target())
+    if (event.type() == eventNames().DOMSubtreeModifiedEvent && &m_trefElement != event.target())
         m_trefElement.updateReferencedText(m_target.get());
-    else if (event->type() == eventNames().DOMNodeRemovedFromDocumentEvent)
+    else if (event.type() == eventNames().DOMNodeRemovedFromDocumentEvent)
         m_trefElement.detachTarget();
 }
 
index dcae8f1..862d68a 100644 (file)
@@ -91,7 +91,7 @@ private:
     {
     }
 
-    void handleEvent(ScriptExecutionContext*, Event*) final;
+    void handleEvent(ScriptExecutionContext&, Event&) final;
 
     SVGSMILElement* m_animation;
     SVGSMILElement::Condition* m_condition;
@@ -104,11 +104,11 @@ bool ConditionEventListener::operator==(const EventListener& listener) const
     return false;
 }
 
-void ConditionEventListener::handleEvent(ScriptExecutionContext*, Event* event) 
+void ConditionEventListener::handleEvent(ScriptExecutionContext&, Event&)
 {
     if (!m_animation)
         return;
-    m_animation->handleConditionEvent(event, m_condition);
+    m_animation->handleConditionEvent(m_condition);
 }
 
 SVGSMILElement::Condition::Condition(Type type, BeginOrEnd beginOrEnd, const String& baseID, const String& name, SMILTime offset, int repeats)
@@ -1195,7 +1195,7 @@ void SVGSMILElement::removeTimeDependent(SVGSMILElement* animation)
     m_timeDependents.remove(animation);
 }
     
-void SVGSMILElement::handleConditionEvent(Event*, Condition* condition)
+void SVGSMILElement::handleConditionEvent(Condition* condition)
 {
     SMILTime elapsed = this->elapsed();
     if (condition->m_beginOrEnd == Begin)
index cb7bd15..fc34ce7 100644 (file)
@@ -166,7 +166,7 @@ private:
     void disconnectConditions();
 
     // Event base timing
-    void handleConditionEvent(Event*, Condition*);
+    void handleConditionEvent(Condition*);
 
     // Syncbase timing
     enum NewOrExistingInterval { NewInterval, ExistingInterval };
index 0c65577..a49899c 100644 (file)
@@ -1,3 +1,25 @@
+2017-07-21  Andreas Kling  <akling@apple.com>
+
+        Use more references in event dispatch code
+        https://bugs.webkit.org/show_bug.cgi?id=174681
+
+        Reviewed by Geoffrey Garen.
+
+        * WebProcess/Plugins/PDF/PDFPluginAnnotation.h:
+        * WebProcess/Plugins/PDF/PDFPluginAnnotation.mm:
+        (WebKit::PDFPluginAnnotation::handleEvent):
+        (WebKit::PDFPluginAnnotation::PDFPluginAnnotationEventListener::handleEvent):
+        * WebProcess/Plugins/PDF/PDFPluginPasswordField.h:
+        * WebProcess/Plugins/PDF/PDFPluginPasswordField.mm:
+        (WebKit::PDFPluginPasswordField::handleEvent):
+        * WebProcess/Plugins/PDF/PDFPluginTextAnnotation.h:
+        * WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm:
+        (WebKit::PDFPluginTextAnnotation::handleEvent):
+        * WebProcess/Plugins/PluginView.cpp:
+        (WebKit::PluginView::createWebEvent):
+        (WebKit::PluginView::handleEvent):
+        * WebProcess/Plugins/PluginView.h:
+
 2017-07-21  Chris Dumez  <cdumez@apple.com>
 
         WebResourceLoadStatisticsStore::m_operatingDates is unsafely modified from several threads
index 8814a5a..54efbc7 100644 (file)
@@ -64,13 +64,13 @@ void GObjectEventListener::gobjectDestroyed()
     m_handler = nullptr;
 }
 
-void GObjectEventListener::handleEvent(ScriptExecutionContext*, Event* event)
+void GObjectEventListener::handleEvent(ScriptExecutionContext&, Event& event)
 {
     GValue parameters[2] = { G_VALUE_INIT, G_VALUE_INIT };
     g_value_init(&parameters[0], WEBKIT_DOM_TYPE_EVENT_TARGET);
     g_value_set_object(&parameters[0], m_target);
 
-    GRefPtr<WebKitDOMEvent> domEvent = adoptGRef(WebKit::kit(event));
+    GRefPtr<WebKitDOMEvent> domEvent = adoptGRef(WebKit::kit(&event));
     g_value_init(&parameters[1], WEBKIT_DOM_TYPE_EVENT);
     g_value_set_object(&parameters[1], domEvent.get());
 
index 02b3b99..be233c3 100644 (file)
@@ -63,7 +63,7 @@ private:
     ~GObjectEventListener();
     void gobjectDestroyed();
 
-    void handleEvent(WebCore::ScriptExecutionContext*, WebCore::Event*) override;
+    void handleEvent(WebCore::ScriptExecutionContext&, WebCore::Event&) override;
 
     GObject* m_target;
     // We do not need to keep a reference to the m_coreTarget, because
index afda171..bc6ceae 100644 (file)
@@ -72,7 +72,7 @@ protected:
     PDFLayerController *pdfLayerController() const { return m_pdfLayerController; }
     WebCore::EventListener* eventListener() const { return m_eventListener.get(); }
 
-    virtual bool handleEvent(WebCore::Event*);
+    virtual bool handleEvent(WebCore::Event&);
 
 private:
     virtual Ref<WebCore::Element> createAnnotationElement() = 0;
@@ -96,7 +96,7 @@ private:
         {
         }
 
-        void handleEvent(WebCore::ScriptExecutionContext*, WebCore::Event*) override;
+        void handleEvent(WebCore::ScriptExecutionContext&, WebCore::Event&) override;
 
         PDFPluginAnnotation* m_annotation;
     };
index 74dcbc8..3363e1c 100644 (file)
@@ -110,9 +110,9 @@ void PDFPluginAnnotation::updateGeometry()
     styledElement->setInlineStyleProperty(CSSPropertyTop, documentSize.height() - annotationRect.origin.y - annotationRect.size.height - scrollPosition.y(), CSSPrimitiveValue::CSS_PX);
 }
 
-bool PDFPluginAnnotation::handleEvent(Event* event)
+bool PDFPluginAnnotation::handleEvent(Event& event)
 {
-    if (event->type() == eventNames().blurEvent || event->type() == eventNames().changeEvent) {
+    if (event.type() == eventNames().blurEvent || event.type() == eventNames().changeEvent) {
         m_plugin->setActiveAnnotation(0);
         return true;
     }
@@ -120,7 +120,7 @@ bool PDFPluginAnnotation::handleEvent(Event* event)
     return false;
 }
 
-void PDFPluginAnnotation::PDFPluginAnnotationEventListener::handleEvent(ScriptExecutionContext*, Event* event)
+void PDFPluginAnnotation::PDFPluginAnnotationEventListener::handleEvent(ScriptExecutionContext&, Event& event)
 {
     if (m_annotation)
         m_annotation->handleEvent(event);
index 36e2e82..7105d9a 100644 (file)
@@ -47,7 +47,7 @@ private:
 
     Ref<WebCore::Element> createAnnotationElement() override;
 
-    bool handleEvent(WebCore::Event*) override;
+    bool handleEvent(WebCore::Event&) override;
 };
 
 } // namespace WebKit
index 6778489..f481bf7 100644 (file)
@@ -65,14 +65,14 @@ void PDFPluginPasswordField::updateGeometry()
 {
 }
 
-bool PDFPluginPasswordField::handleEvent(WebCore::Event* event)
+bool PDFPluginPasswordField::handleEvent(WebCore::Event& event)
 {
-    if (event->isKeyboardEvent() && event->type() == eventNames().keyupEvent) {
-        KeyboardEvent* keyboardEvent = static_cast<KeyboardEvent*>(event);
+    if (event.isKeyboardEvent() && event.type() == eventNames().keyupEvent) {
+        auto& keyboardEvent = downcast<KeyboardEvent>(event);
 
-        if (keyboardEvent->keyIdentifier() == "Enter") {
+        if (keyboardEvent.keyIdentifier() == "Enter") {
             plugin()->attemptToUnlockPDF(value());
-            event->preventDefault();
+            event.preventDefault();
             return true;
         }
     }
index 0cae6f0..92d4023 100644 (file)
@@ -58,7 +58,7 @@ protected:
     String value() const;
 
 private:
-    bool handleEvent(WebCore::Event*) override;
+    bool handleEvent(WebCore::Event&) override;
 
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
index 710945e..1839f7c 100644 (file)
@@ -128,24 +128,24 @@ String PDFPluginTextAnnotation::value() const
     return downcast<HTMLTextFormControlElement>(element())->value();
 }
 
-bool PDFPluginTextAnnotation::handleEvent(Event* event)
+bool PDFPluginTextAnnotation::handleEvent(Event& event)
 {
     if (PDFPluginAnnotation::handleEvent(event))
         return true;
 
-    if (event->isKeyboardEvent() && event->type() == eventNames().keydownEvent) {
-        KeyboardEvent* keyboardEvent = static_cast<KeyboardEvent*>(event);
+    if (event.isKeyboardEvent() && event.type() == eventNames().keydownEvent) {
+        auto& keyboardEvent = downcast<KeyboardEvent>(event);
 
-        if (keyboardEvent->keyIdentifier() == "U+0009") {
-            if (keyboardEvent->ctrlKey() || keyboardEvent->metaKey() || keyboardEvent->altGraphKey())
+        if (keyboardEvent.keyIdentifier() == "U+0009") {
+            if (keyboardEvent.ctrlKey() || keyboardEvent.metaKey() || keyboardEvent.altGraphKey())
                 return false;
 
-            if (keyboardEvent->shiftKey())
+            if (keyboardEvent.shiftKey())
                 plugin()->focusPreviousAnnotation();
             else
                 plugin()->focusNextAnnotation();
             
-            event->preventDefault();
+            event.preventDefault();
             return true;
         }
     }
index 210bda9..eea38f0 100644 (file)
@@ -855,24 +855,24 @@ String PluginView::getSelectionString() const
     return m_plugin->getSelectionString();
 }
 
-std::unique_ptr<WebEvent> PluginView::createWebEvent(MouseEvent* event) const
+std::unique_ptr<WebEvent> PluginView::createWebEvent(MouseEvent& event) const
 {
     WebEvent::Type type = WebEvent::NoType;
     unsigned clickCount = 1;
-    if (event->type() == eventNames().mousedownEvent)
+    if (event.type() == eventNames().mousedownEvent)
         type = WebEvent::MouseDown;
-    else if (event->type() == eventNames().mouseupEvent)
+    else if (event.type() == eventNames().mouseupEvent)
         type = WebEvent::MouseUp;
-    else if (event->type() == eventNames().mouseoverEvent) {
+    else if (event.type() == eventNames().mouseoverEvent) {
         type = WebEvent::MouseMove;
         clickCount = 0;
-    } else if (event->type() == eventNames().clickEvent)
+    } else if (event.type() == eventNames().clickEvent)
         return nullptr;
     else
         ASSERT_NOT_REACHED();
 
     WebMouseEvent::Button button = WebMouseEvent::NoButton;
-    switch (event->button()) {
+    switch (event.button()) {
     case WebCore::LeftButton:
         button = WebMouseEvent::LeftButton;
         break;
@@ -888,26 +888,26 @@ std::unique_ptr<WebEvent> PluginView::createWebEvent(MouseEvent* event) const
     }
 
     unsigned modifiers = 0;
-    if (event->shiftKey())
+    if (event.shiftKey())
         modifiers |= WebEvent::ShiftKey;
-    if (event->ctrlKey())
+    if (event.ctrlKey())
         modifiers |= WebEvent::ControlKey;
-    if (event->altKey())
+    if (event.altKey())
         modifiers |= WebEvent::AltKey;
-    if (event->metaKey())
+    if (event.metaKey())
         modifiers |= WebEvent::MetaKey;
 
-    return std::make_unique<WebMouseEvent>(type, button, m_plugin->convertToRootView(IntPoint(event->offsetX(), event->offsetY())), event->screenLocation(), 0, 0, 0, clickCount, static_cast<WebEvent::Modifiers>(modifiers), 0, 0);
+    return std::make_unique<WebMouseEvent>(type, button, m_plugin->convertToRootView(IntPoint(event.offsetX(), event.offsetY())), event.screenLocation(), 0, 0, 0, clickCount, static_cast<WebEvent::Modifiers>(modifiers), 0, 0);
 }
 
-void PluginView::handleEvent(Event* event)
+void PluginView::handleEvent(Event& event)
 {
     if (!m_isInitialized || !m_plugin)
         return;
 
     const WebEvent* currentEvent = WebPage::currentEvent();
     std::unique_ptr<WebEvent> simulatedWebEvent;
-    if (is<MouseEvent>(*event) && downcast<MouseEvent>(*event).isSimulated()) {
+    if (is<MouseEvent>(event) && downcast<MouseEvent>(event).isSimulated()) {
         simulatedWebEvent = createWebEvent(downcast<MouseEvent>(event));
         currentEvent = simulatedWebEvent.get();
     }
@@ -916,9 +916,9 @@ void PluginView::handleEvent(Event* event)
 
     bool didHandleEvent = false;
 
-    if ((event->type() == eventNames().mousemoveEvent && currentEvent->type() == WebEvent::MouseMove)
-        || (event->type() == eventNames().mousedownEvent && currentEvent->type() == WebEvent::MouseDown)
-        || (event->type() == eventNames().mouseupEvent && currentEvent->type() == WebEvent::MouseUp)) {
+    if ((event.type() == eventNames().mousemoveEvent && currentEvent->type() == WebEvent::MouseMove)
+        || (event.type() == eventNames().mousedownEvent && currentEvent->type() == WebEvent::MouseDown)
+        || (event.type() == eventNames().mouseupEvent && currentEvent->type() == WebEvent::MouseUp)) {
         // FIXME: Clicking in a scroll bar should not change focus.
         if (currentEvent->type() == WebEvent::MouseDown) {
             focusPluginElement();
@@ -927,27 +927,27 @@ void PluginView::handleEvent(Event* event)
             frame()->eventHandler().setCapturingMouseEventsElement(nullptr);
 
         didHandleEvent = m_plugin->handleMouseEvent(static_cast<const WebMouseEvent&>(*currentEvent));
-        if (event->type() != eventNames().mousemoveEvent)
+        if (event.type() != eventNames().mousemoveEvent)
             pluginDidReceiveUserInteraction();
-    } else if (eventNames().isWheelEventType(event->type())
+    } else if (eventNames().isWheelEventType(event.type())
         && currentEvent->type() == WebEvent::Wheel && m_plugin->wantsWheelEvents()) {
         didHandleEvent = m_plugin->handleWheelEvent(static_cast<const WebWheelEvent&>(*currentEvent));
         pluginDidReceiveUserInteraction();
-    } else if (event->type() == eventNames().mouseoverEvent && currentEvent->type() == WebEvent::MouseMove)
+    } else if (event.type() == eventNames().mouseoverEvent && currentEvent->type() == WebEvent::MouseMove)
         didHandleEvent = m_plugin->handleMouseEnterEvent(static_cast<const WebMouseEvent&>(*currentEvent));
-    else if (event->type() == eventNames().mouseoutEvent && currentEvent->type() == WebEvent::MouseMove)
+    else if (event.type() == eventNames().mouseoutEvent && currentEvent->type() == WebEvent::MouseMove)
         didHandleEvent = m_plugin->handleMouseLeaveEvent(static_cast<const WebMouseEvent&>(*currentEvent));
-    else if (event->type() == eventNames().contextmenuEvent && currentEvent->type() == WebEvent::MouseDown) {
+    else if (event.type() == eventNames().contextmenuEvent && currentEvent->type() == WebEvent::MouseDown) {
         didHandleEvent = m_plugin->handleContextMenuEvent(static_cast<const WebMouseEvent&>(*currentEvent));
         pluginDidReceiveUserInteraction();
-    } else if ((event->type() == eventNames().keydownEvent && currentEvent->type() == WebEvent::KeyDown)
-               || (event->type() == eventNames().keyupEvent && currentEvent->type() == WebEvent::KeyUp)) {
+    } else if ((event.type() == eventNames().keydownEvent && currentEvent->type() == WebEvent::KeyDown)
+               || (event.type() == eventNames().keyupEvent && currentEvent->type() == WebEvent::KeyUp)) {
         didHandleEvent = m_plugin->handleKeyboardEvent(static_cast<const WebKeyboardEvent&>(*currentEvent));
         pluginDidReceiveUserInteraction();
     }
 
     if (didHandleEvent)
-        event->setDefaultHandled();
+        event.setDefaultHandled();
 }
     
 bool PluginView::handleEditingCommand(const String& commandName, const String& argument)
index d34748d..04ec132 100644 (file)
@@ -176,7 +176,7 @@ private:
     void setFocus(bool) override;
     void frameRectsChanged() override;
     void setParent(WebCore::ScrollView*) override;
-    void handleEvent(WebCore::Event*) override;
+    void handleEvent(WebCore::Event&) override;
     void notifyWidget(WebCore::WidgetNotification) override;
     void show() override;
     void hide() override;
@@ -238,7 +238,7 @@ private:
     void didFinishLoad(WebFrame*) override;
     void didFailLoad(WebFrame*, bool wasCancelled) override;
 
-    std::unique_ptr<WebEvent> createWebEvent(WebCore::MouseEvent*) const;
+    std::unique_ptr<WebEvent> createWebEvent(WebCore::MouseEvent&) const;
 
     RefPtr<WebCore::HTMLPlugInElement> m_pluginElement;
     RefPtr<Plugin> m_plugin;
index d8284d4..743fcdd 100644 (file)
@@ -1,3 +1,16 @@
+2017-07-21  Andreas Kling  <akling@apple.com>
+
+        Use more references in event dispatch code
+        https://bugs.webkit.org/show_bug.cgi?id=174681
+
+        Reviewed by Geoffrey Garen.
+
+        * DOM/ObjCEventListener.h:
+        * DOM/ObjCEventListener.mm:
+        (WebCore::ObjCEventListener::handleEvent):
+        * WebCoreSupport/WebFrameLoaderClient.mm:
+        (NetscapePluginWidget::handleEvent):
+
 2017-07-21  Brady Eidson  <beidson@apple.com>
 
         Get rid of WebCore IconDatabase code.
index 0697849..631d64f 100644 (file)
@@ -52,7 +52,7 @@ namespace WebCore {
         ObjCEventListener(ObjCListener);
         virtual ~ObjCEventListener();
         virtual bool operator==(const EventListener&) const;
-        virtual void handleEvent(ScriptExecutionContext*, Event*);
+        virtual void handleEvent(ScriptExecutionContext&, Event&);
 
         RetainPtr<ObjCListener> m_listener;
     };
index eead118..40b303c 100644 (file)
@@ -72,10 +72,10 @@ ObjCEventListener::~ObjCEventListener()
     listenerMap->remove(m_listener.get());
 }
 
-void ObjCEventListener::handleEvent(ScriptExecutionContext*, Event* event)
+void ObjCEventListener::handleEvent(ScriptExecutionContext&, Event& event)
 {
     ObjCListener listener = m_listener.get();
-    [listener handleEvent:kit(event)];
+    [listener handleEvent:kit(&event)];
 }
 
 bool ObjCEventListener::operator==(const EventListener& listener) const
index 7783ff4..0ab90e4 100644 (file)
@@ -1842,21 +1842,21 @@ public:
         return false;
     }
 
-    virtual void handleEvent(Event* event)
+    virtual void handleEvent(Event& event)
     {
         Frame* frame = Frame::frameForWidget(*this);
         if (!frame)
             return;
         
         NSEvent* currentNSEvent = frame->eventHandler().currentNSEvent();
-        if (event->type() == eventNames().mousemoveEvent)
+        if (event.type() == eventNames().mousemoveEvent)
             [(WebBaseNetscapePluginView *)platformWidget() handleMouseMoved:currentNSEvent];
-        else if (event->type() == eventNames().mouseoverEvent)
+        else if (event.type() == eventNames().mouseoverEvent)
             [(WebBaseNetscapePluginView *)platformWidget() handleMouseEntered:currentNSEvent];
-        else if (event->type() == eventNames().mouseoutEvent)
+        else if (event.type() == eventNames().mouseoutEvent)
             [(WebBaseNetscapePluginView *)platformWidget() handleMouseExited:currentNSEvent];
-        else if (event->type() == eventNames().contextmenuEvent)
-            event->setDefaultHandled(); // We don't know if the plug-in has handled mousedown event by displaying a context menu, so we never want WebKit to show a default one.
+        else if (event.type() == eventNames().contextmenuEvent)
+            event.setDefaultHandled(); // We don't know if the plug-in has handled mousedown event by displaying a context menu, so we never want WebKit to show a default one.
     }
 
     virtual void clipRectChanged()
index f618e16..d58ba24 100644 (file)
@@ -1,3 +1,17 @@
+2017-07-21  Andreas Kling  <akling@apple.com>
+
+        Use more references in event dispatch code
+        https://bugs.webkit.org/show_bug.cgi?id=174681
+
+        Reviewed by Geoffrey Garen.
+
+        * DOMEventsClasses.cpp:
+        (WebEventListener::handleEvent):
+        * DOMEventsClasses.h:
+        * Plugins/PluginView.cpp:
+        (WebCore::PluginView::handleEvent):
+        * Plugins/PluginView.h:
+
 2017-07-20  Brady Eidson  <beidson@apple.com>
 
         Remove WebIconDatabase from WebKitLegacy/win.
index 052d85c..e5c4571 100644 (file)
@@ -74,9 +74,9 @@ bool WebEventListener::operator==(const WebCore::EventListener& other) const
         && reinterpret_cast<const WebEventListener*>(&other)->m_iDOMEventListener == m_iDOMEventListener);
 }
 
-void WebEventListener::handleEvent(WebCore::ScriptExecutionContext* s, WebCore::Event* e)
+void WebEventListener::handleEvent(WebCore::ScriptExecutionContext& s, WebCore::Event& e)
 {
-    RefPtr<WebCore::Event> ePtr(e);
+    RefPtr<WebCore::Event> ePtr(&e);
     COMPtr<IDOMEvent> domEvent = DOMEvent::createInstance(WTFMove(ePtr));
     m_iDOMEventListener->handleEvent(domEvent.get());
 }
index 3b53b5e..2f77481 100644 (file)
@@ -46,7 +46,7 @@ public:
     WebEventListener(IDOMEventListener*);
     ~WebEventListener();
     virtual bool operator==(const EventListener&) const;
-    virtual void handleEvent(WebCore::ScriptExecutionContext*, WebCore::Event*);
+    virtual void handleEvent(WebCore::ScriptExecutionContext&, WebCore::Event&);
     static Ref<WebEventListener> create(IDOMEventListener*);
 private:
     IDOMEventListener* m_iDOMEventListener;
index ef80dc7..460e78e 100644 (file)
@@ -162,7 +162,7 @@ void PluginView::clipRectChanged()
     updatePluginWidget();
 }
 
-void PluginView::handleEvent(Event* event)
+void PluginView::handleEvent(Event& event)
 {
     if (!m_plugin || m_isWindowed)
         return;
@@ -170,12 +170,12 @@ void PluginView::handleEvent(Event* event)
     // Protect the plug-in from deletion while dispatching the event.
     RefPtr<PluginView> protect(this);
 
-    if (event->isMouseEvent())
-        handleMouseEvent(static_cast<MouseEvent*>(event));
-    else if (event->isKeyboardEvent())
-        handleKeyboardEvent(static_cast<KeyboardEvent*>(event));
-    else if (event->type() == eventNames().contextmenuEvent)
-        event->setDefaultHandled(); // We don't know if the plug-in has handled mousedown event by displaying a context menu, so we never want WebKit to show a default one.
+    if (event.isMouseEvent())
+        handleMouseEvent(downcast<MouseEvent>(event));
+    else if (event.isKeyboardEvent())
+        handleKeyboardEvent(downcast<KeyboardEvent>(event));
+    else if (event.type() == eventNames().contextmenuEvent)
+        event.setDefaultHandled(); // We don't know if the plug-in has handled mousedown event by displaying a context menu, so we never want WebKit to show a default one.
 }
 
 void PluginView::init()
index a7f6f9b..907be35 100644 (file)
@@ -190,7 +190,7 @@ namespace WebCore {
         // This clip includes any clips that the widget itself sets up for its children.
         IntRect windowClipRect() const;
 
-        void handleEvent(Event*) override;
+        void handleEvent(Event&) override;
         void setParent(ScrollView*) override;
         void setParentVisible(bool) override;
 
@@ -291,8 +291,8 @@ namespace WebCore {
         void updatePluginWidget();
         void paintMissingPluginIcon(GraphicsContext&, const IntRect&);
 
-        void handleKeyboardEvent(KeyboardEvent*);
-        void handleMouseEvent(MouseEvent*);
+        void handleKeyboardEvent(KeyboardEvent&);
+        void handleMouseEvent(MouseEvent&);
 
         void paintIntoTransformedContext(HDC);
         RefPtr<Image> snapshot();
index 942875f..8867a8f 100644 (file)
@@ -576,21 +576,21 @@ void PluginView::paint(GraphicsContext& context, const IntRect& rect, Widget::Se
     paintIntoTransformedContext(windowsContext.hdc());
 }
 
-void PluginView::handleKeyboardEvent(KeyboardEvent* event)
+void PluginView::handleKeyboardEvent(KeyboardEvent& event)
 {
     ASSERT(m_plugin && !m_isWindowed);
 
     NPEvent npEvent;
 
-    npEvent.wParam = event->keyCode();
+    npEvent.wParam = event.keyCode();
 
-    if (event->type() == eventNames().keydownEvent) {
+    if (event.type() == eventNames().keydownEvent) {
         npEvent.event = WM_KEYDOWN;
         npEvent.lParam = 0;
-    } else if (event->type() == eventNames().keypressEvent) {
+    } else if (event.type() == eventNames().keypressEvent) {
         npEvent.event = WM_CHAR;
         npEvent.lParam = 0;
-    } else if (event->type() == eventNames().keyupEvent) {
+    } else if (event.type() == eventNames().keyupEvent) {
         npEvent.event = WM_KEYUP;
         npEvent.lParam = 0x8000;
     } else
@@ -598,33 +598,33 @@ void PluginView::handleKeyboardEvent(KeyboardEvent* event)
 
     JSC::JSLock::DropAllLocks dropAllLocks(commonVM());
     if (dispatchNPEvent(npEvent))
-        event->setDefaultHandled();
+        event.setDefaultHandled();
 }
 
 extern bool ignoreNextSetCursor;
 
-void PluginView::handleMouseEvent(MouseEvent* event)
+void PluginView::handleMouseEvent(MouseEvent& event)
 {
     ASSERT(m_plugin && !m_isWindowed);
 
     NPEvent npEvent;
 
-    IntPoint p = contentsToNativeWindow(downcast<FrameView>(parent()), IntPoint(event->pageX(), event->pageY()));
+    IntPoint p = contentsToNativeWindow(downcast<FrameView>(parent()), IntPoint(event.pageX(), event.pageY()));
 
     npEvent.lParam = MAKELPARAM(p.x(), p.y());
     npEvent.wParam = 0;
 
-    if (event->ctrlKey())
+    if (event.ctrlKey())
         npEvent.wParam |= MK_CONTROL;
-    if (event->shiftKey())
+    if (event.shiftKey())
         npEvent.wParam |= MK_SHIFT;
 
-    if (event->type() == eventNames().mousemoveEvent
-        || event->type() == eventNames().mouseoutEvent
-        || event->type() == eventNames().mouseoverEvent) {
+    if (event.type() == eventNames().mousemoveEvent
+        || event.type() == eventNames().mouseoutEvent
+        || event.type() == eventNames().mouseoverEvent) {
         npEvent.event = WM_MOUSEMOVE;
-        if (event->buttonDown())
-            switch (event->button()) {
+        if (event.buttonDown())
+            switch (event.button()) {
             case LeftButton:
                 npEvent.wParam |= MK_LBUTTON;
                 break;
@@ -635,9 +635,9 @@ void PluginView::handleMouseEvent(MouseEvent* event)
                 npEvent.wParam |= MK_RBUTTON;
                 break;
             }
-    } else if (event->type() == eventNames().mousedownEvent) {
+    } else if (event.type() == eventNames().mousedownEvent) {
         focusPluginElement();
-        switch (event->button()) {
+        switch (event.button()) {
         case LeftButton:
             npEvent.event = WM_LBUTTONDOWN;
             break;
@@ -648,8 +648,8 @@ void PluginView::handleMouseEvent(MouseEvent* event)
             npEvent.event = WM_RBUTTONDOWN;
             break;
         }
-    } else if (event->type() == eventNames().mouseupEvent) {
-        switch (event->button()) {
+    } else if (event.type() == eventNames().mouseupEvent) {
+        switch (event.button()) {
         case LeftButton:
             npEvent.event = WM_LBUTTONUP;
             break;
@@ -666,7 +666,7 @@ void PluginView::handleMouseEvent(MouseEvent* event)
     JSC::JSLock::DropAllLocks dropAllLocks(commonVM());
     // FIXME: Consider back porting the http://webkit.org/b/58108 fix here.
     if (dispatchNPEvent(npEvent))
-        event->setDefaultHandled();
+        event.setDefaultHandled();
 
     // Currently, Widget::setCursor is always called after this function in EventHandler.cpp
     // and since we don't want that we set ignoreNextSetCursor to true here to prevent that.