1 /* 2 Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Library General Public 6 License as published by the Free Software Foundation; either 7 version 2 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Library General Public License for more details. 13 14 You should have received a copy of the GNU Library General Public License 15 along with this library; see the file COPYING.LIB. If not, write to 16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 Boston, MA 02110-1301, USA. 18 */ 19 20 #ifndef InspectorServerQt_h 21 #define InspectorServerQt_h 22 23 #include <QList> 24 #include <QMap> 25 #include <QObject> 26 #include <QPair> 27 #include <QString> 28 #include <wtf/Forward.h> 29 30 QT_BEGIN_NAMESPACE 31 class QTcpServer; 32 class QTcpSocket; 33 QT_END_NAMESPACE 34 class QWebPage; 35 36 namespace WebCore { 37 class InspectorServerRequestHandlerQt; 38 class InspectorClientQt; 39 40 class InspectorServerQt : public QObject { 41 Q_OBJECT 42 public: 43 44 static InspectorServerQt* server(); 45 46 void listen(quint16 port); 47 48 void registerClient(InspectorClientQt* client); 49 void unregisterClient(InspectorClientQt* client); 50 51 void close(); 52 InspectorClientQt* inspectorClientForPage(int pageNum); 53 54 protected: 55 InspectorServerQt(); 56 virtual ~InspectorServerQt(); 57 58 private slots: 59 void newConnection(); 60 61 private: 62 QTcpServer* m_tcpServer; 63 QMap<int, InspectorClientQt*> m_inspectorClients; 64 int m_pageNumber; 65 66 friend class InspectorServerRequestHandlerQt; 67 }; 68 69 class RemoteFrontendChannel : public QObject { 70 Q_OBJECT 71 public: 72 73 RemoteFrontendChannel(InspectorServerRequestHandlerQt* requestHandler); 74 bool sendMessageToFrontend(const String& message); 75 76 private: 77 InspectorServerRequestHandlerQt* m_requestHandler; 78 }; 79 80 class InspectorServerRequestHandlerQt : public QObject { 81 Q_OBJECT 82 public: 83 84 InspectorServerRequestHandlerQt(QTcpSocket *tcpConnection, InspectorServerQt *server); 85 virtual ~InspectorServerRequestHandlerQt(); 86 virtual int webSocketSend(QByteArray payload); 87 virtual int webSocketSend(const char *payload, size_t length); 88 89 private slots: 90 void tcpReadyRead(); 91 void tcpConnectionDisconnected(); 92 void webSocketReadyRead(); 93 94 private: 95 QTcpSocket* m_tcpConnection; 96 InspectorServerQt* m_server; 97 98 QString m_path; 99 QByteArray m_contentType; 100 int m_contentLength; 101 bool m_endOfHeaders; 102 QByteArray m_data; 103 InspectorClientQt* m_inspectorClient; 104 105 void handleInspectorRequest(QStringList words); 106 void handleFromFrontendRequest(); 107 void handleResourceRequest(QStringList words); 108 109 }; 110 111 } 112 #endif 113