[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

kenneth at webkit.org kenneth at webkit.org
Wed Apr 7 23:14:28 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit 58156c8b8026d36718d36de3fd7109c9b485151b
Author: kenneth at webkit.org <kenneth at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Oct 29 14:43:18 2009 +0000

    Remove QWebView::guessUrlFromString() and replace its use
    with the new QUrl::fromUserInput() if using Qt 4.6 or newer.
    
    Patch by Kenneth Rohde Christiansen <kenneth at webkit.org> on 2009-10-29
    Reviewed by Tor Arne Vestbø.
    
    * Api/qwebview.cpp:
    * Api/qwebview.h:
    * QGVLauncher/main.cpp:
    (urlFromUserInput):
    (WebPage::applyProxy):
    (MainWindow::load):
    * QtLauncher/main.cpp:
    (urlFromUserInput):
    (MainWindow::MainWindow):
    (MainWindow::changeLocation):
    * tests/qwebview/tst_qwebview.cpp:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@50270 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/qt/Api/qwebview.cpp b/WebKit/qt/Api/qwebview.cpp
index 4fa073d..48de8c6 100644
--- a/WebKit/qt/Api/qwebview.cpp
+++ b/WebKit/qt/Api/qwebview.cpp
@@ -328,79 +328,6 @@ void QWebView::setPage(QWebPage* page)
 }
 
 /*!
-    Returns a valid URL from a user supplied \a string if one can be deducted.
-    In the case that is not possible, an invalid QUrl() is returned.
-
-    \since 4.6
-
-    Most applications that can browse the web, allow the user to input a URL
-    in the form of a plain string. This string can be manually typed into
-    a location bar, obtained from the clipboard, or passed in via command
-    line arguments.
-
-    When the string is not already a valid URL, a best guess is performed,
-    making various web related assumptions.
-
-    In the case the string corresponds to a valid file path on the system,
-    a file:// URL is constructed, using QUrl::fromLocalFile().
-
-    If that is not the case, an attempt is made to turn the string into a
-    http:// or ftp:// URL. The latter in the case the string starts with
-    'ftp'. The result is then passed through QUrl's tolerant parser, and
-    in the case or success, a valid QUrl is returned, or else a QUrl().
-
-    \section1 Examples:
-
-    \list
-    \o webkit.org becomes http://webkit.org
-    \o ftp.webkit.org becomes ftp://ftp.webkit.org
-    \o localhost becomes http://localhost
-    \o /home/user/test.html becomes file:///home/user/test.html (if exists)
-    \endlist
-
-    \section2 Tips when dealing with URLs and strings:
-
-    \list
-    \o When creating a QString from a QByteArray or a char*, always use
-      QString::fromUtf8().
-    \o Do not use QUrl(string), nor QUrl::toString() anywhere where the URL might
-       be used, such as in the location bar, as those functions loose data.
-       Instead use QUrl::fromEncoded() and QUrl::toEncoded(), respectively.
-    \endlist
- */
-QUrl QWebView::guessUrlFromString(const QString &string)
-{
-    QString trimmedString = string.trimmed();
-
-    // Check the most common case of a valid url with scheme and host first
-    QUrl url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode);
-    if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty())
-        return url;
-
-    // Absolute files that exists
-    if (QDir::isAbsolutePath(trimmedString) && QFile::exists(trimmedString))
-        return QUrl::fromLocalFile(trimmedString);
-
-    // If the string is missing the scheme or the scheme is not valid prepend a scheme
-    QString scheme = url.scheme();
-    if (scheme.isEmpty() || scheme.contains(QLatin1Char('.')) || scheme == QLatin1String("localhost")) {
-        // Do not do anything for strings such as "foo", only "foo.com"
-        int dotIndex = trimmedString.indexOf(QLatin1Char('.'));
-        if (dotIndex != -1 || trimmedString.startsWith(QLatin1String("localhost"))) {
-            const QString hostscheme = trimmedString.left(dotIndex).toLower();
-            QByteArray scheme = (hostscheme == QLatin1String("ftp")) ? "ftp" : "http";
-            trimmedString = QLatin1String(scheme) + QLatin1String("://") + trimmedString;
-        }
-        url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode);
-    }
-
-    if (url.isValid())
-        return url;
-
-    return QUrl();
-}
-
-/*!
     Loads the specified \a url and displays it.
 
     \note The view remains the same until enough data has arrived to display the new \a url.
diff --git a/WebKit/qt/Api/qwebview.h b/WebKit/qt/Api/qwebview.h
index b63a593..e9c1ec8 100644
--- a/WebKit/qt/Api/qwebview.h
+++ b/WebKit/qt/Api/qwebview.h
@@ -65,8 +65,6 @@ public:
     QWebPage* page() const;
     void setPage(QWebPage* page);
 
-    static QUrl guessUrlFromString(const QString& string);
-
     void load(const QUrl& url);
 #if QT_VERSION < 0x040400 && !defined(qdoc)
     void load(const QWebNetworkRequest& request);
diff --git a/WebKit/qt/ChangeLog b/WebKit/qt/ChangeLog
index fc2913d..b19a1d0 100644
--- a/WebKit/qt/ChangeLog
+++ b/WebKit/qt/ChangeLog
@@ -1,3 +1,22 @@
+2009-10-29  Kenneth Rohde Christiansen  <kenneth at webkit.org>
+
+        Reviewed by Tor Arne Vestbø.
+
+        Remove QWebView::guessUrlFromString() and replace its use
+        with the new QUrl::fromUserInput() if using Qt 4.6 or newer.
+
+        * Api/qwebview.cpp:
+        * Api/qwebview.h:
+        * QGVLauncher/main.cpp:
+        (urlFromUserInput):
+        (WebPage::applyProxy):
+        (MainWindow::load):
+        * QtLauncher/main.cpp:
+        (urlFromUserInput):
+        (MainWindow::MainWindow):
+        (MainWindow::changeLocation):
+        * tests/qwebview/tst_qwebview.cpp:
+
 2009-10-28  Kenneth Rohde Christiansen  <kenneth at webkit.org>
 
         Reviewed by Tor Arne Vestbø.
diff --git a/WebKit/qt/QGVLauncher/main.cpp b/WebKit/qt/QGVLauncher/main.cpp
index 3632a33..2021cb6 100644
--- a/WebKit/qt/QGVLauncher/main.cpp
+++ b/WebKit/qt/QGVLauncher/main.cpp
@@ -50,6 +50,20 @@
 #include <qwebsettings.h>
 #include <qwebview.h>
 
+static QUrl urlFromUserInput(const QString& string)
+{
+    QString input(string);
+    QFileInfo fi(input);
+    if (fi.exists() && fi.isRelative())
+        input = fi.absoluteFilePath();
+
+#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
+    return QUrl::fromUserInput(input);
+#else
+    return QUrl(input);
+#endif
+}
+
 class WebView : public QGraphicsWebView {
     Q_OBJECT
     Q_PROPERTY(qreal yRotation READ yRotation WRITE setYRotation)
@@ -93,7 +107,7 @@ public:
 private:
     void applyProxy()
     {
-        QUrl proxyUrl = QWebView::guessUrlFromString(qgetenv("http_proxy"));
+        QUrl proxyUrl = urlFromUserInput(qgetenv("http_proxy"));
 
         if (proxyUrl.isValid() && !proxyUrl.host().isEmpty()) {
             int proxyPort = (proxyUrl.port() > 0) ? proxyUrl.port() : 8080;
@@ -278,7 +292,7 @@ public:
 
     void load(const QString& url)
     {
-        QUrl deducedUrl = guessUrlFromString(url);
+        QUrl deducedUrl = urlFromUserInput(url);
         if (!deducedUrl.isValid())
             deducedUrl = QUrl("http://" + url + "/");
 
@@ -287,16 +301,6 @@ public:
         scene->webView()->setFocus(Qt::OtherFocusReason);
     }
 
-    QUrl guessUrlFromString(const QString& string)
-    {
-        QString input(string);
-        QFileInfo fi(input);
-        if (fi.exists() && fi.isRelative())
-            input = fi.absoluteFilePath();
-
-        return QWebView::guessUrlFromString(input);
-    }
-
     QWebPage* page() const
     {
         return scene->webView()->page();
diff --git a/WebKit/qt/QtLauncher/main.cpp b/WebKit/qt/QtLauncher/main.cpp
index e3c6116..dd914fd 100644
--- a/WebKit/qt/QtLauncher/main.cpp
+++ b/WebKit/qt/QtLauncher/main.cpp
@@ -58,6 +58,15 @@
 void QWEBKIT_EXPORT qt_drt_garbageCollector_collect();
 #endif
 
+static QUrl urlFromUserInput(const QString& input)
+{
+#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
+    return QUrl::fromUserInput(input);
+#else
+    return QUrl(input);
+#endif
+}
+
 class WebPage : public QWebPage
 {
 public:
@@ -106,7 +115,8 @@ public:
         setupUI();
 
         // set the proxy to the http_proxy env variable - if present
-        QUrl proxyUrl = view->guessUrlFromString(qgetenv("http_proxy"));
+        QUrl proxyUrl = urlFromUserInput(qgetenv("http_proxy"));
+
         if (proxyUrl.isValid() && !proxyUrl.host().isEmpty()) {
             int proxyPort = (proxyUrl.port() > 0)  ? proxyUrl.port() : 8080;
             page->networkAccessManager()->setProxy(QNetworkProxy(QNetworkProxy::HttpProxy, proxyUrl.host(), proxyPort));
@@ -116,7 +126,7 @@ public:
         if (fi.exists() && fi.isRelative())
             url = fi.absoluteFilePath();
 
-        QUrl qurl = view->guessUrlFromString(url);
+        QUrl qurl = urlFromUserInput(url);
         if (qurl.isValid()) {
             urlEdit->setText(qurl.toEncoded());
             view->load(qurl);
@@ -141,7 +151,7 @@ protected slots:
 
     void changeLocation() {
         QString string = urlEdit->text();
-        QUrl url = view->guessUrlFromString(string);
+        QUrl url = urlFromUserInput(string);
         if (!url.isValid())
             url = QUrl("http://" + string + "/");
         urlEdit->setText(url.toEncoded());
diff --git a/WebKit/qt/tests/qwebview/tst_qwebview.cpp b/WebKit/qt/tests/qwebview/tst_qwebview.cpp
index 9204223..fda979e 100644
--- a/WebKit/qt/tests/qwebview/tst_qwebview.cpp
+++ b/WebKit/qt/tests/qwebview/tst_qwebview.cpp
@@ -41,8 +41,6 @@ public slots:
 
 private slots:
     void renderHints();
-    void guessUrlFromString_data();
-    void guessUrlFromString();
     void getWebKitVersion();
 
     void reusePage_data();
@@ -105,68 +103,6 @@ void tst_QWebView::renderHints()
     QVERIFY(!(webView.renderHints() & QPainter::HighQualityAntialiasing));
 }
 
-void tst_QWebView::guessUrlFromString_data()
-{
-    QTest::addColumn<QString>("string");
-    QTest::addColumn<QUrl>("guessUrlFromString");
-
-    // Null
-    QTest::newRow("null") << QString() << QUrl();
-
-    // File
-    QDirIterator it(QDir::homePath());
-    QString fileString;
-    int c = 0;
-    while (it.hasNext()) {
-        it.next();
-        QTest::newRow(QString("file-%1").arg(c++).toLatin1()) << it.filePath() << QUrl::fromLocalFile(it.filePath());
-    }
-
-    // basic latin1
-    QTest::newRow("unicode-0") << QString::fromUtf8("å.com/") << QUrl::fromEncoded(QString::fromUtf8("http://å.com/").toUtf8(), QUrl::TolerantMode);
-    // unicode
-    QTest::newRow("unicode-1") << QString::fromUtf8("λ.com/") << QUrl::fromEncoded(QString::fromUtf8("http://λ.com/").toUtf8(), QUrl::TolerantMode);
-
-    // no scheme
-    QTest::newRow("add scheme-0") << "webkit.org" << QUrl("http://webkit.org");
-    QTest::newRow("add scheme-1") << "www.webkit.org" << QUrl("http://www.webkit.org");
-    QTest::newRow("add scheme-2") << "ftp.webkit.org" << QUrl("ftp://ftp.webkit.org");
-    QTest::newRow("add scheme-3") << "webkit" << QUrl("webkit");
-
-    // QUrl's tolerant parser should already handle this
-    QTest::newRow("not-encoded-0") << "http://webkit.org/test page.html" << QUrl("http://webkit.org/test%20page.html");
-
-    // Make sure the :80, i.e. port doesn't screw anything up
-    QUrl portUrl("http://webkit.org");
-    portUrl.setPort(80);
-    QTest::newRow("port-0") << "webkit.org:80" << portUrl;
-    QTest::newRow("port-1") << "http://webkit.org:80" << portUrl;
-
-    // mailto doesn't have a ://, but is valid
-    QUrl mailto("ben at meyerhome.net");
-    mailto.setScheme("mailto");
-    QTest::newRow("mailto") << "mailto:ben at meyerhome.net" << mailto;
-
-    // misc
-    QTest::newRow("localhost-0") << "localhost" << QUrl("http://localhost");
-    QTest::newRow("localhost-1") << "localhost:80" << QUrl("http://localhost:80");
-    QTest::newRow("spaces-0") << "  http://webkit.org/test page.html " << QUrl("http://webkit.org/test%20page.html");
-
-    // FYI: The scheme in the resulting url user
-    QUrl authUrl("user:pass at domain.com");
-    QTest::newRow("misc-1") << "user:pass at domain.com" << authUrl;
-}
-
-// public static QUrl guessUrlFromString(QString const& string)
-void tst_QWebView::guessUrlFromString()
-{
-    QFETCH(QString, string);
-    QFETCH(QUrl, guessUrlFromString);
-
-    QUrl url = QWebView::guessUrlFromString(string);
-    QCOMPARE(url, guessUrlFromString);
-}
-
 void tst_QWebView::getWebKitVersion()
 {
     QVERIFY(qWebKitVersion().toDouble() > 0);

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list