[ Mac Debug ] TestWebKitAPI.ProcessSwap.ReuseSuspendedProcessForRegularNavigationReta...
[WebKit-https.git] / Source / WebKit / UIProcess / ProvisionalPageProxy.h
1 /*
2  * Copyright (C) 2019 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 #include "MessageReceiver.h"
29 #include "SandboxExtension.h"
30 #include "WebFramePolicyListenerProxy.h"
31 #include "WebPageProxyMessages.h"
32 #include "WebsitePoliciesData.h"
33 #include <wtf/WeakPtr.h>
34
35 namespace API {
36 class Navigation;
37 }
38
39 namespace IPC {
40 class FormDataReference;
41 }
42
43 namespace WebCore {
44 class ResourceRequest;
45 struct BackForwardItemIdentifier;
46 }
47
48 namespace WebKit {
49
50 class DrawingAreaProxy;
51 class SuspendedPageProxy;
52 class UserData;
53 class WebFrameProxy;
54 class WebPageProxy;
55 class WebProcessProxy;
56 struct FrameInfoData;
57 struct NavigationActionData;
58 struct URLSchemeTaskParameters;
59 struct WebNavigationDataStore;
60
61 class ProvisionalPageProxy : public IPC::MessageReceiver, public CanMakeWeakPtr<ProvisionalPageProxy> {
62     WTF_MAKE_FAST_ALLOCATED;
63 public:
64     ProvisionalPageProxy(WebPageProxy&, Ref<WebProcessProxy>&&, std::unique_ptr<SuspendedPageProxy>, uint64_t navigationID, bool isServerRedirect, const WebCore::ResourceRequest&, ProcessSwapRequestedByClient);
65     ~ProvisionalPageProxy();
66
67     WebPageProxy& page() { return m_page; }
68     WebFrameProxy* mainFrame() const { return m_mainFrame.get(); }
69     WebProcessProxy& process() { return m_process.get(); }
70     ProcessSwapRequestedByClient processSwapRequestedByClient() const { return m_processSwapRequestedByClient; }
71     uint64_t navigationID() const { return m_navigationID; }
72     const URL& provisionalURL() const { return m_provisionalLoadURL; }
73
74     DrawingAreaProxy* drawingArea() const { return m_drawingArea.get(); }
75     std::unique_ptr<DrawingAreaProxy> takeDrawingArea();
76
77 #if PLATFORM(COCOA)
78     Vector<uint8_t> takeAccessibilityToken() { return WTFMove(m_accessibilityToken); }
79 #endif
80
81     void loadData(API::Navigation&, const IPC::DataReference&, const String& MIMEType, const String& encoding, const String& baseURL, API::Object* userData, Optional<WebsitePoliciesData>&& = WTF::nullopt);
82     void loadRequest(API::Navigation&, WebCore::ResourceRequest&&, WebCore::ShouldOpenExternalURLsPolicy, API::Object* userData, Optional<WebsitePoliciesData>&& = WTF::nullopt);
83     void goToBackForwardItem(API::Navigation&, WebBackForwardListItem&, Optional<WebsitePoliciesData>&&);
84     void cancel();
85
86     void processDidTerminate();
87     void connectionWillOpen(IPC::Connection&);
88
89 private:
90     // IPC::MessageReceiver
91     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
92     void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) final;
93
94     void decidePolicyForNavigationActionAsync(uint64_t frameID, WebCore::SecurityOriginData&&, WebCore::PolicyCheckIdentifier, uint64_t navigationID, NavigationActionData&&, FrameInfoData&&,
95         uint64_t originatingPageID, const WebCore::ResourceRequest& originalRequest, WebCore::ResourceRequest&&, IPC::FormDataReference&& requestBody,
96         WebCore::ResourceResponse&& redirectResponse, const UserData&, uint64_t listenerID);
97     void decidePolicyForResponse(uint64_t frameID, const WebCore::SecurityOriginData&, WebCore::PolicyCheckIdentifier, uint64_t navigationID, const WebCore::ResourceResponse&,
98         const WebCore::ResourceRequest&, bool canShowMIMEType, const String& downloadAttribute, uint64_t listenerID, const UserData&);
99     void didChangeProvisionalURLForFrame(uint64_t frameID, uint64_t navigationID, URL&&);
100     void didPerformServerRedirect(const String& sourceURLString, const String& destinationURLString, uint64_t frameID);
101     void didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, WebCore::ResourceRequest&&, const UserData&);
102     void didNavigateWithNavigationData(const WebNavigationDataStore&, uint64_t frameID);
103     void didPerformClientRedirect(const String& sourceURLString, const String& destinationURLString, uint64_t frameID);
104     void didCreateMainFrame(uint64_t frameID);
105     void didStartProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, URL&&, URL&& unreachableURL, const UserData&);
106     void didCommitLoadForFrame(uint64_t frameID, uint64_t navigationID, const String& mimeType, bool frameHasCustomContentProvider, uint32_t frameLoadType, const WebCore::CertificateInfo&, bool containsPluginDocument, Optional<WebCore::HasInsecureContent> forcedHasInsecureContent, const UserData&);
107     void didFailProvisionalLoadForFrame(uint64_t frameID, const WebCore::SecurityOriginData& frameSecurityOrigin, uint64_t navigationID, const String& provisionalURL, const WebCore::ResourceError&, const UserData&);
108     void startURLSchemeTask(URLSchemeTaskParameters&&);
109     void backForwardGoToItem(const WebCore::BackForwardItemIdentifier&, CompletionHandler<void(SandboxExtension::Handle&&)>&&);
110     void decidePolicyForNavigationActionSync(uint64_t frameID, bool isMainFrame, WebCore::SecurityOriginData&&, WebCore::PolicyCheckIdentifier, uint64_t navigationID, NavigationActionData&&,
111         FrameInfoData&&, uint64_t originatingPageID, const WebCore::ResourceRequest& originalRequest, WebCore::ResourceRequest&&, IPC::FormDataReference&& requestBody,
112         WebCore::ResourceResponse&& redirectResponse, const UserData&, Messages::WebPageProxy::DecidePolicyForNavigationActionSync::DelayedReply&&);
113 #if USE(QUICK_LOOK)
114     void didRequestPasswordForQuickLookDocumentInMainFrame(const String& fileName);
115 #endif
116 #if PLATFORM(COCOA)
117     void registerWebProcessAccessibilityToken(const IPC::DataReference&);
118 #endif
119
120     void initializeWebPage();
121     bool validateInput(uint64_t frameID, const Optional<uint64_t>& navigationID = WTF::nullopt);
122
123     WebPageProxy& m_page;
124     Ref<WebProcessProxy> m_process;
125     std::unique_ptr<DrawingAreaProxy> m_drawingArea;
126     RefPtr<WebFrameProxy> m_mainFrame;
127     uint64_t m_navigationID;
128     bool m_isServerRedirect;
129     WebCore::ResourceRequest m_request;
130     ProcessSwapRequestedByClient m_processSwapRequestedByClient;
131     bool m_wasCommitted { false };
132     URL m_provisionalLoadURL;
133
134 #if PLATFORM(COCOA)
135     Vector<uint8_t> m_accessibilityToken;
136 #endif
137 #if PLATFORM(IOS_FAMILY)
138     ProcessThrottler::ForegroundActivityToken m_suspensionToken;
139 #endif
140 };
141
142 } // namespace WebKit