зеркало из https://github.com/mozilla/gecko-dev.git
WebDAV, NPOTB.
- Simplify interfaces by losing implicit parameterization through data on subtypes. - Add ResourceWithLock for manipulating locked resources. - Lose the thinnest OSL-creation wrapper functions; they were just dead boilerplate weight.
This commit is contained in:
Родитель
fa86106a4d
Коммит
1abdd2a93a
|
@ -36,29 +36,15 @@
|
|||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIInputStream;
|
||||
interface nsIProperties;
|
||||
|
||||
[scriptable,uuid(9ec5321f-e3ea-4812-a4c7-5366a01b609e)]
|
||||
interface nsIWebDAVResource : nsISupports
|
||||
{
|
||||
readonly attribute AUTF8String urlSpec;
|
||||
};
|
||||
|
||||
[scriptable,uuid(20f74394-0e19-4bd9-9435-dd29f1644de9)]
|
||||
interface nsIWebDAVResourceWithData : nsIWebDAVResource
|
||||
{
|
||||
readonly attribute nsIInputStream data;
|
||||
};
|
||||
|
||||
[scriptable,uuid(8956be34-abad-4c1a-88eb-cbc1851547ea)]
|
||||
interface nsIWebDAVResourceWithProperties : nsIWebDAVResource
|
||||
interface nsIWebDAVResourceWithLock : nsIWebDAVResource
|
||||
{
|
||||
readonly attribute nsIProperties properties;
|
||||
readonly attribute AUTF8String lockToken;
|
||||
};
|
||||
|
||||
[scriptable,uuid(82e289d9-ba6f-4eab-b325-a6bdaf58be62)]
|
||||
interface nsIWebDAVResourceWithTarget : nsIWebDAVResource
|
||||
{
|
||||
readonly attribute AUTF8String target;
|
||||
};
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
|
||||
interface nsIStreamListener;
|
||||
interface nsIOutputStream;
|
||||
interface nsIInputStream;
|
||||
|
||||
[scriptable,uuid(173ef52e-2a2f-45ca-8f9f-abc7429163c2)]
|
||||
interface nsIWebDAVService : nsISupports
|
||||
|
@ -80,18 +81,21 @@ interface nsIWebDAVService : nsISupports
|
|||
in nsIOutputStream stream,
|
||||
in nsIWebDAVOperationListener listener);
|
||||
|
||||
void put(in nsIWebDAVResourceWithData resource, in ACString contentType,
|
||||
in nsIWebDAVOperationListener listener);
|
||||
void put(in nsIWebDAVResource resource, in ACString contentType,
|
||||
in nsIInputStream data, in nsIWebDAVOperationListener listener);
|
||||
|
||||
void remove(in nsIWebDAVResource resource,
|
||||
in nsIWebDAVOperationListener listener);
|
||||
|
||||
void moveTo(in nsIWebDAVResourceWithTarget resource,
|
||||
void moveTo(in nsIWebDAVResource resource,
|
||||
in ACString destination,
|
||||
in nsIWebDAVOperationListener listener);
|
||||
|
||||
void copyTo(in nsIWebDAVResourceWithTarget resource,
|
||||
void copyTo(in nsIWebDAVResource resource,
|
||||
in ACString destination,
|
||||
in nsIWebDAVOperationListener listener,
|
||||
in boolean recursive);
|
||||
in boolean recursive,
|
||||
in boolean overwrite);
|
||||
|
||||
void makeCollection(in nsIWebDAVResource resource,
|
||||
in nsIWebDAVOperationListener listener);
|
||||
|
|
|
@ -414,39 +414,14 @@ NS_WD_NewPropfindStreamListener(nsIWebDAVResource *resource,
|
|||
}
|
||||
|
||||
nsresult
|
||||
NS_WD_NewPutOperationStreamListener(nsIWebDAVResource *resource,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
nsIStreamListener **streamListener)
|
||||
NS_WD_NewOperationStreamListener(nsIWebDAVResource *resource,
|
||||
PRUint32 operation,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
nsIStreamListener **streamListener)
|
||||
{
|
||||
nsCOMPtr<nsIRequestObserver> osl =
|
||||
new OperationStreamListener(resource, listener, nsnull,
|
||||
nsIWebDAVOperationListener::PUT);
|
||||
if (!osl)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
return CallQueryInterface(osl, streamListener);
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_WD_NewDeleteOperationStreamListener(nsIWebDAVResource *resource,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
nsIStreamListener **streamListener)
|
||||
{
|
||||
nsCOMPtr<nsIRequestObserver> osl =
|
||||
new OperationStreamListener(resource, listener, nsnull,
|
||||
nsIWebDAVOperationListener::REMOVE);
|
||||
if (!osl)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
return CallQueryInterface(osl, streamListener);
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_WD_NewMkcolOperationStreamListener(nsIWebDAVResource *resource,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
nsIStreamListener **streamListener)
|
||||
{
|
||||
nsCOMPtr<nsIRequestObserver> osl =
|
||||
new OperationStreamListener(resource, listener, nsnull,
|
||||
nsIWebDAVOperationListener::MAKE_COLLECTION);
|
||||
operation);
|
||||
if (!osl)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
return CallQueryInterface(osl, streamListener);
|
||||
|
|
|
@ -57,26 +57,17 @@ class nsIDOMNodeList;
|
|||
|
||||
extern PRLogModuleInfo *gDAVLog;
|
||||
|
||||
nsresult
|
||||
NS_WD_NewOperationStreamListener(nsIWebDAVResource *resource,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
PRUint32 operation,
|
||||
nsIStreamListener **streamListener);
|
||||
|
||||
nsIStreamListener *
|
||||
NS_WD_NewPropfindStreamListener(nsIWebDAVResource *resource,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
PRBool isPropname);
|
||||
|
||||
nsresult
|
||||
NS_WD_NewPutOperationStreamListener(nsIWebDAVResource *resource,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
nsIStreamListener **streamListener);
|
||||
|
||||
nsresult
|
||||
NS_WD_NewDeleteOperationStreamListener(nsIWebDAVResource *resource,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
nsIStreamListener **streamListener);
|
||||
|
||||
nsresult
|
||||
NS_WD_NewMkcolOperationStreamListener(nsIWebDAVResource *resource,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
nsIStreamListener **streamListener);
|
||||
|
||||
nsresult
|
||||
NS_WD_NewGetOperationRequestObserver(nsIWebDAVResource *resource,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
|
|
|
@ -81,10 +81,6 @@ protected:
|
|||
nsIHttpChannel** channel,
|
||||
nsIURI ** resourceURI = 0);
|
||||
|
||||
nsresult ChannelWithStreamFromResource(nsIWebDAVResource *resource,
|
||||
nsIHttpChannel **channel,
|
||||
nsIInputStream **stream);
|
||||
|
||||
nsresult CreatePropfindDocument(nsIURI *resourceURI,
|
||||
nsIDOMDocument **requestDoc,
|
||||
nsIDOMElement **propfindElt);
|
||||
|
@ -233,7 +229,8 @@ nsWebDAVService::CreatePropfindDocument(nsIURI *resourceURI,
|
|||
baseDoc->SetDocumentURI(resourceURI);
|
||||
|
||||
nsCOMPtr<nsIDOMElement> elt;
|
||||
rv = NS_WD_AppendElementWithNS(doc, doc, mDAVNSString, NS_LITERAL_STRING("propfind"),
|
||||
rv = NS_WD_AppendElementWithNS(doc, doc, mDAVNSString,
|
||||
NS_LITERAL_STRING("propfind"),
|
||||
getter_AddRefs(elt));
|
||||
elt->SetPrefix(NS_LITERAL_STRING("D"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -246,21 +243,6 @@ nsWebDAVService::CreatePropfindDocument(nsIURI *resourceURI,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsWebDAVService::ChannelWithStreamFromResource(nsIWebDAVResource *resource,
|
||||
nsIHttpChannel **channel,
|
||||
nsIInputStream **stream)
|
||||
{
|
||||
nsresult rv = ChannelFromResource(resource, channel);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIWebDAVResourceWithData> resWithData =
|
||||
do_QueryInterface(resource, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return resWithData->GetData(stream);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsWebDAVService::ChannelFromResource(nsIWebDAVResource *resource,
|
||||
nsIHttpChannel **channel,
|
||||
|
@ -474,26 +456,25 @@ nsWebDAVService::GetToOutputStream(nsIWebDAVResource *resource,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWebDAVService::Put(nsIWebDAVResourceWithData *resource,
|
||||
const nsACString& contentType,
|
||||
nsWebDAVService::Put(nsIWebDAVResource *resource,
|
||||
const nsACString& contentType, nsIInputStream *data,
|
||||
nsIWebDAVOperationListener *listener)
|
||||
{
|
||||
nsCOMPtr<nsIHttpChannel> channel;
|
||||
nsCOMPtr<nsIInputStream> stream;
|
||||
nsresult rv = ChannelWithStreamFromResource(resource,
|
||||
getter_AddRefs(channel),
|
||||
getter_AddRefs(stream));
|
||||
|
||||
nsresult rv = ChannelFromResource(resource, getter_AddRefs(channel));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIUploadChannel> uploadChannel = do_QueryInterface(channel, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = uploadChannel->SetUploadStream(stream, contentType, -1);
|
||||
rv = uploadChannel->SetUploadStream(data, contentType, -1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIStreamListener> streamListener;
|
||||
rv = NS_WD_NewPutOperationStreamListener(resource, listener,
|
||||
getter_AddRefs(streamListener));
|
||||
rv = NS_WD_NewOperationStreamListener(resource, listener,
|
||||
nsIWebDAVOperationListener::PUT,
|
||||
getter_AddRefs(streamListener));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
channel->SetRequestMethod(NS_LITERAL_CSTRING("PUT"));
|
||||
|
@ -518,8 +499,9 @@ nsWebDAVService::Remove(nsIWebDAVResource *resource,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIStreamListener> streamListener;
|
||||
rv = NS_WD_NewDeleteOperationStreamListener(resource, listener,
|
||||
getter_AddRefs(streamListener));
|
||||
rv = NS_WD_NewOperationStreamListener(resource, listener,
|
||||
nsIWebDAVOperationListener::REMOVE,
|
||||
getter_AddRefs(streamListener));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
channel->SetRequestMethod(NS_LITERAL_CSTRING("DELETE"));
|
||||
|
@ -544,8 +526,9 @@ nsWebDAVService::MakeCollection(nsIWebDAVResource *resource,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIStreamListener> streamListener;
|
||||
rv = NS_WD_NewMkcolOperationStreamListener(resource, listener,
|
||||
getter_AddRefs(streamListener));
|
||||
rv = NS_WD_NewOperationStreamListener(resource, listener,
|
||||
nsIWebDAVOperationListener::MAKE_COLLECTION,
|
||||
getter_AddRefs(streamListener));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
channel->SetRequestMethod(NS_LITERAL_CSTRING("MKCOL"));
|
||||
|
@ -562,15 +545,18 @@ nsWebDAVService::MakeCollection(nsIWebDAVResource *resource,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWebDAVService::MoveTo(nsIWebDAVResourceWithTarget *resource,
|
||||
nsWebDAVService::MoveTo(nsIWebDAVResource *resource,
|
||||
const nsACString &destination,
|
||||
nsIWebDAVOperationListener *listener)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWebDAVService::CopyTo(nsIWebDAVResourceWithTarget *resource,
|
||||
nsIWebDAVOperationListener *listener, PRBool recursive)
|
||||
nsWebDAVService::CopyTo(nsIWebDAVResource *resource,
|
||||
const nsACString &destination,
|
||||
nsIWebDAVOperationListener *listener, PRBool recursive,
|
||||
PRBool overwrite)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
|
|
@ -42,9 +42,8 @@ Resource.prototype = {
|
|||
}
|
||||
};
|
||||
|
||||
function ResourceWithFileData(url, filename)
|
||||
function InputStreamForFile(filename)
|
||||
{
|
||||
this.urlSpec = url;
|
||||
var file = makeFile(filename);
|
||||
var instream = createInstance("@mozilla.org/network/file-input-stream;1",
|
||||
"nsIFileInputStream");
|
||||
|
@ -53,20 +52,9 @@ function ResourceWithFileData(url, filename)
|
|||
var buffered = createInstance("@mozilla.org/network/buffered-input-stream;1",
|
||||
"nsIBufferedInputStream");
|
||||
buffered.init(instream, 64 * 1024);
|
||||
this.data = buffered;
|
||||
return buffered;
|
||||
}
|
||||
|
||||
ResourceWithFileData.prototype = {
|
||||
QueryInterface: function(outer, iid) {
|
||||
if (iid.equals(CI.nsIWebDAVResourceWithData))
|
||||
return this;
|
||||
|
||||
return Resource.prototype.QueryInterface.call(this, outer, iid);
|
||||
},
|
||||
|
||||
__proto__: Resource.prototype,
|
||||
};
|
||||
|
||||
function propertiesToKeyArray(props)
|
||||
{
|
||||
return props.getKeys({ });
|
||||
|
@ -214,7 +202,7 @@ function GET(url, filename)
|
|||
|
||||
function PUT(filename, url, contentType)
|
||||
{
|
||||
var resource = new ResourceWithFileData(url, filename);
|
||||
davSvc.put(resource, contentType, new OperationListener());
|
||||
var stream = InputStreamForFile(filename);
|
||||
davSvc.put(new Resource(url), contentType, stream, new OperationListener());
|
||||
runEventPump();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче