mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
GreaseMonkey: Use acceptNavigationRequest for handling userscript downloads
This commit is contained in:
parent
8bc39e9b1c
commit
44913c3284
@ -16,7 +16,6 @@ SOURCES += gm_plugin.cpp \
|
||||
settings/gm_settingslistwidget.cpp \
|
||||
# gm_jsobject.cpp \
|
||||
gm_icon.cpp \
|
||||
gm_urlinterceptor.cpp
|
||||
|
||||
HEADERS += gm_plugin.h \
|
||||
gm_manager.h \
|
||||
@ -30,7 +29,6 @@ HEADERS += gm_plugin.h \
|
||||
settings/gm_settingslistwidget.h \
|
||||
# gm_jsobject.h \
|
||||
gm_icon.h \
|
||||
gm_urlinterceptor.h
|
||||
|
||||
FORMS += \
|
||||
gm_addscriptdialog.ui \
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "gm_script.h"
|
||||
#include "gm_downloader.h"
|
||||
#include "gm_icon.h"
|
||||
#include "gm_urlinterceptor.h"
|
||||
#include "gm_addscriptdialog.h"
|
||||
#include "settings/gm_settings.h"
|
||||
|
||||
@ -40,18 +39,10 @@
|
||||
GM_Manager::GM_Manager(const QString &sPath, QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_settingsPath(sPath)
|
||||
, m_interceptor(new GM_UrlInterceptor(this))
|
||||
{
|
||||
mApp->networkManager()->installUrlInterceptor(m_interceptor);
|
||||
|
||||
QTimer::singleShot(0, this, SLOT(load()));
|
||||
}
|
||||
|
||||
GM_Manager::~GM_Manager()
|
||||
{
|
||||
mApp->networkManager()->removeUrlInterceptor(m_interceptor);
|
||||
}
|
||||
|
||||
void GM_Manager::showSettings(QWidget* parent)
|
||||
{
|
||||
if (!m_settings) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* GreaseMonkey plugin for QupZilla
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2013-2017 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -30,14 +30,12 @@ class BrowserWindow;
|
||||
class GM_Script;
|
||||
class GM_Settings;
|
||||
class GM_Icon;
|
||||
class GM_UrlInterceptor;
|
||||
|
||||
class GM_Manager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GM_Manager(const QString &sPath, QObject* parent = 0);
|
||||
~GM_Manager();
|
||||
|
||||
void showSettings(QWidget* parent);
|
||||
void downloadScript(const QUrl &url);
|
||||
@ -80,7 +78,6 @@ private:
|
||||
QString m_bootstrapScript;
|
||||
QString m_valuesScript;
|
||||
QPointer<GM_Settings> m_settings;
|
||||
GM_UrlInterceptor *m_interceptor;
|
||||
|
||||
QStringList m_disabledScripts;
|
||||
//GM_JSObject* m_jsObject;
|
||||
|
@ -86,3 +86,12 @@ void GM_Plugin::showSettings(QWidget* parent)
|
||||
{
|
||||
m_manager->showSettings(parent);
|
||||
}
|
||||
|
||||
bool GM_Plugin::acceptNavigationRequest(WebPage *page, const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
|
||||
{
|
||||
if (type == QWebEnginePage::NavigationTypeLinkClicked && url.toString().endsWith(QLatin1String(".user.js"))) {
|
||||
m_manager->downloadScript(url);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* GreaseMonkey plugin for QupZilla
|
||||
* Copyright (C) 2012-2014 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2012-2017 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -40,6 +40,8 @@ public:
|
||||
QTranslator* getTranslator(const QString &locale);
|
||||
void showSettings(QWidget* parent = 0);
|
||||
|
||||
bool acceptNavigationRequest(WebPage *page, const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) override;
|
||||
|
||||
private:
|
||||
GM_Manager* m_manager;
|
||||
};
|
||||
|
@ -1,40 +0,0 @@
|
||||
/* ============================================================
|
||||
* QupZilla - QtWebEngine based browser
|
||||
* Copyright (C) 2015-2016 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "gm_urlinterceptor.h"
|
||||
#include "gm_manager.h"
|
||||
|
||||
GM_UrlInterceptor::GM_UrlInterceptor(GM_Manager *manager)
|
||||
: UrlInterceptor(manager)
|
||||
, m_manager(manager)
|
||||
{
|
||||
}
|
||||
|
||||
void GM_UrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
|
||||
{
|
||||
bool xhr = info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeXhr;
|
||||
bool clickedLink = info.navigationType() == QWebEngineUrlRequestInfo::NavigationTypeLink;
|
||||
|
||||
if (xhr || !clickedLink)
|
||||
return;
|
||||
|
||||
if (info.requestUrl().toString().endsWith(QLatin1String(".user.js"))) {
|
||||
m_manager->downloadScript(info.requestUrl());
|
||||
info.block(true);
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
/* ============================================================
|
||||
* QupZilla - QtWebEngine based browser
|
||||
* Copyright (C) 2015 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
|
||||
#ifndef GM_URLINTERCEPTOR_H
|
||||
#define GM_URLINTERCEPTOR_H
|
||||
|
||||
#include "urlinterceptor.h"
|
||||
|
||||
class GM_Manager;
|
||||
|
||||
class GM_UrlInterceptor : public UrlInterceptor
|
||||
{
|
||||
public:
|
||||
explicit GM_UrlInterceptor(GM_Manager* manager);
|
||||
|
||||
void interceptRequest(QWebEngineUrlRequestInfo &info);
|
||||
|
||||
private:
|
||||
GM_Manager *m_manager;
|
||||
|
||||
};
|
||||
|
||||
#endif // GM_URLINTERCEPTOR_H
|
Loading…
Reference in New Issue
Block a user