Add WKUIDelegatePrivate equivalent of WKPageUIClient's toolbarsAreVisible
[WebKit-https.git] / Source / WebKit / UIProcess / Cocoa / UIDelegate.h
1 /*
2  * Copyright (C) 2014 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 }
44
45 namespace WebKit {
46
47 class UIDelegate {
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         RetainPtr<NSMenu> menuFromProposedMenu(WebPageProxy&, NSMenu *, const WebHitTestResultData&, API::Object*) 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         RefPtr<WebPageProxy> createNewPage(WebPageProxy*, API::FrameInfo&, WebCore::ResourceRequest&&, const WebCore::WindowFeatures&, NavigationActionData&&) final;
83         void createNewPageAsync(WebPageProxy*, API::FrameInfo&, WebCore::ResourceRequest&&, const WebCore::WindowFeatures&, NavigationActionData&&, WTF::Function<void(RefPtr<WebPageProxy>&&)>&& completionHandler) final;
84         bool canCreateNewPageAsync() final;
85         RefPtr<WebPageProxy> createNewPageCommon(WebPageProxy*, API::FrameInfo&, WebCore::ResourceRequest&&, const WebCore::WindowFeatures&, NavigationActionData&&, WTF::Function<void(RefPtr<WebPageProxy>&&)>&& completionHandler);
86
87         void close(WebPageProxy*) final;
88         void fullscreenMayReturnToInline(WebPageProxy*) final;
89         void didEnterFullscreen(WebPageProxy*) final;
90         void didExitFullscreen(WebPageProxy*) final;
91         void runJavaScriptAlert(WebPageProxy*, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void()>&& completionHandler) final;
92         void runJavaScriptConfirm(WebPageProxy*, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(bool)>&& completionHandler) final;
93         void runJavaScriptPrompt(WebPageProxy*, const WTF::String&, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(const WTF::String&)>&& completionHandler) 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 #if PLATFORM(MAC)
99         void showPage(WebPageProxy*) final;
100         void takeFocus(WebPageProxy*, WKFocusDirection) final;
101         void focus(WebPageProxy*) final;
102         void unfocus(WebPageProxy*) final;
103         void didNotHandleWheelEvent(WebPageProxy*, const NativeWebWheelEvent&) final;
104         void handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
105         void didClickAutoFillButton(WebPageProxy&, API::Object*) final;
106         void toolbarsAreVisible(WebKit::WebPageProxy&, Function<void(bool)>&&) final;
107         bool runOpenPanel(WebPageProxy*, WebFrameProxy*, const WebCore::SecurityOriginData&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) final;
108         void didExceedBackgroundResourceLimitWhileInForeground(WebPageProxy&, WKResourceLimit) final;
109         void saveDataToFileInDownloadsFolder(WebPageProxy*, const WTF::String&, const WTF::String&, const WebCore::URL&, API::Data&) final;
110 #endif
111         bool decidePolicyForUserMediaPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionRequestProxy&) final;
112         bool checkUserMediaPermissionForOrigin(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionCheckProxy&) final;
113         void mediaCaptureStateDidChange(WebCore::MediaProducer::MediaStateFlags) final;
114         void printFrame(WebPageProxy*, WebFrameProxy*) final;
115 #if PLATFORM(IOS)
116 #if HAVE(APP_LINKS)
117         bool shouldIncludeAppLinkActionsForElement(_WKActivatedElementInfo *) final;
118 #endif
119         RetainPtr<NSArray> actionsForElement(_WKActivatedElementInfo *, RetainPtr<NSArray> defaultActions) final;
120         void didNotHandleTapAsClick(const WebCore::IntPoint&) final;
121         UIViewController *presentingViewController() final;
122 #endif // PLATFORM(IOS)
123
124         NSDictionary *dataDetectionContext() final;
125
126 #if ENABLE(POINTER_LOCK)
127         void requestPointerLock(WebPageProxy*) final;
128         void didLosePointerLock(WebPageProxy*) final;
129 #endif
130         
131         void hasVideoInPictureInPictureDidChange(WebPageProxy*, bool) final;
132
133         void imageOrMediaDocumentSizeChanged(const WebCore::IntSize&) final;
134
135         UIDelegate& m_uiDelegate;
136     };
137
138     WKWebView *m_webView;
139     WeakObjCPtr<id <WKUIDelegate> > m_delegate;
140
141     struct {
142         bool webViewCreateWebViewWithConfigurationForNavigationActionWindowFeatures : 1;
143         bool webViewCreateWebViewWithConfigurationForNavigationActionWindowFeaturesAsync : 1;
144         bool webViewRunJavaScriptAlertPanelWithMessageInitiatedByFrameCompletionHandler : 1;
145         bool webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
146         bool webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler : 1;
147         bool webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
148 #if PLATFORM(MAC)
149         bool showWebView : 1;
150         bool focusWebView : 1;
151         bool unfocusWebView : 1;
152         bool webViewTakeFocus : 1;
153         bool webViewDidNotHandleWheelEvent : 1;
154         bool webViewHandleAutoplayEventWithFlags : 1;
155         bool webViewDidClickAutoFillButtonWithUserInfo : 1;
156         bool webViewGetToolbarsAreVisibleWithCompletionHandler : 1;
157         bool webViewDidExceedBackgroundResourceLimitWhileInForeground : 1;
158         bool webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL : 1;
159         bool webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler : 1;
160 #endif
161         bool webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler : 1;
162         bool webViewDecideWebApplicationCacheQuotaForSecurityOriginCurrentQuotaTotalBytesNeeded : 1;
163         bool webViewPrintFrame : 1;
164         bool webViewDidClose : 1;
165         bool webViewClose : 1;
166         bool webViewFullscreenMayReturnToInline : 1;
167         bool webViewDidEnterFullscreen : 1;
168         bool webViewDidExitFullscreen : 1;
169         bool webViewRequestUserMediaAuthorizationForDevicesURLMainFrameURLDecisionHandler : 1;
170         bool webViewCheckUserMediaPermissionForURLMainFrameURLFrameIdentifierDecisionHandler : 1;
171         bool webViewMediaCaptureStateDidChange : 1;
172 #if PLATFORM(IOS)
173 #if HAVE(APP_LINKS)
174         bool webViewShouldIncludeAppLinkActionsForElement : 1;
175 #endif
176         bool webViewActionsForElementDefaultActions : 1;
177         bool webViewDidNotHandleTapAsClickAtPoint : 1;
178         bool presentingViewControllerForWebView : 1;
179 #endif
180         bool dataDetectionContextForWebView : 1;
181         bool webViewImageOrMediaDocumentSizeChanged : 1;
182 #if ENABLE(POINTER_LOCK)
183         bool webViewRequestPointerLock : 1;
184         bool webViewDidLosePointerLock : 1;
185 #endif
186 #if ENABLE(CONTEXT_MENUS)
187         bool webViewContextMenuForElement : 1;
188         bool webViewContextMenuForElementUserInfo : 1;
189 #endif
190         bool webViewHasVideoInPictureInPictureDidChange : 1;
191     } m_delegateMethods;
192 };
193
194 } // namespace WebKit
195
196 #endif // WK_API_ENABLED