diff options
Diffstat (limited to 'Source/WebKit2/UIProcess/API/cpp')
-rw-r--r-- | Source/WebKit2/UIProcess/API/cpp/WKRetainPtr.h | 212 | ||||
-rw-r--r-- | Source/WebKit2/UIProcess/API/cpp/qt/WKStringQt.cpp | 42 | ||||
-rw-r--r-- | Source/WebKit2/UIProcess/API/cpp/qt/WKStringQt.h | 30 | ||||
-rw-r--r-- | Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.cpp | 42 | ||||
-rw-r--r-- | Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.h | 31 |
5 files changed, 357 insertions, 0 deletions
diff --git a/Source/WebKit2/UIProcess/API/cpp/WKRetainPtr.h b/Source/WebKit2/UIProcess/API/cpp/WKRetainPtr.h new file mode 100644 index 0000000..cb2a63e --- /dev/null +++ b/Source/WebKit2/UIProcess/API/cpp/WKRetainPtr.h @@ -0,0 +1,212 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKRetainPtr_h +#define WKRetainPtr_h + +#include <WebKit2/WKType.h> +#include <algorithm> + +namespace WebKit { + +enum WKAdoptTag { AdoptWK }; + +template<typename T> class WKRetainPtr { +public: + typedef T PtrType; + + WKRetainPtr() + : m_ptr(0) + { + } + + WKRetainPtr(PtrType ptr) + : m_ptr(ptr) + { + if (ptr) + WKRetain(ptr); + } + + WKRetainPtr(WKAdoptTag, PtrType ptr) + : m_ptr(ptr) + { + } + + template<typename U> WKRetainPtr(const WKRetainPtr<U>& o) + : m_ptr(o.get()) + { + if (PtrType ptr = m_ptr) + WKRetain(ptr); + } + + WKRetainPtr(const WKRetainPtr& o) + : m_ptr(o.m_ptr) + { + if (PtrType ptr = m_ptr) + WKRetain(ptr); + } + + ~WKRetainPtr() + { + if (PtrType ptr = m_ptr) + WKRelease(ptr); + } + + PtrType get() const { return m_ptr; } + + void clear() + { + PtrType ptr = m_ptr; + m_ptr = 0; + if (ptr) + WKRelease(ptr); + } + + PtrType leakRef() + { + PtrType ptr = m_ptr; + m_ptr = 0; + return ptr; + } + + PtrType operator->() const { return m_ptr; } + bool operator!() const { return !m_ptr; } + + // This conversion operator allows implicit conversion to bool but not to other integer types. + typedef PtrType WKRetainPtr::*UnspecifiedBoolType; + operator UnspecifiedBoolType() const { return m_ptr ? &WKRetainPtr::m_ptr : 0; } + + WKRetainPtr& operator=(const WKRetainPtr&); + template<typename U> WKRetainPtr& operator=(const WKRetainPtr<U>&); + WKRetainPtr& operator=(PtrType); + template<typename U> WKRetainPtr& operator=(U*); + + void adopt(PtrType); + void swap(WKRetainPtr&); + +private: + PtrType m_ptr; +}; + +template<typename T> inline WKRetainPtr<T>& WKRetainPtr<T>::operator=(const WKRetainPtr<T>& o) +{ + PtrType optr = o.get(); + if (optr) + WKRetain(optr); + PtrType ptr = m_ptr; + m_ptr = optr; + if (ptr) + WKRelease(ptr); + return *this; +} + +template<typename T> template<typename U> inline WKRetainPtr<T>& WKRetainPtr<T>::operator=(const WKRetainPtr<U>& o) +{ + PtrType optr = o.get(); + if (optr) + WKRetain(optr); + PtrType ptr = m_ptr; + m_ptr = optr; + if (ptr) + WKRelease(ptr); + return *this; +} + +template<typename T> inline WKRetainPtr<T>& WKRetainPtr<T>::operator=(PtrType optr) +{ + if (optr) + WKRetain(optr); + PtrType ptr = m_ptr; + m_ptr = optr; + if (ptr) + WKRelease(ptr); + return *this; +} + +template<typename T> inline void WKRetainPtr<T>::adopt(PtrType optr) +{ + PtrType ptr = m_ptr; + m_ptr = optr; + if (ptr) + WKRelease(ptr); +} + +template<typename T> template<typename U> inline WKRetainPtr<T>& WKRetainPtr<T>::operator=(U* optr) +{ + if (optr) + WKRetain(optr); + PtrType ptr = m_ptr; + m_ptr = optr; + if (ptr) + WKRelease(ptr); + return *this; +} + +template<typename T> inline void WKRetainPtr<T>::swap(WKRetainPtr<T>& o) +{ + std::swap(m_ptr, o.m_ptr); +} + +template<typename T> inline void swap(WKRetainPtr<T>& a, WKRetainPtr<T>& b) +{ + a.swap(b); +} + +template<typename T, typename U> inline bool operator==(const WKRetainPtr<T>& a, const WKRetainPtr<U>& b) +{ + return a.get() == b.get(); +} + +template<typename T, typename U> inline bool operator==(const WKRetainPtr<T>& a, U* b) +{ + return a.get() == b; +} + +template<typename T, typename U> inline bool operator==(T* a, const WKRetainPtr<U>& b) +{ + return a == b.get(); +} + +template<typename T, typename U> inline bool operator!=(const WKRetainPtr<T>& a, const WKRetainPtr<U>& b) +{ + return a.get() != b.get(); +} + +template<typename T, typename U> inline bool operator!=(const WKRetainPtr<T>& a, U* b) +{ + return a.get() != b; +} + +template<typename T, typename U> inline bool operator!=(T* a, const WKRetainPtr<U>& b) +{ + return a != b.get(); +} + +} // namespace WebKit + +using WebKit::WKRetainPtr; +using WebKit::AdoptWK; + +#endif // WKRetainPtr_h diff --git a/Source/WebKit2/UIProcess/API/cpp/qt/WKStringQt.cpp b/Source/WebKit2/UIProcess/API/cpp/qt/WKStringQt.cpp new file mode 100644 index 0000000..0f2c946 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/cpp/qt/WKStringQt.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + * + * 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 program 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 program; 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 "WKStringQt.h" + +#include "WKAPICast.h" +#include <QString> +#include <wtf/RefPtr.h> +#include <wtf/text/WTFString.h> + +using namespace WebKit; + +WKStringRef WKStringCreateWithQString(const QString& qString) +{ + WTF::String string(qString); + return toCopiedAPI(string); +} + +QString WKStringCopyQString(WKStringRef stringRef) +{ + if (!stringRef) + return QString(); + const WTF::String& string = toImpl(stringRef)->string(); + return QString(reinterpret_cast<const QChar*>(string.characters()), string.length()); +} diff --git a/Source/WebKit2/UIProcess/API/cpp/qt/WKStringQt.h b/Source/WebKit2/UIProcess/API/cpp/qt/WKStringQt.h new file mode 100644 index 0000000..cc46e42 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/cpp/qt/WKStringQt.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + * + * 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 program 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 program; 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 WKStringQt_h +#define WKStringQt_h + +#include <QString> +#include <WebKit2/WKBase.h> + +WK_EXPORT WKStringRef WKStringCreateWithQString(const QString& string); +WK_EXPORT QString WKStringCopyQString(WKStringRef string); + +#endif /* WKStringQt_h */ diff --git a/Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.cpp b/Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.cpp new file mode 100644 index 0000000..74eca86 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + * + * 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 program 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 program; 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 "WKURLQt.h" + +#include "WKAPICast.h" +#include <QString> +#include <wtf/RefPtr.h> +#include <wtf/text/WTFString.h> + +using namespace WebKit; + +WKURLRef WKURLCreateWithQUrl(const QUrl& qURL) +{ + WTF::String urlString(qURL.toString()); + return toCopiedURLAPI(urlString); +} + +QUrl WKURLCopyQUrl(WKURLRef urlRef) +{ + if (!urlRef) + return QUrl(); + const WTF::String& string = toImpl(urlRef)->string(); + return QUrl(QString(reinterpret_cast<const QChar*>(string.characters()), string.length())); +} diff --git a/Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.h b/Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.h new file mode 100644 index 0000000..2e41473 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + * + * 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 program 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 program; 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 WKURLQt_h +#define WKURLQt_h + +#include <QUrl> +#include <WebKit2/WKBase.h> +#include <WebKit2/WKURL.h> + +WK_EXPORT WKURLRef WKURLCreateWithQUrl(const QUrl& url); +QUrl WKURLCopyQUrl(WKURLRef url); + +#endif /* WKURLCF_h */ |