Changeset 46364 in webkit
- Timestamp:
- Jul 24, 2009 10:55:49 AM (15 years ago)
- Location:
- trunk/WebKit/qt
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKit/qt/Api/qwebframe.cpp
r46170 r46364 281 281 frames are related to a web page and web view. 282 282 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 283 290 The title of an HTML frame can be accessed with the title() property. 284 291 Additionally, a frame may also specify an icon, which can be accessed … … 522 529 523 530 /*! 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 */ 539 QUrl 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 524 549 \property QWebFrame::baseUrl 525 550 \brief the base URL of the frame, can be used to resolve relative URLs -
trunk/WebKit/qt/Api/qwebframe.h
r46170 r46364 108 108 Q_PROPERTY(QString title READ title) 109 109 Q_PROPERTY(QUrl url READ url WRITE setUrl) 110 Q_PROPERTY(QUrl originalUrl READ originalUrl) 110 111 Q_PROPERTY(QUrl baseUrl READ baseUrl) 111 112 Q_PROPERTY(QIcon icon READ icon) … … 141 142 void setUrl(const QUrl &url); 142 143 QUrl url() const; 144 QUrl originalUrl() const; 143 145 QUrl baseUrl() const; 144 146 QIcon icon() const; -
trunk/WebKit/qt/ChangeLog
r46352 r46364 1 2009-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 1 16 2009-07-24 Kenneth Rohde Christiansen <kenneth@webkit.org> 2 17 -
trunk/WebKit/qt/tests/qwebframe/qwebframe.qrc
r44040 r46364 3 3 <file>image.png</file> 4 4 <file>style.css</file> 5 <file>test1.html</file> 6 <file>test2.html</file> 5 7 </qresource> 6 8 </RCC> -
trunk/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp
r45471 r46364 32 32 #include <QRegExp> 33 33 #include <QNetworkRequest> 34 #include <QNetworkReply> 34 35 //TESTED_CLASS= 35 36 //TESTED_FILES= … … 574 575 void urlChange(); 575 576 void domCycles(); 577 void originalUrl(); 576 578 void setHtml(); 577 579 void setHtmlWithResource(); … … 2160 2162 } 2161 2163 2164 class 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 2206 class FakeNetworkManager : public QNetworkAccessManager { 2207 public: 2208 FakeNetworkManager(QObject* parent) : QNetworkAccessManager(parent) { } 2209 2210 protected: 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 2222 void 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 2162 2251 void tst_QWebFrame::setHtml() 2163 2252 {
Note: See TracChangeset
for help on using the changeset viewer.