From 0a21df6d8ef2f7efb397fe109b1ff2a391db1735 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 11 Aug 2015 13:56:18 +0200 Subject: Move custom URL scheme handlers to core Makes the custom URL scheme handler API public, and moves it to core so that it may be shared with the QQuickWebEngine API. Change-Id: I745cb088df6f4cd11b1ac7c8c3c76f112032cb38 Reviewed-by: Joerg Bornemann --- src/core/api/core_api.pro | 9 +- src/core/api/qwebengineurlrequestjob.cpp | 110 +++++++++++++++++++ src/core/api/qwebengineurlrequestjob.h | 94 ++++++++++++++++ src/core/api/qwebengineurlschemehandler.cpp | 109 +++++++++++++++++++ src/core/api/qwebengineurlschemehandler.h | 70 ++++++++++++ src/core/api/qwebengineurlschemehandler_p.h | 76 +++++++++++++ src/core/browser_context_adapter.cpp | 6 ++ src/core/browser_context_adapter.h | 1 + src/core/custom_url_scheme_handler.cpp | 4 - src/core/custom_url_scheme_handler.h | 2 +- src/webenginewidgets/api/qwebengineprofile.cpp | 68 +++++++++--- src/webenginewidgets/api/qwebengineprofile.h | 9 ++ src/webenginewidgets/api/qwebengineprofile_p.h | 7 +- .../api/qwebengineurlrequestjob.cpp | 113 ------------------- .../api/qwebengineurlrequestjob_p.h | 93 ---------------- .../api/qwebengineurlschemehandler.cpp | 119 --------------------- .../api/qwebengineurlschemehandler_p.h | 83 -------------- .../api/qwebengineurlschemehandler_p_p.h | 79 -------------- src/webenginewidgets/webenginewidgets.pro | 5 - 19 files changed, 535 insertions(+), 522 deletions(-) create mode 100644 src/core/api/qwebengineurlrequestjob.cpp create mode 100644 src/core/api/qwebengineurlrequestjob.h create mode 100644 src/core/api/qwebengineurlschemehandler.cpp create mode 100644 src/core/api/qwebengineurlschemehandler.h create mode 100644 src/core/api/qwebengineurlschemehandler_p.h delete mode 100644 src/webenginewidgets/api/qwebengineurlrequestjob.cpp delete mode 100644 src/webenginewidgets/api/qwebengineurlrequestjob_p.h delete mode 100644 src/webenginewidgets/api/qwebengineurlschemehandler.cpp delete mode 100644 src/webenginewidgets/api/qwebengineurlschemehandler_p.h delete mode 100644 src/webenginewidgets/api/qwebengineurlschemehandler_p_p.h (limited to 'src') diff --git a/src/core/api/core_api.pro b/src/core/api/core_api.pro index d72b27229..1f82c7e21 100644 --- a/src/core/api/core_api.pro +++ b/src/core/api/core_api.pro @@ -37,8 +37,13 @@ HEADERS = \ qwebenginecookiestoreclient_p.h \ qwebengineurlrequestinterceptor.h \ qwebengineurlrequestinfo.h \ - qwebengineurlrequestinfo_p.h + qwebengineurlrequestinfo_p.h \ + qwebengineurlrequestjob.h \ + qwebengineurlschemehandler.h \ + qwebengineurlschemehandler_p.h SOURCES = \ qwebenginecookiestoreclient.cpp \ - qwebengineurlrequestinfo.cpp + qwebengineurlrequestinfo.cpp \ + qwebengineurlrequestjob.cpp \ + qwebengineurlschemehandler.cpp diff --git a/src/core/api/qwebengineurlrequestjob.cpp b/src/core/api/qwebengineurlrequestjob.cpp new file mode 100644 index 000000000..f2a7f1619 --- /dev/null +++ b/src/core/api/qwebengineurlrequestjob.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwebengineurlrequestjob.h" + +#include "url_request_custom_job_delegate.h" + +using QtWebEngineCore::URLRequestCustomJobDelegate; + +QT_BEGIN_NAMESPACE + +/*! + \class QWebEngineUrlRequestJob + \brief The QWebEngineUrlRequestJob class represents a custom URL request. + \since 5.6 + + A QWebEngineUrlRequestJob is given to QWebEngineUrlSchemeHandler::requestStarted() and must + be handled by the derived implementations of the class. + + A job can be handled by calling either setReply(), redirect() or setError(). + + The class is owned by QtWebEngine and does not need to be deleted. Note QtWebEngine may delete + the job when it is no longer needed, so the signal QObject::destroyed() must be monitored if + a pointer to the object is stored. + + \inmodule QtWebEngineCore +*/ + +/*! + \internal + */ +QWebEngineUrlRequestJob::QWebEngineUrlRequestJob(URLRequestCustomJobDelegate * p) + : QObject(p) // owned by the jobdelegate and deleted when the job is done + , d_ptr(p) +{ +} + +/*! + \internal + */ +QWebEngineUrlRequestJob::~QWebEngineUrlRequestJob() +{ +} + +/*! + Returns the url requested. + */ +QUrl QWebEngineUrlRequestJob::requestUrl() const +{ + return d_ptr->url(); +} + +/*! + Sets the reply for the request to \a device with the mime-type \a contentType. + */ +void QWebEngineUrlRequestJob::setReply(const QByteArray &contentType, QIODevice *device) +{ + d_ptr->setReply(contentType, device); +} + +/*! + Fails the request with error \a error. + */ +void QWebEngineUrlRequestJob::setError(Error r) +{ + d_ptr->fail((URLRequestCustomJobDelegate::Error)r); +} + +/*! + Tell the request is redirected to \a url. + */ +void QWebEngineUrlRequestJob::setRedirect(const QUrl &url) +{ + d_ptr->redirect(url); +} + +QT_END_NAMESPACE diff --git a/src/core/api/qwebengineurlrequestjob.h b/src/core/api/qwebengineurlrequestjob.h new file mode 100644 index 000000000..1be3808fa --- /dev/null +++ b/src/core/api/qwebengineurlrequestjob.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWEBENGINEURLREQUESTJOB_H +#define QWEBENGINEURLREQUESTJOB_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qtwebenginecoreglobal.h" + +#include +#include +#include + +namespace QtWebEngineCore { +class URLRequestCustomJobDelegate; +} // namespace + +QT_BEGIN_NAMESPACE + +class QIODevice; + +class QWEBENGINE_EXPORT QWebEngineUrlRequestJob : public QObject { + Q_OBJECT +public: + ~QWebEngineUrlRequestJob(); + + enum Error { + NoError = 0, + UrlNotFound, + UrlInvalid, + RequestAborted, + RequestDenied, + RequestFailed + }; + Q_ENUM(Error) + + QUrl requestUrl() const; + void setReply(const QByteArray &contentType, QIODevice *device); + void setError(Error error); + void setRedirect(const QUrl &url); + +private: + QWebEngineUrlRequestJob(QtWebEngineCore::URLRequestCustomJobDelegate *); + friend class QWebEngineUrlSchemeHandlerPrivate; + + QtWebEngineCore::URLRequestCustomJobDelegate* d_ptr; +}; + +QT_END_NAMESPACE + +#endif // QWEBENGINEURLREQUESTJOB_H diff --git a/src/core/api/qwebengineurlschemehandler.cpp b/src/core/api/qwebengineurlschemehandler.cpp new file mode 100644 index 000000000..330648893 --- /dev/null +++ b/src/core/api/qwebengineurlschemehandler.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwebengineurlschemehandler.h" +#include "qwebengineurlschemehandler_p.h" + +#include "qwebengineurlrequestjob.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QWebEngineUrlSchemeHandler + \brief The QWebEngineUrlSchemeHandler base class for handling custom URL schemes. + \since 5.6 + + To implement a custom URL scheme for QtWebEngine you must write a class derived from this class, + and reimplement requestStarted(). + + \inmodule QtWebEngineCore + +*/ + +QWebEngineUrlSchemeHandlerPrivate::QWebEngineUrlSchemeHandlerPrivate(const QByteArray &scheme, QWebEngineUrlSchemeHandler *q) + : CustomUrlSchemeHandler(scheme) + , q_ptr(q) +{ +} + +QWebEngineUrlSchemeHandlerPrivate::~QWebEngineUrlSchemeHandlerPrivate() +{ +} + +bool QWebEngineUrlSchemeHandlerPrivate::handleJob(QtWebEngineCore::URLRequestCustomJobDelegate *job) +{ + QWebEngineUrlRequestJob *requestJob = new QWebEngineUrlRequestJob(job); + q_ptr->requestStarted(requestJob); + return true; +} + +/*! + Constructs a new URL scheme handler. + + The handler is created for \a scheme with the parent \a parent. + + */ +QWebEngineUrlSchemeHandler::QWebEngineUrlSchemeHandler(const QByteArray &scheme, QObject *parent) + : QObject(parent) + , d_ptr(new QWebEngineUrlSchemeHandlerPrivate(scheme, this)) +{ +} + +QWebEngineUrlSchemeHandler::~QWebEngineUrlSchemeHandler() +{ + delete d_ptr; +} + +/*! + Returns the custom URL scheme handled. +*/ +QByteArray QWebEngineUrlSchemeHandler::scheme() const +{ + return d_ptr->scheme(); +} + +/*! + \fn void QWebEngineUrlSchemeHandler::requestStarted(QWebEngineUrlRequestJob *request) + + This method is called whenever a request \a request for the registered scheme is started. + + This method must be reimplemented by all custom URL scheme handlers. + The request is asynchronous and does not need to be handled right away. + + \sa QWebEngineUrlRequestJob +*/ + +QT_END_NAMESPACE diff --git a/src/core/api/qwebengineurlschemehandler.h b/src/core/api/qwebengineurlschemehandler.h new file mode 100644 index 000000000..b6f6a69f0 --- /dev/null +++ b/src/core/api/qwebengineurlschemehandler.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWEBENGINEURLSCHEMEHANDLER_H +#define QWEBENGINEURLSCHEMEHANDLER_H + +#include "qtwebenginecoreglobal.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +class QWebEngineUrlRequestJob; +class QWebEngineUrlSchemeHandlerPrivate; + +class QWEBENGINE_EXPORT QWebEngineUrlSchemeHandler : public QObject { + Q_OBJECT +public: + QWebEngineUrlSchemeHandler(const QByteArray &scheme, QObject *parent = 0); + ~QWebEngineUrlSchemeHandler(); + + QByteArray scheme() const; + + virtual void requestStarted(QWebEngineUrlRequestJob*) = 0; + +private: + Q_DISABLE_COPY(QWebEngineUrlSchemeHandler) + Q_DECLARE_PRIVATE(QWebEngineUrlSchemeHandler) + friend class QWebEngineProfile; + friend class QQuickWebEngineProfile; + QWebEngineUrlSchemeHandlerPrivate *d_ptr; +}; + +QT_END_NAMESPACE + +#endif // QWEBENGINEURLSCHEMEHANDLER_H diff --git a/src/core/api/qwebengineurlschemehandler_p.h b/src/core/api/qwebengineurlschemehandler_p.h new file mode 100644 index 000000000..dc4b272b3 --- /dev/null +++ b/src/core/api/qwebengineurlschemehandler_p.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWEBENGINEURLSCHEMEHANDLER_P_H +#define QWEBENGINEURLSCHEMEHANDLER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qwebengineurlschemehandler.h" + +#include "custom_url_scheme_handler.h" + +QT_BEGIN_NAMESPACE + +class QWebEngineProfile; +class QWebEngineUrlRequestJob; +class QWebEngineUrlSchemeHandler; + +class QWEBENGINE_EXPORT QWebEngineUrlSchemeHandlerPrivate : public QtWebEngineCore::CustomUrlSchemeHandler { +public: + Q_DECLARE_PUBLIC(QWebEngineUrlSchemeHandler) + + QWebEngineUrlSchemeHandlerPrivate(const QByteArray &, QWebEngineUrlSchemeHandler *); + virtual ~QWebEngineUrlSchemeHandlerPrivate(); + + virtual bool handleJob(QtWebEngineCore::URLRequestCustomJobDelegate*) Q_DECL_OVERRIDE; + +private: + QWebEngineUrlSchemeHandler *q_ptr; +}; + +QT_END_NAMESPACE + +#endif // QWEBENGINEURLSCHEMEHANDLER_P_H diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp index 75a906b35..48d05ae1d 100644 --- a/src/core/browser_context_adapter.cpp +++ b/src/core/browser_context_adapter.cpp @@ -358,6 +358,12 @@ void BrowserContextAdapter::updateCustomUrlSchemeHandlers() m_browserContext->url_request_getter_->updateStorageSettings(); } +void BrowserContextAdapter::removeCustomUrlSchemeHandler(CustomUrlSchemeHandler *handler) +{ + m_customUrlSchemeHandlers.removeOne(handler); + Q_ASSERT(!m_customUrlSchemeHandlers.contains(handler)); +} + UserScriptControllerHost *BrowserContextAdapter::userScriptController() { if (!m_userScriptController) diff --git a/src/core/browser_context_adapter.h b/src/core/browser_context_adapter.h index 896743f4b..0bca1bf8b 100644 --- a/src/core/browser_context_adapter.h +++ b/src/core/browser_context_adapter.h @@ -147,6 +147,7 @@ public: QVector &customUrlSchemeHandlers(); void updateCustomUrlSchemeHandlers(); + void removeCustomUrlSchemeHandler(CustomUrlSchemeHandler*); UserScriptControllerHost *userScriptController(); void permissionRequestReply(const QUrl &origin, PermissionType type, bool reply); diff --git a/src/core/custom_url_scheme_handler.cpp b/src/core/custom_url_scheme_handler.cpp index b9fcf9c36..29791b555 100644 --- a/src/core/custom_url_scheme_handler.cpp +++ b/src/core/custom_url_scheme_handler.cpp @@ -44,10 +44,6 @@ CustomUrlSchemeHandler::CustomUrlSchemeHandler(const QByteArray &scheme) { } -CustomUrlSchemeHandler::~CustomUrlSchemeHandler() -{ -} - QByteArray CustomUrlSchemeHandler::scheme() const { return m_scheme; diff --git a/src/core/custom_url_scheme_handler.h b/src/core/custom_url_scheme_handler.h index 745f0eb4c..d866628de 100644 --- a/src/core/custom_url_scheme_handler.h +++ b/src/core/custom_url_scheme_handler.h @@ -53,7 +53,7 @@ class URLRequestCustomJobDelegate; class QWEBENGINE_EXPORT CustomUrlSchemeHandler { public: explicit CustomUrlSchemeHandler(const QByteArray &); - ~CustomUrlSchemeHandler(); + virtual ~CustomUrlSchemeHandler() { } QByteArray scheme() const; void setScheme(const QByteArray &); diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp index db8c0dc89..a38a78cf7 100644 --- a/src/webenginewidgets/api/qwebengineprofile.cpp +++ b/src/webenginewidgets/api/qwebengineprofile.cpp @@ -42,7 +42,7 @@ #include "qwebenginepage.h" #include "qwebengineprofile_p.h" #include "qwebenginesettings.h" -#include "qwebengineurlschemehandler_p_p.h" +#include "qwebengineurlschemehandler_p.h" #include "qwebenginescriptcollection_p.h" #include "browser_context_adapter.h" @@ -536,10 +536,16 @@ QWebEngineSettings *QWebEngineProfile::settings() const return d->settings(); } -QWebEngineUrlSchemeHandler *QWebEngineProfilePrivate::urlSchemeHandler(const QByteArray &protocol) +/*! + \since 5.6 + + Returns the custom URL scheme handler register for the URL scheme \a scheme. +*/ +const QWebEngineUrlSchemeHandler *QWebEngineProfile::urlSchemeHandler(const QByteArray &scheme) const { - if (m_urlSchemeHandlers.contains(protocol)) - return m_urlSchemeHandlers.value(protocol); + const Q_D(QWebEngineProfile); + if (d->m_urlSchemeHandlers.contains(scheme)) + return d->m_urlSchemeHandlers.value(scheme); return 0; } @@ -553,8 +559,14 @@ static bool checkInternalScheme(const QByteArray &scheme) return internalSchemes.contains(scheme); } -void QWebEngineProfilePrivate::installUrlSchemeHandler(QWebEngineUrlSchemeHandler *handler) +/*! + \since 5.6 + + Installs the custom URL scheme handler \a handler in the profile. +*/ +void QWebEngineProfile::installUrlSchemeHandler(QWebEngineUrlSchemeHandler *handler) { + Q_D(QWebEngineProfile); Q_ASSERT(handler); QByteArray scheme = handler->scheme(); if (checkInternalScheme(scheme)) { @@ -562,29 +574,51 @@ void QWebEngineProfilePrivate::installUrlSchemeHandler(QWebEngineUrlSchemeHandle return; } - if (m_urlSchemeHandlers.contains(scheme)) { + if (d->m_urlSchemeHandlers.contains(scheme)) { qWarning() << "URL scheme handler already installed for the scheme: " << scheme; return; } - m_urlSchemeHandlers.insert(scheme, handler); - browserContext()->customUrlSchemeHandlers().append(handler->d_func()); - browserContext()->updateCustomUrlSchemeHandlers(); + d->m_urlSchemeHandlers.insert(scheme, handler); + d->browserContext()->customUrlSchemeHandlers().append(handler->d_func()); + d->browserContext()->updateCustomUrlSchemeHandlers(); + connect(handler, SIGNAL(destroyed(QObject*)), this, SLOT(destroyedUrlSchemeHandler(QObject*))); } -void QWebEngineProfilePrivate::removeUrlSchemeHandler(QWebEngineUrlSchemeHandler *handler) +/*! + \since 5.6 + + Removes the custom URL scheme handler \a handler from the profile +*/ +void QWebEngineProfile::removeUrlSchemeHandler(QWebEngineUrlSchemeHandler *handler) { - int count = m_urlSchemeHandlers.remove(handler->scheme()); + Q_D(QWebEngineProfile); + Q_ASSERT(handler); + if (!handler) + return; + int count = d->m_urlSchemeHandlers.remove(handler->scheme()); if (!count) return; - browserContext()->customUrlSchemeHandlers().removeOne(handler->d_func()); - browserContext()->updateCustomUrlSchemeHandlers(); + disconnect(handler, SIGNAL(destroyed(QObject*)), this, SLOT(destroyedUrlSchemeHandler(QObject*))); + d->browserContext()->removeCustomUrlSchemeHandler(handler->d_func()); + d->browserContext()->updateCustomUrlSchemeHandlers(); +} + +/*! + \since 5.6 + + Removes all custom URL scheme handlers installed in the profile. +*/ +void QWebEngineProfile::clearUrlSchemeHandlers() +{ + Q_D(QWebEngineProfile); + d->m_urlSchemeHandlers.clear(); + d->browserContext()->customUrlSchemeHandlers().clear(); + d->browserContext()->updateCustomUrlSchemeHandlers(); } -void QWebEngineProfilePrivate::clearUrlSchemeHandlers() +void QWebEngineProfile::destroyedUrlSchemeHandler(QObject *obj) { - m_urlSchemeHandlers.clear(); - browserContext()->customUrlSchemeHandlers().clear(); - browserContext()->updateCustomUrlSchemeHandlers(); + removeUrlSchemeHandler(qobject_cast(obj)); } QT_END_NAMESPACE diff --git a/src/webenginewidgets/api/qwebengineprofile.h b/src/webenginewidgets/api/qwebengineprofile.h index c617fe361..5532f12ee 100644 --- a/src/webenginewidgets/api/qwebengineprofile.h +++ b/src/webenginewidgets/api/qwebengineprofile.h @@ -55,6 +55,7 @@ class QWebEngineProfilePrivate; class QWebEngineSettings; class QWebEngineScriptCollection; class QWebEngineUrlRequestInterceptor; +class QWebEngineUrlSchemeHandler; class QWEBENGINEWIDGETS_EXPORT QWebEngineProfile : public QObject { Q_OBJECT @@ -109,11 +110,19 @@ public: QWebEngineSettings *settings() const; QWebEngineScriptCollection *scripts() const; + const QWebEngineUrlSchemeHandler *urlSchemeHandler(const QByteArray &) const; + void installUrlSchemeHandler(QWebEngineUrlSchemeHandler *); + void removeUrlSchemeHandler(QWebEngineUrlSchemeHandler *); + void clearUrlSchemeHandlers(); + static QWebEngineProfile *defaultProfile(); Q_SIGNALS: void downloadRequested(QWebEngineDownloadItem *download); +private Q_SLOTS: + void destroyedUrlSchemeHandler(QObject *obj); + private: Q_DISABLE_COPY(QWebEngineProfile) Q_DECLARE_PRIVATE(QWebEngineProfile) diff --git a/src/webenginewidgets/api/qwebengineprofile_p.h b/src/webenginewidgets/api/qwebengineprofile_p.h index ee3ea57d8..8ba64c438 100644 --- a/src/webenginewidgets/api/qwebengineprofile_p.h +++ b/src/webenginewidgets/api/qwebengineprofile_p.h @@ -79,18 +79,13 @@ public: void downloadRequested(DownloadItemInfo &info) Q_DECL_OVERRIDE; void downloadUpdated(const DownloadItemInfo &info) Q_DECL_OVERRIDE; - QWebEngineUrlSchemeHandler *urlSchemeHandler(const QByteArray &); - void installUrlSchemeHandler(QWebEngineUrlSchemeHandler *); - void removeUrlSchemeHandler(QWebEngineUrlSchemeHandler *); - void clearUrlSchemeHandlers(); - private: QWebEngineProfile *q_ptr; QWebEngineSettings *m_settings; QScopedPointer m_scriptCollection; QExplicitlySharedDataPointer m_browserContextRef; QMap > m_ongoingDownloads; - QMap > m_urlSchemeHandlers; + QMap m_urlSchemeHandlers; }; QT_END_NAMESPACE diff --git a/src/webenginewidgets/api/qwebengineurlrequestjob.cpp b/src/webenginewidgets/api/qwebengineurlrequestjob.cpp deleted file mode 100644 index 2bff57236..000000000 --- a/src/webenginewidgets/api/qwebengineurlrequestjob.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwebengineurlrequestjob_p.h" - -#include "qwebengineprofile.h" - -#include "url_request_custom_job_delegate.h" - -using QtWebEngineCore::URLRequestCustomJobDelegate; - -QT_BEGIN_NAMESPACE - -/*! - \class QWebEngineUrlRequestJob - \brief The QWebEngineUrlRequestJob class represents a custom URL request. - \since 5.5 - \internal - - A QWebEngineUrlRequestJob is given to QWebEngineUrlSchemeHandler::requestStarted() and must - be handled by the derived implementations of class. - - A job can be handled by calling either setReply(), redirect() or setError(). - - The class is owned by QtWebEngine and does not need to be deleted. Note QtWebEngine may delete - the job when it is no longer needed, so the signal QObject::destroyed() must be monitored if - a pointer to the object is stored. - - \inmodule QtWebEngineWidgets -*/ - -/*! - \internal - */ -QWebEngineUrlRequestJob::QWebEngineUrlRequestJob(URLRequestCustomJobDelegate * p) - : QObject(p) // owned by the jobdelegate and deleted when the job is done - , d_ptr(p) -{ -} - -/*! - \internal - */ -QWebEngineUrlRequestJob::~QWebEngineUrlRequestJob() -{ -} - -/*! - Returns the url requested. - */ -QUrl QWebEngineUrlRequestJob::requestUrl() const -{ - return d_ptr->url(); -} - -/*! - Sets the reply for the request to \a device with the mime-type \a contentType. - */ -void QWebEngineUrlRequestJob::setReply(const QByteArray &contentType, QIODevice *device) -{ - d_ptr->setReply(contentType, device); -} - -/*! - Fails the request with error \a error. - */ -void QWebEngineUrlRequestJob::setError(Error r) -{ - d_ptr->fail((URLRequestCustomJobDelegate::Error)r); -} - -/*! - Tell the request is redirected to \a url. - */ -void QWebEngineUrlRequestJob::setRedirect(const QUrl &url) -{ - d_ptr->redirect(url); -} - -QT_END_NAMESPACE diff --git a/src/webenginewidgets/api/qwebengineurlrequestjob_p.h b/src/webenginewidgets/api/qwebengineurlrequestjob_p.h deleted file mode 100644 index 32e2498fa..000000000 --- a/src/webenginewidgets/api/qwebengineurlrequestjob_p.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWEBENGINEURLREQUESTJOB_H -#define QWEBENGINEURLREQUESTJOB_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qtwebenginewidgetsglobal.h" - -#include -#include -#include - -namespace QtWebEngineCore { -class URLRequestCustomJobDelegate; -} // namespace - -QT_BEGIN_NAMESPACE - -class QIODevice; - -class QWEBENGINEWIDGETS_EXPORT QWebEngineUrlRequestJob : public QObject { - Q_OBJECT -public: - ~QWebEngineUrlRequestJob(); - - enum Error { - NoError = 0, - UrlNotFound, - UrlInvalid, - RequestAborted, - RequestDenied, - RequestFailed - }; - - QUrl requestUrl() const; - void setReply(const QByteArray &contentType, QIODevice *device); - void setError(Error error); - void setRedirect(const QUrl &url); - -private: - QWebEngineUrlRequestJob(QtWebEngineCore::URLRequestCustomJobDelegate *); - friend class QWebEngineUrlSchemeHandlerPrivate; - - QtWebEngineCore::URLRequestCustomJobDelegate* d_ptr; -}; - -QT_END_NAMESPACE - -#endif // QWEBENGINEURLREQUESTJOB_H diff --git a/src/webenginewidgets/api/qwebengineurlschemehandler.cpp b/src/webenginewidgets/api/qwebengineurlschemehandler.cpp deleted file mode 100644 index a0e751c24..000000000 --- a/src/webenginewidgets/api/qwebengineurlschemehandler.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwebengineurlschemehandler_p.h" -#include "qwebengineurlschemehandler_p_p.h" - -#include "qwebengineprofile.h" -#include "qwebengineprofile_p.h" -#include "qwebengineurlrequestjob_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QWebEngineUrlSchemeHandler - \brief The QWebEngineUrlSchemeHandler Base class for handling custom URL schemes. - \since 5.5 - \internal - - To implement a custom URL scheme for QtWebEngine you must write a class derived from this class, - and reimplement requestStarted(). - - To install a custom URL scheme handler into a QtWebProfile, you only need to call the constructor - with the correct profile. Each instance of a QWebEngineUrlSchemeHandler can only handle requests - from a single profile. - - \inmodule QtWebEngineWidgets - -*/ - -QWebEngineUrlSchemeHandlerPrivate::QWebEngineUrlSchemeHandlerPrivate(const QByteArray &scheme, QWebEngineUrlSchemeHandler *q, QWebEngineProfile *profile) - : CustomUrlSchemeHandler(scheme) - , q_ptr(q) - , m_profile(profile) -{ -} - -QWebEngineUrlSchemeHandlerPrivate::~QWebEngineUrlSchemeHandlerPrivate() -{ -} - -bool QWebEngineUrlSchemeHandlerPrivate::handleJob(QtWebEngineCore::URLRequestCustomJobDelegate *job) -{ - QWebEngineUrlRequestJob *requestJob = new QWebEngineUrlRequestJob(job); - q_ptr->requestStarted(requestJob); - return true; -} - -/*! - Constructs a new URL scheme handler. - - The handler is created for \a scheme and for the \a profile. - - */ -QWebEngineUrlSchemeHandler::QWebEngineUrlSchemeHandler(const QByteArray &scheme, QWebEngineProfile *profile, QObject *parent) - : QObject(parent) - , d_ptr(new QWebEngineUrlSchemeHandlerPrivate(scheme, this, profile)) -{ - profile->d_func()->installUrlSchemeHandler(this); -} - -QWebEngineUrlSchemeHandler::~QWebEngineUrlSchemeHandler() -{ - if (d_ptr->m_profile) - d_ptr->m_profile->d_func()->removeUrlSchemeHandler(this); -} - -/*! - Returns the custom URL scheme handled. -*/ -QByteArray QWebEngineUrlSchemeHandler::scheme() const -{ - return d_ptr->scheme(); -} - -/*! - \fn void QWebEngineUrlSchemeHandler::requestStarted(QWebEngineUrlRequestJob *request) - - This method is called whenever a request for the registered scheme is started. - - This method must be reimplemented by all custom URL scheme handlers. - The request is asynchronous and does not need to be handled right away. - - \sa QWebEngineUrlRequestJob -*/ - -QT_END_NAMESPACE diff --git a/src/webenginewidgets/api/qwebengineurlschemehandler_p.h b/src/webenginewidgets/api/qwebengineurlschemehandler_p.h deleted file mode 100644 index 7de87dff2..000000000 --- a/src/webenginewidgets/api/qwebengineurlschemehandler_p.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWEBENGINEURLSCHEMEHANDLER_H -#define QWEBENGINEURLSCHEMEHANDLER_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qtwebenginewidgetsglobal.h" - -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QWebEngineProfile; -class QWebEngineUrlRequestJob; -class QWebEngineUrlSchemeHandlerPrivate; - -class QWEBENGINEWIDGETS_EXPORT QWebEngineUrlSchemeHandler : public QObject { - Q_OBJECT -public: - QWebEngineUrlSchemeHandler(const QByteArray &scheme, QWebEngineProfile *profile, QObject *parent = 0); - virtual ~QWebEngineUrlSchemeHandler(); - - QByteArray scheme() const; - - virtual void requestStarted(QWebEngineUrlRequestJob*) = 0; - -private: - Q_DECLARE_PRIVATE(QWebEngineUrlSchemeHandler) - friend class QWebEngineProfilePrivate; - QScopedPointer d_ptr; -}; - -QT_END_NAMESPACE - -#endif // QWEBENGINEURLSCHEMEHANDLER_H diff --git a/src/webenginewidgets/api/qwebengineurlschemehandler_p_p.h b/src/webenginewidgets/api/qwebengineurlschemehandler_p_p.h deleted file mode 100644 index d349d7d8c..000000000 --- a/src/webenginewidgets/api/qwebengineurlschemehandler_p_p.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWEBENGINEURLSCHEMEHANDLER_P_H -#define QWEBENGINEURLSCHEMEHANDLER_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qwebengineurlschemehandler_p.h" - -#include "custom_url_scheme_handler.h" - -#include - -QT_BEGIN_NAMESPACE - -class QWebEngineProfile; -class QWebEngineUrlRequestJob; -class QWebEngineUrlSchemeHandler; - -class QWebEngineUrlSchemeHandlerPrivate : public QtWebEngineCore::CustomUrlSchemeHandler { -public: - Q_DECLARE_PUBLIC(QWebEngineUrlSchemeHandler) - - QWebEngineUrlSchemeHandlerPrivate(const QByteArray &, QWebEngineUrlSchemeHandler *, QWebEngineProfile *); - virtual ~QWebEngineUrlSchemeHandlerPrivate(); - - virtual bool handleJob(QtWebEngineCore::URLRequestCustomJobDelegate*) Q_DECL_OVERRIDE; - -private: - QWebEngineUrlSchemeHandler *q_ptr; - QPointer m_profile; -}; - -QT_END_NAMESPACE - -#endif // QWEBENGINEURLSCHEMEHANDLER_P_H diff --git a/src/webenginewidgets/webenginewidgets.pro b/src/webenginewidgets/webenginewidgets.pro index 0d92767c1..c32185563 100644 --- a/src/webenginewidgets/webenginewidgets.pro +++ b/src/webenginewidgets/webenginewidgets.pro @@ -20,8 +20,6 @@ SOURCES = \ api/qwebenginescript.cpp \ api/qwebenginescriptcollection.cpp \ api/qwebenginesettings.cpp \ - api/qwebengineurlrequestjob.cpp \ - api/qwebengineurlschemehandler.cpp \ api/qwebengineview.cpp \ render_widget_host_view_qt_delegate_widget.cpp @@ -38,9 +36,6 @@ HEADERS = \ api/qwebenginescriptcollection.h \ api/qwebenginescriptcollection_p.h \ api/qwebenginesettings.h \ - api/qwebengineurlrequestjob_p.h \ - api/qwebengineurlschemehandler_p.h \ - api/qwebengineurlschemehandler_p_p.h \ api/qwebengineview.h \ api/qwebengineview_p.h \ render_widget_host_view_qt_delegate_widget.h -- cgit v1.2.3