diff options
Diffstat (limited to 'Source/WebKit2/Shared/Downloads')
-rw-r--r-- | Source/WebKit2/Shared/Downloads/Download.cpp | 165 | ||||
-rw-r--r-- | Source/WebKit2/Shared/Downloads/Download.h | 141 | ||||
-rw-r--r-- | Source/WebKit2/Shared/Downloads/DownloadAuthenticationClient.h | 66 | ||||
-rw-r--r-- | Source/WebKit2/Shared/Downloads/DownloadManager.cpp | 94 | ||||
-rw-r--r-- | Source/WebKit2/Shared/Downloads/DownloadManager.h | 87 | ||||
-rw-r--r-- | Source/WebKit2/Shared/Downloads/gtk/DownloadSoupErrorsGtk.cpp | 46 | ||||
-rw-r--r-- | Source/WebKit2/Shared/Downloads/soup/DownloadSoup.cpp | 310 | ||||
-rw-r--r-- | Source/WebKit2/Shared/Downloads/soup/DownloadSoupErrors.h | 39 |
8 files changed, 0 insertions, 948 deletions
diff --git a/Source/WebKit2/Shared/Downloads/Download.cpp b/Source/WebKit2/Shared/Downloads/Download.cpp deleted file mode 100644 index 77229d73e..000000000 --- a/Source/WebKit2/Shared/Downloads/Download.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "Download.h" - -#include "AuthenticationManager.h" -#include "Connection.h" -#include "DataReference.h" -#include "DownloadAuthenticationClient.h" -#include "DownloadProxyMessages.h" -#include "DownloadManager.h" -#include "SandboxExtension.h" -#include "WebCoreArgumentCoders.h" - -using namespace WebCore; - -namespace WebKit { - -Download::Download(DownloadManager& downloadManager, uint64_t downloadID, const ResourceRequest& request) - : m_downloadManager(downloadManager) - , m_downloadID(downloadID) - , m_request(request) -#if USE(CFNETWORK) - , m_allowOverwrite(false) -#endif -{ - ASSERT(m_downloadID); - - m_downloadManager.didCreateDownload(); -} - -Download::~Download() -{ - platformInvalidate(); - - m_downloadManager.didDestroyDownload(); -} - -void Download::didStart() -{ - send(Messages::DownloadProxy::DidStart(m_request)); -} - -void Download::didReceiveAuthenticationChallenge(const AuthenticationChallenge& authenticationChallenge) -{ - m_downloadManager.downloadsAuthenticationManager().didReceiveAuthenticationChallenge(this, authenticationChallenge); -} - -void Download::didReceiveResponse(const ResourceResponse& response) -{ - send(Messages::DownloadProxy::DidReceiveResponse(response)); -} - -void Download::didReceiveData(uint64_t length) -{ - send(Messages::DownloadProxy::DidReceiveData(length)); -} - -bool Download::shouldDecodeSourceDataOfMIMEType(const String& mimeType) -{ - bool result; - if (!sendSync(Messages::DownloadProxy::ShouldDecodeSourceDataOfMIMEType(mimeType), Messages::DownloadProxy::ShouldDecodeSourceDataOfMIMEType::Reply(result))) - return true; - - return result; -} - -String Download::retrieveDestinationWithSuggestedFilename(const String& filename, bool& allowOverwrite) -{ - String destination; - SandboxExtension::Handle sandboxExtensionHandle; - if (!sendSync(Messages::DownloadProxy::DecideDestinationWithSuggestedFilename(filename), Messages::DownloadProxy::DecideDestinationWithSuggestedFilename::Reply(destination, allowOverwrite, sandboxExtensionHandle))) - return String(); - - m_sandboxExtension = SandboxExtension::create(sandboxExtensionHandle); - if (m_sandboxExtension) - m_sandboxExtension->consume(); - - return destination; -} - -String Download::decideDestinationWithSuggestedFilename(const String& filename, bool& allowOverwrite) -{ - String destination = retrieveDestinationWithSuggestedFilename(filename, allowOverwrite); - - didDecideDestination(destination, allowOverwrite); - - return destination; -} - -void Download::didCreateDestination(const String& path) -{ - send(Messages::DownloadProxy::DidCreateDestination(path)); -} - -void Download::didFinish() -{ - platformDidFinish(); - - send(Messages::DownloadProxy::DidFinish()); - - if (m_sandboxExtension) { - m_sandboxExtension->revoke(); - m_sandboxExtension = nullptr; - } - - m_downloadManager.downloadFinished(this); -} - -void Download::didFail(const ResourceError& error, const IPC::DataReference& resumeData) -{ - send(Messages::DownloadProxy::DidFail(error, resumeData)); - - if (m_sandboxExtension) { - m_sandboxExtension->revoke(); - m_sandboxExtension = nullptr; - } - m_downloadManager.downloadFinished(this); -} - -void Download::didCancel(const IPC::DataReference& resumeData) -{ - send(Messages::DownloadProxy::DidCancel(resumeData)); - - if (m_sandboxExtension) { - m_sandboxExtension->revoke(); - m_sandboxExtension = nullptr; - } - m_downloadManager.downloadFinished(this); -} - -IPC::Connection* Download::messageSenderConnection() -{ - return m_downloadManager.downloadProxyConnection(); -} - -uint64_t Download::messageSenderDestinationID() -{ - return m_downloadID; -} - -} // namespace WebKit diff --git a/Source/WebKit2/Shared/Downloads/Download.h b/Source/WebKit2/Shared/Downloads/Download.h deleted file mode 100644 index d67a04aed..000000000 --- a/Source/WebKit2/Shared/Downloads/Download.h +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef Download_h -#define Download_h - -#include "MessageSender.h" -#include <WebCore/ResourceRequest.h> -#include <wtf/Noncopyable.h> - -#if PLATFORM(MAC) -#include <wtf/RetainPtr.h> - -OBJC_CLASS NSURLDownload; -OBJC_CLASS WKDownloadAsDelegate; -#endif - -#if PLATFORM(GTK) || PLATFORM(EFL) -#include <WebCore/ResourceHandle.h> -#include <WebCore/ResourceHandleClient.h> -#endif - -#if USE(CFNETWORK) -#include <CFNetwork/CFURLDownloadPriv.h> -#endif - -namespace IPC { - class DataReference; -} - -namespace WebCore { - class AuthenticationChallenge; - class Credential; - class ResourceError; - class ResourceHandle; - class ResourceResponse; -} - -namespace WebKit { - -class DownloadAuthenticationClient; -class DownloadManager; -class SandboxExtension; -class WebPage; - -class Download : public IPC::MessageSender { - WTF_MAKE_NONCOPYABLE(Download); -public: - Download(DownloadManager&, uint64_t downloadID, const WebCore::ResourceRequest&); - ~Download(); - - void start(); - void startWithHandle(WebCore::ResourceHandle*, const WebCore::ResourceResponse&); - void cancel(); - - uint64_t downloadID() const { return m_downloadID; } - - void didStart(); - void didReceiveAuthenticationChallenge(const WebCore::AuthenticationChallenge&); - void didReceiveResponse(const WebCore::ResourceResponse&); - void didReceiveData(uint64_t length); - bool shouldDecodeSourceDataOfMIMEType(const String& mimeType); - String decideDestinationWithSuggestedFilename(const String& filename, bool& allowOverwrite); - void didCreateDestination(const String& path); - void didFinish(); - void platformDidFinish(); - void didFail(const WebCore::ResourceError&, const IPC::DataReference& resumeData); - void didCancel(const IPC::DataReference& resumeData); - void didDecideDestination(const String&, bool allowOverwrite); - -#if USE(CFNETWORK) - const String& destination() const { return m_destination; } - DownloadAuthenticationClient* authenticationClient(); -#endif - - // Authentication - static void receivedCredential(const WebCore::AuthenticationChallenge&, const WebCore::Credential&); - static void receivedRequestToContinueWithoutCredential(const WebCore::AuthenticationChallenge&); - static void receivedCancellation(const WebCore::AuthenticationChallenge&); - - void useCredential(const WebCore::AuthenticationChallenge&, const WebCore::Credential&); - void continueWithoutCredential(const WebCore::AuthenticationChallenge&); - void cancelAuthenticationChallenge(const WebCore::AuthenticationChallenge&); - -private: - // IPC::MessageSender - virtual IPC::Connection* messageSenderConnection() override; - virtual uint64_t messageSenderDestinationID() override; - - void platformInvalidate(); - - String retrieveDestinationWithSuggestedFilename(const String& filename, bool& allowOverwrite); - - DownloadManager& m_downloadManager; - uint64_t m_downloadID; - WebCore::ResourceRequest m_request; - - RefPtr<SandboxExtension> m_sandboxExtension; - -#if PLATFORM(MAC) - RetainPtr<NSURLDownload> m_nsURLDownload; - RetainPtr<WKDownloadAsDelegate> m_delegate; -#endif - bool m_allowOverwrite; - String m_destination; - String m_bundlePath; -#if USE(CFNETWORK) - RetainPtr<CFURLDownloadRef> m_download; - RefPtr<DownloadAuthenticationClient> m_authenticationClient; -#endif -#if PLATFORM(GTK) || PLATFORM(EFL) - OwnPtr<WebCore::ResourceHandleClient> m_downloadClient; - RefPtr<WebCore::ResourceHandle> m_resourceHandle; -#endif -}; - -} // namespace WebKit - -#endif // Download_h diff --git a/Source/WebKit2/Shared/Downloads/DownloadAuthenticationClient.h b/Source/WebKit2/Shared/Downloads/DownloadAuthenticationClient.h deleted file mode 100644 index 76321ae6d..000000000 --- a/Source/WebKit2/Shared/Downloads/DownloadAuthenticationClient.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2011 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef DownloadAuthenticationClient_h -#define DownloadAuthenticationClient_h - -#include <WebCore/AuthenticationClient.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> - -namespace WebCore { - class AuthenticationChallenge; - class Credential; -} - -namespace WebKit { - -class Download; - -class DownloadAuthenticationClient : public RefCounted<DownloadAuthenticationClient>, public WebCore::AuthenticationClient { -public: - static PassRefPtr<DownloadAuthenticationClient> create(Download* download) { return adoptRef(new DownloadAuthenticationClient(download)); } - - void detach() { m_download = 0; } - - using RefCounted<DownloadAuthenticationClient>::ref; - using RefCounted<DownloadAuthenticationClient>::deref; - -private: - DownloadAuthenticationClient(Download*); - - virtual void receivedCredential(const WebCore::AuthenticationChallenge&, const WebCore::Credential&); - virtual void receivedRequestToContinueWithoutCredential(const WebCore::AuthenticationChallenge&); - virtual void receivedCancellation(const WebCore::AuthenticationChallenge&); - - virtual void refAuthenticationClient() { ref(); } - virtual void derefAuthenticationClient() { deref(); } - - Download* m_download; -}; - -} // namespace WebKit - -#endif // DownloadAuthenticationClient_h diff --git a/Source/WebKit2/Shared/Downloads/DownloadManager.cpp b/Source/WebKit2/Shared/Downloads/DownloadManager.cpp deleted file mode 100644 index a1d6506eb..000000000 --- a/Source/WebKit2/Shared/Downloads/DownloadManager.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "DownloadManager.h" - -#include "Download.h" -#include <wtf/StdLibExtras.h> - -using namespace WebCore; - -namespace WebKit { - -DownloadManager::DownloadManager(Client* client) - : m_client(client) -{ -} - -void DownloadManager::startDownload(uint64_t downloadID, const ResourceRequest& request) -{ - auto download = std::make_unique<Download>(*this, downloadID, request); - download->start(); - - ASSERT(!m_downloads.contains(downloadID)); - m_downloads.add(downloadID, std::move(download)); -} - -void DownloadManager::convertHandleToDownload(uint64_t downloadID, ResourceHandle* handle, const ResourceRequest& request, const ResourceResponse& response) -{ - auto download = std::make_unique<Download>(*this, downloadID, request); - - download->startWithHandle(handle, response); - ASSERT(!m_downloads.contains(downloadID)); - m_downloads.add(downloadID, std::move(download)); -} - -void DownloadManager::cancelDownload(uint64_t downloadID) -{ - Download* download = m_downloads.get(downloadID); - if (!download) - return; - - download->cancel(); -} - -void DownloadManager::downloadFinished(Download* download) -{ - ASSERT(m_downloads.contains(download->downloadID())); - m_downloads.remove(download->downloadID()); -} - -void DownloadManager::didCreateDownload() -{ - m_client->didCreateDownload(); -} - -void DownloadManager::didDestroyDownload() -{ - m_client->didDestroyDownload(); -} - -IPC::Connection* DownloadManager::downloadProxyConnection() -{ - return m_client->downloadProxyConnection(); -} - -AuthenticationManager& DownloadManager::downloadsAuthenticationManager() -{ - return m_client->downloadsAuthenticationManager(); -} - -} // namespace WebKit diff --git a/Source/WebKit2/Shared/Downloads/DownloadManager.h b/Source/WebKit2/Shared/Downloads/DownloadManager.h deleted file mode 100644 index 2a1694e92..000000000 --- a/Source/WebKit2/Shared/Downloads/DownloadManager.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef DownloadManager_h -#define DownloadManager_h - -#include <wtf/Forward.h> -#include <wtf/HashMap.h> -#include <wtf/Noncopyable.h> - -namespace WebCore { -class ResourceHandle; -class ResourceRequest; -class ResourceResponse; -} - -namespace IPC { -class Connection; -} - -namespace WebKit { - -class AuthenticationManager; -class Download; -class WebPage; - -class DownloadManager { - WTF_MAKE_NONCOPYABLE(DownloadManager); - -public: - class Client { - public: - virtual ~Client() { } - - virtual void didCreateDownload() = 0; - virtual void didDestroyDownload() = 0; - virtual IPC::Connection* downloadProxyConnection() = 0; - virtual AuthenticationManager& downloadsAuthenticationManager() = 0; - }; - - explicit DownloadManager(Client*); - - void startDownload(uint64_t downloadID, const WebCore::ResourceRequest&); - void convertHandleToDownload(uint64_t downloadID, WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&); - - void cancelDownload(uint64_t downloadID); - - void downloadFinished(Download*); - bool isDownloading() const { return !m_downloads.isEmpty(); } - uint64_t activeDownloadCount() const { return m_downloads.size(); } - - void didCreateDownload(); - void didDestroyDownload(); - - IPC::Connection* downloadProxyConnection(); - AuthenticationManager& downloadsAuthenticationManager(); - -private: - Client* m_client; - HashMap<uint64_t, std::unique_ptr<Download>> m_downloads; -}; - -} // namespace WebKit - -#endif // DownloadManager_h diff --git a/Source/WebKit2/Shared/Downloads/gtk/DownloadSoupErrorsGtk.cpp b/Source/WebKit2/Shared/Downloads/gtk/DownloadSoupErrorsGtk.cpp deleted file mode 100644 index 0d3f9d3ed..000000000 --- a/Source/WebKit2/Shared/Downloads/gtk/DownloadSoupErrorsGtk.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2012 Intel Corporation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "DownloadSoupErrors.h" - -#include <WebCore/ErrorsGtk.h> -#include <WebCore/ResourceError.h> - -using namespace WebCore; - -namespace WebKit { - -ResourceError platformDownloadNetworkError(int errorCode, const String& failingURL, const String& localizedDescription) -{ - return downloadNetworkError(ResourceError(errorDomainDownload, errorCode, failingURL, localizedDescription)); -} - -ResourceError platformDownloadDestinationError(const ResourceResponse& response, const String& message) -{ - return downloadDestinationError(response, message); -} - -} // namespace WebKit diff --git a/Source/WebKit2/Shared/Downloads/soup/DownloadSoup.cpp b/Source/WebKit2/Shared/Downloads/soup/DownloadSoup.cpp deleted file mode 100644 index 1c44dd7d4..000000000 --- a/Source/WebKit2/Shared/Downloads/soup/DownloadSoup.cpp +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. - * Copyright (C) 2010 Brent Fulgham <bfulgham@webkit.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "Download.h" - -#include "DataReference.h" -#include "DownloadSoupErrors.h" -#include <WebCore/NotImplemented.h> -#include <WebCore/ResourceHandleInternal.h> -#include <gio/gio.h> -#include <wtf/gobject/GRefPtr.h> -#include <wtf/gobject/GUniquePtr.h> -#include <wtf/text/CString.h> - -#if PLATFORM(GTK) -#include <glib/gi18n-lib.h> -#endif - -using namespace WebCore; - -namespace WebKit { - -class DownloadClient : public ResourceHandleClient { - WTF_MAKE_NONCOPYABLE(DownloadClient); -public: - DownloadClient(Download* download) - : m_download(download) - , m_handleResponseLaterID(0) - , m_allowOverwrite(false) - { - } - - ~DownloadClient() - { - if (m_handleResponseLaterID) - g_source_remove(m_handleResponseLaterID); - } - - void deleteFilesIfNeeded() - { - if (m_destinationFile) - g_file_delete(m_destinationFile.get(), nullptr, nullptr); - - if (m_intermediateFile) { - ASSERT(m_destinationFile); - g_file_delete(m_intermediateFile.get(), nullptr, nullptr); - } - } - - void downloadFailed(const ResourceError& error) - { - deleteFilesIfNeeded(); - m_download->didFail(error, IPC::DataReference()); - } - - void didReceiveResponse(ResourceHandle*, const ResourceResponse& response) - { - m_response = response; - m_download->didReceiveResponse(response); - - if (response.httpStatusCode() >= 400) { - downloadFailed(platformDownloadNetworkError(response.httpStatusCode(), response.url().string(), response.httpStatusText())); - return; - } - - String suggestedFilename = response.suggestedFilename(); - if (suggestedFilename.isEmpty()) { - URL url = response.url(); - url.setQuery(String()); - url.removeFragmentIdentifier(); - suggestedFilename = decodeURLEscapeSequences(url.lastPathComponent()); - } - - String destinationURI = m_download->decideDestinationWithSuggestedFilename(suggestedFilename, m_allowOverwrite); - if (destinationURI.isEmpty()) { -#if PLATFORM(GTK) - GUniquePtr<char> buffer(g_strdup_printf(_("Cannot determine destination URI for download with suggested filename %s"), suggestedFilename.utf8().data())); - String errorMessage = String::fromUTF8(buffer.get()); -#else - String errorMessage = makeString("Cannot determine destination URI for download with suggested filename ", suggestedFilename); -#endif - downloadFailed(platformDownloadDestinationError(response, errorMessage)); - return; - } - - m_destinationFile = adoptGRef(g_file_new_for_uri(destinationURI.utf8().data())); - GRefPtr<GFileOutputStream> outputStream; - GUniqueOutPtr<GError> error; - if (m_allowOverwrite) - outputStream = adoptGRef(g_file_replace(m_destinationFile.get(), nullptr, FALSE, G_FILE_CREATE_NONE, nullptr, &error.outPtr())); - else - outputStream = adoptGRef(g_file_create(m_destinationFile.get(), G_FILE_CREATE_NONE, nullptr, &error.outPtr())); - if (!outputStream) { - m_destinationFile.clear(); - downloadFailed(platformDownloadDestinationError(response, error->message)); - return; - } - - String intermediateURI = destinationURI + ".wkdownload"; - m_intermediateFile = adoptGRef(g_file_new_for_uri(intermediateURI.utf8().data())); - m_outputStream = adoptGRef(g_file_replace(m_intermediateFile.get(), 0, TRUE, G_FILE_CREATE_NONE, 0, &error.outPtr())); - if (!m_outputStream) { - downloadFailed(platformDownloadDestinationError(response, error->message)); - return; - } - - m_download->didCreateDestination(destinationURI); - } - - void didReceiveData(ResourceHandle*, const char* data, unsigned length, int /*encodedDataLength*/) - { - if (m_handleResponseLaterID) { - g_source_remove(m_handleResponseLaterID); - handleResponse(); - } - - gsize bytesWritten; - GUniqueOutPtr<GError> error; - g_output_stream_write_all(G_OUTPUT_STREAM(m_outputStream.get()), data, length, &bytesWritten, 0, &error.outPtr()); - if (error) { - downloadFailed(platformDownloadDestinationError(m_response, error->message)); - return; - } - m_download->didReceiveData(bytesWritten); - } - - void didFinishLoading(ResourceHandle*, double) - { - m_outputStream = 0; - - ASSERT(m_destinationFile); - ASSERT(m_intermediateFile); - GUniqueOutPtr<GError> error; - if (!g_file_move(m_intermediateFile.get(), m_destinationFile.get(), G_FILE_COPY_OVERWRITE, nullptr, nullptr, nullptr, &error.outPtr())) { - downloadFailed(platformDownloadDestinationError(m_response, error->message)); - return; - } - - GRefPtr<GFileInfo> info = adoptGRef(g_file_info_new()); - CString uri = m_response.url().string().utf8(); - g_file_info_set_attribute_string(info.get(), "metadata::download-uri", uri.data()); - g_file_info_set_attribute_string(info.get(), "xattr::xdg.origin.url", uri.data()); - g_file_set_attributes_async(m_destinationFile.get(), info.get(), G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, nullptr, nullptr, nullptr); - - m_download->didFinish(); - } - - void didFail(ResourceHandle*, const ResourceError& error) - { - downloadFailed(platformDownloadNetworkError(error.errorCode(), error.failingURL(), error.localizedDescription())); - } - - void wasBlocked(ResourceHandle*) - { - notImplemented(); - } - - void cannotShowURL(ResourceHandle*) - { - notImplemented(); - } - - void cancel(ResourceHandle* handle) - { - handle->cancel(); - deleteFilesIfNeeded(); - m_download->didCancel(IPC::DataReference()); - } - - void handleResponse() - { - m_handleResponseLaterID = 0; - didReceiveResponse(0, m_delayedResponse); - } - - static gboolean handleResponseLaterCallback(DownloadClient* downloadClient) - { - downloadClient->handleResponse(); - return FALSE; - } - - void handleResponseLater(const ResourceResponse& response) - { - ASSERT(m_response.isNull()); - ASSERT(!m_handleResponseLaterID); - - m_delayedResponse = response; - - // Call didReceiveResponse in an idle to make sure the download is added - // to the DownloadManager downloads map. - m_handleResponseLaterID = g_idle_add_full(G_PRIORITY_DEFAULT, reinterpret_cast<GSourceFunc>(handleResponseLaterCallback), this, 0); - } - - Download* m_download; - GRefPtr<GFileOutputStream> m_outputStream; - ResourceResponse m_response; - GRefPtr<GFile> m_destinationFile; - GRefPtr<GFile> m_intermediateFile; - ResourceResponse m_delayedResponse; - unsigned m_handleResponseLaterID; - bool m_allowOverwrite; -}; - -void Download::start() -{ - ASSERT(!m_downloadClient); - ASSERT(!m_resourceHandle); - m_downloadClient = adoptPtr(new DownloadClient(this)); - m_resourceHandle = ResourceHandle::create(0, m_request, m_downloadClient.get(), false, false); - didStart(); -} - -void Download::startWithHandle(ResourceHandle* resourceHandle, const ResourceResponse& response) -{ - ASSERT(!m_downloadClient); - ASSERT(!m_resourceHandle); - m_downloadClient = adoptPtr(new DownloadClient(this)); - resourceHandle->setClient(m_downloadClient.get()); - m_resourceHandle = resourceHandle; - didStart(); - static_cast<DownloadClient*>(m_downloadClient.get())->handleResponseLater(response); -} - -void Download::cancel() -{ - if (!m_resourceHandle) - return; - - // Cancelling the download will delete it and platformInvalidate() will be called by the destructor. - // So, we need to set m_resourceHandle to nullptr before actually cancelling the download to make sure - // it won't be cancelled again by platformInvalidate. See https://bugs.webkit.org/show_bug.cgi?id=127650. - RefPtr<ResourceHandle> resourceHandle = m_resourceHandle.release(); - static_cast<DownloadClient*>(m_downloadClient.get())->cancel(resourceHandle.get()); -} - -void Download::platformInvalidate() -{ - if (m_resourceHandle) { - m_resourceHandle->setClient(0); - m_resourceHandle->cancel(); - m_resourceHandle = 0; - } - m_downloadClient.release(); -} - -void Download::didDecideDestination(const String& /*destination*/, bool /*allowOverwrite*/) -{ - notImplemented(); -} - -void Download::platformDidFinish() -{ - m_resourceHandle = 0; -} - -void Download::receivedCredential(const AuthenticationChallenge&, const Credential&) -{ - notImplemented(); -} - -void Download::receivedRequestToContinueWithoutCredential(const AuthenticationChallenge&) -{ - notImplemented(); -} - -void Download::receivedCancellation(const AuthenticationChallenge&) -{ - notImplemented(); -} - -void Download::continueWithoutCredential(const AuthenticationChallenge &) -{ - notImplemented(); -} - -void Download::useCredential(const AuthenticationChallenge&, const Credential&) -{ - notImplemented(); -} - -void Download::cancelAuthenticationChallenge(const AuthenticationChallenge&) -{ - notImplemented(); -} - -} // namespace WebKit diff --git a/Source/WebKit2/Shared/Downloads/soup/DownloadSoupErrors.h b/Source/WebKit2/Shared/Downloads/soup/DownloadSoupErrors.h deleted file mode 100644 index 89e23e083..000000000 --- a/Source/WebKit2/Shared/Downloads/soup/DownloadSoupErrors.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2012 Intel Corporation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef DownloadSoupErrors_h -#define DownloadSoupErrors_h - -#include <WebCore/ResourceHandle.h> -#include <wtf/text/WTFString.h> - -namespace WebKit { - -WebCore::ResourceError platformDownloadNetworkError(int errorCode, const String& failingURL, const String& localizedDescription); -WebCore::ResourceError platformDownloadDestinationError(const WebCore::ResourceResponse&, const String& message); - -} // namespace WebKit - -#endif // DownloadSoupErrors_h |