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