Commit 380a5aae authored by eric@webkit.org's avatar eric@webkit.org

2010-01-27 Yael Aharon <yael.aharon@nokia.com>

        Reviewed by Laszlo Gombos.

        [Qt] Enable websockets support in QtWebKit
        https://bugs.webkit.org/show_bug.cgi?id=34180

        Remove websockets tests from skiplist.

        * platform/qt/Skipped:
2010-01-27  Yael Aharon  <yael.aharon@nokia.com>

        Reviewed by Laszlo Gombos.

        [Qt] Enable websockets support in QtWebKit
        https://bugs.webkit.org/show_bug.cgi?id=34180

        Connected between SocketStreamHandle and QTcpSocket/QSslSocket
        to enable support for websockets.
        Proxy authentication is not yet supported.
        SSL certificate errors are ignored while this is under development.

        * WebCore.pro:
        * platform/network/qt/SocketStreamHandle.h:
        * platform/network/qt/SocketStreamHandlePrivate.h: Added.
        * platform/network/qt/SocketStreamHandleQt.cpp:
        (WebCore::SocketStreamHandlePrivate::SocketStreamHandlePrivate):
        (WebCore::SocketStreamHandlePrivate::~SocketStreamHandlePrivate):
        (WebCore::SocketStreamHandlePrivate::socketConnected):
        (WebCore::SocketStreamHandlePrivate::socketReadyRead):
        (WebCore::SocketStreamHandlePrivate::send):
        (WebCore::SocketStreamHandlePrivate::close):
        (WebCore::SocketStreamHandlePrivate::socketSentdata):
        (WebCore::SocketStreamHandlePrivate::socketClosed):
        (WebCore::SocketStreamHandlePrivate::socketError):
        (WebCore::SocketStreamHandlePrivate::socketClosedCallback):
        (WebCore::SocketStreamHandlePrivate::socketErrorCallback):
        (WebCore::SocketStreamHandlePrivate::socketSslErrors):
        (WebCore::SocketStreamHandle::SocketStreamHandle):
        (WebCore::SocketStreamHandle::~SocketStreamHandle):
        (WebCore::SocketStreamHandle::platformSend):
        (WebCore::SocketStreamHandle::platformClose):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@53947 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 3a43f91f
