summaryrefslogtreecommitdiffstats
path: root/WebCore/bindings/cpp
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-06-15 19:36:43 +0100
committerBen Murdoch <benm@google.com>2010-06-16 14:52:28 +0100
commit545e470e52f0ac6a3a072bf559c796b42c6066b6 (patch)
treec0c14763654d84d37577dde512c3d3b4699a9e86 /WebCore/bindings/cpp
parent719298a66237d38ea5c05f1547123ad8aacbc237 (diff)
downloadexternal_webkit-545e470e52f0ac6a3a072bf559c796b42c6066b6.zip
external_webkit-545e470e52f0ac6a3a072bf559c796b42c6066b6.tar.gz
external_webkit-545e470e52f0ac6a3a072bf559c796b42c6066b6.tar.bz2
Merge webkit.org at r61121: Initial merge by git.
Change-Id: Icd6db395c62285be384d137164d95d7466c98760
Diffstat (limited to 'WebCore/bindings/cpp')
-rw-r--r--WebCore/bindings/cpp/WebDOMCString.cpp113
-rw-r--r--WebCore/bindings/cpp/WebDOMCString.h89
-rw-r--r--WebCore/bindings/cpp/WebDOMEventListenerCustom.cpp39
-rw-r--r--WebCore/bindings/cpp/WebDOMEventTarget.cpp155
-rw-r--r--WebCore/bindings/cpp/WebDOMEventTarget.h49
-rw-r--r--WebCore/bindings/cpp/WebDOMHTMLDocumentCustom.cpp50
-rw-r--r--WebCore/bindings/cpp/WebDOMNodeCustom.cpp96
-rw-r--r--WebCore/bindings/cpp/WebDOMObject.h32
-rw-r--r--WebCore/bindings/cpp/WebDOMString.cpp124
-rw-r--r--WebCore/bindings/cpp/WebDOMString.h99
-rw-r--r--WebCore/bindings/cpp/WebExceptionHandler.cpp41
-rw-r--r--WebCore/bindings/cpp/WebExceptionHandler.h40
-rw-r--r--WebCore/bindings/cpp/WebNativeEventListener.cpp53
-rw-r--r--WebCore/bindings/cpp/WebNativeEventListener.h54
14 files changed, 1034 insertions, 0 deletions
diff --git a/WebCore/bindings/cpp/WebDOMCString.cpp b/WebCore/bindings/cpp/WebDOMCString.cpp
new file mode 100644
index 0000000..ab87ac8
--- /dev/null
+++ b/WebCore/bindings/cpp/WebDOMCString.cpp
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebDOMCString.h"
+
+#include "TextEncoding.h"
+#include "WebDOMString.h"
+#include <wtf/text/CString.h>
+
+class WebDOMCStringPrivate : public WTF::CStringBuffer {
+};
+
+void WebDOMCString::reset()
+{
+ if (m_private) {
+ m_private->deref();
+ m_private = 0;
+ }
+}
+
+void WebDOMCString::assign(const WebDOMCString& other)
+{
+ assign(const_cast<WebDOMCStringPrivate*>(other.m_private));
+}
+
+void WebDOMCString::assign(const char* data, size_t length)
+{
+ char* newData;
+ RefPtr<WTF::CStringBuffer> buffer =
+ WTF::CString::newUninitialized(length, newData).buffer();
+ memcpy(newData, data, length);
+ assign(static_cast<WebDOMCStringPrivate*>(buffer.get()));
+}
+
+size_t WebDOMCString::length() const
+{
+ if (!m_private)
+ return 0;
+ // NOTE: The buffer's length includes the null byte.
+ return const_cast<WebDOMCStringPrivate*>(m_private)->length() - 1;
+}
+
+const char* WebDOMCString::data() const
+{
+ if (!m_private)
+ return 0;
+ return const_cast<WebDOMCStringPrivate*>(m_private)->data();
+}
+
+WebDOMString WebDOMCString::utf16() const
+{
+ return WebCore::UTF8Encoding().decode(data(), length());
+}
+
+WebDOMCString WebDOMCString::fromUTF16(const WebUChar* data, size_t length)
+{
+ return WebCore::UTF8Encoding().encode(
+ data, length, WebCore::QuestionMarksForUnencodables);
+}
+
+WebDOMCString WebDOMCString::fromUTF16(const WebUChar* data)
+{
+ size_t len = 0;
+ while (data[len] != WebUChar(0))
+ len++;
+ return fromUTF16(data, len);
+}
+
+WebDOMCString::WebDOMCString(const WTF::CString& s)
+ : m_private(static_cast<WebDOMCStringPrivate*>(s.buffer()))
+{
+ if (m_private)
+ m_private->ref();
+}
+
+WebDOMCString& WebDOMCString::operator=(const WTF::CString& s)
+{
+ assign(static_cast<WebDOMCStringPrivate*>(s.buffer()));
+ return *this;
+}
+
+WebDOMCString::operator WTF::CString() const
+{
+ return m_private;
+}
+
+void WebDOMCString::assign(WebDOMCStringPrivate* p)
+{
+ // Take care to handle the case where m_private == p
+ if (p)
+ p->ref();
+ if (m_private)
+ m_private->deref();
+ m_private = p;
+}
diff --git a/WebCore/bindings/cpp/WebDOMCString.h b/WebCore/bindings/cpp/WebDOMCString.h
new file mode 100644
index 0000000..e02a587
--- /dev/null
+++ b/WebCore/bindings/cpp/WebDOMCString.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WebDOMCString_h
+#define WebDOMCString_h
+
+#include <WebDOMObject.h>
+#include <stddef.h> // For size_t
+
+namespace WTF {
+class CString;
+};
+
+// UTF-16 character type
+#if defined(WIN32)
+typedef wchar_t WebUChar;
+#else
+typedef unsigned short WebUChar;
+#endif
+
+class WebDOMCStringPrivate;
+class WebDOMString;
+
+// A single-byte string container with unspecified encoding. It is
+// inexpensive to copy a WebDOMCString object.
+//
+// WARNING: It is not safe to pass a WebDOMCString across threads!!!
+//
+class WebDOMCString {
+public:
+ ~WebDOMCString() { reset(); }
+
+ WebDOMCString() : m_private(0) { }
+
+ WebDOMCString(const char* data, size_t len) : m_private(0)
+ {
+ assign(data, len);
+ }
+
+ WebDOMCString(const WebDOMCString& s) : m_private(0) { assign(s); }
+
+ WebDOMCString& operator=(const WebDOMCString& s)
+ {
+ assign(s);
+ return *this;
+ }
+
+ void reset();
+ void assign(const WebDOMCString&);
+ void assign(const char* data, size_t len);
+
+ size_t length() const;
+ const char* data() const;
+
+ bool isEmpty() const { return !length(); }
+ bool isNull() const { return !m_private; }
+
+ WebDOMString utf16() const;
+
+ static WebDOMCString fromUTF16(const WebUChar* data, size_t length);
+ static WebDOMCString fromUTF16(const WebUChar* data);
+
+ WebDOMCString(const WTF::CString&);
+ WebDOMCString& operator=(const WTF::CString&);
+ operator WTF::CString() const;
+
+private:
+ void assign(WebDOMCStringPrivate*);
+ WebDOMCStringPrivate* m_private;
+};
+
+#endif
diff --git a/WebCore/bindings/cpp/WebDOMEventListenerCustom.cpp b/WebCore/bindings/cpp/WebDOMEventListenerCustom.cpp
new file mode 100644
index 0000000..db31b71
--- /dev/null
+++ b/WebCore/bindings/cpp/WebDOMEventListenerCustom.cpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebDOMEventListener.h"
+
+#include "WebDOMEvent.h"
+#include "WebNativeEventListener.h"
+#include <wtf/RefPtr.h>
+
+void WebDOMEventListener::handleEvent(const WebDOMEvent& evt)
+{
+ if (!impl())
+ return;
+
+ impl()->handleEvent(0, toWebCore(evt));
+}
+
+WebDOMEventListener toWebKit(WebUserEventListener* value)
+{
+ RefPtr<WebNativeEventListener> listener = WebNativeEventListener::create(value);
+ return WebDOMEventListener(listener.get());
+}
diff --git a/WebCore/bindings/cpp/WebDOMEventTarget.cpp b/WebCore/bindings/cpp/WebDOMEventTarget.cpp
new file mode 100644
index 0000000..2eaef00
--- /dev/null
+++ b/WebCore/bindings/cpp/WebDOMEventTarget.cpp
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebDOMEventTarget.h"
+
+#include "DOMApplicationCache.h"
+#include "DedicatedWorkerContext.h"
+#include "EventSource.h"
+#include "MessagePort.h"
+#include "Node.h"
+#include "Notification.h"
+#include "SharedWorker.h"
+#include "SharedWorkerContext.h"
+#include "ThreadCheck.h"
+#include "WebDOMDOMApplicationCache.h"
+#include "WebDOMDedicatedWorkerContext.h"
+#include "WebDOMEventSource.h"
+#include "WebDOMMessagePort.h"
+#include "WebDOMNode.h"
+#include "WebDOMNotification.h"
+#include "WebDOMSharedWorker.h"
+#include "WebDOMSharedWorkerContext.h"
+#include "WebDOMWebSocket.h"
+#include "WebDOMWorker.h"
+#include "WebDOMXMLHttpRequest.h"
+#include "WebDOMXMLHttpRequestUpload.h"
+#include "WebExceptionHandler.h"
+#include "WebSocket.h"
+#include "Worker.h"
+#include "XMLHttpRequest.h"
+#include "XMLHttpRequestUpload.h"
+
+#include <wtf/RefPtr.h>
+
+struct WebDOMEventTarget::WebDOMEventTargetPrivate {
+ WebDOMEventTargetPrivate(WebCore::EventTarget* object = 0)
+ : impl(object)
+ {
+ }
+
+ RefPtr<WebCore::EventTarget> impl;
+};
+
+WebDOMEventTarget::WebDOMEventTarget()
+ : WebDOMObject()
+ , m_impl(0)
+{
+}
+
+WebDOMEventTarget::WebDOMEventTarget(WebCore::EventTarget* impl)
+ : WebDOMObject()
+ , m_impl(new WebDOMEventTargetPrivate(impl))
+{
+}
+
+WebDOMEventTarget::WebDOMEventTarget(const WebDOMEventTarget& copy)
+ : WebDOMObject()
+{
+ m_impl = copy.impl() ? new WebDOMEventTargetPrivate(copy.impl()) : 0;
+}
+
+WebDOMEventTarget::~WebDOMEventTarget()
+{
+ delete m_impl;
+ m_impl = 0;
+}
+
+WebCore::EventTarget* WebDOMEventTarget::impl() const
+{
+ return m_impl ? m_impl->impl.get() : 0;
+}
+
+WebCore::EventTarget* toWebCore(const WebDOMEventTarget& wrapper)
+{
+ return wrapper.impl();
+}
+
+WebDOMEventTarget toWebKit(WebCore::EventTarget* value)
+{
+#if ENABLE(EVENTSOURCE)
+ if (WebCore::EventSource* eventSource = value->toEventSource())
+ return toWebKit(eventSource);
+#endif
+
+#if ENABLE(SVG) && 0
+ // FIXME: Enable once SVG bindings are generated.
+ // SVGElementInstance supports both toSVGElementInstance and toNode since so much mouse handling code depends on toNode returning a valid node.
+ if (WebCore::SVGElementInstance* instance = value->toSVGElementInstance())
+ return toWebKit(instance);
+#endif
+
+ if (WebCore::Node* node = value->toNode())
+ return toWebKit(node);
+
+ if (WebCore::XMLHttpRequest* xhr = value->toXMLHttpRequest())
+ return toWebKit(xhr);
+
+ if (WebCore::XMLHttpRequestUpload* upload = value->toXMLHttpRequestUpload())
+ return toWebKit(upload);
+
+#if ENABLE(OFFLINE_WEB_APPLICATIONS)
+ if (WebCore::DOMApplicationCache* cache = value->toDOMApplicationCache())
+ return toWebKit(cache);
+#endif
+
+ if (WebCore::MessagePort* messagePort = value->toMessagePort())
+ return toWebKit(messagePort);
+
+#if ENABLE(WORKERS)
+ if (WebCore::Worker* worker = value->toWorker())
+ return toWebKit(worker);
+
+ if (WebCore::DedicatedWorkerContext* workerContext = value->toDedicatedWorkerContext())
+ return toWebKit(workerContext);
+#endif
+
+#if ENABLE(SHARED_WORKERS)
+ if (WebCore::SharedWorker* sharedWorker = value->toSharedWorker())
+ return toWebKit(sharedWorker);
+
+ if (WebCore::SharedWorkerContext* workerContext = value->toSharedWorkerContext())
+ return toWebKit(workerContext);
+#endif
+
+#if ENABLE(NOTIFICATIONS)
+ if (WebCore::Notification* notification = value->toNotification())
+ return toWebKit(notification);
+#endif
+
+#if ENABLE(WEB_SOCKETS)
+ if (WebCore::WebSocket* webSocket = value->toWebSocket())
+ return toWebKit(webSocket);
+#endif
+
+ ASSERT_NOT_REACHED();
+ return WebDOMEventTarget();
+}
diff --git a/WebCore/bindings/cpp/WebDOMEventTarget.h b/WebCore/bindings/cpp/WebDOMEventTarget.h
new file mode 100644
index 0000000..f5360ca
--- /dev/null
+++ b/WebCore/bindings/cpp/WebDOMEventTarget.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WebDOMEventTarget_h
+#define WebDOMEventTarget_h
+
+#include <WebDOMObject.h>
+
+namespace WebCore {
+class EventTarget;
+};
+
+class WebDOMEventTarget : public WebDOMObject {
+public:
+ WebDOMEventTarget();
+ explicit WebDOMEventTarget(WebCore::EventTarget*);
+ WebDOMEventTarget(const WebDOMEventTarget&);
+ ~WebDOMEventTarget();
+
+ WebCore::EventTarget* impl() const;
+
+ // FIXME: Add a possibility to check what kind of EventTarget we have,
+ // to be able to cast eg. a WebDOMEventTarget to a WebDOMNode
+
+protected:
+ struct WebDOMEventTargetPrivate;
+ WebDOMEventTargetPrivate* m_impl;
+};
+
+WebCore::EventTarget* toWebCore(const WebDOMEventTarget&);
+WebDOMEventTarget toWebKit(WebCore::EventTarget*);
+
+#endif
diff --git a/WebCore/bindings/cpp/WebDOMHTMLDocumentCustom.cpp b/WebCore/bindings/cpp/WebDOMHTMLDocumentCustom.cpp
new file mode 100644
index 0000000..aa511ad
--- /dev/null
+++ b/WebCore/bindings/cpp/WebDOMHTMLDocumentCustom.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebDOMHTMLDocument.h"
+
+#include "CharacterNames.h"
+#include "HTMLDocument.h"
+#include "SegmentedString.h"
+#include "WebExceptionHandler.h"
+
+static inline void documentWrite(const WebDOMString& text, WebCore::HTMLDocument* document, bool addNewline)
+{
+ WebCore::SegmentedString segmentedString = WebCore::String(text);
+ if (addNewline)
+ segmentedString.append(WebCore::SegmentedString(&WebCore::newlineCharacter, 1));
+ document->write(segmentedString);
+}
+
+void WebDOMHTMLDocument::write(const WebDOMString& text)
+{
+ if (!impl())
+ return;
+
+ documentWrite(text, impl(), false);
+}
+
+void WebDOMHTMLDocument::writeln(const WebDOMString& text)
+{
+ if (!impl())
+ return;
+
+ documentWrite(text, impl(), true);
+}
diff --git a/WebCore/bindings/cpp/WebDOMNodeCustom.cpp b/WebCore/bindings/cpp/WebDOMNodeCustom.cpp
new file mode 100644
index 0000000..41abb0c
--- /dev/null
+++ b/WebCore/bindings/cpp/WebDOMNodeCustom.cpp
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebDOMNode.h"
+
+#include "Node.h"
+#include "WebDOMEventListener.h"
+#include "WebExceptionHandler.h"
+#include "WebNativeEventListener.h"
+
+WebDOMNode WebDOMNode::insertBefore(const WebDOMNode& newChild, const WebDOMNode& refChild)
+{
+ if (!impl())
+ return WebDOMNode();
+
+ WebCore::ExceptionCode ec = 0;
+ if (impl()->insertBefore(toWebCore(newChild), toWebCore(refChild), ec, true))
+ return newChild;
+
+ webDOMRaiseError(static_cast<WebDOMExceptionCode>(ec));
+ return WebDOMNode();
+}
+
+WebDOMNode WebDOMNode::replaceChild(const WebDOMNode& newChild, const WebDOMNode& oldChild)
+{
+ if (!impl())
+ return WebDOMNode();
+
+ WebCore::ExceptionCode ec = 0;
+ if (impl()->replaceChild(toWebCore(newChild), toWebCore(oldChild), ec, true))
+ return oldChild;
+
+ webDOMRaiseError(static_cast<WebDOMExceptionCode>(ec));
+ return WebDOMNode();
+}
+
+WebDOMNode WebDOMNode::removeChild(const WebDOMNode& oldChild)
+{
+ if (!impl())
+ return WebDOMNode();
+
+ WebCore::ExceptionCode ec = 0;
+ if (impl()->removeChild(toWebCore(oldChild), ec))
+ return oldChild;
+
+ webDOMRaiseError(static_cast<WebDOMExceptionCode>(ec));
+ return WebDOMNode();
+}
+
+WebDOMNode WebDOMNode::appendChild(const WebDOMNode& newChild)
+{
+ if (!impl())
+ return WebDOMNode();
+
+ WebCore::ExceptionCode ec = 0;
+ if (impl()->appendChild(toWebCore(newChild), ec, true))
+ return newChild;
+
+ webDOMRaiseError(static_cast<WebDOMExceptionCode>(ec));
+ return WebDOMNode();
+}
+
+void WebDOMNode::addEventListener(const WebDOMString& type, const WebDOMEventListener& listener, bool useCapture)
+{
+ if (!impl())
+ return;
+
+ if (toWebCore(listener))
+ impl()->addEventListener(type, toWebCore(listener), useCapture);
+}
+
+void WebDOMNode::removeEventListener(const WebDOMString& type, const WebDOMEventListener& listener, bool useCapture)
+{
+ if (!impl())
+ return;
+
+ if (toWebCore(listener))
+ impl()->removeEventListener(type, toWebCore(listener), useCapture);
+}
diff --git a/WebCore/bindings/cpp/WebDOMObject.h b/WebCore/bindings/cpp/WebDOMObject.h
new file mode 100644
index 0000000..4d1830b
--- /dev/null
+++ b/WebCore/bindings/cpp/WebDOMObject.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WebDOMObject_h
+#define WebDOMObject_h
+
+class WebDOMObject {
+protected:
+ WebDOMObject() { }
+ ~WebDOMObject() { }
+};
+
+// Looks akward, though we prefix all classes with WebDOM
+typedef unsigned long long WebDOMDOMTimeStamp;
+
+#endif
diff --git a/WebCore/bindings/cpp/WebDOMString.cpp b/WebCore/bindings/cpp/WebDOMString.cpp
new file mode 100644
index 0000000..d87dedd
--- /dev/null
+++ b/WebCore/bindings/cpp/WebDOMString.cpp
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebDOMString.h"
+
+#include "WebDOMCString.h"
+#include <wtf/text/AtomicString.h>
+#include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
+
+class WebDOMStringPrivate : public WebCore::StringImpl {
+};
+
+void WebDOMString::reset()
+{
+ if (m_private) {
+ m_private->deref();
+ m_private = 0;
+ }
+}
+
+void WebDOMString::assign(const WebDOMString& other)
+{
+ assign(const_cast<WebDOMStringPrivate*>(other.m_private));
+}
+
+void WebDOMString::assign(const WebUChar* data, size_t length)
+{
+ assign(static_cast<WebDOMStringPrivate*>(
+ WebCore::StringImpl::create(data, length).get()));
+}
+
+size_t WebDOMString::length() const
+{
+ return m_private ? const_cast<WebDOMStringPrivate*>(m_private)->length() : 0;
+}
+
+const WebUChar* WebDOMString::data() const
+{
+ return m_private ? const_cast<WebDOMStringPrivate*>(m_private)->characters() : 0;
+}
+
+WebDOMCString WebDOMString::utf8() const
+{
+ return WebCore::String(m_private).utf8();
+}
+
+WebDOMString WebDOMString::fromUTF8(const char* data, size_t length)
+{
+ return WebCore::String::fromUTF8(data, length);
+}
+
+WebDOMString WebDOMString::fromUTF8(const char* data)
+{
+ return WebCore::String::fromUTF8(data);
+}
+
+WebDOMString::WebDOMString(const WebCore::String& s)
+ : m_private(static_cast<WebDOMStringPrivate*>(s.impl()))
+{
+ if (m_private)
+ m_private->ref();
+}
+
+WebDOMString& WebDOMString::operator=(const WebCore::String& s)
+{
+ assign(static_cast<WebDOMStringPrivate*>(s.impl()));
+ return *this;
+}
+
+WebDOMString::operator WebCore::String() const
+{
+ return m_private;
+}
+
+WebDOMString::WebDOMString(const WebCore::AtomicString& s)
+ : m_private(0)
+{
+ assign(s.string());
+}
+
+WebDOMString& WebDOMString::operator=(const WebCore::AtomicString& s)
+{
+ assign(s.string());
+ return *this;
+}
+
+WebDOMString::operator WebCore::AtomicString() const
+{
+ return WebCore::AtomicString(static_cast<WebCore::StringImpl *>(m_private));
+}
+
+bool WebDOMString::equals(const char* string) const
+{
+ return WebCore::equal(m_private, string);
+}
+
+void WebDOMString::assign(WebDOMStringPrivate* p)
+{
+ // Take care to handle the case where m_private == p
+ if (p)
+ p->ref();
+ if (m_private)
+ m_private->deref();
+ m_private = p;
+}
diff --git a/WebCore/bindings/cpp/WebDOMString.h b/WebCore/bindings/cpp/WebDOMString.h
new file mode 100644
index 0000000..ca09ee8
--- /dev/null
+++ b/WebCore/bindings/cpp/WebDOMString.h
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WebDOMString_h
+#define WebDOMString_h
+
+#include <WebDOMCString.h>
+
+namespace WebCore {
+class String;
+class AtomicString;
+}
+
+class WebDOMStringPrivate;
+
+// A UTF-16 string container. It is inexpensive to copy a WebDOMString
+// object.
+//
+// WARNING: It is not safe to pass a WebDOMString across threads!!!
+//
+class WebDOMString {
+public:
+ ~WebDOMString() { reset(); }
+
+ WebDOMString() : m_private(0) { }
+
+ WebDOMString(const WebUChar* data, size_t len) : m_private(0)
+ {
+ assign(data, len);
+ }
+
+ WebDOMString(const WebDOMString& s) : m_private(0) { assign(s); }
+
+ WebDOMString& operator=(const WebDOMString& s)
+ {
+ assign(s);
+ return *this;
+ }
+
+ void reset();
+ void assign(const WebDOMString&);
+ void assign(const WebUChar* data, size_t len);
+
+ size_t length() const;
+ const WebUChar* data() const;
+
+ bool isEmpty() const { return !length(); }
+ bool isNull() const { return !m_private; }
+
+ WebDOMCString utf8() const;
+
+ static WebDOMString fromUTF8(const char* data, size_t length);
+ static WebDOMString fromUTF8(const char* data);
+
+ template <int N> WebDOMString(const char (&data)[N])
+ : m_private(0)
+ {
+ assign(fromUTF8(data, N - 1));
+ }
+
+ template <int N> WebDOMString& operator=(const char (&data)[N])
+ {
+ assign(fromUTF8(data, N - 1));
+ return *this;
+ }
+
+ WebDOMString(const WebCore::String&);
+ WebDOMString& operator=(const WebCore::String&);
+ operator WebCore::String() const;
+
+ WebDOMString(const WebCore::AtomicString&);
+ WebDOMString& operator=(const WebCore::AtomicString&);
+ operator WebCore::AtomicString() const;
+
+ bool equals(const char* string) const;
+
+private:
+ void assign(WebDOMStringPrivate*);
+ WebDOMStringPrivate* m_private;
+};
+
+#endif
diff --git a/WebCore/bindings/cpp/WebExceptionHandler.cpp b/WebCore/bindings/cpp/WebExceptionHandler.cpp
new file mode 100644
index 0000000..f285525
--- /dev/null
+++ b/WebCore/bindings/cpp/WebExceptionHandler.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebExceptionHandler.h"
+
+// To avoid a global static symbol, we declare it in a function
+static inline WebExceptionHandler& globalExceptionHandler()
+{
+ static WebExceptionHandler s_globalExceptionHandler;
+ return s_globalExceptionHandler;
+}
+
+void webInstallExceptionHandler(WebExceptionHandler handler)
+{
+ ASSERT(handler);
+ globalExceptionHandler() = handler;
+}
+
+void webRaiseDOMException(WebDOMExceptionCode ec)
+{
+ ASSERT(ec);
+ if (WebExceptionHandler& handler = globalExceptionHandler())
+ (*handler)(ec);
+}
diff --git a/WebCore/bindings/cpp/WebExceptionHandler.h b/WebCore/bindings/cpp/WebExceptionHandler.h
new file mode 100644
index 0000000..e679254
--- /dev/null
+++ b/WebCore/bindings/cpp/WebExceptionHandler.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WebExceptionHandler_h
+#define WebExceptionHandler_h
+
+typedef int WebDOMExceptionCode;
+typedef void (*WebExceptionHandler)(WebDOMExceptionCode);
+
+// Used from the outside to register a callback that gets fired whenever an exception is raised
+void webInstallExceptionHandler(WebExceptionHandler);
+
+// Never used by the bindings, only indirectly by webDOMRaiseError
+void webRaiseDOMException(WebDOMExceptionCode);
+
+// Used from the bindings
+inline void webDOMRaiseError(WebDOMExceptionCode ec)
+{
+ if (ec)
+ webRaiseDOMException(ec);
+}
+
+#endif
diff --git a/WebCore/bindings/cpp/WebNativeEventListener.cpp b/WebCore/bindings/cpp/WebNativeEventListener.cpp
new file mode 100644
index 0000000..ddd7112
--- /dev/null
+++ b/WebCore/bindings/cpp/WebNativeEventListener.cpp
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebNativeEventListener.h"
+
+#include "WebDOMEvent.h"
+
+WebNativeEventListener::WebNativeEventListener(WebUserEventListener* listener)
+ : WebCore::EventListener(CPPEventListenerType),
+ m_listener(listener)
+{
+ ASSERT(m_listener);
+ m_listener->ref();
+}
+
+WebNativeEventListener::~WebNativeEventListener()
+{
+ m_listener->deref();
+}
+
+void WebNativeEventListener::handleEvent(WebCore::ScriptExecutionContext*, WebCore::Event* event)
+{
+ m_listener->handleEvent(toWebKit(event));
+}
+
+bool WebNativeEventListener::reportError(WebCore::ScriptExecutionContext*, const WebCore::String&, const WebCore::String&, int)
+{
+ // FIXME: Implement error handling
+ return false;
+}
+
+bool WebNativeEventListener::operator==(const WebCore::EventListener& other)
+{
+ const WebNativeEventListener* ptrOther = cast(&other);
+ return ptrOther && m_listener == ptrOther->m_listener;
+}
diff --git a/WebCore/bindings/cpp/WebNativeEventListener.h b/WebCore/bindings/cpp/WebNativeEventListener.h
new file mode 100644
index 0000000..fff1b1c
--- /dev/null
+++ b/WebCore/bindings/cpp/WebNativeEventListener.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ * Copyright (C) 2001 Peter Kelly (pmk@post.com)
+ * Copyright (C) 2003, 2008, 2009 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WebNativeEventListener_h
+#define WebNativeEventListener_h
+
+#include "EventListener.h"
+#include "WebDOMEventListener.h"
+
+class WebNativeEventListener : public WebCore::EventListener {
+public:
+ static PassRefPtr<WebNativeEventListener> create(WebUserEventListener* listener)
+ {
+ return adoptRef(new WebNativeEventListener(listener));
+ }
+
+ static const WebNativeEventListener* cast(const WebCore::EventListener* listener)
+ {
+ return listener->type() == CPPEventListenerType
+ ? static_cast<const WebNativeEventListener*>(listener)
+ : 0;
+ }
+
+ virtual ~WebNativeEventListener();
+ virtual bool operator==(const WebCore::EventListener& other);
+
+private:
+ virtual void handleEvent(WebCore::ScriptExecutionContext*, WebCore::Event*);
+ virtual bool reportError(WebCore::ScriptExecutionContext*, const WebCore::String& message, const WebCore::String& url, int lineNumber);
+
+protected:
+ WebNativeEventListener(WebUserEventListener*);
+ WebUserEventListener* m_listener;
+};
+
+#endif