Browse files

Return unsupported content as plain text

  • Loading branch information...
1 parent 3c8ad25 commit fbead1ebb52e4b3d917820dfdbf0840c2fdb0f83 @mhoran mhoran committed Nov 21, 2012
Showing with 45 additions and 1 deletion.
  1. +25 −0 spec/driver_spec.rb
  2. +1 −0 src/UnsupportedContentHandler.cpp
  3. +10 −0 src/WebPage.cpp
  4. +3 −0 src/WebPage.h
  5. +6 −1 src/body.cpp
View
25 spec/driver_spec.rb
@@ -257,6 +257,31 @@ def visit(url, driver=driver)
it "sets the response headers with respect to the unsupported request" do
driver.response_headers["Content-Type"].should == "text/css"
end
+
+ it "does not wrap the content in HTML tags" do
+ driver.html.should_not =~ /<html>/
+ end
+ end
+
+ context "html app" do
+ let(:driver) do
+ driver_for_html(<<-HTML)
+ <html>
+ <head>
+ <title>Hello HTML</title>
+ </head>
+ <body>
+ <h1>This Is HTML!</h1>
+ </body>
+ </html>
+ HTML
+ end
+
+ before { visit("/") }
+
+ it "does not strip HTML tags" do
+ driver.html.should =~ /<html>/
+ end
end
context "hello app" do
View
1 src/UnsupportedContentHandler.cpp
@@ -10,6 +10,7 @@ UnsupportedContentHandler::UnsupportedContentHandler(WebPage *page, QNetworkRepl
void UnsupportedContentHandler::renderNonHtmlContent() {
QByteArray text = m_reply->readAll();
m_page->mainFrame()->setContent(text, QString("text/plain"), m_reply->url());
+ m_page->setUnsupportedContentLoaded();
m_page->networkAccessManagerFinishedReply(m_reply);
m_page->loadFinished(true);
this->deleteLater();
View
10 src/WebPage.cpp
@@ -14,6 +14,7 @@ WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) {
m_failed = false;
m_manager = manager;
m_uuid = QUuid::createUuid().toString();
+ m_unsupportedContentLoaded = false;
setForwardUnsupportedContent(true);
loadJavascript();
@@ -169,6 +170,7 @@ bool WebPage::javaScriptPrompt(QWebFrame *frame, const QString &message, const Q
void WebPage::loadStarted() {
m_loading = true;
m_errorPageMessage = QString();
+ m_unsupportedContentLoaded = false;
}
void WebPage::loadFinished(bool success) {
@@ -275,6 +277,14 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) {
}
}
+void WebPage::setUnsupportedContentLoaded() {
+ m_unsupportedContentLoaded = true;
+}
+
+bool WebPage::unsupportedContentLoaded() {
+ return m_unsupportedContentLoaded;
+}
+
bool WebPage::supportsExtension(Extension extension) const {
if (extension == ErrorPageExtension)
return true;
View
3 src/WebPage.h
@@ -34,6 +34,8 @@ class WebPage : public QWebPage {
bool matchesWindowSelector(QString);
void setFocus();
NetworkAccessManager *networkAccessManager();
+ void setUnsupportedContentLoaded();
+ bool unsupportedContentLoaded();
public slots:
bool shouldInterruptJavaScript();
@@ -79,6 +81,7 @@ class WebPage : public QWebPage {
QString m_uuid;
WebPageManager *m_manager;
QString m_errorPageMessage;
+ bool m_unsupportedContentLoaded;
};
#endif //_WEBPAGE_H
View
7 src/body.cpp
@@ -6,6 +6,11 @@ Body::Body(WebPageManager *manager, QStringList &arguments, QObject *parent) : S
}
void Body::start() {
- QString result = page()->currentFrame()->toHtml();
+ QString result;
+ if (page()->unsupportedContentLoaded())
+ result = page()->currentFrame()->toPlainText();
+ else
+ result = page()->currentFrame()->toHtml();
+
emit finished(new Response(true, result));
}

0 comments on commit fbead1e

Please sign in to comment.