2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
2017-08-25 17:11:29 +02:00
|
|
|
* Falkon - Qt web browser
|
2018-02-07 11:20:42 +01:00
|
|
|
* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
|
2011-03-03 18:29:20 +01:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "pluginproxy.h"
|
|
|
|
#include "plugininterface.h"
|
|
|
|
#include "mainapplication.h"
|
2012-01-11 21:58:25 +01:00
|
|
|
#include "settings.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QMenu>
|
|
|
|
|
2018-02-07 11:20:42 +01:00
|
|
|
PluginProxy::PluginProxy(QObject *parent)
|
|
|
|
: Plugins(parent)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-04-04 21:12:52 +02:00
|
|
|
connect(this, SIGNAL(pluginUnloaded(PluginInterface*)), this, SLOT(pluginUnloaded(PluginInterface*)));
|
2012-02-22 18:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PluginProxy::registerAppEventHandler(const PluginProxy::EventHandlerType &type, PluginInterface* obj)
|
|
|
|
{
|
|
|
|
switch (type) {
|
2012-03-05 13:16:34 +01:00
|
|
|
case MouseDoubleClickHandler:
|
|
|
|
if (!m_mouseDoubleClickHandlers.contains(obj)) {
|
|
|
|
m_mouseDoubleClickHandlers.append(obj);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-02-22 18:33:44 +01:00
|
|
|
case MousePressHandler:
|
|
|
|
if (!m_mousePressHandlers.contains(obj)) {
|
|
|
|
m_mousePressHandlers.append(obj);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MouseReleaseHandler:
|
|
|
|
if (!m_mouseReleaseHandlers.contains(obj)) {
|
|
|
|
m_mouseReleaseHandlers.append(obj);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MouseMoveHandler:
|
|
|
|
if (!m_mouseMoveHandlers.contains(obj)) {
|
|
|
|
m_mouseMoveHandlers.append(obj);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KeyPressHandler:
|
|
|
|
if (!m_keyPressHandlers.contains(obj)) {
|
|
|
|
m_keyPressHandlers.append(obj);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KeyReleaseHandler:
|
|
|
|
if (!m_keyReleaseHandlers.contains(obj)) {
|
|
|
|
m_keyReleaseHandlers.append(obj);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-03-07 12:19:08 +01:00
|
|
|
case WheelEventHandler:
|
|
|
|
if (!m_wheelEventHandlers.contains(obj)) {
|
|
|
|
m_wheelEventHandlers.append(obj);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-02-22 18:33:44 +01:00
|
|
|
default:
|
|
|
|
qWarning("PluginProxy::registerAppEventHandler registering unknown event handler type");
|
|
|
|
break;
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-04-04 21:12:52 +02:00
|
|
|
void PluginProxy::pluginUnloaded(PluginInterface* plugin)
|
|
|
|
{
|
|
|
|
m_mousePressHandlers.removeOne(plugin);
|
|
|
|
m_mouseReleaseHandlers.removeOne(plugin);
|
|
|
|
m_mouseMoveHandlers.removeOne(plugin);
|
2016-04-04 21:14:40 +02:00
|
|
|
m_wheelEventHandlers.removeOne(plugin);
|
2012-04-04 21:12:52 +02:00
|
|
|
|
|
|
|
m_keyPressHandlers.removeOne(plugin);
|
|
|
|
m_keyReleaseHandlers.removeOne(plugin);
|
|
|
|
}
|
|
|
|
|
2015-09-29 23:15:46 +02:00
|
|
|
void PluginProxy::populateWebViewMenu(QMenu* menu, WebView* view, const WebHitTestResult &r)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-03-14 14:04:20 +01:00
|
|
|
if (!menu || !view) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (PluginInterface* iPlugin, m_loadedPlugins) {
|
2012-02-19 17:50:02 +01:00
|
|
|
iPlugin->populateWebViewMenu(menu, view, r);
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2015-10-13 02:34:47 +02:00
|
|
|
void PluginProxy::populateExtensionsMenu(QMenu *menu)
|
|
|
|
{
|
|
|
|
if (!menu) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (PluginInterface* iPlugin, m_loadedPlugins) {
|
|
|
|
iPlugin->populateExtensionsMenu(menu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-05 13:16:34 +01:00
|
|
|
bool PluginProxy::processMouseDoubleClick(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event)
|
|
|
|
{
|
|
|
|
bool accepted = false;
|
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (PluginInterface* iPlugin, m_mouseDoubleClickHandlers) {
|
2012-03-05 13:16:34 +01:00
|
|
|
if (iPlugin->mouseDoubleClick(type, obj, event)) {
|
|
|
|
accepted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return accepted;
|
|
|
|
}
|
|
|
|
|
2012-02-22 18:33:44 +01:00
|
|
|
bool PluginProxy::processMousePress(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-02-22 18:33:44 +01:00
|
|
|
bool accepted = false;
|
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (PluginInterface* iPlugin, m_mousePressHandlers) {
|
2012-02-22 18:33:44 +01:00
|
|
|
if (iPlugin->mousePress(type, obj, event)) {
|
|
|
|
accepted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return accepted;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-02-22 18:33:44 +01:00
|
|
|
bool PluginProxy::processMouseRelease(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-02-22 18:33:44 +01:00
|
|
|
bool accepted = false;
|
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (PluginInterface* iPlugin, m_mouseReleaseHandlers) {
|
2012-02-22 18:33:44 +01:00
|
|
|
if (iPlugin->mouseRelease(type, obj, event)) {
|
|
|
|
accepted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return accepted;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2012-02-22 18:33:44 +01:00
|
|
|
|
|
|
|
bool PluginProxy::processMouseMove(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event)
|
|
|
|
{
|
|
|
|
bool accepted = false;
|
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (PluginInterface* iPlugin, m_mouseMoveHandlers) {
|
2012-02-22 18:33:44 +01:00
|
|
|
if (iPlugin->mouseMove(type, obj, event)) {
|
|
|
|
accepted = true;
|
|
|
|
}
|
2012-03-07 12:19:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return accepted;
|
|
|
|
}
|
|
|
|
|
2012-03-07 20:01:57 +01:00
|
|
|
bool PluginProxy::processWheelEvent(const Qz::ObjectName &type, QObject* obj, QWheelEvent* event)
|
2012-03-07 12:19:08 +01:00
|
|
|
{
|
|
|
|
bool accepted = false;
|
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (PluginInterface* iPlugin, m_wheelEventHandlers) {
|
2012-03-07 12:19:08 +01:00
|
|
|
if (iPlugin->wheelEvent(type, obj, event)) {
|
|
|
|
accepted = true;
|
|
|
|
}
|
2012-02-22 18:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return accepted;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PluginProxy::processKeyPress(const Qz::ObjectName &type, QObject* obj, QKeyEvent* event)
|
|
|
|
{
|
|
|
|
bool accepted = false;
|
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (PluginInterface* iPlugin, m_keyPressHandlers) {
|
2012-02-22 18:33:44 +01:00
|
|
|
if (iPlugin->keyPress(type, obj, event)) {
|
|
|
|
accepted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return accepted;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PluginProxy::processKeyRelease(const Qz::ObjectName &type, QObject* obj, QKeyEvent* event)
|
|
|
|
{
|
|
|
|
bool accepted = false;
|
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (PluginInterface* iPlugin, m_keyReleaseHandlers) {
|
2012-02-22 18:33:44 +01:00
|
|
|
if (iPlugin->keyRelease(type, obj, event)) {
|
|
|
|
accepted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return accepted;
|
|
|
|
}
|
|
|
|
|
2015-05-24 21:41:09 +02:00
|
|
|
bool PluginProxy::acceptNavigationRequest(WebPage *page, const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
|
2012-07-08 00:15:03 +02:00
|
|
|
{
|
2015-05-24 21:41:09 +02:00
|
|
|
bool accepted = true;
|
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (PluginInterface* iPlugin, m_loadedPlugins) {
|
2015-05-24 21:41:09 +02:00
|
|
|
if (!iPlugin->acceptNavigationRequest(page, url, type, isMainFrame)) {
|
|
|
|
accepted = false;
|
2012-07-08 00:15:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-24 21:41:09 +02:00
|
|
|
return accepted;
|
2012-07-08 00:15:03 +02:00
|
|
|
}
|
|
|
|
|
2012-04-01 10:48:50 +02:00
|
|
|
void PluginProxy::emitWebPageCreated(WebPage* page)
|
2012-03-05 13:16:34 +01:00
|
|
|
{
|
2012-04-01 10:48:50 +02:00
|
|
|
emit webPageCreated(page);
|
2012-03-05 13:16:34 +01:00
|
|
|
}
|
|
|
|
|
2012-04-01 10:48:50 +02:00
|
|
|
void PluginProxy::emitWebPageDeleted(WebPage* page)
|
2012-03-05 13:16:34 +01:00
|
|
|
{
|
2012-04-01 10:48:50 +02:00
|
|
|
emit webPageDeleted(page);
|
2012-03-05 13:16:34 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void PluginProxy::emitMainWindowCreated(BrowserWindow* window)
|
2012-03-05 13:16:34 +01:00
|
|
|
{
|
|
|
|
emit mainWindowCreated(window);
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void PluginProxy::emitMainWindowDeleted(BrowserWindow* window)
|
2012-03-05 13:16:34 +01:00
|
|
|
{
|
|
|
|
emit mainWindowDeleted(window);
|
|
|
|
}
|
|
|
|
|