4432dd40633f9d170acbd66d4cdd67889cfe9d53
[WebKit-https.git] / Source / WebKit / UIProcess / ios / PageClientImplIOS.mm
1 /*
2  * Copyright (C) 2012-2016 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #import "config.h"
27 #import "PageClientImplIOS.h"
28
29 #if PLATFORM(IOS_FAMILY)
30
31 #import "APIData.h"
32 #import "DataReference.h"
33 #import "DownloadProxy.h"
34 #import "DrawingAreaProxy.h"
35 #import "InteractionInformationAtPosition.h"
36 #import "NativeWebKeyboardEvent.h"
37 #import "NavigationState.h"
38 #import "StringUtilities.h"
39 #import "UIKitSPI.h"
40 #import "UndoOrRedo.h"
41 #import "ViewSnapshotStore.h"
42 #import "WKContentView.h"
43 #import "WKContentViewInteraction.h"
44 #import "WKDrawingView.h"
45 #import "WKEditCommand.h"
46 #import "WKGeolocationProviderIOS.h"
47 #import "WKPasswordView.h"
48 #import "WKProcessPoolInternal.h"
49 #import "WKWebViewConfigurationInternal.h"
50 #import "WKWebViewContentProviderRegistry.h"
51 #import "WKWebViewInternal.h"
52 #import "WebContextMenuProxy.h"
53 #import "WebDataListSuggestionsDropdownIOS.h"
54 #import "WebEditCommandProxy.h"
55 #import "WebProcessProxy.h"
56 #import "_WKDownloadInternal.h"
57 #import <WebCore/DOMPasteAccess.h>
58 #import <WebCore/DictionaryLookup.h>
59 #import <WebCore/NotImplemented.h>
60 #import <WebCore/PlatformScreen.h>
61 #import <WebCore/PromisedAttachmentInfo.h>
62 #import <WebCore/ShareData.h>
63 #import <WebCore/SharedBuffer.h>
64 #import <WebCore/TextIndicator.h>
65 #import <WebCore/ValidationBubble.h>
66 #import <pal/spi/cocoa/NSKeyedArchiverSPI.h>
67 #import <wtf/BlockPtr.h>
68
69 #define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, m_webView.get()->_page->process().connection())
70
71 namespace WebKit {
72 using namespace WebCore;
73
74 PageClientImpl::PageClientImpl(WKContentView *contentView, WKWebView *webView)
75     : PageClientImplCocoa(webView)
76     , m_contentView(contentView)
77     , m_undoTarget(adoptNS([[WKEditorUndoTarget alloc] init]))
78 {
79 }
80
81 PageClientImpl::~PageClientImpl()
82 {
83 }
84
85 std::unique_ptr<DrawingAreaProxy> PageClientImpl::createDrawingAreaProxy(WebProcessProxy& process)
86 {
87     return [m_contentView _createDrawingAreaProxy:process];
88 }
89
90 void PageClientImpl::setViewNeedsDisplay(const Region&)
91 {
92     ASSERT_NOT_REACHED();
93 }
94
95 void PageClientImpl::requestScroll(const FloatPoint& scrollPosition, const IntPoint& scrollOrigin)
96 {
97     [m_webView _scrollToContentScrollPosition:scrollPosition scrollOrigin:scrollOrigin];
98 }
99
100 WebCore::FloatPoint PageClientImpl::viewScrollPosition()
101 {
102     if (UIScrollView *scroller = [m_contentView _scroller])
103         return scroller.contentOffset;
104
105     return { };
106 }
107
108 IntSize PageClientImpl::viewSize()
109 {
110     if (UIScrollView *scroller = [m_contentView _scroller])
111         return IntSize(scroller.bounds.size);
112
113     return IntSize(m_contentView.bounds.size);
114 }
115
116 bool PageClientImpl::isViewWindowActive()
117 {
118     // FIXME: https://bugs.webkit.org/show_bug.cgi?id=133098
119     return isViewVisible() || [m_webView _isRetainingActiveFocusedState];
120 }
121
122 bool PageClientImpl::isViewFocused()
123 {
124     return (isViewInWindow() && ![m_webView _isBackground] && [m_webView _contentViewIsFirstResponder]) || [m_webView _isRetainingActiveFocusedState];
125 }
126
127 bool PageClientImpl::isViewVisible()
128 {
129     if (isViewInWindow() && ![m_webView _isBackground])
130         return true;
131     
132     if ([m_webView _isShowingVideoPictureInPicture])
133         return true;
134     
135     if ([m_webView _mayAutomaticallyShowVideoPictureInPicture])
136         return true;
137     
138     return false;
139 }
140
141 bool PageClientImpl::isViewInWindow()
142 {
143     // FIXME: in WebKitTestRunner, m_webView is nil, so check the content view instead.
144     if (auto webView = m_webView.get())
145         return [webView window];
146
147     return [m_contentView window];
148 }
149
150 bool PageClientImpl::isViewVisibleOrOccluded()
151 {
152     return isViewVisible();
153 }
154
155 bool PageClientImpl::isVisuallyIdle()
156 {
157     return !isViewVisible();
158 }
159
160 void PageClientImpl::processDidExit()
161 {
162     [m_contentView _processDidExit];
163     [m_webView _processDidExit];
164 }
165
166 void PageClientImpl::processWillSwap()
167 {
168     [m_contentView _processWillSwap];
169     [m_webView _processWillSwap];
170 }
171
172 void PageClientImpl::didRelaunchProcess()
173 {
174     [m_contentView _didRelaunchProcess];
175     [m_webView _didRelaunchProcess];
176 }
177
178 #if HAVE(VISIBILITY_PROPAGATION_VIEW)
179 void PageClientImpl::didCreateContextForVisibilityPropagation(LayerHostingContextID)
180 {
181     [m_contentView _processDidCreateContextForVisibilityPropagation];
182 }
183 #endif
184
185 void PageClientImpl::pageClosed()
186 {
187     notImplemented();
188 }
189
190 void PageClientImpl::preferencesDidChange()
191 {
192     notImplemented();
193 }
194
195 void PageClientImpl::toolTipChanged(const String&, const String&)
196 {
197     notImplemented();
198 }
199
200 void PageClientImpl::didNotHandleTapAsClick(const WebCore::IntPoint& point)
201 {
202     [m_contentView _didNotHandleTapAsClick:point];
203 }
204     
205 void PageClientImpl::didCompleteSyntheticClick()
206 {
207     [m_contentView _didCompleteSyntheticClick];
208 }
209
210 void PageClientImpl::decidePolicyForGeolocationPermissionRequest(WebFrameProxy& frame, API::SecurityOrigin& origin, Function<void(bool)>& completionHandler)
211 {
212     [[wrapper(m_webView.get()->_page->process().processPool()) _geolocationProvider] decidePolicyForGeolocationRequestFromOrigin:origin.securityOrigin() frame:frame completionHandler:std::exchange(completionHandler, nullptr) view:m_webView.get().get()];
213 }
214
215 void PageClientImpl::didStartProvisionalLoadForMainFrame()
216 {
217     [m_webView _didStartProvisionalLoadForMainFrame];
218     [m_webView _hidePasswordView];
219 }
220
221 void PageClientImpl::didFailProvisionalLoadForMainFrame()
222 {
223     [m_webView _hidePasswordView];
224 }
225
226 void PageClientImpl::didCommitLoadForMainFrame(const String& mimeType, bool useCustomContentProvider)
227 {
228     [m_webView _hidePasswordView];
229     [m_webView _setHasCustomContentView:useCustomContentProvider loadedMIMEType:mimeType];
230     [m_contentView _didCommitLoadForMainFrame];
231 }
232
233 void PageClientImpl::handleDownloadRequest(DownloadProxy&)
234 {
235 }
236
237 void PageClientImpl::didChangeContentSize(const WebCore::IntSize&)
238 {
239     notImplemented();
240 }
241
242 void PageClientImpl::disableDoubleTapGesturesDuringTapIfNecessary(uint64_t requestID)
243 {
244     [m_contentView _disableDoubleTapGesturesDuringTapIfNecessary:requestID];
245 }
246
247 void PageClientImpl::handleSmartMagnificationInformationForPotentialTap(uint64_t requestID, const WebCore::FloatRect& renderRect, bool fitEntireRect, double viewportMinimumScale, double viewportMaximumScale)
248 {
249     [m_contentView _handleSmartMagnificationInformationForPotentialTap:requestID renderRect:renderRect fitEntireRect:fitEntireRect viewportMinimumScale:viewportMinimumScale viewportMaximumScale:viewportMaximumScale];
250 }
251
252 double PageClientImpl::minimumZoomScale() const
253 {
254     if (UIScrollView *scroller = [m_webView scrollView])
255         return scroller.minimumZoomScale;
256
257     return 1;
258 }
259
260 WebCore::FloatRect PageClientImpl::documentRect() const
261 {
262     return [m_contentView bounds];
263 }
264
265 void PageClientImpl::setCursor(const Cursor&)
266 {
267     notImplemented();
268 }
269
270 void PageClientImpl::setCursorHiddenUntilMouseMoves(bool)
271 {
272     notImplemented();
273 }
274
275 void PageClientImpl::didChangeViewportProperties(const ViewportAttributes&)
276 {
277     notImplemented();
278 }
279
280 void PageClientImpl::registerEditCommand(Ref<WebEditCommandProxy>&& command, UndoOrRedo undoOrRedo)
281 {
282     auto actionName = command->label();
283     auto commandObjC = adoptNS([[WKEditCommand alloc] initWithWebEditCommandProxy:WTFMove(command)]);
284     
285     NSUndoManager *undoManager = [m_contentView undoManager];
286     [undoManager registerUndoWithTarget:m_undoTarget.get() selector:((undoOrRedo == UndoOrRedo::Undo) ? @selector(undoEditing:) : @selector(redoEditing:)) object:commandObjC.get()];
287     if (!actionName.isEmpty())
288         [undoManager setActionName:(NSString *)actionName];
289 }
290
291 #if USE(INSERTION_UNDO_GROUPING)
292 void PageClientImpl::registerInsertionUndoGrouping()
293 {
294     notImplemented();
295 }
296 #endif
297
298 void PageClientImpl::clearAllEditCommands()
299 {
300     [[m_contentView undoManager] removeAllActionsWithTarget:m_undoTarget.get()];
301 }
302
303 bool PageClientImpl::canUndoRedo(UndoOrRedo undoOrRedo)
304 {
305     return (undoOrRedo == UndoOrRedo::Undo) ? [[m_contentView undoManager] canUndo] : [[m_contentView undoManager] canRedo];
306 }
307
308 void PageClientImpl::executeUndoRedo(UndoOrRedo undoOrRedo)
309 {
310     return (undoOrRedo == UndoOrRedo::Undo) ? [[m_contentView undoManager] undo] : [[m_contentView undoManager] redo];
311 }
312
313 void PageClientImpl::accessibilityWebProcessTokenReceived(const IPC::DataReference& data)
314 {
315     NSData *remoteToken = [NSData dataWithBytes:data.data() length:data.size()];
316     [m_contentView _setAccessibilityWebProcessToken:remoteToken];
317 }
318
319 bool PageClientImpl::interpretKeyEvent(const NativeWebKeyboardEvent& event, bool isCharEvent)
320 {
321     return [m_contentView _interpretKeyEvent:event.nativeEvent() isCharEvent:isCharEvent];
322 }
323
324 void PageClientImpl::positionInformationDidChange(const InteractionInformationAtPosition& info)
325 {
326     [m_contentView _positionInformationDidChange:info];
327 }
328
329 void PageClientImpl::saveImageToLibrary(Ref<SharedBuffer>&& imageBuffer)
330 {
331     RetainPtr<NSData> imageData = imageBuffer->createNSData();
332     UIImageDataWriteToSavedPhotosAlbum(imageData.get(), nil, NULL, NULL);
333 }
334
335 bool PageClientImpl::executeSavedCommandBySelector(const String&)
336 {
337     notImplemented();
338     return false;
339 }
340
341 void PageClientImpl::selectionDidChange()
342 {
343     [m_contentView _selectionChanged];
344 }
345
346 void PageClientImpl::updateSecureInputState()
347 {
348     notImplemented();
349 }
350
351 void PageClientImpl::resetSecureInputState()
352 {
353     notImplemented();
354 }
355
356 void PageClientImpl::notifyInputContextAboutDiscardedComposition()
357 {
358     notImplemented();
359 }
360
361 void PageClientImpl::assistiveTechnologyMakeFirstResponder()
362 {
363     notImplemented();
364 }
365
366 void PageClientImpl::makeFirstResponder()
367 {
368     notImplemented();
369 }
370
371 FloatRect PageClientImpl::convertToDeviceSpace(const FloatRect& rect)
372 {
373     notImplemented();
374     return FloatRect();
375 }
376
377 FloatRect PageClientImpl::convertToUserSpace(const FloatRect& rect)
378 {
379     notImplemented();
380     return FloatRect();
381 }
382
383 IntPoint PageClientImpl::screenToRootView(const IntPoint& point)
384 {
385     return IntPoint([m_contentView convertPoint:point fromView:nil]);
386 }
387
388 IntRect PageClientImpl::rootViewToScreen(const IntRect& rect)
389 {
390     return enclosingIntRect([m_contentView convertRect:rect toView:nil]);
391 }
392     
393 IntPoint PageClientImpl::accessibilityScreenToRootView(const IntPoint& point)
394 {
395     CGPoint rootViewPoint = point;
396     if ([m_contentView respondsToSelector:@selector(accessibilityConvertPointFromSceneReferenceCoordinates:)])
397         rootViewPoint = [m_contentView accessibilityConvertPointFromSceneReferenceCoordinates:rootViewPoint];
398     return IntPoint(rootViewPoint);
399 }
400     
401 IntRect PageClientImpl::rootViewToAccessibilityScreen(const IntRect& rect)
402 {
403     CGRect rootViewRect = rect;
404     if ([m_contentView respondsToSelector:@selector(accessibilityConvertRectToSceneReferenceCoordinates:)])
405         rootViewRect = [m_contentView accessibilityConvertRectToSceneReferenceCoordinates:rootViewRect];
406     return enclosingIntRect(rootViewRect);
407 }
408     
409 void PageClientImpl::doneWithKeyEvent(const NativeWebKeyboardEvent& event, bool eventWasHandled)
410 {
411     [m_contentView _didHandleKeyEvent:event.nativeEvent() eventWasHandled:eventWasHandled];
412 }
413
414 #if ENABLE(TOUCH_EVENTS)
415 void PageClientImpl::doneWithTouchEvent(const NativeWebTouchEvent& nativeWebtouchEvent, bool eventHandled)
416 {
417     [m_contentView _webTouchEvent:nativeWebtouchEvent preventsNativeGestures:eventHandled];
418 }
419 #endif
420
421 RefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy(WebPageProxy&)
422 {
423     return nullptr;
424 }
425
426 void PageClientImpl::setTextIndicator(Ref<TextIndicator> textIndicator, TextIndicatorWindowLifetime)
427 {
428 }
429
430 void PageClientImpl::clearTextIndicator(TextIndicatorWindowDismissalAnimation)
431 {
432 }
433
434 void PageClientImpl::setTextIndicatorAnimationProgress(float)
435 {
436 }
437
438 void PageClientImpl::enterAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext)
439 {
440 }
441
442 void PageClientImpl::showSafeBrowsingWarning(const SafeBrowsingWarning& warning, CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, URL>&&)>&& completionHandler)
443 {
444     if (auto webView = m_webView.get())
445         [webView _showSafeBrowsingWarning:warning completionHandler:WTFMove(completionHandler)];
446     else
447         completionHandler(ContinueUnsafeLoad::No);
448 }
449
450 void PageClientImpl::clearSafeBrowsingWarning()
451 {
452     [m_webView _clearSafeBrowsingWarning];
453 }
454
455 void PageClientImpl::clearSafeBrowsingWarningIfForMainFrameNavigation()
456 {
457     [m_webView _clearSafeBrowsingWarningIfForMainFrameNavigation];
458 }
459
460 void PageClientImpl::exitAcceleratedCompositingMode()
461 {
462     notImplemented();
463 }
464
465 void PageClientImpl::updateAcceleratedCompositingMode(const LayerTreeContext&)
466 {
467 }
468
469 void PageClientImpl::didPerformDictionaryLookup(const DictionaryPopupInfo& dictionaryPopupInfo)
470 {
471 #if ENABLE(REVEAL)
472     DictionaryLookup::showPopup(dictionaryPopupInfo, m_contentView, nullptr);
473 #else
474     UNUSED_PARAM(dictionaryPopupInfo);
475 #endif // ENABLE(REVEAL)
476 }
477
478 #if USE(APPLE_INTERNAL_SDK)
479 #include <WebKitAdditions/PageClientImplIOSAdditions.mm>
480 #endif
481
482 void PageClientImpl::setRemoteLayerTreeRootNode(RemoteLayerTreeNode* rootNode)
483 {
484     [m_contentView _setAcceleratedCompositingRootView:rootNode ? rootNode->uiView() : nil];
485 }
486
487 CALayer *PageClientImpl::acceleratedCompositingRootLayer() const
488 {
489     notImplemented();
490     return nullptr;
491 }
492
493 RefPtr<ViewSnapshot> PageClientImpl::takeViewSnapshot()
494 {
495     return [m_webView _takeViewSnapshot];
496 }
497
498 void PageClientImpl::wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent& event)
499 {
500     notImplemented();
501 }
502
503 void PageClientImpl::commitPotentialTapFailed()
504 {
505     [m_contentView _commitPotentialTapFailed];
506 }
507
508 void PageClientImpl::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, bool nodeHasBuiltInClickHandling)
509 {
510     [m_contentView _didGetTapHighlightForRequest:requestID color:color quads:highlightedQuads topLeftRadius:topLeftRadius topRightRadius:topRightRadius bottomLeftRadius:bottomLeftRadius bottomRightRadius:bottomRightRadius nodeHasBuiltInClickHandling:nodeHasBuiltInClickHandling];
511 }
512
513 void PageClientImpl::didCommitLayerTree(const RemoteLayerTreeTransaction& layerTreeTransaction)
514 {
515     [m_contentView _didCommitLayerTree:layerTreeTransaction];
516 }
517
518 void PageClientImpl::layerTreeCommitComplete()
519 {
520     [m_contentView _layerTreeCommitComplete];
521 }
522
523 void PageClientImpl::couldNotRestorePageState()
524 {
525     [m_webView _couldNotRestorePageState];
526 }
527
528 void PageClientImpl::restorePageState(Optional<WebCore::FloatPoint> scrollPosition, const WebCore::FloatPoint& scrollOrigin, const WebCore::FloatBoxExtent& obscuredInsetsOnSave, double scale)
529 {
530     [m_webView _restorePageScrollPosition:scrollPosition scrollOrigin:scrollOrigin previousObscuredInset:obscuredInsetsOnSave scale:scale];
531 }
532
533 void PageClientImpl::restorePageCenterAndScale(Optional<WebCore::FloatPoint> center, double scale)
534 {
535     [m_webView _restorePageStateToUnobscuredCenter:center scale:scale];
536 }
537
538 void PageClientImpl::elementDidFocus(const FocusedElementInformation& nodeInformation, bool userIsInteracting, bool blurPreviousNode, bool changingActivityState, API::Object* userData)
539 {
540     MESSAGE_CHECK(!userData || userData->type() == API::Object::Type::Data);
541
542     NSObject <NSSecureCoding> *userObject = nil;
543     if (API::Data* data = static_cast<API::Data*>(userData)) {
544         auto nsData = adoptNS([[NSData alloc] initWithBytesNoCopy:const_cast<void*>(static_cast<const void*>(data->bytes())) length:data->size() freeWhenDone:NO]);
545         auto unarchiver = secureUnarchiverFromData(nsData.get());
546         @try {
547             userObject = [unarchiver decodeObjectOfClass:[NSObject class] forKey:@"userObject"];
548         } @catch (NSException *exception) {
549             LOG_ERROR("Failed to decode user data: %@", exception);
550         }
551     }
552
553     [m_contentView _elementDidFocus:nodeInformation userIsInteracting:userIsInteracting blurPreviousNode:blurPreviousNode changingActivityState:changingActivityState userObject:userObject];
554 }
555
556 bool PageClientImpl::isFocusingElement()
557 {
558     return [m_contentView isFocusingElement];
559 }
560
561 void PageClientImpl::elementDidBlur()
562 {
563     [m_contentView _elementDidBlur];
564 }
565
566 void PageClientImpl::focusedElementDidChangeInputMode(WebCore::InputMode mode)
567 {
568     [m_contentView _didUpdateInputMode:mode];
569 }
570
571 void PageClientImpl::didReceiveEditorStateUpdateAfterFocus()
572 {
573     [m_contentView _didReceiveEditorStateUpdateAfterFocus];
574 }
575
576 void PageClientImpl::showPlaybackTargetPicker(bool hasVideo, const IntRect& elementRect, WebCore::RouteSharingPolicy policy, const String& contextUID)
577 {
578     [m_contentView _showPlaybackTargetPicker:hasVideo fromRect:elementRect routeSharingPolicy:policy routingContextUID:contextUID];
579 }
580
581 bool PageClientImpl::handleRunOpenPanel(WebPageProxy*, WebFrameProxy*, API::OpenPanelParameters* parameters, WebOpenPanelResultListenerProxy* listener)
582 {
583     [m_contentView _showRunOpenPanel:parameters resultListener:listener];
584     return true;
585 }
586
587 bool PageClientImpl::showShareSheet(const ShareDataWithParsedURL& shareData, WTF::CompletionHandler<void(bool)>&& completionHandler)
588 {
589     [m_contentView _showShareSheet:shareData inRect:WTF::nullopt completionHandler:WTFMove(completionHandler)];
590     return true;
591 }
592
593 void PageClientImpl::showInspectorHighlight(const WebCore::Highlight& highlight)
594 {
595     [m_contentView _showInspectorHighlight:highlight];
596 }
597
598 void PageClientImpl::hideInspectorHighlight()
599 {
600     [m_contentView _hideInspectorHighlight];
601 }
602
603 void PageClientImpl::showInspectorIndication()
604 {
605     [m_contentView setShowingInspectorIndication:YES];
606 }
607
608 void PageClientImpl::hideInspectorIndication()
609 {
610     [m_contentView setShowingInspectorIndication:NO];
611 }
612
613 void PageClientImpl::enableInspectorNodeSearch()
614 {
615     [m_contentView _enableInspectorNodeSearch];
616 }
617
618 void PageClientImpl::disableInspectorNodeSearch()
619 {
620     [m_contentView _disableInspectorNodeSearch];
621 }
622
623 #if ENABLE(FULLSCREEN_API)
624
625 WebFullScreenManagerProxyClient& PageClientImpl::fullScreenManagerProxyClient()
626 {
627     return *this;
628 }
629
630 // WebFullScreenManagerProxyClient
631
632 void PageClientImpl::closeFullScreenManager()
633 {
634     [m_webView closeFullScreenWindowController];
635 }
636
637 bool PageClientImpl::isFullScreen()
638 {
639     if (![m_webView hasFullScreenWindowController])
640         return false;
641
642     return [m_webView fullScreenWindowController].isFullScreen;
643 }
644
645 void PageClientImpl::enterFullScreen()
646 {
647     [[m_webView fullScreenWindowController] enterFullScreen];
648 }
649
650 void PageClientImpl::exitFullScreen()
651 {
652     [[m_webView fullScreenWindowController] exitFullScreen];
653 }
654
655 void PageClientImpl::beganEnterFullScreen(const IntRect& initialFrame, const IntRect& finalFrame)
656 {
657     [[m_webView fullScreenWindowController] beganEnterFullScreenWithInitialFrame:initialFrame finalFrame:finalFrame];
658 }
659
660 void PageClientImpl::beganExitFullScreen(const IntRect& initialFrame, const IntRect& finalFrame)
661 {
662     [[m_webView fullScreenWindowController] beganExitFullScreenWithInitialFrame:initialFrame finalFrame:finalFrame];
663 }
664
665 #endif // ENABLE(FULLSCREEN_API)
666
667 void PageClientImpl::didFinishLoadingDataForCustomContentProvider(const String& suggestedFilename, const IPC::DataReference& dataReference)
668 {
669     RetainPtr<NSData> data = adoptNS([[NSData alloc] initWithBytes:dataReference.data() length:dataReference.size()]);
670     [m_webView _didFinishLoadingDataForCustomContentProviderWithSuggestedFilename:suggestedFilename data:data.get()];
671 }
672
673 void PageClientImpl::scrollingNodeScrollViewWillStartPanGesture()
674 {
675     [m_contentView scrollViewWillStartPanOrPinchGesture];
676 }
677
678 void PageClientImpl::scrollingNodeScrollViewDidScroll()
679 {
680     [m_contentView _didScroll];
681 }
682
683 void PageClientImpl::scrollingNodeScrollWillStartScroll()
684 {
685     [m_contentView _scrollingNodeScrollingWillBegin];
686 }
687
688 void PageClientImpl::scrollingNodeScrollDidEndScroll()
689 {
690     [m_contentView _scrollingNodeScrollingDidEnd];
691 }
692
693 Vector<String> PageClientImpl::mimeTypesWithCustomContentProviders()
694 {
695     return [m_webView _contentProviderRegistry]._mimeTypesWithCustomContentProviders;
696 }
697
698 void PageClientImpl::navigationGestureDidBegin()
699 {
700     [m_webView _navigationGestureDidBegin];
701     NavigationState::fromWebPage(*m_webView.get()->_page).navigationGestureDidBegin();
702 }
703
704 void PageClientImpl::navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem& item)
705 {
706     NavigationState::fromWebPage(*m_webView.get()->_page).navigationGestureWillEnd(willNavigate, item);
707 }
708
709 void PageClientImpl::navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem& item)
710 {
711     NavigationState::fromWebPage(*m_webView.get()->_page).navigationGestureDidEnd(willNavigate, item);
712     [m_webView _navigationGestureDidEnd];
713 }
714
715 void PageClientImpl::navigationGestureDidEnd()
716 {
717     [m_webView _navigationGestureDidEnd];
718 }
719
720 void PageClientImpl::willRecordNavigationSnapshot(WebBackForwardListItem& item)
721 {
722     NavigationState::fromWebPage(*m_webView.get()->_page).willRecordNavigationSnapshot(item);
723 }
724
725 void PageClientImpl::didRemoveNavigationGestureSnapshot()
726 {
727     NavigationState::fromWebPage(*m_webView.get()->_page).navigationGestureSnapshotWasRemoved();
728 }
729
730 void PageClientImpl::didFirstVisuallyNonEmptyLayoutForMainFrame()
731 {
732 }
733
734 void PageClientImpl::didFinishLoadForMainFrame()
735 {
736     [m_webView _didFinishLoadForMainFrame];
737 }
738
739 void PageClientImpl::didFailLoadForMainFrame()
740 {
741     [m_webView _didFailLoadForMainFrame];
742 }
743
744 void PageClientImpl::didSameDocumentNavigationForMainFrame(SameDocumentNavigationType navigationType)
745 {
746     [m_webView _didSameDocumentNavigationForMainFrame:navigationType];
747 }
748
749 void PageClientImpl::didChangeBackgroundColor()
750 {
751     [m_webView _updateScrollViewBackground];
752 }
753
754 void PageClientImpl::videoControlsManagerDidChange()
755 {
756     [m_webView _videoControlsManagerDidChange];
757 }
758
759 void PageClientImpl::refView()
760 {
761     [m_contentView retain];
762     [m_webView retain];
763 }
764
765 void PageClientImpl::derefView()
766 {
767     [m_contentView release];
768     [m_webView release];
769 }
770
771 void PageClientImpl::didRestoreScrollPosition()
772 {
773 }
774
775 WebCore::UserInterfaceLayoutDirection PageClientImpl::userInterfaceLayoutDirection()
776 {
777     if (!m_webView)
778         return WebCore::UserInterfaceLayoutDirection::LTR;
779     return ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute:[m_webView semanticContentAttribute]] == UIUserInterfaceLayoutDirectionLeftToRight) ? WebCore::UserInterfaceLayoutDirection::LTR : WebCore::UserInterfaceLayoutDirection::RTL;
780 }
781
782 Ref<ValidationBubble> PageClientImpl::createValidationBubble(const String& message, const ValidationBubble::Settings& settings)
783 {
784     return ValidationBubble::create(m_contentView, message, settings);
785 }
786
787 #if ENABLE(INPUT_TYPE_COLOR)
788 RefPtr<WebColorPicker> PageClientImpl::createColorPicker(WebPageProxy*, const WebCore::Color& initialColor, const WebCore::IntRect&, Vector<WebCore::Color>&&)
789 {
790     return nullptr;
791 }
792 #endif
793
794 #if ENABLE(DATALIST_ELEMENT)
795 RefPtr<WebDataListSuggestionsDropdown> PageClientImpl::createDataListSuggestionsDropdown(WebPageProxy& page)
796 {
797     return WebDataListSuggestionsDropdownIOS::create(page, m_contentView);
798 }
799 #endif
800
801 #if ENABLE(DATA_INTERACTION)
802 void PageClientImpl::didPerformDragOperation(bool handled)
803 {
804     [m_contentView _didPerformDragOperation:handled];
805 }
806
807 void PageClientImpl::didHandleDragStartRequest(bool started)
808 {
809     [m_contentView _didHandleDragStartRequest:started];
810 }
811
812 void PageClientImpl::didHandleAdditionalDragItemsRequest(bool added)
813 {
814     [m_contentView _didHandleAdditionalDragItemsRequest:added];
815 }
816
817 void PageClientImpl::startDrag(const DragItem& item, const ShareableBitmap::Handle& image)
818 {
819     [m_contentView _startDrag:ShareableBitmap::create(image)->makeCGImageCopy() item:item];
820 }
821
822 void PageClientImpl::didConcludeEditDrag(Optional<TextIndicatorData> data)
823 {
824     [m_contentView _didConcludeEditDrag:data];
825 }
826
827 void PageClientImpl::didChangeDragCaretRect(const IntRect& previousCaretRect, const IntRect& caretRect)
828 {
829     [m_contentView _didChangeDragCaretRect:previousCaretRect currentRect:caretRect];
830 }
831 #endif
832
833 #if USE(QUICK_LOOK)
834 void PageClientImpl::requestPasswordForQuickLookDocument(const String& fileName, WTF::Function<void(const String&)>&& completionHandler)
835 {
836     auto passwordHandler = makeBlockPtr([completionHandler = WTFMove(completionHandler)](NSString *password) {
837         completionHandler(password);
838     });
839
840     if (WKPasswordView *passwordView = [m_webView _passwordView]) {
841         ASSERT(fileName == String { passwordView.documentName });
842         [passwordView showPasswordFailureAlert];
843         passwordView.userDidEnterPassword = passwordHandler.get();
844         return;
845     }
846
847     [m_webView _showPasswordViewWithDocumentName:fileName passwordHandler:passwordHandler.get()];
848     NavigationState::fromWebPage(*m_webView.get()->_page).didRequestPasswordForQuickLookDocument();
849 }
850 #endif
851
852 void PageClientImpl::requestDOMPasteAccess(const WebCore::IntRect& elementRect, const String& originIdentifier, CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&& completionHandler)
853 {
854     [m_contentView _requestDOMPasteAccessWithElementRect:elementRect originIdentifier:originIdentifier completionHandler:WTFMove(completionHandler)];
855 }
856
857 #if HAVE(PENCILKIT)
858 RetainPtr<WKDrawingView> PageClientImpl::createDrawingView(WebCore::GraphicsLayer::EmbeddedViewID embeddedViewID)
859 {
860     return adoptNS([[WKDrawingView alloc] initWithEmbeddedViewID:embeddedViewID contentView:m_contentView]);
861 }
862 #endif
863
864 #if ENABLE(POINTER_EVENTS)
865 void PageClientImpl::cancelPointersForGestureRecognizer(UIGestureRecognizer* gestureRecognizer)
866 {
867     [m_contentView cancelPointersForGestureRecognizer:gestureRecognizer];
868 }
869 #endif
870
871 void PageClientImpl::handleAutocorrectionContext(const WebAutocorrectionContext& context)
872 {
873     [m_contentView _handleAutocorrectionContext:context];
874 }
875
876 } // namespace WebKit
877
878 #endif // PLATFORM(IOS_FAMILY)
879
880 #undef MESSAGE_CHECK