2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
3 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #include "WebDOMEventTarget.h"
24 #include "DOMApplicationCache.h"
25 #include "DOMWindow.h"
26 #include "DedicatedWorkerContext.h"
27 #include "EventSource.h"
28 #include "MessagePort.h"
30 #include "Notification.h"
31 #include "SharedWorker.h"
32 #include "SharedWorkerContext.h"
33 #include "ThreadCheck.h"
34 #include "WebDOMDOMApplicationCache.h"
35 #include "WebDOMDOMWindow.h"
36 #include "WebDOMEventSource.h"
37 #include "WebDOMMessagePort.h"
38 #include "WebDOMNode.h"
39 #include "WebDOMXMLHttpRequest.h"
40 #include "WebDOMXMLHttpRequestUpload.h"
41 #include "WebExceptionHandler.h"
42 #include "WebSocket.h"
44 #include "XMLHttpRequest.h"
45 #include "XMLHttpRequestUpload.h"
47 #include <wtf/RefPtr.h>
50 #include "WebDOMDedicatedWorkerContext.h"
51 #include "WebDOMWorker.h"
54 #if ENABLE(SHARED_WORKERS)
55 #include "WebDOMSharedWorker.h"
56 #include "WebDOMSharedWorkerContext.h"
59 #if ENABLE(NOTIFICATIONS)
60 #include "WebDOMNotification.h"
63 #if ENABLE(WEB_SOCKETS)
64 #include "WebDOMWebSocket.h"
67 struct WebDOMEventTarget::WebDOMEventTargetPrivate {
68 WebDOMEventTargetPrivate(WebCore::EventTarget* object = 0)
73 RefPtr<WebCore::EventTarget> impl;
76 WebDOMEventTarget::WebDOMEventTarget()
82 WebDOMEventTarget::WebDOMEventTarget(WebCore::EventTarget* impl)
84 , m_impl(new WebDOMEventTargetPrivate(impl))
88 WebDOMEventTarget::WebDOMEventTarget(const WebDOMEventTarget& copy)
91 m_impl = copy.impl() ? new WebDOMEventTargetPrivate(copy.impl()) : 0;
94 WebDOMEventTarget::~WebDOMEventTarget()
100 WebCore::EventTarget* WebDOMEventTarget::impl() const
102 return m_impl ? m_impl->impl.get() : 0;
105 #define ConvertTo(type) \
106 WebDOM##type WebDOMEventTarget::to##type() \
108 WebCore::EventTarget* target = impl(); \
109 return WebDOM##type(target ? target->to##type() : 0); \
117 ConvertTo(DedicatedWorkerContext)
120 #if ENABLE(SHARED_WORKERS)
121 ConvertTo(SharedWorker)
122 ConvertTo(SharedWorkerContext)
125 #if ENABLE(NOTIFICATIONS)
126 ConvertTo(Notification)
129 #if ENABLE(WEB_SOCKETS)
133 WebCore::EventTarget* toWebCore(const WebDOMEventTarget& wrapper)
135 return wrapper.impl();
138 WebDOMEventTarget toWebKit(WebCore::EventTarget* value)
140 if (WebCore::Node* node = value->toNode())
141 return toWebKit(node);
143 if (WebCore::DOMWindow* window = value->toDOMWindow())
144 return toWebKit(window);
147 // FIXME: Enable once SVG bindings are generated.
148 // SVGElementInstance supports both toSVGElementInstance and toNode since so much mouse handling code depends on toNode returning a valid node.
149 if (WebCore::SVGElementInstance* instance = value->toSVGElementInstance())
150 return toWebKit(instance);
154 if (WebCore::Worker* worker = value->toWorker())
155 return toWebKit(worker);
157 if (WebCore::DedicatedWorkerContext* workerContext = value->toDedicatedWorkerContext())
158 return toWebKit(workerContext);
161 #if ENABLE(SHARED_WORKERS)
162 if (WebCore::SharedWorker* sharedWorker = value->toSharedWorker())
163 return toWebKit(sharedWorker);
165 if (WebCore::SharedWorkerContext* workerContext = value->toSharedWorkerContext())
166 return toWebKit(workerContext);
169 #if ENABLE(NOTIFICATIONS)
170 if (WebCore::Notification* notification = value->toNotification())
171 return toWebKit(notification);
174 #if ENABLE(WEB_SOCKETS)
175 if (WebCore::WebSocket* webSocket = value->toWebSocket())
176 return toWebKit(webSocket);
179 ASSERT_NOT_REACHED();
180 return WebDOMEventTarget();
183 WebDOMEventTarget& WebDOMEventTarget::operator=(const WebDOMEventTarget& copy)
186 m_impl = copy.impl() ? new WebDOMEventTargetPrivate(copy.impl()) : 0;