Title: [104680] trunk/Source/WebKit
Revision
104680
Author
[email protected]
Date
2012-01-11 01:02:18 -0800 (Wed, 11 Jan 2012)

Log Message

[Qt][WK2] Fix the build for newer Qt5
https://bugs.webkit.org/show_bug.cgi?id=75964

Patch by Rafael Brandao <[email protected]> on 2012-01-11
Reviewed by Simon Hausmann.

Source/WebKit:

* WebKit.pri: Added the new files to the buildsystem.

Source/WebKit/qt:

Added QHttpHeader, QHttpResponseHeader and QHttpRequestHeader
that were removed from Qt. They are now kept under a private header
and only the relevant code is present.

* Api/qhttpheader.cpp: Added.
(QHttpHeader::QHttpHeader):
(QHttpHeader::~QHttpHeader):
(QHttpHeader::parse):
(QHttpHeader::value):
(QHttpHeader::hasKey):
(QHttpHeader::setValue):
(QHttpHeader::addValue):
(QHttpHeader::parseLine):
(QHttpHeader::toString):
(QHttpHeader::hasContentLength):
(QHttpHeader::contentLength):
(QHttpHeader::setContentLength):
(QHttpHeader::hasContentType):
(QHttpHeader::contentType):
(QHttpHeader::setContentType):
(QHttpResponseHeader::QHttpResponseHeader):
(QHttpResponseHeader::parseLine):
(QHttpResponseHeader::toString):
(QHttpRequestHeader::QHttpRequestHeader):
(QHttpRequestHeader::parseLine):
(QHttpRequestHeader::toString):
* Api/qhttpheader_p.h: Added.
(QHttpHeader::isValid):
(QHttpHeader::setValid):
(QHttpResponseHeader::statusCode):
(QHttpResponseHeader::reasonPhrase):
(QHttpResponseHeader::majorVersion):
(QHttpResponseHeader::minorVersion):
(QHttpRequestHeader::method):
(QHttpRequestHeader::path):
(QHttpRequestHeader::majorVersion):
(QHttpRequestHeader::minorVersion):
* WebCoreSupport/InspectorServerQt.cpp:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (104679 => 104680)


--- trunk/Source/WebKit/ChangeLog	2012-01-11 08:40:32 UTC (rev 104679)
+++ trunk/Source/WebKit/ChangeLog	2012-01-11 09:02:18 UTC (rev 104680)
@@ -1,3 +1,12 @@
+2012-01-11  Rafael Brandao  <[email protected]>
+
+        [Qt][WK2] Fix the build for newer Qt5
+        https://bugs.webkit.org/show_bug.cgi?id=75964
+
+        Reviewed by Simon Hausmann.
+
+        * WebKit.pri: Added the new files to the buildsystem.
+
 2012-01-10  Mike Lattanzio  <[email protected]>
 
         [BlackBerry] Fix assertion failure in BackingStore::blitContents

Modified: trunk/Source/WebKit/WebKit.pri (104679 => 104680)


--- trunk/Source/WebKit/WebKit.pri	2012-01-11 08:40:32 UTC (rev 104679)
+++ trunk/Source/WebKit/WebKit.pri	2012-01-11 09:02:18 UTC (rev 104680)
@@ -13,7 +13,8 @@
     $$PWD/qt/Api/qwebscriptworld.cpp \
     $$PWD/qt/Api/qwebdatabase.cpp \
     $$PWD/qt/Api/qwebinspector.cpp \
-    $$PWD/qt/Api/qwebkitversion.cpp
+    $$PWD/qt/Api/qwebkitversion.cpp \
+    $$PWD/qt/Api/qhttpheader.cpp
 
 HEADERS += \
     $$PWD/qt/Api/qwebframe.h \
@@ -32,5 +33,6 @@
     $$PWD/qt/Api/qwebhistory.h \
     $$PWD/qt/Api/qwebinspector.h \
     $$PWD/qt/Api/qwebkitversion.h \
-    $$PWD/qt/Api/qwebplugindatabase_p.h
+    $$PWD/qt/Api/qwebplugindatabase_p.h \
+    $$PWD/qt/Api/qhttpheader_p.h
 

