Check for navigation to app-bound domain during script evaluation
[WebKit-https.git] / Source / WebKit / UIProcess / ProvisionalPageProxy.cpp
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 #include "config.h"
27 #include "ProvisionalPageProxy.h"
28
29 #include "APINavigation.h"
30 #include "DrawingAreaProxy.h"
31 #include "FormDataReference.h"
32 #include "Logging.h"
33 #include "PageClient.h"
34 #include "URLSchemeTaskParameters.h"
35 #include "WebBackForwardCacheEntry.h"
36 #include "WebBackForwardList.h"
37 #include "WebBackForwardListItem.h"
38 #include "WebErrors.h"
39 #include "WebNavigationDataStore.h"
40 #include "WebNavigationState.h"
41 #include "WebPageInspectorController.h"
42 #include "WebPageMessages.h"
43 #include "WebPageProxy.h"
44 #include "WebPageProxyMessages.h"
45 #include "WebProcessMessages.h"
46 #include "WebProcessPool.h"
47 #include "WebProcessProxy.h"
48 #include <WebCore/ShouldTreatAsContinuingLoad.h>
49
50 namespace WebKit {
51
52 using namespace WebCore;
53
54 #define RELEASE_LOG_IF_ALLOWED(channel, fmt, ...) RELEASE_LOG_IF(m_page.isAlwaysOnLoggingAllowed(), channel, "%p - ProvisionalPageProxy::" fmt, this, ##__VA_ARGS__)
55 #define RELEASE_LOG_ERROR_IF_ALLOWED(channel, fmt, ...) RELEASE_LOG_ERROR_IF(m_page.isAlwaysOnLoggingAllowed(), channel, "%p - ProvisionalPageProxy::" fmt, this, ##__VA_ARGS__)
56
57 ProvisionalPageProxy::ProvisionalPageProxy(WebPageProxy& page, Ref<WebProcessProxy>&& process, std::unique_ptr<SuspendedPageProxy> suspendedPage, uint64_t navigationID, bool isServerRedirect, const WebCore::ResourceRequest& request, ProcessSwapRequestedByClient processSwapRequestedByClient)
58     : m_page(page)
59     , m_webPageID(suspendedPage ? suspendedPage->webPageID() : PageIdentifier::generate())
60     , m_process(WTFMove(process))
61     , m_navigationID(navigationID)
62     , m_isServerRedirect(isServerRedirect)
63     , m_request(request)
64     , m_processSwapRequestedByClient(processSwapRequestedByClient)
65 #if PLATFORM(IOS_FAMILY)
66     , m_provisionalLoadActivity(m_process->throttler().foregroundActivity("Provisional Load"_s))
67 #endif
68 #if HAVE(VISIBILITY_PROPAGATION_VIEW)
69     , m_contextIDForVisibilityPropagation(suspendedPage ? suspendedPage->contextIDForVisibilityPropagation() : 0)
70 #endif
71 {
72     RELEASE_LOG_IF_ALLOWED(ProcessSwapping, "ProvisionalPageProxy: pageProxyID=%" PRIu64 " webPageID=%" PRIu64 " navigationID=%" PRIu64 " suspendedPage: %p", m_page.identifier().toUInt64(), m_webPageID.toUInt64(), navigationID, suspendedPage.get());
73
74     m_process->addMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_webPageID, *this);
75     m_process->addProvisionalPageProxy(*this);
76
77     if (&m_process->websiteDataStore() != &m_page.websiteDataStore())
78         m_process->processPool().pageBeginUsingWebsiteDataStore(m_page.identifier(), m_process->websiteDataStore());
79
80     // If we are reattaching to a SuspendedPage, then the WebProcess' WebPage already exists and
81     // WebPageProxy::didCreateMainFrame() will not be called to initialize m_mainFrame. In such
82     // case, we need to initialize m_mainFrame to reflect the fact the the WebProcess' WebPage
83     // already exists and already has a main frame.
84     if (suspendedPage) {
85         ASSERT(&suspendedPage->process() == m_process.ptr());
86         suspendedPage->unsuspend();
87         m_mainFrame = WebFrameProxy::create(m_page, suspendedPage->mainFrameID());
88         m_process->frameCreated(suspendedPage->mainFrameID(), *m_mainFrame);
89     }
90
91     initializeWebPage();
92
93     m_page.inspectorController().didCreateProvisionalPage(*this);
94 }
95
96 ProvisionalPageProxy::~ProvisionalPageProxy()
97 {
98     if (!m_wasCommitted) {
99         m_page.inspectorController().willDestroyProvisionalPage(*this);
100
101         if (&m_process->websiteDataStore() != &m_page.websiteDataStore())
102             m_process->processPool().pageEndUsingWebsiteDataStore(m_page.identifier(), m_process->websiteDataStore());
103
104         m_process->removeMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_webPageID);
105         send(Messages::WebPage::Close());
106         m_process->removeVisitedLinkStoreUser(m_page.visitedLinkStore(), m_page.identifier());
107     }
108
109     m_process->removeProvisionalPageProxy(*this);
110 }
111
112 void ProvisionalPageProxy::processDidTerminate()
113 {
114     RELEASE_LOG_ERROR_IF_ALLOWED(ProcessSwapping, "processDidTerminate: pageProxyID=%" PRIu64 " webPageID=%" PRIu64, m_page.identifier().toUInt64(), m_webPageID.toUInt64());
115     m_page.provisionalProcessDidTerminate();
116 }
117
118 std::unique_ptr<DrawingAreaProxy> ProvisionalPageProxy::takeDrawingArea()
119 {
120     return WTFMove(m_drawingArea);
121 }
122
123 void ProvisionalPageProxy::cancel()
124 {
125     // If the provisional load started, then indicate that it failed due to cancellation by calling didFailProvisionalLoadForFrame().
126     if (m_provisionalLoadURL.isEmpty())
127         return;
128         
129     ASSERT(m_process->state() == WebProcessProxy::State::Running);
130
131     RELEASE_LOG_IF_ALLOWED(ProcessSwapping, "cancel: Simulating a didFailProvisionalLoadForFrame for pageProxyID=%" PRIu64 " webPageID=%" PRIu64, m_page.identifier().toUInt64(), m_webPageID.toUInt64());
132     ASSERT(m_mainFrame);
133     auto error = WebKit::cancelledError(m_request);
134     error.setType(WebCore::ResourceError::Type::Cancellation);
135     didFailProvisionalLoadForFrame(m_mainFrame->frameID(), { }, m_navigationID, m_provisionalLoadURL, error, WebCore::WillContinueLoading::No, UserData { }); // Will delete |this|.
136 }
137
138 void ProvisionalPageProxy::initializeWebPage()
139 {
140     m_drawingArea = m_page.pageClient().createDrawingAreaProxy(m_process);
141
142     auto parameters = m_page.creationParameters(m_process, *m_drawingArea);
143     parameters.isProcessSwap = true;
144     m_process->send(Messages::WebProcess::CreateWebPage(m_webPageID, parameters), 0);
145     m_process->addVisitedLinkStoreUser(m_page.visitedLinkStore(), m_page.identifier());
146
147     if (m_page.isLayerTreeFrozenDueToSwipeAnimation())
148         send(Messages::WebPage::FreezeLayerTreeDueToSwipeAnimation());
149 }
150
151 void ProvisionalPageProxy::loadData(API::Navigation& navigation, const IPC::DataReference& data, const String& MIMEType, const String& encoding, const String& baseURL, API::Object* userData, NavigatingToAppBoundDomain isNavigatingToAppBoundDomain, NavigatedAwayFromAppBoundDomain hasNavigatedAwayFromAppBoundDomain, Optional<WebsitePoliciesData>&& websitePolicies)
152 {
153     RELEASE_LOG_IF_ALLOWED(ProcessSwapping, "loadData: pageProxyID=%" PRIu64 " webPageID=%" PRIu64, m_page.identifier().toUInt64(), m_webPageID.toUInt64());
154
155     m_page.loadDataWithNavigationShared(m_process.copyRef(), m_webPageID, navigation, data, MIMEType, encoding, baseURL, userData, WebCore::ShouldTreatAsContinuingLoad::Yes, isNavigatingToAppBoundDomain, hasNavigatedAwayFromAppBoundDomain, WTFMove(websitePolicies), navigation.lastNavigationAction().shouldOpenExternalURLsPolicy);
156 }
157
158 void ProvisionalPageProxy::loadRequest(API::Navigation& navigation, WebCore::ResourceRequest&& request, API::Object* userData, NavigatingToAppBoundDomain isNavigatingToAppBoundDomain, NavigatedAwayFromAppBoundDomain hasNavigatedAwayFromAppBoundDomain, Optional<WebsitePoliciesData>&& websitePolicies)
159 {
160     RELEASE_LOG_IF_ALLOWED(ProcessSwapping, "loadRequest: pageProxyID=%" PRIu64 " webPageID=%" PRIu64, m_page.identifier().toUInt64(), m_webPageID.toUInt64());
161
162     // If this is a client-side redirect continuing in a new process, then the new process will overwrite the fromItem's URL. In this case,
163     // we need to make sure we update fromItem's processIdentifier as we want future navigations to this BackForward item to happen in the
164     // new process.
165     if (navigation.fromItem() && navigation.lockBackForwardList() == WebCore::LockBackForwardList::Yes)
166         navigation.fromItem()->setLastProcessIdentifier(m_process->coreProcessIdentifier());
167
168     m_page.loadRequestWithNavigationShared(m_process.copyRef(), m_webPageID, navigation, WTFMove(request), navigation.lastNavigationAction().shouldOpenExternalURLsPolicy, userData, WebCore::ShouldTreatAsContinuingLoad::Yes, isNavigatingToAppBoundDomain, hasNavigatedAwayFromAppBoundDomain, WTFMove(websitePolicies));
169 }
170
171 void ProvisionalPageProxy::goToBackForwardItem(API::Navigation& navigation, WebBackForwardListItem& item, Optional<WebsitePoliciesData>&& websitePolicies)
172 {
173     RELEASE_LOG_IF_ALLOWED(ProcessSwapping, "goToBackForwardItem: pageProxyID=%" PRIu64 " webPageID=%" PRIu64, m_page.identifier().toUInt64(), m_webPageID.toUInt64());
174
175     auto itemStates = m_page.backForwardList().filteredItemStates([this, targetItem = &item](auto& item) {
176         if (auto* backForwardCacheEntry = item.backForwardCacheEntry()) {
177             if (backForwardCacheEntry->processIdentifier() == m_process->coreProcessIdentifier())
178                 return false;
179         }
180         return &item != targetItem;
181     });
182     send(Messages::WebPage::UpdateBackForwardListForReattach(WTFMove(itemStates)));
183     send(Messages::WebPage::GoToBackForwardItem(navigation.navigationID(), item.itemID(), *navigation.backForwardFrameLoadType(), WebCore::ShouldTreatAsContinuingLoad::Yes, WTFMove(websitePolicies)));
184     m_process->startResponsivenessTimer();
185 }
186
187 inline bool ProvisionalPageProxy::validateInput(FrameIdentifier frameID, const Optional<uint64_t>& navigationID)
188 {
189     // If the previous provisional load used an existing process, we may receive leftover IPC for a previous navigation, which we need to ignore.
190     if (!m_mainFrame || m_mainFrame->frameID() != frameID)
191         return false;
192
193     return !navigationID || !*navigationID || *navigationID == m_navigationID;
194 }
195
196 void ProvisionalPageProxy::didCreateMainFrame(FrameIdentifier frameID)
197 {
198     RELEASE_LOG_IF_ALLOWED(ProcessSwapping, "didCreateMainFrame: pageProxyID=%" PRIu64 " webPageID=%" PRIu64 ", frameID=%" PRIu64, m_page.identifier().toUInt64(), m_webPageID.toUInt64(), frameID.toUInt64());
199     ASSERT(!m_mainFrame);
200
201     m_mainFrame = WebFrameProxy::create(m_page, frameID);
202
203     // Add the frame to the process wide map.
204     m_process->frameCreated(frameID, *m_mainFrame);
205
206     // This navigation was destroyed so no need to notify of redirect.
207     if (!m_page.navigationState().hasNavigation(m_navigationID))
208         return;
209
210     // Restore the main frame's committed URL as some clients may rely on it until the next load is committed.
211     if (auto* mainFrame = m_page.mainFrame())
212         m_mainFrame->frameLoadState().setURL(mainFrame->frameLoadState().url());
213
214     // Normally, notification of a server redirect comes from the WebContent process.
215     // If we are process swapping in response to a server redirect then that notification will not come from the new WebContent process.
216     // In this case we have the UIProcess synthesize the redirect notification at the appropriate time.
217     if (m_isServerRedirect) {
218         m_mainFrame->frameLoadState().didStartProvisionalLoad(m_request.url());
219         m_page.didReceiveServerRedirectForProvisionalLoadForFrameShared(m_process.copyRef(), m_mainFrame->frameID(), m_navigationID, WTFMove(m_request), { });
220     }
221 }
222
223 void ProvisionalPageProxy::didPerformClientRedirect(const String& sourceURLString, const String& destinationURLString, FrameIdentifier frameID)
224 {
225     if (!validateInput(frameID))
226         return;
227
228     m_page.didPerformClientRedirectShared(m_process.copyRef(), sourceURLString, destinationURLString, frameID);
229 }
230
231 void ProvisionalPageProxy::didStartProvisionalLoadForFrame(FrameIdentifier frameID, uint64_t navigationID, URL&& url, URL&& unreachableURL, const UserData& userData)
232 {
233     if (!validateInput(frameID, navigationID))
234         return;
235
236     RELEASE_LOG_IF_ALLOWED(ProcessSwapping, "didStartProvisionalLoadForFrame: pageProxyID=%" PRIu64 " webPageID=%" PRIu64 ", frameID=%" PRIu64 ", navigationID=%" PRIu64, m_page.identifier().toUInt64(), m_webPageID.toUInt64(), frameID.toUInt64(), navigationID);
237     ASSERT(m_provisionalLoadURL.isNull());
238     m_provisionalLoadURL = url;
239
240     // Merely following a server side redirect so there is no need to send a didStartProvisionalLoad again.
241     if (m_isServerRedirect)
242         return;
243
244     // Clients expect the Page's main frame's expectedURL to be the provisional one when a provisional load is started.
245     if (auto* pageMainFrame = m_page.mainFrame())
246         pageMainFrame->didStartProvisionalLoad(url);
247
248     m_page.didStartProvisionalLoadForFrameShared(m_process.copyRef(), frameID, navigationID, WTFMove(url), WTFMove(unreachableURL), userData);
249 }
250
251 void ProvisionalPageProxy::didFailProvisionalLoadForFrame(FrameIdentifier frameID, FrameInfoData&& frameInfo, uint64_t navigationID, const String& provisionalURL, const WebCore::ResourceError& error, WebCore::WillContinueLoading willContinueLoading, const UserData& userData)
252 {
253     if (!validateInput(frameID, navigationID))
254         return;
255
256     RELEASE_LOG_ERROR_IF_ALLOWED(ProcessSwapping, "didFailProvisionalLoadForFrame: pageProxyID=%" PRIu64 " webPageID=%" PRIu64 ", frameID=%" PRIu64 ", navigationID=%" PRIu64, m_page.identifier().toUInt64(), m_webPageID.toUInt64(), frameID.toUInt64(), navigationID);
257     ASSERT(!m_provisionalLoadURL.isNull());
258     m_provisionalLoadURL = { };
259
260     // Make sure the Page's main frame's expectedURL gets cleared since we updated it in didStartProvisionalLoad.
261     if (auto* pageMainFrame = m_page.mainFrame())
262         pageMainFrame->didFailProvisionalLoad();
263
264     m_page.didFailProvisionalLoadForFrameShared(m_process.copyRef(), frameID, WTFMove(frameInfo), navigationID, provisionalURL, error, willContinueLoading, userData); // May delete |this|.
265 }
266
267 void ProvisionalPageProxy::didCommitLoadForFrame(FrameIdentifier frameID, uint64_t navigationID, const String& mimeType, bool frameHasCustomContentProvider, uint32_t frameLoadType, const WebCore::CertificateInfo& certificateInfo, bool usedLegacyTLS, bool containsPluginDocument, Optional<WebCore::HasInsecureContent> forcedHasInsecureContent, const UserData& userData)
268 {
269     if (!validateInput(frameID, navigationID))
270         return;
271
272     RELEASE_LOG_IF_ALLOWED(ProcessSwapping, "didCommitLoadForFrame: pageProxyID=%" PRIu64 " webPageID=%" PRIu64 ", frameID=%" PRIu64 ", navigationID = %" PRIu64, m_page.identifier().toUInt64(), m_webPageID.toUInt64(), frameID.toUInt64(), navigationID);
273     m_provisionalLoadURL = { };
274     m_process->removeMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_webPageID);
275
276     m_wasCommitted = true;
277     m_page.commitProvisionalPage(frameID, navigationID, mimeType, frameHasCustomContentProvider, frameLoadType, certificateInfo, usedLegacyTLS, containsPluginDocument, forcedHasInsecureContent, userData); // Will delete |this|.
278 }
279
280 void ProvisionalPageProxy::didNavigateWithNavigationData(const WebNavigationDataStore& store, FrameIdentifier frameID)
281 {
282     if (!validateInput(frameID))
283         return;
284
285     m_page.didNavigateWithNavigationDataShared(m_process.copyRef(), store, frameID);
286 }
287
288 void ProvisionalPageProxy::didChangeProvisionalURLForFrame(FrameIdentifier frameID, uint64_t navigationID, URL&& url)
289 {
290     if (!validateInput(frameID, navigationID))
291         return;
292
293     m_page.didChangeProvisionalURLForFrameShared(m_process.copyRef(), frameID, navigationID, WTFMove(url));
294 }
295
296 void ProvisionalPageProxy::decidePolicyForNavigationActionAsync(FrameIdentifier frameID, FrameInfoData&& frameInfo, WebCore::PolicyCheckIdentifier identifier,
297     uint64_t navigationID, NavigationActionData&& navigationActionData, FrameInfoData&& originatingFrameInfo, Optional<WebPageProxyIdentifier> originatingPageID, const WebCore::ResourceRequest& originalRequest,
298     WebCore::ResourceRequest&& request, IPC::FormDataReference&& requestBody, WebCore::ResourceResponse&& redirectResponse, const UserData& userData, uint64_t listenerID)
299 {
300     if (!validateInput(frameID, navigationID))
301         return;
302
303     m_page.decidePolicyForNavigationActionAsyncShared(m_process.copyRef(), m_webPageID, frameID, WTFMove(frameInfo), identifier, navigationID, WTFMove(navigationActionData), WTFMove(originatingFrameInfo), originatingPageID, originalRequest, WTFMove(request), WTFMove(requestBody), WTFMove(redirectResponse), userData, listenerID);
304 }
305
306 void ProvisionalPageProxy::decidePolicyForResponse(FrameIdentifier frameID, FrameInfoData&& frameInfo, WebCore::PolicyCheckIdentifier identifier,
307     uint64_t navigationID, const WebCore::ResourceResponse& response, const WebCore::ResourceRequest& request, bool canShowMIMEType, const String& downloadAttribute, uint64_t listenerID, const UserData& userData)
308 {
309     if (!validateInput(frameID, navigationID))
310         return;
311
312     m_page.decidePolicyForResponseShared(m_process.copyRef(), m_webPageID, frameID, WTFMove(frameInfo), identifier, navigationID, response, request, canShowMIMEType, downloadAttribute, listenerID, userData);
313 }
314
315 void ProvisionalPageProxy::didPerformServerRedirect(const String& sourceURLString, const String& destinationURLString, FrameIdentifier frameID)
316 {
317     if (!validateInput(frameID))
318         return;
319
320     m_page.didPerformServerRedirectShared(m_process.copyRef(), sourceURLString, destinationURLString, frameID);
321 }
322
323 void ProvisionalPageProxy::didReceiveServerRedirectForProvisionalLoadForFrame(FrameIdentifier frameID, uint64_t navigationID, WebCore::ResourceRequest&& request, const UserData& userData)
324 {
325     if (!validateInput(frameID, navigationID))
326         return;
327
328     m_page.didReceiveServerRedirectForProvisionalLoadForFrameShared(m_process.copyRef(), frameID, navigationID, WTFMove(request), userData);
329 }
330
331 void ProvisionalPageProxy::startURLSchemeTask(URLSchemeTaskParameters&& parameters)
332 {
333     m_page.startURLSchemeTaskShared(m_process.copyRef(), m_webPageID, WTFMove(parameters));
334 }
335
336 void ProvisionalPageProxy::backForwardGoToItem(const WebCore::BackForwardItemIdentifier& identifier, CompletionHandler<void(SandboxExtension::Handle&&, const WebBackForwardListCounts&)>&& completionHandler)
337 {
338     m_page.backForwardGoToItemShared(m_process.copyRef(), identifier, WTFMove(completionHandler));
339 }
340
341 void ProvisionalPageProxy::decidePolicyForNavigationActionSync(FrameIdentifier frameID, bool isMainFrame, FrameInfoData&& frameInfoData, WebCore::PolicyCheckIdentifier identifier,
342     uint64_t navigationID, NavigationActionData&& navigationActionData, FrameInfoData&& originatingFrameInfo, Optional<WebPageProxyIdentifier> originatingPageID,
343     const WebCore::ResourceRequest& originalRequest, WebCore::ResourceRequest&& request, IPC::FormDataReference&& requestBody, WebCore::ResourceResponse&& redirectResponse,
344     const UserData& userData, Messages::WebPageProxy::DecidePolicyForNavigationActionSync::DelayedReply&& reply)
345 {
346     if (!isMainFrame || (m_mainFrame && m_mainFrame->frameID() != frameID) || navigationID != m_navigationID) {
347         reply(PolicyDecision { identifier, NavigatingToAppBoundDomain::No, NavigatedAwayFromAppBoundDomain::No, WebCore::PolicyAction::Ignore, navigationID, DownloadID(), WTF::nullopt });
348         return;
349     }
350
351     if (!m_mainFrame) {
352         // This synchronous IPC message was processed before the asynchronous DidCreateMainFrame one so we do not know about this frameID yet.
353         didCreateMainFrame(frameID);
354     }
355     ASSERT(m_mainFrame);
356
357     m_page.decidePolicyForNavigationActionSyncShared(m_process.copyRef(), frameID, isMainFrame, WTFMove(frameInfoData), identifier, navigationID, WTFMove(navigationActionData), WTFMove(originatingFrameInfo), originatingPageID, originalRequest, WTFMove(request), WTFMove(requestBody), WTFMove(redirectResponse), userData, WTFMove(reply));
358 }
359
360 #if USE(QUICK_LOOK)
361 void ProvisionalPageProxy::requestPasswordForQuickLookDocumentInMainFrame(const String& fileName, CompletionHandler<void(const String&)>&& completionHandler)
362 {
363     m_page.requestPasswordForQuickLookDocumentInMainFrameShared(fileName, WTFMove(completionHandler));
364 }
365 #endif
366
367 #if PLATFORM(COCOA)
368 void ProvisionalPageProxy::registerWebProcessAccessibilityToken(const IPC::DataReference& data)
369 {
370     m_accessibilityToken = data.vector();
371 }
372 #endif
373
374 #if ENABLE(CONTENT_FILTERING)
375 void ProvisionalPageProxy::contentFilterDidBlockLoadForFrame(const WebCore::ContentFilterUnblockHandler& unblockHandler, FrameIdentifier frameID)
376 {
377     m_page.contentFilterDidBlockLoadForFrameShared(m_process.copyRef(), unblockHandler, frameID);
378 }
379 #endif
380
381 #if HAVE(VISIBILITY_PROPAGATION_VIEW)
382 void ProvisionalPageProxy::didCreateContextForVisibilityPropagation(LayerHostingContextID contextID)
383 {
384     RELEASE_LOG_IF_ALLOWED(ProcessSwapping, "didCreateContextForVisibilityPropagation: contextID=%u pageProxyID=%" PRIu64 " webPageID=%" PRIu64, contextID, m_page.identifier().toUInt64(), m_webPageID.toUInt64());
385     m_contextIDForVisibilityPropagation = contextID;
386 }
387 #endif
388
389 void ProvisionalPageProxy::unfreezeLayerTreeDueToSwipeAnimation()
390 {
391     send(Messages::WebPage::UnfreezeLayerTreeDueToSwipeAnimation());
392 }
393
394 void ProvisionalPageProxy::didReceiveMessage(IPC::Connection& connection, IPC::Decoder& decoder)
395 {
396     ASSERT(decoder.messageReceiverName() == Messages::WebPageProxy::messageReceiverName());
397
398     if (decoder.messageName() == Messages::WebPageProxy::DidStartProgress::name()
399         || decoder.messageName() == Messages::WebPageProxy::DidChangeProgress::name()
400         || decoder.messageName() == Messages::WebPageProxy::DidDestroyNavigation::name()
401         || decoder.messageName() == Messages::WebPageProxy::DidFinishProgress::name()
402         || decoder.messageName() == Messages::WebPageProxy::BackForwardAddItem::name()
403         || decoder.messageName() == Messages::WebPageProxy::LogDiagnosticMessage::name()
404         || decoder.messageName() == Messages::WebPageProxy::LogDiagnosticMessageWithEnhancedPrivacy::name()
405         || decoder.messageName() == Messages::WebPageProxy::LogDiagnosticMessageWithValueDictionary::name()
406         || decoder.messageName() == Messages::WebPageProxy::SetNetworkRequestsInProgress::name()
407         || decoder.messageName() == Messages::WebPageProxy::WillGoToBackForwardListItem::name()
408 #if USE(QUICK_LOOK)
409         || decoder.messageName() == Messages::WebPageProxy::DidStartLoadForQuickLookDocumentInMainFrame::name()
410         || decoder.messageName() == Messages::WebPageProxy::DidFinishLoadForQuickLookDocumentInMainFrame::name()
411 #endif
412         || decoder.messageName() == Messages::WebPageProxy::CreateInspectorTarget::name()
413         || decoder.messageName() == Messages::WebPageProxy::DestroyInspectorTarget::name()
414         || decoder.messageName() == Messages::WebPageProxy::SendMessageToInspectorFrontend::name()
415         )
416     {
417         m_page.didReceiveMessage(connection, decoder);
418         return;
419     }
420
421 #if PLATFORM(COCOA)
422     if (decoder.messageName() == Messages::WebPageProxy::RegisterWebProcessAccessibilityToken::name()) {
423         IPC::handleMessage<Messages::WebPageProxy::RegisterWebProcessAccessibilityToken>(decoder, this, &ProvisionalPageProxy::registerWebProcessAccessibilityToken);
424         return;
425     }
426 #endif
427
428     if (decoder.messageName() == Messages::WebPageProxy::StartURLSchemeTask::name()) {
429         IPC::handleMessage<Messages::WebPageProxy::StartURLSchemeTask>(decoder, this, &ProvisionalPageProxy::startURLSchemeTask);
430         return;
431     }
432
433     if (decoder.messageName() == Messages::WebPageProxy::DecidePolicyForNavigationActionAsync::name()) {
434         IPC::handleMessage<Messages::WebPageProxy::DecidePolicyForNavigationActionAsync>(decoder, this, &ProvisionalPageProxy::decidePolicyForNavigationActionAsync);
435         return;
436     }
437
438     if (decoder.messageName() == Messages::WebPageProxy::DecidePolicyForResponse::name()) {
439         IPC::handleMessage<Messages::WebPageProxy::DecidePolicyForResponse>(decoder, this, &ProvisionalPageProxy::decidePolicyForResponse);
440         return;
441     }
442
443     if (decoder.messageName() == Messages::WebPageProxy::DidChangeProvisionalURLForFrame::name()) {
444         IPC::handleMessage<Messages::WebPageProxy::DidChangeProvisionalURLForFrame>(decoder, this, &ProvisionalPageProxy::didChangeProvisionalURLForFrame);
445         return;
446     }
447
448     if (decoder.messageName() == Messages::WebPageProxy::DidNavigateWithNavigationData::name()) {
449         IPC::handleMessage<Messages::WebPageProxy::DidNavigateWithNavigationData>(decoder, this, &ProvisionalPageProxy::didNavigateWithNavigationData);
450         return;
451     }
452
453     if (decoder.messageName() == Messages::WebPageProxy::DidPerformClientRedirect::name()) {
454         IPC::handleMessage<Messages::WebPageProxy::DidPerformClientRedirect>(decoder, this, &ProvisionalPageProxy::didPerformClientRedirect);
455         return;
456     }
457
458     if (decoder.messageName() == Messages::WebPageProxy::DidCreateMainFrame::name()) {
459         IPC::handleMessage<Messages::WebPageProxy::DidCreateMainFrame>(decoder, this, &ProvisionalPageProxy::didCreateMainFrame);
460         return;
461     }
462
463     if (decoder.messageName() == Messages::WebPageProxy::DidStartProvisionalLoadForFrame::name()) {
464         IPC::handleMessage<Messages::WebPageProxy::DidStartProvisionalLoadForFrame>(decoder, this, &ProvisionalPageProxy::didStartProvisionalLoadForFrame);
465         return;
466     }
467
468     if (decoder.messageName() == Messages::WebPageProxy::DidFailProvisionalLoadForFrame::name()) {
469         IPC::handleMessage<Messages::WebPageProxy::DidFailProvisionalLoadForFrame>(decoder, this, &ProvisionalPageProxy::didFailProvisionalLoadForFrame);
470         return;
471     }
472
473     if (decoder.messageName() == Messages::WebPageProxy::DidCommitLoadForFrame::name()) {
474         IPC::handleMessage<Messages::WebPageProxy::DidCommitLoadForFrame>(decoder, this, &ProvisionalPageProxy::didCommitLoadForFrame);
475         return;
476     }
477
478     if (decoder.messageName() == Messages::WebPageProxy::DidReceiveServerRedirectForProvisionalLoadForFrame::name()) {
479         IPC::handleMessage<Messages::WebPageProxy::DidReceiveServerRedirectForProvisionalLoadForFrame>(decoder, this, &ProvisionalPageProxy::didReceiveServerRedirectForProvisionalLoadForFrame);
480         return;
481     }
482
483     if (decoder.messageName() == Messages::WebPageProxy::DidPerformServerRedirect::name()) {
484         IPC::handleMessage<Messages::WebPageProxy::DidPerformServerRedirect>(decoder, this, &ProvisionalPageProxy::didPerformServerRedirect);
485         return;
486     }
487
488 #if USE(QUICK_LOOK)
489     if (decoder.messageName() == Messages::WebPageProxy::RequestPasswordForQuickLookDocumentInMainFrame::name()) {
490         IPC::handleMessageAsync<Messages::WebPageProxy::RequestPasswordForQuickLookDocumentInMainFrame>(connection, decoder, this, &ProvisionalPageProxy::requestPasswordForQuickLookDocumentInMainFrame);
491         return;
492     }
493 #endif
494
495 #if ENABLE(CONTENT_FILTERING)
496     if (decoder.messageName() == Messages::WebPageProxy::ContentFilterDidBlockLoadForFrame::name()) {
497         IPC::handleMessage<Messages::WebPageProxy::ContentFilterDidBlockLoadForFrame>(decoder, this, &ProvisionalPageProxy::contentFilterDidBlockLoadForFrame);
498         return;
499     }
500 #endif
501
502 #if HAVE(VISIBILITY_PROPAGATION_VIEW)
503     if (decoder.messageName() == Messages::WebPageProxy::DidCreateContextForVisibilityPropagation::name()) {
504         IPC::handleMessage<Messages::WebPageProxy::DidCreateContextForVisibilityPropagation>(decoder, this, &ProvisionalPageProxy::didCreateContextForVisibilityPropagation);
505         return;
506     }
507 #endif
508
509     LOG(ProcessSwapping, "Unhandled message %s::%s from provisional process", decoder.messageReceiverName().toString().data(), decoder.messageName().toString().data());
510 }
511
512 void ProvisionalPageProxy::didReceiveSyncMessage(IPC::Connection& connection, IPC::Decoder& decoder, std::unique_ptr<IPC::Encoder>& replyEncoder)
513 {
514     if (decoder.messageName() == Messages::WebPageProxy::BackForwardGoToItem::name()) {
515         IPC::handleMessageSynchronous<Messages::WebPageProxy::BackForwardGoToItem>(connection, decoder, replyEncoder, this, &ProvisionalPageProxy::backForwardGoToItem);
516         return;
517     }
518
519     if (decoder.messageName() == Messages::WebPageProxy::DecidePolicyForNavigationActionSync::name()) {
520         IPC::handleMessageSynchronous<Messages::WebPageProxy::DecidePolicyForNavigationActionSync>(connection, decoder, replyEncoder, this, &ProvisionalPageProxy::decidePolicyForNavigationActionSync);
521         return;
522     }
523
524     m_page.didReceiveSyncMessage(connection, decoder, replyEncoder);
525 }
526
527 IPC::Connection* ProvisionalPageProxy::messageSenderConnection() const
528 {
529     return m_process->connection();
530 }
531
532 uint64_t ProvisionalPageProxy::messageSenderDestinationID() const
533 {
534     return m_webPageID.toUInt64();
535 }
536
537 bool ProvisionalPageProxy::sendMessage(std::unique_ptr<IPC::Encoder> encoder, OptionSet<IPC::SendOption> sendOptions, Optional<std::pair<CompletionHandler<void(IPC::Decoder*)>, uint64_t>>&& asyncReplyInfo)
538 {
539     // Send messages via the WebProcessProxy instead of the IPC::Connection since AuxiliaryProcessProxy implements queueing of messages
540     // while the process is still launching.
541     return m_process->sendMessage(WTFMove(encoder), sendOptions, WTFMove(asyncReplyInfo));
542 }
543
544 } // namespace WebKit