From a6c9ca7b4cc0a47693ffa48bb1f74d56158d192b Mon Sep 17 00:00:00 2001 From: David Rosca Date: Mon, 5 Oct 2015 19:16:12 +0200 Subject: [PATCH] Workaround error handling in scheme handlers --- .../schemehandlers/adblockschemehandler.cpp | 8 ++++--- .../schemehandlers/qupzillaschemehandler.cpp | 21 +++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/lib/network/schemehandlers/adblockschemehandler.cpp b/src/lib/network/schemehandlers/adblockschemehandler.cpp index 529c4495b..99f6d63a5 100644 --- a/src/lib/network/schemehandlers/adblockschemehandler.cpp +++ b/src/lib/network/schemehandlers/adblockschemehandler.cpp @@ -19,6 +19,7 @@ #include "adblockmanager.h" #include "emptynetworkreply.h" +#include #include #include #include @@ -30,6 +31,10 @@ AdBlockSchemeHandler::AdBlockSchemeHandler(QObject *parent) void AdBlockSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job) { + // Ignore the request + job->setReply(QByteArray(), new QBuffer()); + //job->setError(QWebEngineUrlRequestJob::RequestAborted); + const QUrl url = job->requestUrl(); const QList > queryItems = QUrlQuery(url).queryItems(); @@ -47,7 +52,6 @@ void AdBlockSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job) } if (subscriptionTitle.isEmpty() || subscriptionUrl.isEmpty()) { - job->setError(QWebEngineUrlRequestJob::RequestAborted); return; } @@ -58,6 +62,4 @@ void AdBlockSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job) AdBlockManager::instance()->addSubscription(subscriptionTitle, subscriptionUrl); AdBlockManager::instance()->showDialog(); } - - job->setError(QWebEngineUrlRequestJob::RequestAborted); } diff --git a/src/lib/network/schemehandlers/qupzillaschemehandler.cpp b/src/lib/network/schemehandlers/qupzillaschemehandler.cpp index afe84ea60..4673e446f 100644 --- a/src/lib/network/schemehandlers/qupzillaschemehandler.cpp +++ b/src/lib/network/schemehandlers/qupzillaschemehandler.cpp @@ -44,7 +44,14 @@ QupZillaSchemeHandler::QupZillaSchemeHandler(QObject *parent) void QupZillaSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job) { - job->setReply(QByteArrayLiteral("text/html"), new QupZillaSchemeReply(job)); + QStringList knownPages; + knownPages << "about" << "reportbug" << "start" << "speeddial" << "config" << "restore"; + + if (knownPages.contains(job->requestUrl().path())) + job->setReply(QByteArrayLiteral("text/html"), new QupZillaSchemeReply(job)); + else + job->setReply(QByteArray(), new QBuffer()); + //m_job->setError(QWebEngineUrlRequestJob::UrlNotFound); } QupZillaSchemeReply::QupZillaSchemeReply(QWebEngineUrlRequestJob *job, QObject *parent) @@ -54,16 +61,8 @@ QupZillaSchemeReply::QupZillaSchemeReply(QWebEngineUrlRequestJob *job, QObject * { m_pageName = m_job->requestUrl().path(); - QStringList knownPages; - knownPages << "about" << "reportbug" << "start" << "speeddial" << "config" << "restore"; - - if (knownPages.contains(m_pageName)) { - open(QIODevice::ReadOnly); - m_buffer.open(QIODevice::ReadWrite); - } - else { - //m_job->setError(QWebEngineUrlRequestJob::UrlNotFound); - } + open(QIODevice::ReadOnly); + m_buffer.open(QIODevice::ReadWrite); } void QupZillaSchemeReply::loadPage()