[WTF] Move TextStream into WTF
[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 "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 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, const WebCore::FloatBoxExtent& unobscuredSafeAreaInsets, 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, unobscuredSafeAreaInsets, 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
376     if (!m_hasReceivedLayerTreeTransactionAfterDidCommitLoad) {
377         if (layerTreeTransaction.transactionID() >= m_firstLayerTreeTransactionIdAfterDidCommitLoad) {
378             m_hasReceivedLayerTreeTransactionAfterDidCommitLoad = true;
379             m_lastVisibleContentRectUpdate = VisibleContentRectUpdateInfo();
380         }
381     }
382
383     if (!m_dynamicViewportSizeUpdateWaitingForTarget && m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit) {
384         if (layerTreeTransaction.transactionID() >= m_dynamicViewportSizeUpdateLayerTreeTransactionID)
385             m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit = false;
386     }
387
388     m_pageClient.didCommitLayerTree(layerTreeTransaction);
389
390     // FIXME: Remove this special mechanism and fold it into the transaction's layout milestones.
391     if ((m_observedLayoutMilestones & WebCore::ReachedSessionRestorationRenderTreeSizeThreshold) && !m_hitRenderTreeSizeThreshold
392         && exceedsRenderTreeSizeSizeThreshold(m_sessionRestorationRenderTreeSize, layerTreeTransaction.renderTreeSize())) {
393         m_hitRenderTreeSizeThreshold = true;
394         didReachLayoutMilestone(WebCore::ReachedSessionRestorationRenderTreeSizeThreshold);
395     }
396
397     if (m_hasDeferredStartAssistingNode) {
398         m_pageClient.startAssistingNode(m_deferredNodeAssistanceArguments->m_nodeInformation, m_deferredNodeAssistanceArguments->m_userIsInteracting, m_deferredNodeAssistanceArguments->m_blurPreviousNode, m_deferredNodeAssistanceArguments->m_userData.get());
399         m_hasDeferredStartAssistingNode = false;
400         m_deferredNodeAssistanceArguments = nullptr;
401     }
402 }
403
404 bool WebPageProxy::updateLayoutViewportParameters(const WebKit::RemoteLayerTreeTransaction& layerTreeTransaction)
405 {
406     if (m_baseLayoutViewportSize == layerTreeTransaction.baseLayoutViewportSize()
407         && m_minStableLayoutViewportOrigin == layerTreeTransaction.minStableLayoutViewportOrigin()
408         && m_maxStableLayoutViewportOrigin == layerTreeTransaction.maxStableLayoutViewportOrigin())
409         return false;
410
411     m_baseLayoutViewportSize = layerTreeTransaction.baseLayoutViewportSize();
412     m_minStableLayoutViewportOrigin = layerTreeTransaction.minStableLayoutViewportOrigin();
413     m_maxStableLayoutViewportOrigin = layerTreeTransaction.maxStableLayoutViewportOrigin();
414
415     LOG_WITH_STREAM(VisibleRects, stream << "WebPageProxy::updateLayoutViewportParameters: baseLayoutViewportSize: " << m_baseLayoutViewportSize << " minStableLayoutViewportOrigin: " << m_minStableLayoutViewportOrigin << " maxStableLayoutViewportOrigin: " << m_maxStableLayoutViewportOrigin);
416
417     return true;
418 }
419
420 void WebPageProxy::layerTreeCommitComplete()
421 {
422     m_pageClient.layerTreeCommitComplete();
423 }
424
425 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)
426 {
427     if (!isValid()) {
428         callbackFunction(WebCore::IntPoint(), 0, 0, 0, CallbackBase::Error::Unknown);
429         return;
430     }
431
432     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
433     m_process->send(Messages::WebPage::SelectWithGesture(point, (uint32_t)granularity, gestureType, gestureState, isInteractingWithAssistedNode, callbackID), m_pageID);
434 }
435
436 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)
437 {
438     if (!isValid()) {
439         callbackFunction(WebCore::IntPoint(), 0, 0, CallbackBase::Error::Unknown);
440         return;
441     }
442
443     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
444     m_process->send(Messages::WebPage::UpdateSelectionWithTouches(point, touches, baseIsStart, callbackID), m_pageID);
445 }
446     
447 void WebPageProxy::replaceDictatedText(const String& oldText, const String& newText)
448 {
449     m_process->send(Messages::WebPage::ReplaceDictatedText(oldText, newText), m_pageID);
450 }
451
452 void WebPageProxy::replaceSelectedText(const String& oldText, const String& newText)
453 {
454     m_process->send(Messages::WebPage::ReplaceSelectedText(oldText, newText), m_pageID);
455 }
456
457 void WebPageProxy::requestAutocorrectionData(const String& textForAutocorrection, WTF::Function<void (const Vector<WebCore::FloatRect>&, const String&, double, uint64_t, CallbackBase::Error)>&& callbackFunction)
458 {
459     if (!isValid()) {
460         callbackFunction(Vector<WebCore::FloatRect>(), String(), 0, 0, CallbackBase::Error::Unknown);
461         return;
462     }
463
464     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
465     m_process->send(Messages::WebPage::RequestAutocorrectionData(textForAutocorrection, callbackID), m_pageID);
466 }
467
468 void WebPageProxy::applyAutocorrection(const String& correction, const String& originalText, WTF::Function<void (const String&, CallbackBase::Error)>&& callbackFunction)
469 {
470     if (!isValid()) {
471         callbackFunction(String(), CallbackBase::Error::Unknown);
472         return;
473     }
474
475     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
476     m_process->send(Messages::WebPage::ApplyAutocorrection(correction, originalText, callbackID), m_pageID);
477 }
478
479 void WebPageProxy::executeEditCommand(const String& commandName, WTF::Function<void (CallbackBase::Error)>&& callbackFunction)
480 {
481     if (!isValid()) {
482         callbackFunction(CallbackBase::Error::Unknown);
483         return;
484     }
485     
486     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
487     m_process->send(Messages::WebPage::ExecuteEditCommandWithCallback(commandName, callbackID), m_pageID);
488 }
489
490 bool WebPageProxy::applyAutocorrection(const String& correction, const String& originalText)
491 {
492     bool autocorrectionApplied = false;
493     m_process->sendSync(Messages::WebPage::SyncApplyAutocorrection(correction, originalText), Messages::WebPage::SyncApplyAutocorrection::Reply(autocorrectionApplied), m_pageID);
494     return autocorrectionApplied;
495 }
496
497 void WebPageProxy::selectTextWithGranularityAtPoint(const WebCore::IntPoint point, WebCore::TextGranularity granularity, bool isInteractingWithAssistedNode, WTF::Function<void (CallbackBase::Error)>&& callbackFunction)
498 {
499     if (!isValid()) {
500         callbackFunction(CallbackBase::Error::Unknown);
501         return;
502     }
503     
504     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
505     m_process->send(Messages::WebPage::SelectTextWithGranularityAtPoint(point, static_cast<uint32_t>(granularity), isInteractingWithAssistedNode, callbackID), m_pageID);
506 }
507
508 void WebPageProxy::selectPositionAtBoundaryWithDirection(const WebCore::IntPoint point, WebCore::TextGranularity granularity, WebCore::SelectionDirection direction, bool isInteractingWithAssistedNode, WTF::Function<void (CallbackBase::Error)>&& callbackFunction)
509 {
510     if (!isValid()) {
511         callbackFunction(CallbackBase::Error::Unknown);
512         return;
513     }
514     
515     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
516     m_process->send(Messages::WebPage::SelectPositionAtBoundaryWithDirection(point, static_cast<uint32_t>(granularity), static_cast<uint32_t>(direction), isInteractingWithAssistedNode, callbackID), m_pageID);
517 }
518
519 void WebPageProxy::moveSelectionAtBoundaryWithDirection(WebCore::TextGranularity granularity, WebCore::SelectionDirection direction, WTF::Function<void(CallbackBase::Error)>&& callbackFunction)
520 {
521     if (!isValid()) {
522         callbackFunction(CallbackBase::Error::Unknown);
523         return;
524     }
525     
526     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
527     m_process->send(Messages::WebPage::MoveSelectionAtBoundaryWithDirection(static_cast<uint32_t>(granularity), static_cast<uint32_t>(direction), callbackID), m_pageID);
528 }
529     
530 void WebPageProxy::selectPositionAtPoint(const WebCore::IntPoint point, bool isInteractingWithAssistedNode, WTF::Function<void (CallbackBase::Error)>&& callbackFunction)
531 {
532     if (!isValid()) {
533         callbackFunction(CallbackBase::Error::Unknown);
534         return;
535     }
536     
537     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
538     m_process->send(Messages::WebPage::SelectPositionAtPoint(point, isInteractingWithAssistedNode, callbackID), m_pageID);
539 }
540
541 void WebPageProxy::beginSelectionInDirection(WebCore::SelectionDirection direction, WTF::Function<void (uint64_t, CallbackBase::Error)>&& callbackFunction)
542 {
543     if (!isValid()) {
544         callbackFunction(0, CallbackBase::Error::Unknown);
545         return;
546     }
547     
548     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
549     m_process->send(Messages::WebPage::BeginSelectionInDirection(direction, callbackID), m_pageID);
550 }
551
552 void WebPageProxy::updateSelectionWithExtentPoint(const WebCore::IntPoint point, bool isInteractingWithAssistedNode, WTF::Function<void (uint64_t, CallbackBase::Error)>&& callbackFunction)
553 {
554     if (!isValid()) {
555         callbackFunction(0, CallbackBase::Error::Unknown);
556         return;
557     }
558     
559     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
560     m_process->send(Messages::WebPage::UpdateSelectionWithExtentPoint(point, isInteractingWithAssistedNode, callbackID), m_pageID);
561     
562 }
563
564 void WebPageProxy::updateSelectionWithExtentPointAndBoundary(const WebCore::IntPoint point, WebCore::TextGranularity granularity, bool isInteractingWithAssistedNode, WTF::Function<void(uint64_t, CallbackBase::Error)>&& callbackFunction)
565 {
566     if (!isValid()) {
567         callbackFunction(0, CallbackBase::Error::Unknown);
568         return;
569     }
570     
571     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
572     m_process->send(Messages::WebPage::UpdateSelectionWithExtentPointAndBoundary(point, granularity, isInteractingWithAssistedNode, callbackID), m_pageID);
573     
574 }
575
576 void WebPageProxy::requestDictationContext(WTF::Function<void (const String&, const String&, const String&, CallbackBase::Error)>&& callbackFunction)
577 {
578     if (!isValid()) {
579         callbackFunction(String(), String(), String(), CallbackBase::Error::Unknown);
580         return;
581     }
582
583     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
584     m_process->send(Messages::WebPage::RequestDictationContext(callbackID), m_pageID);
585 }
586
587 void WebPageProxy::requestAutocorrectionContext(WTF::Function<void (const String&, const String&, const String&, const String&, uint64_t, uint64_t, CallbackBase::Error)>&& callbackFunction)
588 {
589     if (!isValid()) {
590         callbackFunction(String(), String(), String(), String(), 0, 0, CallbackBase::Error::Unknown);
591         return;
592     }
593
594     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
595     m_process->send(Messages::WebPage::RequestAutocorrectionContext(callbackID), m_pageID);
596 }
597
598 void WebPageProxy::getAutocorrectionContext(String& beforeContext, String& markedText, String& selectedText, String& afterContext, uint64_t& location, uint64_t& length)
599 {
600     m_process->sendSync(Messages::WebPage::GetAutocorrectionContext(), Messages::WebPage::GetAutocorrectionContext::Reply(beforeContext, markedText, selectedText, afterContext, location, length), m_pageID);
601 }
602
603 void WebPageProxy::getSelectionContext(WTF::Function<void(const String&, const String&, const String&, CallbackBase::Error)>&& callbackFunction)
604 {
605     if (!isValid()) {
606         callbackFunction(String(), String(), String(), CallbackBase::Error::Unknown);
607         return;
608     }
609     
610     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
611     m_process->send(Messages::WebPage::GetSelectionContext(callbackID), m_pageID);
612 }
613
614 void WebPageProxy::handleTwoFingerTapAtPoint(const WebCore::IntPoint& point, uint64_t requestID)
615 {
616     process().send(Messages::WebPage::HandleTwoFingerTapAtPoint(point, requestID), m_pageID);
617 }
618
619 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)
620 {
621     if (!isValid()) {
622         callbackFunction(WebCore::IntPoint(), 0, 0, 0, CallbackBase::Error::Unknown);
623         return;
624     }
625
626     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
627     m_process->send(Messages::WebPage::SelectWithTwoTouches(from, to, gestureType, gestureState, callbackID), m_pageID);
628 }
629
630 void WebPageProxy::updateBlockSelectionWithTouch(const WebCore::IntPoint point, uint32_t touch, uint32_t handlePosition)
631 {
632     m_process->send(Messages::WebPage::UpdateBlockSelectionWithTouch(point, touch, handlePosition), m_pageID);
633 }
634
635 void WebPageProxy::didReceivePositionInformation(const InteractionInformationAtPosition& info)
636 {
637     m_pageClient.positionInformationDidChange(info);
638 }
639
640 void WebPageProxy::requestPositionInformation(const InteractionInformationRequest& request)
641 {
642     m_process->send(Messages::WebPage::RequestPositionInformation(request), m_pageID);
643 }
644
645 void WebPageProxy::startInteractionWithElementAtPosition(const WebCore::IntPoint& point)
646 {
647     m_process->send(Messages::WebPage::StartInteractionWithElementAtPosition(point), m_pageID);
648 }
649
650 void WebPageProxy::stopInteraction()
651 {
652     m_process->send(Messages::WebPage::StopInteraction(), m_pageID);
653 }
654
655 void WebPageProxy::performActionOnElement(uint32_t action)
656 {
657     m_process->send(Messages::WebPage::PerformActionOnElement(action), m_pageID);
658 }
659
660 void WebPageProxy::saveImageToLibrary(const SharedMemory::Handle& imageHandle, uint64_t imageSize)
661 {
662     auto sharedMemoryBuffer = SharedMemory::map(imageHandle, SharedMemory::Protection::ReadOnly);
663     auto buffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryBuffer->data()), imageSize);
664     m_pageClient.saveImageToLibrary(WTFMove(buffer));
665 }
666
667 void WebPageProxy::didUpdateBlockSelectionWithTouch(uint32_t touch, uint32_t flags, float growThreshold, float shrinkThreshold)
668 {
669     m_pageClient.didUpdateBlockSelectionWithTouch(touch, flags, growThreshold, shrinkThreshold);
670 }
671
672 void WebPageProxy::applicationDidEnterBackground()
673 {
674     bool isSuspendedUnderLock = [UIApp isSuspendedUnderLock];
675     m_process->send(Messages::WebPage::ApplicationDidEnterBackground(isSuspendedUnderLock), m_pageID);
676 }
677
678 void WebPageProxy::applicationDidFinishSnapshottingAfterEnteringBackground()
679 {
680     if (m_drawingArea)
681         m_drawingArea->prepareForAppSuspension();
682     m_process->send(Messages::WebPage::ApplicationDidFinishSnapshottingAfterEnteringBackground(), m_pageID);
683 }
684
685 void WebPageProxy::applicationWillEnterForeground()
686 {
687     bool isSuspendedUnderLock = [UIApp isSuspendedUnderLock];
688     m_process->send(Messages::WebPage::ApplicationWillEnterForeground(isSuspendedUnderLock), m_pageID);
689 }
690
691 void WebPageProxy::applicationWillResignActive()
692 {
693     m_process->send(Messages::WebPage::ApplicationWillResignActive(), m_pageID);
694 }
695
696 void WebPageProxy::applicationDidBecomeActive()
697 {
698 #if HAVE(AVKIT)
699     if (m_videoFullscreenManager)
700         m_videoFullscreenManager->applicationDidBecomeActive();
701 #endif
702     m_process->send(Messages::WebPage::ApplicationDidBecomeActive(), m_pageID);
703 }
704
705 void WebPageProxy::extendSelection(WebCore::TextGranularity granularity)
706 {
707     m_process->send(Messages::WebPage::ExtendSelection(static_cast<uint32_t>(granularity)), m_pageID);
708 }
709
710 void WebPageProxy::selectWordBackward()
711 {
712     m_process->send(Messages::WebPage::SelectWordBackward(), m_pageID);
713 }
714
715 void WebPageProxy::requestRectsForGranularityWithSelectionOffset(WebCore::TextGranularity granularity, uint32_t offset, WTF::Function<void(const Vector<WebCore::SelectionRect>&, CallbackBase::Error)>&& callbackFunction)
716 {
717     if (!isValid()) {
718         callbackFunction(Vector<WebCore::SelectionRect>(), CallbackBase::Error::Unknown);
719         return;
720     }
721     
722     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
723     m_process->send(Messages::WebPage::GetRectsForGranularityWithSelectionOffset(static_cast<uint32_t>(granularity), offset, callbackID), m_pageID);
724 }
725
726 void WebPageProxy::requestRectsAtSelectionOffsetWithText(int32_t offset, const String& text, WTF::Function<void(const Vector<WebCore::SelectionRect>&, CallbackBase::Error)>&& callbackFunction)
727 {
728     if (!isValid()) {
729         callbackFunction(Vector<WebCore::SelectionRect>(), CallbackBase::Error::Unknown);
730         return;
731     }
732     
733     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
734     m_process->send(Messages::WebPage::GetRectsAtSelectionOffsetWithText(offset, text, callbackID), m_pageID);
735 }
736
737 void WebPageProxy::moveSelectionByOffset(int32_t offset, WTF::Function<void (CallbackBase::Error)>&& callbackFunction)
738 {
739     if (!isValid()) {
740         callbackFunction(CallbackBase::Error::Unknown);
741         return;
742     }
743     
744     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
745     m_process->send(Messages::WebPage::MoveSelectionByOffset(offset, callbackID), m_pageID);
746 }
747
748 void WebPageProxy::interpretKeyEvent(const EditorState& state, bool isCharEvent, bool& handled)
749 {
750     m_editorState = state;
751     handled = m_pageClient.interpretKeyEvent(m_keyEventQueue.first(), isCharEvent);
752 }
753
754 // Complex text input support for plug-ins.
755 void WebPageProxy::sendComplexTextInputToPlugin(uint64_t, const String&)
756 {
757     notImplemented();
758 }
759
760 void WebPageProxy::setSmartInsertDeleteEnabled(bool)
761 {
762     notImplemented();
763 }
764
765 void WebPageProxy::registerWebProcessAccessibilityToken(const IPC::DataReference& data)
766 {
767     m_pageClient.accessibilityWebProcessTokenReceived(data);
768 }    
769
770 void WebPageProxy::makeFirstResponder()
771 {
772     notImplemented();
773 }
774
775 void WebPageProxy::registerUIProcessAccessibilityTokens(const IPC::DataReference& elementToken, const IPC::DataReference& windowToken)
776 {
777     if (!isValid())
778         return;
779     
780     process().send(Messages::WebPage::RegisterUIProcessAccessibilityTokens(elementToken, windowToken), m_pageID);
781 }
782
783 void WebPageProxy::pluginFocusOrWindowFocusChanged(uint64_t, bool)
784 {
785     notImplemented();
786 }
787
788 void WebPageProxy::setPluginComplexTextInputState(uint64_t, uint64_t)
789 {
790     notImplemented();
791 }
792
793 void WebPageProxy::executeSavedCommandBySelector(const String&, bool&)
794 {
795     notImplemented();
796 }
797
798 bool WebPageProxy::shouldDelayWindowOrderingForEvent(const WebKit::WebMouseEvent&)
799 {
800     notImplemented();
801     return false;
802 }
803
804 bool WebPageProxy::acceptsFirstMouse(int, const WebKit::WebMouseEvent&)
805 {
806     notImplemented();
807     return false;
808 }
809
810 void WebPageProxy::willStartUserTriggeredZooming()
811 {
812     process().send(Messages::WebPage::WillStartUserTriggeredZooming(), m_pageID);
813 }
814
815 void WebPageProxy::potentialTapAtPosition(const WebCore::FloatPoint& position, uint64_t& requestID)
816 {
817     hideValidationMessage();
818     process().send(Messages::WebPage::PotentialTapAtPosition(requestID, position), m_pageID);
819 }
820
821 void WebPageProxy::commitPotentialTap(uint64_t layerTreeTransactionIdAtLastTouchStart)
822 {
823     process().send(Messages::WebPage::CommitPotentialTap(layerTreeTransactionIdAtLastTouchStart), m_pageID);
824 }
825
826 void WebPageProxy::cancelPotentialTap()
827 {
828     process().send(Messages::WebPage::CancelPotentialTap(), m_pageID);
829 }
830
831 void WebPageProxy::tapHighlightAtPosition(const WebCore::FloatPoint& position, uint64_t& requestID)
832 {
833     process().send(Messages::WebPage::TapHighlightAtPosition(requestID, position), m_pageID);
834 }
835
836 void WebPageProxy::handleTap(const FloatPoint& location, uint64_t layerTreeTransactionIdAtLastTouchStart)
837 {
838     process().send(Messages::WebPage::HandleTap(roundedIntPoint(location), layerTreeTransactionIdAtLastTouchStart), m_pageID);
839 }
840
841 void WebPageProxy::inspectorNodeSearchMovedToPosition(const WebCore::FloatPoint& position)
842 {
843     process().send(Messages::WebPage::InspectorNodeSearchMovedToPosition(position), m_pageID);
844 }
845
846 void WebPageProxy::inspectorNodeSearchEndedAtPosition(const WebCore::FloatPoint& position)
847 {
848     process().send(Messages::WebPage::InspectorNodeSearchEndedAtPosition(position), m_pageID);
849 }
850
851 void WebPageProxy::blurAssistedNode()
852 {
853     process().send(Messages::WebPage::BlurAssistedNode(), m_pageID);
854 }
855
856 FloatSize WebPageProxy::screenSize()
857 {
858     return WebCore::screenSize();
859 }
860
861 FloatSize WebPageProxy::availableScreenSize()
862 {
863     return WebCore::availableScreenSize();
864 }
865     
866 float WebPageProxy::textAutosizingWidth()
867 {
868     return WebCore::screenSize().width();
869 }
870
871 void WebPageProxy::dynamicViewportUpdateChangedTarget(double newScale, const WebCore::FloatPoint& newScrollPosition, uint64_t dynamicViewportSizeUpdateID)
872 {
873     if (dynamicViewportSizeUpdateID != m_currentDynamicViewportSizeUpdateID)
874         return;
875
876     if (m_dynamicViewportSizeUpdateWaitingForTarget) {
877         m_dynamicViewportSizeUpdateLayerTreeTransactionID = downcast<RemoteLayerTreeDrawingAreaProxy>(*drawingArea()).nextLayerTreeTransactionID();
878         m_dynamicViewportSizeUpdateWaitingForTarget = false;
879         m_pageClient.dynamicViewportUpdateChangedTarget(newScale, newScrollPosition, m_dynamicViewportSizeUpdateLayerTreeTransactionID);
880     }
881 }
882
883 void WebPageProxy::couldNotRestorePageState()
884 {
885     m_pageClient.couldNotRestorePageState();
886 }
887
888 void WebPageProxy::restorePageState(std::optional<WebCore::FloatPoint> scrollPosition, const WebCore::FloatPoint& scrollOrigin, const WebCore::FloatBoxExtent& obscuredInsetsOnSave, double scale)
889 {
890     m_pageClient.restorePageState(scrollPosition, scrollOrigin, obscuredInsetsOnSave, scale);
891 }
892
893 void WebPageProxy::restorePageCenterAndScale(std::optional<WebCore::FloatPoint> center, double scale)
894 {
895     m_pageClient.restorePageCenterAndScale(center, scale);
896 }
897
898 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)
899 {
900     m_pageClient.didGetTapHighlightGeometries(requestID, color, highlightedQuads, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);
901 }
902
903 void WebPageProxy::startAssistingNode(const AssistedNodeInformation& information, bool userIsInteracting, bool blurPreviousNode, const UserData& userData)
904 {
905     API::Object* userDataObject = process().transformHandlesToObjects(userData.object()).get();
906     if (m_editorState.isMissingPostLayoutData) {
907         m_deferredNodeAssistanceArguments = std::make_unique<NodeAssistanceArguments>(NodeAssistanceArguments { information, userIsInteracting, blurPreviousNode, userDataObject });
908         m_hasDeferredStartAssistingNode = true;
909         return;
910     }
911
912     m_pageClient.startAssistingNode(information, userIsInteracting, blurPreviousNode, userDataObject);
913 }
914
915 void WebPageProxy::stopAssistingNode()
916 {
917     if (m_hasDeferredStartAssistingNode) {
918         m_hasDeferredStartAssistingNode = false;
919         m_deferredNodeAssistanceArguments = nullptr;
920     }
921     m_pageClient.stopAssistingNode();
922 }
923
924 void WebPageProxy::showInspectorHighlight(const WebCore::Highlight& highlight)
925 {
926     m_pageClient.showInspectorHighlight(highlight);
927 }
928
929 void WebPageProxy::hideInspectorHighlight()
930 {
931     m_pageClient.hideInspectorHighlight();
932 }
933
934 void WebPageProxy::showInspectorIndication()
935 {
936     m_pageClient.showInspectorIndication();
937 }
938
939 void WebPageProxy::hideInspectorIndication()
940 {
941     m_pageClient.hideInspectorIndication();
942 }
943
944 void WebPageProxy::enableInspectorNodeSearch()
945 {
946     m_pageClient.enableInspectorNodeSearch();
947 }
948
949 void WebPageProxy::disableInspectorNodeSearch()
950 {
951     m_pageClient.disableInspectorNodeSearch();
952 }
953
954 void WebPageProxy::focusNextAssistedNode(bool isForward, WTF::Function<void (CallbackBase::Error)>&& callbackFunction)
955 {
956     if (!isValid()) {
957         callbackFunction(CallbackBase::Error::Unknown);
958         return;
959     }
960     
961     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
962     process().send(Messages::WebPage::FocusNextAssistedNode(isForward, callbackID), m_pageID);
963 }
964
965 void WebPageProxy::setAssistedNodeValue(const String& value)
966 {
967     process().send(Messages::WebPage::SetAssistedNodeValue(value), m_pageID);
968 }
969
970 void WebPageProxy::setAssistedNodeValueAsNumber(double value)
971 {
972     process().send(Messages::WebPage::SetAssistedNodeValueAsNumber(value), m_pageID);
973 }
974
975 void WebPageProxy::setAssistedNodeSelectedIndex(uint32_t index, bool allowMultipleSelection)
976 {
977     process().send(Messages::WebPage::SetAssistedNodeSelectedIndex(index, allowMultipleSelection), m_pageID);
978 }
979
980 void WebPageProxy::didPerformDictionaryLookup(const DictionaryPopupInfo&)
981 {
982     notImplemented();
983 }
984
985 void WebPageProxy::savePDFToTemporaryFolderAndOpenWithNativeApplication(const String&, const String&, const IPC::DataReference&, const String&)
986 {
987     notImplemented();
988 }
989
990 void WebPageProxy::savePDFToTemporaryFolderAndOpenWithNativeApplicationRaw(const String&, const String&, const uint8_t*, unsigned long, const String&)
991 {
992     notImplemented();
993 }
994
995 void WebPageProxy::openPDFFromTemporaryFolderWithNativeApplication(const String&)
996 {
997     notImplemented();
998 }
999
1000 void WebPageProxy::setAcceleratedCompositingRootLayer(LayerOrView* rootLayer)
1001 {
1002     m_pageClient.setAcceleratedCompositingRootLayer(rootLayer);
1003 }
1004
1005 void WebPageProxy::showPlaybackTargetPicker(bool hasVideo, const IntRect& elementRect)
1006 {
1007     m_pageClient.showPlaybackTargetPicker(hasVideo, elementRect);
1008 }
1009
1010 void WebPageProxy::commitPotentialTapFailed()
1011 {
1012     m_pageClient.commitPotentialTapFailed();
1013 }
1014
1015 void WebPageProxy::didNotHandleTapAsClick(const WebCore::IntPoint& point)
1016 {
1017     m_pageClient.didNotHandleTapAsClick(point);
1018     m_uiClient->didNotHandleTapAsClick(point);
1019 }
1020     
1021 void WebPageProxy::didCompleteSyntheticClick()
1022 {
1023     m_pageClient.didCompleteSyntheticClick();
1024 }
1025
1026 void WebPageProxy::disableDoubleTapGesturesDuringTapIfNecessary(uint64_t requestID)
1027 {
1028     m_pageClient.disableDoubleTapGesturesDuringTapIfNecessary(requestID);
1029 }
1030
1031 uint32_t WebPageProxy::computePagesForPrintingAndDrawToPDF(uint64_t frameID, const PrintInfo& printInfo, DrawToPDFCallback::CallbackFunction&& callback)
1032 {
1033     if (!isValid()) {
1034         callback(IPC::DataReference(), CallbackBase::Error::OwnerWasInvalidated);
1035         return 0;
1036     }
1037
1038     uint32_t pageCount = 0;
1039     auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivityToken());
1040     using Message = Messages::WebPage::ComputePagesForPrintingAndDrawToPDF;
1041     process().sendSync(Message(frameID, printInfo, callbackID), Message::Reply(pageCount), m_pageID);
1042     return pageCount;
1043 }
1044
1045 void WebPageProxy::drawToPDFCallback(const IPC::DataReference& pdfData, CallbackID callbackID)
1046 {
1047     auto callback = m_callbacks.take<DrawToPDFCallback>(callbackID);
1048     RELEASE_ASSERT(callback);
1049     callback->performCallbackWithReturnValue(pdfData);
1050 }
1051
1052 void WebPageProxy::contentSizeCategoryDidChange(const String& contentSizeCategory)
1053 {
1054     process().send(Messages::WebPage::ContentSizeCategoryDidChange(contentSizeCategory), m_pageID);
1055 }
1056
1057 void WebPageProxy::editorStateChanged(const EditorState& editorState)
1058 {
1059     bool couldChangeSecureInputState = m_editorState.isInPasswordField != editorState.isInPasswordField || m_editorState.selectionIsNone;
1060     
1061     m_editorState = editorState;
1062     
1063     // Selection being none is a temporary state when editing. Flipping secure input state too quickly was causing trouble (not fully understood).
1064     if (couldChangeSecureInputState && !editorState.selectionIsNone)
1065         m_pageClient.updateSecureInputState();
1066     
1067     if (editorState.shouldIgnoreSelectionChanges)
1068         return;
1069     
1070     // We always need to notify the client on iOS to make sure the selection is redrawn,
1071     // even during composition to support phrase boundary gesture.
1072     m_pageClient.selectionDidChange();
1073 }
1074
1075 void WebPageProxy::showValidationMessage(const IntRect& anchorClientRect, const String& message)
1076 {
1077     m_validationBubble = m_pageClient.createValidationBubble(message, { m_preferences->minimumFontSize() });
1078     m_validationBubble->setAnchorRect(anchorClientRect, uiClient().presentingViewController());
1079
1080     // If we are currently doing a scrolling / zoom animation, then we'll delay showing the validation
1081     // bubble until the animation is over.
1082     if (!m_isScrollingOrZooming)
1083         m_validationBubble->show();
1084 }
1085
1086 void WebPageProxy::setIsScrollingOrZooming(bool isScrollingOrZooming)
1087 {
1088     m_isScrollingOrZooming = isScrollingOrZooming;
1089
1090     // We finished doing the scrolling / zoom animation so we can now show the validation
1091     // bubble if we're supposed to.
1092     if (!m_isScrollingOrZooming && m_validationBubble)
1093         m_validationBubble->show();
1094 }
1095
1096 #if ENABLE(DATA_INTERACTION)
1097
1098 void WebPageProxy::didPerformDataInteractionControllerOperation(bool handled)
1099 {
1100     m_pageClient.didPerformDataInteractionControllerOperation(handled);
1101 }
1102
1103 void WebPageProxy::didHandleStartDataInteractionRequest(bool started)
1104 {
1105     m_pageClient.didHandleStartDataInteractionRequest(started);
1106 }
1107
1108 void WebPageProxy::requestStartDataInteraction(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition)
1109 {
1110     if (isValid())
1111         m_process->send(Messages::WebPage::RequestStartDataInteraction(clientPosition, globalPosition), m_pageID);
1112 }
1113
1114 void WebPageProxy::didConcludeEditDataInteraction(std::optional<TextIndicatorData> data)
1115 {
1116     m_pageClient.didConcludeEditDataInteraction(data);
1117 }
1118
1119 #endif
1120
1121 #if USE(QUICK_LOOK)
1122     
1123 void WebPageProxy::didStartLoadForQuickLookDocumentInMainFrame(const String& fileName, const String& uti)
1124 {
1125     // Ensure that fileName isn't really a path name
1126     static_assert(notFound + 1 == 0, "The following line assumes WTF::notFound equals -1");
1127     if (m_navigationClient)
1128         m_navigationClient->didStartLoadForQuickLookDocumentInMainFrame(fileName.substring(fileName.reverseFind('/') + 1), uti);
1129     else
1130         m_loaderClient->didStartLoadForQuickLookDocumentInMainFrame(fileName.substring(fileName.reverseFind('/') + 1), uti);
1131 }
1132
1133 void WebPageProxy::didFinishLoadForQuickLookDocumentInMainFrame(const QuickLookDocumentData& data)
1134 {
1135     if (m_navigationClient)
1136         m_navigationClient->didFinishLoadForQuickLookDocumentInMainFrame(data);
1137     else
1138         m_loaderClient->didFinishLoadForQuickLookDocumentInMainFrame(data);
1139 }
1140
1141 void WebPageProxy::didRequestPasswordForQuickLookDocumentInMainFrame(const String& fileName)
1142 {
1143     m_pageClient.requestPasswordForQuickLookDocument(fileName, [protectedThis = makeRef(*this)](const String& password) {
1144         protectedThis->process().send(Messages::WebPage::DidReceivePasswordForQuickLookDocument(password), protectedThis->m_pageID);
1145     });
1146 }
1147
1148 #endif
1149
1150 } // namespace WebKit
1151
1152 #endif // PLATFORM(IOS)