diff options
Diffstat (limited to 'Source/WebKit2/WebProcess/Downloads')
8 files changed, 174 insertions, 40 deletions
diff --git a/Source/WebKit2/WebProcess/Downloads/Download.cpp b/Source/WebKit2/WebProcess/Downloads/Download.cpp index 3cb5588..1c36df2 100644 --- a/Source/WebKit2/WebProcess/Downloads/Download.cpp +++ b/Source/WebKit2/WebProcess/Downloads/Download.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * 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 @@ -23,6 +23,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" #include "Download.h" #include "Connection.h" @@ -45,6 +46,9 @@ PassOwnPtr<Download> Download::create(uint64_t downloadID, const ResourceRequest Download::Download(uint64_t downloadID, const ResourceRequest& request) : m_downloadID(downloadID) , m_request(request) +#if USE(CFNETWORK) + , m_allowOverwrite(false) +#endif { ASSERT(m_downloadID); } @@ -83,7 +87,7 @@ bool Download::shouldDecodeSourceDataOfMIMEType(const String& mimeType) return result; } -String Download::decideDestinationWithSuggestedFilename(const String& filename, bool& allowOverwrite) +String Download::retrieveDestinationWithSuggestedFilename(const String& filename, bool& allowOverwrite) { String destination; SandboxExtension::Handle sandboxExtensionHandle; @@ -97,6 +101,15 @@ String Download::decideDestinationWithSuggestedFilename(const String& filename, 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)); @@ -104,6 +117,8 @@ void Download::didCreateDestination(const String& path) void Download::didFinish() { + platformDidFinish(); + send(Messages::DownloadProxy::DidFinish()); if (m_sandboxExtension) diff --git a/Source/WebKit2/WebProcess/Downloads/Download.h b/Source/WebKit2/WebProcess/Downloads/Download.h index bacdd01..26d8f3d 100644 --- a/Source/WebKit2/WebProcess/Downloads/Download.h +++ b/Source/WebKit2/WebProcess/Downloads/Download.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * 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 @@ -33,13 +33,9 @@ #if PLATFORM(MAC) #include <wtf/RetainPtr.h> -#ifdef __OBJC__ -@class NSURLDownload; -@class WKDownloadAsDelegate; -#else -class NSURLDownload; -class WKDownloadAsDelegate; -#endif + +OBJC_CLASS NSURLDownload; +OBJC_CLASS WKDownloadAsDelegate; #endif #if USE(CFNETWORK) @@ -84,14 +80,22 @@ public: String decideDestinationWithSuggestedFilename(const String& filename, bool& allowOverwrite); void didCreateDestination(const String& path); void didFinish(); + void platformDidFinish(); void didFail(const WebCore::ResourceError&, const CoreIPC::DataReference& resumeData); void didCancel(const CoreIPC::DataReference& resumeData); + void didDecideDestination(const String&, bool allowOverwrite); + +#if USE(CFNETWORK) + const String& destination() const { return m_destination; } +#endif private: Download(uint64_t downloadID, const WebCore::ResourceRequest&); void platformInvalidate(); + String retrieveDestinationWithSuggestedFilename(const String& filename, bool& allowOverwrite); + uint64_t m_downloadID; WebCore::ResourceRequest m_request; @@ -102,6 +106,9 @@ private: RetainPtr<WKDownloadAsDelegate> m_delegate; #endif #if USE(CFNETWORK) + bool m_allowOverwrite; + String m_destination; + String m_bundlePath; RetainPtr<CFURLDownloadRef> m_download; #endif }; diff --git a/Source/WebKit2/WebProcess/Downloads/DownloadManager.cpp b/Source/WebKit2/WebProcess/Downloads/DownloadManager.cpp index e65883a..1cb288e 100644 --- a/Source/WebKit2/WebProcess/Downloads/DownloadManager.cpp +++ b/Source/WebKit2/WebProcess/Downloads/DownloadManager.cpp @@ -23,6 +23,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" #include "DownloadManager.h" #include "Download.h" diff --git a/Source/WebKit2/WebProcess/Downloads/cf/DownloadCFNet.cpp b/Source/WebKit2/WebProcess/Downloads/cf/DownloadCFNet.cpp index 08c381f..c8a065e 100644 --- a/Source/WebKit2/WebProcess/Downloads/cf/DownloadCFNet.cpp +++ b/Source/WebKit2/WebProcess/Downloads/cf/DownloadCFNet.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * 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 @@ -23,12 +23,14 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" #include "Download.h" #include "DataReference.h" #include "NotImplemented.h" #pragma warning(push, 0) +#include <WebCore/DownloadBundle.h> #include <WebCore/LoaderRunLoopCF.h> #include <WebCore/ResourceError.h> #include <WebCore/ResourceHandle.h> @@ -52,7 +54,7 @@ static void didCreateDestinationCallback(CFURLDownloadRef download, CFURLRef pat static void didFinishCallback(CFURLDownloadRef download, const void* clientInfo); static void didFailCallback(CFURLDownloadRef download, CFErrorRef error, const void* clientInfo); -void Download::start(WebPage* initiatingWebPage) +void Download::start(WebPage*) { ASSERT(!m_download); @@ -70,7 +72,7 @@ void Download::start(WebPage* initiatingWebPage) CFURLDownloadScheduleDownloadWithRunLoop(m_download.get(), loaderRunLoop(), kCFRunLoopDefaultMode); } -void Download::startWithHandle(WebPage* initiatingPage, ResourceHandle* handle, const ResourceRequest& initialRequest, const ResourceResponse& response) +void Download::startWithHandle(WebPage*, ResourceHandle* handle, const ResourceRequest& initialRequest, const ResourceResponse& response) { ASSERT(!m_download); @@ -98,7 +100,18 @@ void Download::startWithHandle(WebPage* initiatingPage, ResourceHandle* handle, void Download::cancel() { - notImplemented(); + ASSERT(m_download); + if (!m_download) + return; + + CFURLDownloadSetDeletesUponFailure(m_download.get(), false); + CFURLDownloadCancel(m_download.get()); + + RetainPtr<CFDataRef> resumeData(AdoptCF, CFURLDownloadCopyResumeData(m_download.get())); + if (resumeData) + DownloadBundle::appendResumeData(resumeData.get(), m_bundlePath); + + didCancel(CoreIPC::DataReference()); } void Download::platformInvalidate() @@ -106,6 +119,21 @@ void Download::platformInvalidate() m_download = nullptr; } +void Download::didDecideDestination(const String& destination, bool allowOverwrite) +{ + ASSERT(!destination.isEmpty()); + if (destination.isEmpty()) + return; + + m_allowOverwrite = allowOverwrite; + m_destination = destination; + m_bundlePath = destination + DownloadBundle::fileExtension(); + + RetainPtr<CFStringRef> bundlePath(AdoptCF, CFStringCreateWithCharactersNoCopy(0, reinterpret_cast<const UniChar*>(m_bundlePath.characters()), m_bundlePath.length(), kCFAllocatorNull)); + RetainPtr<CFURLRef> bundlePathURL(AdoptCF, CFURLCreateWithFileSystemPath(0, bundlePath.get(), kCFURLWindowsPathStyle, false)); + CFURLDownloadSetDestination(m_download.get(), bundlePathURL.get(), allowOverwrite); +} + // CFURLDownload Callbacks ---------------------------------------------------------------- static Download* downloadFromClientInfo(const void* clientInfo) { @@ -136,7 +164,7 @@ void didReceiveResponseCallback(CFURLDownloadRef, CFURLResponseRef response, con } void willResumeWithResponseCallback(CFURLDownloadRef, CFURLResponseRef response, UInt64 startingByte, const void* clientInfo) -{ +{ // FIXME: implement. notImplemented(); } @@ -151,24 +179,20 @@ Boolean shouldDecodeDataOfMIMETypeCallback(CFURLDownloadRef, CFStringRef encodin return downloadFromClientInfo(clientInfo)->shouldDecodeSourceDataOfMIMEType(encodingType); } -void decideDestinationWithSuggestedObjectNameCallback(CFURLDownloadRef cfURLDownloadRef, CFStringRef objectName, const void* clientInfo) +void decideDestinationWithSuggestedObjectNameCallback(CFURLDownloadRef, CFStringRef objectName, const void* clientInfo) { Download* download = downloadFromClientInfo(clientInfo); bool allowOverwrite; - String destination = download->decideDestinationWithSuggestedFilename(objectName, allowOverwrite); - if (destination.isNull()) - return; - - RetainPtr<CFStringRef> cfPath(AdoptCF, CFStringCreateWithCharactersNoCopy(0, reinterpret_cast<const UniChar*>(destination.characters()), destination.length(), kCFAllocatorNull)); - RetainPtr<CFURLRef> pathURL(AdoptCF, CFURLCreateWithFileSystemPath(0, cfPath.get(), kCFURLWindowsPathStyle, false)); - CFURLDownloadSetDestination(cfURLDownloadRef, pathURL.get(), allowOverwrite); + download->decideDestinationWithSuggestedFilename(objectName, allowOverwrite); } -void didCreateDestinationCallback(CFURLDownloadRef, CFURLRef url, const void* clientInfo) -{ - RetainPtr<CFStringRef> path(AdoptCF, CFURLCopyFileSystemPath(url, kCFURLWindowsPathStyle)); - String result(path.get()); - downloadFromClientInfo(clientInfo)->didCreateDestination(result); +void didCreateDestinationCallback(CFURLDownloadRef, CFURLRef, const void* clientInfo) +{ + // The concept of the ".download bundle" is internal to the Download, so we try to hide its + // existence by reporting the final destination was created, when in reality the bundle was created. + + Download* download = downloadFromClientInfo(clientInfo); + download->didCreateDestination(download->destination()); } void didFinishCallback(CFURLDownloadRef, const void* clientInfo) diff --git a/Source/WebKit2/WebProcess/Downloads/cf/win/DownloadCFNetWin.cpp b/Source/WebKit2/WebProcess/Downloads/cf/win/DownloadCFNetWin.cpp new file mode 100644 index 0000000..0dd6508 --- /dev/null +++ b/Source/WebKit2/WebProcess/Downloads/cf/win/DownloadCFNetWin.cpp @@ -0,0 +1,56 @@ +/* + * 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. + */ + +#include "config.h" +#include "Download.h" + +using namespace WebCore; + +namespace WebKit { + +void Download::platformDidFinish() +{ + ASSERT(!m_bundlePath.isEmpty()); + ASSERT(!m_destination.isEmpty()); + + // Try to move the bundle to the final filename. + DWORD flags = MOVEFILE_COPY_ALLOWED | (m_allowOverwrite ? MOVEFILE_REPLACE_EXISTING : 0); + if (::MoveFileExW(m_bundlePath.charactersWithNullTermination(), m_destination.charactersWithNullTermination(), flags)) + return; + + // The move failed. Give the client one more chance to choose the final filename. + m_destination = retrieveDestinationWithSuggestedFilename(m_destination, m_allowOverwrite); + if (m_destination.isEmpty()) + return; + + // We either need to report our final filename as the bundle filename or the updated destination filename. + flags = MOVEFILE_COPY_ALLOWED | (m_allowOverwrite ? MOVEFILE_REPLACE_EXISTING : 0); + if (::MoveFileExW(m_bundlePath.charactersWithNullTermination(), m_destination.charactersWithNullTermination(), flags)) + didCreateDestination(m_destination); + else + didCreateDestination(m_bundlePath); +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/Downloads/curl/DownloadCurl.cpp b/Source/WebKit2/WebProcess/Downloads/curl/DownloadCurl.cpp index 25ed351..eb0a1cd 100644 --- a/Source/WebKit2/WebProcess/Downloads/curl/DownloadCurl.cpp +++ b/Source/WebKit2/WebProcess/Downloads/curl/DownloadCurl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * 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 @@ -24,6 +24,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" #include "Download.h" #include "NotImplemented.h" @@ -52,4 +53,14 @@ void Download::platformInvalidate() notImplemented(); } +void Download::didDecideDestination(const String& destination, bool allowOverwrite) +{ + notImplemented(); +} + +void Download::platformDidFinish() +{ + notImplemented(); +} + } // namespace WebKit diff --git a/Source/WebKit2/WebProcess/Downloads/mac/DownloadMac.mm b/Source/WebKit2/WebProcess/Downloads/mac/DownloadMac.mm index 6839020..0abd744 100644 --- a/Source/WebKit2/WebProcess/Downloads/mac/DownloadMac.mm +++ b/Source/WebKit2/WebProcess/Downloads/mac/DownloadMac.mm @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * 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 @@ -23,16 +23,17 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#include "Download.h" +#import "config.h" +#import "Download.h" -#include <WebCore/BackForwardController.h> -#include <WebCore/HistoryItem.h> -#include <WebCore/Page.h> -#include <WebCore/ResourceHandle.h> -#include <WebCore/ResourceResponse.h> -#include "DataReference.h" -#include "NotImplemented.h" -#include "WebPage.h" +#import <WebCore/BackForwardController.h> +#import <WebCore/HistoryItem.h> +#import <WebCore/Page.h> +#import <WebCore/ResourceHandle.h> +#import <WebCore/ResourceResponse.h> +#import "DataReference.h" +#import "NotImplemented.h" +#import "WebPage.h" @interface NSURLDownload (WebNSURLDownloadDetails) +(id)_downloadWithLoadingConnection:(NSURLConnection *)connection @@ -168,6 +169,14 @@ void Download::platformInvalidate() m_nsURLDownload = nullptr; } +void Download::didDecideDestination(const String& destination, bool allowOverwrite) +{ +} + +void Download::platformDidFinish() +{ +} + } // namespace WebKit @implementation WKDownloadAsDelegate diff --git a/Source/WebKit2/WebProcess/Downloads/qt/DownloadQt.cpp b/Source/WebKit2/WebProcess/Downloads/qt/DownloadQt.cpp index 34fd60e..131f53a 100644 --- a/Source/WebKit2/WebProcess/Downloads/qt/DownloadQt.cpp +++ b/Source/WebKit2/WebProcess/Downloads/qt/DownloadQt.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * 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 @@ -23,6 +23,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" #include "Download.h" #include "NotImplemented.h" @@ -51,4 +52,14 @@ void Download::platformInvalidate() notImplemented(); } +void Download::didDecideDestination(const String& destination, bool allowOverwrite) +{ + notImplemented(); +} + +void Download::platformDidFinish() +{ + notImplemented(); +} + } // namespace WebKit |