UIDelegate::UIClient::didResignInputElementStrongPasswordAppearance() is applicable...
[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 "WeakObjCPtr.h"
35 #import <wtf/RetainPtr.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 public:
50     explicit UIDelegate(WKWebView *);
51     ~UIDelegate();
52
53 #if ENABLE(CONTEXT_MENUS)
54     std::unique_ptr<API::ContextMenuClient> createContextMenuClient();
55 #endif
56     std::unique_ptr<API::UIClient> createUIClient();
57
58     RetainPtr<id <WKUIDelegate> > delegate();
59     void setDelegate(id <WKUIDelegate>);
60
61 private:
62 #if ENABLE(CONTEXT_MENUS)
63     class ContextMenuClient : public API::ContextMenuClient {
64     public:
65         explicit ContextMenuClient(UIDelegate&);
66         ~ContextMenuClient();
67
68     private:
69         // API::ContextMenuClient
70         RetainPtr<NSMenu> menuFromProposedMenu(WebPageProxy&, NSMenu *, const WebHitTestResultData&, API::Object*) override;
71
72         UIDelegate& m_uiDelegate;
73     };
74 #endif
75
76     class UIClient : public API::UIClient {
77     public:
78         explicit UIClient(UIDelegate&);
79         ~UIClient();
80
81     private:
82         // API::UIClient
83         void createNewPage(WebPageProxy&, Ref<API::FrameInfo>&&, WebCore::ResourceRequest&&, WebCore::WindowFeatures&&, NavigationActionData&&, CompletionHandler<void(RefPtr<WebPageProxy>&&)>&&) final;
84         void close(WebPageProxy*) final;
85         void fullscreenMayReturnToInline(WebPageProxy*) final;
86         void didEnterFullscreen(WebPageProxy*) final;
87         void didExitFullscreen(WebPageProxy*) final;
88         void runJavaScriptAlert(WebPageProxy*, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void()>&& completionHandler) final;
89         void runJavaScriptConfirm(WebPageProxy*, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(bool)>&& completionHandler) final;
90         void runJavaScriptPrompt(WebPageProxy*, const WTF::String&, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(const WTF::String&)>&&) 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 #if PLATFORM(MAC)
98         void showPage(WebPageProxy*) final;
99         void takeFocus(WebPageProxy*, WKFocusDirection) 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&, WebEvent::Modifiers, 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 WebCore::URL&, API::Data&) final;
122 #endif
123         bool decidePolicyForUserMediaPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionRequestProxy&) final;
124         bool checkUserMediaPermissionForOrigin(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionCheckProxy&) final;
125         void mediaCaptureStateDidChange(WebCore::MediaProducer::MediaStateFlags) final;
126         void printFrame(WebPageProxy&, WebFrameProxy&) final;
127 #if PLATFORM(IOS)
128 #if HAVE(APP_LINKS)
129         bool shouldIncludeAppLinkActionsForElement(_WKActivatedElementInfo *) final;
130 #endif
131         RetainPtr<NSArray> actionsForElement(_WKActivatedElementInfo *, RetainPtr<NSArray> defaultActions) final;
132         void didNotHandleTapAsClick(const WebCore::IntPoint&) final;
133         UIViewController *presentingViewController() final;
134 #endif // PLATFORM(IOS)
135
136         NSDictionary *dataDetectionContext() final;
137
138 #if ENABLE(POINTER_LOCK)
139         void requestPointerLock(WebPageProxy*) final;
140         void didLosePointerLock(WebPageProxy*) final;
141 #endif
142         
143         void hasVideoInPictureInPictureDidChange(WebPageProxy*, bool) final;
144
145         void imageOrMediaDocumentSizeChanged(const WebCore::IntSize&) final;
146
147         UIDelegate& m_uiDelegate;
148     };
149
150     WKWebView *m_webView;
151     WeakObjCPtr<id <WKUIDelegate> > m_delegate;
152
153     struct {
154         bool webViewCreateWebViewWithConfigurationForNavigationActionWindowFeatures : 1;
155         bool webViewCreateWebViewWithConfigurationForNavigationActionWindowFeaturesAsync : 1;
156         bool webViewRunJavaScriptAlertPanelWithMessageInitiatedByFrameCompletionHandler : 1;
157         bool webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
158         bool webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler : 1;
159         bool webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
160         bool webViewRequestGeolocationPermissionForFrameDecisionHandler : 1;
161 #if PLATFORM(MAC)
162         bool showWebView : 1;
163         bool focusWebView : 1;
164         bool unfocusWebView : 1;
165         bool webViewRunModal : 1;
166         bool webViewTakeFocus : 1;
167         bool webViewDidScroll : 1;
168         bool webViewHeaderHeight : 1;
169         bool webViewFooterHeight : 1;
170         bool webViewSetResizable : 1;
171         bool webViewSetWindowFrame : 1;
172         bool webViewDidNotHandleWheelEvent : 1;
173         bool webViewHandleAutoplayEventWithFlags : 1;
174         bool webViewUnavailablePlugInButtonClicked : 1;
175         bool webViewDidClickAutoFillButtonWithUserInfo : 1;
176         bool webViewDidResignInputElementStrongPasswordAppearanceWithUserInfo : 1;
177         bool webViewDrawHeaderInRectForPageWithTitleURL : 1;
178         bool webViewDrawFooterInRectForPageWithTitleURL : 1;
179         bool webViewGetWindowFrameWithCompletionHandler : 1;
180         bool webViewMouseDidMoveOverElementWithFlagsUserInfo : 1;
181         bool webViewGetToolbarsAreVisibleWithCompletionHandler : 1;
182         bool webViewDidExceedBackgroundResourceLimitWhileInForeground : 1;
183         bool webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL : 1;
184         bool webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler : 1;
185         bool webViewRequestNotificationPermissionForSecurityOriginDecisionHandler : 1;
186 #endif
187         bool webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler : 1;
188         bool webViewDecideWebApplicationCacheQuotaForSecurityOriginCurrentQuotaTotalBytesNeeded : 1;
189         bool webViewPrintFrame : 1;
190         bool webViewDidClose : 1;
191         bool webViewClose : 1;
192         bool webViewFullscreenMayReturnToInline : 1;
193         bool webViewDidEnterFullscreen : 1;
194         bool webViewDidExitFullscreen : 1;
195         bool webViewRequestUserMediaAuthorizationForDevicesURLMainFrameURLDecisionHandler : 1;
196         bool webViewCheckUserMediaPermissionForURLMainFrameURLFrameIdentifierDecisionHandler : 1;
197         bool webViewMediaCaptureStateDidChange : 1;
198 #if PLATFORM(IOS)
199 #if HAVE(APP_LINKS)
200         bool webViewShouldIncludeAppLinkActionsForElement : 1;
201 #endif
202         bool webViewActionsForElementDefaultActions : 1;
203         bool webViewDidNotHandleTapAsClickAtPoint : 1;
204         bool presentingViewControllerForWebView : 1;
205 #endif
206         bool dataDetectionContextForWebView : 1;
207         bool webViewImageOrMediaDocumentSizeChanged : 1;
208 #if ENABLE(POINTER_LOCK)
209         bool webViewRequestPointerLock : 1;
210         bool webViewDidLosePointerLock : 1;
211 #endif
212 #if ENABLE(CONTEXT_MENUS)
213         bool webViewContextMenuForElement : 1;
214         bool webViewContextMenuForElementUserInfo : 1;
215 #endif
216         bool webViewHasVideoInPictureInPictureDidChange : 1;
217     } m_delegateMethods;
218 };
219
220 } // namespace WebKit
221
222 #endif // WK_API_ENABLED