46
46
47
47
using QtWebEngineCore::UserScript;
48
48
49
+ /* !
50
+ \qmltype WebEngineScript
51
+ \instantiates QQuickWebEngineScript
52
+ \inqmlmodule QtWebEngine
53
+ \since QtWebEngine 1.1
54
+ \brief Enables the programmatic injection of scripts in the JavaScript engine.
55
+
56
+ The WebEngineScript type enables the programmatic injection of so called \e {user scripts} in
57
+ the JavaScript engine at different points, determined by injectionPoint, during the loading of
58
+ web content.
59
+
60
+ Scripts can be executed either in the main JavaScript \e world, along with the rest of the
61
+ JavaScript coming from the web contents, or in their own isolated world. While the DOM of the
62
+ page can be accessed from any world, JavaScript variables of a function defined in one world are
63
+ not accessible from a different one. The worldId property provides some predefined IDs for this
64
+ purpose.
65
+
66
+ Use \l{WebEngineView::userScripts}{WebEngineView.userScripts} to access a list of scripts
67
+ attached to the web view.
68
+ */
69
+
49
70
QQuickWebEngineScript::QQuickWebEngineScript ()
50
71
: d_ptr(new QQuickWebEngineScriptPrivate)
51
72
{
@@ -79,6 +100,12 @@ QString QQuickWebEngineScript::toString() const
79
100
return ret;
80
101
}
81
102
103
+ /* !
104
+ \qmlproperty QString WebEngineScript::name
105
+
106
+ The name of the script. Can be useful to retrieve a particular script from
107
+ \l{WebEngineView::userScripts}{WebEngineView.userScripts}.
108
+ */
82
109
QString QQuickWebEngineScript::name () const
83
110
{
84
111
Q_D (const QQuickWebEngineScript);
@@ -91,7 +118,7 @@ QString QQuickWebEngineScript::name() const
91
118
This property holds the remote source location of the user script (if any).
92
119
93
120
Unlike \l sourceCode, this property allows referring to user scripts that
94
- are not already loaded in memory, for instance, when stored on disk.
121
+ are not already loaded in memory, for instance, when stored on disk.
95
122
96
123
Setting this property will change the \l sourceCode of the script.
97
124
@@ -122,20 +149,57 @@ ASSERT_ENUMS_MATCH(QQuickWebEngineScript::Deferred, UserScript::AfterLoad)
122
149
ASSERT_ENUMS_MATCH(QQuickWebEngineScript::DocumentReady, UserScript::DocumentLoadFinished)
123
150
ASSERT_ENUMS_MATCH(QQuickWebEngineScript::DocumentCreation, UserScript::DocumentElementCreation)
124
151
152
+ /* !
153
+ \qmlproperty enumeration WebEngineScript::injectionPoint
154
+
155
+ The point in the loading process at which the script will be executed.
156
+ The default value is \c Deferred.
157
+
158
+ \value DocumentCreation
159
+ The script will be executed as soon as the document is created. This is not suitable for
160
+ any DOM operation.
161
+ \value DocumentReady
162
+ The script will run as soon as the DOM is ready. This is equivalent to the
163
+ \c DOMContentLoaded event firing in JavaScript.
164
+ \value Deferred
165
+ The script will run when the page load finishes, or 500 ms after the document is ready,
166
+ whichever comes first.
167
+ */
125
168
QQuickWebEngineScript::InjectionPoint QQuickWebEngineScript::injectionPoint() const
126
169
{
127
170
Q_D (const QQuickWebEngineScript);
128
171
return static_cast <QQuickWebEngineScript::InjectionPoint>(d->coreScript .injectionPoint ());
129
172
}
130
173
131
-
174
+ /* !
175
+ \qmlproperty enumeration WebEngineScript::worldId
176
+
177
+ The world ID defining which isolated world the script is executed in.
178
+
179
+ \value MainWorld
180
+ The world used by the page's web contents. It can be useful in order to expose custom
181
+ functionality to web contents in certain scenarios.
182
+ \value ApplicationWorld
183
+ The default isolated world used for application level functionality implemented in
184
+ JavaScript.
185
+ \value UserWorld
186
+ The first isolated world to be used by scripts set by users if the application is not
187
+ making use of more worlds. As a rule of thumb, if that functionality is exposed to the
188
+ application users, each individual script should probably get its own isolated world.
189
+ */
132
190
QQuickWebEngineScript::ScriptWorldId QQuickWebEngineScript::worldId () const
133
191
{
134
192
Q_D (const QQuickWebEngineScript);
135
193
return static_cast <QQuickWebEngineScript::ScriptWorldId>(d->coreScript .worldId ());
136
194
}
137
195
196
+ /* !
197
+ \qmlproperty int WebEngineScript::runOnSubframes
138
198
199
+ Set this property to \c true if the script is executed on every frame in the page, or \c false
200
+ if it is only ran for the main frame.
201
+ The default value is \c{false}.
202
+ */
139
203
bool QQuickWebEngineScript::runOnSubframes () const
140
204
{
141
205
Q_D (const QQuickWebEngineScript);
0 commit comments