source: trunk/src/3rdparty/webkit/WebKit/qt/docs/qtwebkit-bridge.qdoc@ 846

Last change on this file since 846 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 20.7 KB
Line 
1/*!
2 \inmodule QtWebKit
3 \page qtwebkit-bridge.html
4 \title The QtWebKit Bridge
5 \contentspage QtWebKit
6 \section1 Overview
7 \section2 The technology
8
9 The QtWebKit bridge is a mechanism that extends WebKit's JavaScript environment to access native
10 objects that are represented as \l{QObject}s. It takes advantage of the \l{QObject} introspection,
11 a part of the \l{Object Model}, which makes it easy to integrate with the dynamic JavaScript environment,
12 for example \l{QObject} properties map directly to JavaScript properties.
13
14 For example, both JavaScript and QObjects have properties: a construct that represent a getter/setter
15 pair under one name.
16
17 \section2 Use Cases
18
19 There are two main use cases for the QtWebKit bridge. Web content in a native application, and Thin Clients.
20
21 \section3 Web Content in a Native Application
22
23 This is a common use case in classic Qt application, and a design pattern used by several modern
24 applications. For example, an application that contains a media-player, playlist manager, and music store.
25 The playlist manager is usually best authored as a classic desktop application,
26 with the native-looking robust \l{QWidget}s helping with producing that application.
27 The media-player control, which usually looks custom, can be written using the \l{Graphics View framework}
28 or with in a declarative way with \l{QtDeclarative}. The music store, which shows dynamic content
29 from the internet and gets modified rapidly, is best authored in HTML and maintained on the server.
30
31 With the QtWebKit bridge, that music store component can interact with native parts of the application,
32 for example, if a file needs to be saved to a specific location.
33
34 \section3 Thin Client
35
36 Another use case is using Qt as a native backend to a full web application,
37 referred to here as a thin client. In this use-case, the entire UI is driven by
38 HTML, JavaScript and CSS, and native Qt-based components are used to allow that application
39 access to native features not usually exposed to the web, or to enable helper components that
40 are best written with C++.
41
42 An example for such a client is a UI for a video-on-demand service on a TV. The entire content and
43 UI can be kept on the server, served dynamically through HTTP and rendered with WebKit, with additional
44 native components for accessing hardware-specific features like extracting the list of images
45 out of the video.
46
47 \section2 Difference from Other Bridge Technologies
48
49 Of course QtWebKit is not the only bridge technology out there. NPAPI, for example,
50 is a long-time standard or web-native bridging. Due to Qt's meta-object system, full applications
51 built partially with web-technologies are much easier to develop. NPAPI, however, is more geared
52 towards cross-browser plugins, due to it being an accepted standard.
53
54 When developing a plugin for a browser, NPAPI is recommended. When developing a full application
55 that utilizes HTML-rendering, the QtWebKit bridge is recommended.
56
57 \section2 Relationship with QtScript
58
59 The QtWebKit bridge is similar to \l{QtScript}, especially to some of the features described in the
60 \l{Making Applications Scriptable} page. However, as of Qt 4.7, full QtScript API is not supported for web applications.
61 That is planned as an enhancement for future versions. You might notice that some of the features
62 described here are an exact copy of the ones described in the \l{Making Applications Scriptable} page. That is because
63 the QtWebKit bridge is a subset of that functionality, and this page tries to capture the full
64 capabilities available through the QtWebKit bridge specifically.
65
66 \section1 Accessing QObjects
67
68 \section2 Creating the link via QWebFrame
69
70 By default, no QObjects are accessible through the web environment, for security reasons.
71 To enable web content access for a native QObject, the application must explicitly grant it access,
72 using the following call:
73
74 \snippet webkitsnippets/qtwebkit_bridge_snippets.cpp 0
75
76 See \l{QWebFrame::addToJavaScriptWindowObject()} for more information.
77
78 \section2 Using Signals and Slots
79
80 The QtWebKit bridge adapts Qt's central \l{Signals and Slots} feature for