Falkon Develop
Cross-platform Qt-based web browser
pluginproxy.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-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* ============================================================ */
18#include "pluginproxy.h"
19#include "plugininterface.h"
20#include "mainapplication.h"
21#include "settings.h"
22
23#include <QMenu>
24
26 : Plugins(parent)
27{
28 connect(this, SIGNAL(pluginUnloaded(PluginInterface*)), this, SLOT(pluginUnloaded(PluginInterface*)));
29}
30
32{
33 switch (type) {
35 if (!m_mouseDoubleClickHandlers.contains(obj)) {
36 m_mouseDoubleClickHandlers.append(obj);
37 }
38 break;
39
41 if (!m_mousePressHandlers.contains(obj)) {
42 m_mousePressHandlers.append(obj);
43 }
44 break;
45
47 if (!m_mouseReleaseHandlers.contains(obj)) {
48 m_mouseReleaseHandlers.append(obj);
49 }
50 break;
51
53 if (!m_mouseMoveHandlers.contains(obj)) {
54 m_mouseMoveHandlers.append(obj);
55 }
56 break;
57
58 case KeyPressHandler:
59 if (!m_keyPressHandlers.contains(obj)) {
60 m_keyPressHandlers.append(obj);
61 }
62 break;
63
65 if (!m_keyReleaseHandlers.contains(obj)) {
66 m_keyReleaseHandlers.append(obj);
67 }
68 break;
69
71 if (!m_wheelEventHandlers.contains(obj)) {
72 m_wheelEventHandlers.append(obj);
73 }
74 break;
75
76 default:
77 qWarning("PluginProxy::registerAppEventHandler registering unknown event handler type");
78 break;
79 }
80}
81
82void PluginProxy::pluginUnloaded(PluginInterface* plugin)
83{
84 m_mousePressHandlers.removeOne(plugin);
85 m_mouseReleaseHandlers.removeOne(plugin);
86 m_mouseMoveHandlers.removeOne(plugin);
87 m_wheelEventHandlers.removeOne(plugin);
88
89 m_keyPressHandlers.removeOne(plugin);
90 m_keyReleaseHandlers.removeOne(plugin);
91}
92
94{
95 if (!menu || !view) {
96 return;
97 }
98
99 for (PluginInterface* iPlugin : std::as_const(m_loadedPlugins)) {
100 iPlugin->populateWebViewMenu(menu, view, r);
101 }
102}
103
105{
106 if (!menu) {
107 return;
108 }
109
110 for (PluginInterface* iPlugin : std::as_const(m_loadedPlugins)) {
111 iPlugin->populateExtensionsMenu(menu);
112 }
113}
114
115bool PluginProxy::processMouseDoubleClick(Qz::ObjectName type, QObject* obj, QMouseEvent* event)
116{
117 bool accepted = false;
118
119 for (PluginInterface* iPlugin : std::as_const(m_mouseDoubleClickHandlers)) {
120 if (iPlugin->mouseDoubleClick(type, obj, event)) {
121 accepted = true;
122 }
123 }
124
125 return accepted;
126}
127
128bool PluginProxy::processMousePress(Qz::ObjectName type, QObject* obj, QMouseEvent* event)
129{
130 bool accepted = false;
131
132 for (PluginInterface* iPlugin : std::as_const(m_mousePressHandlers)) {
133 if (iPlugin->mousePress(type, obj, event)) {
134 accepted = true;
135 }
136 }
137
138 return accepted;
139}
140
141bool PluginProxy::processMouseRelease(Qz::ObjectName type, QObject* obj, QMouseEvent* event)
142{
143 bool accepted = false;
144
145 for (PluginInterface* iPlugin : std::as_const(m_mouseReleaseHandlers)) {
146 if (iPlugin->mouseRelease(type, obj, event)) {
147 accepted = true;
148 }
149 }
150
151 return accepted;
152}
153
154bool PluginProxy::processMouseMove(Qz::ObjectName type, QObject* obj, QMouseEvent* event)
155{
156 bool accepted = false;
157
158 for (PluginInterface* iPlugin : std::as_const(m_mouseMoveHandlers)) {
159 if (iPlugin->mouseMove(type, obj, event)) {
160 accepted = true;
161 }
162 }
163
164 return accepted;
165}
166
167bool PluginProxy::processWheelEvent(Qz::ObjectName type, QObject* obj, QWheelEvent* event)
168{
169 bool accepted = false;
170
171 for (PluginInterface* iPlugin : std::as_const(m_wheelEventHandlers)) {
172 if (iPlugin->wheelEvent(type, obj, event)) {
173 accepted = true;
174 }
175 }
176
177 return accepted;
178}
179
180bool PluginProxy::processKeyPress(Qz::ObjectName type, QObject* obj, QKeyEvent* event)
181{
182 bool accepted = false;
183
184 for (PluginInterface* iPlugin : std::as_const(m_keyPressHandlers)) {
185 if (iPlugin->keyPress(type, obj, event)) {
186 accepted = true;
187 }
188 }
189
190 return accepted;
191}
192
193bool PluginProxy::processKeyRelease(Qz::ObjectName type, QObject* obj, QKeyEvent* event)
194{
195 bool accepted = false;
196
197 for (PluginInterface* iPlugin : std::as_const(m_keyReleaseHandlers)) {
198 if (iPlugin->keyRelease(type, obj, event)) {
199 accepted = true;
200 }
201 }
202
203 return accepted;
204}
205
206bool PluginProxy::acceptNavigationRequest(WebPage *page, const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
207{
208 bool accepted = true;
209
210 for (PluginInterface* iPlugin : std::as_const(m_loadedPlugins)) {
211 if (!iPlugin->acceptNavigationRequest(page, url, type, isMainFrame)) {
212 accepted = false;
213 }
214 }
215
216 return accepted;
217}
218
220{
221 Q_EMIT webPageCreated(page);
222}
223
225{
226 Q_EMIT webPageDeleted(page);
227}
228
230{
231 Q_EMIT mainWindowCreated(window);
232}
233
235{
236 Q_EMIT mainWindowDeleted(window);
237}
void webPageCreated(WebPage *page)
bool processMousePress(Qz::ObjectName type, QObject *obj, QMouseEvent *event)
void emitWebPageCreated(WebPage *page)
bool processKeyRelease(Qz::ObjectName type, QObject *obj, QKeyEvent *event)
bool processWheelEvent(Qz::ObjectName type, QObject *obj, QWheelEvent *event)
void emitMainWindowCreated(BrowserWindow *window)
PluginProxy(QObject *parent=nullptr)
Definition: pluginproxy.cpp:25
void populateExtensionsMenu(QMenu *menu)
@ WheelEventHandler
Definition: pluginproxy.h:35
@ MouseReleaseHandler
Definition: pluginproxy.h:33
@ MouseDoubleClickHandler
Definition: pluginproxy.h:33
@ KeyReleaseHandler
Definition: pluginproxy.h:34
@ MouseMoveHandler
Definition: pluginproxy.h:34
@ MousePressHandler
Definition: pluginproxy.h:33
void emitMainWindowDeleted(BrowserWindow *window)
bool processKeyPress(Qz::ObjectName type, QObject *obj, QKeyEvent *event)
void mainWindowDeleted(BrowserWindow *window)
void mainWindowCreated(BrowserWindow *window)
bool processMouseMove(Qz::ObjectName type, QObject *obj, QMouseEvent *event)
void emitWebPageDeleted(WebPage *page)
bool acceptNavigationRequest(WebPage *page, const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
bool processMouseDoubleClick(Qz::ObjectName type, QObject *obj, QMouseEvent *event)
void populateWebViewMenu(QMenu *menu, WebView *view, const WebHitTestResult &r)
Definition: pluginproxy.cpp:93
bool processMouseRelease(Qz::ObjectName type, QObject *obj, QMouseEvent *event)
void webPageDeleted(WebPage *page)
void registerAppEventHandler(EventHandlerType type, PluginInterface *obj)
Definition: pluginproxy.cpp:31
QList< PluginInterface * > m_loadedPlugins
Definition: plugins.h:106
ObjectName
Definition: qzcommon.h:89