Add closure params to everything except get. Not part of build

This commit is contained in:
dmose%mozilla.org 2004-12-02 01:41:03 +00:00
parent 9643fc6c04
commit a0b14f4e2b
6 changed files with 175 additions and 60 deletions

View File

@ -22,6 +22,7 @@
*
* Contributor(s):
* Mike Shaver <shaver@off.net> (original author)
* Dan Mosedale <dan.mosedale@oracle.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -68,9 +69,10 @@ interface nsIWebDAVOperationListener : nsISupports
void onOperationComplete(in unsigned long statusCode,
in nsIWebDAVResource resource,
in unsigned long operation);
in unsigned long operation,
in nsISupports closure);
void onOperationDetail(in unsigned long statusCode,
in nsIURL resource, in unsigned long operation,
in nsISupports detail);
void onOperationDetail(in unsigned long statusCode, in nsIURL resource,
in unsigned long operation, in nsISupports detail,
in nsISupports closure);
};

View File

@ -22,6 +22,7 @@
*
* Contributor(s):
* Mike Shaver <shaver@off.net> (original author)
* Dan Mosedale <dan.mosedale@oracle.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -48,61 +49,103 @@ interface nsIInputStream;
[scriptable,uuid(173ef52e-2a2f-45ca-8f9f-abc7429163c2)]
interface nsIWebDAVService : nsISupports
{
/**
* @param closure caller-private data returned via listener
*/
void lockResources(in PRUint32 count,
[array, size_is(count)]
in nsIWebDAVResource resources,
in nsIWebDAVOperationListener listener);
in nsIWebDAVOperationListener listener,
in nsISupports closure);
/**
* @param closure caller-private data returned via listener
*/
void unlockResources(in PRUint32 count,
[array, size_is(count)]
in nsIWebDAVResource resources,
in nsIWebDAVOperationListener listener);
in nsIWebDAVOperationListener listener,
in nsISupports closure);
/**
* @param closure caller-private data returned via listener
*/
void getResourcePropertyNames(in nsIWebDAVResource resource,
in boolean withDepth,
in nsIWebDAVOperationListener listener);
in nsIWebDAVOperationListener listener,
in nsISupports closure);
/**
* @param closure caller-private data returned via listener
*/
void getResourceProperties(in nsIWebDAVResource resource,
in PRUint32 propCount,
[array, size_is(propCount)]
in string properties, /* XXX wstring? */
in boolean withDepth,
in nsIWebDAVOperationListener listener);
in nsIWebDAVOperationListener listener,
in nsISupports closure);
/**
* @param closure caller-private data returned via listener
*/
void getResourceOptions(in nsIWebDAVResource resource,
in nsIWebDAVOperationListener listener);
in nsIWebDAVOperationListener listener,
in nsISupports closure);
/**
* XXX need to add a closure param
*/
void get(in nsIWebDAVResource resource, in nsIStreamListener listener);
/*
/**
* GET the resource and stick it in the provided OutputStream.
* Your output stream must be buffered, or we will fail miserably.
* I would check that for you and provide a buffered wrapper automatically,
* but there is no way to check if one is needed!
*
* @param closure caller-private data returned via listener
*/
void getToOutputStream(in nsIWebDAVResource resource,
in nsIOutputStream stream,
in nsIWebDAVOperationListener listener);
in nsIWebDAVOperationListener listener,
in nsISupports closure);
/**
* @param closure caller-private data returned via listener
*/
void put(in nsIWebDAVResource resource, in ACString contentType,
in nsIInputStream data, in nsIWebDAVOperationListener listener);
in nsIInputStream data, in nsIWebDAVOperationListener listener,
in nsISupports closure);
/**
* @param closure caller-private data returned via listener
*/
void remove(in nsIWebDAVResource resource,
in nsIWebDAVOperationListener listener);
in nsIWebDAVOperationListener listener,
in nsISupports closure);
/**
* @param closure caller-private data returned via listener
*/
void moveTo(in nsIWebDAVResource resource,
in ACString destination,
in boolean overwrite,
in nsIWebDAVOperationListener listener);
in nsIWebDAVOperationListener listener,
in nsISupports closure);
/**
* @param closure caller-private data returned via listener
*/
void copyTo(in nsIWebDAVResource resource,
in ACString destination,
in boolean recursive,
in boolean overwrite,
in nsIWebDAVOperationListener listener);
in nsIWebDAVOperationListener listener,
in nsISupports closure);
/**
* @param closure caller-private data returned via listener
*/
void makeCollection(in nsIWebDAVResource resource,
in nsIWebDAVOperationListener listener);
in nsIWebDAVOperationListener listener,
in nsISupports closure);
};
[scriptable,uuid(96c8d65a-fa17-408c-8008-1aa2b95952d4)]

