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#pragma once
27
28#include "MessageSender.h"
29#include "NetworkLoadClient.h"
30#include "SandboxExtension.h"
31
32namespace IPC {
33class Connection;
34}
35
36namespace WebCore {
37class BlobRegistryImpl;
38class ResourceResponse;
39}
40
41namespace WebKit {
42
43class Download;
44class DownloadID;
45class NetworkLoad;
46class NetworkLoadParameters;
47class NetworkSession;
48
49class PendingDownload : public NetworkLoadClient, public IPC::MessageSender {
50 WTF_MAKE_FAST_ALLOCATED;
51public:
52 PendingDownload(IPC::Connection*, NetworkLoadParameters&&, DownloadID, NetworkSession&, WebCore::BlobRegistryImpl*, const String& suggestedName);
53 PendingDownload(IPC::Connection*, std::unique_ptr<NetworkLoad>&&, ResponseCompletionHandler&&, DownloadID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
54
55 void continueWillSendRequest(WebCore::ResourceRequest&&);
56 void cancel();
57
58#if PLATFORM(COCOA)
59 void publishProgress(const URL&, SandboxExtension::Handle&&);
60 void didBecomeDownload(const std::unique_ptr<Download>&);
61#endif
62
63private:
64 // NetworkLoadClient.
65 void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) override { }
66 bool isSynchronous() const override { return false; }
67 bool isAllowedToAskUserForCredentials() const final { return m_isAllowedToAskUserForCredentials; }
68 void willSendRedirectedRequest(WebCore::ResourceRequest&&, WebCore::ResourceRequest&& redirectRequest, WebCore::ResourceResponse&& redirectResponse) override;
69 void didReceiveResponse(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) override;
70 void didReceiveBuffer(Ref<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) override { };
71 void didFinishLoading(const WebCore::NetworkLoadMetrics&) override { };
72 void didFailLoading(const WebCore::ResourceError&) override;
73
74 // MessageSender.
75 IPC::Connection* messageSenderConnection() const override;
76 uint64_t messageSenderDestinationID() const override;
77
78private:
79 std::unique_ptr<NetworkLoad> m_networkLoad;
80 RefPtr<IPC::Connection> m_parentProcessConnection;
81 bool m_isAllowedToAskUserForCredentials;
82
83#if PLATFORM(COCOA)
84 URL m_progressURL;
85 SandboxExtension::Handle m_progressSandboxExtension;
86#endif
87};
88
89}
90