Implement DownloadMonitor to prevent long-running slow downloads from background...
[WebKit-https.git] / Source / WebKit / UIProcess / API / wpe / PageClientImpl.cpp
1 /*
2  * Copyright (C) 2014 Igalia S.L.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "PageClientImpl.h"
28
29 #include "DrawingAreaProxyCoordinatedGraphics.h"
30 #include "NativeWebMouseEvent.h"
31 #include "NativeWebWheelEvent.h"
32 #include "ScrollGestureController.h"
33 #include "WPEView.h"
34 #include "WebContextMenuProxy.h"
35 #include "WebContextMenuProxyWPE.h"
36 #include <WebCore/ActivityState.h>
37 #include <WebCore/DOMPasteAccess.h>
38 #include <WebCore/NotImplemented.h>
39
40 namespace WebKit {
41
42 PageClientImpl::PageClientImpl(WKWPE::View& view)
43     : m_view(view)
44     , m_scrollGestureController(std::make_unique<ScrollGestureController>())
45 {
46 }
47
48 PageClientImpl::~PageClientImpl() = default;
49
50 struct wpe_view_backend* PageClientImpl::viewBackend()
51 {
52     return m_view.backend();
53 }
54
55 IPC::Attachment PageClientImpl::hostFileDescriptor()
56 {
57     return wpe_view_backend_get_renderer_host_fd(m_view.backend());
58 }
59
60 std::unique_ptr<DrawingAreaProxy> PageClientImpl::createDrawingAreaProxy(WebProcessProxy& process)
61 {
62     return std::make_unique<DrawingAreaProxyCoordinatedGraphics>(m_view.page(), process);
63 }
64
65 void PageClientImpl::setViewNeedsDisplay(const WebCore::Region&)
66 {
67 }
68
69 void PageClientImpl::requestScroll(const WebCore::FloatPoint&, const WebCore::IntPoint&, bool)
70 {
71 }
72
73 WebCore::FloatPoint PageClientImpl::viewScrollPosition()
74 {
75     return { };
76 }
77
78 WebCore::IntSize PageClientImpl::viewSize()
79 {
80     return m_view.size();
81 }
82
83 bool PageClientImpl::isViewWindowActive()
84 {
85     return m_view.viewState().contains(WebCore::ActivityState::WindowIsActive);
86 }
87
88 bool PageClientImpl::isViewFocused()
89 {
90     return m_view.viewState().contains(WebCore::ActivityState::IsFocused);
91 }
92
93 bool PageClientImpl::isViewVisible()
94 {
95     return m_view.viewState().contains(WebCore::ActivityState::IsVisible);
96 }
97
98 bool PageClientImpl::isViewInWindow()
99 {
100     return m_view.viewState().contains(WebCore::ActivityState::IsInWindow);
101 }
102
103 void PageClientImpl::processDidExit()
104 {
105 }
106
107 void PageClientImpl::didRelaunchProcess()
108 {
109 }
110
111 void PageClientImpl::pageClosed()
112 {
113 }
114
115 void PageClientImpl::preferencesDidChange()
116 {
117 }
118
119 void PageClientImpl::toolTipChanged(const String&, const String&)
120 {
121 }
122
123 void PageClientImpl::didCommitLoadForMainFrame(const String&, bool)
124 {
125 }
126
127 void PageClientImpl::handleDownloadRequest(DownloadProxy& download)
128 {
129     m_view.handleDownloadRequest(download);
130 }
131
132 void PageClientImpl::didChangeContentSize(const WebCore::IntSize&)
133 {
134 }
135
136 void PageClientImpl::setCursor(const WebCore::Cursor&)
137 {
138 }
139
140 void PageClientImpl::setCursorHiddenUntilMouseMoves(bool)
141 {
142 }
143
144 void PageClientImpl::didChangeViewportProperties(const WebCore::ViewportAttributes&)
145 {
146 }
147
148 void PageClientImpl::registerEditCommand(Ref<WebEditCommandProxy>&&, UndoOrRedo)
149 {
150 }
151
152 void PageClientImpl::clearAllEditCommands()
153 {
154 }
155
156 bool PageClientImpl::canUndoRedo(UndoOrRedo)
157 {
158     return false;
159 }
160
161 void PageClientImpl::executeUndoRedo(UndoOrRedo)
162 {
163 }
164
165 WebCore::FloatRect PageClientImpl::convertToDeviceSpace(const WebCore::FloatRect& rect)
166 {
167     return rect;
168 }
169
170 WebCore::FloatRect PageClientImpl::convertToUserSpace(const WebCore::FloatRect& rect)
171 {
172     return rect;
173 }
174
175 WebCore::IntPoint PageClientImpl::screenToRootView(const WebCore::IntPoint& point)
176 {
177     return point;
178 }
179
180 WebCore::IntRect PageClientImpl::rootViewToScreen(const WebCore::IntRect& rect)
181 {
182     return rect;
183 }
184
185 WebCore::IntPoint PageClientImpl::accessibilityScreenToRootView(const WebCore::IntPoint& point)
186 {
187     return screenToRootView(point);
188 }
189
190 WebCore::IntRect PageClientImpl::rootViewToAccessibilityScreen(const WebCore::IntRect& rect)
191 {
192     return rootViewToScreen(rect);    
193 }
194
195 void PageClientImpl::doneWithKeyEvent(const NativeWebKeyboardEvent&, bool)
196 {
197 }
198
199 #if ENABLE(TOUCH_EVENTS)
200 void PageClientImpl::doneWithTouchEvent(const NativeWebTouchEvent& touchEvent, bool wasEventHandled)
201 {
202     if (wasEventHandled)
203         return;
204
205     const struct wpe_input_touch_event_raw* touchPoint = touchEvent.nativeFallbackTouchPoint();
206     if (touchPoint->type == wpe_input_touch_event_type_null)
207         return;
208
209     auto& page = m_view.page();
210
211     if (m_scrollGestureController->handleEvent(touchPoint)) {
212         struct wpe_input_axis_event* axisEvent = m_scrollGestureController->axisEvent();
213         if (axisEvent->type != wpe_input_axis_event_type_null)
214             page.handleWheelEvent(WebKit::NativeWebWheelEvent(axisEvent, m_view.page().deviceScaleFactor()));
215         return;
216     }
217
218     struct wpe_input_pointer_event pointerEvent {
219         wpe_input_pointer_event_type_null, touchPoint->time,
220         touchPoint->x, touchPoint->y,
221         1, 0, 0
222     };
223
224     switch (touchPoint->type) {
225     case wpe_input_touch_event_type_down:
226         pointerEvent.type = wpe_input_pointer_event_type_button;
227         pointerEvent.state = 1;
228         pointerEvent.modifiers |= wpe_input_pointer_modifier_button1;
229         break;
230     case wpe_input_touch_event_type_motion:
231         pointerEvent.type = wpe_input_pointer_event_type_motion;
232         pointerEvent.state = 1;
233         break;
234     case wpe_input_touch_event_type_up:
235         pointerEvent.type = wpe_input_pointer_event_type_button;
236         pointerEvent.state = 0;
237         pointerEvent.modifiers &= ~wpe_input_pointer_modifier_button1;
238         break;
239     case wpe_input_pointer_event_type_null:
240         ASSERT_NOT_REACHED();
241         return;
242     }
243
244     page.handleMouseEvent(NativeWebMouseEvent(&pointerEvent, page.deviceScaleFactor()));
245 }
246 #endif
247
248 void PageClientImpl::wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent&)
249 {
250 }
251
252 RefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy(WebPageProxy&)
253 {
254     return nullptr;
255 }
256
257 #if ENABLE(CONTEXT_MENUS)
258 Ref<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy&, ContextMenuContextData&& context, const UserData& userData)
259 {
260     return WebContextMenuProxyWPE::create(WTFMove(context), userData);
261 }
262 #endif
263
264 void PageClientImpl::enterAcceleratedCompositingMode(const LayerTreeContext&)
265 {
266 }
267
268 void PageClientImpl::exitAcceleratedCompositingMode()
269 {
270 }
271
272 void PageClientImpl::updateAcceleratedCompositingMode(const LayerTreeContext&)
273 {
274 }
275
276 void PageClientImpl::didFinishLoadingDataForCustomContentProvider(const String&, const IPC::DataReference&)
277 {
278 }
279
280 void PageClientImpl::navigationGestureDidBegin()
281 {
282 }
283
284 void PageClientImpl::navigationGestureWillEnd(bool, WebBackForwardListItem&)
285 {
286 }
287
288 void PageClientImpl::navigationGestureDidEnd(bool, WebBackForwardListItem&)
289 {
290 }
291
292 void PageClientImpl::navigationGestureDidEnd()
293 {
294 }
295
296 void PageClientImpl::willRecordNavigationSnapshot(WebBackForwardListItem&)
297 {
298 }
299
300 void PageClientImpl::didRemoveNavigationGestureSnapshot()
301 {
302 }
303
304 void PageClientImpl::didStartProvisionalLoadForMainFrame()
305 {
306     m_view.willStartLoad();
307 }
308
309 void PageClientImpl::didFirstVisuallyNonEmptyLayoutForMainFrame()
310 {
311 }
312
313 void PageClientImpl::didFinishLoadForMainFrame()
314 {
315 }
316
317 void PageClientImpl::didFailLoadForMainFrame()
318 {
319 }
320
321 void PageClientImpl::didSameDocumentNavigationForMainFrame(SameDocumentNavigationType)
322 {
323 }
324
325 void PageClientImpl::didChangeBackgroundColor()
326 {
327 }
328
329 void PageClientImpl::refView()
330 {
331 }
332
333 void PageClientImpl::derefView()
334 {
335 }
336
337 #if ENABLE(VIDEO)
338 bool PageClientImpl::decidePolicyForInstallMissingMediaPluginsPermissionRequest(InstallMissingMediaPluginsPermissionRequest&)
339 {
340     return false;
341 }
342 #endif
343
344 void PageClientImpl::didRestoreScrollPosition()
345 {
346 }
347
348 WebCore::UserInterfaceLayoutDirection PageClientImpl::userInterfaceLayoutDirection()
349 {
350     return WebCore::UserInterfaceLayoutDirection::LTR;
351 }
352
353 #if ENABLE(FULLSCREEN_API)
354 WebFullScreenManagerProxyClient& PageClientImpl::fullScreenManagerProxyClient()
355 {
356     return *this;
357 }
358
359 void PageClientImpl::closeFullScreenManager()
360 {
361     notImplemented();
362 }
363
364 bool PageClientImpl::isFullScreen()
365 {
366     return m_view.isFullScreen();
367 }
368
369 void PageClientImpl::enterFullScreen()
370 {
371     if (isFullScreen())
372         return;
373
374     WebFullScreenManagerProxy* fullScreenManagerProxy = m_view.page().fullScreenManager();
375     if (fullScreenManagerProxy) {
376         fullScreenManagerProxy->willEnterFullScreen();
377         m_view.setFullScreen(true);
378         fullScreenManagerProxy->didEnterFullScreen();
379     }
380 }
381
382 void PageClientImpl::exitFullScreen()
383 {
384     if (!isFullScreen())
385         return;
386
387     WebFullScreenManagerProxy* fullScreenManagerProxy = m_view.page().fullScreenManager();
388     if (fullScreenManagerProxy) {
389         fullScreenManagerProxy->willExitFullScreen();
390         m_view.setFullScreen(false);
391         fullScreenManagerProxy->didExitFullScreen();
392     }
393 }
394
395 void PageClientImpl::beganEnterFullScreen(const WebCore::IntRect& /* initialFrame */, const WebCore::IntRect& /* finalFrame */)
396 {
397     notImplemented();
398 }
399
400 void PageClientImpl::beganExitFullScreen(const WebCore::IntRect& /* initialFrame */, const WebCore::IntRect& /* finalFrame */)
401 {
402     notImplemented();
403 }
404
405 #endif // ENABLE(FULLSCREEN_API)
406
407 void PageClientImpl::requestDOMPasteAccess(const WebCore::IntRect&, const String&, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completionHandler)
408 {
409     completionHandler(WebCore::DOMPasteAccessResponse::DeniedForGesture);
410 }
411
412 } // namespace WebKit