Falkon Develop
Cross-platform Qt-based web browser
extensionschemehandler.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
19
20#include <QBuffer>
21#include <QUrlQuery>
22#include <QWebEngineUrlRequestJob>
23
24// ExtensionSchemeHandler
25void ExtensionSchemeHandler::setReply(QWebEngineUrlRequestJob *job, const QByteArray &contentType, const QByteArray &content)
26{
27 auto *buffer = new QBuffer(job);
28 buffer->open(QIODevice::ReadWrite);
29 buffer->write(content);
30 buffer->seek(0);
31 job->reply(contentType, buffer);
32}
33
34// ExtensionSchemeManager
36 : QWebEngineUrlSchemeHandler(parent)
37{
38}
39
40void ExtensionSchemeManager::requestStarted(QWebEngineUrlRequestJob *job)
41{
42 ExtensionSchemeHandler *handler = m_handlers.value(job->requestUrl().host());
43 if (handler) {
44 handler->requestStarted(job);
45 } else {
46 job->fail(QWebEngineUrlRequestJob::UrlInvalid);
47 }
48}
49
51{
52 m_handlers[name] = handler;
53}
54
56{
57 m_handlers.remove(m_handlers.key(handler));
58}
void setReply(QWebEngineUrlRequestJob *job, const QByteArray &contentType, const QByteArray &content)
virtual void requestStarted(QWebEngineUrlRequestJob *job)=0
void unregisterHandler(ExtensionSchemeHandler *handler)
void registerHandler(const QString &name, ExtensionSchemeHandler *handler)
void requestStarted(QWebEngineUrlRequestJob *job) override
ExtensionSchemeManager(QObject *parent=nullptr)