Add WKNavigationDelegate SPI to tell the client when an insecure plug-in is blocked
[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 "WeakObjCPtr.h"
38 #import <wtf/RetainPtr.h>
39 #import <wtf/RunLoop.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 private:
86     class NavigationClient final : public API::NavigationClient {
87     public:
88         explicit NavigationClient(NavigationState&);
89         ~NavigationClient();
90
91     private:
92         void didStartProvisionalNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
93         void didReceiveServerRedirectForProvisionalNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
94         void willPerformClientRedirect(WebPageProxy&, const WTF::String&, double) override;
95         void didCancelClientRedirect(WebPageProxy&) override;
96         void didFailProvisionalNavigationWithError(WebPageProxy&, WebFrameProxy&, API::Navigation*, const WebCore::ResourceError&, API::Object*) override;
97         void didFailProvisionalLoadInSubframeWithError(WebPageProxy&, WebFrameProxy&, const WebCore::SecurityOriginData&, API::Navigation*, const WebCore::ResourceError&, API::Object*) override;
98         void didCommitNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
99         void didFinishDocumentLoad(WebPageProxy&, API::Navigation*, API::Object*) override;
100         void didFinishNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
101         void didFailNavigationWithError(WebPageProxy&, WebFrameProxy&, API::Navigation*, const WebCore::ResourceError&, API::Object*) override;
102         void didSameDocumentNavigation(WebPageProxy&, API::Navigation*, SameDocumentNavigationType, API::Object*) override;
103
104         void renderingProgressDidChange(WebPageProxy&, WebCore::LayoutMilestones) override;
105
106         bool canAuthenticateAgainstProtectionSpace(WebPageProxy&, WebProtectionSpace*) override;
107         void didReceiveAuthenticationChallenge(WebPageProxy&, AuthenticationChallengeProxy&) override;
108         void processDidTerminate(WebPageProxy&, ProcessTerminationReason) override;
109         void processDidBecomeResponsive(WebPageProxy&) override;
110         void processDidBecomeUnresponsive(WebPageProxy&) override;
111
112         RefPtr<API::Data> webCryptoMasterKey(WebPageProxy&) override;
113
114 #if USE(QUICK_LOOK)
115         void didStartLoadForQuickLookDocumentInMainFrame(const WTF::String& fileName, const WTF::String& uti) override;
116         void didFinishLoadForQuickLookDocumentInMainFrame(const QuickLookDocumentData&) override;
117 #endif
118
119 #if PLATFORM(MAC)
120         void webGLLoadPolicy(WebPageProxy&, const WebCore::URL&, WTF::Function<void(WebCore::WebGLLoadPolicy)>&& completionHandler) const final;
121         void resolveWebGLLoadPolicy(WebPageProxy&, const WebCore::URL&, WTF::Function<void(WebCore::WebGLLoadPolicy)>&& completionHandler) const final;
122         bool willGoToBackForwardListItem(WebPageProxy&, WebBackForwardListItem&, bool inPageCache, API::Object*) final;
123         bool didFailToInitializePlugIn(WebPageProxy&, API::Dictionary&) final;
124         bool didBlockInsecurePluginVersion(WebPageProxy&, API::Dictionary&) final;
125         WebKit::PluginModuleLoadPolicy decidePolicyForPluginLoad(WebKit::WebPageProxy&, WebKit::PluginModuleLoadPolicy, API::Dictionary&, WTF::String&) final;
126         bool didChangeBackForwardList(WebPageProxy&, WebBackForwardListItem*, const Vector<Ref<WebBackForwardListItem>>&) final;
127 #endif
128
129         void contentRuleListNotification(WebPageProxy&, WebCore::URL&&, Vector<String>&&, Vector<String>&&) final;
130         void decidePolicyForNavigationAction(WebPageProxy&, Ref<API::NavigationAction>&&, Ref<WebFramePolicyListenerProxy>&&, API::Object* userData) override;
131         void decidePolicyForNavigationResponse(WebPageProxy&, Ref<API::NavigationResponse>&&, Ref<WebFramePolicyListenerProxy>&&, API::Object* userData) override;
132
133         NavigationState& m_navigationState;
134     };
135     
136     class HistoryClient final : public API::HistoryClient {
137     public:
138         explicit HistoryClient(NavigationState&);
139         ~HistoryClient();
140         
141     private:
142         void didNavigateWithNavigationData(WebPageProxy&, const WebNavigationDataStore&) override;
143         void didPerformClientRedirect(WebPageProxy&, const WTF::String&, const WTF::String&) override;
144         void didPerformServerRedirect(WebPageProxy&, const WTF::String&, const WTF::String&) override;
145         void didUpdateHistoryTitle(WebPageProxy&, const WTF::String&, const WTF::String&) override;
146         
147         NavigationState& m_navigationState;
148     };
149
150     // PageLoadState::Observer
151     void willChangeIsLoading() override;
152     void didChangeIsLoading() override;
153     void willChangeTitle() override;
154     void didChangeTitle() override;
155     void willChangeActiveURL() override;
156     void didChangeActiveURL() override;
157     void willChangeHasOnlySecureContent() override;
158     void didChangeHasOnlySecureContent() override;
159     void willChangeEstimatedProgress() override;
160     void didChangeEstimatedProgress() override;
161     void willChangeCanGoBack() override;
162     void didChangeCanGoBack() override;
163     void willChangeCanGoForward() override;
164     void didChangeCanGoForward() override;
165     void willChangeNetworkRequestsInProgress() override;
166     void didChangeNetworkRequestsInProgress() override;
167     void willChangeCertificateInfo() override;
168     void didChangeCertificateInfo() override;
169     void willChangeWebProcessIsResponsive() override;
170     void didChangeWebProcessIsResponsive() override;
171
172 #if PLATFORM(IOS)
173     void releaseNetworkActivityToken();
174 #endif
175
176     WKWebView *m_webView;
177     WeakObjCPtr<id <WKNavigationDelegate> > m_navigationDelegate;
178
179     struct {
180         bool webViewDecidePolicyForNavigationActionDecisionHandler : 1;
181         bool webViewDecidePolicyForNavigationActionDecisionHandlerWebsitePolicies : 1;
182         bool webViewDecidePolicyForNavigationActionUserInfoDecisionHandlerWebsitePolicies : 1;
183         bool webViewDecidePolicyForNavigationResponseDecisionHandler : 1;
184
185         bool webViewDidStartProvisionalNavigation : 1;
186         bool webViewDidStartProvisionalNavigationUserInfo : 1;
187         bool webViewDidReceiveServerRedirectForProvisionalNavigation : 1;
188         bool webViewDidFailProvisionalNavigationWithError : 1;
189         bool webViewNavigationDidFailProvisionalLoadInSubframeWithError : 1;
190         bool webViewWillPerformClientRedirect : 1;
191         bool webViewDidCancelClientRedirect : 1;
192         bool webViewDidCommitNavigation : 1;
193         bool webViewNavigationDidFinishDocumentLoad : 1;
194         bool webViewDidFinishNavigation : 1;
195         bool webViewDidFailNavigationWithError : 1;
196         bool webViewDidFailNavigationWithErrorUserInfo : 1;
197         bool webViewNavigationDidSameDocumentNavigation : 1;
198
199         bool webViewRenderingProgressDidChange : 1;
200         bool webViewDidReceiveAuthenticationChallengeCompletionHandler : 1;
201         bool webViewWebContentProcessDidTerminate : 1;
202         bool webViewWebContentProcessDidTerminateWithReason : 1;
203         bool webViewCanAuthenticateAgainstProtectionSpace : 1;
204         bool webViewDidReceiveAuthenticationChallenge : 1;
205         bool webViewWebProcessDidCrash : 1;
206         bool webViewWebProcessDidBecomeResponsive : 1;
207         bool webViewWebProcessDidBecomeUnresponsive : 1;
208         bool webCryptoMasterKeyForWebView : 1;
209         bool webViewDidBeginNavigationGesture : 1;
210         bool webViewWillEndNavigationGestureWithNavigationToBackForwardListItem : 1;
211         bool webViewDidEndNavigationGestureWithNavigationToBackForwardListItem : 1;
212         bool webViewWillSnapshotBackForwardListItem : 1;
213         bool webViewNavigationGestureSnapshotWasRemoved : 1;
214         bool webViewURLContentRuleListIdentifiersNotifications : 1;
215 #if USE(QUICK_LOOK)
216         bool webViewDidStartLoadForQuickLookDocumentInMainFrame : 1;
217         bool webViewDidFinishLoadForQuickLookDocumentInMainFrame : 1;
218         bool webViewDidRequestPasswordForQuickLookDocument : 1;
219 #endif
220
221 #if PLATFORM(MAC)
222         bool webViewWebGLLoadPolicyForURL : 1;
223         bool webViewResolveWebGLLoadPolicyForURL : 1;
224         bool webViewBackForwardListItemAddedRemoved : 1;
225         bool webViewDidFailToInitializePlugInWithInfo : 1;
226         bool webViewDidBlockInsecurePluginVersionWithInfo : 1;
227         bool webViewWillGoToBackForwardListItemInPageCache : 1;
228         bool webViewDecidePolicyForPluginLoadWithCurrentPolicyPluginInfoUnavailabilityDescription : 1;
229 #endif
230     } m_navigationDelegateMethods;
231
232     WeakObjCPtr<id <WKHistoryDelegatePrivate> > m_historyDelegate;
233     struct {
234         bool webViewDidNavigateWithNavigationData : 1;
235         bool webViewDidPerformClientRedirectFromURLToURL : 1;
236         bool webViewDidPerformServerRedirectFromURLToURL : 1;
237         bool webViewDidUpdateHistoryTitleForURL : 1;
238     } m_historyDelegateMethods;
239
240 #if PLATFORM(IOS)
241     ProcessThrottler::BackgroundActivityToken m_activityToken;
242     RunLoop::Timer<NavigationState> m_releaseActivityTimer;
243 #endif
244 };
245
246 } // namespace WebKit
247
248 #endif