[webkit-qt] Webkit remote inspector in QtWebkit, does it work ?

Stephane Cerveau scerveau at connected-labs.com
Tue Aug 21 03:16:09 PDT 2012


Dear all,

I'm currently trying to use the webkit remote inspector using websocket. 
I can see that an implementation is available in 
Source/Webkit/qt/WebcoreSupport but i'm facing some problem to use it.

Here is my command line to launch the remote inspector
./QtTestBrowser -remote-inspector-port 9222 http://www.google.fr

When i'm launching another browser such as Chrome, i start with white 
page with www.google.fr and when i'm clicking on it, i'm getting a 
websocket error.

I fixed this error with this patch:
/diff --git a/Source/WebKit/qt/WebCoreSupport/InspectorServerQt.cpp 
b/Source/WebKit/qt/WebCoreSupport/InspectorServerQt.cpp
index 14f5dd7..95e2781 100644
--- a/Source/WebKit/qt/WebCoreSupport/InspectorServerQt.cpp
+++ b/Source/WebKit/qt/WebCoreSupport/InspectorServerQt.cpp

@@ -192,7 +193,9 @@ void InspectorServerRequestHandlerQt::tcpReadyRead()
                  m_path = header.path();
                  m_contentType = header.contentType().toLatin1();
                  m_contentLength = header.contentLength();
-                if (header.hasKey(QLatin1String("Upgrade")) && 
(header.value(QLatin1String("Upgrade")) == QLatin1String("WebSocket")))
+                if (header.hasKey(QLatin1String("Upgrade")) && 
(header.value(QLatin1String("Upgrade")).toLower() == 
QLatin1String("websocket")))
                      isWebSocket = true;/

Then i encounter an issue with websocket handshake where the header 
missed Sec-WebSocket-Accept in the answer:

/diff --git a/Source/WebKit/qt/WebCoreSupport/InspectorServerQt.cpp 
b/Source/WebKit/qt/WebCoreSupport/InspectorServerQt.cpp
index 14f5dd7..95e2781 100644
--- a/Source/WebKit/qt/WebCoreSupport/InspectorServerQt.cpp
+++ b/Source/WebKit/qt/WebCoreSupport/InspectorServerQt.cpp
@@ -225,6 +228,8 @@ void InspectorServerRequestHandlerQt::tcpReadyRead()
responseHeader.setValue(QLatin1String("Connection"), 
header.value(QLatin1String("Connection")));
responseHeader.setValue(QLatin1String("Sec-WebSocket-Origin"), 
header.value(QLatin1String("Origin")));
responseHeader.setValue(QLatin1String("Sec-WebSocket-Location"), 
(QLatin1String("ws://") + header.value(QLatin1String("Host")) + m_path));
+                QString acceptSec = 
getExpectedWebSocketAccept(header.value(QLatin1String("Sec-WebSocket-Key")));
+ responseHeader.setValue(QLatin1String("Sec-WebSocket-Accept"), acceptSec);
responseHeader.setContentLength(response.size());
m_tcpConnection->write(responseHeader.toString().toLatin1());
                  m_tcpConnection->write(response);
@@ -298,6 +303,22 @@ void InspectorServerRequestHandlerQt::tcpReadyRead()
      }
  }

+QString 
InspectorServerRequestHandlerQt::getExpectedWebSocketAccept(const 
QString& secWebSocketKey)
+{
+    static const char* const webSocketKeyGUID = 
"258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
+    static const size_t sha1HashSize = 20; // FIXME: This should be 
defined in SHA1.h.
+    SHA1 sha1;
+    QString keyData = secWebSocketKey;
+    sha1.addBytes(reinterpret_cast<const 
uint8_t*>(keyData.toAscii().data()), keyData.length());
+    sha1.addBytes(reinterpret_cast<const uint8_t*>(webSocketKeyGUID), 
strlen(webSocketKeyGUID));
+    Vector<uint8_t, sha1HashSize> hash;
+    sha1.computeHash(hash);
+    QByteArray theHash(reinterpret_cast<const char*>(hash.data()), 
sha1HashSize);
+    //return base64Encode(reinterpret_cast<const char*>(hash.data()), 
sha1HashSize);
+    QString theResult = QString::fromAscii(theHash.toBase64());
+    return theResult;
+}/

And now the message received from the client is not handled correctly, 
crashing in webSocketReadyRead on  Q_ASSERT(!m_data[0]);

So i'm wondering if anybody is using this functionnality or this is only 
a beta code.
Any help would be appreciated :)

Stéphane.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-qt/attachments/20120821/0ac8881c/attachment.html>


More information about the webkit-qt mailing list