Remove block selection code
[WebKit-https.git] / Source / WebKit / UIProcess / ios / WebPageProxyIOS.mm
1 /*
2  * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
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 #import "config.h"
27 #import "WebPageProxy.h"
28
29 #if PLATFORM(IOS)
30
31 #import "APIUIClient.h"
32 #import "DataReference.h"
33 #import "EditingRange.h"
34 #import "InteractionInformationAtPosition.h"
35 #import "Logging.h"
36 #import "NativeWebKeyboardEvent.h"
37 #import "PageClient.h"
38 #import "PrintInfo.h"
39 #import "RemoteLayerTreeDrawingAreaProxy.h"
40 #import "RemoteLayerTreeDrawingAreaProxyMessages.h"
41 #import "RemoteLayerTreeTransaction.h"
42 #import "UIKitSPI.h"
43 #import "UserData.h"
44 #import "VideoFullscreenManagerProxy.h"
45 #import "ViewUpdateDispatcherMessages.h"
46 #import "WKBrowsingContextControllerInternal.h"
47 #import "WebPageMessages.h"
48 #import "WebProcessProxy.h"
49 #import <WebCore/FrameView.h>
50 #import <WebCore/NotImplemented.h>
51 #import <WebCore/PlatformScreen.h>
52 #import <WebCore/SharedBuffer.h>
53 #import <WebCore/UserAgent.h>
54 #import <WebCore/ValidationBubble.h>
55 #import <wtf/text/TextStream.h>
56
57 #if USE(QUICK_LOOK)
58 #import "APILoaderClient.h"
59 #import "APINavigationClient.h"
60 #import <wtf/text/WTFString.h>
61 #endif
62
63 using namespace WebCore;
64
65 namespace WebKit {
66
67 void WebPageProxy::platformInitialize()
68 {
69 }
70
71 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
72 {
73     return standardUserAgentWithApplicationName(applicationNameForUserAgent);
74 }
75
76 void WebPageProxy::getIsSpeaking(bool&)
77 {
78     notImplemented();
79 }
80
81 void WebPageProxy::speak(const String&)
82 {
83     notImplemented();
84 }
85
86 void WebPageProxy::stopSpeaking()
87 {
88     notImplemented();
89 }
90
91 void WebPageProxy::searchWithSpotlight(const String&)
92 {
93     notImplemented();
94 }
95
96 void WebPageProxy::searchTheWeb(const String&)
97 {
98     notImplemented();
99 }
100
101 void WebPageProxy::windowAndViewFramesChanged(const FloatRect&, const FloatPoint&)
102 {
103     notImplemented();
104 }
105
106 String WebPageProxy::stringSelectionForPasteboard()
107 {
108     notImplemented();
109     return String();
110 }
111
112 RefPtr<WebCore::SharedBuffer> WebPageProxy::dataSelectionForPasteboard(const String&)
113 {
114     notImplemented();
115     return nullptr;
116 }
117
118 bool WebPageProxy::readSelectionFromPasteboard(const String&)
119 {
120     notImplemented();
121     return false;
122 }
123
124 void WebPageProxy::performDictionaryLookupAtLocation(const WebCore::FloatPoint&)
125 {
126     notImplemented();
127 }
128
129 void WebPageProxy::gestureCallback(const WebCore::IntPoint& point, uint32_t gestureType, uint32_t gestureState, uint32_t flags, CallbackID callbackID)
130 {
131     auto callback = m_callbacks.take<GestureCallback>(callbackID);
132     if (!callback) {
133         ASSERT_NOT_REACHED();
134         return;
135     }
136     
137     callback->performCallbackWithReturnValue(point, gestureType, gestureState, flags);
138 }
139
140 void WebPageProxy::touchesCallback(const WebCore::IntPoint& point, uint32_t touches, uint32_t flags, CallbackID callbackID)
141 {
142     auto callback = m_callbacks.take<TouchesCallback>(callbackID);
143     if (!callback) {
144         ASSERT_NOT_REACHED();
145         return;
146     }
147
148     callback->performCallbackWithReturnValue(point, touches, flags);
149 }
150
151 void WebPageProxy::autocorrectionDataCallback(const Vector<WebCore::FloatRect>& rects, const String& fontName, float fontSize, uint64_t fontTraits, CallbackID callbackID)
152 {
153     auto callback = m_callbacks.take<AutocorrectionDataCallback>(callbackID);
154     if (!callback) {
155         ASSERT_NOT_REACHED();
156         return;
157     }
158
159     callback->performCallbackWithReturnValue(rects, fontName, fontSize, fontTraits);
160 }
161
162 void WebPageProxy::selectionContextCallback(const String& selectedText, const String& beforeText, const String& afterText, CallbackID callbackID)
163 {
164     auto callback = m_callbacks.take<SelectionContextCallback>(callbackID);
165     if (!callback) {
166         ASSERT_NOT_REACHED();
167         return;
168     }
169
170     callback->performCallbackWithReturnValue(selectedText, beforeText, afterText);
171 }
172
173 void WebPageProxy::autocorrectionContextCallback(const String& beforeText, const String& markedText, const String& selectedText, const String& afterText, uint64_t location, uint64_t length, CallbackID callbackID)
174 {
175     auto callback = m_callbacks.take<AutocorrectionContextCallback>(callbackID);
176     if (!callback) {
177         ASSERT_NOT_REACHED();
178         return;
179     }
180
181     callback->performCallbackWithReturnValue(beforeText, markedText, selectedText, afterText, location, length);
182 }
183
184 void WebPageProxy::selectionRectsCallback(const Vector<WebCore::SelectionRect>& selectionRects, CallbackID callbackID)
185 {
186     auto callback = m_callbacks.take<SelectionRectsCallback>(callbackID);
187     if (!callback) {
188         ASSERT_NOT_REACHED();
189         return;
190     }
191     
192     callback->performCallbackWithReturnValue(selectionRects);
193 }
194
195 void WebPageProxy::assistedNodeInformationCallback(const AssistedNodeInformation& info, CallbackID callbackID)
196 {
197     auto callback = m_callbacks.take<AssistedNodeInformationCallback>(callbackID);
198     if (!callback) {
199         ASSERT_NOT_REACHED();
200         return;
201     }
202
203     callback->performCallbackWithReturnValue(info);
204 }
205
206 void WebPageProxy::requestAssistedNodeInformation(Function<void(const AssistedNodeInformation&, CallbackBase::Error)>&& callback)
207 {
208     if (!isValid()) {
209         callback({ }, CallbackBase::Error::OwnerWasInvalidated);
210         return;
211     }
212
213     auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivityToken());
214     m_process->send(Messages::WebPage::RequestAssistedNodeInformation(callbackID), m_pageID);
215 }
216
217 void WebPageProxy::updateVisibleContentRects(const VisibleContentRectUpdateInfo& visibleContentRectUpdate)
218 {
219     if (!isValid())
220         return;
221
222     if (visibleContentRectUpdate == m_lastVisibleContentRectUpdate)
223         return;
224
225     m_lastVisibleContentRectUpdate = visibleContentRectUpdate;
226     m_process->send(Messages::ViewUpdateDispatcher::VisibleContentRectUpdate(m_pageID, visibleContentRectUpdate), 0);
227 }
228
229 void WebPageProxy::resendLastVisibleContentRects()
230 {
231     m_process->send(Messages::ViewUpdateDispatcher::VisibleContentRectUpdate(m_pageID, m_lastVisibleContentRectUpdate), 0);
232 }
233
234 static inline float adjustedUnexposedEdge(float documentEdge, float exposedRectEdge, float factor)
235 {
236     if (exposedRectEdge < documentEdge)
237         return documentEdge - factor * (documentEdge - exposedRectEdge);
238     
239     return exposedRectEdge;
240 }
241
242 static inline float adjustedUnexposedMaxEdge(float documentEdge, float exposedRectEdge, float factor)
243 {
244     if (exposedRectEdge > documentEdge)
245         return documentEdge + factor * (exposedRectEdge - documentEdge);
246     
247     return exposedRectEdge;
248 }
249
250 // FIXME: rename this when visual viewports are the default.
251 WebCore::FloatRect WebPageProxy::computeCustomFixedPositionRect(const FloatRect& unobscuredContentRect, const FloatRect& unobscuredContentRectRespectingInputViewBounds, const FloatRect& currentCustomFixedPositionRect, double displayedContentScale, FrameView::LayoutViewportConstraint constraint, bool visualViewportEnabled) const
252 {
253     FloatRect constrainedUnobscuredRect = unobscuredContentRect;
254     FloatRect documentRect = m_pageClient.documentRect();
255
256     if (!visualViewportEnabled && m_pageClient.isAssistingNode())
257         return documentRect;
258
259     if (constraint == FrameView::LayoutViewportConstraint::ConstrainedToDocumentRect)
260         constrainedUnobscuredRect.intersect(documentRect);
261
262     double minimumScale = m_pageClient.minimumZoomScale();
263     bool isBelowMinimumScale = displayedContentScale < minimumScale;
264     if (isBelowMinimumScale) {
265         const CGFloat slope = 12;
266         CGFloat factor = std::max<CGFloat>(1 - slope * (minimumScale - displayedContentScale), 0);
267             
268         constrainedUnobscuredRect.setX(adjustedUnexposedEdge(documentRect.x(), constrainedUnobscuredRect.x(), factor));
269         constrainedUnobscuredRect.setY(adjustedUnexposedEdge(documentRect.y(), constrainedUnobscuredRect.y(), factor));
270         constrainedUnobscuredRect.setWidth(adjustedUnexposedMaxEdge(documentRect.maxX(), constrainedUnobscuredRect.maxX(), factor) - constrainedUnobscuredRect.x());
271         constrainedUnobscuredRect.setHeight(adjustedUnexposedMaxEdge(documentRect.maxY(), constrainedUnobscuredRect.maxY(), factor) - constrainedUnobscuredRect.y());
272     }
273
274     if (!visualViewportEnabled)
275         return FrameView::rectForViewportConstrainedObjects(enclosingLayoutRect(constrainedUnobscuredRect), LayoutSize(documentRect.size()), displayedContentScale, false, StickToViewportBounds);
276         
277     FloatSize constainedSize = isBelowMinimumScale ? constrainedUnobscuredRect.size() : unobscuredContentRect.size();
278     FloatRect unobscuredContentRectForViewport = isBelowMinimumScale ? constrainedUnobscuredRect : unobscuredContentRectRespectingInputViewBounds;
279
280     FloatRect layoutViewportRect = FrameView::computeUpdatedLayoutViewportRect(LayoutRect(currentCustomFixedPositionRect), LayoutRect(documentRect), LayoutSize(constainedSize), LayoutRect(unobscuredContentRectForViewport), m_baseLayoutViewportSize, m_minStableLayoutViewportOrigin, m_maxStableLayoutViewportOrigin, constraint);
281     
282     if (layoutViewportRect != currentCustomFixedPositionRect)
283         LOG_WITH_STREAM(VisibleRects, stream << "WebPageProxy::computeCustomFixedPositionRect: new layout viewport  " << layoutViewportRect);
284     return layoutViewportRect;
285 }
286
287 void WebPageProxy::overflowScrollViewWillStartPanGesture()
288 {
289     m_pageClient.overflowScrollViewWillStartPanGesture();
290 }
291
292 void WebPageProxy::overflowScrollViewDidScroll()
293 {
294     m_pageClient.overflowScrollViewDidScroll();
295 }
296
297 void WebPageProxy::overflowScrollWillStartScroll()
298 {
299     m_pageClient.overflowScrollWillStartScroll();
300 }
301
302 void WebPageProxy::overflowScrollDidEndScroll()
303 {
304     m_pageClient.overflowScrollDidEndScroll();
305 }
306
307 void WebPageProxy::dynamicViewportSizeUpdate(const FloatSize& minimumLayoutSize, const FloatSize& viewSize, const WebCore::FloatSize& maximumUnobscuredSize, const FloatRect& targetExposedContentRect, const FloatRect& targetUnobscuredRect, const FloatRect& targetUnobscuredRectInScrollViewCoordinates, const WebCore::FloatBoxExtent& unobscuredSafeAreaInsets, double targetScale, int32_t deviceOrientation)
308 {
309     if (!isValid())
310         return;
311
312     hideValidationMessage();
313
314     m_dynamicViewportSizeUpdateWaitingForTarget = true;
315     m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit = true;
316     m_process->send(Messages::WebPage::DynamicViewportSizeUpdate(minimumLayoutSize, viewSize, maximumUnobscuredSize, targetExposedContentRect, targetUnobscuredRect, targetUnobscuredRectInScrollViewCoordinates, unobscuredSafeAreaInsets, targetScale, deviceOrientation, ++m_currentDynamicViewportSizeUpdateID), m_pageID);
317 }
318
319 void WebPageProxy::synchronizeDynamicViewportUpdate()
320 {
321     if (!isValid())
322         return;
323
324     if (m_dynamicViewportSizeUpdateWaitingForTarget) {
325         // We do not want the UIProcess to finish animated resize with the old content size, scale, etc.
326         // If that happens, the UIProcess would start pushing new VisibleContentRectUpdateInfo to the WebProcess with
327         // invalid informations.
328         //
329         // Ideally, the animated resize should just be transactional, and the UIProcess would remain in the "resize" state
330         // until both DynamicViewportUpdateChangedTarget and the associated commitLayerTree are finished.
331         // The tricky part with such implementation is if a second animated resize starts before the end of the previous one.
332         // In that case, the values used for the target state needs to be computed from the output of the previous animated resize.
333         //
334         // The following is a workaround to have the UIProcess in a consistent state.
335         // Instead of handling nested resize, we block the UIProcess until the animated resize finishes.
336         double newScale;
337         FloatPoint newScrollPosition;
338         uint64_t nextValidLayerTreeTransactionID;
339         if (m_process->sendSync(Messages::WebPage::SynchronizeDynamicViewportUpdate(), Messages::WebPage::SynchronizeDynamicViewportUpdate::Reply(newScale, newScrollPosition, nextValidLayerTreeTransactionID), m_pageID, 2_s)) {
340             m_dynamicViewportSizeUpdateWaitingForTarget = false;
341             m_dynamicViewportSizeUpdateLayerTreeTransactionID = nextValidLayerTreeTransactionID;
342             m_pageClient.dynamicViewportUpdateChangedTarget(newScale, newScrollPosition, nextValidLayerTreeTransactionID);
343         }
344
345     }
346
347     // If m_dynamicViewportSizeUpdateWaitingForTarget is false, we are waiting for the next valid frame with the hope it is the one for the new target.
348     // If m_dynamicViewportSizeUpdateWaitingForTarget is still true, this is a desperate attempt to get the valid frame before finishing the animation.
349     if (m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit)
350         m_drawingArea->waitForDidUpdateActivityState();
351
352     m_dynamicViewportSizeUpdateWaitingForTarget = false;
353     m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit = false;
354 }
355
356 void WebPageProxy::setViewportConfigurationMinimumLayoutSize(const WebCore::FloatSize& size, const WebCore::FloatSize& viewSize)
357 {
358     m_viewportConfigurationMinimumLayoutSize = size;
359     m_viewportConfigurationViewSize = viewSize;
360
361     if (isValid())
362         m_process->send(Messages::WebPage::SetViewportConfigurationMinimumLayoutSize(size, viewSize), m_pageID);
363 }
364
365 void WebPageProxy::setForceAlwaysUserScalable(bool userScalable)
366 {
367     if (m_forceAlwaysUserScalable == userScalable)
368         return;
369     m_forceAlwaysUserScalable = userScalable;
370
371     if (isValid())
372         m_process->send(Messages::WebPage::SetForceAlwaysUserScalable(userScalable), m_pageID);
373 }
374
375 void WebPageProxy::setMaximumUnobscuredSize(const WebCore::FloatSize& size)
376 {
377     m_maximumUnobscuredSize = size;
378
379     if (isValid())
380         m_process->send(Messages::WebPage::SetMaximumUnobscuredSize(size), m_pageID);
381 }
382
383 void WebPageProxy::setDeviceOrientation(int32_t deviceOrientation)
384 {
385     if (deviceOrientation != m_deviceOrientation) {
386         m_deviceOrientation = deviceOrientation;
387         if (isValid())
388             m_process->send(Messages::WebPage::SetDeviceOrientation(deviceOrientation), m_pageID);
389     }
390 }
391
392 static bool exceedsRenderTreeSizeSizeThreshold(uint64_t thresholdSize, uint64_t committedSize)
393 {
394     const double thesholdSizeFraction = 0.5; // Empirically-derived.
395     return committedSize > thresholdSize * thesholdSizeFraction;
396 }
397
398 void WebPageProxy::didCommitLayerTree(const WebKit::RemoteLayerTreeTransaction& layerTreeTransaction)
399 {
400     m_pageExtendedBackgroundColor = layerTreeTransaction.pageExtendedBackgroundColor();
401
402     if (!m_hasReceivedLayerTreeTransactionAfterDidCommitLoad) {
403         if (layerTreeTransaction.transactionID() >= m_firstLayerTreeTransactionIdAfterDidCommitLoad) {
404             m_hasReceivedLayerTreeTransactionAfterDidCommitLoad = true;
405             m_lastVisibleContentRectUpdate = VisibleContentRectUpdateInfo();
406         }
407     }
408
409     if (!m_dynamicViewportSizeUpdateWaitingForTarget && m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit) {
410         if (layerTreeTransaction.transactionID() >= m_dynamicViewportSizeUpdateLayerTreeTransactionID)
411             m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit = false;
412     }
413
414     m_pageClient.didCommitLayerTree(layerTreeTransaction);
415
416     // FIXME: Remove this special mechanism and fold it into the transaction's layout milestones.
417     if ((m_observedLayoutMilestones & WebCore::ReachedSessionRestorationRenderTreeSizeThreshold) && !m_hitRenderTreeSizeThreshold
418         && exceedsRenderTreeSizeSizeThreshold(m_sessionRestorationRenderTreeSize, layerTreeTransaction.renderTreeSize())) {
419         m_hitRenderTreeSizeThreshold = true;
420         didReachLayoutMilestone(WebCore::ReachedSessionRestorationRenderTreeSizeThreshold);
421     }
422
423     if (m_deferredNodeAssistanceArguments) {
424         m_pageClient.startAssistingNode(m_deferredNodeAssistanceArguments->m_nodeInformation, m_deferredNodeAssistanceArguments->m_userIsInteracting, m_deferredNodeAssistanceArguments->m_blurPreviousNode,
425             m_deferredNodeAssistanceArguments->m_changingActivityState, m_deferredNodeAssistanceArguments->m_userData.get());
426         m_deferredNodeAssistanceArguments = nullptr;
427     }
428 }
429
430 bool WebPageProxy::updateLayoutViewportParameters(const WebKit::RemoteLayerTreeTransaction& layerTreeTransaction)
431 {
432     if (m_baseLayoutViewportSize == layerTreeTransaction.baseLayoutViewportSize()
433         && m_minStableLayoutViewportOrigin == layerTreeTransaction.minStableLayoutViewportOrigin()
434         && m_maxStableLayoutViewportOrigin == layerTreeTransaction.maxStableLayoutViewportOrigin())
435         return false;
436
437     m_baseLayoutViewportSize = layerTreeTransaction.baseLayoutViewportSize();
438     m_minStableLayoutViewportOrigin = layerTreeTransaction.minStableLayoutViewportOrigin();
439     m_maxStableLayoutViewportOrigin = layerTreeTransaction.maxStableLayoutViewportOrigin();
440
441     LOG_WITH_STREAM(VisibleRects, stream << "WebPageProxy::updateLayoutViewportParameters: baseLayoutViewportSize: " << m_baseLayoutViewportSize << " minStableLayoutViewportOrigin: " << m_minStableLayoutViewportOrigin << " maxStableLayoutViewportOrigin: " << m_maxStableLayoutViewportOrigin);
442
443     return true;
444 }
445
446 void WebPageProxy::layerTreeCommitComplete()
447 {
448     m_pageClient.layerTreeCommitComplete();
449 }
450
451 void WebPageProxy::selectWithGesture(const WebCore::IntPoint point, WebCore::TextGranularity granularity, uint32_t gestureType, uint32_t gestureState, bool isInteractingWithAssistedNode, WTF::Function<void (const WebCore::IntPoint&, uint32_t, uint32_t, uint32_t, CallbackBase::Error)>&& callbackFunction)
452 {
453     if (!isValid()) {
454         callbackFunction(WebCore::IntPoint(), 0, 0, 0, CallbackBase::Error::Unknown);
455         return;
456     }
457
458     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
459     m_process->send(Messages::WebPage::SelectWithGesture(point, (uint32_t)granularity, gestureType, gestureState, isInteractingWithAssistedNode, callbackID), m_pageID);
460 }
461
462 void WebPageProxy::updateSelectionWithTouches(const WebCore::IntPoint point, uint32_t touches, bool baseIsStart, WTF::Function<void (const WebCore::IntPoint&, uint32_t, uint32_t, CallbackBase::Error)>&& callbackFunction)
463 {
464     if (!isValid()) {
465         callbackFunction(WebCore::IntPoint(), 0, 0, CallbackBase::Error::Unknown);
466         return;
467     }
468
469     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
470     m_process->send(Messages::WebPage::UpdateSelectionWithTouches(point, touches, baseIsStart, callbackID), m_pageID);
471 }
472     
473 void WebPageProxy::replaceDictatedText(const String& oldText, const String& newText)
474 {
475     m_process->send(Messages::WebPage::ReplaceDictatedText(oldText, newText), m_pageID);
476 }
477
478 void WebPageProxy::replaceSelectedText(const String& oldText, const String& newText)
479 {
480     m_process->send(Messages::WebPage::ReplaceSelectedText(oldText, newText), m_pageID);
481 }
482
483 void WebPageProxy::requestAutocorrectionData(const String& textForAutocorrection, WTF::Function<void (const Vector<WebCore::FloatRect>&, const String&, double, uint64_t, CallbackBase::Error)>&& callbackFunction)
484 {
485     if (!isValid()) {
486         callbackFunction(Vector<WebCore::FloatRect>(), String(), 0, 0, CallbackBase::Error::Unknown);
487         return;
488     }
489
490     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
491     m_process->send(Messages::WebPage::RequestAutocorrectionData(textForAutocorrection, callbackID), m_pageID);
492 }
493
494 void WebPageProxy::applyAutocorrection(const String& correction, const String& originalText, WTF::Function<void (const String&, CallbackBase::Error)>&& callbackFunction)
495 {
496     if (!isValid()) {
497         callbackFunction(String(), CallbackBase::Error::Unknown);
498         return;
499     }
500
501     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
502     m_process->send(Messages::WebPage::ApplyAutocorrection(correction, originalText, callbackID), m_pageID);
503 }
504
505 bool WebPageProxy::applyAutocorrection(const String& correction, const String& originalText)
506 {
507     bool autocorrectionApplied = false;
508     m_process->sendSync(Messages::WebPage::SyncApplyAutocorrection(correction, originalText), Messages::WebPage::SyncApplyAutocorrection::Reply(autocorrectionApplied), m_pageID);
509     return autocorrectionApplied;
510 }
511
512 void WebPageProxy::selectTextWithGranularityAtPoint(const WebCore::IntPoint point, WebCore::TextGranularity granularity, bool isInteractingWithAssistedNode, WTF::Function<void (CallbackBase::Error)>&& callbackFunction)
513 {
514     if (!isValid()) {
515         callbackFunction(CallbackBase::Error::Unknown);
516         return;
517     }
518     
519     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
520     m_process->send(Messages::WebPage::SelectTextWithGranularityAtPoint(point, static_cast<uint32_t>(granularity), isInteractingWithAssistedNode, callbackID), m_pageID);
521 }
522
523 void WebPageProxy::selectPositionAtBoundaryWithDirection(const WebCore::IntPoint point, WebCore::TextGranularity granularity, WebCore::SelectionDirection direction, bool isInteractingWithAssistedNode, WTF::Function<void (CallbackBase::Error)>&& callbackFunction)
524 {
525     if (!isValid()) {
526         callbackFunction(CallbackBase::Error::Unknown);
527         return;
528     }
529     
530     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
531     m_process->send(Messages::WebPage::SelectPositionAtBoundaryWithDirection(point, static_cast<uint32_t>(granularity), static_cast<uint32_t>(direction), isInteractingWithAssistedNode, callbackID), m_pageID);
532 }
533
534 void WebPageProxy::moveSelectionAtBoundaryWithDirection(WebCore::TextGranularity granularity, WebCore::SelectionDirection direction, WTF::Function<void(CallbackBase::Error)>&& callbackFunction)
535 {
536     if (!isValid()) {
537         callbackFunction(CallbackBase::Error::Unknown);
538         return;
539     }
540     
541     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
542     m_process->send(Messages::WebPage::MoveSelectionAtBoundaryWithDirection(static_cast<uint32_t>(granularity), static_cast<uint32_t>(direction), callbackID), m_pageID);
543 }
544     
545 void WebPageProxy::selectPositionAtPoint(const WebCore::IntPoint point, bool isInteractingWithAssistedNode, WTF::Function<void (CallbackBase::Error)>&& callbackFunction)
546 {
547     if (!isValid()) {
548         callbackFunction(CallbackBase::Error::Unknown);
549         return;
550     }
551     
552     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
553     m_process->send(Messages::WebPage::SelectPositionAtPoint(point, isInteractingWithAssistedNode, callbackID), m_pageID);
554 }
555
556 void WebPageProxy::beginSelectionInDirection(WebCore::SelectionDirection direction, WTF::Function<void (uint64_t, CallbackBase::Error)>&& callbackFunction)
557 {
558     if (!isValid()) {
559         callbackFunction(0, CallbackBase::Error::Unknown);
560         return;
561     }
562     
563     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
564     m_process->send(Messages::WebPage::BeginSelectionInDirection(direction, callbackID), m_pageID);
565 }
566
567 void WebPageProxy::updateSelectionWithExtentPoint(const WebCore::IntPoint point, bool isInteractingWithAssistedNode, WTF::Function<void (uint64_t, CallbackBase::Error)>&& callbackFunction)
568 {
569     if (!isValid()) {
570         callbackFunction(0, CallbackBase::Error::Unknown);
571         return;
572     }
573     
574     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
575     m_process->send(Messages::WebPage::UpdateSelectionWithExtentPoint(point, isInteractingWithAssistedNode, callbackID), m_pageID);
576     
577 }
578
579 void WebPageProxy::updateSelectionWithExtentPointAndBoundary(const WebCore::IntPoint point, WebCore::TextGranularity granularity, bool isInteractingWithAssistedNode, WTF::Function<void(uint64_t, CallbackBase::Error)>&& callbackFunction)
580 {
581     if (!isValid()) {
582         callbackFunction(0, CallbackBase::Error::Unknown);
583         return;
584     }
585     
586     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
587     m_process->send(Messages::WebPage::UpdateSelectionWithExtentPointAndBoundary(point, granularity, isInteractingWithAssistedNode, callbackID), m_pageID);
588     
589 }
590
591 void WebPageProxy::requestDictationContext(WTF::Function<void (const String&, const String&, const String&, CallbackBase::Error)>&& callbackFunction)
592 {
593     if (!isValid()) {
594         callbackFunction(String(), String(), String(), CallbackBase::Error::Unknown);
595         return;
596     }
597
598     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
599     m_process->send(Messages::WebPage::RequestDictationContext(callbackID), m_pageID);
600 }
601
602 void WebPageProxy::requestAutocorrectionContext(WTF::Function<void (const String&, const String&, const String&, const String&, uint64_t, uint64_t, CallbackBase::Error)>&& callbackFunction)
603 {
604     if (!isValid()) {
605         callbackFunction(String(), String(), String(), String(), 0, 0, CallbackBase::Error::Unknown);
606         return;
607     }
608
609     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
610     m_process->send(Messages::WebPage::RequestAutocorrectionContext(callbackID), m_pageID);
611 }
612
613 void WebPageProxy::getAutocorrectionContext(String& beforeContext, String& markedText, String& selectedText, String& afterContext, uint64_t& location, uint64_t& length)
614 {
615     m_process->sendSync(Messages::WebPage::GetAutocorrectionContext(), Messages::WebPage::GetAutocorrectionContext::Reply(beforeContext, markedText, selectedText, afterContext, location, length), m_pageID);
616 }
617
618 void WebPageProxy::getSelectionContext(WTF::Function<void(const String&, const String&, const String&, CallbackBase::Error)>&& callbackFunction)
619 {
620     if (!isValid()) {
621         callbackFunction(String(), String(), String(), CallbackBase::Error::Unknown);
622         return;
623     }
624     
625     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
626     m_process->send(Messages::WebPage::GetSelectionContext(callbackID), m_pageID);
627 }
628
629 void WebPageProxy::handleTwoFingerTapAtPoint(const WebCore::IntPoint& point, uint64_t requestID)
630 {
631     process().send(Messages::WebPage::HandleTwoFingerTapAtPoint(point, requestID), m_pageID);
632 }
633
634 void WebPageProxy::selectWithTwoTouches(const WebCore::IntPoint from, const WebCore::IntPoint to, uint32_t gestureType, uint32_t gestureState, WTF::Function<void (const WebCore::IntPoint&, uint32_t, uint32_t, uint32_t, CallbackBase::Error)>&& callbackFunction)
635 {
636     if (!isValid()) {
637         callbackFunction(WebCore::IntPoint(), 0, 0, 0, CallbackBase::Error::Unknown);
638         return;
639     }
640
641     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
642     m_process->send(Messages::WebPage::SelectWithTwoTouches(from, to, gestureType, gestureState, callbackID), m_pageID);
643 }
644
645 void WebPageProxy::didReceivePositionInformation(const InteractionInformationAtPosition& info)
646 {
647     m_pageClient.positionInformationDidChange(info);
648 }
649
650 void WebPageProxy::requestPositionInformation(const InteractionInformationRequest& request)
651 {
652     m_process->send(Messages::WebPage::RequestPositionInformation(request), m_pageID);
653 }
654
655 void WebPageProxy::startInteractionWithElementAtPosition(const WebCore::IntPoint& point)
656 {
657     m_process->send(Messages::WebPage::StartInteractionWithElementAtPosition(point), m_pageID);
658 }
659
660 void WebPageProxy::stopInteraction()
661 {
662     m_process->send(Messages::WebPage::StopInteraction(), m_pageID);
663 }
664
665 void WebPageProxy::performActionOnElement(uint32_t action)
666 {
667     m_process->send(Messages::WebPage::PerformActionOnElement(action), m_pageID);
668 }
669
670 void WebPageProxy::saveImageToLibrary(const SharedMemory::Handle& imageHandle, uint64_t imageSize)
671 {
672     auto sharedMemoryBuffer = SharedMemory::map(imageHandle, SharedMemory::Protection::ReadOnly);
673     auto buffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryBuffer->data()), imageSize);
674     m_pageClient.saveImageToLibrary(WTFMove(buffer));
675 }
676
677 void WebPageProxy::applicationDidEnterBackground()
678 {
679     bool isSuspendedUnderLock = [UIApp isSuspendedUnderLock];
680     m_process->send(Messages::WebPage::ApplicationDidEnterBackground(isSuspendedUnderLock), m_pageID);
681 }
682
683 void WebPageProxy::applicationDidFinishSnapshottingAfterEnteringBackground()
684 {
685     if (m_drawingArea)
686         m_drawingArea->prepareForAppSuspension();
687     m_process->send(Messages::WebPage::ApplicationDidFinishSnapshottingAfterEnteringBackground(), m_pageID);
688 }
689
690 void WebPageProxy::applicationWillEnterForeground()
691 {
692     bool isSuspendedUnderLock = [UIApp isSuspendedUnderLock];
693     m_process->send(Messages::WebPage::ApplicationWillEnterForeground(isSuspendedUnderLock), m_pageID);
694 }
695
696 void WebPageProxy::applicationWillResignActive()
697 {
698     m_process->send(Messages::WebPage::ApplicationWillResignActive(), m_pageID);
699 }
700
701 void WebPageProxy::applicationDidBecomeActive()
702 {
703 #if HAVE(AVKIT)
704     if (m_videoFullscreenManager)
705         m_videoFullscreenManager->applicationDidBecomeActive();
706 #endif
707     m_process->send(Messages::WebPage::ApplicationDidBecomeActive(), m_pageID);
708 }
709
710 void WebPageProxy::extendSelection(WebCore::TextGranularity granularity)
711 {
712     m_process->send(Messages::WebPage::ExtendSelection(static_cast<uint32_t>(granularity)), m_pageID);
713 }
714
715 void WebPageProxy::selectWordBackward()
716 {
717     m_process->send(Messages::WebPage::SelectWordBackward(), m_pageID);
718 }
719
720 void WebPageProxy::requestRectsForGranularityWithSelectionOffset(WebCore::TextGranularity granularity, uint32_t offset, WTF::Function<void(const Vector<WebCore::SelectionRect>&, CallbackBase::Error)>&& callbackFunction)
721 {
722     if (!isValid()) {
723         callbackFunction(Vector<WebCore::SelectionRect>(), CallbackBase::Error::Unknown);
724         return;
725     }
726     
727     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
728     m_process->send(Messages::WebPage::GetRectsForGranularityWithSelectionOffset(static_cast<uint32_t>(granularity), offset, callbackID), m_pageID);
729 }
730
731 void WebPageProxy::requestRectsAtSelectionOffsetWithText(int32_t offset, const String& text, WTF::Function<void(const Vector<WebCore::SelectionRect>&, CallbackBase::Error)>&& callbackFunction)
732 {
733     if (!isValid()) {
734         callbackFunction(Vector<WebCore::SelectionRect>(), CallbackBase::Error::Unknown);
735         return;
736     }
737     
738     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
739     m_process->send(Messages::WebPage::GetRectsAtSelectionOffsetWithText(offset, text, callbackID), m_pageID);
740 }
741
742 void WebPageProxy::storeSelectionForAccessibility(bool shouldStore)
743 {
744     m_process->send(Messages::WebPage::StoreSelectionForAccessibility(shouldStore), m_pageID);
745 }
746
747 void WebPageProxy::startAutoscrollAtPosition(const WebCore::FloatPoint& positionInWindow)
748 {
749     m_process->send(Messages::WebPage::StartAutoscrollAtPosition(positionInWindow), m_pageID);
750 }
751     
752 void WebPageProxy::cancelAutoscroll()
753 {
754     m_process->send(Messages::WebPage::CancelAutoscroll(), m_pageID);
755 }
756
757 void WebPageProxy::moveSelectionByOffset(int32_t offset, WTF::Function<void (CallbackBase::Error)>&& callbackFunction)
758 {
759     if (!isValid()) {
760         callbackFunction(CallbackBase::Error::Unknown);
761         return;
762     }
763     
764     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
765     m_process->send(Messages::WebPage::MoveSelectionByOffset(offset, callbackID), m_pageID);
766 }
767
768 void WebPageProxy::interpretKeyEvent(const EditorState& state, bool isCharEvent, bool& handled)
769 {
770     m_editorState = state;
771     handled = m_pageClient.interpretKeyEvent(m_keyEventQueue.first(), isCharEvent);
772 }
773
774 // Complex text input support for plug-ins.
775 void WebPageProxy::sendComplexTextInputToPlugin(uint64_t, const String&)
776 {
777     notImplemented();
778 }
779
780 void WebPageProxy::setSmartInsertDeleteEnabled(bool)
781 {
782     notImplemented();
783 }
784
785 void WebPageProxy::registerWebProcessAccessibilityToken(const IPC::DataReference& data)
786 {
787     m_pageClient.accessibilityWebProcessTokenReceived(data);
788 }    
789
790 void WebPageProxy::assistiveTechnologyMakeFirstResponder()
791 {
792     notImplemented();
793 }
794     
795 void WebPageProxy::makeFirstResponder()
796 {
797     notImplemented();
798 }
799
800 void WebPageProxy::registerUIProcessAccessibilityTokens(const IPC::DataReference& elementToken, const IPC::DataReference& windowToken)
801 {
802     if (!isValid())
803         return;
804     
805     process().send(Messages::WebPage::RegisterUIProcessAccessibilityTokens(elementToken, windowToken), m_pageID);
806 }
807
808 void WebPageProxy::pluginFocusOrWindowFocusChanged(uint64_t, bool)
809 {
810     notImplemented();
811 }
812
813 void WebPageProxy::setPluginComplexTextInputState(uint64_t, uint64_t)
814 {
815     notImplemented();
816 }
817
818 void WebPageProxy::executeSavedCommandBySelector(const String&, bool&)
819 {
820     notImplemented();
821 }
822
823 bool WebPageProxy::shouldDelayWindowOrderingForEvent(const WebKit::WebMouseEvent&)
824 {
825     notImplemented();
826     return false;
827 }
828
829 bool WebPageProxy::acceptsFirstMouse(int, const WebKit::WebMouseEvent&)
830 {
831     notImplemented();
832     return false;
833 }
834
835 void WebPageProxy::willStartUserTriggeredZooming()
836 {
837     process().send(Messages::WebPage::WillStartUserTriggeredZooming(), m_pageID);
838 }
839
840 void WebPageProxy::potentialTapAtPosition(const WebCore::FloatPoint& position, uint64_t& requestID)
841 {
842     hideValidationMessage();
843     process().send(Messages::WebPage::PotentialTapAtPosition(requestID, position), m_pageID);
844 }
845
846 void WebPageProxy::commitPotentialTap(uint64_t layerTreeTransactionIdAtLastTouchStart)
847 {
848     process().send(Messages::WebPage::CommitPotentialTap(layerTreeTransactionIdAtLastTouchStart), m_pageID);
849 }
850
851 void WebPageProxy::cancelPotentialTap()
852 {
853     process().send(Messages::WebPage::CancelPotentialTap(), m_pageID);
854 }
855
856 void WebPageProxy::tapHighlightAtPosition(const WebCore::FloatPoint& position, uint64_t& requestID)
857 {
858     process().send(Messages::WebPage::TapHighlightAtPosition(requestID, position), m_pageID);
859 }
860
861 void WebPageProxy::handleTap(const FloatPoint& location, uint64_t layerTreeTransactionIdAtLastTouchStart)
862 {
863     process().send(Messages::WebPage::HandleTap(roundedIntPoint(location), layerTreeTransactionIdAtLastTouchStart), m_pageID);
864 }
865
866 void WebPageProxy::inspectorNodeSearchMovedToPosition(const WebCore::FloatPoint& position)
867 {
868     process().send(Messages::WebPage::InspectorNodeSearchMovedToPosition(position), m_pageID);
869 }
870
871 void WebPageProxy::inspectorNodeSearchEndedAtPosition(const WebCore::FloatPoint& position)
872 {
873     process().send(Messages::WebPage::InspectorNodeSearchEndedAtPosition(position), m_pageID);
874 }
875
876 void WebPageProxy::blurAssistedNode()
877 {
878     process().send(Messages::WebPage::BlurAssistedNode(), m_pageID);
879 }
880
881 FloatSize WebPageProxy::screenSize()
882 {
883     return WebCore::screenSize();
884 }
885
886 FloatSize WebPageProxy::availableScreenSize()
887 {
888     return WebCore::availableScreenSize();
889 }
890
891 FloatSize WebPageProxy::overrideScreenSize()
892 {
893     return WebCore::overrideScreenSize();
894 }
895
896 float WebPageProxy::textAutosizingWidth()
897 {
898     return WebCore::screenSize().width();
899 }
900
901 void WebPageProxy::dynamicViewportUpdateChangedTarget(double newScale, const WebCore::FloatPoint& newScrollPosition, uint64_t dynamicViewportSizeUpdateID)
902 {
903     if (dynamicViewportSizeUpdateID != m_currentDynamicViewportSizeUpdateID)
904         return;
905
906     if (m_dynamicViewportSizeUpdateWaitingForTarget) {
907         m_dynamicViewportSizeUpdateLayerTreeTransactionID = downcast<RemoteLayerTreeDrawingAreaProxy>(*drawingArea()).nextLayerTreeTransactionID();
908         m_dynamicViewportSizeUpdateWaitingForTarget = false;
909         m_pageClient.dynamicViewportUpdateChangedTarget(newScale, newScrollPosition, m_dynamicViewportSizeUpdateLayerTreeTransactionID);
910     }
911 }
912
913 void WebPageProxy::couldNotRestorePageState()
914 {
915     m_pageClient.couldNotRestorePageState();
916 }
917
918 void WebPageProxy::restorePageState(std::optional<WebCore::FloatPoint> scrollPosition, const WebCore::FloatPoint& scrollOrigin, const WebCore::FloatBoxExtent& obscuredInsetsOnSave, double scale)
919 {
920     m_pageClient.restorePageState(scrollPosition, scrollOrigin, obscuredInsetsOnSave, scale);
921 }
922
923 void WebPageProxy::restorePageCenterAndScale(std::optional<WebCore::FloatPoint> center, double scale)
924 {
925     m_pageClient.restorePageCenterAndScale(center, scale);
926 }
927
928 void WebPageProxy::didGetTapHighlightGeometries(uint64_t requestID, const WebCore::Color& color, const Vector<WebCore::FloatQuad>& highlightedQuads, const WebCore::IntSize& topLeftRadius, const WebCore::IntSize& topRightRadius, const WebCore::IntSize& bottomLeftRadius, const WebCore::IntSize& bottomRightRadius)
929 {
930     m_pageClient.didGetTapHighlightGeometries(requestID, color, highlightedQuads, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);
931 }
932
933 void WebPageProxy::startAssistingNode(const AssistedNodeInformation& information, bool userIsInteracting, bool blurPreviousNode, bool changingActivityState, const UserData& userData)
934 {
935     API::Object* userDataObject = process().transformHandlesToObjects(userData.object()).get();
936     if (m_editorState.isMissingPostLayoutData) {
937         m_deferredNodeAssistanceArguments = std::make_unique<NodeAssistanceArguments>(NodeAssistanceArguments { information, userIsInteracting, blurPreviousNode, changingActivityState, userDataObject });
938         return;
939     }
940
941     m_pageClient.startAssistingNode(information, userIsInteracting, blurPreviousNode, changingActivityState, userDataObject);
942 }
943
944 void WebPageProxy::stopAssistingNode()
945 {
946     m_deferredNodeAssistanceArguments = nullptr;
947     m_pageClient.stopAssistingNode();
948 }
949
950 void WebPageProxy::autofillLoginCredentials(const String& username, const String& password)
951 {
952     m_process->send(Messages::WebPage::AutofillLoginCredentials(username, password), m_pageID);
953 }
954
955 void WebPageProxy::showInspectorHighlight(const WebCore::Highlight& highlight)
956 {
957     m_pageClient.showInspectorHighlight(highlight);
958 }
959
960 void WebPageProxy::hideInspectorHighlight()
961 {
962     m_pageClient.hideInspectorHighlight();
963 }
964
965 void WebPageProxy::showInspectorIndication()
966 {
967     m_pageClient.showInspectorIndication();
968 }
969
970 void WebPageProxy::hideInspectorIndication()
971 {
972     m_pageClient.hideInspectorIndication();
973 }
974
975 void WebPageProxy::enableInspectorNodeSearch()
976 {
977     m_pageClient.enableInspectorNodeSearch();
978 }
979
980 void WebPageProxy::disableInspectorNodeSearch()
981 {
982     m_pageClient.disableInspectorNodeSearch();
983 }
984
985 void WebPageProxy::focusNextAssistedNode(bool isForward, WTF::Function<void (CallbackBase::Error)>&& callbackFunction)
986 {
987     if (!isValid()) {
988         callbackFunction(CallbackBase::Error::Unknown);
989         return;
990     }
991     
992     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
993     process().send(Messages::WebPage::FocusNextAssistedNode(isForward, callbackID), m_pageID);
994 }
995
996 void WebPageProxy::setAssistedNodeValue(const String& value)
997 {
998     process().send(Messages::WebPage::SetAssistedNodeValue(value), m_pageID);
999 }
1000
1001 void WebPageProxy::setAssistedNodeValueAsNumber(double value)
1002 {
1003     process().send(Messages::WebPage::SetAssistedNodeValueAsNumber(value), m_pageID);
1004 }
1005
1006 void WebPageProxy::setAssistedNodeSelectedIndex(uint32_t index, bool allowMultipleSelection)
1007 {
1008     process().send(Messages::WebPage::SetAssistedNodeSelectedIndex(index, allowMultipleSelection), m_pageID);
1009 }
1010
1011 void WebPageProxy::didPerformDictionaryLookup(const DictionaryPopupInfo&)
1012 {
1013     notImplemented();
1014 }
1015
1016 void WebPageProxy::savePDFToTemporaryFolderAndOpenWithNativeApplication(const String&, const String&, const IPC::DataReference&, const String&)
1017 {
1018     notImplemented();
1019 }
1020
1021 void WebPageProxy::savePDFToTemporaryFolderAndOpenWithNativeApplicationRaw(const String&, const String&, const uint8_t*, unsigned long, const String&)
1022 {
1023     notImplemented();
1024 }
1025
1026 void WebPageProxy::openPDFFromTemporaryFolderWithNativeApplication(const String&)
1027 {
1028     notImplemented();
1029 }
1030
1031 void WebPageProxy::setAcceleratedCompositingRootLayer(LayerOrView* rootLayer)
1032 {
1033     m_pageClient.setAcceleratedCompositingRootLayer(rootLayer);
1034 }
1035
1036 void WebPageProxy::showPlaybackTargetPicker(bool hasVideo, const IntRect& elementRect)
1037 {
1038     m_pageClient.showPlaybackTargetPicker(hasVideo, elementRect);
1039 }
1040
1041 void WebPageProxy::commitPotentialTapFailed()
1042 {
1043     m_pageClient.commitPotentialTapFailed();
1044 }
1045
1046 void WebPageProxy::didNotHandleTapAsClick(const WebCore::IntPoint& point)
1047 {
1048     m_pageClient.didNotHandleTapAsClick(point);
1049     m_uiClient->didNotHandleTapAsClick(point);
1050 }
1051     
1052 void WebPageProxy::didCompleteSyntheticClick()
1053 {
1054     m_pageClient.didCompleteSyntheticClick();
1055 }
1056
1057 void WebPageProxy::disableDoubleTapGesturesDuringTapIfNecessary(uint64_t requestID)
1058 {
1059     m_pageClient.disableDoubleTapGesturesDuringTapIfNecessary(requestID);
1060 }
1061
1062 uint32_t WebPageProxy::computePagesForPrintingAndDrawToPDF(uint64_t frameID, const PrintInfo& printInfo, DrawToPDFCallback::CallbackFunction&& callback)
1063 {
1064     if (!isValid()) {
1065         callback(IPC::DataReference(), CallbackBase::Error::OwnerWasInvalidated);
1066         return 0;
1067     }
1068
1069     uint32_t pageCount = 0;
1070     auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivityToken());
1071     using Message = Messages::WebPage::ComputePagesForPrintingAndDrawToPDF;
1072     process().sendSync(Message(frameID, printInfo, callbackID), Message::Reply(pageCount), m_pageID);
1073     return pageCount;
1074 }
1075
1076 void WebPageProxy::drawToPDFCallback(const IPC::DataReference& pdfData, CallbackID callbackID)
1077 {
1078     auto callback = m_callbacks.take<DrawToPDFCallback>(callbackID);
1079     RELEASE_ASSERT(callback);
1080     callback->performCallbackWithReturnValue(pdfData);
1081 }
1082
1083 void WebPageProxy::contentSizeCategoryDidChange(const String& contentSizeCategory)
1084 {
1085     process().send(Messages::WebPage::ContentSizeCategoryDidChange(contentSizeCategory), m_pageID);
1086 }
1087
1088 void WebPageProxy::editorStateChanged(const EditorState& editorState)
1089 {
1090     bool couldChangeSecureInputState = m_editorState.isInPasswordField != editorState.isInPasswordField || m_editorState.selectionIsNone;
1091     
1092     m_editorState = editorState;
1093     
1094     // Selection being none is a temporary state when editing. Flipping secure input state too quickly was causing trouble (not fully understood).
1095     if (couldChangeSecureInputState && !editorState.selectionIsNone)
1096         m_pageClient.updateSecureInputState();
1097     
1098     if (editorState.shouldIgnoreSelectionChanges)
1099         return;
1100     
1101     // We always need to notify the client on iOS to make sure the selection is redrawn,
1102     // even during composition to support phrase boundary gesture.
1103     m_pageClient.selectionDidChange();
1104 }
1105
1106 void WebPageProxy::showValidationMessage(const IntRect& anchorClientRect, const String& message)
1107 {
1108     m_validationBubble = m_pageClient.createValidationBubble(message, { m_preferences->minimumFontSize() });
1109     m_validationBubble->setAnchorRect(anchorClientRect, uiClient().presentingViewController());
1110
1111     // If we are currently doing a scrolling / zoom animation, then we'll delay showing the validation
1112     // bubble until the animation is over.
1113     if (!m_isScrollingOrZooming)
1114         m_validationBubble->show();
1115 }
1116
1117 void WebPageProxy::setIsScrollingOrZooming(bool isScrollingOrZooming)
1118 {
1119     m_isScrollingOrZooming = isScrollingOrZooming;
1120
1121     // We finished doing the scrolling / zoom animation so we can now show the validation
1122     // bubble if we're supposed to.
1123     if (!m_isScrollingOrZooming && m_validationBubble)
1124         m_validationBubble->show();
1125 }
1126
1127 #if ENABLE(DATA_INTERACTION)
1128
1129 void WebPageProxy::didPerformDataInteractionControllerOperation(bool handled)
1130 {
1131     m_pageClient.didPerformDataInteractionControllerOperation(handled);
1132 }
1133
1134 void WebPageProxy::didHandleStartDataInteractionRequest(bool started)
1135 {
1136     m_pageClient.didHandleStartDataInteractionRequest(started);
1137 }
1138
1139 void WebPageProxy::didHandleAdditionalDragItemsRequest(bool added)
1140 {
1141     m_pageClient.didHandleAdditionalDragItemsRequest(added);
1142 }
1143
1144 void WebPageProxy::requestStartDataInteraction(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition)
1145 {
1146     if (isValid())
1147         m_process->send(Messages::WebPage::RequestStartDataInteraction(clientPosition, globalPosition), m_pageID);
1148 }
1149
1150 void WebPageProxy::requestAdditionalItemsForDragSession(const IntPoint& clientPosition, const IntPoint& globalPosition)
1151 {
1152     if (isValid())
1153         m_process->send(Messages::WebPage::RequestAdditionalItemsForDragSession(clientPosition, globalPosition), m_pageID);
1154 }
1155
1156 void WebPageProxy::didConcludeEditDataInteraction(std::optional<TextIndicatorData> data)
1157 {
1158     m_pageClient.didConcludeEditDataInteraction(data);
1159 }
1160
1161 #endif
1162
1163 #if USE(QUICK_LOOK)
1164     
1165 void WebPageProxy::didStartLoadForQuickLookDocumentInMainFrame(const String& fileName, const String& uti)
1166 {
1167     // Ensure that fileName isn't really a path name
1168     static_assert(notFound + 1 == 0, "The following line assumes WTF::notFound equals -1");
1169     if (m_navigationClient)
1170         m_navigationClient->didStartLoadForQuickLookDocumentInMainFrame(fileName.substring(fileName.reverseFind('/') + 1), uti);
1171     else
1172         m_loaderClient->didStartLoadForQuickLookDocumentInMainFrame(fileName.substring(fileName.reverseFind('/') + 1), uti);
1173 }
1174
1175 void WebPageProxy::didFinishLoadForQuickLookDocumentInMainFrame(const QuickLookDocumentData& data)
1176 {
1177     if (m_navigationClient)
1178         m_navigationClient->didFinishLoadForQuickLookDocumentInMainFrame(data);
1179     else
1180         m_loaderClient->didFinishLoadForQuickLookDocumentInMainFrame(data);
1181 }
1182
1183 void WebPageProxy::didRequestPasswordForQuickLookDocumentInMainFrame(const String& fileName)
1184 {
1185     m_pageClient.requestPasswordForQuickLookDocument(fileName, [protectedThis = makeRef(*this)](const String& password) {
1186         protectedThis->process().send(Messages::WebPage::DidReceivePasswordForQuickLookDocument(password), protectedThis->m_pageID);
1187     });
1188 }
1189
1190 #endif
1191
1192 } // namespace WebKit
1193
1194 #endif // PLATFORM(IOS)