[iOS] Rename some WebKit-internal functions and variables that reference "data intera...
[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/DictionaryLookup.h>
58 #import <WebCore/NotImplemented.h>
59 #import <WebCore/PlatformScreen.h>
60 #import <WebCore/PromisedAttachmentInfo.h>
61 #import <WebCore/ShareData.h>
62 #import <WebCore/SharedBuffer.h>
63 #import <WebCore/TextIndicator.h>
64 #import <WebCore/ValidationBubble.h>
65 #import <pal/spi/cocoa/NSKeyedArchiverSPI.h>
66 #import <wtf/BlockPtr.h>
67
68 #define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, m_webView.get()->_page->process().connection())
69
70 namespace WebKit {
71 using namespace WebCore;
72
73 PageClientImpl::PageClientImpl(WKContentView *contentView, WKWebView *webView)
74     : PageClientImplCocoa(webView)
75     , m_contentView(contentView)
76     , m_undoTarget(adoptNS([[WKEditorUndoTarget alloc] init]))
77 {
78 }
79
80 PageClientImpl::~PageClientImpl()
81 {
82 }
83
84 std::unique_ptr<DrawingAreaProxy> PageClientImpl::createDrawingAreaProxy(WebProcessProxy& process)
85 {
86     return [m_contentView _createDrawingAreaProxy:process];
87 }
88
89 void PageClientImpl::setViewNeedsDisplay(const Region&)
90 {
91     ASSERT_NOT_REACHED();
92 }
93
94 void PageClientImpl::requestScroll(const FloatPoint& scrollPosition, const IntPoint& scrollOrigin, bool isProgrammaticScroll)
95 {
96     UNUSED_PARAM(isProgrammaticScroll);
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 void PageClientImpl::pageClosed()
179 {
180     notImplemented();
181 }
182
183 void PageClientImpl::preferencesDidChange()
184 {
185     notImplemented();
186 }
187
188 void PageClientImpl::toolTipChanged(const String&, const String&)
189 {
190     notImplemented();
191 }
192
193 void PageClientImpl::didNotHandleTapAsClick(const WebCore::IntPoint& point)
194 {
195     [m_contentView _didNotHandleTapAsClick:point];
196 }
197     
198 void PageClientImpl::didCompleteSyntheticClick()
199 {
200     [m_contentView _didCompleteSyntheticClick];
201 }
202
203 void PageClientImpl::decidePolicyForGeolocationPermissionRequest(WebFrameProxy& frame, API::SecurityOrigin& origin, Function<void(bool)>& completionHandler)
204 {
205     [[wrapper(m_webView.get()->_page->process().processPool()) _geolocationProvider] decidePolicyForGeolocationRequestFromOrigin:origin.securityOrigin() frame:frame completionHandler:std::exchange(completionHandler, nullptr) view:m_webView.get().get()];
206 }
207
208 void PageClientImpl::didStartProvisionalLoadForMainFrame()
209 {
210     [m_webView _didStartProvisionalLoadForMainFrame];
211     [m_webView _hidePasswordView];
212 }
213
214 void PageClientImpl::didFailProvisionalLoadForMainFrame()
215 {
216     [m_webView _hidePasswordView];
217 }
218
219 void PageClientImpl::didCommitLoadForMainFrame(const String& mimeType, bool useCustomContentProvider)
220 {
221     [m_webView _hidePasswordView];
222     [m_webView _setHasCustomContentView:useCustomContentProvider loadedMIMEType:mimeType];
223     [m_contentView _didCommitLoadForMainFrame];
224 }
225
226 void PageClientImpl::handleDownloadRequest(DownloadProxy*)
227 {
228 }
229
230 void PageClientImpl::didChangeContentSize(const WebCore::IntSize&)
231 {
232     notImplemented();
233 }
234
235 void PageClientImpl::disableDoubleTapGesturesDuringTapIfNecessary(uint64_t requestID)
236 {
237     [m_contentView _disableDoubleTapGesturesDuringTapIfNecessary:requestID];
238 }
239
240 double PageClientImpl::minimumZoomScale() const
241 {
242     if (UIScrollView *scroller = [m_webView scrollView])
243         return scroller.minimumZoomScale;
244
245     return 1;
246 }
247
248 WebCore::FloatRect PageClientImpl::documentRect() const
249 {
250     return [m_contentView bounds];
251 }
252
253 void PageClientImpl::setCursor(const Cursor&)
254 {
255     notImplemented();
256 }
257
258 void PageClientImpl::setCursorHiddenUntilMouseMoves(bool)
259 {
260     notImplemented();
261 }
262
263 void PageClientImpl::didChangeViewportProperties(const ViewportAttributes&)
264 {
265     notImplemented();
266 }
267
268 void PageClientImpl::registerEditCommand(Ref<WebEditCommandProxy>&& command, UndoOrRedo undoOrRedo)
269 {
270     auto actionName = command->label();
271     auto commandObjC = adoptNS([[WKEditCommand alloc] initWithWebEditCommandProxy:WTFMove(command)]);
272     
273     NSUndoManager *undoManager = [m_contentView undoManager];
274     [undoManager registerUndoWithTarget:m_undoTarget.get() selector:((undoOrRedo == UndoOrRedo::Undo) ? @selector(undoEditing:) : @selector(redoEditing:)) object:commandObjC.get()];
275     if (!actionName.isEmpty())
276         [undoManager setActionName:(NSString *)actionName];
277 }
278
279 #if USE(INSERTION_UNDO_GROUPING)
280 void PageClientImpl::registerInsertionUndoGrouping()
281 {
282     notImplemented();
283 }
284 #endif
285
286 void PageClientImpl::clearAllEditCommands()
287 {
288     [[m_contentView undoManager] removeAllActionsWithTarget:m_undoTarget.get()];
289 }
290
291 bool PageClientImpl::canUndoRedo(UndoOrRedo undoOrRedo)
292 {
293     return (undoOrRedo == UndoOrRedo::Undo) ? [[m_contentView undoManager] canUndo] : [[m_contentView undoManager] canRedo];
294 }
295
296 void PageClientImpl::executeUndoRedo(UndoOrRedo undoOrRedo)
297 {
298     return (undoOrRedo == UndoOrRedo::Undo) ? [[m_contentView undoManager] undo] : [[m_contentView undoManager] redo];
299 }
300
301 void PageClientImpl::accessibilityWebProcessTokenReceived(const IPC::DataReference& data)
302 {
303     NSData *remoteToken = [NSData dataWithBytes:data.data() length:data.size()];
304     [m_contentView _setAccessibilityWebProcessToken:remoteToken];
305 }
306
307 bool PageClientImpl::interpretKeyEvent(const NativeWebKeyboardEvent& event, bool isCharEvent)
308 {
309     return [m_contentView _interpretKeyEvent:event.nativeEvent() isCharEvent:isCharEvent];
310 }
311
312 void PageClientImpl::positionInformationDidChange(const InteractionInformationAtPosition& info)
313 {
314     [m_contentView _positionInformationDidChange:info];
315 }
316
317 void PageClientImpl::saveImageToLibrary(Ref<SharedBuffer>&& imageBuffer)
318 {
319     RetainPtr<NSData> imageData = imageBuffer->createNSData();
320     UIImageDataWriteToSavedPhotosAlbum(imageData.get(), nil, NULL, NULL);
321 }
322
323 bool PageClientImpl::executeSavedCommandBySelector(const String&)
324 {
325     notImplemented();
326     return false;
327 }
328
329 void PageClientImpl::selectionDidChange()
330 {
331     [m_contentView _selectionChanged];
332 }
333
334 void PageClientImpl::updateSecureInputState()
335 {
336     notImplemented();
337 }
338
339 void PageClientImpl::resetSecureInputState()
340 {
341     notImplemented();
342 }
343
344 void PageClientImpl::notifyInputContextAboutDiscardedComposition()
345 {
346     notImplemented();
347 }
348
349 void PageClientImpl::assistiveTechnologyMakeFirstResponder()
350 {
351     notImplemented();
352 }
353
354 void PageClientImpl::makeFirstResponder()
355 {
356     notImplemented();
357 }
358
359 FloatRect PageClientImpl::convertToDeviceSpace(const FloatRect& rect)
360 {
361     notImplemented();
362     return FloatRect();
363 }
364
365 FloatRect PageClientImpl::convertToUserSpace(const FloatRect& rect)
366 {
367     notImplemented();
368     return FloatRect();
369 }
370
371 IntPoint PageClientImpl::screenToRootView(const IntPoint& point)
372 {
373     return IntPoint([m_contentView convertPoint:point fromView:nil]);
374 }
375
376 IntRect PageClientImpl::rootViewToScreen(const IntRect& rect)
377 {
378     return enclosingIntRect([m_contentView convertRect:rect toView:nil]);
379 }
380     
381 IntPoint PageClientImpl::accessibilityScreenToRootView(const IntPoint& point)
382 {
383     CGPoint rootViewPoint = point;
384     if ([m_contentView respondsToSelector:@selector(accessibilityConvertPointFromSceneReferenceCoordinates:)])
385         rootViewPoint = [m_contentView accessibilityConvertPointFromSceneReferenceCoordinates:rootViewPoint];
386     return IntPoint(rootViewPoint);
387 }
388     
389 IntRect PageClientImpl::rootViewToAccessibilityScreen(const IntRect& rect)
390 {
391     CGRect rootViewRect = rect;
392     if ([m_contentView respondsToSelector:@selector(accessibilityConvertRectToSceneReferenceCoordinates:)])
393         rootViewRect = [m_contentView accessibilityConvertRectToSceneReferenceCoordinates:rootViewRect];
394     return enclosingIntRect(rootViewRect);
395 }
396     
397 void PageClientImpl::doneWithKeyEvent(const NativeWebKeyboardEvent& event, bool eventWasHandled)
398 {
399     [m_contentView _didHandleKeyEvent:event.nativeEvent() eventWasHandled:eventWasHandled];
400 }
401
402 #if ENABLE(TOUCH_EVENTS)
403 void PageClientImpl::doneWithTouchEvent(const NativeWebTouchEvent& nativeWebtouchEvent, bool eventHandled)
404 {
405     [m_contentView _webTouchEvent:nativeWebtouchEvent preventsNativeGestures:eventHandled];
406 }
407 #endif
408
409 RefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy(WebPageProxy&)
410 {
411     return nullptr;
412 }
413
414 void PageClientImpl::setTextIndicator(Ref<TextIndicator> textIndicator, TextIndicatorWindowLifetime)
415 {
416 }
417
418 void PageClientImpl::clearTextIndicator(TextIndicatorWindowDismissalAnimation)
419 {
420 }
421
422 void PageClientImpl::setTextIndicatorAnimationProgress(float)
423 {
424 }
425
426 void PageClientImpl::enterAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext)
427 {
428 }
429
430 void PageClientImpl::showSafeBrowsingWarning(const SafeBrowsingWarning& warning, CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, URL>&&)>&& completionHandler)
431 {
432     if (auto webView = m_webView.get())
433         [webView _showSafeBrowsingWarning:warning completionHandler:WTFMove(completionHandler)];
434     else
435         completionHandler(ContinueUnsafeLoad::No);
436 }
437
438 void PageClientImpl::clearSafeBrowsingWarning()
439 {
440     [m_webView _clearSafeBrowsingWarning];
441 }
442
443 void PageClientImpl::clearSafeBrowsingWarningIfForMainFrameNavigation()
444 {
445     [m_webView _clearSafeBrowsingWarningIfForMainFrameNavigation];
446 }
447
448 void PageClientImpl::exitAcceleratedCompositingMode()
449 {
450     notImplemented();
451 }
452
453 void PageClientImpl::updateAcceleratedCompositingMode(const LayerTreeContext&)
454 {
455 }
456
457 void PageClientImpl::didPerformDictionaryLookup(const DictionaryPopupInfo& dictionaryPopupInfo)
458 {
459 #if ENABLE(REVEAL)
460     DictionaryLookup::showPopup(dictionaryPopupInfo, m_contentView, nullptr);
461 #else
462     UNUSED_PARAM(dictionaryPopupInfo);
463 #endif // ENABLE(REVEAL)
464 }
465
466 void PageClientImpl::setRemoteLayerTreeRootNode(RemoteLayerTreeNode* rootNode)
467 {
468     [m_contentView _setAcceleratedCompositingRootView:rootNode ? rootNode->uiView() : nil];
469 }
470
471 CALayer *PageClientImpl::acceleratedCompositingRootLayer() const
472 {
473     notImplemented();
474     return nullptr;
475 }
476
477 RefPtr<ViewSnapshot> PageClientImpl::takeViewSnapshot()
478 {
479     return [m_webView _takeViewSnapshot];
480 }
481
482 void PageClientImpl::wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent& event)
483 {
484     notImplemented();
485 }
486
487 void PageClientImpl::commitPotentialTapFailed()
488 {
489     [m_contentView _commitPotentialTapFailed];
490 }
491
492 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)
493 {
494     [m_contentView _didGetTapHighlightForRequest:requestID color:color quads:highlightedQuads topLeftRadius:topLeftRadius topRightRadius:topRightRadius bottomLeftRadius:bottomLeftRadius bottomRightRadius:bottomRightRadius nodeHasBuiltInClickHandling:nodeHasBuiltInClickHandling];
495 }
496
497 void PageClientImpl::didCommitLayerTree(const RemoteLayerTreeTransaction& layerTreeTransaction)
498 {
499     [m_contentView _didCommitLayerTree:layerTreeTransaction];
500 }
501
502 void PageClientImpl::layerTreeCommitComplete()
503 {
504     [m_contentView _layerTreeCommitComplete];
505 }
506
507 void PageClientImpl::couldNotRestorePageState()
508 {
509     [m_webView _couldNotRestorePageState];
510 }
511
512 void PageClientImpl::restorePageState(Optional<WebCore::FloatPoint> scrollPosition, const WebCore::FloatPoint& scrollOrigin, const WebCore::FloatBoxExtent& obscuredInsetsOnSave, double scale)
513 {
514     [m_webView _restorePageScrollPosition:scrollPosition scrollOrigin:scrollOrigin previousObscuredInset:obscuredInsetsOnSave scale:scale];
515 }
516
517 void PageClientImpl::restorePageCenterAndScale(Optional<WebCore::FloatPoint> center, double scale)
518 {
519     [m_webView _restorePageStateToUnobscuredCenter:center scale:scale];
520 }
521
522 void PageClientImpl::elementDidFocus(const FocusedElementInformation& nodeInformation, bool userIsInteracting, bool blurPreviousNode, bool changingActivityState, API::Object* userData)
523 {
524     MESSAGE_CHECK(!userData || userData->type() == API::Object::Type::Data);
525
526     NSObject <NSSecureCoding> *userObject = nil;
527     if (API::Data* data = static_cast<API::Data*>(userData)) {
528         auto nsData = adoptNS([[NSData alloc] initWithBytesNoCopy:const_cast<void*>(static_cast<const void*>(data->bytes())) length:data->size() freeWhenDone:NO]);
529         auto unarchiver = secureUnarchiverFromData(nsData.get());
530         @try {
531             userObject = [unarchiver decodeObjectOfClass:[NSObject class] forKey:@"userObject"];
532         } @catch (NSException *exception) {
533             LOG_ERROR("Failed to decode user data: %@", exception);
534         }
535     }
536
537     [m_contentView _elementDidFocus:nodeInformation userIsInteracting:userIsInteracting blurPreviousNode:blurPreviousNode changingActivityState:changingActivityState userObject:userObject];
538 }
539
540 bool PageClientImpl::isFocusingElement()
541 {
542     return [m_contentView isFocusingElement];
543 }
544
545 void PageClientImpl::elementDidBlur()
546 {
547     [m_contentView _elementDidBlur];
548 }
549
550 void PageClientImpl::focusedElementDidChangeInputMode(WebCore::InputMode mode)
551 {
552     [m_contentView _didUpdateInputMode:mode];
553 }
554
555 void PageClientImpl::didReceiveEditorStateUpdateAfterFocus()
556 {
557     [m_contentView _didReceiveEditorStateUpdateAfterFocus];
558 }
559
560 void PageClientImpl::showPlaybackTargetPicker(bool hasVideo, const IntRect& elementRect, WebCore::RouteSharingPolicy policy, const String& contextUID)
561 {
562     [m_contentView _showPlaybackTargetPicker:hasVideo fromRect:elementRect routeSharingPolicy:policy routingContextUID:contextUID];
563 }
564
565 bool PageClientImpl::handleRunOpenPanel(WebPageProxy*, WebFrameProxy*, API::OpenPanelParameters* parameters, WebOpenPanelResultListenerProxy* listener)
566 {
567     [m_contentView _showRunOpenPanel:parameters resultListener:listener];
568     return true;
569 }
570
571 bool PageClientImpl::showShareSheet(const ShareDataWithParsedURL& shareData, WTF::CompletionHandler<void(bool)>&& completionHandler)
572 {
573     [m_contentView _showShareSheet:shareData completionHandler:WTFMove(completionHandler)];
574     return true;
575 }
576
577 void PageClientImpl::showInspectorHighlight(const WebCore::Highlight& highlight)
578 {
579     [m_contentView _showInspectorHighlight:highlight];
580 }
581
582 void PageClientImpl::hideInspectorHighlight()
583 {
584     [m_contentView _hideInspectorHighlight];
585 }
586
587 void PageClientImpl::showInspectorIndication()
588 {
589     [m_contentView setShowingInspectorIndication:YES];
590 }
591
592 void PageClientImpl::hideInspectorIndication()
593 {
594     [m_contentView setShowingInspectorIndication:NO];
595 }
596
597 void PageClientImpl::enableInspectorNodeSearch()
598 {
599     [m_contentView _enableInspectorNodeSearch];
600 }
601
602 void PageClientImpl::disableInspectorNodeSearch()
603 {
604     [m_contentView _disableInspectorNodeSearch];
605 }
606
607 #if ENABLE(FULLSCREEN_API)
608
609 WebFullScreenManagerProxyClient& PageClientImpl::fullScreenManagerProxyClient()
610 {
611     return *this;
612 }
613
614 // WebFullScreenManagerProxyClient
615
616 void PageClientImpl::closeFullScreenManager()
617 {
618     [m_webView closeFullScreenWindowController];
619 }
620
621 bool PageClientImpl::isFullScreen()
622 {
623     if (![m_webView hasFullScreenWindowController])
624         return false;
625
626     return [m_webView fullScreenWindowController].isFullScreen;
627 }
628
629 void PageClientImpl::enterFullScreen()
630 {
631     [[m_webView fullScreenWindowController] enterFullScreen];
632 }
633
634 void PageClientImpl::exitFullScreen()
635 {
636     [[m_webView fullScreenWindowController] exitFullScreen];
637 }
638
639 void PageClientImpl::beganEnterFullScreen(const IntRect& initialFrame, const IntRect& finalFrame)
640 {
641     [[m_webView fullScreenWindowController] beganEnterFullScreenWithInitialFrame:initialFrame finalFrame:finalFrame];
642 }
643
644 void PageClientImpl::beganExitFullScreen(const IntRect& initialFrame, const IntRect& finalFrame)
645 {
646     [[m_webView fullScreenWindowController] beganExitFullScreenWithInitialFrame:initialFrame finalFrame:finalFrame];
647 }
648
649 #endif // ENABLE(FULLSCREEN_API)
650
651 void PageClientImpl::didFinishLoadingDataForCustomContentProvider(const String& suggestedFilename, const IPC::DataReference& dataReference)
652 {
653     RetainPtr<NSData> data = adoptNS([[NSData alloc] initWithBytes:dataReference.data() length:dataReference.size()]);
654     [m_webView _didFinishLoadingDataForCustomContentProviderWithSuggestedFilename:suggestedFilename data:data.get()];
655 }
656
657 void PageClientImpl::scrollingNodeScrollViewWillStartPanGesture()
658 {
659     [m_contentView scrollViewWillStartPanOrPinchGesture];
660 }
661
662 void PageClientImpl::scrollingNodeScrollViewDidScroll()
663 {
664     [m_contentView _didScroll];
665 }
666
667 void PageClientImpl::scrollingNodeScrollWillStartScroll()
668 {
669     [m_contentView _scrollingNodeScrollingWillBegin];
670 }
671
672 void PageClientImpl::scrollingNodeScrollDidEndScroll()
673 {
674     [m_contentView _scrollingNodeScrollingDidEnd];
675 }
676
677 Vector<String> PageClientImpl::mimeTypesWithCustomContentProviders()
678 {
679     return [m_webView _contentProviderRegistry]._mimeTypesWithCustomContentProviders;
680 }
681
682 void PageClientImpl::navigationGestureDidBegin()
683 {
684     [m_webView _navigationGestureDidBegin];
685     NavigationState::fromWebPage(*m_webView.get()->_page).navigationGestureDidBegin();
686 }
687
688 void PageClientImpl::navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem& item)
689 {
690     NavigationState::fromWebPage(*m_webView.get()->_page).navigationGestureWillEnd(willNavigate, item);
691 }
692
693 void PageClientImpl::navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem& item)
694 {
695     NavigationState::fromWebPage(*m_webView.get()->_page).navigationGestureDidEnd(willNavigate, item);
696     [m_webView _navigationGestureDidEnd];
697 }
698
699 void PageClientImpl::navigationGestureDidEnd()
700 {
701     [m_webView _navigationGestureDidEnd];
702 }
703
704 void PageClientImpl::willRecordNavigationSnapshot(WebBackForwardListItem& item)
705 {
706     NavigationState::fromWebPage(*m_webView.get()->_page).willRecordNavigationSnapshot(item);
707 }
708
709 void PageClientImpl::didRemoveNavigationGestureSnapshot()
710 {
711     NavigationState::fromWebPage(*m_webView.get()->_page).navigationGestureSnapshotWasRemoved();
712 }
713
714 void PageClientImpl::didFirstVisuallyNonEmptyLayoutForMainFrame()
715 {
716 }
717
718 void PageClientImpl::didFinishLoadForMainFrame()
719 {
720     [m_webView _didFinishLoadForMainFrame];
721 }
722
723 void PageClientImpl::didFailLoadForMainFrame()
724 {
725     [m_webView _didFailLoadForMainFrame];
726 }
727
728 void PageClientImpl::didSameDocumentNavigationForMainFrame(SameDocumentNavigationType navigationType)
729 {
730     [m_webView _didSameDocumentNavigationForMainFrame:navigationType];
731 }
732
733 void PageClientImpl::didChangeBackgroundColor()
734 {
735     [m_webView _updateScrollViewBackground];
736 }
737
738 void PageClientImpl::videoControlsManagerDidChange()
739 {
740     [m_webView _videoControlsManagerDidChange];
741 }
742
743 void PageClientImpl::refView()
744 {
745     [m_contentView retain];
746     [m_webView retain];
747 }
748
749 void PageClientImpl::derefView()
750 {
751     [m_contentView release];
752     [m_webView release];
753 }
754
755 void PageClientImpl::didRestoreScrollPosition()
756 {
757 }
758
759 WebCore::UserInterfaceLayoutDirection PageClientImpl::userInterfaceLayoutDirection()
760 {
761     if (!m_webView)
762         return WebCore::UserInterfaceLayoutDirection::LTR;
763     return ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute:[m_webView semanticContentAttribute]] == UIUserInterfaceLayoutDirectionLeftToRight) ? WebCore::UserInterfaceLayoutDirection::LTR : WebCore::UserInterfaceLayoutDirection::RTL;
764 }
765
766 Ref<ValidationBubble> PageClientImpl::createValidationBubble(const String& message, const ValidationBubble::Settings& settings)
767 {
768     return ValidationBubble::create(m_contentView, message, settings);
769 }
770
771 #if ENABLE(INPUT_TYPE_COLOR)
772 RefPtr<WebColorPicker> PageClientImpl::createColorPicker(WebPageProxy*, const WebCore::Color& initialColor, const WebCore::IntRect&, Vector<WebCore::Color>&&)
773 {
774     return nullptr;
775 }
776 #endif
777
778 #if ENABLE(DATALIST_ELEMENT)
779 RefPtr<WebDataListSuggestionsDropdown> PageClientImpl::createDataListSuggestionsDropdown(WebPageProxy& page)
780 {
781     return WebDataListSuggestionsDropdownIOS::create(page, m_contentView);
782 }
783 #endif
784
785 #if ENABLE(DATA_INTERACTION)
786 void PageClientImpl::didPerformDragOperation(bool handled)
787 {
788     [m_contentView _didPerformDragOperation:handled];
789 }
790
791 void PageClientImpl::didHandleDragStartRequest(bool started)
792 {
793     [m_contentView _didHandleDragStartRequest:started];
794 }
795
796 void PageClientImpl::didHandleAdditionalDragItemsRequest(bool added)
797 {
798     [m_contentView _didHandleAdditionalDragItemsRequest:added];
799 }
800
801 void PageClientImpl::startDrag(const DragItem& item, const ShareableBitmap::Handle& image)
802 {
803     [m_contentView _startDrag:ShareableBitmap::create(image)->makeCGImageCopy() item:item];
804 }
805
806 void PageClientImpl::didConcludeEditDrag(Optional<TextIndicatorData> data)
807 {
808     [m_contentView _didConcludeEditDrag:data];
809 }
810
811 void PageClientImpl::didChangeDragCaretRect(const IntRect& previousCaretRect, const IntRect& caretRect)
812 {
813     [m_contentView _didChangeDragCaretRect:previousCaretRect currentRect:caretRect];
814 }
815 #endif
816
817 #if USE(QUICK_LOOK)
818 void PageClientImpl::requestPasswordForQuickLookDocument(const String& fileName, WTF::Function<void(const String&)>&& completionHandler)
819 {
820     auto passwordHandler = makeBlockPtr([completionHandler = WTFMove(completionHandler)](NSString *password) {
821         completionHandler(password);
822     });
823
824     if (WKPasswordView *passwordView = [m_webView _passwordView]) {
825         ASSERT(fileName == String { passwordView.documentName });
826         [passwordView showPasswordFailureAlert];
827         passwordView.userDidEnterPassword = passwordHandler.get();
828         return;
829     }
830
831     [m_webView _showPasswordViewWithDocumentName:fileName passwordHandler:passwordHandler.get()];
832     NavigationState::fromWebPage(*m_webView.get()->_page).didRequestPasswordForQuickLookDocument();
833 }
834 #endif
835
836 #if HAVE(PENCILKIT)
837 RetainPtr<WKDrawingView> PageClientImpl::createDrawingView(WebCore::GraphicsLayer::EmbeddedViewID embeddedViewID)
838 {
839     return adoptNS([[WKDrawingView alloc] initWithEmbeddedViewID:embeddedViewID contentView:m_contentView]);
840 }
841 #endif
842
843 } // namespace WebKit
844
845 #endif // PLATFORM(IOS_FAMILY)
846
847 #undef MESSAGE_CHECK