Changeset 113026 in webkit


Ignore:
Timestamp:
Apr 3, 2012 6:24:11 AM (12 years ago)
Author:
jocelyn.turcotte@nokia.com
Message:

Add a Generic WebSocket Server.
https://bugs.webkit.org/show_bug.cgi?id=73093

Reviewed by Simon Hausmann.

Source/WebCore:

Allow SocketStreamHandle for the Qt port to take an existing QTcpSocket in its constructor.

  • platform/network/qt/SocketStreamHandle.h:

(WebCore::SocketStreamHandle::create):
(SocketStreamHandle):

  • platform/network/qt/SocketStreamHandlePrivate.h:

(SocketStreamHandlePrivate):

  • platform/network/qt/SocketStreamHandleQt.cpp:

(WebCore::SocketStreamHandlePrivate::SocketStreamHandlePrivate):
(WebCore):
(WebCore::SocketStreamHandlePrivate::initConnections):
(WebCore::SocketStreamHandlePrivate::close):
(WebCore::SocketStreamHandle::SocketStreamHandle):

Source/WebKit2:

The Inspector Server will be a WebSocket Server that also responds to
non-WebSocket-Upgrade HTTP Requests. This is a generic WebSocket server
that passes on what it doesn't know on to its client for extended
functionality. This code is wrapped in a new ENABLE(INSPECTOR_SERVER) flag.

There are no tests yet for a built-in WebSocket server.
This will be covered by API level tests in a later patch.

  • Target.pri:

WebSocketServer is a simple server. Calling listen, or close,
multiple times is safe. Subclassing is expected.

  • UIProcess/InspectorServer/WebSocketServer.cpp: Added.

(WebKit):
(WebKit::WebSocketServer::WebSocketServer):
(WebKit::WebSocketServer::~WebSocketServer):
(WebKit::WebSocketServer::listen):
(WebKit::WebSocketServer::close):
(WebKit::WebSocketServer::didAcceptConnection):
(WebKit::WebSocketServer::didCloseWebSocketServerConnection):

  • UIProcess/InspectorServer/WebSocketServer.h: Added.

(WebKit):
(WebCore):
(WebSocketServer):

  • UIProcess/InspectorServer/WebSocketServerClient.h: Added.

(WebCore):
(WebKit):
(WebSocketServerClient):
(WebKit::WebSocketServerClient::~WebSocketServerClient):
(WebKit::WebSocketServerClient::didReceiveUnrecognizedHTTPRequest):
(WebKit::WebSocketServerClient::didReceiveWebSocketUpgradeHTTPRequest):
(WebKit::WebSocketServerClient::didEstablishWebSocketConnection):
(WebKit::WebSocketServerClient::didReceiveWebSocketMessage):
(WebKit::WebSocketServerClient::didCloseWebSocketConnection):

Each WebSocketConnection:

  • Passes unknown HTTP Requests to the server's client.
  • Handles WebSocket Upgrade Requests.
    • First ask the client if it is okay.
    • Later notify the client about a success.
  • Once upgraded the connection parses and passes WebSocket frames to the client.
  • UIProcess/InspectorServer/WebSocketServerConnection.cpp: Added.

(WebKit):
(WebKit::WebSocketServerConnection::WebSocketServerConnection):
(WebKit::WebSocketServerConnection::~WebSocketServerConnection):
(WebKit::WebSocketServerConnection::shutdownNow):
(WebKit::WebSocketServerConnection::shutdownAfterSendOrNow): meant to shutdown after an HTTP response. Ensure all platforms work as expected.
(WebKit::WebSocketServerConnection::sendWebSocketMessage): send a text message (WebSocket message) over the connection.
(WebKit::WebSocketServerConnection::sendHTTPResponseHeader):
(WebKit::WebSocketServerConnection::sendRawData): send raw data (HTTP message) over the connection.
(WebKit::WebSocketServerConnection::didCloseSocketStream): handle socket closing scenarios.
(WebKit::WebSocketServerConnection::didReceiveSocketStreamData): parse the incoming data in HTTP / WebSocket modes.
(WebKit::WebSocketServerConnection::didFailSocketStream): log errors.
(WebKit::WebSocketServerConnection::readHTTPMessage): when starting, a web socket connection reads an HTTP message.
(WebKit::WebSocketServerConnection::upgradeToWebSocketServerConnection):
(WebKit::WebSocketServerConnection::readWebSocketFrames): parse our buffer for as many frames as possible.
(WebKit::WebSocketServerConnection::readWebSocketFrame): parse an individual frame.

  • UIProcess/InspectorServer/WebSocketServerConnection.h: Added.