Added: trunk/Source/WebKit/qt/Api/qhttpheader.cpp (0 => 104680)


--- trunk/Source/WebKit/qt/Api/qhttpheader.cpp	                        (rev 0)
+++ trunk/Source/WebKit/qt/Api/qhttpheader.cpp	2012-01-11 09:02:18 UTC (rev 104680)
@@ -0,0 +1,273 @@
+/*
+    Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+
+    These were part of the QtNetwork module of the Qt Toolkit.
+
+    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 library 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 library; 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 "qhttpheader_p.h"
+
+using namespace WebKit;
+
+static QString contentLengthString = QLatin1String("content-length");
+static QString contentTypeString = QLatin1String("content-type");
+
+QHttpHeader::QHttpHeader()
+{
+    setValid(true);
+}
+
+QHttpHeader::QHttpHeader(const QString& str)
+{
+    setValid(true);
+    parse(str);
+}
+
+QHttpHeader::~QHttpHeader()
+{
+}
+
+bool QHttpHeader::parse(const QString& str)
+{
+    QStringList lst;
+    int pos = str.indexOf(QLatin1Char('\n'));
+    if (pos > 0 && str.at(pos - 1) == QLatin1Char('\r'))
+        lst = str.trimmed().split(QLatin1String("\r\n"));
+    else
+        lst = str.trimmed().split(QLatin1String("\n"));
+    lst.removeAll(QString());
+
+    if (lst.isEmpty())
+        return true;
+
+    QStringList lines;
+    QStringList::Iterator it = lst.begin();
+    for (; it != lst.end(); ++it) {
+        if (!(*it).isEmpty()) {
+            if ((*it)[0].isSpace()) {
+                if (!lines.isEmpty()) {
+                    lines.last() += QLatin1Char(' ');
+                    lines.last() += (*it).trimmed();
+                }
+            } else
+                lines.append((*it));
+        }
+    }
+
+    int number = 0;
+    for (it = lines.begin(); it != lines.end(); ++it) {
+        if (!parseLine(*it, number++)) {
+            setValid(false);
+            return false;
+        }
+    }
+    return true;
+}
+
+QString QHttpHeader::value(const QString& key) const
+{
+    QString lowercaseKey = key.toLower();
+    QList<QPair<QString, QString> >::ConstIterator it = m_values.constBegin();
+    while (it != m_values.constEnd()) {
+        if ((*it).first.toLower() == lowercaseKey)
+            return (*it).second;
+        ++it;
+    }
+    return QString();
+}
+
+bool QHttpHeader::hasKey(const QString& key) const
+{
+    QString lowercaseKey = key.toLower();
+    QList<QPair<QString, QString> >::ConstIterator it = m_values.constBegin();
+    while (it != m_values.constEnd()) {
+        if ((*it).first.toLower() == lowercaseKey)
+            return true;
+        ++it;
+    }
+    return false;
+}
+
+void QHttpHeader::setValue(const QString& key, const QString& value)
+{
+    QString lowercaseKey = key.toLower();
+    QList<QPair<QString, QString> >::Iterator it = m_values.begin();
+    while (it != m_values.end()) {
+        if ((*it).first.toLower() == lowercaseKey) {
+            (*it).second = value;
+            return;
+        }
+        ++it;
+    }
+    addValue(key, value);
+}
+
+void QHttpHeader::addValue(const QString& key, const QString& value)
+{
+    m_values.append(qMakePair(key, value));
+}
+
+bool QHttpHeader::parseLine(const QString& line, int)
+{
+    int i = line.indexOf(QLatin1Char(':'));
+    if (i == -1)
+        return false;
+
+    addValue(line.left(i).trimmed(), line.mid(i + 1).trimmed());
+    return true;
+}
+
+QString QHttpHeader::toString() const
+{
+    if (!isValid())
+        return QLatin1String("");
+
+    QString ret = QLatin1String("");
+
+    QList<QPair<QString, QString> >::ConstIterator it = m_values.constBegin();
+    while (it != m_values.constEnd()) {
+        ret += (*it).first + QLatin1String(": ") + (*it).second + QLatin1String("\r\n");
+        ++it;
+    }
+    return ret;
+}
+
+bool QHttpHeader::hasContentLength() const
+{
+    return hasKey(contentLengthString);
+}
+
+uint QHttpHeader::contentLength() const
+{
+    return value(contentLengthString).toUInt();
+}
+
+void QHttpHeader::setContentLength(int len)
+{
+    setValue(contentLengthString, QString::number(len));
+}
+
+bool QHttpHeader::hasContentType() const
+{
+    return hasKey(contentTypeString);
+}
+
+QString QHttpHeader::contentType() const
+{
+    QString type = value(contentTypeString);
+    if (type.isEmpty())
+        return QString();
+
+    int pos = type.indexOf(QLatin1Char(';'));
+    if (pos == -1)
+        return type;
+
+    return type.left(pos).trimmed();
+}
+
+void QHttpHeader::setContentType(const QString &type)
+{
+    setValue(contentTypeString, type);
+}
+
+QHttpResponseHeader::QHttpResponseHeader(int code, const QString &text, int majorVer, int minorVer)
+    : QHttpHeader()
+    , m_statusCode(code)
+    , m_reasonPhrase(text)
+    , m_majorVersion(majorVer)
+    , m_minorVersion(minorVer)
+{
+}
+
+bool QHttpResponseHeader::parseLine(const QString& line, int number)
+{
+    if (number)
+        return QHttpHeader::parseLine(line, number);
+
+    QString l = line.simplified();
+    if (l.length() < 10)
+        return false;
+
+    if (l.left(5) == QLatin1String("HTTP/") && l[5].isDigit() && l[6] == QLatin1Char('.')
+            && l[7].isDigit() && l[8] == QLatin1Char(' ') && l[9].isDigit()) {
+        m_majorVersion = l[5].toLatin1() - '0';
+        m_minorVersion = l[7].toLatin1() - '0';
+
+        int pos = l.indexOf(QLatin1Char(' '), 9);
+        if (pos != -1) {
+            m_reasonPhrase = l.mid(pos + 1);
+            m_statusCode = l.mid(9, pos - 9).toInt();
+        } else {
+            m_statusCode = l.mid(9).toInt();
+            m_reasonPhrase.clear();
+        }
+    } else
+        return false;
+
+    return true;
+}
+
+QString QHttpResponseHeader::toString() const
+{
+    static QString ret(QLatin1String("HTTP/%1.%2 %3 %4\r\n%5\r\n"));
+    return ret.arg(m_majorVersion).arg(m_minorVersion).arg(m_statusCode).arg(m_reasonPhrase).arg(QHttpHeader::toString());
+}
+
+QHttpRequestHeader::QHttpRequestHeader()
+    : QHttpHeader()
+{
+    setValid(false);
+}
+
+QHttpRequestHeader::QHttpRequestHeader(const QString& str)
+{
+    parse(str);
+}
+
+bool QHttpRequestHeader::parseLine(const QString& line, int number)
+{
+    if (number)
+        return QHttpHeader::parseLine(line, number);
+
+    QStringList lst = line.simplified().split(QLatin1String(" "));
+    if (lst.count() > 0) {
+        m_method = lst[0];
+        if (lst.count() > 1) {
+            m_path = lst[1];
+            if (lst.count() > 2) {
+                QString v = lst[2];
+                if (v.length() >= 8 && v.left(5) == QLatin1String("HTTP/")
+                        && v[5].isDigit() && v[6] == QLatin1Char('.') && v[7].isDigit()) {
+                    m_majorVersion = v[5].toLatin1() - '0';
+                    m_minorVersion = v[7].toLatin1() - '0';
+                    return true;
+                }
+            }
+        }
+    }
+
+    return false;
+}
+
+QString QHttpRequestHeader::toString() const
+{
+    static QString first(QLatin1String("%1 %2"));
+    static QString last(QLatin1String(" HTTP/%3.%4\r\n%5\r\n"));
+    return first.arg(m_method).arg(m_path) + last.arg(m_majorVersion).arg(m_minorVersion).arg(QHttpHeader::toString());
+}
+

Added: trunk/Source/WebKit/qt/Api/qhttpheader_p.h (0 => 104680)


--- trunk/Source/WebKit/qt/Api/qhttpheader_p.h	                        (rev 0)
+++ trunk/Source/WebKit/qt/Api/qhttpheader_p.h	2012-01-11 09:02:18 UTC (rev 104680)
@@ -0,0 +1,112 @@
+/*
+    Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+
+    These were part of the QtNetwork module of the Qt Toolkit.
+
+    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 library 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 library; 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 qhttpheader_p_h
+#define qhttpheader_p_h
+
+#include <QPair>
+#include <QString>
+#include <QStringList>
+
+namespace WebKit {
+
+class QHttpHeader {
+public:
+    QHttpHeader();
+    QHttpHeader(const QString&);
+    virtual ~QHttpHeader();
+
+    void setValue(const QString& key, const QString& value);
+    void addValue(const QString& key, const QString& value);
+    QString value(const QString& key) const;
+    bool hasKey(const QString&) const;
+
+    // ### Qt 5: change to qint64
+    bool hasContentLength() const;
+    uint contentLength() const;
+    void setContentLength(int);
+
+    bool hasContentType() const;
+    QString contentType() const;
+    void setContentType(const QString&);
+
+    virtual QString toString() const;
+    bool isValid() const { return m_valid; }
+
+    virtual int majorVersion() const = 0;
+    virtual int minorVersion() const = 0;
+
+protected:
+    virtual bool parseLine(const QString& line, int number);
+    bool parse(const QString&);
+    void setValid(bool v) { m_valid = v; }
+
+private:
+    bool m_valid;
+    QList<QPair<QString, QString> > m_values;
+};
+
+class QHttpResponseHeader : public QHttpHeader {
+public:
+    QHttpResponseHeader(int code, const QString& text = QString(), int majorVer = 1, int minorVer = 1);
+
+    int statusCode() const { return m_statusCode; }
+    QString reasonPhrase() const {return m_reasonPhrase; }
+    int majorVersion() const { return m_majorVersion; }
+    int minorVersion() const { return m_minorVersion; }
+
+    QString toString() const;
+
+protected:
+    bool parseLine(const QString& line, int number);
+
+private:
+    int m_statusCode;
+    QString m_reasonPhrase;
+    int m_majorVersion;
+    int m_minorVersion;
+};
+
+class QHttpRequestHeader : public QHttpHeader {
+public:
+    QHttpRequestHeader();
+    QHttpRequestHeader(const QString&);
+
+    QString method() const { return m_method; }
+    QString path() const { return m_path; }
+    int majorVersion() const { return m_majorVersion; }
+    int minorVersion() const { return m_minorVersion; }
+
+    QString toString() const;
+
+protected:
+    bool parseLine(const QString& line, int number);
+
+private:
+    QString m_method;
+    QString m_path;
+    int m_majorVersion;
+    int m_minorVersion;
+};
+
+}
+
+#endif

Modified: trunk/Source/WebKit/qt/ChangeLog (104679 => 104680)


--- trunk/Source/WebKit/qt/ChangeLog	2012-01-11 08:40:32 UTC (rev 104679)
+++ trunk/Source/WebKit/qt/ChangeLog	2012-01-11 09:02:18 UTC (rev 104680)
@@ -1,3 +1,49 @@
+2012-01-11  Rafael Brandao  <[email protected]>
+
+        [Qt][WK2] Fix the build for newer Qt5
+        https://bugs.webkit.org/show_bug.cgi?id=75964
+
+        Reviewed by Simon Hausmann.
+
+        Added QHttpHeader, QHttpResponseHeader and QHttpRequestHeader
+        that were removed from Qt. They are now kept under a private header
+        and only the relevant code is present.
+
+        * Api/qhttpheader.cpp: Added.
+        (QHttpHeader::QHttpHeader):
+        (QHttpHeader::~QHttpHeader):
+        (QHttpHeader::parse):
+        (QHttpHeader::value):
+        (QHttpHeader::hasKey):
+        (QHttpHeader::setValue):
+        (QHttpHeader::addValue):
+        (QHttpHeader::parseLine):
+        (QHttpHeader::toString):
+        (QHttpHeader::hasContentLength):
+        (QHttpHeader::contentLength):
+        (QHttpHeader::setContentLength):
+        (QHttpHeader::hasContentType):
+        (QHttpHeader::contentType):
+        (QHttpHeader::setContentType):
+        (QHttpResponseHeader::QHttpResponseHeader):
+        (QHttpResponseHeader::parseLine):
+        (QHttpResponseHeader::toString):
+        (QHttpRequestHeader::QHttpRequestHeader):
+        (QHttpRequestHeader::parseLine):
+        (QHttpRequestHeader::toString):
+        * Api/qhttpheader_p.h: Added.
+        (QHttpHeader::isValid):
+        (QHttpHeader::setValid):
+        (QHttpResponseHeader::statusCode):
+        (QHttpResponseHeader::reasonPhrase):
+        (QHttpResponseHeader::majorVersion):
+        (QHttpResponseHeader::minorVersion):
+        (QHttpRequestHeader::method):
+        (QHttpRequestHeader::path):
+        (QHttpRequestHeader::majorVersion):
+        (QHttpRequestHeader::minorVersion):
+        * WebCoreSupport/InspectorServerQt.cpp:
+
 2012-01-10  No'am Rosenthal  <[email protected]>
 
         [Qt] Enable CSS_FILTERS in Qt build

Modified: trunk/Source/WebKit/qt/WebCoreSupport/InspectorServerQt.cpp (104679 => 104680)


--- trunk/Source/WebKit/qt/WebCoreSupport/InspectorServerQt.cpp	2012-01-11 08:40:32 UTC (rev 104679)
+++ trunk/Source/WebKit/qt/WebCoreSupport/InspectorServerQt.cpp	2012-01-11 09:02:18 UTC (rev 104680)
@@ -24,12 +24,10 @@
 #include "InspectorController.h"
 #include "MD5.h"
 #include "Page.h"
+#include "qhttpheader_p.h"
 #include "qwebpage.h"
 #include "qwebpage_p.h"
 #include <QFile>
-#include <QHttpHeader>
-#include <QHttpRequestHeader>
-#include <QHttpResponseHeader>
 #include <QString>
 #include <QStringList>
 #include <QTcpServer>
@@ -176,7 +174,7 @@
 
 void InspectorServerRequestHandlerQt::tcpReadyRead()
 {
-    QHttpRequestHeader header;
+    WebKit::QHttpRequestHeader header;
     bool isWebSocket = false;
     if (!m_tcpConnection)
         return;
@@ -189,7 +187,7 @@
                 m_endOfHeaders = true;
         }
         if (m_endOfHeaders) {
-            header = QHttpRequestHeader(QString::fromLatin1(m_data));
+            header = WebKit::QHttpRequestHeader(QString::fromLatin1(m_data));
             if (header.isValid()) {
                 m_path = header.path();
                 m_contentType = header.contentType().toLatin1();
@@ -222,7 +220,7 @@
                 generateWebSocketChallengeResponse(number1, number2, (unsigned char*)key3.data(), (unsigned char*)responseData);
                 QByteArray response(responseData, sizeof(responseData));
 
-                QHttpResponseHeader responseHeader(101, QLatin1String("WebSocket Protocol Handshake"), 1, 1);
+                WebKit::QHttpResponseHeader responseHeader(101, QLatin1String("WebSocket Protocol Handshake"), 1, 1);
                 responseHeader.setValue(QLatin1String("Upgrade"), header.value(QLatin1String("Upgrade")));
                 responseHeader.setValue(QLatin1String("Connection"), header.value(QLatin1String("Connection")));
                 responseHeader.setValue(QLatin1String("Sec-WebSocket-Origin"), header.value(QLatin1String("Origin")));
@@ -284,7 +282,7 @@
             }
         }
 
-        QHttpResponseHeader responseHeader(code, text, 1, 0);
+        WebKit::QHttpResponseHeader responseHeader(code, text, 1, 0);
         responseHeader.setContentLength(response.size());
         if (!m_contentType.isEmpty())
             responseHeader.setContentType(QString::fromLatin1(m_contentType));
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to