summaryrefslogtreecommitdiffstats
path: root/src/webengine/doc/src/qtwebengine-overview.qdoc
blob: 18c1f462da9c7f640719584d7e12ff9977fa2b30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \page qtwebengine-overview.html
    \title Qt WebEngine Overview

    The Qt WebEngine module provides a web browser engine that makes it easy to embed content from
    the World Wide Web into your Qt application on platforms that do not have a native web engine.
    The web engine is not intended to function as a \e {Web Runtime}; to display web content in a
    QML application by using APIs native to the platform, use the \l{Qt WebView} module, instead.

    Qt WebEngine provides C++ classes and QML types for rendering HTML, XHTML, and SVG documents,
    styled using Cascading Style Sheets (CSS) and scripted with JavaScript. HTML documents can be
    made fully editable by the user through the use of the \c{contenteditable} attribute on HTML
    elements.

    Qt WebEngine supercedes the \l{http://doc.qt.io/archives/qt-5.3/qtwebkit-index.html}{Qt WebKit}
    module, which is based on the
    WebKit project, but has not been actively synchronized with the upstream WebKit code since
    Qt 5.2 and has been deprecated in Qt 5.5. For tips on how to change a Qt WebKit widgets
    application to use Qt WebEngine widgets, see \l{Porting from Qt WebKit to Qt WebEngine}. For new
    applications, we recommend using Qt Quick and the WebEngineView QML type.

    For more information about the requirements for building Qt WebEngine from source on the
    supported platforms and for other platform-specific information, see
    \l{Qt WebEngine Platform Notes}.

    The \l {Qt WebChannel} module can be used to create a bi-directional communication channel
    between QObject objects on the C++ side and JavaScript on the QML side.

    \section1 Qt WebEngine Architecture

    \image qtwebengine-architecture.png

    The functionality in Qt WebEngine is divided into the following modules:

    \list
        \li \l{Qt WebEngine Widgets} for creating widget-based web applications
        \li \l{Qt WebEngine} for creating Qt Quick based web applications
        \li \l{Qt WebEngine Core} for interacting with Chromium
    \endlist

    Page rendering and JavaScript execution are separated from the GUI process into the Qt WebEngine
    Process. It is a library that must be shipped with the application if the Qt libraries are
    bundled into the application.

    \section2 Qt WebEngine Widgets

    \image qtwebenginewidgets-model.png

    A \e {web engine view} is the main widget component of the Qt WebEngine module. It can be used
    in various applications to load web content. Within a view, a \e {web engine page} holds a main
    frame that is responsible for web content, the \e history of navigated links, and \e actions.
    The view and page are quite similar, as they provide a set of common functions.

    All pages belong to a \e {web engine profile} that contains shared \e settings, \e scripts, and
    \e cookies. Profiles can be used to isolate pages from each other. A typical use case is a
    dedicated profile for a \e {private browsing} mode, where no information is permanently saved.

    \section2 Qt WebEngine

    \image qtwebengine-model.png

    The Qt WebEngine QML implementation contains the same elements as the C++ implementation,
    except that there is no separately accessible web engine page. The supported page functionality
    is integrated into the web engine view.

    \section2 Qt WebEngine Core

    The Qt WebEngine core is based on the \l {Chromium Project}. Chromium provides its own network
    and painting engines and is developed tightly together with its dependent modules, and
    therefore Qt WebEngine provides better and more reliable support for the latest HTML5
    specification than Qt WebKit. However, Qt WebEngine is thus heavier than Qt WebKit and does
    not provide direct access to the network stack and the HTML document through C++ APIs.

    Please note that Qt WebEngine is based on Chromium, but does not contain or use any services
    or add-ons that might be part of the Chrome browser that is built and delivered by Google.
    You can find more detailed information about the differences between Chromium and Chrome in this
    \l{https://chromium.googlesource.com/chromium/src/+/master/docs/chromium_browser_vs_google_chrome.md}{overview}
    that is part of the documentation in the \l {Chromium Project} upstream source tree.

    This version of Qt WebEngine is based on Chromium snapshot version 45.0.2554.101, with
    additional security fixes from the 46, 47 and 48 branches of the \l {Chromium Project}.

    \section2 Qt WebEngine Process

    The Qt WebEngine Process renders web pages and executes JavaScript.

    Chromium is tightly integrated to the \l{Qt Quick Scene Graph}{Qt Quick scene graph}, which is
    based on OpenGL ES 2.0 or OpenGL 2.0 for its rendering. This provides you with one-pass
    compositing of web content and all the Qt Quick UI. The integration to Chromium is transparent
    to developers, who just work with Qt and JavaScript.

    The document object model (DOM) of a page is constructed when the document is ready, typically
    when the page is completely loaded. Therefore, executing scripts as soon as a document is
    created is not suitable for DOM operations, where one has to wait until the DOM is ready.

    In addition, an injected script shares the same \e world as the other scripts executed on the
    page, which might lead to conflicts. To avoid this, the QWebEngineScript class and the
    WebEngineScript QML type provide implementations of the Chromium API for
    \e{Content Script Extensions}. They specify the
    script to run, the injection point, and the world where the script is run. This enables
    accessing the DOM to manipulate it within a world.

    \note Chromium extensions, such as \c @include, \c @match, and \c @exclude, are not supported.

    Because the render process is separated from the GUI process, they should ideally share an
    OpenGL context to enable one process to access the resources uploaded by the other, such as
    images or textures. However, some inter-process communication is needed for safety and
    reliability, because it enables restarting a crashed process.

    \section1 Embedding Web Content into Widget Based Applications

    Use the QWebEngineView class to display web pages in the simplest way. Because it is a widget,
    you can embed QWebEngineView into your forms and use its convenience functions to download and
    display web sites.

    \code
    QWebEngineView *view = new QWebEngineView(parent);
    view->load(QUrl("http://www.qt.io/"));
    view->show();
    \endcode

    An instance of QWebEngineView has one QWebEnginePage. QWebEnginePage can have a
    QWebEngineHistory that provides access to the page's navigation history and several QAction
    objects that apply actions on the web page. In addition, a QWebEnginePage has the ability to
    run JavaScript code in the context of the page's main frame and to enable customization of
    handlers for specific events like showing custom authentication dialogs.

    Each QWebEnginePage belongs to a QWebEngineProfile that can have a QWebEngineSettings
    for specifying page settings, a QWebEngineScriptCollection for running scripts on the page, and
    a QWebEngineCookieStore for accessing the HTTP cookies of Chromium. A QWebEnginePage can also
    directly point to a script collection.

    \section1 Embedding Web Content into Qt Quick Applications

    The WebEngineView QML type allows Qt Quick applications to render regions of dynamic web
    content. A \e{WebEngineView} type may share the screen with other QML types or encompass the
    full screen as specified within the Qt Quick application.

    To make sure that OpenGL context can be shared between the GUI and render processes, the web
    engine must be initialized by using \l QtWebEngine::initialize in the application main source
    file, as illustrated by the following code snippet:

    \quotefromfile webengine/minimal/main.cpp
    \skipto main
    \printuntil }

    An application can load pages into the WebEngineView, using either an URL or HTML string, and
    navigate within session history. By default, links to different pages load within the same
    WebEngineView object, but web sites may request them to be opened as a new tab, window, or
    dialog.

    The following sample QML application loads a web page using the \l{WebEngineView::}{url}
    property:

    \quotefromfile webengine/minimal/main.qml
    \skipto import
    \printuntil /^\}/

    \section1 Managing Certificates

    Qt WebEngine uses its own network stack, and therefore QSslConfiguration is not used to
    open SSL connections. Instead, Qt WebEngine uses the root CA certificates from the operating
    system to validate the peer's certificate.

    The \l{WebEngineCertificateError::error} and \l{QWebEngineCertificateError::Error} enumerations
    provide information about the types of certificate errors that might occur. The errors can be
    handled by using the WebEngineView::certificateError QML method or by reimplementing the
    QWebEnginePage::certificateError function.

    \section1 Proxy Support

    If QNetworkProxy::applicationProxy is set, it will also be used for Qt WebEngine. Otherwise,
    Qt WebEngine automatically picks up the proxy configuration from OS X and Windows. On Linux,
    it acknowledges settings from KDE and Gnome.

    If a proxy requires authentication, QWebEnginePage::proxyAuthenticationRequired is emitted.
    For Qt Quick, a dialog is shown.

    \section1 Using WebEngine Core

    Qt WebEngine Core provides an API shared by Qt WebEngine and Qt WebEngine Widgets for handling
    URL requests issued for the networking stack of Chromium and for accessing its HTTP cookies.

    Implementing the QWebEngineUrlRequestInterceptor interface and installing the interceptor on a
    profile enables intercepting, blocking, and modifying URL requests (QWebEngineUrlRequestInfo)
    before they reach the networking stack of Chromium.

    A QWebEngineUrlSchemeHandler can be registered for a profile to add support for custom URL
    schemes. Requests for the scheme are then issued to QWebEngineUrlSchemeHandler::requestStarted()
    as QWebEngineUrlRequestJob objects.

    The QWebEngineCookieStore class provides functions for accessing HTTP cookies of Chromium.
    The functions can be used to synchronize cookies with QNetworkAccessManager, as well as to set,
    delete, and intercept cookies during navigation.

    \section1 Deploying Qt WebEngine Applications

    Qt WebEngine takes advantage of the multi process model that the Chromium project offers.
    The multi process model requires the QtWebEngineProcess executable to be deployed alongside your application.
    To do this, we recommend the use of Qt's cross-platform deployment tools.

    Alternatively, if you are carrying out manual deployment, you will find the QtWebEngineProcess executable in the
    libexec directory of your Qt installation.
    On Windows, QtWebEngineProcess.exe is located in the bin directory of your Qt application.

    For more information on deploying Qt applications, please see \l {Deploying Qt Applications}.

    \section1 License Information

    Qt WebEngine module is a snapshot of the integration of Chromium into Qt.

    Qt Commercial Edition licensees that wish to distribute applications that
    use the Qt WebEngine module need to be aware of their obligations under the
    GNU Library General Public License (LGPLv2).

    Developers using the Open Source Edition can choose to redistribute
    the module under the GNU LGPLv3 or GPLv2 and up.

    \legalese

    Chromium is licensed under the following license:

    Copyright (c) 2013 The Chromium Authors. All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are
    met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above
      copyright notice, this list of conditions and the following disclaimer
      in the documentation and/or other materials provided with the
      distribution.
    * Neither the name of Google Inc. nor the names of its
    contributors may be used to endorse or promote products derived from
    this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    \endlegalese
*/