Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Treat fewer responses as fatal failures

* Relies on errorExtension instead of loadFinished
* Ignores errors from canceled requests
  • Loading branch information...
commit d8020ce3a4dfc75cfb715c563398cc6e444d601b 1 parent 0942500
Joe Ferris authored July 10, 2012
15  src/UnsupportedContentHandler.cpp
@@ -10,23 +10,18 @@ UnsupportedContentHandler::UnsupportedContentHandler(WebPage *page, QNetworkRepl
10 10
 }
11 11
 
12 12
 void UnsupportedContentHandler::handleUnsupportedContent() {
13  
-  QVariant contentMimeType = m_reply->header(QNetworkRequest::ContentTypeHeader);
14  
-  if(contentMimeType.isNull()) {
15  
-    this->finish(false);
16  
-  } else {
17  
-    this->loadUnsupportedContent();
18  
-    this->finish(true);
19  
-  }
  13
+  this->renderNonHtmlContent();
  14
+  this->finish();
20 15
   this->deleteLater();
21 16
 }
22 17
 
23  
-void UnsupportedContentHandler::loadUnsupportedContent() {
  18
+void UnsupportedContentHandler::renderNonHtmlContent() {
24 19
     QByteArray text = m_reply->readAll();
25 20
     m_page->mainFrame()->setContent(text, QString("text/plain"), m_reply->url());
26 21
 }
27 22
 
28  
-void UnsupportedContentHandler::finish(bool success) {
  23
+void UnsupportedContentHandler::finish() {
29 24
     connect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
30 25
     m_page->networkAccessManagerFinishedReply(m_reply);
31  
-    m_page->loadFinished(success);
  26
+    m_page->loadFinished(true);
32 27
 }
4  src/UnsupportedContentHandler.h
@@ -13,6 +13,6 @@ class UnsupportedContentHandler : public QObject {
13 13
   private:
14 14
     WebPage *m_page;
15 15
     QNetworkReply *m_reply;
16  
-    void loadUnsupportedContent();
17  
-    void finish(bool success);
  16
+    void renderNonHtmlContent();
  17
+    void finish();
18 18
 };
14  src/WebPage.cpp
@@ -11,6 +11,7 @@
11 11
 
12 12
 WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) {
13 13
   m_loading = false;
  14
+  m_failed = false;
14 15
   m_manager = manager;
15 16
   m_uuid = QUuid::createUuid().toString();
16 17
   m_lastStatus = 0;
@@ -162,8 +163,10 @@ void WebPage::loadStarted() {
162 163
 }
163 164
 
164 165
 void WebPage::loadFinished(bool success) {
  166
+  Q_UNUSED(success);
165 167
   m_loading = false;
166  
-  emit pageFinished(success);
  168
+  emit pageFinished(!m_failed);
  169
+  m_failed = false;
167 170
 }
168 171
 
169 172
 bool WebPage::isLoading() const {
@@ -221,6 +224,7 @@ bool WebPage::extension(Extension extension, const ExtensionOption *option, Exte
221 224
   else if (extension == QWebPage::ErrorPageExtension) {
222 225
     ErrorPageExtensionOption *errorOption = (ErrorPageExtensionOption*) option;
223 226
     m_errorPageMessage = " because of error loading " + errorOption->url.toString() + ": " + errorOption->errorString;
  227
+    m_failed = true;
224 228
     return false;
225 229
   }
226 230
   return false;
@@ -248,8 +252,12 @@ QString WebPage::pageHeaders() {
248 252
 }
249 253
 
250 254
 void WebPage::handleUnsupportedContent(QNetworkReply *reply) {
251  
-  UnsupportedContentHandler *handler = new UnsupportedContentHandler(this, reply);
252  
-  Q_UNUSED(handler);
  255
+  QVariant contentMimeType = reply->header(QNetworkRequest::ContentTypeHeader);
  256
+  if(!contentMimeType.isNull()) {
  257
+    triggerAction(QWebPage::Stop);
  258
+    UnsupportedContentHandler *handler = new UnsupportedContentHandler(this, reply);
  259
+    Q_UNUSED(handler);
  260
+  }
253 261
 }
254 262
 
255 263
 bool WebPage::supportsExtension(Extension extension) const {
1  src/WebPage.h
@@ -57,6 +57,7 @@ class WebPage : public QWebPage {
57 57
     QString m_capybaraJavascript;
58 58
     QString m_userAgent;
59 59
     bool m_loading;
  60
+    bool m_failed;
60 61
     QString getLastAttachedFileName();
61 62
     void loadJavascript();
62 63
     void setUserStylesheet();

0 notes on commit d8020ce

Please sign in to comment.
Something went wrong with that request. Please try again.