forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIDelegate.h
More file actions
293 lines (264 loc) · 15.9 KB
/
UIDelegate.h
File metadata and controls
293 lines (264 loc) · 15.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
* Copyright (C) 2014-2018 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#import "WKFoundation.h"
#import "APIContextMenuClient.h"
#import "APIUIClient.h"
#import <WebCore/PlatformViewController.h>
#import <wtf/RetainPtr.h>
#import <wtf/WeakObjCPtr.h>
#import <wtf/WeakPtr.h>
@class _WKActivatedElementInfo;
@class WKWebView;
@protocol WKUIDelegate;
namespace API {
class FrameInfo;
class SecurityOrigin;
}
namespace WebCore {
class RegistrableDomain;
}
namespace WebKit {
enum class TapHandlingResult : uint8_t;
class UIDelegate : public CanMakeWeakPtr<UIDelegate> {
WTF_MAKE_FAST_ALLOCATED;
public:
explicit UIDelegate(WKWebView *);
~UIDelegate();
#if ENABLE(CONTEXT_MENUS)
std::unique_ptr<API::ContextMenuClient> createContextMenuClient();
#endif
std::unique_ptr<API::UIClient> createUIClient();
RetainPtr<id <WKUIDelegate> > delegate();
void setDelegate(id <WKUIDelegate>);
private:
#if ENABLE(CONTEXT_MENUS)
class ContextMenuClient : public API::ContextMenuClient {
public:
explicit ContextMenuClient(UIDelegate&);
~ContextMenuClient();
private:
// API::ContextMenuClient
void menuFromProposedMenu(WebPageProxy&, NSMenu *, const WebHitTestResultData&, API::Object*, CompletionHandler<void(RetainPtr<NSMenu>&&)>&&) override;
WeakPtr<UIDelegate> m_uiDelegate;
};
#endif
class UIClient : public API::UIClient, public CanMakeWeakPtr<UIClient> {
public:
explicit UIClient(UIDelegate&);
~UIClient();
private:
// API::UIClient
void createNewPage(WebKit::WebPageProxy&, WebCore::WindowFeatures&&, Ref<API::NavigationAction>&&, CompletionHandler<void(RefPtr<WebPageProxy>&&)>&&) final;
void close(WebPageProxy*) final;
void fullscreenMayReturnToInline(WebPageProxy*) final;
void didEnterFullscreen(WebPageProxy*) final;
void didExitFullscreen(WebPageProxy*) final;
void runJavaScriptAlert(WebPageProxy&, const WTF::String&, WebFrameProxy*, FrameInfoData&&, Function<void()>&& completionHandler) final;
void runJavaScriptConfirm(WebPageProxy&, const WTF::String&, WebFrameProxy*, FrameInfoData&&, Function<void(bool)>&& completionHandler) final;
void runJavaScriptPrompt(WebPageProxy&, const WTF::String&, const WTF::String&, WebFrameProxy*, FrameInfoData&&, Function<void(const WTF::String&)>&&) final;
void presentStorageAccessConfirmDialog(const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&&);
void requestStorageAccessConfirm(WebPageProxy&, WebFrameProxy*, const WebCore::RegistrableDomain& requestingDomain, const WebCore::RegistrableDomain& currentDomain, CompletionHandler<void(bool)>&&) final;
void decidePolicyForGeolocationPermissionRequest(WebPageProxy&, WebFrameProxy&, const FrameInfoData&, Function<void(bool)>&) final;
bool canRunBeforeUnloadConfirmPanel() const final;
void runBeforeUnloadConfirmPanel(WebPageProxy&, const WTF::String&, WebFrameProxy*, FrameInfoData&&, Function<void(bool)>&& completionHandler) final;
void exceededDatabaseQuota(WebPageProxy*, WebFrameProxy*, API::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) final;
void reachedApplicationCacheOriginQuota(WebPageProxy*, const WebCore::SecurityOrigin&, uint64_t currentQuota, uint64_t totalBytesNeeded, Function<void(unsigned long long)>&& completionHandler) final;
void didResignInputElementStrongPasswordAppearance(WebPageProxy&, API::Object*) final;
bool takeFocus(WebPageProxy*, WKFocusDirection) final;
void handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
void decidePolicyForNotificationPermissionRequest(WebPageProxy&, API::SecurityOrigin&, CompletionHandler<void(bool allowed)>&&) final;
void requestCookieConsent(CompletionHandler<void(WebCore::CookieConsentDecisionResult)>&&) final;
void decidePolicyForModalContainer(OptionSet<WebCore::ModalContainerControlType>, CompletionHandler<void(WebCore::ModalContainerDecision)>&&) final;
#if PLATFORM(MAC) || HAVE(UIKIT_WITH_MOUSE_SUPPORT)
void mouseDidMoveOverElement(WebPageProxy&, const WebHitTestResultData&, OptionSet<WebEvent::Modifier>, API::Object*);
#endif
#if PLATFORM(MAC)
void showPage(WebPageProxy*) final;
void focus(WebPageProxy*) final;
void unfocus(WebPageProxy*) final;
bool focusFromServiceWorker(WebKit::WebPageProxy&) final;
bool canRunModal() const final;
void runModal(WebPageProxy&) final;
void pageDidScroll(WebPageProxy*) final;
void setIsResizable(WebPageProxy&, bool) final;
void setWindowFrame(WebPageProxy&, const WebCore::FloatRect&) final;
void windowFrame(WebPageProxy&, Function<void(WebCore::FloatRect)>&&) final;
void didNotHandleWheelEvent(WebPageProxy*, const NativeWebWheelEvent&) final;
// Printing.
float headerHeight(WebPageProxy&, WebFrameProxy&) final;
float footerHeight(WebPageProxy&, WebFrameProxy&) final;
void drawHeader(WebPageProxy&, WebFrameProxy&, WebCore::FloatRect&&) final;
void drawFooter(WebPageProxy&, WebFrameProxy&, WebCore::FloatRect&&) final;
void didClickAutoFillButton(WebPageProxy&, API::Object*) final;
void toolbarsAreVisible(WebPageProxy&, Function<void(bool)>&&) final;
bool runOpenPanel(WebPageProxy&, WebFrameProxy*, FrameInfoData&&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) final;
void didExceedBackgroundResourceLimitWhileInForeground(WebPageProxy&, WKResourceLimit) final;
void saveDataToFileInDownloadsFolder(WebPageProxy*, const WTF::String&, const WTF::String&, const URL&, API::Data&) final;
Ref<API::InspectorConfiguration> configurationForLocalInspector(WebPageProxy&, WebInspectorUIProxy&) final;
void didAttachLocalInspector(WebPageProxy&, WebInspectorUIProxy&) final;
void willCloseLocalInspector(WebPageProxy&, WebInspectorUIProxy&) final;
#endif
#if ENABLE(DEVICE_ORIENTATION)
void shouldAllowDeviceOrientationAndMotionAccess(WebKit::WebPageProxy&, WebFrameProxy&, FrameInfoData&&, CompletionHandler<void(bool)>&&) final;
#endif
bool needsFontAttributes() const final { return m_uiDelegate ? m_uiDelegate->m_delegateMethods.webViewDidChangeFontAttributes : false; }
void didChangeFontAttributes(const WebCore::FontAttributes&) final;
void decidePolicyForUserMediaPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionRequestProxy&) final;
void checkUserMediaPermissionForOrigin(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionCheckProxy&) final;
void mediaCaptureStateDidChange(WebCore::MediaProducerMediaStateFlags) final;
void promptForDisplayCapturePermission(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionRequestProxy&);
void printFrame(WebPageProxy&, WebFrameProxy&, const WebCore::FloatSize& pdfFirstPageSize, CompletionHandler<void()>&&) final;
#if PLATFORM(IOS_FAMILY)
#if HAVE(APP_LINKS)
bool shouldIncludeAppLinkActionsForElement(_WKActivatedElementInfo *) final;
#endif
RetainPtr<NSArray> actionsForElement(_WKActivatedElementInfo *, RetainPtr<NSArray> defaultActions) final;
void didNotHandleTapAsClick(const WebCore::IntPoint&) final;
#endif // PLATFORM(IOS_FAMILY)
PlatformViewController *presentingViewController() final;
NSDictionary *dataDetectionContext() final;
#if ENABLE(POINTER_LOCK)
void requestPointerLock(WebPageProxy*) final;
void didLosePointerLock(WebPageProxy*) final;
#endif
void hasVideoInPictureInPictureDidChange(WebPageProxy*, bool) final;
void imageOrMediaDocumentSizeChanged(const WebCore::IntSize&) final;
void didShowSafeBrowsingWarning() final;
void confirmPDFOpening(WebPageProxy&, const WTF::URL&, FrameInfoData&&, CompletionHandler<void(bool)>&&) final;
#if ENABLE(WEB_AUTHN)
void runWebAuthenticationPanel(WebPageProxy&, API::WebAuthenticationPanel&, WebFrameProxy&, FrameInfoData&&, CompletionHandler<void(WebAuthenticationPanelResult)>&&) final;
void requestWebAuthenticationNoGesture(API::SecurityOrigin&, CompletionHandler<void(bool)>&&) final;
#endif
void decidePolicyForSpeechRecognitionPermissionRequest(WebPageProxy&, API::SecurityOrigin&, CompletionHandler<void(bool)>&&) final;
void queryPermission(const String&, API::SecurityOrigin&, CompletionHandler<void(std::optional<WebCore::PermissionState>)>&&) final;
void didEnableInspectorBrowserDomain(WebPageProxy&) final;
void didDisableInspectorBrowserDomain(WebPageProxy&) final;
#if ENABLE(WEBXR)
void requestPermissionOnXRSessionFeatures(WebPageProxy&, const WebCore::SecurityOriginData&, PlatformXR::SessionMode, const PlatformXR::Device::FeatureList& /* granted */, const PlatformXR::Device::FeatureList& /* consentRequired */, const PlatformXR::Device::FeatureList& /* consentOptional */, CompletionHandler<void(std::optional<PlatformXR::Device::FeatureList>&&)>&&) final;
void startXRSession(WebPageProxy&, CompletionHandler<void(RetainPtr<id>)>&&) final;
void endXRSession(WebPageProxy&) final;
#endif
WeakPtr<UIDelegate> m_uiDelegate;
};
WeakObjCPtr<WKWebView> m_webView;
WeakObjCPtr<id <WKUIDelegate> > m_delegate;
struct {
bool webViewCreateWebViewWithConfigurationForNavigationActionWindowFeatures : 1;
bool webViewCreateWebViewWithConfigurationForNavigationActionWindowFeaturesAsync : 1;
bool webViewRunJavaScriptAlertPanelWithMessageInitiatedByFrameCompletionHandler : 1;
bool webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
bool webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler : 1;
bool webViewRequestStorageAccessPanelUnderFirstPartyCompletionHandler : 1;
bool webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
bool webViewRequestGeolocationPermissionForFrameDecisionHandler : 1;
bool webViewRequestGeolocationPermissionForOriginDecisionHandler : 1;
bool webViewDidResignInputElementStrongPasswordAppearanceWithUserInfo : 1;
bool webViewTakeFocus : 1;
bool webViewHandleAutoplayEventWithFlags : 1;
#if PLATFORM(MAC) || HAVE(UIKIT_WITH_MOUSE_SUPPORT)
bool webViewMouseDidMoveOverElementWithFlagsUserInfo : 1;
#endif
#if PLATFORM(MAC)
bool showWebView : 1;
bool focusWebView : 1;
bool focusWebViewFromServiceWorker : 1;
bool unfocusWebView : 1;
bool webViewRunModal : 1;
bool webViewDidScroll : 1;
bool webViewHeaderHeight : 1;
bool webViewFooterHeight : 1;
bool webViewSetResizable : 1;
bool webViewSetWindowFrame : 1;
bool webViewDidNotHandleWheelEvent : 1;
bool webViewUnavailablePlugInButtonClicked : 1;
bool webViewDidClickAutoFillButtonWithUserInfo : 1;
bool webViewDrawHeaderInRectForPageWithTitleURL : 1;
bool webViewDrawFooterInRectForPageWithTitleURL : 1;
bool webViewGetWindowFrameWithCompletionHandler : 1;
bool webViewGetToolbarsAreVisibleWithCompletionHandler : 1;
bool webViewDidExceedBackgroundResourceLimitWhileInForeground : 1;
bool webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL : 1;
bool webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler : 1;
bool webViewConfigurationForLocalInspector : 1;
bool webViewDidAttachLocalInspector : 1;
bool webViewWillCloseLocalInspector : 1;
#endif
#if ENABLE(DEVICE_ORIENTATION)
bool webViewRequestDeviceOrientationAndMotionPermissionForOriginDecisionHandler : 1;
#endif
bool webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler : 1;
bool webViewDecideDatabaseQuotaForSecurityOriginDatabaseNameDisplayNameCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler : 1;
bool webViewDecideWebApplicationCacheQuotaForSecurityOriginCurrentQuotaTotalBytesNeeded : 1;
bool webViewPrintFrame : 1;
bool webViewPrintFramePDFFirstPageSizeCompletionHandler : 1;
bool webViewDidClose : 1;
bool webViewClose : 1;
bool webViewFullscreenMayReturnToInline : 1;
bool webViewDidEnterFullscreen : 1;
bool webViewDidExitFullscreen : 1;
bool webViewIsMediaCaptureAuthorizedForFrameDecisionHandler : 1;
bool webViewMediaCaptureStateDidChange : 1;
bool webViewDidChangeFontAttributes : 1;
#if PLATFORM(IOS_FAMILY)
#if HAVE(APP_LINKS)
bool webViewShouldIncludeAppLinkActionsForElement : 1;
#endif
bool webViewActionsForElementDefaultActions : 1;
bool webViewDidNotHandleTapAsClickAtPoint : 1;
#endif
bool presentingViewControllerForWebView : 1;
bool dataDetectionContextForWebView : 1;
bool webViewImageOrMediaDocumentSizeChanged : 1;
#if ENABLE(POINTER_LOCK)
bool webViewRequestPointerLock : 1;
bool webViewDidRequestPointerLockCompletionHandler : 1;
bool webViewDidLosePointerLock : 1;
#endif
#if ENABLE(CONTEXT_MENUS)
bool webViewContextMenuForElement : 1;
bool webViewContextMenuForElementUserInfo : 1;
bool webViewGetContextMenuFromProposedMenuForElementUserInfoCompletionHandler : 1;
#endif
bool webViewHasVideoInPictureInPictureDidChange : 1;
bool webViewDidShowSafeBrowsingWarning : 1;
bool webViewShouldAllowPDFAtURLToOpenFromFrameCompletionHandler : 1;
#if ENABLE(WEB_AUTHN)
bool webViewRunWebAuthenticationPanelInitiatedByFrameCompletionHandler : 1;
bool webViewRequestWebAuthenticationNoGestureForOriginCompletionHandler : 1;
#endif
bool webViewDidEnableInspectorBrowserDomain : 1;
bool webViewDidDisableInspectorBrowserDomain : 1;
#if ENABLE(WEBXR)
bool webViewRequestPermissionForXRSessionOriginModeAndFeaturesWithCompletionHandler: 1;
bool webViewStartXRSessionWithCompletionHandler : 1;
bool webViewEndXRSession : 1;
#endif
bool webViewRequestNotificationPermissionForSecurityOriginDecisionHandler : 1;
bool webViewRequestCookieConsentWithMoreInfoHandlerDecisionHandler : 1;
bool webViewDecidePolicyForModalContainerDecisionHandler : 1;
} m_delegateMethods;
};
} // namespace WebKit