Update device orientation & motion permission native SPI as per latest proposal
[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 #if ENABLE(DEVICE_ORIENTATION)
124         void shouldAllowDeviceOrientationAndMotionAccess(WebKit::WebPageProxy&, WebFrameProxy&, const WebCore::SecurityOriginData&, CompletionHandler<void(bool)>&&) final;
125 #endif
126         bool needsFontAttributes() const final { return m_uiDelegate.m_delegateMethods.webViewDidChangeFontAttributes; }
127         void didChangeFontAttributes(const WebCore::FontAttributes&) final;
128         void decidePolicyForUserMediaPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionRequestProxy&) final;
129         void checkUserMediaPermissionForOrigin(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionCheckProxy&) final;
130         void mediaCaptureStateDidChange(WebCore::MediaProducer::MediaStateFlags) final;
131         void printFrame(WebPageProxy&, WebFrameProxy&) final;
132 #if PLATFORM(IOS_FAMILY)
133 #if HAVE(APP_LINKS)
134         bool shouldIncludeAppLinkActionsForElement(_WKActivatedElementInfo *) final;
135 #endif
136         RetainPtr<NSArray> actionsForElement(_WKActivatedElementInfo *, RetainPtr<NSArray> defaultActions) final;
137         void didNotHandleTapAsClick(const WebCore::IntPoint&) final;
138         UIViewController *presentingViewController() final;
139 #endif // PLATFORM(IOS_FAMILY)
140
141         NSDictionary *dataDetectionContext() final;
142
143 #if ENABLE(POINTER_LOCK)
144         void requestPointerLock(WebPageProxy*) final;
145         void didLosePointerLock(WebPageProxy*) final;
146 #endif
147         
148         void hasVideoInPictureInPictureDidChange(WebPageProxy*, bool) final;
149
150         void imageOrMediaDocumentSizeChanged(const WebCore::IntSize&) final;
151         void didShowSafeBrowsingWarning() 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 #if ENABLE(DEVICE_ORIENTATION)
195         bool webViewShouldAllowDeviceOrientationAndMotionAccessRequestedByFrameDecisionHandler : 1;
196 #endif
197         bool webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler : 1;
198         bool webViewDecideDatabaseQuotaForSecurityOriginDatabaseNameDisplayNameCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler : 1;
199         bool webViewDecideWebApplicationCacheQuotaForSecurityOriginCurrentQuotaTotalBytesNeeded : 1;
200         bool webViewPrintFrame : 1;
201         bool webViewDidClose : 1;
202         bool webViewClose : 1;
203         bool webViewFullscreenMayReturnToInline : 1;
204         bool webViewDidEnterFullscreen : 1;
205         bool webViewDidExitFullscreen : 1;
206         bool webViewRequestMediaCaptureAuthorizationForFrameDecisionHandler : 1;
207         bool webViewIsMediaCaptureAuthorizedForFrameDecisionHandler : 1;
208         bool webViewMediaCaptureStateDidChange : 1;
209         bool webViewDidChangeFontAttributes : 1;
210 #if PLATFORM(IOS_FAMILY)
211 #if HAVE(APP_LINKS)
212         bool webViewShouldIncludeAppLinkActionsForElement : 1;
213 #endif
214         bool webViewActionsForElementDefaultActions : 1;
215         bool webViewDidNotHandleTapAsClickAtPoint : 1;
216         bool presentingViewControllerForWebView : 1;
217 #endif
218         bool dataDetectionContextForWebView : 1;
219         bool webViewImageOrMediaDocumentSizeChanged : 1;
220 #if ENABLE(POINTER_LOCK)
221         bool webViewRequestPointerLock : 1;
222         bool webViewDidRequestPointerLockCompletionHandler : 1;
223         bool webViewDidLosePointerLock : 1;
224 #endif
225 #if ENABLE(CONTEXT_MENUS)
226         bool webViewContextMenuForElement : 1;
227         bool webViewContextMenuForElementUserInfo : 1;
228         bool webViewGetContextMenuFromProposedMenuForElementUserInfoCompletionHandler : 1;
229 #endif
230         bool webViewHasVideoInPictureInPictureDidChange : 1;
231         bool webViewDidShowSafeBrowsingWarning : 1;
232     } m_delegateMethods;
233 };
234
235 } // namespace WebKit