forked from thoughtbot/capybara-webkit
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle unsupported content types gracefully
- Loading branch information
1 parent
f493b22
commit 353fe86
Showing
8 changed files
with
72 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#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()) { | ||
QByteArray text = m_reply->readAll(); | ||
m_page->mainFrame()->setContent(text, QString("text/plain"), m_reply->url()); | ||
connect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool))); | ||
m_page->loadFinished(true); | ||
} else { | ||
connect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool))); | ||
m_page->loadFinished(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <QObject> | ||
class WebPage; | ||
class QNetworkReply; | ||
class UnsupportedContentHandler : public QObject { | ||
Q_OBJECT | ||
|
||
public: | ||
UnsupportedContentHandler(WebPage *page, QNetworkReply *reply, QObject *parent = 0); | ||
|
||
public slots: | ||
void handleUnsupportedContent(); | ||
|
||
private: | ||
WebPage *m_page; | ||
QNetworkReply *m_reply; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters