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