1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00
capybara-webkit/src/UnsupportedContentHandler.cpp

32 lines
1.1 KiB
C++
Raw Normal View History

#include "UnsupportedContentHandler.h"
#include "WebPage.h"
#include <QNetworkReply>
UnsupportedContentHandler::UnsupportedContentHandler(WebPage *page, QNetworkReply *reply, QObject *parent) : QObject(parent) {
m_page = page;
m_reply = reply;
connect(m_reply, SIGNAL(finished()), this, SLOT(handleUnsupportedContent()));
disconnect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
}
void UnsupportedContentHandler::handleUnsupportedContent() {
QVariant contentMimeType = m_reply->header(QNetworkRequest::ContentTypeHeader);
if(!contentMimeType.isNull()) {
2011-09-23 11:00:50 -04:00
this->loadUnsupportedContent();
this->finish(true);
} else {
this->finish(false);
}
this->deleteLater();
}
void UnsupportedContentHandler::loadUnsupportedContent() {
QByteArray text = m_reply->readAll();
m_page->mainFrame()->setContent(text, QString("text/plain"), m_reply->url());
2011-09-23 11:00:50 -04:00
}
void UnsupportedContentHandler::finish(bool success) {
connect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
2011-09-23 11:00:50 -04:00
m_page->loadFinished(success);
}