af0797b909b83236cf79611fbebe6a3ae4f4742b
[WebKit-https.git] / Source / WebKit2 / UIProcess / qt / QtPageClient.cpp
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 #include "config.h"
22 #include "QtPageClient.h"
23
24 #include "QtWebPageEventHandler.h"
25 #include "QtWebUndoController.h"
26 #include "WebContextMenuProxyQt.h"
27 #include "WebEditCommandProxy.h"
28 #include "WebPopupMenuProxyQt.h"
29 #include "qquickwebview_p.h"
30 #include "qquickwebview_p_p.h"
31 #include <QGuiApplication>
32 #include <QQuickCanvas>
33 #include <WebCore/Cursor.h>
34 #include <WebCore/DragData.h>
35 #include <WebCore/FloatRect.h>
36 #include <WebCore/NotImplemented.h>
37
38 using namespace WebKit;
39 using namespace WebCore;
40
41 QtPageClient::QtPageClient()
42     : m_webView(0)
43     , m_eventHandler(0)
44     , m_undoController(0)
45 {
46 }
47
48 QtPageClient::~QtPageClient()
49 {
50 }
51
52 void QtPageClient::initialize(QQuickWebView* webView, QtWebPageEventHandler* eventHandler, QtWebUndoController* undoController)
53 {
54     m_webView = webView;
55     m_eventHandler = eventHandler;
56     m_undoController = undoController;
57 }
58
59 PassOwnPtr<DrawingAreaProxy> QtPageClient::createDrawingAreaProxy()
60 {
61     return QQuickWebViewPrivate::get(m_webView)->createDrawingAreaProxy();
62 }
63
64 void QtPageClient::setViewNeedsDisplay(const WebCore::IntRect& rect)
65 {
66     QQuickWebViewPrivate::get(m_webView)->setNeedsDisplay();
67 }
68
69 void QtPageClient::pageDidRequestScroll(const IntPoint& pos)
70 {
71     QQuickWebViewPrivate::get(m_webView)->pageDidRequestScroll(pos);
72 }
73
74 void QtPageClient::processDidCrash()
75 {
76     QQuickWebViewPrivate::get(m_webView)->processDidCrash();
77 }
78
79 void QtPageClient::didRelaunchProcess()
80 {
81     QQuickWebViewPrivate::get(m_webView)->didRelaunchProcess();
82 }
83
84 void QtPageClient::didChangeContentsSize(const IntSize& newSize)
85 {
86     QQuickWebViewPrivate::get(m_webView)->didChangeContentsSize(newSize);
87 }
88
89 void QtPageClient::didChangeViewportProperties(const WebCore::ViewportArguments& args)
90 {
91     QQuickWebViewPrivate::get(m_webView)->didChangeViewportProperties(args);
92 }
93
94 void QtPageClient::startDrag(const WebCore::DragData& dragData, PassRefPtr<ShareableBitmap> dragImage)
95 {
96     m_eventHandler->startDrag(dragData, dragImage);
97 }
98
99 void QtPageClient::handleDownloadRequest(DownloadProxy* download)
100 {
101     QQuickWebViewPrivate::get(m_webView)->handleDownloadRequest(download);
102 }
103
104 void QtPageClient::handleApplicationSchemeRequest(PassRefPtr<QtRefCountedNetworkRequestData> requestData)
105 {
106     if (!m_webView || !m_webView->experimental())
107         return;
108     m_webView->experimental()->invokeApplicationSchemeHandler(requestData);
109 }
110
111 void QtPageClient::handleAuthenticationRequiredRequest(const String& hostname, const String& realm, const String& prefilledUsername, String& username, String& password)
112 {
113     QString qUsername;
114     QString qPassword;
115
116     QQuickWebViewPrivate::get(m_webView)->handleAuthenticationRequiredRequest(hostname, realm, prefilledUsername, qUsername, qPassword);
117
118     username = qUsername;
119     password = qPassword;
120 }
121
122 void QtPageClient::handleCertificateVerificationRequest(const String& hostname, bool& ignoreErrors)
123 {
124     ignoreErrors = QQuickWebViewPrivate::get(m_webView)->handleCertificateVerificationRequest(hostname);
125 }
126
127 void QtPageClient::handleProxyAuthenticationRequiredRequest(const String& hostname, uint16_t port, const String& prefilledUsername, String& username, String& password)
128 {
129     QString qUsername;
130     QString qPassword;
131
132     QQuickWebViewPrivate::get(m_webView)->handleProxyAuthenticationRequiredRequest(hostname, port, prefilledUsername, qUsername, qPassword);
133
134     username = qUsername;
135     password = qPassword;
136 }
137
138 void QtPageClient::setCursor(const WebCore::Cursor& cursor)
139 {
140     // FIXME: This is a temporary fix until we get cursor support in QML items.
141     QGuiApplication::setOverrideCursor(*cursor.platformCursor());
142 }
143
144 void QtPageClient::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves)
145 {
146     notImplemented();
147 }
148
149 void QtPageClient::toolTipChanged(const String&, const String& newTooltip)
150 {
151     // There is not yet any UI defined for the tooltips for mobile so we ignore the change.
152 }
153
154 void QtPageClient::registerEditCommand(PassRefPtr<WebEditCommandProxy> command, WebPageProxy::UndoOrRedo undoOrRedo)
155 {
156     m_undoController->registerEditCommand(command, undoOrRedo);
157 }
158
159 void QtPageClient::clearAllEditCommands()
160 {
161     m_undoController->clearAllEditCommands();
162 }
163
164 bool QtPageClient::canUndoRedo(WebPageProxy::UndoOrRedo undoOrRedo)
165 {
166     return m_undoController->canUndoRedo(undoOrRedo);
167 }
168
169 void QtPageClient::executeUndoRedo(WebPageProxy::UndoOrRedo undoOrRedo)
170 {
171     m_undoController->executeUndoRedo(undoOrRedo);
172 }
173
174 FloatRect QtPageClient::convertToDeviceSpace(const FloatRect& rect)
175 {
176     return rect;
177 }
178
179 FloatRect QtPageClient::convertToUserSpace(const FloatRect& rect)
180 {
181     return rect;
182 }
183
184 IntPoint QtPageClient::screenToWindow(const IntPoint& point)
185 {
186     return point;
187 }
188
189 IntRect QtPageClient::windowToScreen(const IntRect& rect)
190 {
191     return rect;
192 }
193
194 PassRefPtr<WebPopupMenuProxy> QtPageClient::createPopupMenuProxy(WebPageProxy* webPageProxy)
195 {
196     return WebPopupMenuProxyQt::create(webPageProxy, m_webView);
197 }
198
199 PassRefPtr<WebContextMenuProxy> QtPageClient::createContextMenuProxy(WebPageProxy* webPageProxy)
200 {
201     return WebContextMenuProxyQt::create(webPageProxy);
202 }
203
204 void QtPageClient::flashBackingStoreUpdates(const Vector<IntRect>&)
205 {
206     notImplemented();
207 }
208
209 void QtPageClient::didFindZoomableArea(const IntPoint& target, const IntRect& area)
210 {
211     ASSERT(m_eventHandler);
212     m_eventHandler->didFindZoomableArea(target, area);
213 }
214
215 void QtPageClient::didReceiveMessageFromNavigatorQtObject(const String& message)
216 {
217     QQuickWebViewPrivate::get(m_webView)->didReceiveMessageFromNavigatorQtObject(message);
218 }
219
220 void QtPageClient::updateTextInputState()
221 {
222     ASSERT(m_eventHandler);
223     m_eventHandler->updateTextInputState();
224 }
225
226 #if ENABLE(GESTURE_EVENTS)
227 void QtPageClient::doneWithGestureEvent(const WebGestureEvent& event, bool wasEventHandled)
228 {
229     ASSERT(m_eventHandler);
230     m_eventHandler->doneWithGestureEvent(event, wasEventHandled);
231 }
232 #endif
233
234 #if ENABLE(TOUCH_EVENTS)
235 void QtPageClient::doneWithTouchEvent(const NativeWebTouchEvent& event, bool wasEventHandled)
236 {
237     ASSERT(m_eventHandler);
238     m_eventHandler->doneWithTouchEvent(event, wasEventHandled);
239 }
240 #endif
241
242 void QtPageClient::displayView()
243 {
244     // FIXME: Implement.
245 }
246
247 void QtPageClient::scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset)
248 {
249     // FIXME: Implement.
250 }
251
252 WebCore::IntSize QtPageClient::viewSize()
253 {
254     return QQuickWebViewPrivate::get(m_webView)->viewSize();
255 }
256
257 bool QtPageClient::isViewWindowActive()
258 {
259     if (!m_webView || !m_webView->canvas())
260         return false;
261     return m_webView->canvas()->isActive();
262 }
263
264 bool QtPageClient::isViewFocused()
265 {
266     if (!m_webView)
267         return false;
268     return m_webView->hasFocus();
269 }
270
271 bool QtPageClient::isViewVisible()
272 {
273     if (!m_webView)
274         return false;
275     return m_webView->isVisible() && m_webView->page()->isVisible();
276 }
277
278 bool QtPageClient::isViewInWindow()
279 {
280     // FIXME: Implement.
281     return true;
282 }
283
284 void QtPageClient::enterAcceleratedCompositingMode(const LayerTreeContext&)
285 {
286     // FIXME: Implement.
287 }
288
289 void QtPageClient::exitAcceleratedCompositingMode()
290 {
291     // FIXME: Implement.
292 }
293
294 void QtPageClient::updateAcceleratedCompositingMode(const LayerTreeContext&)
295 {
296     // FIXME: Implement.
297 }
298