Stop using canAuthenticateAgainstProtectionSpace in modern WebKit
[WebKit-https.git] / Source / WebKit / NetworkProcess / Downloads / PendingDownload.cpp
1 /*
2  * Copyright (C) 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 #include "config.h"
27 #include "PendingDownload.h"
28
29 #include "DataReference.h"
30 #include "DownloadProxyMessages.h"
31 #include "NetworkLoad.h"
32 #include "NetworkProcess.h"
33 #include "WebCoreArgumentCoders.h"
34
35 using namespace WebCore;
36
37 namespace WebKit {
38
39 PendingDownload::PendingDownload(NetworkLoadParameters&& parameters, DownloadID downloadID, NetworkSession& networkSession, const String& suggestedName)
40     : m_networkLoad(std::make_unique<NetworkLoad>(*this, WTFMove(parameters), networkSession))
41 {
42     m_isAllowedToAskUserForCredentials = parameters.clientCredentialPolicy == ClientCredentialPolicy::MayAskClientForCredentials;
43
44     m_networkLoad->setPendingDownloadID(downloadID);
45     m_networkLoad->setPendingDownload(*this);
46     m_networkLoad->setSuggestedFilename(suggestedName);
47
48     send(Messages::DownloadProxy::DidStart(m_networkLoad->currentRequest(), suggestedName));
49 }
50
51 PendingDownload::PendingDownload(std::unique_ptr<NetworkLoad>&& networkLoad, DownloadID downloadID, const ResourceRequest& request, const ResourceResponse& response)
52     : m_networkLoad(WTFMove(networkLoad))
53 {
54     m_isAllowedToAskUserForCredentials = m_networkLoad->isAllowedToAskUserForCredentials();
55
56     m_networkLoad->setPendingDownloadID(downloadID);
57     send(Messages::DownloadProxy::DidStart(request, String()));
58
59     m_networkLoad->convertTaskToDownload(*this, request, response);
60 }
61
62 void PendingDownload::willSendRedirectedRequest(WebCore::ResourceRequest&&, WebCore::ResourceRequest&& redirectRequest, WebCore::ResourceResponse&& redirectResponse)
63 {
64     send(Messages::DownloadProxy::WillSendRequest(WTFMove(redirectRequest), WTFMove(redirectResponse)));
65 };
66     
67 void PendingDownload::continueWillSendRequest(WebCore::ResourceRequest&& newRequest)
68 {
69     m_networkLoad->continueWillSendRequest(WTFMove(newRequest));
70 }
71
72 void PendingDownload::cancel()
73 {
74     ASSERT(m_networkLoad);
75     m_networkLoad->cancel();
76     send(Messages::DownloadProxy::DidCancel({ }));
77 }
78
79 void PendingDownload::didFailLoading(const WebCore::ResourceError& error)
80 {
81     send(Messages::DownloadProxy::DidFail(error, { }));
82 }
83     
84 IPC::Connection* PendingDownload::messageSenderConnection()
85 {
86     return NetworkProcess::singleton().parentProcessConnection();
87 }
88
89 uint64_t PendingDownload::messageSenderDestinationID()
90 {
91     return m_networkLoad->pendingDownloadID().downloadID();
92 }
93     
94 }