Changeset 46364 in webkit


Ignore:
Timestamp:
Jul 24, 2009 10:55:49 AM (15 years ago)
Author:
kenneth@webkit.org
Message:

2009-07-24 Antonio Gomes <antonio.gomes@openbossa.org>

Reviewed by Simon Hausmann.

[QT] Implement originalUrl getter method to the API
https://bugs.webkit.org/show_bug.cgi?id=25867

  • Api/qwebframe.cpp: (QWebFrame::originalUrl):
  • Api/qwebframe.h:
  • tests/qwebframe/qwebframe.qrc:
  • tests/qwebframe/test1.html: Added.
  • tests/qwebframe/test2.html: Added.
  • tests/qwebframe/tst_qwebframe.cpp:
Location:
trunk/WebKit/qt
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/qt/Api/qwebframe.cpp

    r46170 r46364  
    281281    frames are related to a web page and web view.
    282282
     283    The QWebFrame class also offers methods to retrieve both the URL currently
     284    loaded by the frame (see url()) as well as the URL originally requested
     285    to be loaded (see originalUrl()). These methods make possible the retrieval
     286    of the URL before and after a DNS resolution or a redirection occurs during
     287    the load process. The originalUrl() also matches to the URL added to the
     288    frame history (\l{QwebHistory}) if load is successful.
     289
    283290    The title of an HTML frame can be accessed with the title() property.
    284291    Additionally, a frame may also specify an icon, which can be accessed
     
    522529
    523530/*!
     531    \since 4.6
     532    \property QWebFrame::originalUrl
     533
     534    The original url loaded by the frame currently viewed. The URL may differ from
     535    the one returned by url() if a DNS resolution or a redirection occurs.
     536
     537    \sa url(), setUrl()
     538*/
     539QUrl QWebFrame::originalUrl() const
     540{
     541    if (!d->frame->loader()->activeDocumentLoader()
     542        || !d->frameLoaderClient->m_loadSucceeded)
     543        return QUrl(d->frame->loader()->outgoingReferrer());
     544
     545    return d->frame->loader()->originalRequest().url();
     546}
     547/*!
     548    \since 4.6
    524549    \property QWebFrame::baseUrl
    525550    \brief the base URL of the frame, can be used to resolve relative URLs
  • trunk/WebKit/qt/Api/qwebframe.h

    r46170 r46364  
    108108    Q_PROPERTY(QString title READ title)
    109109    Q_PROPERTY(QUrl url READ url WRITE setUrl)
     110    Q_PROPERTY(QUrl originalUrl READ originalUrl)
    110111    Q_PROPERTY(QUrl baseUrl READ baseUrl)
    111112    Q_PROPERTY(QIcon icon READ icon)
     
    141142    void setUrl(const QUrl &url);
    142143    QUrl url() const;
     144    QUrl originalUrl() const;
    143145    QUrl baseUrl() const;
    144146    QIcon icon() const;
  • trunk/WebKit/qt/ChangeLog

    r46352 r46364  
     12009-07-24  Antonio Gomes   <antonio.gomes@openbossa.org>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        [QT] Implement originalUrl getter method to the API
     6        https://bugs.webkit.org/show_bug.cgi?id=25867
     7
     8        * Api/qwebframe.cpp:
     9        (QWebFrame::originalUrl):
     10        * Api/qwebframe.h:
     11        * tests/qwebframe/qwebframe.qrc:
     12        * tests/qwebframe/test1.html: Added.
     13        * tests/qwebframe/test2.html: Added.
     14        * tests/qwebframe/tst_qwebframe.cpp:
     15
    1162009-07-24  Kenneth Rohde Christiansen  <kenneth@webkit.org>
    217
  • trunk/WebKit/qt/tests/qwebframe/qwebframe.qrc

    r44040 r46364  
    33<file>image.png</file>
    44<file>style.css</file>
     5<file>test1.html</file>
     6<file>test2.html</file>
    57</qresource>
    68</RCC>
  • trunk/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp

    r45471 r46364  
    3232#include <QRegExp>
    3333#include <QNetworkRequest>
     34#include <QNetworkReply>
    3435//TESTED_CLASS=
    3536//TESTED_FILES=
     
    574575    void urlChange();
    575576    void domCycles();
     577    void originalUrl();
    576578    void setHtml();
    577579    void setHtmlWithResource();
     
    21602162}
    21612163
     2164class FakeReply : public QNetworkReply {
     2165    Q_OBJECT
     2166
     2167    public:
     2168        FakeReply(const QNetworkRequest& request, QObject* parent = 0)
     2169            : QNetworkReply(parent)
     2170        {
     2171            setOperation(QNetworkAccessManager::GetOperation);
     2172            setRequest(request);
     2173            if (request.url() == QUrl("qrc:/test1.html")) {
     2174                setHeader(QNetworkRequest::LocationHeader, QString("qrc:/test2.html"));
     2175                setAttribute(QNetworkRequest::RedirectionTargetAttribute, QUrl("qrc:/test2.html"));
     2176            } else
     2177                setError(QNetworkReply::HostNotFoundError, tr("Invalid URL"));
     2178
     2179            open(QIODevice::ReadOnly);
     2180            QTimer::singleShot(0, this, SLOT(timeout()));
     2181        }
     2182        ~FakeReply()
     2183        {
     2184            close();
     2185        }
     2186        virtual void abort() {}
     2187        virtual void close() {}
     2188    protected:
     2189        qint64 readData(char* data, qint64 maxSize)
     2190        {
     2191            return 0;
     2192        }
     2193    private slots:
     2194        void timeout()
     2195        {
     2196            if (request().url() == QUrl("qrc://test1.html"))
     2197                emit error(this->error());
     2198            else if (request().url() == QUrl("http://abcdef.abcdef/"))
     2199                emit metaDataChanged();
     2200
     2201            emit readyRead();
     2202            emit finished();
     2203        }
     2204};
     2205
     2206class FakeNetworkManager : public QNetworkAccessManager {
     2207public:
     2208    FakeNetworkManager(QObject* parent) : QNetworkAccessManager(parent) { }
     2209
     2210protected:
     2211    virtual QNetworkReply* createRequest(Operation op, const QNetworkRequest& request, QIODevice* outgoingData)
     2212    {
     2213        if (op == QNetworkAccessManager::GetOperation
     2214            && (request.url().toString() == "qrc:/test1.html"
     2215            ||  request.url().toString() == "http://abcdef.abcdef/"))
     2216            return new FakeReply(request, this);
     2217
     2218        return QNetworkAccessManager::createRequest(op, request, outgoingData);
     2219    }
     2220};
     2221
     2222void tst_QWebFrame::originalUrl()
     2223{
     2224    QWebPage page;
     2225    QWebFrame* frame = page.mainFrame();
     2226
     2227    // in few seconds, the image should be completely loaded
     2228    QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
     2229    FakeNetworkManager* networkManager = new FakeNetworkManager(&page);
     2230    page.setNetworkAccessManager(networkManager);
     2231
     2232    frame->setUrl(QUrl("qrc:/test1.html"));
     2233    QTest::qWait(200);
     2234    QCOMPARE(spy.count(), 1);
     2235    QCOMPARE(frame->originalUrl(), QUrl("qrc:/test1.html"));
     2236    QCOMPARE(frame->url(), QUrl("qrc:/test2.html"));
     2237
     2238    frame->setUrl(QUrl("qrc:/non-existent.html"));
     2239    QTest::qWait(200);
     2240    QCOMPARE(spy.count(), 2);
     2241    QCOMPARE(frame->originalUrl(), QUrl("qrc:/non-existent.html"));
     2242    QCOMPARE(frame->url(), QUrl("qrc:/non-existent.html"));
     2243
     2244    frame->setUrl(QUrl("http://abcdef.abcdef"));
     2245    QTest::qWait(200);
     2246    QCOMPARE(spy.count(), 3);
     2247    QCOMPARE(frame->originalUrl(), QUrl("http://abcdef.abcdef/"));
     2248    QCOMPARE(frame->url(), QUrl("http://abcdef.abcdef/"));
     2249}
     2250
    21622251void tst_QWebFrame::setHtml()
    21632252{
Note: See TracChangeset for help on using the changeset viewer.