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