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