summaryrefslogtreecommitdiffstats
path: root/Source/WebKit2/UIProcess/Downloads
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit2/UIProcess/Downloads')
-rw-r--r--Source/WebKit2/UIProcess/Downloads/DownloadProxy.cpp179
-rw-r--r--Source/WebKit2/UIProcess/Downloads/DownloadProxy.h90
-rw-r--r--Source/WebKit2/UIProcess/Downloads/DownloadProxy.messages.in33
3 files changed, 302 insertions, 0 deletions
diff --git a/Source/WebKit2/UIProcess/Downloads/DownloadProxy.cpp b/Source/WebKit2/UIProcess/Downloads/DownloadProxy.cpp
new file mode 100644
index 0000000..fcc4a75
--- /dev/null
+++ b/Source/WebKit2/UIProcess/Downloads/DownloadProxy.cpp
@@ -0,0 +1,179 @@
+/*
+ * 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 "DownloadProxy.h"
+
+#include "DataReference.h"
+#include "WebContext.h"
+#include "WebData.h"
+#include "WebProcessMessages.h"
+#include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+static uint64_t generateDownloadID()
+{
+ static uint64_t uniqueDownloadID = 0;
+ return ++uniqueDownloadID;
+}
+
+PassRefPtr<DownloadProxy> DownloadProxy::create(WebContext* webContext)
+{
+ return adoptRef(new DownloadProxy(webContext));
+}
+
+DownloadProxy::DownloadProxy(WebContext* webContext)
+ : m_webContext(webContext)
+ , m_downloadID(generateDownloadID())
+{
+}
+
+DownloadProxy::~DownloadProxy()
+{
+ ASSERT(!m_webContext);
+}
+
+void DownloadProxy::cancel()
+{
+ if (!m_webContext)
+ return;
+
+ m_webContext->process()->send(Messages::WebProcess::CancelDownload(m_downloadID), 0);
+}
+
+void DownloadProxy::invalidate()
+{
+ ASSERT(m_webContext);
+ m_webContext = 0;
+}
+
+void DownloadProxy::processDidClose()
+{
+ if (!m_webContext)
+ return;
+
+ m_webContext->downloadClient().processDidCrash(m_webContext, this);
+}
+
+void DownloadProxy::didStart(const ResourceRequest& request)
+{
+ m_request = request;
+
+ if (!m_webContext)
+ return;
+
+ m_webContext->downloadClient().didStart(m_webContext, this);
+}
+
+void DownloadProxy::didReceiveResponse(const ResourceResponse& response)
+{
+ if (!m_webContext)
+ return;
+
+ m_webContext->downloadClient().didReceiveResponse(m_webContext, this, response);
+}
+
+void DownloadProxy::didReceiveData(uint64_t length)
+{
+ if (!m_webContext)
+ return;
+
+ m_webContext->downloadClient().didReceiveData(m_webContext, this, length);
+}
+
+void DownloadProxy::shouldDecodeSourceDataOfMIMEType(const String& mimeType, bool& result)
+{
+ if (!m_webContext)
+ return;
+
+ result = m_webContext->downloadClient().shouldDecodeSourceDataOfMIMEType(m_webContext, this, mimeType);
+}
+
+void DownloadProxy::decideDestinationWithSuggestedFilename(const String& filename, String& destination, bool& allowOverwrite, SandboxExtension::Handle& sandboxExtensionHandle)
+{
+ if (!m_webContext)
+ return;
+
+ destination = m_webContext->downloadClient().decideDestinationWithSuggestedFilename(m_webContext, this, filename, allowOverwrite);
+
+ if (!destination.isNull())
+ SandboxExtension::createHandle(destination, SandboxExtension::WriteOnly, sandboxExtensionHandle);
+}
+
+void DownloadProxy::didCreateDestination(const String& path)
+{
+ if (!m_webContext)
+ return;
+
+ m_webContext->downloadClient().didCreateDestination(m_webContext, this, path);
+}
+
+void DownloadProxy::didFinish()
+{
+ if (!m_webContext)
+ return;
+
+ m_webContext->downloadClient().didFinish(m_webContext, this);
+
+ // This can cause the DownloadProxy object to be deleted.
+ m_webContext->downloadFinished(this);
+}
+
+static PassRefPtr<WebData> createWebData(const CoreIPC::DataReference& data)
+{
+ if (data.isEmpty())
+ return 0;
+
+ return WebData::create(data.data(), data.size());
+}
+
+void DownloadProxy::didFail(const ResourceError& error, const CoreIPC::DataReference& resumeData)
+{
+ if (!m_webContext)
+ return;
+
+ m_resumeData = createWebData(resumeData);
+
+ m_webContext->downloadClient().didFail(m_webContext, this, error);
+
+ // This can cause the DownloadProxy object to be deleted.
+ m_webContext->downloadFinished(this);
+}
+
+void DownloadProxy::didCancel(const CoreIPC::DataReference& resumeData)
+{
+ m_resumeData = createWebData(resumeData);
+
+ m_webContext->downloadClient().didCancel(m_webContext, this);
+
+ // This can cause the DownloadProxy object to be deleted.
+ m_webContext->downloadFinished(this);
+}
+
+} // namespace WebKit
+
diff --git a/Source/WebKit2/UIProcess/Downloads/DownloadProxy.h b/Source/WebKit2/UIProcess/Downloads/DownloadProxy.h
new file mode 100644
index 0000000..a155d72
--- /dev/null
+++ b/Source/WebKit2/UIProcess/Downloads/DownloadProxy.h
@@ -0,0 +1,90 @@
+/*
+ * 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 DownloadProxy_h
+#define DownloadProxy_h
+
+#include "APIObject.h"
+#include "Connection.h"
+#include "SandboxExtension.h"
+#include <WebCore/ResourceRequest.h>
+#include <wtf/Forward.h>
+#include <wtf/PassRefPtr.h>
+
+namespace WebCore {
+ class ResourceError;
+ class ResourceResponse;
+}
+
+namespace WebKit {
+
+class WebContext;
+class WebData;
+
+class DownloadProxy : public APIObject {
+public:
+ static const Type APIType = TypeDownload;
+
+ static PassRefPtr<DownloadProxy> create(WebContext*);
+ ~DownloadProxy();
+
+ uint64_t downloadID() const { return m_downloadID; }
+ const WebCore::ResourceRequest& request() const { return m_request; }
+ WebData* resumeData() const { return m_resumeData.get(); }
+
+ void cancel();
+
+ void invalidate();
+ void processDidClose();
+
+ void didReceiveDownloadProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
+ CoreIPC::SyncReplyMode didReceiveSyncDownloadProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*);
+
+private:
+ explicit DownloadProxy(WebContext*);
+
+ virtual Type type() const { return APIType; }
+
+ // Message handlers.
+ void didStart(const WebCore::ResourceRequest&);
+ void didReceiveResponse(const WebCore::ResourceResponse&);
+ void didReceiveData(uint64_t length);
+ void shouldDecodeSourceDataOfMIMEType(const String& mimeType, bool& result);
+ void decideDestinationWithSuggestedFilename(const String& filename, String& destination, bool& allowOverwrite, SandboxExtension::Handle& sandboxExtensionHandle);
+ void didCreateDestination(const String& path);
+ void didFinish();
+ void didFail(const WebCore::ResourceError&, const CoreIPC::DataReference& resumeData);
+ void didCancel(const CoreIPC::DataReference& resumeData);
+
+ WebContext* m_webContext;
+ uint64_t m_downloadID;
+
+ RefPtr<WebData> m_resumeData;
+ WebCore::ResourceRequest m_request;
+};
+
+} // namespace WebKit
+
+#endif // DownloadProxy_h
diff --git a/Source/WebKit2/UIProcess/Downloads/DownloadProxy.messages.in b/Source/WebKit2/UIProcess/Downloads/DownloadProxy.messages.in
new file mode 100644
index 0000000..999080b
--- /dev/null
+++ b/Source/WebKit2/UIProcess/Downloads/DownloadProxy.messages.in
@@ -0,0 +1,33 @@
+# 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.
+
+messages -> DownloadProxy {
+ DidStart(WebCore::ResourceRequest request)
+ DidReceiveResponse(WebCore::ResourceResponse response)
+ DidReceiveData(uint64_t length)
+ ShouldDecodeSourceDataOfMIMEType(String mimeType) -> (bool result)
+ DecideDestinationWithSuggestedFilename(String filename) -> (String destination, bool allowOverwrite, WebKit::SandboxExtension::Handle sandboxExtensionHandle)
+ DidCreateDestination(WTF::String path)
+ DidFinish()
+ DidFail(WebCore::ResourceError error, CoreIPC::DataReference resumeData)
+ DidCancel(CoreIPC::DataReference resumeData)
+}