Skip to content

Commit 28fddd8

Browse files
author
Leena Miettinen
committed
Doc: add documentation for the WebEngineScript item
Change-Id: Ice1b0a403686b4a280b2709a79fe2ed18ace3ab6 Reviewed-by: Joerg Bornemann <[email protected]>
1 parent f32f4af commit 28fddd8

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

src/webengine/api/qquickwebenginescript.cpp

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,27 @@
4646

4747
using QtWebEngineCore::UserScript;
4848

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+
4970
QQuickWebEngineScript::QQuickWebEngineScript()
5071
: d_ptr(new QQuickWebEngineScriptPrivate)
5172
{
@@ -79,6 +100,12 @@ QString QQuickWebEngineScript::toString() const
79100
return ret;
80101
}
81102

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+
*/
82109
QString QQuickWebEngineScript::name() const
83110
{
84111
Q_D(const QQuickWebEngineScript);
@@ -91,7 +118,7 @@ QString QQuickWebEngineScript::name() const
91118
This property holds the remote source location of the user script (if any).
92119
93120
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.
95122
96123
Setting this property will change the \l sourceCode of the script.
97124
@@ -122,20 +149,57 @@ ASSERT_ENUMS_MATCH(QQuickWebEngineScript::Deferred, UserScript::AfterLoad)
122149
ASSERT_ENUMS_MATCH(QQuickWebEngineScript::DocumentReady, UserScript::DocumentLoadFinished)
123150
ASSERT_ENUMS_MATCH(QQuickWebEngineScript::DocumentCreation, UserScript::DocumentElementCreation)
124151

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+
*/
125168
QQuickWebEngineScript::InjectionPoint QQuickWebEngineScript::injectionPoint() const
126169
{
127170
Q_D(const QQuickWebEngineScript);
128171
return static_cast<QQuickWebEngineScript::InjectionPoint>(d->coreScript.injectionPoint());
129172
}
130173

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+
*/
132190
QQuickWebEngineScript::ScriptWorldId QQuickWebEngineScript::worldId() const
133191
{
134192
Q_D(const QQuickWebEngineScript);
135193
return static_cast<QQuickWebEngineScript::ScriptWorldId>(d->coreScript.worldId());
136194
}
137195

196+
/*!
197+
\qmlproperty int WebEngineScript::runOnSubframes
138198
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+
*/
139203
bool QQuickWebEngineScript::runOnSubframes() const
140204
{
141205
Q_D(const QQuickWebEngineScript);

src/webengine/doc/src/qquickwebengineview_lgpl.qdoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@
257257
\readonly
258258

259259
List of script objects attached to the view.
260+
261+
\sa WebEngineScript
260262
*/
261263

262264
/*!

0 commit comments

Comments
 (0)