diff --git a/extensions/webdav/public/nsIWebDAVService.idl b/extensions/webdav/public/nsIWebDAVService.idl index 10128d88dde..71a9a1f2159 100644 --- a/extensions/webdav/public/nsIWebDAVService.idl +++ b/extensions/webdav/public/nsIWebDAVService.idl @@ -89,13 +89,14 @@ interface nsIWebDAVService : nsISupports void moveTo(in nsIWebDAVResource resource, in ACString destination, + in boolean overwrite, in nsIWebDAVOperationListener listener); void copyTo(in nsIWebDAVResource resource, in ACString destination, - in nsIWebDAVOperationListener listener, in boolean recursive, - in boolean overwrite); + in boolean overwrite, + in nsIWebDAVOperationListener listener); void makeCollection(in nsIWebDAVResource resource, in nsIWebDAVOperationListener listener); diff --git a/extensions/webdav/src/nsWebDAVService.cpp b/extensions/webdav/src/nsWebDAVService.cpp index 9615c916b16..32beb0c8d23 100644 --- a/extensions/webdav/src/nsWebDAVService.cpp +++ b/extensions/webdav/src/nsWebDAVService.cpp @@ -181,13 +181,12 @@ nsWebDAVService::SendPropfindDocumentToChannel(nsIDocument *doc, channel->SetRequestMethod(NS_LITERAL_CSTRING("PROPFIND")); - // XXX I wonder how many compilers this will break... if (withDepth) { channel->SetRequestHeader(NS_LITERAL_CSTRING("Depth"), - NS_LITERAL_CSTRING("1"), false); + NS_LITERAL_CSTRING("1"), PR_FALSE); } else { channel->SetRequestHeader(NS_LITERAL_CSTRING("Depth"), - NS_LITERAL_CSTRING("0"), false); + NS_LITERAL_CSTRING("0"), PR_FALSE); } if (LOG_ENABLED()) { @@ -547,18 +546,95 @@ nsWebDAVService::MakeCollection(nsIWebDAVResource *resource, NS_IMETHODIMP nsWebDAVService::MoveTo(nsIWebDAVResource *resource, const nsACString &destination, + PRBool overwrite, nsIWebDAVOperationListener *listener) { - return NS_ERROR_NOT_IMPLEMENTED; + nsCOMPtr channel; + nsresult rv = ChannelFromResource(resource, getter_AddRefs(channel)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr streamListener; + rv = NS_WD_NewOperationStreamListener(resource, listener, + nsIWebDAVOperationListener::COPY, + getter_AddRefs(streamListener)); + NS_ENSURE_SUCCESS(rv, rv); + + channel->SetRequestMethod(NS_LITERAL_CSTRING("MOVE")); + + if (!overwrite) { + channel->SetRequestHeader(NS_LITERAL_CSTRING("Overwrite"), + NS_LITERAL_CSTRING("F"), + PR_FALSE); + } else { + channel->SetRequestHeader(NS_LITERAL_CSTRING("Overwrite"), + NS_LITERAL_CSTRING("F"), + PR_FALSE); + } + + channel->SetRequestHeader(NS_LITERAL_CSTRING("Destination"), + destination, PR_FALSE); + + if (LOG_ENABLED()) { + nsCOMPtr uri; + channel->GetURI(getter_AddRefs(uri)); + nsCAutoString spec; + uri->GetSpec(spec); + LOG(("MOVE starting for %s -> %s", spec.get(), + nsCAutoString(destination).get())); + } + + return channel->AsyncOpen(streamListener, channel); } NS_IMETHODIMP nsWebDAVService::CopyTo(nsIWebDAVResource *resource, const nsACString &destination, - nsIWebDAVOperationListener *listener, PRBool recursive, - PRBool overwrite) + PRBool recursive, PRBool overwrite, + nsIWebDAVOperationListener *listener) + { - return NS_ERROR_NOT_IMPLEMENTED; + nsCOMPtr channel; + nsresult rv = ChannelFromResource(resource, getter_AddRefs(channel)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr streamListener; + rv = NS_WD_NewOperationStreamListener(resource, listener, + nsIWebDAVOperationListener::COPY, + getter_AddRefs(streamListener)); + NS_ENSURE_SUCCESS(rv, rv); + + channel->SetRequestMethod(NS_LITERAL_CSTRING("COPY")); + if (!overwrite) { + channel->SetRequestHeader(NS_LITERAL_CSTRING("Overwrite"), + NS_LITERAL_CSTRING("F"), + PR_FALSE); + } else { + channel->SetRequestHeader(NS_LITERAL_CSTRING("Overwrite"), + NS_LITERAL_CSTRING("F"), + PR_FALSE); + } + + if (recursive) { + channel->SetRequestHeader(NS_LITERAL_CSTRING("Depth"), + NS_LITERAL_CSTRING("infinity"), PR_FALSE); + } else { + channel->SetRequestHeader(NS_LITERAL_CSTRING("Depth"), + NS_LITERAL_CSTRING("0"), PR_FALSE); + } + + channel->SetRequestHeader(NS_LITERAL_CSTRING("Destination"), + destination, PR_FALSE); + + if (LOG_ENABLED()) { + nsCOMPtr uri; + channel->GetURI(getter_AddRefs(uri)); + nsCAutoString spec; + uri->GetSpec(spec); + LOG(("COPY starting for %s -> %s", spec.get(), + nsCAutoString(destination).get())); + } + + return channel->AsyncOpen(streamListener, channel); } NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebDAVService) diff --git a/extensions/webdav/tests/davshell.js b/extensions/webdav/tests/davshell.js index f2afe16a4f1..64db4b09fce 100644 --- a/extensions/webdav/tests/davshell.js +++ b/extensions/webdav/tests/davshell.js @@ -200,6 +200,20 @@ function GET(url, filename) runEventPump(); } +function COPY(url, target, recursive, overwrite) +{ + davSvc.copyTo(new Resource(url), target, recursive, overwrite, + new OperationListener()); + runEventPump(); +} + +function MOVE(url, target, overwrite) +{ + davSvc.moveTo(new Resource(url), target, overwrite, + new OperationListener()); + runEventPump(); +} + function PUT(filename, url, contentType) { var stream = InputStreamForFile(filename);