Commit f319b265 authored by ap@webkit.org's avatar ap@webkit.org
Browse files

Reviewed by Darin Adler.

        https://bugs.webkit.org/show_bug.cgi?id=21998
        Use JSDOMGlobalObject in EventListener-related bindings

        * dom/MessagePort.idl: Auto-generate bindings for onclose and onmessage.

        * bindings/scripts/CodeGeneratorJS.pm: Use JSDOMGlobalObject instead of JSDOMWindow in JS
        bindings for inline event handlers.

        * bindings/js/JSDOMApplicationCacheCustom.cpp:
        (WebCore::JSDOMApplicationCache::addEventListener):
        (WebCore::JSDOMApplicationCache::removeEventListener):
        * bindings/js/JSEventTargetNodeCustom.cpp:
        (WebCore::JSEventTargetNode::addEventListener):
        (WebCore::JSEventTargetNode::removeEventListener):
        * bindings/js/JSMessagePortCustom.cpp:
        (WebCore::JSMessagePort::removeEventListener):
        * bindings/js/JSSVGElementInstanceCustom.cpp:
        (WebCore::JSSVGElementInstance::addEventListener):
        (WebCore::JSSVGElementInstance::removeEventListener):
        * bindings/js/JSXMLHttpRequestCustom.cpp:
        (WebCore::JSXMLHttpRequest::addEventListener):
        (WebCore::JSXMLHttpRequest::removeEventListener):
        * bindings/js/JSXMLHttpRequestUploadCustom.cpp:
        (WebCore::JSXMLHttpRequestUpload::addEventListener):
        (WebCore::JSXMLHttpRequestUpload::removeEventListener):
        Use ScriptExecutionContext and JSDOMGlobalObject in bindings.

        * dom/EventTarget.h:
        * dom/EventTargetNode.cpp:
        (WebCore::EventTargetNode::scriptExecutionContext):
        * dom/EventTargetNode.h:
        * dom/MessagePort.cpp:
        * dom/MessagePort.h:
        (WebCore::MessagePort::scriptExecutionContext):
        * loader/appcache/DOMApplicationCache.cpp:
        (WebCore::DOMApplicationCache::scriptExecutionContext):
        * loader/appcache/DOMApplicationCache.h:
        * svg/SVGElementInstance.cpp:
        (WebCore::SVGElementInstance::scriptExecutionContext):
        * svg/SVGElementInstance.h:
        * xml/XMLHttpRequest.cpp:
        (WebCore::XMLHttpRequest::scriptExecutionContext):
        * xml/XMLHttpRequest.h:
        * xml/XMLHttpRequestUpload.cpp:
        (WebCore::XMLHttpRequestUpload::scriptExecutionContext):
        * xml/XMLHttpRequestUpload.h:
        Remove associatedFrame() method, and provide scriptExecutionContext() where it wasn't
        available yet.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@38063 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 487c452c
2008-10-31 Alexey Proskuryakov <ap@webkit.org>
Reviewed by Darin Adler.
https://bugs.webkit.org/show_bug.cgi?id=21998
Use JSDOMGlobalObject in EventListener-related bindings
* dom/MessagePort.idl: Auto-generate bindings for onclose and onmessage.
* bindings/scripts/CodeGeneratorJS.pm: Use JSDOMGlobalObject instead of JSDOMWindow in JS
bindings for inline event handlers.
* bindings/js/JSDOMApplicationCacheCustom.cpp:
(WebCore::JSDOMApplicationCache::addEventListener):
(WebCore::JSDOMApplicationCache::removeEventListener):
* bindings/js/JSEventTargetNodeCustom.cpp:
(WebCore::JSEventTargetNode::addEventListener):
(WebCore::JSEventTargetNode::removeEventListener):
* bindings/js/JSMessagePortCustom.cpp:
(WebCore::JSMessagePort::removeEventListener):
* bindings/js/JSSVGElementInstanceCustom.cpp:
(WebCore::JSSVGElementInstance::addEventListener):
(WebCore::JSSVGElementInstance::removeEventListener):
* bindings/js/JSXMLHttpRequestCustom.cpp:
(WebCore::JSXMLHttpRequest::addEventListener):
(WebCore::JSXMLHttpRequest::removeEventListener):
* bindings/js/JSXMLHttpRequestUploadCustom.cpp:
(WebCore::JSXMLHttpRequestUpload::addEventListener):
(WebCore::JSXMLHttpRequestUpload::removeEventListener):
Use ScriptExecutionContext and JSDOMGlobalObject in bindings.
* dom/EventTarget.h:
* dom/EventTargetNode.cpp:
(WebCore::EventTargetNode::scriptExecutionContext):
* dom/EventTargetNode.h:
* dom/MessagePort.cpp:
* dom/MessagePort.h:
(WebCore::MessagePort::scriptExecutionContext):
* loader/appcache/DOMApplicationCache.cpp:
(WebCore::DOMApplicationCache::scriptExecutionContext):
* loader/appcache/DOMApplicationCache.h:
* svg/SVGElementInstance.cpp:
(WebCore::SVGElementInstance::scriptExecutionContext):
* svg/SVGElementInstance.h:
* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::scriptExecutionContext):
* xml/XMLHttpRequest.h:
* xml/XMLHttpRequestUpload.cpp:
(WebCore::XMLHttpRequestUpload::scriptExecutionContext):
* xml/XMLHttpRequestUpload.h:
Remove associatedFrame() method, and provide scriptExecutionContext() where it wasn't
available yet.
2008-10-31 Cameron Zwarich <zwarich@apple.com>
 
