Move Lookup Code for better cross platform usage
[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_FAMILY)
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::gestureCallback(const WebCore::IntPoint& point, uint32_t gestureType, uint32_t gestureState, uint32_t flags, CallbackID callbackID)
125 {
126     auto callback = m_callbacks.take<GestureCallback>(callbackID);
127     if (!callback) {
128         ASSERT_NOT_REACHED();
129         return;
130     }
131     
132     callback->performCallbackWithReturnValue(point, gestureType, gestureState, flags);
133 }
134
135 void WebPageProxy::touchesCallback(const WebCore::IntPoint& point, uint32_t touches, uint32_t flags, CallbackID callbackID)
136 {
137     auto callback = m_callbacks.take<TouchesCallback>(callbackID);
138     if (!callback) {
139         ASSERT_NOT_REACHED();
140         return;
141     }
142
143     callback->performCallbackWithReturnValue(point, touches, flags);
144 }
145
146 void WebPageProxy::autocorrectionDataCallback(const Vector<WebCore::FloatRect>& rects, const String& fontName, float fontSize, uint64_t fontTraits, CallbackID callbackID)
147 {
148     auto callback = m_callbacks.take<AutocorrectionDataCallback>(callbackID);
149     if (!callback) {
150         ASSERT_NOT_REACHED();
151         return;
152     }
153
154     callback->performCallbackWithReturnValue(rects, fontName, fontSize, fontTraits);
155 }
156
157 void WebPageProxy::selectionContextCallback(const String& selectedText, const String& beforeText, const String& afterText, CallbackID callbackID)
158 {
159     auto callback = m_callbacks.take<SelectionContextCallback>(callbackID);
160     if (!callback) {
161         ASSERT_NOT_REACHED();
162         return;
163     }
164
165     callback->performCallbackWithReturnValue(selectedText, beforeText, afterText);
166 }
167
168 void WebPageProxy::autocorrectionContextCallback(const String& beforeText, const String& markedText, const String& selectedText, const String& afterText, uint64_t location, uint64_t length, CallbackID callbackID)
169 {
170     auto callback = m_callbacks.take<AutocorrectionContextCallback>(callbackID);
171     if (!callback) {
172         ASSERT_NOT_REACHED();
173         return;
174     }
175
176     callback->performCallbackWithReturnValue(beforeText, markedText, selectedText, afterText, location, length);
177 }
178
179 void WebPageProxy::selectionRectsCallback(const Vector<WebCore::SelectionRect>& selectionRects, CallbackID callbackID)
180 {
181     auto callback = m_callbacks.take<SelectionRectsCallback>(callbackID);
182     if (!callback) {
183         ASSERT_NOT_REACHED();
184         return;
185     }
186     
187     callback->performCallbackWithReturnValue(selectionRects);
188 }
189
190 void WebPageProxy::assistedNodeInformationCallback(const AssistedNodeInformation& info, CallbackID callbackID)
191 {
192     auto callback = m_callbacks.take<AssistedNodeInformationCallback>(callbackID);
193     if (!callback) {
194         ASSERT_NOT_REACHED();
195         return;
196     }
197
198     callback->performCallbackWithReturnValue(info);
199 }
200
201 void WebPageProxy::requestAssistedNodeInformation(Function<void(const AssistedNodeInformation&, CallbackBase::Error)>&& callback)
202 {
203     if (!isValid()) {
204         callback({ }, CallbackBase::Error::OwnerWasInvalidated);
205         return;
206     }
207
208     auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivityToken());
209     m_process->send(Messages::WebPage::RequestAssistedNodeInformation(callbackID), m_pageID);
210 }
211
212 void WebPageProxy::updateVisibleContentRects(const VisibleContentRectUpdateInfo& visibleContentRectUpdate)
213 {
214     if (!isValid())
215         return;
216
217     if (visibleContentRectUpdate == m_lastVisibleContentRectUpdate)
218         return;
219
220     m_lastVisibleContentRectUpdate = visibleContentRectUpdate;
221     m_process->send(Messages::ViewUpdateDispatcher::VisibleContentRectUpdate(m_pageID, visibleContentRectUpdate), 0);
222 }
223
224 void WebPageProxy::resendLastVisibleContentRects()
225 {
226     m_process->send(Messages::ViewUpdateDispatcher::VisibleContentRectUpdate(m_pageID, m_lastVisibleContentRectUpdate), 0);
227 }
228
229 static inline float adjustedUnexposedEdge(float documentEdge, float exposedRectEdge, float factor)
230 {
231     if (exposedRectEdge < documentEdge)
232         return documentEdge - factor * (documentEdge - exposedRectEdge);
233     
234     return exposedRectEdge;
235 }
236
237 static inline float adjustedUnexposedMaxEdge(float documentEdge, float exposedRectEdge, float factor)
238 {
239     if (exposedRectEdge > documentEdge)
240         return documentEdge + factor * (exposedRectEdge - documentEdge);
241     
242     return exposedRectEdge;
243 }
244
245 // FIXME: rename this when visual viewports are the default.
246 WebCore::FloatRect WebPageProxy::computeCustomFixedPositionRect(const FloatRect& unobscuredContentRect, const FloatRect& unobscuredContentRectRespectingInputViewBounds, const FloatRect& currentCustomFixedPositionRect, double displayedContentScale, FrameView::LayoutViewportConstraint constraint, bool visualViewportEnabled) const
247 {
248     FloatRect constrainedUnobscuredRect = unobscuredContentRect;
249     FloatRect documentRect = pageClient().documentRect();
250
251     if (!visualViewportEnabled && pageClient().isAssistingNode())
252         return documentRect;
253
254     if (constraint == FrameView::LayoutViewportConstraint::ConstrainedToDocumentRect)
255         constrainedUnobscuredRect.intersect(documentRect);
256
257     double minimumScale = pageClient().minimumZoomScale();
258     bool isBelowMinimumScale = displayedContentScale < minimumScale;
259     if (isBelowMinimumScale) {
260         const CGFloat slope = 12;
261         CGFloat factor = std::max<CGFloat>(1 - slope * (minimumScale - displayedContentScale), 0);
262             
263         constrainedUnobscuredRect.setX(adjustedUnexposedEdge(documentRect.x(), constrainedUnobscuredRect.x(), factor));
264         constrainedUnobscuredRect.setY(adjustedUnexposedEdge(documentRect.y(), constrainedUnobscuredRect.y(), factor));
265         constrainedUnobscuredRect.setWidth(adjustedUnexposedMaxEdge(documentRect.maxX(), constrainedUnobscuredRect.maxX(), factor) - constrainedUnobscuredRect.x());
266         constrainedUnobscuredRect.setHeight(adjustedUnexposedMaxEdge(documentRect.maxY(), constrainedUnobscuredRect.maxY(), factor) - constrainedUnobscuredRect.y());
267     }
268
269     if (!visualViewportEnabled)
270         return FrameView::rectForViewportConstrainedObjects(enclosingLayoutRect(constrainedUnobscuredRect), LayoutSize(documentRect.size()), displayedContentScale, false, StickToViewportBounds);
271         
272     FloatSize constrainedSize = isBelowMinimumScale ? constrainedUnobscuredRect.size() : unobscuredContentRect.size();
273     FloatRect unobscuredContentRectForViewport = isBelowMinimumScale ? constrainedUnobscuredRect : unobscuredContentRectRespectingInputViewBounds;
274
275     auto layoutViewportSize = FrameView::expandedLayoutViewportSize(m_baseLayoutViewportSize, LayoutSize(documentRect.size()), m_preferences->layoutViewportHeightExpansionFactor());
276     FloatRect layoutViewportRect = FrameView::computeUpdatedLayoutViewportRect(LayoutRect(currentCustomFixedPositionRect), LayoutRect(documentRect), LayoutSize(constrainedSize), LayoutRect(unobscuredContentRectForViewport), layoutViewportSize, m_minStableLayoutViewportOrigin, m_maxStableLayoutViewportOrigin, constraint);
277     
278     if (layoutViewportRect != currentCustomFixedPositionRect)
279         LOG_WITH_STREAM(VisibleRects, stream << "WebPageProxy::computeCustomFixedPositionRect: new layout viewport  " << layoutViewportRect);
280     return layoutViewportRect;
281 }
282
283 void WebPageProxy::scrollingNodeScrollViewWillStartPanGesture()
284 {
285     pageClient().scrollingNodeScrollViewWillStartPanGesture();
286 }
287
288 void WebPageProxy::scrollingNodeScrollViewDidScroll()
289 {
290     pageClient().scrollingNodeScrollViewDidScroll();
291 }
292
293 void WebPageProxy::scrollingNodeScrollWillStartScroll()
294 {
295     pageClient().scrollingNodeScrollWillStartScroll();
296 }
297
298 void WebPageProxy::scrollingNodeScrollDidEndScroll()
299 {
300     pageClient().scrollingNodeScrollDidEndScroll();
301 }
302
303 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)
304 {
305     if (!isValid())
306         return;
307
308     hideValidationMessage();
309
310     m_process->send(Messages::WebPage::DynamicViewportSizeUpdate(viewLayoutSize,
311         maximumUnobscuredSize, targetExposedContentRect, targetUnobscuredRect,
312         targetUnobscuredRectInScrollViewCoordinates, unobscuredSafeAreaInsets,
313         targetScale, deviceOrientation, dynamicViewportSizeUpdateID), m_pageID);
314 }
315
316 void WebPageProxy::setViewportConfigurationViewLayoutSize(const WebCore::FloatSize& size, double scaleFactor, double minimumEffectiveDeviceWidth)
317 {
318     m_viewportConfigurationViewLayoutSize = size;
319     m_viewportConfigurationLayoutSizeScaleFactor = scaleFactor;
320
321     if (isValid())
322         m_process->send(Messages::WebPage::SetViewportConfigurationViewLayoutSize(size, scaleFactor, minimumEffectiveDeviceWidth), m_pageID);
323 }
324
325 void WebPageProxy::setForceAlwaysUserScalable(bool userScalable)
326 {
327     if (m_forceAlwaysUserScalable == userScalable)
328         return;
329     m_forceAlwaysUserScalable = userScalable;
330
331     if (isValid())
332         m_process->send(Messages::WebPage::SetForceAlwaysUserScalable(userScalable), m_pageID);
333 }
334
335 void WebPageProxy::setMaximumUnobscuredSize(const WebCore::FloatSize& size)
336 {
337     m_maximumUnobscuredSize = size;
338
339     if (isValid())
340         m_process->send(Messages::WebPage::SetMaximumUnobscuredSize(size), m_pageID);
341 }
342
343 void WebPageProxy::setDeviceOrientation(int32_t deviceOrientation)
344 {
345     if (deviceOrientation != m_deviceOrientation) {
346         m_deviceOrientation = deviceOrientation;
347         if (isValid())
348             m_process->send(Messages::WebPage::SetDeviceOrientation(deviceOrientation), m_pageID);
349     }
350 }
351
352 void WebPageProxy::setOverrideViewportArguments(const std::optional<ViewportArguments>& viewportArguments)
353 {
354     if (isValid())
355         m_process->send(Messages::WebPage::SetOverrideViewportArguments(viewportArguments), m_pageID);
356 }
357
358 static bool exceedsRenderTreeSizeSizeThreshold(uint64_t thresholdSize, uint64_t committedSize)
359 {
360     const double thesholdSizeFraction = 0.5; // Empirically-derived.
361     return committedSize > thresholdSize * thesholdSizeFraction;
362 }
363
364 void WebPageProxy::didCommitLayerTree(const WebKit::RemoteLayerTreeTransaction& layerTreeTransaction)
365 {
366     m_pageExtendedBackgroundColor = layerTreeTransaction.pageExtendedBackgroundColor();
367
368     if (!m_hasReceivedLayerTreeTransactionAfterDidCommitLoad) {
369         if (layerTreeTransaction.transactionID() >= m_firstLayerTreeTransactionIdAfterDidCommitLoad) {
370             m_hasReceivedLayerTreeTransactionAfterDidCommitLoad = true;
371             m_lastVisibleContentRectUpdate = VisibleContentRectUpdateInfo();
372         }
373     }
374
375     pageClient().didCommitLayerTree(layerTreeTransaction);
376
377     // FIXME: Remove this special mechanism and fold it into the transaction's layout milestones.
378     if (m_observedLayoutMilestones.contains(WebCore::ReachedSessionRestorationRenderTreeSizeThreshold) && !m_hitRenderTreeSizeThreshold
379         && exceedsRenderTreeSizeSizeThreshold(m_sessionRestorationRenderTreeSize, layerTreeTransaction.renderTreeSize())) {
380         m_hitRenderTreeSizeThreshold = true;
381         didReachLayoutMilestone(WebCore::ReachedSessionRestorationRenderTreeSizeThreshold);
382     }
383
384     if (m_deferredNodeAssistanceArguments) {
385         pageClient().startAssistingNode(m_deferredNodeAssistanceArguments->m_nodeInformation, m_deferredNodeAssistanceArguments->m_userIsInteracting, m_deferredNodeAssistanceArguments->m_blurPreviousNode,
386             m_deferredNodeAssistanceArguments->m_changingActivityState, m_deferredNodeAssistanceArguments->m_userData.get());
387         m_deferredNodeAssistanceArguments = nullptr;
388     }
389 }
390
391 bool WebPageProxy::updateLayoutViewportParameters(const WebKit::RemoteLayerTreeTransaction& layerTreeTransaction)
392 {
393     if (m_baseLayoutViewportSize == layerTreeTransaction.baseLayoutViewportSize()
394         && m_minStableLayoutViewportOrigin == layerTreeTransaction.minStableLayoutViewportOrigin()
395         && m_maxStableLayoutViewportOrigin == layerTreeTransaction.maxStableLayoutViewportOrigin())
396         return false;
397
398     m_baseLayoutViewportSize = layerTreeTransaction.baseLayoutViewportSize();
399     m_minStableLayoutViewportOrigin = layerTreeTransaction.minStableLayoutViewportOrigin();
400     m_maxStableLayoutViewportOrigin = layerTreeTransaction.maxStableLayoutViewportOrigin();
401
402     LOG_WITH_STREAM(VisibleRects, stream << "WebPageProxy::updateLayoutViewportParameters: baseLayoutViewportSize: " << m_baseLayoutViewportSize << " minStableLayoutViewportOrigin: " << m_minStableLayoutViewportOrigin << " maxStableLayoutViewportOrigin: " << m_maxStableLayoutViewportOrigin);
403
404     return true;
405 }
406
407 void WebPageProxy::layerTreeCommitComplete()
408 {
409     pageClient().layerTreeCommitComplete();
410 }
411
412 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)
413 {
414     if (!isValid()) {
415         callbackFunction(WebCore::IntPoint(), 0, 0, 0, CallbackBase::Error::Unknown);
416         return;
417     }
418
419     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
420     m_process->send(Messages::WebPage::SelectWithGesture(point, (uint32_t)granularity, gestureType, gestureState, isInteractingWithAssistedNode, callbackID), m_pageID);
421 }
422
423 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)
424 {
425     if (!isValid()) {
426         callbackFunction(WebCore::IntPoint(), 0, 0, CallbackBase::Error::Unknown);
427         return;
428     }
429
430     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
431     m_process->send(Messages::WebPage::UpdateSelectionWithTouches(point, touches, baseIsStart, callbackID), m_pageID);
432 }
433     
434 void WebPageProxy::replaceDictatedText(const String& oldText, const String& newText)
435 {
436     m_process->send(Messages::WebPage::ReplaceDictatedText(oldText, newText), m_pageID);
437 }
438
439 void WebPageProxy::replaceSelectedText(const String& oldText, const String& newText)
440 {
441     m_process->send(Messages::WebPage::ReplaceSelectedText(oldText, newText), m_pageID);
442 }
443
444 void WebPageProxy::requestAutocorrectionData(const String& textForAutocorrection, WTF::Function<void (const Vector<WebCore::FloatRect>&, const String&, double, uint64_t, CallbackBase::Error)>&& callbackFunction)
445 {
446     if (!isValid()) {
447         callbackFunction(Vector<WebCore::FloatRect>(), String(), 0, 0, CallbackBase::Error::Unknown);
448         return;
449     }
450
451     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
452     m_process->send(Messages::WebPage::RequestAutocorrectionData(textForAutocorrection, callbackID), m_pageID);
453 }
454
455 void WebPageProxy::applyAutocorrection(const String& correction, const String& originalText, WTF::Function<void (const String&, CallbackBase::Error)>&& callbackFunction)
456 {
457     if (!isValid()) {
458         callbackFunction(String(), CallbackBase::Error::Unknown);
459         return;
460     }
461
462     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
463     m_process->send(Messages::WebPage::ApplyAutocorrection(correction, originalText, callbackID), m_pageID);
464 }
465
466 bool WebPageProxy::applyAutocorrection(const String& correction, const String& originalText)
467 {
468     bool autocorrectionApplied = false;
469     m_process->sendSync(Messages::WebPage::SyncApplyAutocorrection(correction, originalText), Messages::WebPage::SyncApplyAutocorrection::Reply(autocorrectionApplied), m_pageID);
470     return autocorrectionApplied;
471 }
472
473 void WebPageProxy::selectTextWithGranularityAtPoint(const WebCore::IntPoint point, WebCore::TextGranularity granularity, bool isInteractingWithAssistedNode, WTF::Function<void (CallbackBase::Error)>&& callbackFunction)
474 {
475     if (!isValid()) {
476         callbackFunction(CallbackBase::Error::Unknown);
477         return;
478     }
479     
480     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
481     m_process->send(Messages::WebPage::SelectTextWithGranularityAtPoint(point, static_cast<uint32_t>(granularity), isInteractingWithAssistedNode, callbackID), m_pageID);
482 }
483
484 void WebPageProxy::selectPositionAtBoundaryWithDirection(const WebCore::IntPoint point, WebCore::TextGranularity granularity, WebCore::SelectionDirection direction, bool isInteractingWithAssistedNode, WTF::Function<void (CallbackBase::Error)>&& callbackFunction)
485 {
486     if (!isValid()) {
487         callbackFunction(CallbackBase::Error::Unknown);
488         return;
489     }
490     
491     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
492     m_process->send(Messages::WebPage::SelectPositionAtBoundaryWithDirection(point, static_cast<uint32_t>(granularity), static_cast<uint32_t>(direction), isInteractingWithAssistedNode, callbackID), m_pageID);
493 }
494
495 void WebPageProxy::moveSelectionAtBoundaryWithDirection(WebCore::TextGranularity granularity, WebCore::SelectionDirection direction, WTF::Function<void(CallbackBase::Error)>&& callbackFunction)
496 {
497     if (!isValid()) {
498         callbackFunction(CallbackBase::Error::Unknown);
499         return;
500     }
501     
502     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
503     m_process->send(Messages::WebPage::MoveSelectionAtBoundaryWithDirection(static_cast<uint32_t>(granularity), static_cast<uint32_t>(direction), callbackID), m_pageID);
504 }
505     
506 void WebPageProxy::selectPositionAtPoint(const WebCore::IntPoint point, bool isInteractingWithAssistedNode, WTF::Function<void (CallbackBase::Error)>&& callbackFunction)
507 {
508     if (!isValid()) {
509         callbackFunction(CallbackBase::Error::Unknown);
510         return;
511     }
512     
513     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
514     m_process->send(Messages::WebPage::SelectPositionAtPoint(point, isInteractingWithAssistedNode, callbackID), m_pageID);
515 }
516
517 void WebPageProxy::beginSelectionInDirection(WebCore::SelectionDirection direction, WTF::Function<void (uint64_t, CallbackBase::Error)>&& callbackFunction)
518 {
519     if (!isValid()) {
520         callbackFunction(0, CallbackBase::Error::Unknown);
521         return;
522     }
523     
524     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
525     m_process->send(Messages::WebPage::BeginSelectionInDirection(direction, callbackID), m_pageID);
526 }
527
528 void WebPageProxy::updateSelectionWithExtentPoint(const WebCore::IntPoint point, bool isInteractingWithAssistedNode, WTF::Function<void (uint64_t, CallbackBase::Error)>&& callbackFunction)
529 {
530     if (!isValid()) {
531         callbackFunction(0, CallbackBase::Error::Unknown);
532         return;
533     }
534     
535     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
536     m_process->send(Messages::WebPage::UpdateSelectionWithExtentPoint(point, isInteractingWithAssistedNode, callbackID), m_pageID);
537     
538 }
539
540 void WebPageProxy::updateSelectionWithExtentPointAndBoundary(const WebCore::IntPoint point, WebCore::TextGranularity granularity, bool isInteractingWithAssistedNode, WTF::Function<void(uint64_t, CallbackBase::Error)>&& callbackFunction)
541 {
542     if (!isValid()) {
543         callbackFunction(0, CallbackBase::Error::Unknown);
544         return;
545     }
546     
547     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
548     m_process->send(Messages::WebPage::UpdateSelectionWithExtentPointAndBoundary(point, granularity, isInteractingWithAssistedNode, callbackID), m_pageID);
549     
550 }
551
552 void WebPageProxy::requestDictationContext(WTF::Function<void (const String&, const String&, const String&, CallbackBase::Error)>&& callbackFunction)
553 {
554     if (!isValid()) {
555         callbackFunction(String(), String(), String(), 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::RequestDictationContext(callbackID), m_pageID);
561 }
562
563 void WebPageProxy::requestAutocorrectionContext(WTF::Function<void (const String&, const String&, const String&, const String&, uint64_t, uint64_t, CallbackBase::Error)>&& callbackFunction)
564 {
565     if (!isValid()) {
566         callbackFunction(String(), String(), String(), String(), 0, 0, CallbackBase::Error::Unknown);
567         return;
568     }
569
570     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
571     m_process->send(Messages::WebPage::RequestAutocorrectionContext(callbackID), m_pageID);
572 }
573
574 void WebPageProxy::getAutocorrectionContext(String& beforeContext, String& markedText, String& selectedText, String& afterContext, uint64_t& location, uint64_t& length)
575 {
576     m_process->sendSync(Messages::WebPage::GetAutocorrectionContext(), Messages::WebPage::GetAutocorrectionContext::Reply(beforeContext, markedText, selectedText, afterContext, location, length), m_pageID);
577 }
578
579 void WebPageProxy::getSelectionContext(WTF::Function<void(const String&, const String&, const String&, CallbackBase::Error)>&& callbackFunction)
580 {
581     if (!isValid()) {
582         callbackFunction(String(), String(), String(), CallbackBase::Error::Unknown);
583         return;
584     }
585     
586     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
587     m_process->send(Messages::WebPage::GetSelectionContext(callbackID), m_pageID);
588 }
589
590 void WebPageProxy::handleTwoFingerTapAtPoint(const WebCore::IntPoint& point, uint64_t requestID)
591 {
592     process().send(Messages::WebPage::HandleTwoFingerTapAtPoint(point, requestID), m_pageID);
593 }
594
595 void WebPageProxy::handleStylusSingleTapAtPoint(const WebCore::IntPoint& point, uint64_t requestID)
596 {
597     process().send(Messages::WebPage::HandleStylusSingleTapAtPoint(point, requestID), m_pageID);
598 }
599
600 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)
601 {
602     if (!isValid()) {
603         callbackFunction(WebCore::IntPoint(), 0, 0, 0, CallbackBase::Error::Unknown);
604         return;
605     }
606
607     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
608     m_process->send(Messages::WebPage::SelectWithTwoTouches(from, to, gestureType, gestureState, callbackID), m_pageID);
609 }
610
611 void WebPageProxy::didReceivePositionInformation(const InteractionInformationAtPosition& info)
612 {
613     pageClient().positionInformationDidChange(info);
614 }
615
616 void WebPageProxy::requestPositionInformation(const InteractionInformationRequest& request)
617 {
618     m_process->send(Messages::WebPage::RequestPositionInformation(request), m_pageID);
619 }
620
621 void WebPageProxy::startInteractionWithElementAtPosition(const WebCore::IntPoint& point)
622 {
623     m_process->send(Messages::WebPage::StartInteractionWithElementAtPosition(point), m_pageID);
624 }
625
626 void WebPageProxy::stopInteraction()
627 {
628     m_process->send(Messages::WebPage::StopInteraction(), m_pageID);
629 }
630
631 void WebPageProxy::performActionOnElement(uint32_t action)
632 {
633     m_process->send(Messages::WebPage::PerformActionOnElement(action), m_pageID);
634 }
635
636 void WebPageProxy::saveImageToLibrary(const SharedMemory::Handle& imageHandle, uint64_t imageSize)
637 {
638     auto sharedMemoryBuffer = SharedMemory::map(imageHandle, SharedMemory::Protection::ReadOnly);
639     auto buffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryBuffer->data()), imageSize);
640     pageClient().saveImageToLibrary(WTFMove(buffer));
641 }
642
643 void WebPageProxy::applicationDidEnterBackground()
644 {
645     bool isSuspendedUnderLock = [UIApp isSuspendedUnderLock];
646
647 #if !PLATFORM(WATCHOS)
648     // We normally delay process suspension when the app is backgrounded until the current page load completes. However,
649     // we do not want to do so when the screen is locked for power reasons.
650     if (isSuspendedUnderLock)
651         NavigationState::fromWebPage(*this).releaseNetworkActivityToken(NavigationState::NetworkActivityTokenReleaseReason::ScreenLocked);
652 #endif
653     m_process->send(Messages::WebPage::ApplicationDidEnterBackground(isSuspendedUnderLock), m_pageID);
654 }
655
656 void WebPageProxy::applicationDidFinishSnapshottingAfterEnteringBackground()
657 {
658     if (m_drawingArea) {
659         m_drawingArea->prepareForAppSuspension();
660         m_drawingArea->hideContentUntilPendingUpdate();
661     }
662     m_process->send(Messages::WebPage::ApplicationDidFinishSnapshottingAfterEnteringBackground(), m_pageID);
663 }
664
665 void WebPageProxy::applicationWillEnterForeground()
666 {
667     bool isSuspendedUnderLock = [UIApp isSuspendedUnderLock];
668     m_process->send(Messages::WebPage::ApplicationWillEnterForeground(isSuspendedUnderLock), m_pageID);
669 }
670
671 void WebPageProxy::applicationWillResignActive()
672 {
673     m_process->send(Messages::WebPage::ApplicationWillResignActive(), m_pageID);
674 }
675
676 void WebPageProxy::applicationDidBecomeActive()
677 {
678 #if HAVE(AVKIT)
679     if (m_videoFullscreenManager)
680         m_videoFullscreenManager->applicationDidBecomeActive();
681 #endif
682     m_process->send(Messages::WebPage::ApplicationDidBecomeActive(), m_pageID);
683 }
684
685 void WebPageProxy::extendSelection(WebCore::TextGranularity granularity)
686 {
687     m_process->send(Messages::WebPage::ExtendSelection(static_cast<uint32_t>(granularity)), m_pageID);
688 }
689
690 void WebPageProxy::selectWordBackward()
691 {
692     m_process->send(Messages::WebPage::SelectWordBackward(), m_pageID);
693 }
694
695 void WebPageProxy::requestRectsForGranularityWithSelectionOffset(WebCore::TextGranularity granularity, uint32_t offset, WTF::Function<void(const Vector<WebCore::SelectionRect>&, CallbackBase::Error)>&& callbackFunction)
696 {
697     if (!isValid()) {
698         callbackFunction(Vector<WebCore::SelectionRect>(), CallbackBase::Error::Unknown);
699         return;
700     }
701     
702     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
703     m_process->send(Messages::WebPage::GetRectsForGranularityWithSelectionOffset(static_cast<uint32_t>(granularity), offset, callbackID), m_pageID);
704 }
705
706 void WebPageProxy::requestRectsAtSelectionOffsetWithText(int32_t offset, const String& text, WTF::Function<void(const Vector<WebCore::SelectionRect>&, CallbackBase::Error)>&& callbackFunction)
707 {
708     if (!isValid()) {
709         callbackFunction(Vector<WebCore::SelectionRect>(), CallbackBase::Error::Unknown);
710         return;
711     }
712     
713     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
714     m_process->send(Messages::WebPage::GetRectsAtSelectionOffsetWithText(offset, text, callbackID), m_pageID);
715 }
716
717 void WebPageProxy::storeSelectionForAccessibility(bool shouldStore)
718 {
719     m_process->send(Messages::WebPage::StoreSelectionForAccessibility(shouldStore), m_pageID);
720 }
721
722 void WebPageProxy::startAutoscrollAtPosition(const WebCore::FloatPoint& positionInWindow)
723 {
724     m_process->send(Messages::WebPage::StartAutoscrollAtPosition(positionInWindow), m_pageID);
725 }
726     
727 void WebPageProxy::cancelAutoscroll()
728 {
729     m_process->send(Messages::WebPage::CancelAutoscroll(), m_pageID);
730 }
731
732 void WebPageProxy::moveSelectionByOffset(int32_t offset, WTF::Function<void (CallbackBase::Error)>&& callbackFunction)
733 {
734     if (!isValid()) {
735         callbackFunction(CallbackBase::Error::Unknown);
736         return;
737     }
738     
739     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
740     m_process->send(Messages::WebPage::MoveSelectionByOffset(offset, callbackID), m_pageID);
741 }
742
743 void WebPageProxy::interpretKeyEvent(const EditorState& state, bool isCharEvent, bool& handled)
744 {
745     m_editorState = state;
746     handled = pageClient().interpretKeyEvent(m_keyEventQueue.first(), isCharEvent);
747 }
748
749 // Complex text input support for plug-ins.
750 void WebPageProxy::sendComplexTextInputToPlugin(uint64_t, const String&)
751 {
752     notImplemented();
753 }
754
755 void WebPageProxy::setSmartInsertDeleteEnabled(bool)
756 {
757     notImplemented();
758 }
759
760 void WebPageProxy::registerWebProcessAccessibilityToken(const IPC::DataReference& data)
761 {
762     pageClient().accessibilityWebProcessTokenReceived(data);
763 }    
764
765 void WebPageProxy::assistiveTechnologyMakeFirstResponder()
766 {
767     notImplemented();
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 FloatSize WebPageProxy::overrideScreenSize()
867 {
868     return WebCore::overrideScreenSize();
869 }
870
871 float WebPageProxy::textAutosizingWidth()
872 {
873     return WebCore::screenSize().width();
874 }
875
876 void WebPageProxy::couldNotRestorePageState()
877 {
878     pageClient().couldNotRestorePageState();
879 }
880
881 void WebPageProxy::restorePageState(std::optional<WebCore::FloatPoint> scrollPosition, const WebCore::FloatPoint& scrollOrigin, const WebCore::FloatBoxExtent& obscuredInsetsOnSave, double scale)
882 {
883     pageClient().restorePageState(scrollPosition, scrollOrigin, obscuredInsetsOnSave, scale);
884 }
885
886 void WebPageProxy::restorePageCenterAndScale(std::optional<WebCore::FloatPoint> center, double scale)
887 {
888     pageClient().restorePageCenterAndScale(center, scale);
889 }
890
891 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)
892 {
893     pageClient().didGetTapHighlightGeometries(requestID, color, highlightedQuads, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);
894 }
895
896 void WebPageProxy::startAssistingNode(const AssistedNodeInformation& information, bool userIsInteracting, bool blurPreviousNode, bool changingActivityState, const UserData& userData)
897 {
898     API::Object* userDataObject = process().transformHandlesToObjects(userData.object()).get();
899     if (m_editorState.isMissingPostLayoutData) {
900         m_deferredNodeAssistanceArguments = std::make_unique<NodeAssistanceArguments>(NodeAssistanceArguments { information, userIsInteracting, blurPreviousNode, changingActivityState, userDataObject });
901         return;
902     }
903
904     pageClient().startAssistingNode(information, userIsInteracting, blurPreviousNode, changingActivityState, userDataObject);
905 }
906
907 void WebPageProxy::stopAssistingNode()
908 {
909     m_deferredNodeAssistanceArguments = nullptr;
910     pageClient().stopAssistingNode();
911 }
912
913 void WebPageProxy::autofillLoginCredentials(const String& username, const String& password)
914 {
915     m_process->send(Messages::WebPage::AutofillLoginCredentials(username, password), m_pageID);
916 }
917
918 void WebPageProxy::showInspectorHighlight(const WebCore::Highlight& highlight)
919 {
920     pageClient().showInspectorHighlight(highlight);
921 }
922
923 void WebPageProxy::hideInspectorHighlight()
924 {
925     pageClient().hideInspectorHighlight();
926 }
927
928 void WebPageProxy::showInspectorIndication()
929 {
930     pageClient().showInspectorIndication();
931 }
932
933 void WebPageProxy::hideInspectorIndication()
934 {
935     pageClient().hideInspectorIndication();
936 }
937
938 void WebPageProxy::enableInspectorNodeSearch()
939 {
940     pageClient().enableInspectorNodeSearch();
941 }
942
943 void WebPageProxy::disableInspectorNodeSearch()
944 {
945     pageClient().disableInspectorNodeSearch();
946 }
947
948 void WebPageProxy::focusNextAssistedNode(bool isForward, WTF::Function<void (CallbackBase::Error)>&& callbackFunction)
949 {
950     if (!isValid()) {
951         callbackFunction(CallbackBase::Error::Unknown);
952         return;
953     }
954     
955     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
956     process().send(Messages::WebPage::FocusNextAssistedNode(isForward, callbackID), m_pageID);
957 }
958
959 void WebPageProxy::setAssistedNodeValue(const String& value)
960 {
961     process().send(Messages::WebPage::SetAssistedNodeValue(value), m_pageID);
962 }
963
964 void WebPageProxy::setAssistedNodeValueAsNumber(double value)
965 {
966     process().send(Messages::WebPage::SetAssistedNodeValueAsNumber(value), m_pageID);
967 }
968
969 void WebPageProxy::setAssistedNodeSelectedIndex(uint32_t index, bool allowMultipleSelection)
970 {
971     process().send(Messages::WebPage::SetAssistedNodeSelectedIndex(index, allowMultipleSelection), m_pageID);
972 }
973
974 void WebPageProxy::didPerformDictionaryLookup(const DictionaryPopupInfo&)
975 {
976     notImplemented();
977 }
978
979 void WebPageProxy::savePDFToTemporaryFolderAndOpenWithNativeApplication(const String&, const String&, const IPC::DataReference&, const String&)
980 {
981     notImplemented();
982 }
983
984 void WebPageProxy::savePDFToTemporaryFolderAndOpenWithNativeApplicationRaw(const String&, const String&, const uint8_t*, unsigned long, const String&)
985 {
986     notImplemented();
987 }
988
989 void WebPageProxy::openPDFFromTemporaryFolderWithNativeApplication(const String&)
990 {
991     notImplemented();
992 }
993
994 void WebPageProxy::setRemoteLayerTreeRootNode(RemoteLayerTreeNode* rootNode)
995 {
996     pageClient().setRemoteLayerTreeRootNode(rootNode);
997     m_frozenRemoteLayerTreeHost = nullptr;
998 }
999
1000 void WebPageProxy::showPlaybackTargetPicker(bool hasVideo, const IntRect& elementRect, WebCore::RouteSharingPolicy policy, const String& contextUID)
1001 {
1002     pageClient().showPlaybackTargetPicker(hasVideo, elementRect, policy, contextUID);
1003 }
1004
1005 void WebPageProxy::commitPotentialTapFailed()
1006 {
1007     pageClient().commitPotentialTapFailed();
1008 }
1009
1010 void WebPageProxy::didNotHandleTapAsClick(const WebCore::IntPoint& point)
1011 {
1012     pageClient().didNotHandleTapAsClick(point);
1013     m_uiClient->didNotHandleTapAsClick(point);
1014 }
1015     
1016 void WebPageProxy::didCompleteSyntheticClick()
1017 {
1018     pageClient().didCompleteSyntheticClick();
1019 }
1020
1021 void WebPageProxy::disableDoubleTapGesturesDuringTapIfNecessary(uint64_t requestID)
1022 {
1023     pageClient().disableDoubleTapGesturesDuringTapIfNecessary(requestID);
1024 }
1025
1026 uint32_t WebPageProxy::computePagesForPrintingAndDrawToPDF(uint64_t frameID, const PrintInfo& printInfo, DrawToPDFCallback::CallbackFunction&& callback)
1027 {
1028     if (!isValid()) {
1029         callback(IPC::DataReference(), CallbackBase::Error::OwnerWasInvalidated);
1030         return 0;
1031     }
1032
1033     uint32_t pageCount = 0;
1034     auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivityToken());
1035     using Message = Messages::WebPage::ComputePagesForPrintingAndDrawToPDF;
1036     process().sendSync(Message(frameID, printInfo, callbackID), Message::Reply(pageCount), m_pageID, Seconds::infinity());
1037     return pageCount;
1038 }
1039
1040 void WebPageProxy::drawToPDFCallback(const IPC::DataReference& pdfData, CallbackID callbackID)
1041 {
1042     auto callback = m_callbacks.take<DrawToPDFCallback>(callbackID);
1043     RELEASE_ASSERT(callback);
1044     callback->performCallbackWithReturnValue(pdfData);
1045 }
1046
1047 void WebPageProxy::contentSizeCategoryDidChange(const String& contentSizeCategory)
1048 {
1049     process().send(Messages::WebPage::ContentSizeCategoryDidChange(contentSizeCategory), m_pageID);
1050 }
1051
1052 void WebPageProxy::editorStateChanged(const EditorState& editorState)
1053 {
1054     bool couldChangeSecureInputState = m_editorState.isInPasswordField != editorState.isInPasswordField || m_editorState.selectionIsNone;
1055     
1056     m_editorState = editorState;
1057     
1058     // Selection being none is a temporary state when editing. Flipping secure input state too quickly was causing trouble (not fully understood).
1059     if (couldChangeSecureInputState && !editorState.selectionIsNone)
1060         pageClient().updateSecureInputState();
1061     
1062     if (editorState.shouldIgnoreSelectionChanges)
1063         return;
1064     
1065     // We always need to notify the client on iOS to make sure the selection is redrawn,
1066     // even during composition to support phrase boundary gesture.
1067     pageClient().selectionDidChange();
1068     updateFontAttributesAfterEditorStateChange();
1069 }
1070
1071 void WebPageProxy::showValidationMessage(const IntRect& anchorClientRect, const String& message)
1072 {
1073     m_validationBubble = pageClient().createValidationBubble(message, { m_preferences->minimumFontSize() });
1074     m_validationBubble->setAnchorRect(anchorClientRect, uiClient().presentingViewController());
1075
1076     // If we are currently doing a scrolling / zoom animation, then we'll delay showing the validation
1077     // bubble until the animation is over.
1078     if (!m_isScrollingOrZooming)
1079         m_validationBubble->show();
1080 }
1081
1082 void WebPageProxy::setIsScrollingOrZooming(bool isScrollingOrZooming)
1083 {
1084     m_isScrollingOrZooming = isScrollingOrZooming;
1085
1086     // We finished doing the scrolling / zoom animation so we can now show the validation
1087     // bubble if we're supposed to.
1088     if (!m_isScrollingOrZooming && m_validationBubble)
1089         m_validationBubble->show();
1090 }
1091
1092 void WebPageProxy::hardwareKeyboardAvailabilityChanged()
1093 {
1094     updateCurrentModifierState();
1095     m_process->send(Messages::WebPage::HardwareKeyboardAvailabilityChanged(), m_pageID);
1096 }
1097
1098 #if ENABLE(DATA_INTERACTION)
1099
1100 void WebPageProxy::didHandleStartDataInteractionRequest(bool started)
1101 {
1102     pageClient().didHandleStartDataInteractionRequest(started);
1103 }
1104
1105 void WebPageProxy::didHandleAdditionalDragItemsRequest(bool added)
1106 {
1107     pageClient().didHandleAdditionalDragItemsRequest(added);
1108 }
1109
1110 void WebPageProxy::requestStartDataInteraction(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition)
1111 {
1112     if (isValid())
1113         m_process->send(Messages::WebPage::RequestStartDataInteraction(clientPosition, globalPosition), m_pageID);
1114 }
1115
1116 void WebPageProxy::requestAdditionalItemsForDragSession(const IntPoint& clientPosition, const IntPoint& globalPosition)
1117 {
1118     if (isValid())
1119         m_process->send(Messages::WebPage::RequestAdditionalItemsForDragSession(clientPosition, globalPosition), m_pageID);
1120 }
1121
1122 void WebPageProxy::didConcludeEditDataInteraction(std::optional<TextIndicatorData> data)
1123 {
1124     pageClient().didConcludeEditDataInteraction(data);
1125 }
1126
1127 #endif
1128
1129 #if USE(QUICK_LOOK)
1130     
1131 void WebPageProxy::didStartLoadForQuickLookDocumentInMainFrame(const String& fileName, const String& uti)
1132 {
1133     // Ensure that fileName isn't really a path name
1134     static_assert(notFound + 1 == 0, "The following line assumes WTF::notFound equals -1");
1135     m_navigationClient->didStartLoadForQuickLookDocumentInMainFrame(fileName.substring(fileName.reverseFind('/') + 1), uti);
1136 }
1137
1138 void WebPageProxy::didFinishLoadForQuickLookDocumentInMainFrame(const QuickLookDocumentData& data)
1139 {
1140     m_navigationClient->didFinishLoadForQuickLookDocumentInMainFrame(data);
1141 }
1142
1143 void WebPageProxy::didRequestPasswordForQuickLookDocumentInMainFrame(const String& fileName)
1144 {
1145     pageClient().requestPasswordForQuickLookDocument(fileName, [protectedThis = makeRef(*this)](const String& password) {
1146         protectedThis->process().send(Messages::WebPage::DidReceivePasswordForQuickLookDocument(password), protectedThis->m_pageID);
1147     });
1148 }
1149
1150 #endif
1151
1152 } // namespace WebKit
1153
1154 #endif // PLATFORM(IOS_FAMILY)