Remove WKNavigationDelegatePrivate's canAuthenticateAgainstProtectionSpace
[WebKit-https.git] / Source / WebKit / UIProcess / Cocoa / NavigationState.h
1 /*
2  * Copyright (C) 2014-2016 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 "APIHistoryClient.h"
33 #import "APINavigationClient.h"
34 #import "PageLoadState.h"
35 #import "ProcessTerminationReason.h"
36 #import "ProcessThrottler.h"
37 #import <wtf/RetainPtr.h>
38 #import <wtf/RunLoop.h>
39 #import <wtf/WeakObjCPtr.h>
40
41 @class WKWebView;
42 @protocol WKHistoryDelegatePrivate;
43 @protocol WKNavigationDelegate;
44
45 namespace API {
46 class Navigation;
47 }
48
49 namespace WebCore {
50 struct SecurityOriginData;
51 }
52
53 namespace WebKit {
54
55 struct WebNavigationDataStore;
56
57 class NavigationState final : private PageLoadState::Observer {
58 public:
59     explicit NavigationState(WKWebView *);
60     ~NavigationState();
61
62     static NavigationState& fromWebPage(WebPageProxy&);
63
64     std::unique_ptr<API::NavigationClient> createNavigationClient();
65     std::unique_ptr<API::HistoryClient> createHistoryClient();
66
67     RetainPtr<id <WKNavigationDelegate> > navigationDelegate();
68     void setNavigationDelegate(id <WKNavigationDelegate>);
69
70     RetainPtr<id <WKHistoryDelegatePrivate> > historyDelegate();
71     void setHistoryDelegate(id <WKHistoryDelegatePrivate>);
72
73     // Called by the page client.
74     void navigationGestureDidBegin();
75     void navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem&);
76     void navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem&);
77     void willRecordNavigationSnapshot(WebBackForwardListItem&);
78     void navigationGestureSnapshotWasRemoved();
79 #if USE(QUICK_LOOK)
80     void didRequestPasswordForQuickLookDocument();
81 #endif
82
83     void didFirstPaint();
84
85 #if PLATFORM(IOS)
86     enum class NetworkActivityTokenReleaseReason { LoadCompleted, ScreenLocked };
87     void releaseNetworkActivityToken(NetworkActivityTokenReleaseReason);
88 #endif
89
90 private:
91     class NavigationClient final : public API::NavigationClient {
92     public:
93         explicit NavigationClient(NavigationState&);
94         ~NavigationClient();
95
96     private:
97         void didStartProvisionalNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
98         void didReceiveServerRedirectForProvisionalNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
99         void willPerformClientRedirect(WebPageProxy&, const WTF::String&, double) override;
100         void didCancelClientRedirect(WebPageProxy&) override;
101         void didFailProvisionalNavigationWithError(WebPageProxy&, WebFrameProxy&, API::Navigation*, const WebCore::ResourceError&, API::Object*) override;
102         void didFailProvisionalLoadInSubframeWithError(WebPageProxy&, WebFrameProxy&, const WebCore::SecurityOriginData&, API::Navigation*, const WebCore::ResourceError&, API::Object*) override;
103         void didCommitNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
104         void didFinishDocumentLoad(WebPageProxy&, API::Navigation*, API::Object*) override;
105         void didFinishNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
106         void didFailNavigationWithError(WebPageProxy&, WebFrameProxy&, API::Navigation*, const WebCore::ResourceError&, API::Object*) override;
107         void didSameDocumentNavigation(WebPageProxy&, API::Navigation*, SameDocumentNavigationType, API::Object*) override;
108
109         void renderingProgressDidChange(WebPageProxy&, WebCore::LayoutMilestones) override;
110
111         bool canAuthenticateAgainstProtectionSpace(WebPageProxy&, WebProtectionSpace*) override;
112         void didReceiveAuthenticationChallenge(WebPageProxy&, AuthenticationChallengeProxy&) override;
113         bool processDidTerminate(WebPageProxy&, ProcessTerminationReason) override;
114         void processDidBecomeResponsive(WebPageProxy&) override;
115         void processDidBecomeUnresponsive(WebPageProxy&) override;
116
117         RefPtr<API::Data> webCryptoMasterKey(WebPageProxy&) override;
118
119         RefPtr<API::String> signedPublicKeyAndChallengeString(WebPageProxy&, unsigned keySizeIndex, const RefPtr<API::String>& challengeString, const WebCore::URL&) override;
120
121 #if USE(QUICK_LOOK)
122         void didStartLoadForQuickLookDocumentInMainFrame(const WTF::String& fileName, const WTF::String& uti) override;
123         void didFinishLoadForQuickLookDocumentInMainFrame(const QuickLookDocumentData&) override;
124 #endif
125
126 #if PLATFORM(MAC)
127         void webGLLoadPolicy(WebPageProxy&, const WebCore::URL&, WTF::Function<void(WebCore::WebGLLoadPolicy)>&& completionHandler) const final;
128         void resolveWebGLLoadPolicy(WebPageProxy&, const WebCore::URL&, WTF::Function<void(WebCore::WebGLLoadPolicy)>&& completionHandler) const final;
129         bool willGoToBackForwardListItem(WebPageProxy&, WebBackForwardListItem&, bool inPageCache, API::Object*) final;
130         bool didFailToInitializePlugIn(WebPageProxy&, API::Dictionary&) final;
131         bool didBlockInsecurePluginVersion(WebPageProxy&, API::Dictionary&) final;
132         WebKit::PluginModuleLoadPolicy decidePolicyForPluginLoad(WebKit::WebPageProxy&, WebKit::PluginModuleLoadPolicy, API::Dictionary&, WTF::String&) final;
133         bool didChangeBackForwardList(WebPageProxy&, WebBackForwardListItem*, const Vector<Ref<WebBackForwardListItem>>&) final;
134 #endif
135
136         void contentRuleListNotification(WebPageProxy&, WebCore::URL&&, Vector<String>&&, Vector<String>&&) final;
137         void decidePolicyForNavigationAction(WebPageProxy&, Ref<API::NavigationAction>&&, Ref<WebFramePolicyListenerProxy>&&, API::Object* userData) override;
138         void decidePolicyForNavigationResponse(WebPageProxy&, Ref<API::NavigationResponse>&&, Ref<WebFramePolicyListenerProxy>&&, API::Object* userData) override;
139
140         NavigationState& m_navigationState;
141     };
142     
143     class HistoryClient final : public API::HistoryClient {
144     public:
145         explicit HistoryClient(NavigationState&);
146         ~HistoryClient();
147         
148     private:
149         void didNavigateWithNavigationData(WebPageProxy&, const WebNavigationDataStore&) override;
150         void didPerformClientRedirect(WebPageProxy&, const WTF::String&, const WTF::String&) override;
151         void didPerformServerRedirect(WebPageProxy&, const WTF::String&, const WTF::String&) override;
152         void didUpdateHistoryTitle(WebPageProxy&, const WTF::String&, const WTF::String&) override;
153         
154         NavigationState& m_navigationState;
155     };
156
157     // PageLoadState::Observer
158     void willChangeIsLoading() override;
159     void didChangeIsLoading() override;
160     void willChangeTitle() override;
161     void didChangeTitle() override;
162     void willChangeActiveURL() override;
163     void didChangeActiveURL() override;
164     void willChangeHasOnlySecureContent() override;
165     void didChangeHasOnlySecureContent() override;
166     void willChangeEstimatedProgress() override;
167     void didChangeEstimatedProgress() override;
168     void willChangeCanGoBack() override;
169     void didChangeCanGoBack() override;
170     void willChangeCanGoForward() override;
171     void didChangeCanGoForward() override;
172     void willChangeNetworkRequestsInProgress() override;
173     void didChangeNetworkRequestsInProgress() override;
174     void willChangeCertificateInfo() override;
175     void didChangeCertificateInfo() override;
176     void willChangeWebProcessIsResponsive() override;
177     void didChangeWebProcessIsResponsive() override;
178
179 #if PLATFORM(IOS)
180     void releaseNetworkActivityTokenAfterLoadCompletion() { releaseNetworkActivityToken(NetworkActivityTokenReleaseReason::LoadCompleted); }
181 #endif
182
183     WKWebView *m_webView;
184     WeakObjCPtr<id <WKNavigationDelegate> > m_navigationDelegate;
185
186     struct {
187         bool webViewDecidePolicyForNavigationActionDecisionHandler : 1;
188         bool webViewDecidePolicyForNavigationActionDecisionHandlerWebsitePolicies : 1;
189         bool webViewDecidePolicyForNavigationActionUserInfoDecisionHandlerWebsitePolicies : 1;
190         bool webViewDecidePolicyForNavigationResponseDecisionHandler : 1;
191
192         bool webViewDidStartProvisionalNavigation : 1;
193         bool webViewDidStartProvisionalNavigationUserInfo : 1;
194         bool webViewDidReceiveServerRedirectForProvisionalNavigation : 1;
195         bool webViewDidFailProvisionalNavigationWithError : 1;
196         bool webViewNavigationDidFailProvisionalLoadInSubframeWithError : 1;
197         bool webViewWillPerformClientRedirect : 1;
198         bool webViewDidCancelClientRedirect : 1;
199         bool webViewDidCommitNavigation : 1;
200         bool webViewNavigationDidFinishDocumentLoad : 1;
201         bool webViewDidFinishNavigation : 1;
202         bool webViewDidFailNavigationWithError : 1;
203         bool webViewDidFailNavigationWithErrorUserInfo : 1;
204         bool webViewNavigationDidSameDocumentNavigation : 1;
205
206         bool webViewRenderingProgressDidChange : 1;
207         bool webViewDidReceiveAuthenticationChallengeCompletionHandler : 1;
208         bool webViewWebContentProcessDidTerminate : 1;
209         bool webViewWebContentProcessDidTerminateWithReason : 1;
210         bool webViewDidReceiveAuthenticationChallenge : 1;
211         bool webViewWebProcessDidCrash : 1;
212         bool webViewWebProcessDidBecomeResponsive : 1;
213         bool webViewWebProcessDidBecomeUnresponsive : 1;
214         bool webCryptoMasterKeyForWebView : 1;
215         bool webViewDidBeginNavigationGesture : 1;
216         bool webViewWillEndNavigationGestureWithNavigationToBackForwardListItem : 1;
217         bool webViewDidEndNavigationGestureWithNavigationToBackForwardListItem : 1;
218         bool webViewWillSnapshotBackForwardListItem : 1;
219         bool webViewNavigationGestureSnapshotWasRemoved : 1;
220         bool webViewURLContentRuleListIdentifiersNotifications : 1;
221 #if USE(QUICK_LOOK)
222         bool webViewDidStartLoadForQuickLookDocumentInMainFrame : 1;
223         bool webViewDidFinishLoadForQuickLookDocumentInMainFrame : 1;
224         bool webViewDidRequestPasswordForQuickLookDocument : 1;
225 #endif
226
227 #if PLATFORM(MAC)
228         bool webViewWebGLLoadPolicyForURL : 1;
229         bool webViewResolveWebGLLoadPolicyForURL : 1;
230         bool webViewBackForwardListItemAddedRemoved : 1;
231         bool webViewDidFailToInitializePlugInWithInfo : 1;
232         bool webViewDidBlockInsecurePluginVersionWithInfo : 1;
233         bool webViewWillGoToBackForwardListItemInPageCache : 1;
234         bool webViewDecidePolicyForPluginLoadWithCurrentPolicyPluginInfoUnavailabilityDescription : 1;
235 #endif
236     } m_navigationDelegateMethods;
237
238     WeakObjCPtr<id <WKHistoryDelegatePrivate> > m_historyDelegate;
239     struct {
240         bool webViewDidNavigateWithNavigationData : 1;
241         bool webViewDidPerformClientRedirectFromURLToURL : 1;
242         bool webViewDidPerformServerRedirectFromURLToURL : 1;
243         bool webViewDidUpdateHistoryTitleForURL : 1;
244     } m_historyDelegateMethods;
245
246 #if PLATFORM(IOS)
247     ProcessThrottler::BackgroundActivityToken m_activityToken;
248     RunLoop::Timer<NavigationState> m_releaseActivityTimer;
249 #endif
250 };
251
252 } // namespace WebKit
253
254 #endif