Rubber-stamped by Geoff Garen.
......
......@@ -106,10 +106,10 @@ JSValue* JSDOMApplicationCache::remove(ExecState* exec, const ArgList& args)
JSValue* JSDOMApplicationCache::addEventListener(ExecState* exec, const ArgList& args)
{
Frame* frame = impl()->associatedFrame();
if (!frame)
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext());
if (!globalObject)
return jsUndefined();
RefPtr<JSUnprotectedEventListener> listener = toJSDOMWindow(frame)->findOrCreateJSUnprotectedEventListener(exec, args.at(exec, 1));
RefPtr<JSUnprotectedEventListener> listener = globalObject->findOrCreateJSUnprotectedEventListener(exec, args.at(exec, 1));
if (!listener)
return jsUndefined();
impl()->addEventListener(args.at(exec, 0)->toString(exec), listener.release(), args.at(exec, 2)->toBoolean(exec));
......@@ -118,10 +118,10 @@ JSValue* JSDOMApplicationCache::addEventListener(ExecState* exec, const ArgList&
JSValue* JSDOMApplicationCache::removeEventListener(ExecState* exec, const ArgList& args)
{
Frame* frame = impl()->associatedFrame();
if (!frame)
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext());
if (!globalObject)
return jsUndefined();
JSUnprotectedEventListener* listener = toJSDOMWindow(frame)->findJSUnprotectedEventListener(exec, args.at(exec, 1));
JSUnprotectedEventListener* listener = globalObject->findJSUnprotectedEventListener(exec, args.at(exec, 1));
if (!listener)
return jsUndefined();
impl()->removeEventListener(args.at(exec, 0)->toString(exec), listener, args.at(exec, 2)->toBoolean(exec));
......
......@@ -42,11 +42,11 @@ namespace WebCore {
JSValue* JSEventTargetNode::addEventListener(ExecState* exec, const ArgList& args)
{
Frame* frame = impl()->associatedFrame();
if (!frame)
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext());
if (!globalObject)
return jsUndefined();
if (RefPtr<JSEventListener> listener = toJSDOMWindow(frame)->findOrCreateJSEventListener(exec, args.at(exec, 1)))
if (RefPtr<JSEventListener> listener = globalObject->findOrCreateJSEventListener(exec, args.at(exec, 1)))
impl()->addEventListener(args.at(exec, 0)->toString(exec), listener.release(), args.at(exec, 2)->toBoolean(exec));
return jsUndefined();
......@@ -54,11 +54,11 @@ JSValue* JSEventTargetNode::addEventListener(ExecState* exec, const ArgList& arg
JSValue* JSEventTargetNode::removeEventListener(ExecState* exec, const ArgList& args)
{
Frame* frame = impl()->associatedFrame();
if (!frame)
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext());
if (!globalObject)
return jsUndefined();
if (JSEventListener* listener = toJSDOMWindow(frame)->findJSEventListener(args.at(exec, 1)))
if (JSEventListener* listener = globalObject->findJSEventListener(args.at(exec, 1)))
impl()->removeEventListener(args.at(exec, 0)->toString(exec), listener, args.at(exec, 2)->toBoolean(exec));
return jsUndefined();
......
......@@ -95,39 +95,6 @@ JSValue* JSMessagePort::removeEventListener(ExecState* exec, const ArgList& args
return jsUndefined();
impl()->removeEventListener(args.at(exec, 0)->toString(exec), listener, args.at(exec, 2)->toBoolean(exec));
return jsUndefined();
}
void JSMessagePort::setOnmessage(ExecState* exec, JSValue* value)
{
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext());
if (!globalObject)
return;
impl()->setOnmessage(globalObject->findOrCreateJSUnprotectedEventListener(exec, value, true));
}
JSValue* JSMessagePort::onmessage(ExecState*) const
{
if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(impl()->onmessage()))
if (JSObject* listenerObj = listener->listenerObj())
return listenerObj;
return jsNull();
}
void JSMessagePort::setOnclose(ExecState* exec, JSValue* value)
{
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext());
if (!globalObject)
return;
impl()->setOnclose(globalObject->findOrCreateJSUnprotectedEventListener(exec, value, true));
}
JSValue* JSMessagePort::onclose(ExecState*) const
{
if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(impl()->onclose()))
if (JSObject* listenerObj = listener->listenerObj())
return listenerObj;
return jsNull();
}
} // namespace WebCore
......@@ -38,11 +38,11 @@ namespace WebCore {
JSValue* JSSVGElementInstance::addEventListener(ExecState* exec, const ArgList& args)
{
Frame* frame = impl()->associatedFrame();
if (!frame)
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext());
if (!globalObject)
return jsUndefined();
if (RefPtr<JSEventListener> listener = toJSDOMWindow(frame)->findOrCreateJSEventListener(exec, args.at(exec, 1)))
if (RefPtr<JSEventListener> listener = globalObject->findOrCreateJSEventListener(exec, args.at(exec, 1)))
impl()->addEventListener(args.at(exec, 0)->toString(exec), listener.release(), args.at(exec, 2)->toBoolean(exec));
return jsUndefined();
......@@ -50,11 +50,11 @@ JSValue* JSSVGElementInstance::addEventListener(ExecState* exec, const ArgList&
JSValue* JSSVGElementInstance::removeEventListener(ExecState* exec, const ArgList& args)
{
Frame* frame = impl()->associatedFrame();
if (!frame)
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext());
if (!globalObject)
return jsUndefined();
if (JSEventListener* listener = toJSDOMWindow(frame)->findJSEventListener(args.at(exec, 1)))
if (JSEventListener* listener = globalObject->findJSEventListener(args.at(exec, 1)))
impl()->removeEventListener(args.at(exec, 0)->toString(exec), listener, args.at(exec, 2)->toBoolean(exec));
return jsUndefined();
......
......@@ -183,10 +183,10 @@ JSValue* JSXMLHttpRequest::overrideMimeType(ExecState* exec, const ArgList& args
JSValue* JSXMLHttpRequest::addEventListener(ExecState* exec, const ArgList& args)
{
Frame* frame = impl()->associatedFrame();
if (!frame)
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext());
if (!globalObject)
return jsUndefined();
RefPtr<JSUnprotectedEventListener> listener = toJSDOMWindow(frame)->findOrCreateJSUnprotectedEventListener(exec, args.at(exec, 1));
RefPtr<JSUnprotectedEventListener> listener = globalObject->findOrCreateJSUnprotectedEventListener(exec, args.at(exec, 1));
if (!listener)
return jsUndefined();
impl()->addEventListener(args.at(exec, 0)->toString(exec), listener.release(), args.at(exec, 2)->toBoolean(exec));
......@@ -195,10 +195,10 @@ JSValue* JSXMLHttpRequest::addEventListener(ExecState* exec, const ArgList& args
JSValue* JSXMLHttpRequest::removeEventListener(ExecState* exec, const ArgList& args)
{
Frame* frame = impl()->associatedFrame();
if (!frame)
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext());
if (!globalObject)
return jsUndefined();
JSUnprotectedEventListener* listener = toJSDOMWindow(frame)->findJSUnprotectedEventListener(exec, args.at(exec, 1));
JSUnprotectedEventListener* listener = globalObject->findJSUnprotectedEventListener(exec, args.at(exec, 1));
if (!listener)
return jsUndefined();
impl()->removeEventListener(args.at(exec, 0)->toString(exec), listener, args.at(exec, 2)->toBoolean(exec));
......
......@@ -79,10 +79,10 @@ void JSXMLHttpRequestUpload::mark()
JSValue* JSXMLHttpRequestUpload::addEventListener(ExecState* exec, const ArgList& args)
{
Frame* frame = impl()->associatedFrame();
if (!frame)
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext());
if (!globalObject)
return jsUndefined();
RefPtr<JSUnprotectedEventListener> listener = toJSDOMWindow(frame)->findOrCreateJSUnprotectedEventListener(exec, args.at(exec, 1));
RefPtr<JSUnprotectedEventListener> listener = globalObject->findOrCreateJSUnprotectedEventListener(exec, args.at(exec, 1));
if (!listener)
return jsUndefined();
impl()->addEventListener(args.at(exec, 0)->toString(exec), listener.release(), args.at(exec, 2)->toBoolean(exec));
......@@ -91,10 +91,10 @@ JSValue* JSXMLHttpRequestUpload::addEventListener(ExecState* exec, const ArgList
JSValue* JSXMLHttpRequestUpload::removeEventListener(ExecState* exec, const ArgList& args)
{
Frame* frame = impl()->associatedFrame();
if (!frame)
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext());
if (!globalObject)
return jsUndefined();
JSUnprotectedEventListener* listener = toJSDOMWindow(frame)->findJSUnprotectedEventListener(exec, args.at(exec, 1));
JSUnprotectedEventListener* listener = globalObject->findJSUnprotectedEventListener(exec, args.at(exec, 1));
if (!listener)
return jsUndefined();
impl()->removeEventListener(args.at(exec, 0)->toString(exec), listener, args.at(exec, 2)->toBoolean(exec));
......
......@@ -1211,16 +1211,15 @@ sub GenerateImplementation
$listenerType = "JSUnprotectedEventListener";
}
if ($interfaceName eq "DOMWindow") {
push(@implContent, " JSDOMWindow* window = static_cast<JSDOMWindow*>(thisObject);\n");
push(@implContent, " JSDOMGlobalObject* globalObject = static_cast<JSDOMWindow*>(thisObject);\n");
} else {
$implIncludes{"Frame.h"} = 1;
$implIncludes{"JSDOMWindow.h"} = 1;
push(@implContent, " Frame* frame = imp->associatedFrame();\n");
push(@implContent, " if (!frame)\n");
$implIncludes{"JSDOMGlobalObject.h"} = 1;
push(@implContent, " JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(imp->scriptExecutionContext());\n");
push(@implContent, " if (!globalObject)\n");
push(@implContent, " return;\n");
push(@implContent, " JSDOMWindow* window = toJSDOMWindow(frame);\n");
}
push(@implContent, " imp->set$implSetterFunctionName(window->findOrCreate${listenerType}(exec, value, true));\n");
push(@implContent, " imp->set$implSetterFunctionName(globalObject->findOrCreate${listenerType}(exec, value, true));\n");
} elsif ($attribute->signature->type =~ /Constructor$/) {
my $constructorType = $attribute->signature->type;
$constructorType =~ s/Constructor$//;
......
......@@ -41,9 +41,9 @@ namespace WebCore {
class Event;
class EventListener;
class EventTargetNode;
class Frame;
class MessagePort;
class RegisteredEventListener;
class ScriptExecutionContext;
class SVGElementInstance;
class XMLHttpRequest;
class XMLHttpRequestUpload;
......@@ -66,7 +66,7 @@ namespace WebCore {
virtual SVGElementInstance* toSVGElementInstance();
#endif
virtual Frame* associatedFrame() const = 0;
virtual ScriptExecutionContext* scriptExecutionContext() const = 0;
virtual void addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture) = 0;
virtual void removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture) = 0;
......
......@@ -77,9 +77,9 @@ EventTargetNode::~EventTargetNode()
m_regdListeners = 0;
}
Frame* EventTargetNode::associatedFrame() const
ScriptExecutionContext* EventTargetNode::scriptExecutionContext() const
{
return document()->frame();
return document();
}
void EventTargetNode::insertedIntoDocument()
......
......@@ -41,7 +41,7 @@ public:
virtual bool isEventTargetNode() const { return true; }
virtual EventTargetNode* toNode() { return this; }
Frame* associatedFrame() const;
virtual ScriptExecutionContext* scriptExecutionContext() const;
virtual void addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
virtual void removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
......
......@@ -81,13 +81,6 @@ MessagePort::~MessagePort()
m_scriptExecutionContext->destroyedMessagePort(this);
}
Frame* MessagePort::associatedFrame() const
{
if (!m_scriptExecutionContext || !m_scriptExecutionContext->isDocument())
return 0;
return static_cast<Document*>(m_scriptExecutionContext)->frame();
}
PassRefPtr<MessagePort> MessagePort::clone(ScriptExecutionContext* newOwner, ExceptionCode& ec)
{
if (!m_entangledPort) {
......
......@@ -67,12 +67,10 @@ namespace WebCore {
void unentangle();
void contextDestroyed();
ScriptExecutionContext* scriptExecutionContext() { return m_scriptExecutionContext; }
virtual ScriptExecutionContext* scriptExecutionContext() const { return m_scriptExecutionContext; }
virtual MessagePort* toMessagePort() { return this; }
virtual Frame* associatedFrame() const;
void queueCloseEvent();
void dispatchMessages();
......
......@@ -42,8 +42,8 @@ module events {
void close();
// event handler attributes
attribute [Custom] EventListener onmessage;
attribute [Custom] EventListener onclose;
attribute EventListener onmessage;
attribute EventListener onclose;
// EventTarget interface
[Custom] void addEventListener(in DOMString type,
......
......@@ -175,7 +175,12 @@ void DOMApplicationCache::remove(const KURL& url, ExceptionCode& ec)
cache->removeDynamicEntry(url);
}
ScriptExecutionContext* DOMApplicationCache::scriptExecutionContext() const
{
return m_frame->document();
}
void DOMApplicationCache::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> eventListener, bool)
{
EventListenersMap::iterator iter = m_eventListeners.find(eventType.impl());
......
......@@ -99,7 +99,7 @@ public:
void setOncached(PassRefPtr<EventListener> eventListener) { m_onCachedListener = eventListener; }
EventListener* oncached() const { return m_onCachedListener.get(); }
Frame* associatedFrame() const { return m_frame; }
virtual ScriptExecutionContext* scriptExecutionContext() const;
DOMApplicationCache* toDOMApplicationCache() { return this; }
void callCheckingListener();
......
......@@ -130,10 +130,10 @@ void SVGElementInstance::setNeedsUpdate(bool value)
correspondingUseElement()->setChanged();
}
Frame* SVGElementInstance::associatedFrame() const
ScriptExecutionContext* SVGElementInstance::scriptExecutionContext() const
{
if (SVGElement* element = correspondingElement())
return element->associatedFrame();
return element->scriptExecutionContext();
return 0;
}
......
......@@ -53,7 +53,7 @@ namespace WebCore {
bool needsUpdate() const { return m_needsUpdate; }
void setNeedsUpdate(bool);
virtual Frame* associatedFrame() const;
virtual ScriptExecutionContext* scriptExecutionContext() const;
virtual EventTargetNode* toNode() { return shadowTreeElement(); }
virtual SVGElementInstance* toSVGElementInstance() { return this; }
......
......@@ -195,13 +195,6 @@ Document* XMLHttpRequest::document() const
return static_cast<Document*>(scriptExecutionContext());
}
Frame* XMLHttpRequest::associatedFrame() const
{
if (!document())
return 0;
return document()->frame();
}
XMLHttpRequest::State XMLHttpRequest::readyState() const
{
return m_state;
......@@ -1318,4 +1311,9 @@ void XMLHttpRequest::contextDestroyed()
internalAbort();
}
ScriptExecutionContext* XMLHttpRequest::scriptExecutionContext() const
{
return ActiveDOMObject::scriptExecutionContext();
}
} // namespace WebCore
......@@ -50,11 +50,11 @@ public:
virtual XMLHttpRequest* toXMLHttpRequest() { return this; }
Frame* associatedFrame() const;
virtual void contextDestroyed();
virtual void stop();
virtual ScriptExecutionContext* scriptExecutionContext() const;
String statusText(ExceptionCode&) const;
int status(ExceptionCode&) const;
State readyState() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment