Falkon Develop
Cross-platform Qt-based web browser
externaljsobject.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2014-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 "externaljsobject.h"
19#include "mainapplication.h"
20#include "pluginproxy.h"
21#include "speeddial.h"
22#include "webpage.h"
23#include "autofilljsobject.h"
24#include "restoremanager.h"
25
26#include <QWebChannel>
27
28static QHash<QString, QObject*> s_extraObjects;
29
31 : QObject(page)
32 , m_page(page)
33 , m_autoFill(new AutoFillJsObject(this))
34{
35}
36
38{
39 return m_page;
40}
41
42// static
43void ExternalJsObject::setupWebChannel(QWebChannel *webChannel, WebPage *page)
44{
45 webChannel->registerObject(QSL("qz_object"), new ExternalJsObject(page));
46
47 for (auto it = s_extraObjects.constBegin(); it != s_extraObjects.constEnd(); ++it) {
48 webChannel->registerObject(QSL("qz_") + it.key(), it.value());
49 }
50}
51
52// static
53void ExternalJsObject::registerExtraObject(const QString &id, QObject *object)
54{
55 s_extraObjects[id] = object;
56}
57
58// static
60{
61 s_extraObjects.remove(s_extraObjects.key(object));
62}
63
64QObject *ExternalJsObject::speedDial() const
65{
66 if (m_page->url().toString() != QL1S("falkon:speeddial")
67 && (m_page->requestedUrl().toString() != QL1S("falkon:speeddial") && !m_page->url().toString().isEmpty())) {
68 return nullptr;
69 }
70
71 return mApp->plugins()->speedDial();
72}
73
74QObject *ExternalJsObject::autoFill() const
75{
76 return m_autoFill;
77}
78
79QObject *ExternalJsObject::recovery() const
80{
81 if (!mApp->restoreManager() || m_page->url().toString() != QL1S("falkon:restore"))
82 return nullptr;
83
84 return mApp->restoreManager()->recoveryObject(m_page);
85}
ExternalJsObject(WebPage *page)
static void unregisterExtraObject(QObject *object)
static void setupWebChannel(QWebChannel *webChannel, WebPage *page)
WebPage * page() const
static void registerExtraObject(const QString &id, QObject *object)
#define mApp
#define QL1S(x)
Definition: qzcommon.h:44
#define QSL(x)
Definition: qzcommon.h:40