2010-12-11 Jan Erik Hanssen <jhanssen@sencha.com>

        Reviewed by Andreas Kling.

        [Qt] QWebFrame does not support QNetworkRequest::CacheLoadControl
        https://bugs.webkit.org/show_bug.cgi?id=35671

        Make QWebFrame respect the QNetworkRequest::CacheLoadControl attribute
        set on the request, if any.

        * Api/qwebframe.cpp:
        (cacheLoadControlToCachePolicy):
        (QWebFrame::load):
        * tests/qwebframe/tst_qwebframe.cpp:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@73865 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 41579485
......@@ -201,6 +201,21 @@ void QWEBKIT_EXPORT qtwebkit_webframe_scrollRecursively(QWebFrame* qFrame, int d
} while (qFrame);
}
static inline ResourceRequestCachePolicy cacheLoadControlToCachePolicy(uint cacheLoadControl)
{
switch (cacheLoadControl) {
case QNetworkRequest::AlwaysNetwork:
return WebCore::ReloadIgnoringCacheData;
case QNetworkRequest::PreferCache:
return WebCore::ReturnCacheDataElseLoad;
case QNetworkRequest::AlwaysCache:
return WebCore::ReturnCacheDataDontLoad;
default:
break;
}
return WebCore::UseProtocolCachePolicy;
}
QWebFrameData::QWebFrameData(WebCore::Page* parentPage, WebCore::Frame* parentFrame,
WebCore::HTMLFrameOwnerElement* ownerFrameElement,
const WTF::String& frameName)
......@@ -883,6 +898,14 @@ void QWebFrame::load(const QNetworkRequest &req,
break;
}
QVariant cacheLoad = req.attribute(QNetworkRequest::CacheLoadControlAttribute);
if (cacheLoad.isValid()) {
bool ok;
uint cacheLoadValue = cacheLoad.toUInt(&ok);
if (ok)
request.setCachePolicy(cacheLoadControlToCachePolicy(cacheLoadValue));
}
QList<QByteArray> httpHeaders = req.rawHeaderList();
for (int i = 0; i < httpHeaders.size(); ++i) {
const QByteArray &headerName = httpHeaders.at(i);
......
2010-12-11 Jan Erik Hanssen <jhanssen@sencha.com>
Reviewed by Andreas Kling.
[Qt] QWebFrame does not support QNetworkRequest::CacheLoadControl
https://bugs.webkit.org/show_bug.cgi?id=35671
Make QWebFrame respect the QNetworkRequest::CacheLoadControl attribute
set on the request, if any.
* Api/qwebframe.cpp:
(cacheLoadControlToCachePolicy):
(QWebFrame::load):
* tests/qwebframe/tst_qwebframe.cpp:
2010-10-11 Diego Gonzalez <diegohcg@webkit.org>
Reviewed by Kenneth Rohde Christiansen.
......
......@@ -625,6 +625,7 @@ private slots:
void introspectQtMethods();
void setContent_data();
void setContent();
void setCacheLoadControlAttribute();
private:
QString evalJS(const QString&s) {
......@@ -3068,5 +3069,58 @@ void tst_QWebFrame::setContent()
QCOMPARE(expected , mainFrame->toPlainText());
}
class CacheNetworkAccessManager : public QNetworkAccessManager {
public:
CacheNetworkAccessManager(QObject* parent = 0)
: QNetworkAccessManager(parent)
, m_lastCacheLoad(QNetworkRequest::PreferNetwork)
{
}
virtual QNetworkReply* createRequest(Operation, const QNetworkRequest& request, QIODevice*)
{
QVariant cacheLoad = request.attribute(QNetworkRequest::CacheLoadControlAttribute);
if (cacheLoad.isValid())
m_lastCacheLoad = static_cast<QNetworkRequest::CacheLoadControl>(cacheLoad.toUInt());
else
m_lastCacheLoad = QNetworkRequest::PreferNetwork; // default value
return new FakeReply(request, this);
}
QNetworkRequest::CacheLoadControl lastCacheLoad() const
{
return m_lastCacheLoad;
}
private:
QNetworkRequest::CacheLoadControl m_lastCacheLoad;
};
void tst_QWebFrame::setCacheLoadControlAttribute()
{
QWebPage page;
CacheNetworkAccessManager* manager = new CacheNetworkAccessManager(&page);
page.setNetworkAccessManager(manager);
QWebFrame* frame = page.mainFrame();
QNetworkRequest request(QUrl("http://abcdef.abcdef/"));
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysCache);
frame->load(request);
QCOMPARE(manager->lastCacheLoad(), QNetworkRequest::AlwaysCache);
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
frame->load(request);
QCOMPARE(manager->lastCacheLoad(), QNetworkRequest::PreferCache);
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork);
frame->load(request);
QCOMPARE(manager->lastCacheLoad(), QNetworkRequest::AlwaysNetwork);
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork);
frame->load(request);
QCOMPARE(manager->lastCacheLoad(), QNetworkRequest::PreferNetwork);
}
QTEST_MAIN(tst_QWebFrame)
#include "tst_qwebframe.moc"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment