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