2 * Copyright (C) 2010-2016 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef DownloadProxy_h
27 #define DownloadProxy_h
29 #include "APIObject.h"
30 #include "Connection.h"
31 #include "DownloadID.h"
32 #include "SandboxExtension.h"
33 #include <WebCore/ResourceRequest.h>
34 #include <wtf/Forward.h>
36 #include <wtf/WeakPtr.h>
43 class AuthenticationChallenge;
44 class ProtectionSpace;
46 class ResourceResponse;
53 class DownloadProxyMap;
57 class DownloadProxy : public API::ObjectImpl<API::Object::Type::Download>, public IPC::MessageReceiver {
59 static Ref<DownloadProxy> create(DownloadProxyMap&, WebProcessPool&, const WebCore::ResourceRequest&);
62 DownloadID downloadID() const { return m_downloadID; }
63 const WebCore::ResourceRequest& request() const { return m_request; }
64 API::Data* resumeData() const { return m_resumeData.get(); }
69 void processDidClose();
71 void didReceiveDownloadProxyMessage(IPC::Connection&, IPC::Decoder&);
72 void didReceiveSyncDownloadProxyMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&);
74 WebPageProxy* originatingPage() const;
75 void setOriginatingPage(WebPageProxy*);
77 void setRedirectChain(Vector<WebCore::URL>&& redirectChain) { m_redirectChain = WTFMove(redirectChain); }
78 const Vector<WebCore::URL>& redirectChain() const { return m_redirectChain; }
80 void setWasUserInitiated(bool value) { m_wasUserInitiated = value; }
81 bool wasUserInitiated() const { return m_wasUserInitiated; }
84 explicit DownloadProxy(DownloadProxyMap&, WebProcessPool&, const WebCore::ResourceRequest&);
86 // IPC::MessageReceiver
87 void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
88 void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
91 void didStart(const WebCore::ResourceRequest&, const String& suggestedFilename);
92 void didReceiveAuthenticationChallenge(const WebCore::AuthenticationChallenge&, uint64_t challengeID);
93 void didReceiveResponse(const WebCore::ResourceResponse&);
94 void didReceiveData(uint64_t length);
95 void shouldDecodeSourceDataOfMIMEType(const String& mimeType, bool& result);
96 void didCreateDestination(const String& path);
98 void didFail(const WebCore::ResourceError&, const IPC::DataReference& resumeData);
99 void didCancel(const IPC::DataReference& resumeData);
100 void willSendRequest(const WebCore::ResourceRequest& redirectRequest, const WebCore::ResourceResponse& redirectResponse);
101 #if USE(NETWORK_SESSION)
102 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
103 void canAuthenticateAgainstProtectionSpace(const WebCore::ProtectionSpace&);
106 void decideDestinationWithSuggestedFilename(const String& filename, const String& mimeType, String& destination, bool& allowOverwrite, SandboxExtension::Handle& sandboxExtensionHandle);
108 void decideDestinationWithSuggestedFilenameAsync(DownloadID, const String& suggestedFilename);
110 DownloadProxyMap& m_downloadProxyMap;
111 RefPtr<WebProcessPool> m_processPool;
112 DownloadID m_downloadID;
114 RefPtr<API::Data> m_resumeData;
115 WebCore::ResourceRequest m_request;
116 String m_suggestedFilename;
118 WeakPtr<WebPageProxy> m_originatingPage;
119 Vector<WebCore::URL> m_redirectChain;
120 bool m_wasUserInitiated { true };
123 } // namespace WebKit
125 #endif // DownloadProxy_h