b3a4352ff66e2232781b64023e7f12dbfe47f09b
[WebKit-https.git] / Source / WebKit / UIProcess / Cocoa / UIDelegate.h
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 #pragma once
27
28 #import "WKFoundation.h"
29
30 #if WK_API_ENABLED
31
32 #import "APIContextMenuClient.h"
33 #import "APIUIClient.h"
34 #import <wtf/RetainPtr.h>
35 #import <wtf/WeakObjCPtr.h>
36
37 @class _WKActivatedElementInfo;
38 @class WKWebView;
39 @protocol WKUIDelegate;
40
41 namespace API {
42 class FrameInfo;
43 class SecurityOrigin;
44 }
45
46 namespace WebKit {
47
48 class UIDelegate {
49     WTF_MAKE_FAST_ALLOCATED;
50 public:
51     explicit UIDelegate(WKWebView *);
52     ~UIDelegate();
53
54 #if ENABLE(CONTEXT_MENUS)
55     std::unique_ptr<API::ContextMenuClient> createContextMenuClient();
56 #endif
57     std::unique_ptr<API::UIClient> createUIClient();
58
59     RetainPtr<id <WKUIDelegate> > delegate();
60     void setDelegate(id <WKUIDelegate>);
61
62 private:
63 #if ENABLE(CONTEXT_MENUS)
64     class ContextMenuClient : public API::ContextMenuClient {
65     public:
66         explicit ContextMenuClient(UIDelegate&);
67         ~ContextMenuClient();
68
69     private:
70         // API::ContextMenuClient
71         void menuFromProposedMenu(WebPageProxy&, NSMenu *, const WebHitTestResultData&, API::Object*, CompletionHandler<void(RetainPtr<NSMenu>&&)>&&) override;
72
73         UIDelegate& m_uiDelegate;
74     };
75 #endif
76
77     class UIClient : public API::UIClient {
78     public:
79         explicit UIClient(UIDelegate&);
80         ~UIClient();
81
82     private:
83         // API::UIClient
84         void createNewPage(WebPageProxy&, Ref<API::FrameInfo>&&, WebCore::ResourceRequest&&, WebCore::WindowFeatures&&, NavigationActionData&&, CompletionHandler<void(RefPtr<WebPageProxy>&&)>&&) final;
85         void close(WebPageProxy*) final;
86         void fullscreenMayReturnToInline(WebPageProxy*) final;
87         void didEnterFullscreen(WebPageProxy*) final;
88         void didExitFullscreen(WebPageProxy*) final;
89         void runJavaScriptAlert(WebPageProxy*, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void()>&& completionHandler) final;
90         void runJavaScriptConfirm(WebPageProxy*, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(bool)>&& completionHandler) final;
91         void runJavaScriptPrompt(WebPageProxy*, const WTF::String&, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(const WTF::String&)>&&) final;
92         void requestStorageAccessConfirm(WebPageProxy&, WebFrameProxy*, const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&&) final;
93         void decidePolicyForGeolocationPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>&) final;
94         bool canRunBeforeUnloadConfirmPanel() const final;
95         void runBeforeUnloadConfirmPanel(WebPageProxy*, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(bool)>&& completionHandler) final;
96         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;
97         void reachedApplicationCacheOriginQuota(WebPageProxy*, const WebCore::SecurityOrigin&, uint64_t currentQuota, uint64_t totalBytesNeeded, Function<void(unsigned long long)>&& completionHandler) final;
98         void didResignInputElementStrongPasswordAppearance(WebPageProxy&, API::Object*) final;
99         bool takeFocus(WebPageProxy*, WKFocusDirection) final;
100 #if PLATFORM(MAC)
101         void showPage(WebPageProxy*) final;
102         void focus(WebPageProxy*) final;
103         void unfocus(WebPageProxy*) final;
104         bool canRunModal() const final;
105         void runModal(WebPageProxy&) final;
106         void pageDidScroll(WebPageProxy*) final;
107         void setIsResizable(WebPageProxy&, bool) final;
108         void setWindowFrame(WebPageProxy&, const WebCore::FloatRect&) final;
109         void windowFrame(WebPageProxy&, Function<void(WebCore::FloatRect)>&&) final;
110         void didNotHandleWheelEvent(WebPageProxy*, const NativeWebWheelEvent&) final;
111         float headerHeight(WebPageProxy&, WebFrameProxy&) final;
112         float footerHeight(WebPageProxy&, WebFrameProxy&) final;
113         void drawHeader(WebPageProxy&, WebFrameProxy&, WebCore::FloatRect&&) final;
114         void drawFooter(WebPageProxy&, WebFrameProxy&, WebCore::FloatRect&&) final;
115         void decidePolicyForNotificationPermissionRequest(WebPageProxy&, API::SecurityOrigin&, Function<void(bool)>&&) final;
116         void handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
117         void unavailablePluginButtonClicked(WebPageProxy&, WKPluginUnavailabilityReason, API::Dictionary&) final;
118         void mouseDidMoveOverElement(WebPageProxy&, const WebHitTestResultData&, OptionSet<WebEvent::Modifier>, API::Object*);
119         void didClickAutoFillButton(WebPageProxy&, API::Object*) final;
120         void toolbarsAreVisible(WebPageProxy&, Function<void(bool)>&&) final;
121         bool runOpenPanel(WebPageProxy*, WebFrameProxy*, const WebCore::SecurityOriginData&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) final;
122         void didExceedBackgroundResourceLimitWhileInForeground(WebPageProxy&, WKResourceLimit) final;
123         void saveDataToFileInDownloadsFolder(WebPageProxy*, const WTF::String&, const WTF::String&, const URL&, API::Data&) final;
124 #endif
125         bool needsFontAttributes() const final { return m_uiDelegate.m_delegateMethods.webViewDidChangeFontAttributes; }
126         void didChangeFontAttributes(const WebCore::FontAttributes&) final;
127         void decidePolicyForUserMediaPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionRequestProxy&) final;
128         void checkUserMediaPermissionForOrigin(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionCheckProxy&) final;
129         void mediaCaptureStateDidChange(WebCore::MediaProducer::MediaStateFlags) final;
130         void printFrame(WebPageProxy&, WebFrameProxy&) final;
131 #if PLATFORM(IOS_FAMILY)
132 #if HAVE(APP_LINKS)
133         bool shouldIncludeAppLinkActionsForElement(_WKActivatedElementInfo *) final;
134 #endif
135         RetainPtr<NSArray> actionsForElement(_WKActivatedElementInfo *, RetainPtr<NSArray> defaultActions) final;
136         void didNotHandleTapAsClick(const WebCore::IntPoint&) final;
137         UIViewController *presentingViewController() final;
138 #endif // PLATFORM(IOS_FAMILY)
139
140         NSDictionary *dataDetectionContext() final;
141
142 #if ENABLE(POINTER_LOCK)
143         void requestPointerLock(WebPageProxy*) final;
144         void didLosePointerLock(WebPageProxy*) final;
145 #endif
146         
147         void hasVideoInPictureInPictureDidChange(WebPageProxy*, bool) final;
148
149         void imageOrMediaDocumentSizeChanged(const WebCore::IntSize&) final;
150         void didShowSafeBrowsingWarning() final;
151         void didClickGoBackFromSafeBrowsingWarning() final;
152
153         UIDelegate& m_uiDelegate;
154     };
155
156     WKWebView *m_webView;
157     WeakObjCPtr<id <WKUIDelegate> > m_delegate;
158
159     struct {
160         bool webViewCreateWebViewWithConfigurationForNavigationActionWindowFeatures : 1;
161         bool webViewCreateWebViewWithConfigurationForNavigationActionWindowFeaturesAsync : 1;
162         bool webViewRunJavaScriptAlertPanelWithMessageInitiatedByFrameCompletionHandler : 1;
163         bool webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
164         bool webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler : 1;
165         bool webViewRequestStorageAccessPanelForTopPrivatelyControlledDomainUnderFirstPartyTopPrivatelyControlledDomainCompletionHandler : 1;
166         bool webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
167         bool webViewRequestGeolocationPermissionForFrameDecisionHandler : 1;
168         bool webViewDidResignInputElementStrongPasswordAppearanceWithUserInfo : 1;
169         bool webViewTakeFocus : 1;
170 #if PLATFORM(MAC)
171         bool showWebView : 1;
172         bool focusWebView : 1;
173         bool unfocusWebView : 1;
174         bool webViewRunModal : 1;
175         bool webViewDidScroll : 1;
176         bool webViewHeaderHeight : 1;
177         bool webViewFooterHeight : 1;
178         bool webViewSetResizable : 1;
179         bool webViewSetWindowFrame : 1;
180         bool webViewDidNotHandleWheelEvent : 1;
181         bool webViewHandleAutoplayEventWithFlags : 1;
182         bool webViewUnavailablePlugInButtonClicked : 1;
183         bool webViewDidClickAutoFillButtonWithUserInfo : 1;
184         bool webViewDrawHeaderInRectForPageWithTitleURL : 1;
185         bool webViewDrawFooterInRectForPageWithTitleURL : 1;
186         bool webViewGetWindowFrameWithCompletionHandler : 1;
187         bool webViewMouseDidMoveOverElementWithFlagsUserInfo : 1;
188         bool webViewGetToolbarsAreVisibleWithCompletionHandler : 1;
189         bool webViewDidExceedBackgroundResourceLimitWhileInForeground : 1;
190         bool webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL : 1;
191         bool webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler : 1;
192         bool webViewRequestNotificationPermissionForSecurityOriginDecisionHandler : 1;
193 #endif
194         bool webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler : 1;
195         bool webViewDecideDatabaseQuotaForSecurityOriginDatabaseNameDisplayNameCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler : 1;
196         bool webViewDecideWebApplicationCacheQuotaForSecurityOriginCurrentQuotaTotalBytesNeeded : 1;
197         bool webViewPrintFrame : 1;
198         bool webViewDidClose : 1;
199         bool webViewClose : 1;
200         bool webViewFullscreenMayReturnToInline : 1;
201         bool webViewDidEnterFullscreen : 1;
202         bool webViewDidExitFullscreen : 1;
203         bool webViewRequestMediaCaptureAuthorizationForFrameDecisionHandler : 1;
204         bool webViewIsMediaCaptureAuthorizedForFrameDecisionHandler : 1;
205         bool webViewMediaCaptureStateDidChange : 1;
206         bool webViewDidChangeFontAttributes : 1;
207 #if PLATFORM(IOS_FAMILY)
208 #if HAVE(APP_LINKS)
209         bool webViewShouldIncludeAppLinkActionsForElement : 1;
210 #endif
211         bool webViewActionsForElementDefaultActions : 1;
212         bool webViewDidNotHandleTapAsClickAtPoint : 1;
213         bool presentingViewControllerForWebView : 1;
214 #endif
215         bool dataDetectionContextForWebView : 1;
216         bool webViewImageOrMediaDocumentSizeChanged : 1;
217 #if ENABLE(POINTER_LOCK)
218         bool webViewRequestPointerLock : 1;
219         bool webViewDidRequestPointerLockCompletionHandler : 1;
220         bool webViewDidLosePointerLock : 1;
221 #endif
222 #if ENABLE(CONTEXT_MENUS)
223         bool webViewContextMenuForElement : 1;
224         bool webViewContextMenuForElementUserInfo : 1;
225         bool webViewGetContextMenuFromProposedMenuForElementUserInfoCompletionHandler : 1;
226 #endif
227         bool webViewHasVideoInPictureInPictureDidChange : 1;
228         bool webViewDidShowSafeBrowsingWarning : 1;
229         bool webViewDidClickGoBackFromSafeBrowsingWarning : 1;
230     } m_delegateMethods;
231 };
232
233 } // namespace WebKit
234
235 #endif // WK_API_ENABLED