View File

@ -74,9 +74,10 @@ public:
OperationStreamListener(nsIWebDAVResource *resource,
nsIWebDAVOperationListener *listener,
nsISupports *closure,
nsIOutputStream *outstream,
PRUint32 mode) :
mResource(resource), mListener(listener),
mResource(resource), mListener(listener), mClosure(closure),
mOutputStream(outstream), mOperation(mode) { }
virtual ~OperationStreamListener() { }
@ -84,7 +85,8 @@ public:
protected:
virtual nsresult SignalCompletion(PRUint32 status)
{
mListener->OnOperationComplete(status, mResource, mOperation);
mListener->OnOperationComplete(status, mResource, mOperation,
mClosure);
if (mOutputStream)
return mOutputStream->Flush();
return NS_OK;
@ -101,6 +103,7 @@ protected:
nsCOMPtr<nsIWebDAVResource> mResource;
nsCOMPtr<nsIWebDAVOperationListener> mListener;
nsCOMPtr<nsISupports> mClosure;
nsCOMPtr<nsIOutputStream> mOutputStream;
PRUint32 mOperation;
nsCString mBody;
@ -119,6 +122,7 @@ NS_IMETHODIMP
OperationStreamListener::OnStartRequest(nsIRequest *aRequest,
nsISupports *aContext)
{
LOG(("OperationStreamListener::OnStartRequest() entered"));
mBody.Truncate();
return NS_OK;
}
@ -131,6 +135,8 @@ OperationStreamListener::OnStopRequest(nsIRequest *aRequest,
PRUint32 status, rv;
nsCOMPtr<nsIHttpChannel> channel = do_QueryInterface(aContext);
LOG(("OperationStreamListener::OnStopRequest() entered"));
rv = channel ? channel->GetResponseStatus(&status) : NS_ERROR_UNEXPECTED;
if (NS_FAILED(rv))
@ -188,6 +194,7 @@ OperationStreamListener::OnDataAvailable(nsIRequest *aRequest,
nsIInputStream *aInputStream,
PRUint32 offset, PRUint32 count)
{
LOG(("OperationStreamListener::OnDataAvailable() entered"));
PRUint32 result;
nsCOMPtr<nsIHttpChannel> channel = do_QueryInterface(aContext);
if (!channel)
@ -216,7 +223,8 @@ OperationStreamListener::SignalDetail(PRUint32 statusCode,
NS_SUCCEEDED(resourceURL->Clone(getter_AddRefs(detailURI))) &&
(detailURL = do_QueryInterface(detailURI)) &&
NS_SUCCEEDED(detailURI->SetSpec(resource))) {
mListener->OnOperationDetail(statusCode, detailURL, mOperation, detail);
mListener->OnOperationDetail(statusCode, detailURL, mOperation, detail,
mClosure);
}
}
@ -268,8 +276,9 @@ public:
PropfindStreamListener(nsIWebDAVResource *resource,
nsIWebDAVOperationListener *listener,
nsISupports *closure,
PRBool isPropname) :
OperationStreamListener(resource, listener, nsnull,
OperationStreamListener(resource, listener, closure, nsnull,
isPropname ?
(PRUint32)nsIWebDAVOperationListener::GET_PROPERTY_NAMES :
(PRUint32)nsIWebDAVOperationListener::GET_PROPERTIES) { }
@ -419,19 +428,21 @@ PropfindStreamListener::ProcessResponse(nsIDOMElement *responseElt)
nsIStreamListener *
NS_WD_NewPropfindStreamListener(nsIWebDAVResource *resource,
nsIWebDAVOperationListener *listener,
nsISupports *closure,
PRBool isPropname)
{
return new PropfindStreamListener(resource, listener, isPropname);
return new PropfindStreamListener(resource, listener, closure, isPropname);
}
nsresult
NS_WD_NewOperationStreamListener(nsIWebDAVResource *resource,
nsIWebDAVOperationListener *listener,
nsISupports *closure,
PRUint32 operation,
nsIStreamListener **streamListener)
{
nsCOMPtr<nsIRequestObserver> osl =
new OperationStreamListener(resource, listener, nsnull,
new OperationStreamListener(resource, listener, closure, nsnull,
operation);
if (!osl)
return NS_ERROR_OUT_OF_MEMORY;
@ -441,11 +452,12 @@ NS_WD_NewOperationStreamListener(nsIWebDAVResource *resource,
nsresult
NS_WD_NewGetOperationRequestObserver(nsIWebDAVResource *resource,
nsIWebDAVOperationListener *listener,
nsISupports *closure,
nsIOutputStream *outstream,
nsIRequestObserver **observer)
{
nsCOMPtr<nsIRequestObserver> osl =
new OperationStreamListener(resource, listener, outstream,
new OperationStreamListener(resource, listener, closure, outstream,
nsIWebDAVOperationListener::GET);
if (!osl)
return NS_ERROR_OUT_OF_MEMORY;

View File

@ -63,17 +63,20 @@ extern PRLogModuleInfo *gDAVLog;
nsresult
NS_WD_NewOperationStreamListener(nsIWebDAVResource *resource,
nsIWebDAVOperationListener *listener,
nsISupports *closure,
PRUint32 operation,
nsIStreamListener **streamListener);
nsIStreamListener *
NS_WD_NewPropfindStreamListener(nsIWebDAVResource *resource,
nsIWebDAVOperationListener *listener,
nsISupports *closure,
PRBool isPropname);
nsresult
NS_WD_NewGetOperationRequestObserver(nsIWebDAVResource *resource,
nsIWebDAVOperationListener *listener,
nsISupports *closure,
nsIOutputStream *outstream,
nsIRequestObserver **observer);

View File

@ -92,7 +92,7 @@ protected:
nsresult PropfindInternal(nsIWebDAVResource *resource, PRUint32 propCount,
const char **properties, PRBool withDepth,
nsIWebDAVOperationListener *listener,
PRBool namesOnly);
nsISupports *closure, PRBool namesOnly);
nsresult SendPropfindDocumentToChannel(nsIDocument *doc,
nsIHttpChannel *channel,
@ -286,14 +286,16 @@ nsWebDAVService::~nsWebDAVService()
NS_IMETHODIMP
nsWebDAVService::LockResources(PRUint32 count, nsIWebDAVResource **resources,
nsIWebDAVOperationListener *listener)
nsIWebDAVOperationListener *listener,
nsISupports *closure)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsWebDAVService::UnlockResources(PRUint32 count, nsIWebDAVResource **resources,
nsIWebDAVOperationListener *listener)
nsIWebDAVOperationListener *listener,
nsISupports *closure)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -301,10 +303,11 @@ nsWebDAVService::UnlockResources(PRUint32 count, nsIWebDAVResource **resources,
NS_IMETHODIMP
nsWebDAVService::GetResourcePropertyNames(nsIWebDAVResource *resource,
PRBool withDepth,
nsIWebDAVOperationListener *listener)
nsIWebDAVOperationListener *listener,
nsISupports *closure)
{
return PropfindInternal(resource, 0, nsnull, withDepth,
listener, PR_TRUE);
listener, closure, PR_TRUE);
}
NS_IMETHODIMP
@ -312,10 +315,11 @@ nsWebDAVService::GetResourceProperties(nsIWebDAVResource *resource,
PRUint32 propCount,
const char **properties,
PRBool withDepth,
nsIWebDAVOperationListener *listener)
nsIWebDAVOperationListener *listener,
nsISupports *closure)
{
return PropfindInternal(resource, propCount, properties, withDepth,
listener, PR_FALSE);
listener, closure, PR_FALSE);
}
nsresult
@ -324,6 +328,7 @@ nsWebDAVService::PropfindInternal(nsIWebDAVResource *resource,
const char **properties,
PRBool withDepth,
nsIWebDAVOperationListener *listener,
nsISupports *closure,
PRBool namesOnly)
{
nsresult rv;
@ -377,8 +382,8 @@ nsWebDAVService::PropfindInternal(nsIWebDAVResource *resource,
RFindInReadable(NS_LITERAL_CSTRING(" "), start, end);
if (start == end) {
nsCAutoString msg(NS_LITERAL_CSTRING("Illegal property name ") +
fullpropName);
nsCAutoString msg(NS_LITERAL_CSTRING("Illegal property name ")
+ fullpropName + NS_LITERAL_CSTRING("\n"));
NS_WARNING(msg.get());
return NS_ERROR_INVALID_ARG;
}
@ -403,7 +408,8 @@ nsWebDAVService::PropfindInternal(nsIWebDAVResource *resource,
}
nsCOMPtr<nsIStreamListener> streamListener =
NS_WD_NewPropfindStreamListener(resource, listener, namesOnly);
NS_WD_NewPropfindStreamListener(resource, listener, closure,
namesOnly);
if (!streamListener)
return NS_ERROR_OUT_OF_MEMORY;
@ -415,7 +421,8 @@ nsWebDAVService::PropfindInternal(nsIWebDAVResource *resource,
NS_IMETHODIMP
nsWebDAVService::GetResourceOptions(nsIWebDAVResource *resource,
nsIWebDAVOperationListener *listener)
nsIWebDAVOperationListener *listener,
nsISupports *closure)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -435,12 +442,14 @@ nsWebDAVService::Get(nsIWebDAVResource *resource, nsIStreamListener *listener)
NS_IMETHODIMP
nsWebDAVService::GetToOutputStream(nsIWebDAVResource *resource,
nsIOutputStream *stream,
nsIWebDAVOperationListener *listener)
nsIWebDAVOperationListener *listener,
nsISupports *closure)
{
nsCOMPtr<nsIRequestObserver> getObserver;
nsresult rv;
rv = NS_WD_NewGetOperationRequestObserver(resource, listener, stream,
rv = NS_WD_NewGetOperationRequestObserver(resource, listener, closure,
stream,
getter_AddRefs(getObserver));
NS_ENSURE_SUCCESS(rv, rv);
@ -455,7 +464,8 @@ nsWebDAVService::GetToOutputStream(nsIWebDAVResource *resource,
NS_IMETHODIMP
nsWebDAVService::Put(nsIWebDAVResource *resource,
const nsACString& contentType, nsIInputStream *data,
nsIWebDAVOperationListener *listener)
nsIWebDAVOperationListener *listener,
nsISupports *closure)
{
nsCOMPtr<nsIHttpChannel> channel;
@ -469,7 +479,7 @@ nsWebDAVService::Put(nsIWebDAVResource *resource,
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStreamListener> streamListener;
rv = NS_WD_NewOperationStreamListener(resource, listener,
rv = NS_WD_NewOperationStreamListener(resource, listener, closure,
nsIWebDAVOperationListener::PUT,
getter_AddRefs(streamListener));
NS_ENSURE_SUCCESS(rv, rv);
@ -489,14 +499,15 @@ nsWebDAVService::Put(nsIWebDAVResource *resource,
NS_IMETHODIMP
nsWebDAVService::Remove(nsIWebDAVResource *resource,
nsIWebDAVOperationListener *listener)
nsIWebDAVOperationListener *listener,
nsISupports *closure)
{
nsCOMPtr<nsIHttpChannel> channel;
nsresult rv = ChannelFromResource(resource, getter_AddRefs(channel));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStreamListener> streamListener;
rv = NS_WD_NewOperationStreamListener(resource, listener,
rv = NS_WD_NewOperationStreamListener(resource, listener, closure,
nsIWebDAVOperationListener::REMOVE,
getter_AddRefs(streamListener));
NS_ENSURE_SUCCESS(rv, rv);
@ -516,14 +527,15 @@ nsWebDAVService::Remove(nsIWebDAVResource *resource,
NS_IMETHODIMP
nsWebDAVService::MakeCollection(nsIWebDAVResource *resource,
nsIWebDAVOperationListener *listener)
nsIWebDAVOperationListener *listener,
nsISupports *closure)
{
nsCOMPtr<nsIHttpChannel> channel;
nsresult rv = ChannelFromResource(resource, getter_AddRefs(channel));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStreamListener> streamListener;
rv = NS_WD_NewOperationStreamListener(resource, listener,
rv = NS_WD_NewOperationStreamListener(resource, listener, closure,
nsIWebDAVOperationListener::MAKE_COLLECTION,
getter_AddRefs(streamListener));
NS_ENSURE_SUCCESS(rv, rv);
@ -545,14 +557,15 @@ NS_IMETHODIMP
nsWebDAVService::MoveTo(nsIWebDAVResource *resource,
const nsACString &destination,
PRBool overwrite,
nsIWebDAVOperationListener *listener)
nsIWebDAVOperationListener *listener,
nsISupports *closure)
{
nsCOMPtr<nsIHttpChannel> channel;
nsresult rv = ChannelFromResource(resource, getter_AddRefs(channel));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStreamListener> streamListener;
rv = NS_WD_NewOperationStreamListener(resource, listener,
rv = NS_WD_NewOperationStreamListener(resource, listener, closure,
nsIWebDAVOperationListener::COPY,
getter_AddRefs(streamListener));
NS_ENSURE_SUCCESS(rv, rv);
@ -588,7 +601,8 @@ NS_IMETHODIMP
nsWebDAVService::CopyTo(nsIWebDAVResource *resource,
const nsACString &destination,
PRBool recursive, PRBool overwrite,
nsIWebDAVOperationListener *listener)
nsIWebDAVOperationListener *listener,
nsISupports *closure)
{
nsCOMPtr<nsIHttpChannel> channel;
@ -596,7 +610,7 @@ nsWebDAVService::CopyTo(nsIWebDAVResource *resource,
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStreamListener> streamListener;
rv = NS_WD_NewOperationStreamListener(resource, listener,
rv = NS_WD_NewOperationStreamListener(resource, listener, closure,
nsIWebDAVOperationListener::COPY,
getter_AddRefs(streamListener));
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -1,3 +1,42 @@
/* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Oracle Corporation code.
*
* The Initial Developer of the Original Code is
* Oracle Corporation
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mike Shaver <mike.x.shaver@oracle.com>
* Dan Mosedale <dan.mosedale@oracle.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
const C = Components;
const CI = C.interfaces;
@ -100,14 +139,14 @@ for (var i in OperationListener.opNames) {
OperationListener.prototype =
{
onOperationComplete: function (status, resource, op)
onOperationComplete: function (status, resource, op, closure)
{
dump(OperationListener.opToName[op] + " " + resource.resourceURL.spec +
" complete: " + status + "\n");
stopEventPump();
},
onOperationDetail: function (status, resource, op, detail)
onOperationDetail: function (status, resource, op, detail, closure)
{
dump(resource.spec + " " + OperationListener.opToName[op] + " (" +
status + "):\n");
@ -158,26 +197,26 @@ function PROPFIND(url, depth, props)
}
davSvc.getResourceProperties(new Resource(url), length, props, depth,
new OperationListener());
new OperationListener(), null);
runEventPump();
}
function PROPFIND_names(url, depth)
{
davSvc.getResourcePropertyNames(new Resource(url), depth,
new OperationListener);
new OperationListener, null);
runEventPump();
}
function DELETE(url)
{
davSvc.remove(new Resource(url), new OperationListener());
davSvc.remove(new Resource(url), new OperationListener(), null);
runEventPump();
}
function MKCOL(url)
{
davSvc.makeCollection(new Resource(url), new OperationListener());
davSvc.makeCollection(new Resource(url), new OperationListener(), null);
runEventPump();
}
@ -231,21 +270,22 @@ function GET_string(url)
function COPY(url, target, recursive, overwrite)
{
davSvc.copyTo(new Resource(url), target, recursive, overwrite,
new OperationListener());
new OperationListener(), null);
runEventPump();
}
function MOVE(url, target, overwrite)
{
davSvc.moveTo(new Resource(url), target, overwrite,
new OperationListener());
new OperationListener(), null);
runEventPump();
}
function PUT(filename, url, contentType)
{
var stream = InputStreamForFile(filename);
davSvc.put(new Resource(url), contentType, stream, new OperationListener());
davSvc.put(new Resource(url), contentType, stream,
new OperationListener(), null);
runEventPump();
}
@ -254,6 +294,7 @@ function PUT_string(string, url, contentType)
var stream = createInstance("@mozilla.org/io/string-input-stream;1",
"nsIStringInputStream");
stream.setData(string, string.length);
davSvc.put(new Resource(url), contentType, stream, new OperationListener());
davSvc.put(new Resource(url), contentType, stream,
new OperationListener(), null);
runEventPump();
}