From 40736c5763bf61337c8c14e16d8587db021a87d4 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 6 Jan 2012 14:44:00 +0100 Subject: Imported WebKit commit 2ea9d364d0f6efa8fa64acf19f451504c59be0e4 (http://svn.webkit.org/repository/webkit/trunk@104285) --- Source/WebKit2/UIProcess/API/cpp/WKRetainPtr.h | 251 +++++++++++++++++++++ Source/WebKit2/UIProcess/API/cpp/qt/WKStringQt.cpp | 43 ++++ Source/WebKit2/UIProcess/API/cpp/qt/WKStringQt.h | 30 +++ Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.cpp | 43 ++++ Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.h | 31 +++ 5 files changed, 398 insertions(+) create mode 100644 Source/WebKit2/UIProcess/API/cpp/WKRetainPtr.h create mode 100644 Source/WebKit2/UIProcess/API/cpp/qt/WKStringQt.cpp create mode 100644 Source/WebKit2/UIProcess/API/cpp/qt/WKStringQt.h create mode 100644 Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.cpp create mode 100644 Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.h (limited to 'Source/WebKit2/UIProcess/API/cpp') diff --git a/Source/WebKit2/UIProcess/API/cpp/WKRetainPtr.h b/Source/WebKit2/UIProcess/API/cpp/WKRetainPtr.h new file mode 100644 index 000000000..d5dbdf029 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/cpp/WKRetainPtr.h @@ -0,0 +1,251 @@ +/* + * 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 +#include + +namespace WebKit { + +enum WKAdoptTag { AdoptWK }; + +template 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 WKRetainPtr(const WKRetainPtr& 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); + } + +#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES) + template WKRetainPtr(WKRetainPtr&& o) + : m_ptr(o.leakRef()) + { + } + + WKRetainPtr(WKRetainPtr&& o) + : m_ptr(o.leakRef()) + { + } +#endif + + ~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 WKRetainPtr& operator=(const WKRetainPtr&); + WKRetainPtr& operator=(PtrType); + template WKRetainPtr& operator=(U*); + +#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES) + WKRetainPtr& operator=(WKRetainPtr&&); + template WKRetainPtr& operator=(WKRetainPtr&&); +#endif + + void adopt(PtrType); + void swap(WKRetainPtr&); + +private: + PtrType m_ptr; +}; + +template inline WKRetainPtr& WKRetainPtr::operator=(const WKRetainPtr& o) +{ + PtrType optr = o.get(); + if (optr) + WKRetain(optr); + PtrType ptr = m_ptr; + m_ptr = optr; + if (ptr) + WKRelease(ptr); + return *this; +} + +template template inline WKRetainPtr& WKRetainPtr::operator=(const WKRetainPtr& o) +{ + PtrType optr = o.get(); + if (optr) + WKRetain(optr); + PtrType ptr = m_ptr; + m_ptr = optr; + if (ptr) + WKRelease(ptr); + return *this; +} + +template inline WKRetainPtr& WKRetainPtr::operator=(PtrType optr) +{ + if (optr) + WKRetain(optr); + PtrType ptr = m_ptr; + m_ptr = optr; + if (ptr) + WKRelease(ptr); + return *this; +} + +template template inline WKRetainPtr& WKRetainPtr::operator=(U* optr) +{ + if (optr) + WKRetain(optr); + PtrType ptr = m_ptr; + m_ptr = optr; + if (ptr) + WKRelease(ptr); + return *this; +} + +#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES) +template inline WKRetainPtr& WKRetainPtr::operator=(WKRetainPtr&& o) +{ + adopt(o.leakRef()); + return *this; +} + +template template inline WKRetainPtr& WKRetainPtr::operator=(WKRetainPtr&& o) +{ + adopt(o.leakRef()); + return *this; +} +#endif + +template inline void WKRetainPtr::adopt(PtrType optr) +{ + PtrType ptr = m_ptr; + m_ptr = optr; + if (ptr) + WKRelease(ptr); +} + +template inline void WKRetainPtr::swap(WKRetainPtr& o) +{ + std::swap(m_ptr, o.m_ptr); +} + +template inline void swap(WKRetainPtr& a, WKRetainPtr& b) +{ + a.swap(b); +} + +template inline bool operator==(const WKRetainPtr& a, const WKRetainPtr& b) +{ + return a.get() == b.get(); +} + +template inline bool operator==(const WKRetainPtr& a, U* b) +{ + return a.get() == b; +} + +template inline bool operator==(T* a, const WKRetainPtr& b) +{ + return a == b.get(); +} + +template inline bool operator!=(const WKRetainPtr& a, const WKRetainPtr& b) +{ + return a.get() != b.get(); +} + +template inline bool operator!=(const WKRetainPtr& a, U* b) +{ + return a.get() != b; +} + +template inline bool operator!=(T* a, const WKRetainPtr& b) +{ + return a != b.get(); +} + +template inline WKRetainPtr adoptWK(T) WARN_UNUSED_RETURN; + +template inline WKRetainPtr adoptWK(T o) +{ + return WKRetainPtr(AdoptWK, o); +} + +} // namespace WebKit + +using WebKit::WKRetainPtr; +using WebKit::AdoptWK; +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 000000000..f2f188354 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/cpp/qt/WKStringQt.cpp @@ -0,0 +1,43 @@ +/* + * 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 "config.h" +#include "WKStringQt.h" + +#include "WKAPICast.h" +#include +#include +#include + +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(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 000000000..cc46e4250 --- /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 +#include + +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 000000000..f9111f7ea --- /dev/null +++ b/Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.cpp @@ -0,0 +1,43 @@ +/* + * 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 "config.h" +#include "WKURLQt.h" + +#include "WKAPICast.h" +#include +#include +#include + +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(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 000000000..2e4147330 --- /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 +#include +#include + +WK_EXPORT WKURLRef WKURLCreateWithQUrl(const QUrl& url); +QUrl WKURLCopyQUrl(WKURLRef url); + +#endif /* WKURLCF_h */ -- cgit v1.2.1