1/* 2 * Copyright (C) 2010 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#include "config.h" 27#include "WebDownloadClient.h" 28 29#include "WKAPICast.h" 30#include "WebURLResponse.h" 31#include "WKRetainPtr.h" 32 33using namespace WebCore; 34 35namespace WebKit { 36 37void WebDownloadClient::didStart(WebContext* webContext, DownloadProxy* downloadProxy) 38{ 39 if (!m_client.didStart) 40 return; 41 42 m_client.didStart(toAPI(webContext), toAPI(downloadProxy), m_client.clientInfo); 43} 44 45void WebDownloadClient::didReceiveAuthenticationChallenge(WebContext* webContext, DownloadProxy* downloadProxy, AuthenticationChallengeProxy* authenticationChallengeProxy) 46{ 47 if (!m_client.didReceiveAuthenticationChallenge) 48 return; 49 50 m_client.didReceiveAuthenticationChallenge(toAPI(webContext), toAPI(downloadProxy), toAPI(authenticationChallengeProxy), m_client.clientInfo); 51} 52 53void WebDownloadClient::didReceiveResponse(WebContext* webContext, DownloadProxy* downloadProxy, const ResourceResponse& response) 54{ 55 if (!m_client.didReceiveResponse) 56 return; 57 58 m_client.didReceiveResponse(toAPI(webContext), toAPI(downloadProxy), toAPI(WebURLResponse::create(response).get()), m_client.clientInfo); 59} 60 61void WebDownloadClient::didReceiveData(WebContext* webContext, DownloadProxy* downloadProxy, uint64_t length) 62{ 63 if (!m_client.didReceiveData) 64 return; 65 66 m_client.didReceiveData(toAPI(webContext), toAPI(downloadProxy), length, m_client.clientInfo); 67} 68 69bool WebDownloadClient::shouldDecodeSourceDataOfMIMEType(WebContext* webContext, DownloadProxy* downloadProxy, const String& mimeType) 70{ 71 if (!m_client.shouldDecodeSourceDataOfMIMEType) 72 return true; 73 74 return m_client.shouldDecodeSourceDataOfMIMEType(toAPI(webContext), toAPI(downloadProxy), toAPI(mimeType.impl()), m_client.clientInfo); 75} 76 77String WebDownloadClient::decideDestinationWithSuggestedFilename(WebContext* webContext, DownloadProxy* downloadProxy, const String& filename, bool& allowOverwrite) 78{ 79 if (!m_client.decideDestinationWithSuggestedFilename) 80 return String(); 81 82 WKRetainPtr<WKStringRef> destination(AdoptWK, m_client.decideDestinationWithSuggestedFilename(toAPI(webContext), toAPI(downloadProxy), toAPI(filename.impl()), &allowOverwrite, m_client.clientInfo)); 83 return toWTFString(destination.get()); 84} 85 86void WebDownloadClient::didCreateDestination(WebContext* webContext, DownloadProxy* downloadProxy, const String& path) 87{ 88 if (!m_client.didCreateDestination) 89 return; 90 91 m_client.didCreateDestination(toAPI(webContext), toAPI(downloadProxy), toAPI(path.impl()), m_client.clientInfo); 92} 93 94void WebDownloadClient::didFinish(WebContext* webContext, DownloadProxy* downloadProxy) 95{ 96 if (!m_client.didFinish) 97 return; 98 99 m_client.didFinish(toAPI(webContext), toAPI(downloadProxy), m_client.clientInfo); 100} 101 102void WebDownloadClient::didFail(WebContext* webContext, DownloadProxy* downloadProxy, const ResourceError& error) 103{ 104 if (!m_client.didFail) 105 return; 106 107 m_client.didFail(toAPI(webContext), toAPI(downloadProxy), toAPI(error), m_client.clientInfo); 108} 109 110void WebDownloadClient::didCancel(WebContext* webContext, DownloadProxy* downloadProxy) 111{ 112 if (!m_client.didCancel) 113 return; 114 115 m_client.didCancel(toAPI(webContext), toAPI(downloadProxy), m_client.clientInfo); 116} 117 118void WebDownloadClient::processDidCrash(WebContext* webContext, DownloadProxy* downloadProxy) 119{ 120 if (!m_client.processDidCrash) 121 return; 122 123 m_client.processDidCrash(toAPI(webContext), toAPI(downloadProxy), m_client.clientInfo); 124} 125 126} // namespace WebKit 127