f33c6e6547669950e08422ed4f059dae146756ee
[WebKit-https.git] / Source / WebKit2 / UIProcess / API / qt / qquickwebview_p.h
1 /*
2  * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this program; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  *
19  */
20
21 #ifndef qquickwebview_p_h
22 #define qquickwebview_p_h
23
24 #include "qquickurlschemedelegate_p.h"
25 #include "qwebkitglobal.h"
26 #include <QtQml/qqmllist.h>
27 #include <QtQuick/qquickitem.h>
28 #include <private/qquickflickable_p.h>
29
30 class QWebNavigationRequest;
31 class QQmlComponent;
32 class QQuickWebPage;
33 class QQuickWebViewAttached;
34 class QWebLoadRequest;
35 class QQuickWebViewPrivate;
36 class QQuickWebViewExperimental;
37 class QWebDownloadItem;
38 class QWebNavigationHistory;
39 class QWebPreferences;
40 class QWebPermissionRequest;
41 class QWebKitTest;
42 class QQuickNetworkReply;
43
44 namespace WTR {
45 class PlatformWebView;
46 }
47
48 namespace WebKit {
49 class QtRefCountedNetworkRequestData;
50 class QtViewportInteractionEngine;
51 class QtWebPageLoadClient;
52 class QtWebPagePolicyClient;
53 class QtWebPageUIClient;
54 }
55
56 namespace WTF {
57 template<class T> class PassRefPtr;
58 }
59
60 typedef const struct OpaqueWKContext* WKContextRef;
61 typedef const struct OpaqueWKPageGroup* WKPageGroupRef;
62 typedef const struct OpaqueWKPage* WKPageRef;
63
64 QT_BEGIN_NAMESPACE
65 class QPainter;
66 class QUrl;
67 class QQuickFlickable;
68 class QJSValue;
69 QT_END_NAMESPACE
70
71
72 // Instantiating the WebView in C++ is only possible by creating
73 // a QQmlComponent as the initialization depends on the
74 // componentComplete method being called.
75 class QWEBKIT_EXPORT QQuickWebView : public QQuickFlickable {
76     Q_OBJECT
77     Q_PROPERTY(QString title READ title NOTIFY titleChanged)
78     Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
79     Q_PROPERTY(QUrl icon READ icon NOTIFY iconChanged FINAL)
80     Q_PROPERTY(bool canGoBack READ canGoBack NOTIFY navigationHistoryChanged FINAL)
81     Q_PROPERTY(bool canGoForward READ canGoForward NOTIFY navigationHistoryChanged FINAL)
82     Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged FINAL)
83     Q_PROPERTY(int loadProgress READ loadProgress NOTIFY loadProgressChanged)
84     Q_ENUMS(NavigationRequestAction)
85     Q_ENUMS(LoadStatus)
86     Q_ENUMS(ErrorDomain)
87     Q_ENUMS(NavigationType)
88
89 public:
90     enum NavigationRequestAction {
91         AcceptRequest,
92         // Make room in the valid range of the enum for extra actions exposed in Experimental.
93         IgnoreRequest = 0xFF
94     };
95     enum LoadStatus {
96         LoadStartedStatus,
97         LoadSucceededStatus,
98         LoadFailedStatus
99     };
100     enum ErrorDomain {
101         NoErrorDomain,
102         InternalErrorDomain,
103         NetworkErrorDomain,
104         HttpErrorDomain,
105         DownloadErrorDomain
106     };
107
108     enum NavigationType {
109         LinkClickedNavigation,
110         FormSubmittedNavigation,
111         BackForwardNavigation,
112         ReloadNavigation,
113         FormResubmittedNavigation,
114         OtherNavigation
115     };
116
117     QQuickWebView(QQuickItem* parent = 0);
118     virtual ~QQuickWebView();
119
120     QUrl url() const;
121     void setUrl(const QUrl&);
122     QUrl icon() const;
123     QString title() const;
124     int loadProgress() const;
125
126     bool canGoBack() const;
127     bool canGoForward() const;
128     bool loading() const;
129
130     virtual QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
131
132     QPointF mapToWebContent(const QPointF&) const;
133     QRectF mapRectToWebContent(const QRectF&) const;
134     QPointF mapFromWebContent(const QPointF&) const;
135     QRectF mapRectFromWebContent(const QRectF&) const;
136
137     QQuickWebPage* page();
138
139     QQuickWebViewExperimental* experimental() const;
140     static QQuickWebViewAttached* qmlAttachedProperties(QObject*);
141
142     static void platformInitialize(); // Only needed by WTR.
143
144     // Private C++-only API.
145     qreal zoomFactor() const;
146     void setZoomFactor(qreal);
147     void runJavaScriptInMainFrame(const QString& script, QObject* receiver, const char* method);
148     // Used to automatically accept the HTTPS certificate in WTR. No other use intended.
149     bool allowAnyHTTPSCertificateForLocalHost() const;
150     void setAllowAnyHTTPSCertificateForLocalHost(bool allow);
151
152 public Q_SLOTS:
153     void loadHtml(const QString& html, const QUrl& baseUrl = QUrl(), const QUrl& unreachableUrl = QUrl());
154
155     void goBack();
156     void goForward();
157     void stop();
158     void reload();
159
160 Q_SIGNALS:
161     void titleChanged();
162     void navigationHistoryChanged();
163     void loadingChanged(QWebLoadRequest* loadRequest);
164     void loadProgressChanged();
165     void urlChanged();
166     void iconChanged();
167     void linkHovered(const QUrl& hoveredUrl, const QString& hoveredTitle);
168     void navigationRequested(QWebNavigationRequest* request);
169
170 protected:
171     virtual void geometryChanged(const QRectF&, const QRectF&);
172     virtual void componentComplete();
173     virtual void keyPressEvent(QKeyEvent*);
174     virtual void keyReleaseEvent(QKeyEvent*);
175     virtual void inputMethodEvent(QInputMethodEvent*);
176     virtual void focusInEvent(QFocusEvent*);
177     virtual void focusOutEvent(QFocusEvent*);
178     virtual void touchEvent(QTouchEvent*);
179     virtual void mousePressEvent(QMouseEvent*);
180     virtual void mouseMoveEvent(QMouseEvent*);
181     virtual void mouseReleaseEvent(QMouseEvent *);
182     virtual void mouseDoubleClickEvent(QMouseEvent*);
183     virtual void wheelEvent(QWheelEvent*);
184     virtual void hoverEnterEvent(QHoverEvent*);
185     virtual void hoverMoveEvent(QHoverEvent*);
186     virtual void hoverLeaveEvent(QHoverEvent*);
187     virtual void dragMoveEvent(QDragMoveEvent*);
188     virtual void dragEnterEvent(QDragEnterEvent*);
189     virtual void dragLeaveEvent(QDragLeaveEvent*);
190     virtual void dropEvent(QDropEvent*);
191     virtual bool event(QEvent*);
192
193 private:
194     Q_DECLARE_PRIVATE(QQuickWebView)
195
196     void handleFlickableMousePress(const QPointF& position, qint64 eventTimestampMillis);
197     void handleFlickableMouseMove(const QPointF& position, qint64 eventTimestampMillis);
198     void handleFlickableMouseRelease(const QPointF& position, qint64 eventTimestampMillis);
199
200     QPointF contentPos() const;
201     void setContentPos(const QPointF&);
202
203     QQuickWebView(WKContextRef, WKPageGroupRef, QQuickItem* parent = 0);
204     WKPageRef pageRef() const;
205
206     void emitUrlChangeIfNeeded();
207
208     Q_PRIVATE_SLOT(d_func(), void _q_suspend());
209     Q_PRIVATE_SLOT(d_func(), void _q_resume());
210     Q_PRIVATE_SLOT(d_func(), void _q_onInformVisibleContentChange(const QPointF&));
211
212     Q_PRIVATE_SLOT(d_func(), void _q_onVisibleChanged());
213     Q_PRIVATE_SLOT(d_func(), void _q_onUrlChanged());
214     Q_PRIVATE_SLOT(d_func(), void _q_onReceivedResponseFromDownload(QWebDownloadItem*));
215     Q_PRIVATE_SLOT(d_func(), void _q_onIconChangedForPageURL(const QUrl&, const QUrl&));
216     // Hides QObject::d_ptr allowing us to use the convenience macros.
217     QScopedPointer<QQuickWebViewPrivate> d_ptr;
218     QQuickWebViewExperimental* m_experimental;
219
220     friend class WebKit::QtViewportInteractionEngine;
221     friend class WebKit::QtWebPageLoadClient;
222     friend class WebKit::QtWebPagePolicyClient;
223     friend class WebKit::QtWebPageUIClient;
224     friend class WTR::PlatformWebView;
225     friend class QQuickWebViewExperimental;
226 };
227
228 QML_DECLARE_TYPE(QQuickWebView)
229
230 class QWEBKIT_EXPORT QQuickWebViewAttached : public QObject {
231     Q_OBJECT
232     Q_PROPERTY(QQuickWebView* view READ view NOTIFY viewChanged FINAL)
233
234 public:
235     QQuickWebViewAttached(QObject* object);
236     QQuickWebView* view() const { return m_view; }
237     void setView(QQuickWebView*);
238
239 Q_SIGNALS:
240     void viewChanged();
241
242 private:
243     QQuickWebView* m_view;
244 };
245
246 QML_DECLARE_TYPEINFO(QQuickWebView, QML_HAS_ATTACHED_PROPERTIES)
247
248 class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject {
249     Q_OBJECT
250     Q_PROPERTY(QQuickWebPage* page READ page CONSTANT FINAL)
251
252     Q_PROPERTY(bool transparentBackground WRITE setTransparentBackground READ transparentBackground)
253     Q_PROPERTY(bool useDefaultContentItemSize WRITE setUseDefaultContentItemSize READ useDefaultContentItemSize)
254     Q_PROPERTY(int preferredMinimumContentsWidth WRITE setPreferredMinimumContentsWidth READ preferredMinimumContentsWidth)
255
256     Q_PROPERTY(QWebNavigationHistory* navigationHistory READ navigationHistory CONSTANT FINAL)
257     Q_PROPERTY(QQmlComponent* alertDialog READ alertDialog WRITE setAlertDialog NOTIFY alertDialogChanged)
258     Q_PROPERTY(QQmlComponent* confirmDialog READ confirmDialog WRITE setConfirmDialog NOTIFY confirmDialogChanged)
259     Q_PROPERTY(QQmlComponent* promptDialog READ promptDialog WRITE setPromptDialog NOTIFY promptDialogChanged)
260     Q_PROPERTY(QQmlComponent* authenticationDialog READ authenticationDialog WRITE setAuthenticationDialog NOTIFY authenticationDialogChanged)
261     Q_PROPERTY(QQmlComponent* proxyAuthenticationDialog READ proxyAuthenticationDialog WRITE setProxyAuthenticationDialog NOTIFY proxyAuthenticationDialogChanged)
262     Q_PROPERTY(QQmlComponent* certificateVerificationDialog READ certificateVerificationDialog WRITE setCertificateVerificationDialog NOTIFY certificateVerificationDialogChanged)
263     Q_PROPERTY(QQmlComponent* itemSelector READ itemSelector WRITE setItemSelector NOTIFY itemSelectorChanged)
264     Q_PROPERTY(QQmlComponent* filePicker READ filePicker WRITE setFilePicker NOTIFY filePickerChanged)
265     Q_PROPERTY(QQmlComponent* databaseQuotaDialog READ databaseQuotaDialog WRITE setDatabaseQuotaDialog NOTIFY databaseQuotaDialogChanged)
266     Q_PROPERTY(QWebPreferences* preferences READ preferences CONSTANT FINAL)
267     Q_PROPERTY(QWebKitTest* test READ test CONSTANT FINAL)
268     Q_PROPERTY(QQmlListProperty<QQuickUrlSchemeDelegate> urlSchemeDelegates READ schemeDelegates)
269     Q_PROPERTY(QString userAgent READ userAgent WRITE setUserAgent NOTIFY userAgentChanged)
270     Q_PROPERTY(double devicePixelRatio READ devicePixelRatio WRITE setDevicePixelRatio NOTIFY devicePixelRatioChanged)
271     Q_ENUMS(NavigationRequestActionExperimental)
272
273 public:
274     enum NavigationRequestActionExperimental {
275         DownloadRequest = QQuickWebView::IgnoreRequest - 1
276     };
277
278     QQuickWebViewExperimental(QQuickWebView* webView);
279     virtual ~QQuickWebViewExperimental();
280
281     QQmlComponent* alertDialog() const;
282     void setAlertDialog(QQmlComponent*);
283     QQmlComponent* confirmDialog() const;
284     void setConfirmDialog(QQmlComponent*);
285     QQmlComponent* promptDialog() const;
286     void setPromptDialog(QQmlComponent*);
287     QQmlComponent* authenticationDialog() const;
288     void setAuthenticationDialog(QQmlComponent*);
289     QQmlComponent* certificateVerificationDialog() const;
290     void setCertificateVerificationDialog(QQmlComponent*);
291     QQmlComponent* itemSelector() const;
292     void setItemSelector(QQmlComponent*);
293     QQmlComponent* proxyAuthenticationDialog() const;
294     void setProxyAuthenticationDialog(QQmlComponent*);
295     QQmlComponent* filePicker() const;
296     void setFilePicker(QQmlComponent*);
297     QQmlComponent* databaseQuotaDialog() const;
298     void setDatabaseQuotaDialog(QQmlComponent*);
299     QString userAgent() const;
300     void setUserAgent(const QString& userAgent);
301     double devicePixelRatio() const;
302     void setDevicePixelRatio(double);
303
304     QWebKitTest* test();
305
306     QWebPreferences* preferences() const;
307     QWebNavigationHistory* navigationHistory() const;
308     QQuickWebPage* page();
309
310     static QQuickUrlSchemeDelegate* schemeDelegates_At(QQmlListProperty<QQuickUrlSchemeDelegate>*, int index);
311     static void schemeDelegates_Append(QQmlListProperty<QQuickUrlSchemeDelegate>*, QQuickUrlSchemeDelegate*);
312     static int schemeDelegates_Count(QQmlListProperty<QQuickUrlSchemeDelegate>*);
313     static void schemeDelegates_Clear(QQmlListProperty<QQuickUrlSchemeDelegate>*);
314     QQmlListProperty<QQuickUrlSchemeDelegate> schemeDelegates();
315     void invokeApplicationSchemeHandler(WTF::PassRefPtr<WebKit::QtRefCountedNetworkRequestData>);
316     void sendApplicationSchemeReply(QQuickNetworkReply*);
317
318     bool transparentBackground() const;
319     void setTransparentBackground(bool);
320
321     bool useDefaultContentItemSize() const;
322     void setUseDefaultContentItemSize(bool enable);
323
324     int preferredMinimumContentsWidth() const;
325     void setPreferredMinimumContentsWidth(int);
326
327     // C++ only
328     bool renderToOffscreenBuffer() const;
329     void setRenderToOffscreenBuffer(bool enable);
330     static void setFlickableViewportEnabled(bool enable);
331     static bool flickableViewportEnabled();
332
333 public Q_SLOTS:
334     void goBackTo(int index);
335     void goForwardTo(int index);
336     void postMessage(const QString&);
337     void evaluateJavaScript(const QString& script, const QJSValue& value = QJSValue());
338
339 Q_SIGNALS:
340     void alertDialogChanged();
341     void confirmDialogChanged();
342     void promptDialogChanged();
343     void authenticationDialogChanged();
344     void certificateVerificationDialogChanged();
345     void itemSelectorChanged();
346     void filePickerChanged();
347     void databaseQuotaDialogChanged();
348     void downloadRequested(QWebDownloadItem* downloadItem);
349     void permissionRequested(QWebPermissionRequest* permission);
350     void messageReceived(const QVariantMap& message);
351     void proxyAuthenticationDialogChanged();
352     void userAgentChanged();
353     void devicePixelRatioChanged();
354     void enterFullScreenRequested();
355     void exitFullScreenRequested();
356
357 private:
358     QQuickWebView* q_ptr;
359     QQuickWebViewPrivate* d_ptr;
360     QObject* schemeParent;
361     QWebKitTest* m_test;
362
363     friend class WebKit::QtWebPageUIClient;
364
365     Q_DECLARE_PRIVATE(QQuickWebView)
366     Q_DECLARE_PUBLIC(QQuickWebView)
367 };
368
369 #endif // qquickwebview_p_h