diff --git a/src/core/custom_url_scheme_handler.cpp b/src/core/custom_url_scheme_handler.cpp index a8701a5d4c506b82ae7bccc488a932caa53fe1d7..edc8000c91adf678aa75bd1432abf41d33519bb8 100644 --- a/src/core/custom_url_scheme_handler.cpp +++ b/src/core/custom_url_scheme_handler.cpp @@ -39,7 +39,6 @@ CustomUrlSchemeHandler::CustomUrlSchemeHandler(const QByteArray &scheme) : m_scheme(scheme) - , m_protocolHandler(new CustomProtocolHandler(this)) { } @@ -57,7 +56,8 @@ void CustomUrlSchemeHandler::setScheme(const QByteArray &scheme) m_scheme = scheme; } -CustomProtocolHandler *CustomUrlSchemeHandler::protocolHandler() +CustomProtocolHandler *CustomUrlSchemeHandler::createProtocolHandler() { - return m_protocolHandler.data(); + // Will be owned by the JobFactory. + return new CustomProtocolHandler(this); } diff --git a/src/core/custom_url_scheme_handler.h b/src/core/custom_url_scheme_handler.h index fef29c98a13a781b228ef41b42d57fdf1540e176..dbcdf2a60de49792971c8ff4e58ba5222db37902 100644 --- a/src/core/custom_url_scheme_handler.h +++ b/src/core/custom_url_scheme_handler.h @@ -55,13 +55,12 @@ public: QByteArray scheme() const; void setScheme(const QByteArray &); - CustomProtocolHandler *protocolHandler(); + CustomProtocolHandler *createProtocolHandler(); virtual bool handleJob(URLRequestCustomJobDelegate*) = 0; private: QByteArray m_scheme; - QScopedPointer<CustomProtocolHandler> m_protocolHandler; }; #endif // CUSTOM_URL_SCHEME_HANDLER_H_ diff --git a/src/core/url_request_context_getter_qt.cpp b/src/core/url_request_context_getter_qt.cpp index 41af37e5dda14ba65d85cb53db37e5df936e7308..0a604eaaa4e9157935961e42b7eb9be68bb96f0e 100644 --- a/src/core/url_request_context_getter_qt.cpp +++ b/src/core/url_request_context_getter_qt.cpp @@ -122,6 +122,8 @@ void URLRequestContextGetterQt::generateStorage() { Q_ASSERT(m_urlRequestContext); Q_ASSERT(m_proxyConfigService); + if (!m_proxyConfigService) + return; m_updateStorageSettings = false; m_storage.reset(new net::URLRequestContextStorage(m_urlRequestContext.get())); @@ -285,7 +287,7 @@ void URLRequestContextGetterQt::generateJobFactory() new net::FtpProtocolHandler(new net::FtpNetworkLayer(m_urlRequestContext->host_resolver()))); Q_FOREACH (CustomUrlSchemeHandler* handler, m_browserContext->customUrlSchemeHandlers()) { - m_jobFactory->SetProtocolHandler(handler->scheme().toStdString(), handler->protocolHandler()); + m_jobFactory->SetProtocolHandler(handler->scheme().toStdString(), handler->createProtocolHandler()); } m_urlRequestContext->set_job_factory(m_jobFactory.get()); diff --git a/src/core/url_request_custom_job.cpp b/src/core/url_request_custom_job.cpp index e97804c2f98783f7aafac7f4b0fdee254d2c52c4..f206955f19ed1eb029e48187a8599daa14bdab9f 100644 --- a/src/core/url_request_custom_job.cpp +++ b/src/core/url_request_custom_job.cpp @@ -72,7 +72,7 @@ void URLRequestCustomJob::Start() void URLRequestCustomJob::Kill() { - if (m_device->isOpen()) + if (m_device && m_device->isOpen()) m_device->close(); m_weakFactory.InvalidateWeakPtrs(); diff --git a/src/webenginewidgets/api/qwebengineurlschemehandler.cpp b/src/webenginewidgets/api/qwebengineurlschemehandler.cpp index b52912b7c6c93432594c7599bbb0d57331fb227e..ccb92258bac9e1a62baae53a6c05240212638d64 100644 --- a/src/webenginewidgets/api/qwebengineurlschemehandler.cpp +++ b/src/webenginewidgets/api/qwebengineurlschemehandler.cpp @@ -41,8 +41,6 @@ #include "qwebengineprofile_p.h" #include "qwebengineurlrequestjob_p.h" -#include <QSharedPointer> - QT_BEGIN_NAMESPACE QWebEngineUrlSchemeHandlerPrivate::QWebEngineUrlSchemeHandlerPrivate(const QByteArray &scheme, QWebEngineUrlSchemeHandler *q, QWebEngineProfile *profile) @@ -63,8 +61,8 @@ bool QWebEngineUrlSchemeHandlerPrivate::handleJob(URLRequestCustomJobDelegate *j return true; } -QWebEngineUrlSchemeHandler::QWebEngineUrlSchemeHandler(const QByteArray &scheme, QWebEngineProfile *profile) - : QObject(profile) +QWebEngineUrlSchemeHandler::QWebEngineUrlSchemeHandler(const QByteArray &scheme, QWebEngineProfile *profile, QObject *parent) + : QObject(parent) , d_ptr(new QWebEngineUrlSchemeHandlerPrivate(scheme, this, profile)) { profile->d_func()->installUrlSchemeHandler(this); @@ -72,7 +70,8 @@ QWebEngineUrlSchemeHandler::QWebEngineUrlSchemeHandler(const QByteArray &scheme, QWebEngineUrlSchemeHandler::~QWebEngineUrlSchemeHandler() { - d_ptr->m_profile->d_func()->removeUrlSchemeHandler(this); + if (d_ptr->m_profile) + d_ptr->m_profile->d_func()->removeUrlSchemeHandler(this); } QByteArray QWebEngineUrlSchemeHandler::scheme() const diff --git a/src/webenginewidgets/api/qwebengineurlschemehandler_p.h b/src/webenginewidgets/api/qwebengineurlschemehandler_p.h index 0455128c7abd338c9a5d129d0c693d66fb7d16c9..153b78f813543ab9d0b169ebd335a81228836e54 100644 --- a/src/webenginewidgets/api/qwebengineurlschemehandler_p.h +++ b/src/webenginewidgets/api/qwebengineurlschemehandler_p.h @@ -54,7 +54,7 @@ class QWebEngineUrlSchemeHandlerPrivate; class QWEBENGINEWIDGETS_EXPORT QWebEngineUrlSchemeHandler : public QObject { Q_OBJECT public: - QWebEngineUrlSchemeHandler(const QByteArray &scheme, QWebEngineProfile *profile); + QWebEngineUrlSchemeHandler(const QByteArray &scheme, QWebEngineProfile *profile, QObject *parent = 0); virtual ~QWebEngineUrlSchemeHandler(); QByteArray scheme() const; diff --git a/src/webenginewidgets/api/qwebengineurlschemehandler_p_p.h b/src/webenginewidgets/api/qwebengineurlschemehandler_p_p.h index e880bf0001d4feffe68a045979e213b666e295f3..6146cc05e0653d4578ce95c00d194f5641dd0171 100644 --- a/src/webenginewidgets/api/qwebengineurlschemehandler_p_p.h +++ b/src/webenginewidgets/api/qwebengineurlschemehandler_p_p.h @@ -41,6 +41,8 @@ #include "custom_url_scheme_handler.h" +#include <QPointer> + QT_BEGIN_NAMESPACE class QWebEngineProfile; @@ -58,7 +60,7 @@ public: private: QWebEngineUrlSchemeHandler *q_ptr; - QWebEngineProfile* m_profile; + QPointer<QWebEngineProfile> m_profile; }; QT_END_NAMESPACE