2010-01-27 Yael Aharon <yael.aharon@nokia.com>
Reviewed by Laszlo Gombos.
[Qt] Enable websockets support in QtWebKit
https://bugs.webkit.org/show_bug.cgi?id=34180
Remove websockets tests from skiplist.
* platform/qt/Skipped:
2010-01-27 Mads Ager <ager@chromium.org>
Reviewed by Dimitri Glazkov.
......@@ -4963,9 +4963,6 @@ http/tests/xmlhttprequest/workers/methods-async.html
http/tests/xmlhttprequest/workers/methods.html
http/tests/xmlhttprequest/workers/shared-worker-methods-async.html
# Missing SocketStreamHandle implementation
websocket/tests
# Need rebaseline: https://bugs.webkit.org/show_bug.cgi?id=26830
fast/multicol/single-line.html
......
2010-01-27 Yael Aharon <yael.aharon@nokia.com>
Reviewed by Laszlo Gombos.
[Qt] Enable websockets support in QtWebKit
https://bugs.webkit.org/show_bug.cgi?id=34180
Connected between SocketStreamHandle and QTcpSocket/QSslSocket
to enable support for websockets.
Proxy authentication is not yet supported.
SSL certificate errors are ignored while this is under development.
* WebCore.pro:
* platform/network/qt/SocketStreamHandle.h:
* platform/network/qt/SocketStreamHandlePrivate.h: Added.
* platform/network/qt/SocketStreamHandleQt.cpp:
(WebCore::SocketStreamHandlePrivate::SocketStreamHandlePrivate):
(WebCore::SocketStreamHandlePrivate::~SocketStreamHandlePrivate):
(WebCore::SocketStreamHandlePrivate::socketConnected):
(WebCore::SocketStreamHandlePrivate::socketReadyRead):
(WebCore::SocketStreamHandlePrivate::send):
(WebCore::SocketStreamHandlePrivate::close):
(WebCore::SocketStreamHandlePrivate::socketSentdata):
(WebCore::SocketStreamHandlePrivate::socketClosed):
(WebCore::SocketStreamHandlePrivate::socketError):
(WebCore::SocketStreamHandlePrivate::socketClosedCallback):
(WebCore::SocketStreamHandlePrivate::socketErrorCallback):
(WebCore::SocketStreamHandlePrivate::socketSslErrors):
(WebCore::SocketStreamHandle::SocketStreamHandle):
(WebCore::SocketStreamHandle::~SocketStreamHandle):
(WebCore::SocketStreamHandle::platformSend):
(WebCore::SocketStreamHandle::platformClose):
2010-01-27 Mads Ager <ager@chromium.org>
Reviewed by Dimitri Glazkov.
......@@ -1526,6 +1526,7 @@ HEADERS += \
platform/network/NetworkStateNotifier.h \
platform/network/ProtectionSpace.h \
platform/network/qt/QNetworkReplyHandler.h \
platform/network/qt/SocketStreamHandlePrivate.h \
platform/network/ResourceErrorBase.h \
platform/network/ResourceHandle.h \
platform/network/ResourceRequestBase.h \
......
/*
* Copyright (C) 2010 Nokia Inc. All rights reserved.
* Copyright (C) 2009 Apple Inc. All rights reserved.
* Copyright (C) 2009 Google Inc. All rights reserved.
*
......@@ -42,6 +43,7 @@ namespace WebCore {
class AuthenticationChallenge;
class Credential;
class SocketStreamHandleClient;
class SocketStreamHandlePrivate;
class SocketStreamHandle : public RefCounted<SocketStreamHandle>, public SocketStreamHandleBase {
public:
......@@ -61,6 +63,8 @@ namespace WebCore {
void receivedCredential(const AuthenticationChallenge&, const Credential&);
void receivedRequestToContinueWithoutCredential(const AuthenticationChallenge&);
void receivedCancellation(const AuthenticationChallenge&);
SocketStreamHandlePrivate* m_p;
friend class SocketStreamHandlePrivate;
};
} // namespace WebCore
......
/*
* Copyright (C) 2010 Nokia 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:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
* OWNER OR 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 SocketStreamHandlePrivate_h
#define SocketStreamHandlePrivate_h
#include "SocketStreamHandleBase.h"
#include <QSslSocket>
#include <QTcpSocket>
namespace WebCore {
class AuthenticationChallenge;
class Credential;
class SocketStreamHandleClient;
class SocketStreamHandlePrivate;
class SocketStreamHandlePrivate : public QObject {
Q_OBJECT
public:
SocketStreamHandlePrivate(SocketStreamHandle*, const KURL&);
~SocketStreamHandlePrivate();
public slots:
void socketConnected();
void socketReadyRead();
int send(const char* data, int len);
void close();
void socketSentdata();
void socketClosed();
void socketError(QAbstractSocket::SocketError);
void socketClosedCallback();
void socketErrorCallback(int);
void socketSslErrors(const QList<QSslError>&);
public:
QTcpSocket* m_socket;
SocketStreamHandle* m_streamHandle;
};
}
#endif
/*
* Copyright (C) 2010 Nokia Inc. All rights reserved.
* Copyright (C) 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -35,34 +36,139 @@
#include "Logging.h"
#include "NotImplemented.h"
#include "SocketStreamHandleClient.h"
#include "SocketStreamHandlePrivate.h"
namespace WebCore {
SocketStreamHandlePrivate::SocketStreamHandlePrivate(SocketStreamHandle* streamHandle, const KURL& url) : QObject()
{
m_streamHandle = streamHandle;
m_socket = 0;
bool isSecure = url.protocolIs("wss");
if (isSecure)
m_socket = new QSslSocket(this);
else
m_socket = new QTcpSocket(this);
connect(m_socket, SIGNAL(connected()), this, SLOT(socketConnected()));
connect(m_socket, SIGNAL(readyRead()), this, SLOT(socketReadyRead()));
connect(m_socket, SIGNAL(disconnected()), this, SLOT(socketClosed()));
connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)));
if (isSecure)
connect(m_socket, SIGNAL(sslErrors(const QList<QSslError>&)), this, SLOT(socketSslErrors(const QList<QSslError>&)));
unsigned int port = url.hasPort() ? url.port() : (isSecure ? 443 : 80);
QString host = url.host();
if (isSecure)
static_cast<QSslSocket*>(m_socket)->connectToHostEncrypted(host, port);
else
m_socket->connectToHost(host, port);
}
SocketStreamHandlePrivate::~SocketStreamHandlePrivate()
{
Q_ASSERT(!(m_socket && m_socket->state() == QAbstractSocket::ConnectedState));
}
void SocketStreamHandlePrivate::socketConnected()
{
if (m_streamHandle && m_streamHandle->client()) {
m_streamHandle->m_state = SocketStreamHandleBase::Open;
m_streamHandle->client()->didOpen(m_streamHandle);
}
}
void SocketStreamHandlePrivate::socketReadyRead()
{
if (m_streamHandle && m_streamHandle->client()) {
QByteArray data = m_socket->read(m_socket->bytesAvailable());
m_streamHandle->client()->didReceiveData(m_streamHandle, data.constData(), data.size());
}
}
int SocketStreamHandlePrivate::send(const char* data, int len)
{
if (m_socket->state() != QAbstractSocket::ConnectedState)
return 0;
quint64 sentSize = m_socket->write(data, len);
QMetaObject::invokeMethod(this, "socketSentData", Qt::QueuedConnection);
return sentSize;
}
void SocketStreamHandlePrivate::close()
{
if (m_socket && m_socket->state() == QAbstractSocket::ConnectedState)
m_socket->close();
}
void SocketStreamHandlePrivate::socketSentdata()
{
if (m_streamHandle)
m_streamHandle->sendPendingData();
}
void SocketStreamHandlePrivate::socketClosed()
{
QMetaObject::invokeMethod(this, "socketClosedCallback", Qt::QueuedConnection);
}
void SocketStreamHandlePrivate::socketError(QAbstractSocket::SocketError error)
{
QMetaObject::invokeMethod(this, "socketErrorCallback", Qt::QueuedConnection, Q_ARG(int, error));
}
void SocketStreamHandlePrivate::socketClosedCallback()
{
if (m_streamHandle && m_streamHandle->client()) {
SocketStreamHandle* streamHandle = m_streamHandle;
m_streamHandle = 0;
// This following call deletes _this_. Nothing should be after it.
streamHandle->client()->didClose(streamHandle);
}
}
void SocketStreamHandlePrivate::socketErrorCallback(int error)
{
// FIXME - in the future, we might not want to treat all errors as fatal.
if (m_streamHandle && m_streamHandle->client()) {
SocketStreamHandle* streamHandle = m_streamHandle;
m_streamHandle = 0;
// This following call deletes _this_. Nothing should be after it.
streamHandle->client()->didClose(streamHandle);
}
}
void SocketStreamHandlePrivate::socketSslErrors(const QList<QSslError>&)
{
// FIXME: based on http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-68#page-15
// we should abort on certificate errors.
// We don't abort while this is still work in progress.
static_cast<QSslSocket*>(m_socket)->ignoreSslErrors();
}
SocketStreamHandle::SocketStreamHandle(const KURL& url, SocketStreamHandleClient* client)
: SocketStreamHandleBase(url, client)
{
LOG(Network, "SocketStreamHandle %p new client %p", this, m_client);
notImplemented();
m_p = new SocketStreamHandlePrivate(this, url);
}
SocketStreamHandle::~SocketStreamHandle()
{
LOG(Network, "SocketStreamHandle %p delete", this);
setClient(0);
notImplemented();
delete m_p;
}
int SocketStreamHandle::platformSend(const char*, int)
int SocketStreamHandle::platformSend(const char* data, int len)
{
LOG(Network, "SocketStreamHandle %p platformSend", this);
notImplemented();
return 0;
return m_p->send(data, len);
}
void SocketStreamHandle::platformClose()
{
LOG(Network, "SocketStreamHandle %p platformClose", this);
notImplemented();
m_p->close();
}
void SocketStreamHandle::didReceiveAuthenticationChallenge(const AuthenticationChallenge&)
......@@ -86,3 +192,5 @@ void SocketStreamHandle::receivedCancellation(const AuthenticationChallenge&)
}
} // namespace WebCore
#include "moc_SocketStreamHandlePrivate.cpp"
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