diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-02-05 10:48:38 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-02-19 14:49:08 +0000 |
commit | d3f80fb0b71e3020e4e8173e2002dc93efdc5f60 (patch) | |
tree | 1a019dbd7330479a278cce5908975ee940af38ef /src/core | |
parent | e263449d32e9392985c1587f2a0b4e0e77e605a2 (diff) |
Experimental custom URL scheme API
Introduces API for custom URL scheme as an experimental API in widgets.
A QML api is not included yet.
Change-Id: Ice4542e5238feb961a4c9c60a809455e31dc1ec6
Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/browser_context_adapter.cpp | 11 | ||||
-rw-r--r-- | src/core/browser_context_adapter.h | 6 | ||||
-rw-r--r-- | src/core/core_gyp_generator.pro | 8 | ||||
-rw-r--r-- | src/core/custom_protocol_handler.cpp | 55 | ||||
-rw-r--r-- | src/core/custom_protocol_handler.h | 71 | ||||
-rw-r--r-- | src/core/custom_url_scheme_handler.cpp | 63 | ||||
-rw-r--r-- | src/core/custom_url_scheme_handler.h | 67 | ||||
-rw-r--r-- | src/core/url_request_context_getter_qt.cpp | 6 | ||||
-rw-r--r-- | src/core/url_request_custom_job.cpp | 143 | ||||
-rw-r--r-- | src/core/url_request_custom_job.h | 80 | ||||
-rw-r--r-- | src/core/url_request_custom_job_delegate.cpp | 63 | ||||
-rw-r--r-- | src/core/url_request_custom_job_delegate.h | 65 |
12 files changed, 638 insertions, 0 deletions
diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp index b8c14c39e..1749fc708 100644 --- a/src/core/browser_context_adapter.cpp +++ b/src/core/browser_context_adapter.cpp @@ -314,3 +314,14 @@ void BrowserContextAdapter::setHttpCacheMaxSize(int maxSize) if (m_browserContext->url_request_getter_.get()) m_browserContext->url_request_getter_->updateHttpCache(); } + +QVector<CustomUrlSchemeHandler*> &BrowserContextAdapter::customUrlSchemeHandlers() +{ + return m_customUrlSchemeHandlers; +} + +void BrowserContextAdapter::updateCustomUrlSchemeHandlers() +{ + if (m_browserContext->url_request_getter_.get()) + m_browserContext->url_request_getter_->updateStorageSettings(); +} diff --git a/src/core/browser_context_adapter.h b/src/core/browser_context_adapter.h index 90f0bec7a..6389d666c 100644 --- a/src/core/browser_context_adapter.h +++ b/src/core/browser_context_adapter.h @@ -42,9 +42,11 @@ #include <QScopedPointer> #include <QSharedData> #include <QString> +#include <QVector> class BrowserContextAdapterClient; class BrowserContextQt; +class CustomUrlSchemeHandler; class DownloadManagerDelegateQt; class WebEngineVisitedLinksManager; @@ -119,6 +121,9 @@ public: bool trackVisitedLinks() const; bool persistVisitedLinks() const; + QVector<CustomUrlSchemeHandler*> &customUrlSchemeHandlers(); + void updateCustomUrlSchemeHandlers(); + private: QString m_name; bool m_offTheRecord; @@ -131,6 +136,7 @@ private: HttpCacheType m_httpCacheType; PersistentCookiesPolicy m_persistentCookiesPolicy; VisitedLinksPolicy m_visitedLinksPolicy; + QVector<CustomUrlSchemeHandler*> m_customUrlSchemeHandlers; BrowserContextAdapterClient *m_client; int m_httpCacheMaxSize; diff --git a/src/core/core_gyp_generator.pro b/src/core/core_gyp_generator.pro index 3980dcc5a..b93ea0175 100644 --- a/src/core/core_gyp_generator.pro +++ b/src/core/core_gyp_generator.pro @@ -41,6 +41,8 @@ SOURCES = \ content_client_qt.cpp \ content_browser_client_qt.cpp \ content_main_delegate_qt.cpp \ + custom_protocol_handler.cpp \ + custom_url_scheme_handler.cpp \ delegated_frame_node.cpp \ desktop_screen_qt.cpp \ dev_tools_http_handler_delegate_qt.cpp \ @@ -66,6 +68,8 @@ SOURCES = \ stream_video_node.cpp \ surface_factory_qt.cpp \ url_request_context_getter_qt.cpp \ + url_request_custom_job.cpp \ + url_request_custom_job_delegate.cpp \ url_request_qrc_job_qt.cpp \ web_channel_ipc_transport_host.cpp \ web_contents_adapter.cpp \ @@ -94,6 +98,8 @@ HEADERS = \ content_client_qt.h \ content_browser_client_qt.h \ content_main_delegate_qt.h \ + custom_protocol_handler.h \ + custom_url_scheme_handler.h \ delegated_frame_node.h \ desktop_screen_qt.h \ dev_tools_http_handler_delegate_qt.h \ @@ -121,6 +127,8 @@ HEADERS = \ surface_factory_qt.h \ type_conversion.h \ url_request_context_getter_qt.h \ + url_request_custom_job.h \ + url_request_custom_job_delegate.h \ url_request_qrc_job_qt.h \ web_channel_ipc_transport_host.h \ web_contents_adapter.h \ diff --git a/src/core/custom_protocol_handler.cpp b/src/core/custom_protocol_handler.cpp new file mode 100644 index 000000000..fd8cebb9e --- /dev/null +++ b/src/core/custom_protocol_handler.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 "custom_protocol_handler.h" +#include "url_request_custom_job.h" + +#include "net/base/net_errors.h" +#include "net/url_request/url_request.h" +#include "net/url_request/url_request_error_job.h" + +CustomProtocolHandler::CustomProtocolHandler(CustomUrlSchemeHandler *schemeHandler) + : m_schemeHandler(schemeHandler) +{ +} + +net::URLRequestJob *CustomProtocolHandler::MaybeCreateJob(net::URLRequest *request, net::NetworkDelegate *networkDelegate) const +{ + if (!networkDelegate) + return new net::URLRequestErrorJob(request, Q_NULLPTR, net::ERR_ACCESS_DENIED); + + return new URLRequestCustomJob(request, networkDelegate, m_schemeHandler); +} diff --git a/src/core/custom_protocol_handler.h b/src/core/custom_protocol_handler.h new file mode 100644 index 000000000..4b29a82b7 --- /dev/null +++ b/src/core/custom_protocol_handler.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 CUSTOM_PROTOCOL_HANDLER_H_ +#define CUSTOM_PROTOCOL_HANDLER_H_ + +#include "qtwebenginecoreglobal.h" +#include "net/url_request/url_request_job_factory.h" + +#include <QtCore/QByteArray> +#include <QtCore/QObject> +#include <QtCore/qcompilerdetection.h> // Needed for Q_DECL_OVERRIDE + +class BrowserContextAdapter; +class CustomUrlSchemeHandler; + +QT_FORWARD_DECLARE_CLASS(QIODevice) + +namespace net { +class NetworkDelegate; +class URLRequestJob; +} // namespace + +// Implements a ProtocolHandler for custom URL schemes. +// If |network_delegate_| is NULL then all file requests will fail with ERR_ACCESS_DENIED. +class QWEBENGINE_EXPORT CustomProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { + +public: + CustomProtocolHandler(CustomUrlSchemeHandler *); + + virtual net::URLRequestJob *MaybeCreateJob(net::URLRequest *request, net::NetworkDelegate *networkDelegate) const Q_DECL_OVERRIDE; + +private: + DISALLOW_COPY_AND_ASSIGN(CustomProtocolHandler); + CustomUrlSchemeHandler *m_schemeHandler; +}; + +#endif // CUSTOM_PROTOCOL_HANDLER_H_ diff --git a/src/core/custom_url_scheme_handler.cpp b/src/core/custom_url_scheme_handler.cpp new file mode 100644 index 000000000..a8701a5d4 --- /dev/null +++ b/src/core/custom_url_scheme_handler.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 "custom_url_scheme_handler.h" +#include "custom_protocol_handler.h" + +CustomUrlSchemeHandler::CustomUrlSchemeHandler(const QByteArray &scheme) + : m_scheme(scheme) + , m_protocolHandler(new CustomProtocolHandler(this)) +{ +} + +CustomUrlSchemeHandler::~CustomUrlSchemeHandler() +{ +} + +QByteArray CustomUrlSchemeHandler::scheme() const +{ + return m_scheme; +} + +void CustomUrlSchemeHandler::setScheme(const QByteArray &scheme) +{ + m_scheme = scheme; +} + +CustomProtocolHandler *CustomUrlSchemeHandler::protocolHandler() +{ + return m_protocolHandler.data(); +} diff --git a/src/core/custom_url_scheme_handler.h b/src/core/custom_url_scheme_handler.h new file mode 100644 index 000000000..fef29c98a --- /dev/null +++ b/src/core/custom_url_scheme_handler.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 CUSTOM_URL_SCHEME_HANDLER_H_ +#define CUSTOM_URL_SCHEME_HANDLER_H_ + +#include "qtwebenginecoreglobal.h" + +#include <QtCore/QByteArray> +#include <QtCore/QScopedPointer> + +class BrowserContextAdapter; +class CustomProtocolHandler; +class URLRequestCustomJobDelegate; + +QT_FORWARD_DECLARE_CLASS(QIODevice) + +class QWEBENGINE_EXPORT CustomUrlSchemeHandler { +public: + explicit CustomUrlSchemeHandler(const QByteArray &); + ~CustomUrlSchemeHandler(); + + QByteArray scheme() const; + void setScheme(const QByteArray &); + CustomProtocolHandler *protocolHandler(); + + 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 96ba36565..41af37e5d 100644 --- a/src/core/url_request_context_getter_qt.cpp +++ b/src/core/url_request_context_getter_qt.cpp @@ -62,6 +62,8 @@ #include "net/ftp/ftp_network_layer.h" #include "browser_context_adapter.h" +#include "custom_protocol_handler.h" +#include "custom_url_scheme_handler.h" #include "content_client_qt.h" #include "network_delegate_qt.h" #include "qrc_protocol_handler_qt.h" @@ -282,6 +284,10 @@ void URLRequestContextGetterQt::generateJobFactory() m_jobFactory->SetProtocolHandler(url::kFtpScheme, 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_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 new file mode 100644 index 000000000..e97804c2f --- /dev/null +++ b/src/core/url_request_custom_job.cpp @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 "url_request_custom_job.h" +#include "url_request_custom_job_delegate.h" + +#include "custom_url_scheme_handler.h" +#include "type_conversion.h" + +#include "content/public/browser/browser_thread.h" +#include "net/base/net_errors.h" +#include "net/base/io_buffer.h" + +#include <QFileInfo> +#include <QMimeDatabase> +#include <QMimeType> +#include <QUrl> + +using namespace net; + +URLRequestCustomJob::URLRequestCustomJob(URLRequest *request, NetworkDelegate *networkDelegate, CustomUrlSchemeHandler *schemeHandler) + : URLRequestJob(request, networkDelegate) + , m_device(0) + , m_schemeHandler(schemeHandler) + , m_weakFactory(this) +{ +} + +URLRequestCustomJob::~URLRequestCustomJob() +{ + if (m_device && m_device->isOpen()) + m_device->close(); +} + +void URLRequestCustomJob::Start() +{ + content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, base::Bind(&URLRequestCustomJob::startAsync, m_weakFactory.GetWeakPtr())); +} + +void URLRequestCustomJob::Kill() +{ + if (m_device->isOpen()) + m_device->close(); + m_weakFactory.InvalidateWeakPtrs(); + + URLRequestJob::Kill(); +} + +bool URLRequestCustomJob::GetMimeType(std::string *mimeType) const +{ + if (m_mimeType.size() > 0) { + *mimeType = m_mimeType; + return true; + } + return false; +} + +bool URLRequestCustomJob::GetCharset(std::string* charset) +{ + if (m_charset.size() > 0) { + *charset = m_charset; + return true; + } + return false; +} + +void URLRequestCustomJob::setReplyMimeType(const std::string &mimeType) +{ + m_mimeType = mimeType; +} + +void URLRequestCustomJob::setReplyCharset(const std::string &charset) +{ + m_charset = charset; +} + +void URLRequestCustomJob::setReplyDevice(QIODevice *device) +{ + m_device = device; + if (m_device && !m_device->isReadable()) + m_device->open(QIODevice::ReadOnly); + content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJob::notifyStarted, m_weakFactory.GetWeakPtr())); +} + +bool URLRequestCustomJob::ReadRawData(IOBuffer *buf, int bufSize, int *bytesRead) +{ + Q_ASSERT(bytesRead); + qint64 rv = m_device ? m_device->read(buf->data(), bufSize) : -1; + if (rv >= 0) { + *bytesRead = static_cast<int>(rv); + return true; + } else { + NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, ERR_FAILED)); + } + return false; +} + +void URLRequestCustomJob::notifyStarted() +{ + if (m_device && m_device->isReadable()) + NotifyHeadersComplete(); + else + NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, ERR_INVALID_URL)); +} + +void URLRequestCustomJob::startAsync() +{ + m_delegate.reset(new URLRequestCustomJobDelegate(this)); + m_schemeHandler->handleJob(m_delegate.get()); +} diff --git a/src/core/url_request_custom_job.h b/src/core/url_request_custom_job.h new file mode 100644 index 000000000..c47358e71 --- /dev/null +++ b/src/core/url_request_custom_job.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 URL_REQUEST_CUSTOM_JOB_H_ +#define URL_REQUEST_CUSTOM_JOB_H_ + +#include "net/url_request/url_request.h" +#include "net/url_request/url_request_job.h" + +#include <QtCore/qglobal.h> + +QT_FORWARD_DECLARE_CLASS(QIODevice) + +class CustomUrlSchemeHandler; +class URLRequestCustomJobDelegate; + +// A request job that handles reading custom URL schemes +class URLRequestCustomJob : public net::URLRequestJob { +public: + URLRequestCustomJob(net::URLRequest *request, net::NetworkDelegate *networkDelegate, CustomUrlSchemeHandler *schemeHandler); + virtual void Start() Q_DECL_OVERRIDE; + virtual void Kill() Q_DECL_OVERRIDE; + virtual bool ReadRawData(net::IOBuffer *buf, int bufSize, int *bytesRead) Q_DECL_OVERRIDE; + virtual bool GetMimeType(std::string *mimeType) const Q_DECL_OVERRIDE; + virtual bool GetCharset(std::string *charset) Q_DECL_OVERRIDE; + + void setReplyMimeType(const std::string &); + void setReplyCharset(const std::string &); + void setReplyDevice(QIODevice *); + +protected: + virtual ~URLRequestCustomJob(); + void startAsync(); + void notifyStarted(); + +private: + QIODevice *m_device; + scoped_ptr<URLRequestCustomJobDelegate> m_delegate; + CustomUrlSchemeHandler *m_schemeHandler; + std::string m_mimeType; + std::string m_charset; + base::WeakPtrFactory<URLRequestCustomJob> m_weakFactory; + + DISALLOW_COPY_AND_ASSIGN(URLRequestCustomJob); +}; + +#endif // URL_REQUEST_CUSTOM_JOB_H_ diff --git a/src/core/url_request_custom_job_delegate.cpp b/src/core/url_request_custom_job_delegate.cpp new file mode 100644 index 000000000..fcb2220bc --- /dev/null +++ b/src/core/url_request_custom_job_delegate.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 "url_request_custom_job.h" +#include "url_request_custom_job_delegate.h" + +#include "type_conversion.h" + +#include <QByteArray> + +URLRequestCustomJobDelegate::URLRequestCustomJobDelegate(URLRequestCustomJob *job) + : m_job(job) +{ +} + +URLRequestCustomJobDelegate::~URLRequestCustomJobDelegate() +{ +} + +QUrl URLRequestCustomJobDelegate::url() const +{ + return toQt(m_job->request()->url()); +} + +void URLRequestCustomJobDelegate::setReply(const QByteArray &contentType, QIODevice *device) +{ + m_job->setReplyMimeType(contentType.toStdString()); + m_job->setReplyDevice(device); +} + diff --git a/src/core/url_request_custom_job_delegate.h b/src/core/url_request_custom_job_delegate.h new file mode 100644 index 000000000..e82debdf2 --- /dev/null +++ b/src/core/url_request_custom_job_delegate.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 URL_REQUEST_CUSTOM_JOB_DELEGATE_H_ +#define URL_REQUEST_CUSTOM_JOB_DELEGATE_H_ + +#include "qtwebenginecoreglobal.h" + +#include <QObject> +#include <QUrl> + +QT_FORWARD_DECLARE_CLASS(QIODevice) + +class URLRequestCustomJob; + +class QWEBENGINE_EXPORT URLRequestCustomJobDelegate : public QObject { + Q_OBJECT +public: + ~URLRequestCustomJobDelegate(); + + QUrl url() const; + + void setReply(const QByteArray &contentType, QIODevice *device); + +private: + URLRequestCustomJobDelegate(URLRequestCustomJob *job); + + friend class URLRequestCustomJob; + URLRequestCustomJob *m_job; +}; + +#endif // URL_REQUEST_CUSTOM_JOB_DELEGATE_H_ |