Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 28 lines (23 sloc) 0.953 kB
353fe86 @halogenandtoast Handle unsupported content types gracefully
halogenandtoast authored
1 #include "UnsupportedContentHandler.h"
2 #include "WebPage.h"
3 #include <QNetworkReply>
4
5 UnsupportedContentHandler::UnsupportedContentHandler(WebPage *page, QNetworkReply *reply, QObject *parent) : QObject(parent) {
6 m_page = page;
7 m_reply = reply;
8 connect(m_reply, SIGNAL(finished()), this, SLOT(handleUnsupportedContent()));
9 disconnect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
10 }
11
12 void UnsupportedContentHandler::handleUnsupportedContent() {
d8020ce @jferris Treat fewer responses as fatal failures
jferris authored
13 this->renderNonHtmlContent();
14 this->finish();
9257fe3 @halogenandtoast Cleanup
halogenandtoast authored
15 this->deleteLater();
16 }
17
d8020ce @jferris Treat fewer responses as fatal failures
jferris authored
18 void UnsupportedContentHandler::renderNonHtmlContent() {
353fe86 @halogenandtoast Handle unsupported content types gracefully
halogenandtoast authored
19 QByteArray text = m_reply->readAll();
20 m_page->mainFrame()->setContent(text, QString("text/plain"), m_reply->url());
9257fe3 @halogenandtoast Cleanup
halogenandtoast authored
21 }
22
d8020ce @jferris Treat fewer responses as fatal failures
jferris authored
23 void UnsupportedContentHandler::finish() {
353fe86 @halogenandtoast Handle unsupported content types gracefully
halogenandtoast authored
24 connect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
784b9b7 @halogenandtoast Setup multi-window sync.
halogenandtoast authored
25 m_page->networkAccessManagerFinishedReply(m_reply);
d8020ce @jferris Treat fewer responses as fatal failures
jferris authored
26 m_page->loadFinished(true);
353fe86 @halogenandtoast Handle unsupported content types gracefully
halogenandtoast authored
27 }
Something went wrong with that request. Please try again.