b5a0a508bc996d3c9a97f93af3ea3f925097f665
[WebKit-https.git] / Source / WebKit / UIProcess / Cocoa / UIDelegate.mm
1 /*
2  * Copyright (C) 2014-2018 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 "UIDelegate.h"
28
29 #import "APIFrameInfo.h"
30 #import "APIHitTestResult.h"
31 #import "CompletionHandlerCallChecker.h"
32 #import "MediaCaptureUtilities.h"
33 #import "NativeWebWheelEvent.h"
34 #import "NavigationActionData.h"
35 #import "UserMediaPermissionCheckProxy.h"
36 #import "UserMediaPermissionRequestProxy.h"
37 #import "WKFrameInfoInternal.h"
38 #import "WKNSData.h"
39 #import "WKNSDictionary.h"
40 #import "WKNavigationActionInternal.h"
41 #import "WKOpenPanelParametersInternal.h"
42 #import "WKSecurityOriginInternal.h"
43 #import "WKUIDelegatePrivate.h"
44 #import "WKWebViewConfigurationInternal.h"
45 #import "WKWebViewInternal.h"
46 #import "WKWindowFeaturesInternal.h"
47 #import "WebEventFactory.h"
48 #import "WebOpenPanelResultListenerProxy.h"
49 #import "WebProcessProxy.h"
50 #import "_WKContextMenuElementInfo.h"
51 #import "_WKFrameHandleInternal.h"
52 #import "_WKHitTestResultInternal.h"
53 #import <WebCore/FontAttributes.h>
54 #import <WebCore/SecurityOriginData.h>
55 #import <wtf/BlockPtr.h>
56 #import <wtf/URL.h>
57
58 #if HAVE(AUTHORIZATION_STATUS_FOR_MEDIA_TYPE)
59 #import <AVFoundation/AVCaptureDevice.h>
60 #import <AVFoundation/AVMediaFormat.h>
61 #import <wtf/SoftLinking.h>
62
63 SOFT_LINK_FRAMEWORK(AVFoundation);
64 SOFT_LINK_CLASS(AVFoundation, AVCaptureDevice);
65 SOFT_LINK_CONSTANT(AVFoundation, AVMediaTypeAudio, NSString *);
66 SOFT_LINK_CONSTANT(AVFoundation, AVMediaTypeVideo, NSString *);
67 #endif
68
69 namespace WebKit {
70
71 UIDelegate::UIDelegate(WKWebView *webView)
72     : m_webView(webView)
73 {
74 }
75
76 UIDelegate::~UIDelegate()
77 {
78 }
79
80 #if ENABLE(CONTEXT_MENUS)
81 std::unique_ptr<API::ContextMenuClient> UIDelegate::createContextMenuClient()
82 {
83     return std::make_unique<ContextMenuClient>(*this);
84 }
85 #endif
86
87 std::unique_ptr<API::UIClient> UIDelegate::createUIClient()
88 {
89     return std::make_unique<UIClient>(*this);
90 }
91
92 RetainPtr<id <WKUIDelegate> > UIDelegate::delegate()
93 {
94     return m_delegate.get();
95 }
96
97 void UIDelegate::setDelegate(id <WKUIDelegate> delegate)
98 {
99     m_delegate = delegate;
100
101     m_delegateMethods.webViewCreateWebViewWithConfigurationForNavigationActionWindowFeatures = [delegate respondsToSelector:@selector(webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:)];
102     m_delegateMethods.webViewCreateWebViewWithConfigurationForNavigationActionWindowFeaturesAsync = [delegate respondsToSelector:@selector(_webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:completionHandler:)];
103     m_delegateMethods.webViewRunJavaScriptAlertPanelWithMessageInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:)];
104     m_delegateMethods.webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:completionHandler:)];
105     m_delegateMethods.webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:completionHandler:)];
106     m_delegateMethods.webViewRequestStorageAccessPanelForTopPrivatelyControlledDomainUnderFirstPartyTopPrivatelyControlledDomainCompletionHandler = [delegate respondsToSelector:@selector(_webView:requestStorageAccessPanelForDomain:underCurrentDomain:completionHandler:)];
107     m_delegateMethods.webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(_webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:)];
108     m_delegateMethods.webViewRequestGeolocationPermissionForFrameDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestGeolocationPermissionForFrame:decisionHandler:)];
109     m_delegateMethods.webViewDidResignInputElementStrongPasswordAppearanceWithUserInfo = [delegate respondsToSelector:@selector(_webView:didResignInputElementStrongPasswordAppearanceWithUserInfo:)];
110     m_delegateMethods.webViewTakeFocus = [delegate respondsToSelector:@selector(_webView:takeFocus:)];
111
112 #if PLATFORM(MAC)
113     m_delegateMethods.showWebView = [delegate respondsToSelector:@selector(_showWebView:)];
114     m_delegateMethods.focusWebView = [delegate respondsToSelector:@selector(_focusWebView:)];
115     m_delegateMethods.unfocusWebView = [delegate respondsToSelector:@selector(_unfocusWebView:)];
116     m_delegateMethods.webViewRunModal = [delegate respondsToSelector:@selector(_webViewRunModal:)];
117     m_delegateMethods.webViewDidScroll = [delegate respondsToSelector:@selector(_webViewDidScroll:)];
118     m_delegateMethods.webViewGetToolbarsAreVisibleWithCompletionHandler = [delegate respondsToSelector:@selector(_webView:getToolbarsAreVisibleWithCompletionHandler:)];
119     m_delegateMethods.webViewDidNotHandleWheelEvent = [delegate respondsToSelector:@selector(_webView:didNotHandleWheelEvent:)];
120     m_delegateMethods.webViewSetResizable = [delegate respondsToSelector:@selector(_webView:setResizable:)];
121     m_delegateMethods.webViewGetWindowFrameWithCompletionHandler = [delegate respondsToSelector:@selector(_webView:getWindowFrameWithCompletionHandler:)];
122     m_delegateMethods.webViewSetWindowFrame = [delegate respondsToSelector:@selector(_webView:setWindowFrame:)];
123     m_delegateMethods.webViewUnavailablePlugInButtonClicked = [delegate respondsToSelector:@selector(_webView:unavailablePlugInButtonClickedWithReason:plugInInfo:)];
124     m_delegateMethods.webViewHandleAutoplayEventWithFlags = [delegate respondsToSelector:@selector(_webView:handleAutoplayEvent:withFlags:)];
125     m_delegateMethods.webViewDidClickAutoFillButtonWithUserInfo = [delegate respondsToSelector:@selector(_webView:didClickAutoFillButtonWithUserInfo:)];
126     m_delegateMethods.webViewDrawHeaderInRectForPageWithTitleURL = [delegate respondsToSelector:@selector(_webView:drawHeaderInRect:forPageWithTitle:URL:)];
127     m_delegateMethods.webViewDrawFooterInRectForPageWithTitleURL = [delegate respondsToSelector:@selector(_webView:drawFooterInRect:forPageWithTitle:URL:)];
128     m_delegateMethods.webViewHeaderHeight = [delegate respondsToSelector:@selector(_webViewHeaderHeight:)];
129     m_delegateMethods.webViewFooterHeight = [delegate respondsToSelector:@selector(_webViewFooterHeight:)];
130     m_delegateMethods.webViewMouseDidMoveOverElementWithFlagsUserInfo = [delegate respondsToSelector:@selector(_webView:mouseDidMoveOverElement:withFlags:userInfo:)];
131     m_delegateMethods.webViewDidExceedBackgroundResourceLimitWhileInForeground = [delegate respondsToSelector:@selector(_webView:didExceedBackgroundResourceLimitWhileInForeground:)];
132     m_delegateMethods.webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL = [delegate respondsToSelector:@selector(_webView:saveDataToFile:suggestedFilename:mimeType:originatingURL:)];
133     m_delegateMethods.webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:)];
134     m_delegateMethods.webViewRequestNotificationPermissionForSecurityOriginDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:)];
135 #endif
136     m_delegateMethods.webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler = [delegate respondsToSelector:@selector(_webView:decideDatabaseQuotaForSecurityOrigin:currentQuota:currentOriginUsage:currentDatabaseUsage:expectedUsage:decisionHandler:)];
137     m_delegateMethods.webViewDecideDatabaseQuotaForSecurityOriginDatabaseNameDisplayNameCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler = [delegate respondsToSelector:@selector(_webView:decideDatabaseQuotaForSecurityOrigin:databaseName:displayName:currentQuota:currentOriginUsage:currentDatabaseUsage:expectedUsage:decisionHandler:)];
138     m_delegateMethods.webViewDecideWebApplicationCacheQuotaForSecurityOriginCurrentQuotaTotalBytesNeeded = [delegate respondsToSelector:@selector(_webView:decideWebApplicationCacheQuotaForSecurityOrigin:currentQuota:totalBytesNeeded:decisionHandler:)];
139     m_delegateMethods.webViewPrintFrame = [delegate respondsToSelector:@selector(_webView:printFrame:)];
140     m_delegateMethods.webViewDidClose = [delegate respondsToSelector:@selector(webViewDidClose:)];
141     m_delegateMethods.webViewClose = [delegate respondsToSelector:@selector(_webViewClose:)];
142     m_delegateMethods.webViewFullscreenMayReturnToInline = [delegate respondsToSelector:@selector(_webViewFullscreenMayReturnToInline:)];
143     m_delegateMethods.webViewDidEnterFullscreen = [delegate respondsToSelector:@selector(_webViewDidEnterFullscreen:)];
144     m_delegateMethods.webViewDidExitFullscreen = [delegate respondsToSelector:@selector(_webViewDidExitFullscreen:)];
145 #if PLATFORM(IOS_FAMILY)
146 #if HAVE(APP_LINKS)
147     m_delegateMethods.webViewShouldIncludeAppLinkActionsForElement = [delegate respondsToSelector:@selector(_webView:shouldIncludeAppLinkActionsForElement:)];
148 #endif
149     m_delegateMethods.webViewActionsForElementDefaultActions = [delegate respondsToSelector:@selector(_webView:actionsForElement:defaultActions:)];
150     m_delegateMethods.webViewDidNotHandleTapAsClickAtPoint = [delegate respondsToSelector:@selector(_webView:didNotHandleTapAsClickAtPoint:)];
151     m_delegateMethods.presentingViewControllerForWebView = [delegate respondsToSelector:@selector(_presentingViewControllerForWebView:)];
152 #endif
153     m_delegateMethods.webViewRequestMediaCaptureAuthorizationForFrameDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestUserMediaAuthorizationForDevices:url:mainFrameURL:decisionHandler:)] || [delegate respondsToSelector:@selector(_webView:requestMediaCaptureAuthorization:decisionHandler:)];
154     m_delegateMethods.webViewIsMediaCaptureAuthorizedForFrameDecisionHandler = [delegate respondsToSelector:@selector(_webView:checkUserMediaPermissionForURL:mainFrameURL:frameIdentifier:decisionHandler:)] || [delegate respondsToSelector:@selector(_webView:includeSensitiveMediaDeviceDetails:)];
155
156     m_delegateMethods.webViewMediaCaptureStateDidChange = [delegate respondsToSelector:@selector(_webView:mediaCaptureStateDidChange:)];
157     m_delegateMethods.webViewDidChangeFontAttributes = [delegate respondsToSelector:@selector(_webView:didChangeFontAttributes:)];
158     m_delegateMethods.dataDetectionContextForWebView = [delegate respondsToSelector:@selector(_dataDetectionContextForWebView:)];
159     m_delegateMethods.webViewImageOrMediaDocumentSizeChanged = [delegate respondsToSelector:@selector(_webView:imageOrMediaDocumentSizeChanged:)];
160
161 #if ENABLE(POINTER_LOCK)
162     m_delegateMethods.webViewRequestPointerLock = [delegate respondsToSelector:@selector(_webViewRequestPointerLock:)];
163     m_delegateMethods.webViewDidRequestPointerLockCompletionHandler = [delegate respondsToSelector:@selector(_webViewDidRequestPointerLock:completionHandler:)];
164     m_delegateMethods.webViewDidLosePointerLock = [delegate respondsToSelector:@selector(_webViewDidLosePointerLock:)];
165 #endif
166 #if ENABLE(CONTEXT_MENUS)
167     m_delegateMethods.webViewContextMenuForElement = [delegate respondsToSelector:@selector(_webView:contextMenu:forElement:)];
168     m_delegateMethods.webViewContextMenuForElementUserInfo = [delegate respondsToSelector:@selector(_webView:contextMenu:forElement:userInfo:)];
169     m_delegateMethods.webViewGetContextMenuFromProposedMenuForElementUserInfoCompletionHandler = [delegate respondsToSelector:@selector(_webView:getContextMenuFromProposedMenu:forElement:userInfo:completionHandler:)];
170 #endif
171     
172     m_delegateMethods.webViewHasVideoInPictureInPictureDidChange = [delegate respondsToSelector:@selector(_webView:hasVideoInPictureInPictureDidChange:)];
173     m_delegateMethods.webViewDidShowSafeBrowsingWarning = [delegate respondsToSelector:@selector(_webViewDidShowSafeBrowsingWarning:)];
174 }
175
176 #if ENABLE(CONTEXT_MENUS)
177 UIDelegate::ContextMenuClient::ContextMenuClient(UIDelegate& uiDelegate)
178     : m_uiDelegate(uiDelegate)
179 {
180 }
181
182 UIDelegate::ContextMenuClient::~ContextMenuClient()
183 {
184 }
185
186 void UIDelegate::ContextMenuClient::menuFromProposedMenu(WebPageProxy&, NSMenu *menu, const WebHitTestResultData&, API::Object* userInfo, CompletionHandler<void(RetainPtr<NSMenu>&&)>&& completionHandler)
187 {
188     if (!m_uiDelegate.m_delegateMethods.webViewContextMenuForElement
189         && !m_uiDelegate.m_delegateMethods.webViewContextMenuForElementUserInfo
190         && !m_uiDelegate.m_delegateMethods.webViewGetContextMenuFromProposedMenuForElementUserInfoCompletionHandler)
191         return completionHandler(menu);
192
193     auto delegate = m_uiDelegate.m_delegate.get();
194     if (!delegate)
195         return completionHandler(menu);
196
197     auto contextMenuElementInfo = adoptNS([[_WKContextMenuElementInfo alloc] init]);
198
199     if (m_uiDelegate.m_delegateMethods.webViewGetContextMenuFromProposedMenuForElementUserInfoCompletionHandler) {
200         auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:getContextMenuFromProposedMenu:forElement:userInfo:completionHandler:));
201         [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView getContextMenuFromProposedMenu:menu forElement:contextMenuElementInfo.get() userInfo:userInfo ? static_cast<id <NSSecureCoding>>(userInfo->wrapper()) : nil completionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] (NSMenu *menu) mutable {
202             if (checker->completionHandlerHasBeenCalled())
203                 return;
204             checker->didCallCompletionHandler();
205             completionHandler(menu);
206         }).get()];
207         return;
208     }
209     
210     ALLOW_DEPRECATED_DECLARATIONS_BEGIN
211     if (m_uiDelegate.m_delegateMethods.webViewContextMenuForElement)
212         return completionHandler([(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView contextMenu:menu forElement:contextMenuElementInfo.get()]);
213
214     completionHandler([(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView contextMenu:menu forElement:contextMenuElementInfo.get() userInfo:userInfo ? static_cast<id <NSSecureCoding>>(userInfo->wrapper()) : nil]);
215     ALLOW_DEPRECATED_DECLARATIONS_END
216 }
217 #endif
218
219 UIDelegate::UIClient::UIClient(UIDelegate& uiDelegate)
220     : m_uiDelegate(uiDelegate)
221 {
222 }
223
224 UIDelegate::UIClient::~UIClient()
225 {
226 }
227
228 void UIDelegate::UIClient::createNewPage(WebPageProxy& page, Ref<API::FrameInfo>&& sourceFrameInfo, WebCore::ResourceRequest&& request, WebCore::WindowFeatures&& windowFeatures, NavigationActionData&& navigationActionData, CompletionHandler<void(RefPtr<WebPageProxy>&&)>&& completionHandler)
229 {
230     auto delegate = m_uiDelegate.m_delegate.get();
231     ASSERT(delegate);
232
233     auto configuration = adoptNS([m_uiDelegate.m_webView->_configuration copy]);
234     [configuration _setRelatedWebView:m_uiDelegate.m_webView];
235
236     auto userInitiatedActivity = page.process().userInitiatedActivity(navigationActionData.userGestureTokenIdentifier);
237     bool shouldOpenAppLinks = !hostsAreEqual(sourceFrameInfo->request().url(), request.url());
238     auto apiNavigationAction = API::NavigationAction::create(WTFMove(navigationActionData), sourceFrameInfo.ptr(), nullptr, WTF::nullopt, WTFMove(request), URL(), shouldOpenAppLinks, WTFMove(userInitiatedActivity));
239
240     auto apiWindowFeatures = API::WindowFeatures::create(windowFeatures);
241
242     if (m_uiDelegate.m_delegateMethods.webViewCreateWebViewWithConfigurationForNavigationActionWindowFeaturesAsync) {
243         auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:completionHandler:));
244
245         [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView createWebViewWithConfiguration:configuration.get() forNavigationAction:wrapper(apiNavigationAction) windowFeatures:wrapper(apiWindowFeatures) completionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker), relatedWebView = RetainPtr<WKWebView>(m_uiDelegate.m_webView)] (WKWebView *webView) mutable {
246             if (checker->completionHandlerHasBeenCalled())
247                 return;
248             checker->didCallCompletionHandler();
249
250             if (!webView) {
251                 completionHandler(nullptr);
252                 return;
253             }
254
255             if ([webView->_configuration _relatedWebView] != relatedWebView.get())
256                 [NSException raise:NSInternalInconsistencyException format:@"Returned WKWebView was not created with the given configuration."];
257
258             completionHandler(webView->_page.get());
259         }).get()];
260         return;
261     }
262     if (!m_uiDelegate.m_delegateMethods.webViewCreateWebViewWithConfigurationForNavigationActionWindowFeatures)
263         return completionHandler(nullptr);
264
265     RetainPtr<WKWebView> webView = [delegate webView:m_uiDelegate.m_webView createWebViewWithConfiguration:configuration.get() forNavigationAction:wrapper(apiNavigationAction) windowFeatures:wrapper(apiWindowFeatures)];
266     if (!webView)
267         return completionHandler(nullptr);
268
269     if ([webView->_configuration _relatedWebView] != m_uiDelegate.m_webView)
270         [NSException raise:NSInternalInconsistencyException format:@"Returned WKWebView was not created with the given configuration."];
271     completionHandler(webView->_page.get());
272 }
273
274 void UIDelegate::UIClient::runJavaScriptAlert(WebPageProxy*, const WTF::String& message, WebFrameProxy* webFrameProxy, const WebCore::SecurityOriginData& securityOriginData, Function<void()>&& completionHandler)
275 {
276     if (!m_uiDelegate.m_delegateMethods.webViewRunJavaScriptAlertPanelWithMessageInitiatedByFrameCompletionHandler) {
277         completionHandler();
278         return;
279     }
280
281     auto delegate = m_uiDelegate.m_delegate.get();
282     if (!delegate) {
283         completionHandler();
284         return;
285     }
286
287     auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:));
288     [delegate webView:m_uiDelegate.m_webView runJavaScriptAlertPanelWithMessage:message initiatedByFrame:wrapper(API::FrameInfo::create(*webFrameProxy, securityOriginData.securityOrigin())) completionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] {
289         if (checker->completionHandlerHasBeenCalled())
290             return;
291         completionHandler();
292         checker->didCallCompletionHandler();
293     }).get()];
294 }
295
296 void UIDelegate::UIClient::runJavaScriptConfirm(WebPageProxy*, const WTF::String& message, WebFrameProxy* webFrameProxy, const WebCore::SecurityOriginData& securityOriginData, Function<void(bool)>&& completionHandler)
297 {
298     if (!m_uiDelegate.m_delegateMethods.webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler) {
299         completionHandler(false);
300         return;
301     }
302
303     auto delegate = m_uiDelegate.m_delegate.get();
304     if (!delegate) {
305         completionHandler(false);
306         return;
307     }
308
309     auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:completionHandler:));
310     [delegate webView:m_uiDelegate.m_webView runJavaScriptConfirmPanelWithMessage:message initiatedByFrame:wrapper(API::FrameInfo::create(*webFrameProxy, securityOriginData.securityOrigin())) completionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] (BOOL result) mutable {
311         if (checker->completionHandlerHasBeenCalled())
312             return;
313         completionHandler(result);
314         checker->didCallCompletionHandler();
315     }).get()];
316 }
317
318 void UIDelegate::UIClient::runJavaScriptPrompt(WebPageProxy*, const WTF::String& message, const WTF::String& defaultValue, WebFrameProxy* webFrameProxy, const WebCore::SecurityOriginData& securityOriginData, Function<void(const WTF::String&)>&& completionHandler)
319 {
320     if (!m_uiDelegate.m_delegateMethods.webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler) {
321         completionHandler(String());
322         return;
323     }
324
325     auto delegate = m_uiDelegate.m_delegate.get();
326     if (!delegate) {
327         completionHandler(String());
328         return;
329     }
330
331     auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:completionHandler:));
332     [delegate webView:m_uiDelegate.m_webView runJavaScriptTextInputPanelWithPrompt:message defaultText:defaultValue initiatedByFrame:wrapper(API::FrameInfo::create(*webFrameProxy, securityOriginData.securityOrigin())) completionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] (NSString *result) mutable {
333         if (checker->completionHandlerHasBeenCalled())
334             return;
335         completionHandler(result);
336         checker->didCallCompletionHandler();
337     }).get()];
338 }
339
340 void UIDelegate::UIClient::requestStorageAccessConfirm(WebPageProxy&, WebFrameProxy*, const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&& completionHandler)
341 {
342     if (!m_uiDelegate.m_delegateMethods.webViewRequestStorageAccessPanelForTopPrivatelyControlledDomainUnderFirstPartyTopPrivatelyControlledDomainCompletionHandler) {
343         completionHandler(true);
344         return;
345     }
346
347     auto delegate = m_uiDelegate.m_delegate.get();
348     if (!delegate) {
349         completionHandler(true);
350         return;
351     }
352     
353     auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:requestStorageAccessPanelForDomain:underCurrentDomain:completionHandler:));
354     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView requestStorageAccessPanelForDomain:requestingDomain underCurrentDomain:currentDomain completionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] (BOOL result) mutable {
355         if (checker->completionHandlerHasBeenCalled())
356             return;
357         completionHandler(result);
358         checker->didCallCompletionHandler();
359     }).get()];
360 }
361
362 void UIDelegate::UIClient::decidePolicyForGeolocationPermissionRequest(WebKit::WebPageProxy&, WebKit::WebFrameProxy& frame, API::SecurityOrigin& securityOrigin, Function<void(bool)>& completionHandler)
363 {
364     if (!m_uiDelegate.m_delegateMethods.webViewRequestGeolocationPermissionForFrameDecisionHandler)
365         return;
366     
367     auto delegate = m_uiDelegate.m_delegate.get();
368     if (!delegate)
369         return;
370
371     auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:requestGeolocationPermissionForFrame:decisionHandler:));
372     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView requestGeolocationPermissionForFrame:wrapper(API::FrameInfo::create(frame, securityOrigin.securityOrigin())) decisionHandler:makeBlockPtr([completionHandler = std::exchange(completionHandler, nullptr), checker = WTFMove(checker)] (BOOL result) mutable {
373         if (checker->completionHandlerHasBeenCalled())
374             return;
375         checker->didCallCompletionHandler();
376         completionHandler(result);
377     }).get()];
378 }
379
380 void UIDelegate::UIClient::didResignInputElementStrongPasswordAppearance(WebPageProxy&, API::Object* userInfo)
381 {
382     if (!m_uiDelegate.m_delegateMethods.webViewDidResignInputElementStrongPasswordAppearanceWithUserInfo)
383         return;
384
385     auto delegate = m_uiDelegate.m_delegate.get();
386     if (!delegate)
387         return;
388
389     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView didResignInputElementStrongPasswordAppearanceWithUserInfo:userInfo ? static_cast<id <NSSecureCoding>>(userInfo->wrapper()) : nil];
390 }
391
392 bool UIDelegate::UIClient::canRunBeforeUnloadConfirmPanel() const
393 {
394     return m_uiDelegate.m_delegateMethods.webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler;
395 }
396
397 void UIDelegate::UIClient::runBeforeUnloadConfirmPanel(WebPageProxy*, const WTF::String& message, WebFrameProxy* webFrameProxy, const WebCore::SecurityOriginData& securityOriginData, Function<void(bool)>&& completionHandler)
398 {
399     if (!m_uiDelegate.m_delegateMethods.webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler) {
400         completionHandler(false);
401         return;
402     }
403
404     auto delegate = m_uiDelegate.m_delegate.get();
405     if (!delegate) {
406         completionHandler(false);
407         return;
408     }
409
410     auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:));
411     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView runBeforeUnloadConfirmPanelWithMessage:message initiatedByFrame:wrapper(API::FrameInfo::create(*webFrameProxy, securityOriginData.securityOrigin())) completionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] (BOOL result) mutable {
412         if (checker->completionHandlerHasBeenCalled())
413             return;
414         completionHandler(result);
415         checker->didCallCompletionHandler();
416     }).get()];
417 }
418
419 void UIDelegate::UIClient::exceededDatabaseQuota(WebPageProxy*, WebFrameProxy*, API::SecurityOrigin* securityOrigin, const WTF::String& databaseName, const WTF::String& displayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentUsage, unsigned long long expectedUsage, Function<void (unsigned long long)>&& completionHandler)
420 {
421     if (!m_uiDelegate.m_delegateMethods.webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler && !m_uiDelegate.m_delegateMethods.webViewDecideDatabaseQuotaForSecurityOriginDatabaseNameDisplayNameCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler) {
422
423         // Use 50 MB as the default database quota.
424         unsigned long long defaultPerOriginDatabaseQuota = 50 * 1024 * 1024;
425
426         completionHandler(defaultPerOriginDatabaseQuota);
427         return;
428     }
429
430     auto delegate = m_uiDelegate.m_delegate.get();
431     if (!delegate) {
432         completionHandler(currentQuota);
433         return;
434     }
435
436     ASSERT(securityOrigin);
437
438     if (m_uiDelegate.m_delegateMethods.webViewDecideDatabaseQuotaForSecurityOriginDatabaseNameDisplayNameCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler) {
439         auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:decideDatabaseQuotaForSecurityOrigin:databaseName:displayName:currentQuota:currentOriginUsage:currentDatabaseUsage:expectedUsage:decisionHandler:));
440         [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView decideDatabaseQuotaForSecurityOrigin:wrapper(*securityOrigin) databaseName:databaseName displayName:displayName currentQuota:currentQuota currentOriginUsage:currentOriginUsage currentDatabaseUsage:currentUsage expectedUsage:expectedUsage decisionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)](unsigned long long newQuota) {
441             if (checker->completionHandlerHasBeenCalled())
442                 return;
443             checker->didCallCompletionHandler();
444             completionHandler(newQuota);
445         }).get()];
446         return;
447     }
448
449     auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:decideDatabaseQuotaForSecurityOrigin:currentQuota:currentOriginUsage:currentDatabaseUsage:expectedUsage:decisionHandler:));
450     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView decideDatabaseQuotaForSecurityOrigin:wrapper(*securityOrigin) currentQuota:currentQuota currentOriginUsage:currentOriginUsage currentDatabaseUsage:currentUsage expectedUsage:expectedUsage decisionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)](unsigned long long newQuota) {
451         if (checker->completionHandlerHasBeenCalled())
452             return;
453         checker->didCallCompletionHandler();
454         completionHandler(newQuota);
455     }).get()];
456 }
457
458 static inline _WKFocusDirection toWKFocusDirection(WKFocusDirection direction)
459 {
460     switch (direction) {
461     case kWKFocusDirectionBackward:
462         return _WKFocusDirectionBackward;
463     case kWKFocusDirectionForward:
464         return _WKFocusDirectionForward;
465     }
466     ASSERT_NOT_REACHED();
467     return _WKFocusDirectionForward;
468 }
469
470 bool UIDelegate::UIClient::takeFocus(WebPageProxy*, WKFocusDirection direction)
471 {
472     if (!m_uiDelegate.m_delegateMethods.webViewTakeFocus)
473         return false;
474     
475     auto delegate = m_uiDelegate.m_delegate.get();
476     if (!delegate)
477         return false;
478     
479     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView takeFocus:toWKFocusDirection(direction)];
480     return true;
481 }
482
483 #if PLATFORM(MAC)
484 bool UIDelegate::UIClient::canRunModal() const
485 {
486     return m_uiDelegate.m_delegateMethods.webViewRunModal;
487 }
488
489 void UIDelegate::UIClient::runModal(WebPageProxy&)
490 {
491     if (!m_uiDelegate.m_delegateMethods.webViewRunModal)
492         return;
493     
494     auto delegate = m_uiDelegate.m_delegate.get();
495     if (!delegate)
496         return;
497
498     [(id <WKUIDelegatePrivate>)delegate _webViewRunModal:m_uiDelegate.m_webView];
499 }
500
501 float UIDelegate::UIClient::headerHeight(WebPageProxy&, WebFrameProxy& webFrameProxy)
502 {
503     if (!m_uiDelegate.m_delegateMethods.webViewHeaderHeight)
504         return 0;
505     
506     auto delegate = m_uiDelegate.m_delegate.get();
507     if (!delegate)
508         return 0;
509     
510     return [(id <WKUIDelegatePrivate>)delegate _webViewHeaderHeight:m_uiDelegate.m_webView];
511 }
512
513 float UIDelegate::UIClient::footerHeight(WebPageProxy&, WebFrameProxy&)
514 {
515     if (!m_uiDelegate.m_delegateMethods.webViewFooterHeight)
516         return 0;
517     
518     auto delegate = m_uiDelegate.m_delegate.get();
519     if (!delegate)
520         return 0;
521     
522     return [(id <WKUIDelegatePrivate>)delegate _webViewFooterHeight:m_uiDelegate.m_webView];
523 }
524
525 void UIDelegate::UIClient::drawHeader(WebPageProxy&, WebFrameProxy& frame, WebCore::FloatRect&& rect)
526 {
527     if (!m_uiDelegate.m_delegateMethods.webViewDrawHeaderInRectForPageWithTitleURL)
528         return;
529     
530     auto delegate = m_uiDelegate.m_delegate.get();
531     if (!delegate)
532         return;
533     
534     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView drawHeaderInRect:rect forPageWithTitle:frame.title() URL:frame.url()];
535 }
536
537 void UIDelegate::UIClient::drawFooter(WebPageProxy&, WebFrameProxy& frame, WebCore::FloatRect&& rect)
538 {
539     if (!m_uiDelegate.m_delegateMethods.webViewDrawFooterInRectForPageWithTitleURL)
540         return;
541     
542     auto delegate = m_uiDelegate.m_delegate.get();
543     if (!delegate)
544         return;
545     
546     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView drawFooterInRect:rect forPageWithTitle:frame.title() URL:frame.url()];
547 }
548
549 void UIDelegate::UIClient::pageDidScroll(WebPageProxy*)
550 {
551     if (!m_uiDelegate.m_delegateMethods.webViewDidScroll)
552         return;
553     
554     auto delegate = m_uiDelegate.m_delegate.get();
555     if (!delegate)
556         return;
557     
558     [(id <WKUIDelegatePrivate>)delegate _webViewDidScroll:m_uiDelegate.m_webView];
559 }
560
561 void UIDelegate::UIClient::focus(WebPageProxy*)
562 {
563     if (!m_uiDelegate.m_delegateMethods.focusWebView)
564         return;
565     
566     auto delegate = m_uiDelegate.m_delegate.get();
567     if (!delegate)
568         return;
569     
570     [(id <WKUIDelegatePrivate>)delegate _focusWebView:m_uiDelegate.m_webView];
571 }
572
573 void UIDelegate::UIClient::unfocus(WebPageProxy*)
574 {
575     if (!m_uiDelegate.m_delegateMethods.unfocusWebView)
576         return;
577     
578     auto delegate = m_uiDelegate.m_delegate.get();
579     if (!delegate)
580         return;
581     
582     [(id <WKUIDelegatePrivate>)delegate _unfocusWebView:m_uiDelegate.m_webView];
583 }
584
585 static _WKPlugInUnavailabilityReason toWKPlugInUnavailabilityReason(WKPluginUnavailabilityReason reason)
586 {
587     switch (reason) {
588     case kWKPluginUnavailabilityReasonPluginMissing:
589         return _WKPlugInUnavailabilityReasonPluginMissing;
590     case kWKPluginUnavailabilityReasonPluginCrashed:
591         return _WKPlugInUnavailabilityReasonPluginCrashed;
592     case kWKPluginUnavailabilityReasonInsecurePluginVersion:
593         return _WKPlugInUnavailabilityReasonInsecurePluginVersion;
594     }
595     ASSERT_NOT_REACHED();
596     return _WKPlugInUnavailabilityReasonPluginMissing;
597 }
598     
599 void UIDelegate::UIClient::unavailablePluginButtonClicked(WebPageProxy&, WKPluginUnavailabilityReason reason, API::Dictionary& plugInInfo)
600 {
601     if (!m_uiDelegate.m_delegateMethods.webViewUnavailablePlugInButtonClicked)
602         return;
603     
604     auto delegate = m_uiDelegate.m_delegate.get();
605     if (!delegate)
606         return;
607
608     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView unavailablePlugInButtonClickedWithReason:toWKPlugInUnavailabilityReason(reason) plugInInfo:wrapper(plugInInfo)];
609 }
610     
611 static _WKResourceLimit toWKResourceLimit(WKResourceLimit limit)
612 {
613     switch (limit) {
614     case kWKResourceLimitMemory:
615         return _WKResourceLimitMemory;
616     case kWKResourceLimitCPU:
617         return _WKResourceLimitCPU;
618     }
619     ASSERT_NOT_REACHED();
620     return _WKResourceLimitMemory;
621 }
622
623 void UIDelegate::UIClient::didExceedBackgroundResourceLimitWhileInForeground(WebPageProxy&, WKResourceLimit limit)
624 {
625     if (!m_uiDelegate.m_delegateMethods.webViewDidExceedBackgroundResourceLimitWhileInForeground)
626         return;
627     
628     auto delegate = m_uiDelegate.m_delegate.get();
629     if (!delegate)
630         return;
631     
632     [static_cast<id <WKUIDelegatePrivate>>(delegate) _webView:m_uiDelegate.m_webView didExceedBackgroundResourceLimitWhileInForeground:toWKResourceLimit(limit)];
633 }
634
635 void UIDelegate::UIClient::didNotHandleWheelEvent(WebPageProxy*, const NativeWebWheelEvent& event)
636 {
637     if (!m_uiDelegate.m_delegateMethods.webViewDidNotHandleWheelEvent)
638         return;
639     
640     auto delegate = m_uiDelegate.m_delegate.get();
641     if (!delegate)
642         return;
643     
644     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView didNotHandleWheelEvent:event.nativeEvent()];
645 }
646
647 void UIDelegate::UIClient::setIsResizable(WebKit::WebPageProxy&, bool resizable)
648 {
649     if (!m_uiDelegate.m_delegateMethods.webViewSetResizable)
650         return;
651     
652     auto delegate = m_uiDelegate.m_delegate.get();
653     if (!delegate)
654         return;
655     
656     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView setResizable:resizable];
657 }
658
659 void UIDelegate::UIClient::setWindowFrame(WebKit::WebPageProxy&, const WebCore::FloatRect& frame)
660 {
661     if (!m_uiDelegate.m_delegateMethods.webViewSetWindowFrame)
662         return;
663     
664     auto delegate = m_uiDelegate.m_delegate.get();
665     if (!delegate)
666         return;
667     
668     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView setWindowFrame:frame];
669 }
670
671 void UIDelegate::UIClient::windowFrame(WebKit::WebPageProxy&, Function<void(WebCore::FloatRect)>&& completionHandler)
672 {
673     if (!m_uiDelegate.m_delegateMethods.webViewGetWindowFrameWithCompletionHandler)
674         return completionHandler({ });
675     
676     auto delegate = m_uiDelegate.m_delegate.get();
677     if (!delegate)
678         return completionHandler({ });
679     
680     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView getWindowFrameWithCompletionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:getWindowFrameWithCompletionHandler:))](CGRect frame) {
681         if (checker->completionHandlerHasBeenCalled())
682             return;
683         checker->didCallCompletionHandler();
684         completionHandler(frame);
685     }).get()];
686 }
687
688 void UIDelegate::UIClient::mouseDidMoveOverElement(WebPageProxy&, const WebHitTestResultData& data, OptionSet<WebEvent::Modifier> modifiers, API::Object* userInfo)
689 {
690     if (!m_uiDelegate.m_delegateMethods.webViewMouseDidMoveOverElementWithFlagsUserInfo)
691         return;
692
693     auto delegate = m_uiDelegate.m_delegate.get();
694     if (!delegate)
695         return;
696
697     auto apiHitTestResult = API::HitTestResult::create(data);
698     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView mouseDidMoveOverElement:wrapper(apiHitTestResult.get()) withFlags:WebEventFactory::toNSEventModifierFlags(modifiers) userInfo:userInfo ? static_cast<id <NSSecureCoding>>(userInfo->wrapper()) : nil];
699 }
700
701 static _WKAutoplayEventFlags toWKAutoplayEventFlags(OptionSet<WebCore::AutoplayEventFlags> flags)
702 {
703     _WKAutoplayEventFlags wkFlags = _WKAutoplayEventFlagsNone;
704     if (flags.contains(WebCore::AutoplayEventFlags::HasAudio))
705         wkFlags |= _WKAutoplayEventFlagsHasAudio;
706     if (flags.contains(WebCore::AutoplayEventFlags::PlaybackWasPrevented))
707         wkFlags |= _WKAutoplayEventFlagsPlaybackWasPrevented;
708     if (flags.contains(WebCore::AutoplayEventFlags::MediaIsMainContent))
709         wkFlags |= _WKAutoplayEventFlagsMediaIsMainContent;
710     
711     return wkFlags;
712 }
713
714 static _WKAutoplayEvent toWKAutoplayEvent(WebCore::AutoplayEvent event)
715 {
716     switch (event) {
717     case WebCore::AutoplayEvent::DidPreventMediaFromPlaying:
718         return _WKAutoplayEventDidPreventFromAutoplaying;
719     case WebCore::AutoplayEvent::DidPlayMediaWithUserGesture:
720         return _WKAutoplayEventDidPlayMediaWithUserGesture;
721     case WebCore::AutoplayEvent::DidAutoplayMediaPastThresholdWithoutUserInterference:
722         return _WKAutoplayEventDidAutoplayMediaPastThresholdWithoutUserInterference;
723     case WebCore::AutoplayEvent::UserDidInterfereWithPlayback:
724         return _WKAutoplayEventUserDidInterfereWithPlayback;
725     }
726     ASSERT_NOT_REACHED();
727     return _WKAutoplayEventDidPlayMediaWithUserGesture;
728 }
729
730 void UIDelegate::UIClient::toolbarsAreVisible(WebPageProxy&, Function<void(bool)>&& completionHandler)
731 {
732     if (!m_uiDelegate.m_delegateMethods.webViewGetToolbarsAreVisibleWithCompletionHandler)
733         return completionHandler(true);
734     
735     auto delegate = m_uiDelegate.m_delegate.get();
736     if (!delegate)
737         return completionHandler(true);
738     
739     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView getToolbarsAreVisibleWithCompletionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:getToolbarsAreVisibleWithCompletionHandler:))](BOOL visible) {
740         if (checker->completionHandlerHasBeenCalled())
741             return;
742         checker->didCallCompletionHandler();
743         completionHandler(visible);
744     }).get()];
745 }
746
747 void UIDelegate::UIClient::didClickAutoFillButton(WebPageProxy&, API::Object* userInfo)
748 {
749     if (!m_uiDelegate.m_delegateMethods.webViewDidClickAutoFillButtonWithUserInfo)
750         return;
751     
752     auto delegate = m_uiDelegate.m_delegate.get();
753     if (!delegate)
754         return;
755     
756     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView didClickAutoFillButtonWithUserInfo:userInfo ? static_cast<id <NSSecureCoding>>(userInfo->wrapper()) : nil];
757 }
758
759 void UIDelegate::UIClient::handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent event, OptionSet<WebCore::AutoplayEventFlags> flags)
760 {
761     if (!m_uiDelegate.m_delegateMethods.webViewHandleAutoplayEventWithFlags)
762         return;
763     
764     auto delegate = m_uiDelegate.m_delegate.get();
765     if (!delegate)
766         return;
767     
768     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView handleAutoplayEvent:toWKAutoplayEvent(event) withFlags:toWKAutoplayEventFlags(flags)];
769 }
770
771 void UIDelegate::UIClient::showPage(WebPageProxy*)
772 {
773     if (!m_uiDelegate.m_delegateMethods.showWebView)
774         return;
775
776     auto delegate = m_uiDelegate.m_delegate.get();
777     if (!delegate)
778         return;
779     
780     [(id <WKUIDelegatePrivate>)delegate _showWebView:m_uiDelegate.m_webView];
781 }
782     
783 void UIDelegate::UIClient::saveDataToFileInDownloadsFolder(WebPageProxy*, const WTF::String& suggestedFilename, const WTF::String& mimeType, const URL& originatingURL, API::Data& data)
784 {
785     if (!m_uiDelegate.m_delegateMethods.webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL)
786         return;
787     
788     auto delegate = m_uiDelegate.m_delegate.get();
789     if (!delegate)
790         return;
791
792     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView saveDataToFile:wrapper(data) suggestedFilename:suggestedFilename mimeType:mimeType originatingURL:originatingURL];
793 }
794
795 void UIDelegate::UIClient::decidePolicyForNotificationPermissionRequest(WebKit::WebPageProxy&, API::SecurityOrigin& securityOrigin, WTF::Function<void(bool)>&& completionHandler)
796 {
797     if (!m_uiDelegate.m_delegateMethods.webViewRequestNotificationPermissionForSecurityOriginDecisionHandler)
798         return completionHandler(false);
799     
800     auto delegate = m_uiDelegate.m_delegate.get();
801     if (!delegate)
802         return completionHandler(false);
803
804     auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:));
805     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView requestNotificationPermissionForSecurityOrigin:wrapper(securityOrigin) decisionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] (BOOL result) mutable {
806         if (checker->completionHandlerHasBeenCalled())
807             return;
808         checker->didCallCompletionHandler();
809         completionHandler(result);
810     }).get()];
811 }
812
813 bool UIDelegate::UIClient::runOpenPanel(WebPageProxy*, WebFrameProxy* webFrameProxy, const WebCore::SecurityOriginData& securityOriginData, API::OpenPanelParameters* openPanelParameters, WebOpenPanelResultListenerProxy* listener)
814 {
815     if (!m_uiDelegate.m_delegateMethods.webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler)
816         return false;
817
818     auto delegate = m_uiDelegate.m_delegate.get();
819     if (!delegate)
820         return false;
821
822     auto frame = API::FrameInfo::create(*webFrameProxy, securityOriginData.securityOrigin());
823
824     auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:));
825
826     [delegate webView:m_uiDelegate.m_webView runOpenPanelWithParameters:wrapper(*openPanelParameters) initiatedByFrame:wrapper(frame) completionHandler:makeBlockPtr([checker = WTFMove(checker), listener = WTFMove(listener)] (NSArray *URLs) mutable {
827         if (checker->completionHandlerHasBeenCalled())
828             return;
829         checker->didCallCompletionHandler();
830
831         if (!URLs) {
832             listener->cancel();
833             return;
834         }
835
836         Vector<String> filenames;
837         for (NSURL *url in URLs)
838             filenames.append(url.path);
839
840         listener->chooseFiles(filenames);
841     }).get()];
842
843     return true;
844 }
845 #endif
846
847 void UIDelegate::UIClient::didChangeFontAttributes(const WebCore::FontAttributes& fontAttributes)
848 {
849     if (!needsFontAttributes())
850         return;
851
852     auto privateUIDelegate = (id <WKUIDelegatePrivate>)m_uiDelegate.m_delegate.get();
853     [privateUIDelegate _webView:m_uiDelegate.m_webView didChangeFontAttributes:fontAttributes.createDictionary().get()];
854 }
855
856 #if ENABLE(MEDIA_STREAM)
857 static void requestUserMediaAuthorizationForFrame(const WebFrameProxy& frame, API::SecurityOrigin& topLevelOrigin, UserMediaPermissionRequestProxy& request, id <WKUIDelegatePrivate> delegate, WKWebView& webView)
858 {
859     auto checker = CompletionHandlerCallChecker::create(delegate, @selector(_webView:requestMediaCaptureAuthorization:decisionHandler:));
860     auto decisionHandler = makeBlockPtr([protectedRequest = makeRef(request), checker = WTFMove(checker)](BOOL authorized) {
861         if (checker->completionHandlerHasBeenCalled())
862             return;
863         checker->didCallCompletionHandler();
864
865         if (!authorized) {
866             protectedRequest->deny(UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::PermissionDenied);
867             return;
868         }
869         const String& videoDeviceUID = (protectedRequest->requiresVideoCapture() || protectedRequest->requiresDisplayCapture()) ? protectedRequest->videoDeviceUIDs().first() : String();
870         const String& audioDeviceUID = protectedRequest->requiresAudioCapture() ? protectedRequest->audioDeviceUIDs().first() : String();
871         protectedRequest->allow(audioDeviceUID, videoDeviceUID);
872     });
873
874     _WKCaptureDevices devices = 0;
875     if (request.requiresAudioCapture())
876         devices |= _WKCaptureDeviceMicrophone;
877     if (request.requiresVideoCapture())
878         devices |= _WKCaptureDeviceCamera;
879     if (request.requiresDisplayCapture()) {
880         devices |= _WKCaptureDeviceDisplay;
881         ASSERT(!(devices & _WKCaptureDeviceCamera));
882     }
883
884     const auto* mainFrame = frame.page()->mainFrame();
885
886     // FIXME: Provide a specific delegate for display capture.
887     if (!request.requiresDisplayCapture() && [delegate respondsToSelector:@selector(_webView:requestMediaCaptureAuthorization:decisionHandler:)]) {
888
889         [delegate _webView:&webView requestMediaCaptureAuthorization:devices decisionHandler:decisionHandler.get()];
890         return;
891     }
892
893     URL requestFrameURL { URL(), frame.url() };
894     URL mainFrameURL { URL(), mainFrame->url() };
895
896     [delegate _webView:&webView requestUserMediaAuthorizationForDevices:devices url:requestFrameURL mainFrameURL:mainFrameURL decisionHandler:decisionHandler.get()];
897 }
898 #endif
899
900 void UIDelegate::UIClient::decidePolicyForUserMediaPermissionRequest(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& userMediaOrigin, API::SecurityOrigin& topLevelOrigin, UserMediaPermissionRequestProxy& request)
901 {
902 #if ENABLE(MEDIA_STREAM)
903     auto delegate = m_uiDelegate.m_delegate.get();
904     if (!delegate || !m_uiDelegate.m_delegateMethods.webViewRequestMediaCaptureAuthorizationForFrameDecisionHandler) {
905         request.deny(UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::UserMediaDisabled);
906         return;
907     }
908
909     bool requiresAudioCapture = request.requiresAudioCapture();
910     bool requiresVideoCapture = request.requiresVideoCapture();
911     bool requiresDisplayCapture = request.requiresDisplayCapture();
912     if (!requiresAudioCapture && !requiresVideoCapture && !requiresDisplayCapture) {
913         request.deny(UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::NoConstraints);
914         return;
915     }
916
917 #if HAVE(AUTHORIZATION_STATUS_FOR_MEDIA_TYPE)
918     bool usingMockCaptureDevices = page.preferences().mockCaptureDevicesEnabled();
919     auto requestCameraAuthorization = makeBlockPtr([this, &frame, protectedRequest = makeRef(request), webView = RetainPtr<WKWebView>(m_uiDelegate.m_webView), topLevelOrigin = makeRef(topLevelOrigin), usingMockCaptureDevices]() mutable {
920
921         if (!protectedRequest->requiresVideoCapture()) {
922             requestUserMediaAuthorizationForFrame(frame, topLevelOrigin, protectedRequest, (id <WKUIDelegatePrivate>)m_uiDelegate.m_delegate.get(), *webView.get());
923             return;
924         }
925         AVAuthorizationStatus cameraAuthorizationStatus = usingMockCaptureDevices ? AVAuthorizationStatusAuthorized : [getAVCaptureDeviceClass() authorizationStatusForMediaType:getAVMediaTypeVideo()];
926         switch (cameraAuthorizationStatus) {
927         case AVAuthorizationStatusAuthorized:
928             requestUserMediaAuthorizationForFrame(frame, topLevelOrigin, protectedRequest, (id <WKUIDelegatePrivate>)m_uiDelegate.m_delegate.get(), *webView.get());
929             break;
930         case AVAuthorizationStatusDenied:
931         case AVAuthorizationStatusRestricted:
932             protectedRequest->deny(UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::PermissionDenied);
933             return;
934         case AVAuthorizationStatusNotDetermined:
935             auto decisionHandler = makeBlockPtr([this, &frame, protectedRequest = makeRef(protectedRequest.get()), webView = RetainPtr<WKWebView>(m_uiDelegate.m_webView), topLevelOrigin = WTFMove(topLevelOrigin)](BOOL authorized) {
936                 if (!authorized) {
937                     protectedRequest->deny(UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::PermissionDenied);
938                     return;
939                 }
940                 requestUserMediaAuthorizationForFrame(frame, topLevelOrigin, protectedRequest, (id <WKUIDelegatePrivate>)m_uiDelegate.m_delegate.get(), *webView.get());
941             });
942
943             [getAVCaptureDeviceClass() requestAccessForMediaType:getAVMediaTypeVideo() completionHandler:decisionHandler.get()];
944             break;
945         }
946     });
947
948     if (requiresAudioCapture) {
949         AVAuthorizationStatus microphoneAuthorizationStatus = usingMockCaptureDevices ? AVAuthorizationStatusAuthorized : [getAVCaptureDeviceClass() authorizationStatusForMediaType:getAVMediaTypeAudio()];
950         switch (microphoneAuthorizationStatus) {
951         case AVAuthorizationStatusAuthorized:
952             requestCameraAuthorization();
953             break;
954         case AVAuthorizationStatusDenied:
955         case AVAuthorizationStatusRestricted:
956             request.deny(UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::PermissionDenied);
957             return;
958         case AVAuthorizationStatusNotDetermined:
959             auto decisionHandler = makeBlockPtr([protectedRequest = makeRef(request), requestCameraAuthorization](BOOL authorized) {
960                 if (!authorized) {
961                     protectedRequest->deny(UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::PermissionDenied);
962                     return;
963                 }
964                 requestCameraAuthorization();
965             });
966
967             [getAVCaptureDeviceClass() requestAccessForMediaType:getAVMediaTypeAudio() completionHandler:decisionHandler.get()];
968             break;
969         }
970     } else
971         requestCameraAuthorization();
972 #else
973     requestUserMediaAuthorizationForFrame(frame, topLevelOrigin, request, (id <WKUIDelegatePrivate>)m_uiDelegate.m_delegate.get(), *m_uiDelegate.m_webView);
974 #endif
975 #endif
976 }
977
978 void UIDelegate::UIClient::checkUserMediaPermissionForOrigin(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& userMediaOrigin, API::SecurityOrigin& topLevelOrigin, UserMediaPermissionCheckProxy& request)
979 {
980     auto delegate = m_uiDelegate.m_delegate.get();
981     if (!delegate || !m_uiDelegate.m_delegateMethods.webViewIsMediaCaptureAuthorizedForFrameDecisionHandler) {
982         request.setUserMediaAccessInfo(false);
983         return;
984     }
985
986     const auto* mainFrame = frame.page()->mainFrame();
987
988     if ([delegate respondsToSelector:@selector(_webView:includeSensitiveMediaDeviceDetails:)]) {
989         auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:includeSensitiveMediaDeviceDetails:));
990         auto decisionHandler = makeBlockPtr([protectedRequest = makeRef(request), checker = WTFMove(checker)](BOOL includeSensitiveDetails) {
991             if (checker->completionHandlerHasBeenCalled())
992                 return;
993             checker->didCallCompletionHandler();
994
995             protectedRequest->setUserMediaAccessInfo(includeSensitiveDetails);
996         });
997
998         [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView includeSensitiveMediaDeviceDetails:decisionHandler.get()];
999         return;
1000     }
1001
1002     auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:checkUserMediaPermissionForURL:mainFrameURL:frameIdentifier:decisionHandler:));
1003     auto decisionHandler = makeBlockPtr([protectedRequest = makeRef(request), checker = WTFMove(checker)](NSString*, BOOL authorized) {
1004         if (checker->completionHandlerHasBeenCalled())
1005             return;
1006         checker->didCallCompletionHandler();
1007
1008         protectedRequest->setUserMediaAccessInfo(authorized);
1009     });
1010
1011     URL requestFrameURL { URL(), frame.url() };
1012     URL mainFrameURL { URL(), mainFrame->url() };
1013
1014     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView checkUserMediaPermissionForURL:requestFrameURL mainFrameURL:mainFrameURL frameIdentifier:frame.frameID() decisionHandler:decisionHandler.get()];
1015 }
1016
1017 void UIDelegate::UIClient::mediaCaptureStateDidChange(WebCore::MediaProducer::MediaStateFlags state)
1018 {
1019     WKWebView *webView = m_uiDelegate.m_webView;
1020
1021     [webView didChangeValueForKey:@"mediaCaptureState"];
1022
1023     auto delegate = m_uiDelegate.m_delegate.get();
1024     if (!delegate || !m_uiDelegate.m_delegateMethods.webViewMediaCaptureStateDidChange)
1025         return;
1026
1027     [(id <WKUIDelegatePrivate>)delegate _webView:webView mediaCaptureStateDidChange:toWKMediaCaptureState(state)];
1028 }
1029
1030 void UIDelegate::UIClient::reachedApplicationCacheOriginQuota(WebPageProxy*, const WebCore::SecurityOrigin& securityOrigin, uint64_t currentQuota, uint64_t totalBytesNeeded, Function<void (unsigned long long)>&& completionHandler)
1031 {
1032     if (!m_uiDelegate.m_delegateMethods.webViewDecideWebApplicationCacheQuotaForSecurityOriginCurrentQuotaTotalBytesNeeded) {
1033         completionHandler(currentQuota);
1034         return;
1035     }
1036
1037     auto delegate = m_uiDelegate.m_delegate.get();
1038     if (!delegate) {
1039         completionHandler(currentQuota);
1040         return;
1041     }
1042
1043     auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:decideWebApplicationCacheQuotaForSecurityOrigin:currentQuota:totalBytesNeeded:decisionHandler:));
1044     auto apiOrigin = API::SecurityOrigin::create(securityOrigin);
1045     
1046     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView decideWebApplicationCacheQuotaForSecurityOrigin:wrapper(apiOrigin.get()) currentQuota:currentQuota totalBytesNeeded:totalBytesNeeded decisionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)](unsigned long long newQuota) {
1047         if (checker->completionHandlerHasBeenCalled())
1048             return;
1049         checker->didCallCompletionHandler();
1050         completionHandler(newQuota);
1051     }).get()];
1052 }
1053
1054 void UIDelegate::UIClient::printFrame(WebPageProxy&, WebFrameProxy& webFrameProxy)
1055 {
1056     if (!m_uiDelegate.m_delegateMethods.webViewPrintFrame)
1057         return;
1058
1059     auto delegate = m_uiDelegate.m_delegate.get();
1060     if (!delegate)
1061         return;
1062
1063     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView printFrame:wrapper(API::FrameHandle::create(webFrameProxy.frameID()))];
1064 }
1065
1066 void UIDelegate::UIClient::close(WebPageProxy*)
1067 {
1068     if (m_uiDelegate.m_delegateMethods.webViewClose) {
1069         auto delegate = m_uiDelegate.m_delegate.get();
1070         if (!delegate)
1071             return;
1072
1073         [(id <WKUIDelegatePrivate>)delegate _webViewClose:m_uiDelegate.m_webView];
1074         return;
1075     }
1076
1077     if (!m_uiDelegate.m_delegateMethods.webViewDidClose)
1078         return;
1079
1080     auto delegate = m_uiDelegate.m_delegate.get();
1081     if (!delegate)
1082         return;
1083
1084     [delegate webViewDidClose:m_uiDelegate.m_webView];
1085 }
1086
1087 void UIDelegate::UIClient::fullscreenMayReturnToInline(WebPageProxy*)
1088 {
1089     if (!m_uiDelegate.m_delegateMethods.webViewFullscreenMayReturnToInline)
1090         return;
1091     
1092     auto delegate = m_uiDelegate.m_delegate.get();
1093     if (!delegate)
1094         return;
1095     
1096     [(id <WKUIDelegatePrivate>)delegate _webViewFullscreenMayReturnToInline:m_uiDelegate.m_webView];
1097 }
1098
1099 void UIDelegate::UIClient::didEnterFullscreen(WebPageProxy*)
1100 {
1101     if (!m_uiDelegate.m_delegateMethods.webViewDidEnterFullscreen)
1102         return;
1103
1104     auto delegate = m_uiDelegate.m_delegate.get();
1105     if (!delegate)
1106         return;
1107
1108     [(id <WKUIDelegatePrivate>)delegate _webViewDidEnterFullscreen:m_uiDelegate.m_webView];
1109 }
1110
1111 void UIDelegate::UIClient::didExitFullscreen(WebPageProxy*)
1112 {
1113     if (!m_uiDelegate.m_delegateMethods.webViewDidExitFullscreen)
1114         return;
1115
1116     auto delegate = m_uiDelegate.m_delegate.get();
1117     if (!delegate)
1118         return;
1119
1120     [(id <WKUIDelegatePrivate>)delegate _webViewDidExitFullscreen:m_uiDelegate.m_webView];
1121 }
1122     
1123 #if PLATFORM(IOS_FAMILY)
1124 #if HAVE(APP_LINKS)
1125 bool UIDelegate::UIClient::shouldIncludeAppLinkActionsForElement(_WKActivatedElementInfo *elementInfo)
1126 {
1127     if (!m_uiDelegate.m_delegateMethods.webViewShouldIncludeAppLinkActionsForElement)
1128         return true;
1129
1130     auto delegate = m_uiDelegate.m_delegate.get();
1131     if (!delegate)
1132         return true;
1133
1134     return [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView shouldIncludeAppLinkActionsForElement:elementInfo];
1135 }
1136 #endif
1137
1138 RetainPtr<NSArray> UIDelegate::UIClient::actionsForElement(_WKActivatedElementInfo *elementInfo, RetainPtr<NSArray> defaultActions)
1139 {
1140     if (!m_uiDelegate.m_delegateMethods.webViewActionsForElementDefaultActions)
1141         return defaultActions;
1142
1143     auto delegate = m_uiDelegate.m_delegate.get();
1144     if (!delegate)
1145         return defaultActions;
1146
1147     return [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView actionsForElement:elementInfo defaultActions:defaultActions.get()];
1148 }
1149
1150 void UIDelegate::UIClient::didNotHandleTapAsClick(const WebCore::IntPoint& point)
1151 {
1152     if (!m_uiDelegate.m_delegateMethods.webViewDidNotHandleTapAsClickAtPoint)
1153         return;
1154
1155     auto delegate = m_uiDelegate.m_delegate.get();
1156     if (!delegate)
1157         return;
1158
1159     [static_cast<id <WKUIDelegatePrivate>>(delegate) _webView:m_uiDelegate.m_webView didNotHandleTapAsClickAtPoint:point];
1160 }
1161
1162 UIViewController *UIDelegate::UIClient::presentingViewController()
1163 {
1164     if (!m_uiDelegate.m_delegateMethods.presentingViewControllerForWebView)
1165         return nullptr;
1166
1167     auto delegate = m_uiDelegate.m_delegate.get();
1168     if (!delegate)
1169         return nullptr;
1170
1171     return [static_cast<id <WKUIDelegatePrivate>>(delegate) _presentingViewControllerForWebView:m_uiDelegate.m_webView];
1172 }
1173
1174 #endif
1175
1176 NSDictionary *UIDelegate::UIClient::dataDetectionContext()
1177 {
1178     if (!m_uiDelegate.m_delegateMethods.dataDetectionContextForWebView)
1179         return nullptr;
1180
1181     auto delegate = m_uiDelegate.m_delegate.get();
1182     if (!delegate)
1183         return nullptr;
1184
1185     return [static_cast<id <WKUIDelegatePrivate>>(delegate) _dataDetectionContextForWebView:m_uiDelegate.m_webView];
1186 }
1187
1188 #if ENABLE(POINTER_LOCK)
1189
1190 void UIDelegate::UIClient::requestPointerLock(WebPageProxy* page)
1191 {
1192     if (!m_uiDelegate.m_delegateMethods.webViewRequestPointerLock && !m_uiDelegate.m_delegateMethods.webViewDidRequestPointerLockCompletionHandler)
1193         return;
1194
1195     auto delegate = m_uiDelegate.m_delegate.get();
1196     if (!delegate)
1197         return;
1198
1199     if (m_uiDelegate.m_delegateMethods.webViewRequestPointerLock) {
1200         [static_cast<id <WKUIDelegatePrivate>>(delegate) _webViewRequestPointerLock:m_uiDelegate.m_webView];
1201         return;
1202     }
1203
1204     auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webViewDidRequestPointerLock:completionHandler:));
1205     [static_cast<id <WKUIDelegatePrivate>>(delegate) _webViewDidRequestPointerLock:m_uiDelegate.m_webView completionHandler:makeBlockPtr([checker = WTFMove(checker), page = makeRefPtr(page)] (BOOL allow) {
1206         if (checker->completionHandlerHasBeenCalled())
1207             return;
1208         checker->didCallCompletionHandler();
1209
1210         if (allow)
1211             page->didAllowPointerLock();
1212         else
1213             page->didDenyPointerLock();
1214     }).get()];
1215 }
1216
1217 void UIDelegate::UIClient::didLosePointerLock(WebPageProxy*)
1218 {
1219     if (!m_uiDelegate.m_delegateMethods.webViewDidLosePointerLock)
1220         return;
1221
1222     auto delegate = m_uiDelegate.m_delegate.get();
1223     if (!delegate)
1224         return;
1225
1226     [static_cast<id <WKUIDelegatePrivate>>(delegate) _webViewDidLosePointerLock:m_uiDelegate.m_webView];
1227 }
1228
1229 #endif
1230     
1231 void UIDelegate::UIClient::didShowSafeBrowsingWarning()
1232 {
1233     if (!m_uiDelegate.m_delegateMethods.webViewDidShowSafeBrowsingWarning)
1234         return;
1235
1236     auto delegate = m_uiDelegate.m_delegate.get();
1237     if (!delegate)
1238         return;
1239
1240     [static_cast<id <WKUIDelegatePrivate>>(delegate) _webViewDidShowSafeBrowsingWarning:m_uiDelegate.m_webView];
1241 }
1242
1243 void UIDelegate::UIClient::hasVideoInPictureInPictureDidChange(WebPageProxy*, bool hasVideoInPictureInPicture)
1244 {
1245     if (!m_uiDelegate.m_delegateMethods.webViewHasVideoInPictureInPictureDidChange)
1246         return;
1247     
1248     auto delegate = m_uiDelegate.m_delegate.get();
1249     if (!delegate)
1250         return;
1251     
1252     [static_cast<id <WKUIDelegatePrivate>>(delegate) _webView:m_uiDelegate.m_webView hasVideoInPictureInPictureDidChange:hasVideoInPictureInPicture];
1253 }
1254
1255 void UIDelegate::UIClient::imageOrMediaDocumentSizeChanged(const WebCore::IntSize& newSize)
1256 {
1257     if (!m_uiDelegate.m_delegateMethods.webViewImageOrMediaDocumentSizeChanged)
1258         return;
1259
1260     auto delegate = m_uiDelegate.m_delegate.get();
1261     if (!delegate)
1262         return;
1263
1264     [static_cast<id <WKUIDelegatePrivate>>(delegate) _webView:m_uiDelegate.m_webView imageOrMediaDocumentSizeChanged:newSize];
1265 }
1266
1267 } // namespace WebKit