(WebCore):
(WebKit):
(WebSocketServerConnection):
(WebKit::WebSocketServerConnection::identifier):
(WebKit::WebSocketServerConnection::setIdentifier):

Qt specific implementation.

  • UIProcess/InspectorServer/qt/WebSocketServerQt.cpp: Added.

(WebKit):
(WebKit::WebSocketServer::platformInitialize):
(WebKit::WebSocketServer::platformListen):
(WebKit::WebSocketServer::platformClose):
(WebKit::QtTcpServerHandler::QtTcpServerHandler):
(WebKit::QtTcpServerHandler::handleNewConnection):
(WebKit::QtTcpServerHandler::listen):
(WebKit::QtTcpServerHandler::close):

  • UIProcess/InspectorServer/qt/WebSocketServerQt.h: Added.

(WebKit):
(QtTcpServerHandler):

  • WebKit2.pri:
  • config.h: Add ENABLE(INSPECTOR_SERVER) for WebKit2.
Location:
trunk/Source
Files:
9 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r113025 r113026  
     12012-03-29  Joseph Pecoraro  <joepeck@webkit.org> and Jocelyn Turcotte  <jocelyn.turcotte@nokia.com>
     2
     3        Add a Generic WebSocket Server.
     4        https://bugs.webkit.org/show_bug.cgi?id=73093
     5
     6        Reviewed by Simon Hausmann.
     7
     8        Allow SocketStreamHandle for the Qt port to take an existing QTcpSocket in its constructor.
     9
     10        * platform/network/qt/SocketStreamHandle.h:
     11        (WebCore::SocketStreamHandle::create):
     12        (SocketStreamHandle):
     13        * platform/network/qt/SocketStreamHandlePrivate.h:
     14        (SocketStreamHandlePrivate):
     15        * platform/network/qt/SocketStreamHandleQt.cpp:
     16        (WebCore::SocketStreamHandlePrivate::SocketStreamHandlePrivate):
     17        (WebCore):
     18        (WebCore::SocketStreamHandlePrivate::initConnections):
     19        (WebCore::SocketStreamHandlePrivate::close):
     20        (WebCore::SocketStreamHandle::SocketStreamHandle):
     21
    1222012-04-01  Jocelyn Turcotte  <jocelyn.turcotte@nokia.com>
    223
  • trunk/Source/WebCore/platform/network/qt/SocketStreamHandle.h

    r95901 r113026  
    4343#endif
    4444
     45QT_BEGIN_NAMESPACE
     46class QTcpSocket;
     47QT_END_NAMESPACE
     48
    4549namespace WebCore {
    4650
     
    5357    public:
    5458        static PassRefPtr<SocketStreamHandle> create(const KURL& url, SocketStreamHandleClient* client) { return adoptRef(new SocketStreamHandle(url, client)); }
     59        static PassRefPtr<SocketStreamHandle> create(QTcpSocket* socket, SocketStreamHandleClient* client) { return adoptRef(new SocketStreamHandle(socket, client)); }
    5560
    5661        virtual ~SocketStreamHandle();
     
    6267    private:
    6368        SocketStreamHandle(const KURL&, SocketStreamHandleClient*);
     69        SocketStreamHandle(QTcpSocket*, SocketStreamHandleClient*);
    6470
    6571        // No authentication for streams per se, but proxy may ask for credentials.
  • trunk/Source/WebCore/platform/network/qt/SocketStreamHandlePrivate.h

    r95901 r113026  
    4848public:
    4949    SocketStreamHandlePrivate(SocketStreamHandle*, const KURL&);
     50    SocketStreamHandlePrivate(SocketStreamHandle*, QTcpSocket*);
    5051    ~SocketStreamHandlePrivate();
    5152
     
    6465#endif
    6566public:
     67    void initConnections();
    6668    QTcpSocket* m_socket;
    6769    SocketStreamHandle* m_streamHandle;
  • trunk/Source/WebCore/platform/network/qt/SocketStreamHandleQt.cpp

    r100891 r113026  
    4141namespace WebCore {
    4242
    43 SocketStreamHandlePrivate::SocketStreamHandlePrivate(SocketStreamHandle* streamHandle, const KURL& url) : QObject()
     43SocketStreamHandlePrivate::SocketStreamHandlePrivate(SocketStreamHandle* streamHandle, const KURL& url)
    4444{
    4545    m_streamHandle = streamHandle;
     
    5757        return;
    5858
     59    initConnections();
     60
     61    unsigned int port = url.hasPort() ? url.port() : (isSecure ? 443 : 80);
     62
     63    QString host = url.host();
     64    if (isSecure) {
     65#ifndef QT_NO_OPENSSL
     66        static_cast<QSslSocket*>(m_socket)->connectToHostEncrypted(host, port);
     67#endif
     68    } else
     69        m_socket->connectToHost(host, port);
     70}
     71
     72SocketStreamHandlePrivate::SocketStreamHandlePrivate(SocketStreamHandle* streamHandle, QTcpSocket* socket)
     73{
     74    m_streamHandle = streamHandle;
     75    m_socket = socket;
     76    initConnections();
     77}
     78
     79SocketStreamHandlePrivate::~SocketStreamHandlePrivate()
     80{
     81    Q_ASSERT(!(m_socket && m_socket->state() == QAbstractSocket::ConnectedState));
     82}
     83
     84void SocketStreamHandlePrivate::initConnections()
     85{
    5986    connect(m_socket, SIGNAL(connected()), this, SLOT(socketConnected()));
    6087    connect(m_socket, SIGNAL(readyRead()), this, SLOT(socketReadyRead()));
    6188    connect(m_socket, SIGNAL(disconnected()), this, SLOT(socketClosed()));
    6289    connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)));
    63     if (isSecure)
     90#ifndef QT_NO_OPENSSL
     91    if (qobject_cast<QSslSocket*>(m_socket))
    6492        connect(m_socket, SIGNAL(sslErrors(const QList<QSslError>&)), this, SLOT(socketSslErrors(const QList<QSslError>&)));
    65 
    66     unsigned int port = url.hasPort() ? url.port() : (isSecure ? 443 : 80);
    67 
    68     QString host = url.host();
    69     if (isSecure) {
    70 #ifndef QT_NO_OPENSSL
    71         static_cast<QSslSocket*>(m_socket)->connectToHostEncrypted(host, port);
    72 #endif
    73     } else
    74         m_socket->connectToHost(host, port);
    75 }
    76 
    77 SocketStreamHandlePrivate::~SocketStreamHandlePrivate()
    78 {
    79     Q_ASSERT(!(m_socket && m_socket->state() == QAbstractSocket::ConnectedState));
     93#endif
     94
     95    // Check for missed signals and call the slots asynchronously to allow a client to be set first.
     96    if (m_socket->state() >= QAbstractSocket::ConnectedState)
     97        QMetaObject::invokeMethod(this, "socketConnected", Qt::QueuedConnection);
     98    if (m_socket->bytesAvailable())
     99        QMetaObject::invokeMethod(this, "socketReadyRead", Qt::QueuedConnection);
    80100}
    81101
     
    107127void SocketStreamHandlePrivate::close()
    108128{
    109     if (m_streamHandle->m_state == SocketStreamHandleBase::Connecting) {
     129    if (m_streamHandle && m_streamHandle->m_state == SocketStreamHandleBase::Connecting) {
    110130        m_socket->abort();
    111131        m_streamHandle->client()->didCloseSocketStream(m_streamHandle);
     
    167187}
    168188
     189SocketStreamHandle::SocketStreamHandle(QTcpSocket* socket, SocketStreamHandleClient* client)
     190    : SocketStreamHandleBase(KURL(), client)
     191{
     192    LOG(Network, "SocketStreamHandle %p new client %p", this, m_client);
     193    m_p = new SocketStreamHandlePrivate(this, socket);
     194}
     195
    169196SocketStreamHandle::~SocketStreamHandle()
    170197{
  • trunk/Source/WebKit2/ChangeLog

    r113022 r113026  
     12012-03-29  Joseph Pecoraro  <joepeck@webkit.org> and Jocelyn Turcotte  <jocelyn.turcotte@nokia.com>
     2
     3        Add a Generic WebSocket Server.
     4        https://bugs.webkit.org/show_bug.cgi?id=73093
     5
     6        Reviewed by Simon Hausmann.
     7
     8        The Inspector Server will be a WebSocket Server that also responds to
     9        non-WebSocket-Upgrade HTTP Requests. This is a generic WebSocket server
     10        that passes on what it doesn't know on to its client for extended
     11        functionality. This code is wrapped in a new ENABLE(INSPECTOR_SERVER) flag.
     12
     13        There are no tests yet for a built-in WebSocket server.
     14        This will be covered by API level tests in a later patch.
     15
     16        * Target.pri:
     17
     18          WebSocketServer is a simple server. Calling listen, or close,
     19          multiple times is safe. Subclassing is expected.
     20
     21        * UIProcess/InspectorServer/WebSocketServer.cpp: Added.
     22        (WebKit):
     23        (WebKit::WebSocketServer::WebSocketServer):
     24        (WebKit::WebSocketServer::~WebSocketServer):
     25        (WebKit::WebSocketServer::listen):
     26        (WebKit::WebSocketServer::close):
     27        (WebKit::WebSocketServer::didAcceptConnection):
     28        (WebKit::WebSocketServer::didCloseWebSocketServerConnection):
     29        * UIProcess/InspectorServer/WebSocketServer.h: Added.
     30        (WebKit):
     31        (WebCore):
     32        (WebSocketServer):
     33        * UIProcess/InspectorServer/WebSocketServerClient.h: Added.
     34        (WebCore):
     35        (WebKit):
     36        (WebSocketServerClient):
     37        (WebKit::WebSocketServerClient::~WebSocketServerClient):
     38        (WebKit::WebSocketServerClient::didReceiveUnrecognizedHTTPRequest):
     39        (WebKit::WebSocketServerClient::didReceiveWebSocketUpgradeHTTPRequest):
     40        (WebKit::WebSocketServerClient::didEstablishWebSocketConnection):
     41        (WebKit::WebSocketServerClient::didReceiveWebSocketMessage):
     42        (WebKit::WebSocketServerClient::didCloseWebSocketConnection):
     43
     44          Each WebSocketConnection:
     45
     46           - Passes unknown HTTP Requests to the server's client.
     47           - Handles WebSocket Upgrade Requests.
     48             - First ask the client if it is okay.
     49             - Later notify the client about a success.
     50           - Once upgraded the connection parses and passes WebSocket
     51             frames to the client.
     52
     53        * UIProcess/InspectorServer/WebSocketServerConnection.cpp: Added.
     54        (WebKit):
     55        (WebKit::WebSocketServerConnection::WebSocketServerConnection):
     56        (WebKit::WebSocketServerConnection::~WebSocketServerConnection):
     57        (WebKit::WebSocketServerConnection::shutdownNow):
     58        (WebKit::WebSocketServerConnection::shutdownAfterSendOrNow): meant to shutdown after an HTTP response. Ensure all platforms work as expected.
     59        (WebKit::WebSocketServerConnection::sendWebSocketMessage): send a text message (WebSocket message) over the connection.
     60        (WebKit::WebSocketServerConnection::sendHTTPResponseHeader):
     61        (WebKit::WebSocketServerConnection::sendRawData): send raw data (HTTP message) over the connection.
     62        (WebKit::WebSocketServerConnection::didCloseSocketStream): handle socket closing scenarios.
     63        (WebKit::WebSocketServerConnection::didReceiveSocketStreamData): parse the incoming data in HTTP / WebSocket modes.
     64        (WebKit::WebSocketServerConnection::didFailSocketStream): log errors.
     65        (WebKit::WebSocketServerConnection::readHTTPMessage): when starting, a web socket connection reads an HTTP message.
     66        (WebKit::WebSocketServerConnection::upgradeToWebSocketServerConnection):
     67        (WebKit::WebSocketServerConnection::readWebSocketFrames): parse our buffer for as many frames as possible.
     68        (WebKit::WebSocketServerConnection::readWebSocketFrame): parse an individual frame.
     69        * UIProcess/InspectorServer/WebSocketServerConnection.h: Added.
     70        (WebCore):
     71        (WebKit):
     72        (WebSocketServerConnection):
     73        (WebKit::WebSocketServerConnection::identifier):
     74        (WebKit::WebSocketServerConnection::setIdentifier):
     75
     76          Qt specific implementation.
     77
     78        * UIProcess/InspectorServer/qt/WebSocketServerQt.cpp: Added.
     79        (WebKit):
     80        (WebKit::WebSocketServer::platformInitialize):
     81        (WebKit::WebSocketServer::platformListen):
     82        (WebKit::WebSocketServer::platformClose):
     83        (WebKit::QtTcpServerHandler::QtTcpServerHandler):
     84        (WebKit::QtTcpServerHandler::handleNewConnection):
     85        (WebKit::QtTcpServerHandler::listen):
     86        (WebKit::QtTcpServerHandler::close):
     87        * UIProcess/InspectorServer/qt/WebSocketServerQt.h: Added.
     88        (WebKit):
     89        (QtTcpServerHandler):
     90
     91        * WebKit2.pri:
     92        * config.h: Add ENABLE(INSPECTOR_SERVER) for WebKit2.
     93
    1942012-04-03  Jocelyn Turcotte  <jocelyn.turcotte@nokia.com>
    295
  • trunk/Source/WebKit2/Target.pri

    r112889 r113026  
    205205    UIProcess/GeolocationPermissionRequestManagerProxy.h \
    206206    UIProcess/GeolocationPermissionRequestProxy.h \
     207    UIProcess/InspectorServer/WebSocketServer.h \
     208    UIProcess/InspectorServer/WebSocketServerClient.h \
     209    UIProcess/InspectorServer/WebSocketServerConnection.h \
     210    UIProcess/InspectorServer/qt/WebSocketServerQt.h \
    207211    UIProcess/Launcher/ProcessLauncher.h \
    208212    UIProcess/Launcher/ThreadLauncher.h \
     
    542546    UIProcess/GeolocationPermissionRequestManagerProxy.cpp \
    543547    UIProcess/GeolocationPermissionRequestProxy.cpp \
     548    UIProcess/InspectorServer/WebSocketServer.cpp \
     549    UIProcess/InspectorServer/WebSocketServerConnection.cpp \
     550    UIProcess/InspectorServer/qt/WebSocketServerQt.cpp \
    544551    UIProcess/Launcher/ProcessLauncher.cpp \
    545552    UIProcess/Launcher/ThreadLauncher.cpp \
  • trunk/Source/WebKit2/WebKit2.pri

    r111783 r113026  
    2828    $$SOURCE_DIR/UIProcess/Authentication \
    2929    $$SOURCE_DIR/UIProcess/Downloads \
     30    $$SOURCE_DIR/UIProcess/InspectorServer \
     31    $$SOURCE_DIR/UIProcess/InspectorServer/qt \
    3032    $$SOURCE_DIR/UIProcess/Launcher \
    3133    $$SOURCE_DIR/UIProcess/Notifications \
  • trunk/Source/WebKit2/config.h

    r105203 r113026  
    136136
    137137#define PLUGIN_ARCHITECTURE(ARCH) (defined PLUGIN_ARCHITECTURE_##ARCH && PLUGIN_ARCHITECTURE_##ARCH)
     138
     139#ifndef ENABLE_INSPECTOR_SERVER
     140#if PLATFORM(QT)
     141#define ENABLE_INSPECTOR_SERVER 1
     142#endif
     143#endif
Note: See TracChangeset for help on using the changeset viewer.