Falkon Develop
Cross-platform Qt-based web browser
qmluserscript.h
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2018 Anmol Gautam <tarptaeya@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#pragma once
19
20#include "qzcommon.h"
21
22#include <QObject>
23#include <QBasicTimer>
24#include <QWebEngineScript>
25
29class FALKON_EXPORT QmlUserScript : public QObject
30{
31 Q_OBJECT
35 Q_PROPERTY(bool null READ null CONSTANT)
39 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
43 Q_PROPERTY(bool runsOnSubFrames READ runsOnSubFrames WRITE setRunsOnSubFrames NOTIFY runsOnSubFramesChanged)
47 Q_PROPERTY(int worldId READ worldId WRITE setWorldId NOTIFY worldIdChanged)
51 Q_PROPERTY(QString sourceCode READ sourceCode WRITE setSourceCode NOTIFY sourceCodeChanged)
55 Q_PROPERTY(InjectionPoint injectionPoint READ injectionPoint WRITE setInjectionPoint NOTIFY injectionPointChanged)
56public:
61 DocumentCreation = QWebEngineScript::DocumentCreation,
62 DocumentReady = QWebEngineScript::DocumentReady,
63 Deferred = QWebEngineScript::Deferred
64 };
69 MainWorld = QWebEngineScript::MainWorld,
70 ApplicationWorld = QWebEngineScript::ApplicationWorld,
71 UserWorld = QWebEngineScript::UserWorld
72 };
73 Q_ENUM(InjectionPoint)
74 Q_ENUM(ScriptWorldId)
75
76 explicit QmlUserScript(QObject *parent = nullptr);
77 ~QmlUserScript() override;
78 QWebEngineScript webEngineScript() const;
79 void setWebEngineScript(const QWebEngineScript &script);
80Q_SIGNALS:
84 void nameChanged(const QString &name);
88 void runsOnSubFramesChanged(bool runsOnSubFrames);
92 void worldIdChanged(int worldId);
96 void sourceCodeChanged(const QString &sourceCode);
100 void injectionPointChanged(int injectionPoint);
101private:
102 QWebEngineScript m_webEngineScript;
103 QBasicTimer m_basicTimer;
104 bool m_isNull;
105
106 bool null() const;
107 QString name() const;
108 void setName(const QString &name);
109 bool runsOnSubFrames() const;
110 void setRunsOnSubFrames(bool runsOnSubFrames);
111 int worldId() const;
112 void setWorldId(int worldId);
113 QString sourceCode() const;
114 void setSourceCode(const QString &sourceCode);
115 InjectionPoint injectionPoint() const;
116 void setInjectionPoint(InjectionPoint injectionPoint);
117
118 void timerEvent(QTimerEvent *e) override;
119 void aboutToUpdateUnderlyingScript();
120
121 void setNotNull()
122 {
123 // TODO QT6: This is a really hacky way of keeping track of whether the script has been initialized - and is it even necessary?
124 m_isNull = false;
125 }
126};
The class exposing QWebEngineScript to QML.
Definition: qmluserscript.h:30
void nameChanged(const QString &name)
The signal emitted when the script name is changed.
void sourceCodeChanged(const QString &sourceCode)
The signal emitted when source code of the script is changed.
ScriptWorldId
The enum wrapping QWebEngineScript::ScriptWorldId.
Definition: qmluserscript.h:68
void runsOnSubFramesChanged(bool runsOnSubFrames)
The signal emitted when runsOnSubFrame property of the script is changed.
void injectionPointChanged(int injectionPoint)
The signal emitted when injectionPoint property of the script is changed.
void worldIdChanged(int worldId)
The signal emitted when worldId property of the script is changed.
InjectionPoint
The enum exposing QWebEngineScript::InjectionPoint.
Definition: qmluserscript.h:60
#define FALKON_EXPORT
Definition: qzcommon.h:28