[Qt][WK2] Implement custom URL schemes defined in QML.
[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 <QtDeclarative/qdeclarativelist.h>
27 #include <QtQuick/qquickitem.h>
28
29 class QWebNavigationRequest;
30 class QDeclarativeComponent;
31 class QQuickWebPage;
32 class QQuickWebViewAttached;
33 class QQuickWebViewPrivate;
34 class QQuickWebViewExperimental;
35 class QWebDownloadItem;
36 class QWebNavigationHistory;
37 class QWebPreferences;
38 class QWebPermissionRequest;
39 class QWebViewportInfo;
40 class QQuickNetworkReply;
41
42 namespace WTR {
43 class PlatformWebView;
44 }
45
46 namespace WebKit {
47 class QtNetworkRequestData;
48 }
49
50 namespace WTF {
51 template<class T> class PassRefPtr;
52 }
53
54 typedef const struct OpaqueWKContext* WKContextRef;
55 typedef const struct OpaqueWKPageGroup* WKPageGroupRef;
56 typedef const struct OpaqueWKPage* WKPageRef;
57
58 QT_BEGIN_NAMESPACE
59 class QPainter;
60 class QUrl;
61 QT_END_NAMESPACE
62
63 class QWEBKIT_EXPORT QQuickWebView : public QQuickItem {
64     Q_OBJECT
65     Q_PROPERTY(QString title READ title NOTIFY titleChanged)
66     Q_PROPERTY(QUrl url READ url NOTIFY urlChanged)
67     Q_PROPERTY(QUrl icon READ icon NOTIFY iconChanged FINAL)
68     Q_PROPERTY(int loadProgress READ loadProgress NOTIFY loadProgressChanged)
69     Q_PROPERTY(bool canGoBack READ canGoBack NOTIFY navigationStateChanged FINAL)
70     Q_PROPERTY(bool canGoForward READ canGoForward NOTIFY navigationStateChanged FINAL)
71     Q_PROPERTY(bool loading READ loading NOTIFY navigationStateChanged FINAL)
72     Q_PROPERTY(bool canReload READ canReload NOTIFY navigationStateChanged FINAL)
73     Q_ENUMS(NavigationRequestAction)
74     Q_ENUMS(ErrorDomain)
75
76 public:
77     enum NavigationRequestAction {
78         AcceptRequest,
79         IgnoreRequest
80     };
81
82     enum ErrorDomain {
83         InternalErrorDomain,
84         NetworkErrorDomain,
85         HttpErrorDomain,
86         DownloadErrorDomain
87     };
88     QQuickWebView(QQuickItem* parent = 0);
89     virtual ~QQuickWebView();
90
91     QUrl url() const;
92     QUrl icon() const;
93     QString title() const;
94     int loadProgress() const;
95
96     bool canGoBack() const;
97     bool canGoForward() const;
98     bool loading() const;
99     bool canReload() const;
100
101     virtual QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
102
103     QQuickWebPage* page();
104
105     QQuickWebViewExperimental* experimental() const;
106     static QQuickWebViewAttached* qmlAttachedProperties(QObject*);
107
108     static void platformInitialize(); // Only needed by WTR.
109
110 public Q_SLOTS:
111     void load(const QUrl&);
112     void loadHtml(const QString& html, const QUrl& baseUrl = QUrl());
113
114     void goBack();
115     void goForward();
116     void stop();
117     void reload();
118
119 Q_SIGNALS:
120     void titleChanged(const QString& title);
121     void loadStarted();
122     void loadSucceeded();
123     void loadFailed(QQuickWebView::ErrorDomain errorDomain, int errorCode, const QUrl& url, const QString& description);
124     void loadProgressChanged(int progress);
125     void urlChanged(const QUrl& url);
126     void iconChanged(const QUrl& iconURL);
127     void linkHovered(const QUrl& url, const QString& title);
128     void navigationStateChanged();
129     void navigationRequested(QWebNavigationRequest* request);
130
131 protected:
132     virtual void geometryChanged(const QRectF&, const QRectF&);
133     virtual void focusInEvent(QFocusEvent*);
134     virtual void focusOutEvent(QFocusEvent*);
135
136 private:
137     Q_DECLARE_PRIVATE(QQuickWebView)
138
139     QQuickWebView(WKContextRef, WKPageGroupRef, QQuickItem* parent = 0);
140     WKPageRef pageRef() const;
141
142     Q_PRIVATE_SLOT(d_func(), void _q_suspend());
143     Q_PRIVATE_SLOT(d_func(), void _q_resume());
144     Q_PRIVATE_SLOT(d_func(), void _q_viewportTrajectoryVectorChanged(const QPointF&));
145     Q_PRIVATE_SLOT(d_func(), void _q_onOpenPanelFilesSelected());
146     Q_PRIVATE_SLOT(d_func(), void _q_onOpenPanelFinished(int result));
147     Q_PRIVATE_SLOT(d_func(), void _q_onVisibleChanged());
148     Q_PRIVATE_SLOT(d_func(), void _q_onReceivedResponseFromDownload(QWebDownloadItem*));
149     Q_PRIVATE_SLOT(d_func(), void _q_onIconChangedForPageURL(const QUrl&, const QUrl&));
150     // Hides QObject::d_ptr allowing us to use the convenience macros.
151     QScopedPointer<QQuickWebViewPrivate> d_ptr;
152     QQuickWebViewExperimental* m_experimental;
153
154     friend class QtWebPageLoadClient;
155     friend class QtWebPagePolicyClient;
156     friend class QtWebPageUIClient;
157     friend class WTR::PlatformWebView;
158     friend class QQuickWebViewExperimental;
159 };
160
161 QML_DECLARE_TYPE(QQuickWebView)
162
163 class QWEBKIT_EXPORT QQuickWebViewAttached : public QObject {
164     Q_OBJECT
165     Q_PROPERTY(QQuickWebView* view READ view NOTIFY viewChanged FINAL)
166
167 public:
168     QQuickWebViewAttached(QObject* object);
169     QQuickWebView* view() const { return m_view; }
170     void setView(QQuickWebView*);
171
172 Q_SIGNALS:
173     void viewChanged();
174
175 private:
176     QQuickWebView* m_view;
177 };
178
179 QML_DECLARE_TYPEINFO(QQuickWebView, QML_HAS_ATTACHED_PROPERTIES)
180
181 class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject {
182     Q_OBJECT
183     Q_PROPERTY(QQuickWebPage* page READ page CONSTANT FINAL)
184     Q_PROPERTY(QWebNavigationHistory* navigationHistory READ navigationHistory CONSTANT FINAL)
185     Q_PROPERTY(QDeclarativeComponent* alertDialog READ alertDialog WRITE setAlertDialog NOTIFY alertDialogChanged)
186     Q_PROPERTY(QDeclarativeComponent* confirmDialog READ confirmDialog WRITE setConfirmDialog NOTIFY confirmDialogChanged)
187     Q_PROPERTY(QDeclarativeComponent* promptDialog READ promptDialog WRITE setPromptDialog NOTIFY promptDialogChanged)
188     Q_PROPERTY(QDeclarativeComponent* itemSelector READ itemSelector WRITE setItemSelector NOTIFY itemSelectorChanged)
189     Q_PROPERTY(QWebPreferences* preferences READ preferences CONSTANT FINAL)
190     Q_PROPERTY(bool useTraditionalDesktopBehaviour READ useTraditionalDesktopBehaviour WRITE setUseTraditionalDesktopBehaviour)
191     Q_PROPERTY(QWebViewportInfo* viewportInfo READ viewportInfo CONSTANT FINAL)
192     Q_PROPERTY(QDeclarativeListProperty<QQuickUrlSchemeDelegate> urlSchemeDelegates READ schemeDelegates)
193     Q_ENUMS(NavigationRequestAction)
194
195 public:
196     enum NavigationRequestAction {
197         DownloadRequest = 2
198     };
199
200     QQuickWebViewExperimental(QQuickWebView* webView);
201     virtual ~QQuickWebViewExperimental();
202
203     QDeclarativeComponent* alertDialog() const;
204     void setAlertDialog(QDeclarativeComponent*);
205     QDeclarativeComponent* confirmDialog() const;
206     void setConfirmDialog(QDeclarativeComponent*);
207     QDeclarativeComponent* promptDialog() const;
208     void setPromptDialog(QDeclarativeComponent*);
209     QDeclarativeComponent* itemSelector() const;
210     void setItemSelector(QDeclarativeComponent*);
211     
212     QWebViewportInfo* viewportInfo();
213
214     QWebPreferences* preferences() const;
215     bool useTraditionalDesktopBehaviour() const;
216     QWebNavigationHistory* navigationHistory() const;
217     QQuickWebPage* page();
218
219     static QQuickUrlSchemeDelegate* schemeDelegates_At(QDeclarativeListProperty<QQuickUrlSchemeDelegate>*, int index);
220     static void schemeDelegates_Append(QDeclarativeListProperty<QQuickUrlSchemeDelegate>*, QQuickUrlSchemeDelegate*);
221     static int schemeDelegates_Count(QDeclarativeListProperty<QQuickUrlSchemeDelegate>*);
222     static void schemeDelegates_Clear(QDeclarativeListProperty<QQuickUrlSchemeDelegate>*);
223     QDeclarativeListProperty<QQuickUrlSchemeDelegate> schemeDelegates();
224     void invokeApplicationSchemeHandler(WTF::PassRefPtr<WebKit::QtNetworkRequestData>);
225     void sendApplicationSchemeReply(QQuickNetworkReply*);
226
227 public Q_SLOTS:
228     void setUseTraditionalDesktopBehaviour(bool enable);
229     void goBackTo(int index);
230     void goForwardTo(int index);
231     void postMessage(const QString&);
232
233 Q_SIGNALS:
234     void alertDialogChanged();
235     void confirmDialogChanged();
236     void promptDialogChanged();
237     void itemSelectorChanged();
238     void downloadRequested(QWebDownloadItem* downloadItem);
239     void permissionRequested(QWebPermissionRequest* permission);
240     void messageReceived(const QVariantMap& message);
241
242 private:
243     QQuickWebView* q_ptr;
244     QQuickWebViewPrivate* d_ptr;
245     QObject* schemeParent;
246     QWebViewportInfo* m_viewportInfo;
247
248     friend class QtWebPageUIClient;
249
250     Q_DECLARE_PRIVATE(QQuickWebView)
251     Q_DECLARE_PUBLIC(QQuickWebView)
252 };
253
254 #endif // qquickwebview_p_h