Change interfaces to use nsIURL to specific resources, instead of UTF8 strings.

Don't cap the storage stream (and therefore the generated PROPFIND request
body) at 256K.

Don't leak a ref on the resource's URL if we can't QI the channel we create
to nsIHttpChannel.  (Honestly, though, that really shouldn't happen.)
This commit is contained in:
shaver%mozilla.org 2004-11-19 09:12:41 +00:00
Родитель 960e751ca0
Коммит b64fa152b4
5 изменённых файлов: 42 добавлений и 30 удалений

Просмотреть файл

@ -35,7 +35,9 @@
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl" #include "nsISupports.idl"
#include "nsIWebDAVResource.idl"
interface nsIURL;
interface nsIWebDAVResource;
[scriptable,uuid(e198a0fd-9e62-4299-84e3-d93c0cd68881)] [scriptable,uuid(e198a0fd-9e62-4299-84e3-d93c0cd68881)]
interface nsIWebDAVOperationListener : nsISupports interface nsIWebDAVOperationListener : nsISupports
@ -66,6 +68,6 @@ interface nsIWebDAVOperationListener : nsISupports
in unsigned long operation); in unsigned long operation);
void onOperationDetail(in unsigned long statusCode, void onOperationDetail(in unsigned long statusCode,
in AUTF8String resource, in unsigned long operation, in nsIURL resource, in unsigned long operation,
in nsISupports detail); in nsISupports detail);
}; };

Просмотреть файл

@ -36,10 +36,12 @@
#include "nsISupports.idl" #include "nsISupports.idl"
interface nsIURL;
[scriptable,uuid(9ec5321f-e3ea-4812-a4c7-5366a01b609e)] [scriptable,uuid(9ec5321f-e3ea-4812-a4c7-5366a01b609e)]
interface nsIWebDAVResource : nsISupports interface nsIWebDAVResource : nsISupports
{ {
readonly attribute AUTF8String urlSpec; readonly attribute nsIURL resourceURL;
}; };
[scriptable,uuid(8956be34-abad-4c1a-88eb-cbc1851547ea)] [scriptable,uuid(8956be34-abad-4c1a-88eb-cbc1851547ea)]

Просмотреть файл

@ -37,6 +37,7 @@
#include "nsIHttpChannel.h" #include "nsIHttpChannel.h"
#include "nsIIOService.h" #include "nsIIOService.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsIURL.h"
#include "nsIDOM3Node.h" #include "nsIDOM3Node.h"
#include "nsIDOMDocument.h" #include "nsIDOMDocument.h"
@ -206,7 +207,14 @@ OperationStreamListener::SignalDetail(PRUint32 statusCode,
nsACString &resource, nsACString &resource,
nsISupports *detail) nsISupports *detail)
{ {
mListener->OnOperationDetail(statusCode, resource, mOperation, detail); nsCOMPtr<nsIURL> resourceURL, detailURL;
nsCOMPtr<nsIURI> detailURI;
if (NS_SUCCEEDED(mResource->GetResourceURL(getter_AddRefs(resourceURL))) &&
NS_SUCCEEDED(resourceURL->Clone(getter_AddRefs(detailURI))) &&
(detailURL = do_QueryInterface(detailURI)) &&
NS_SUCCEEDED(detailURI->SetSpec(resource))) {
mListener->OnOperationDetail(statusCode, detailURL, mOperation, detail);
}
} }
nsresult nsresult

Просмотреть файл

@ -50,6 +50,7 @@
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsIStorageStream.h" #include "nsIStorageStream.h"
#include "nsIUploadChannel.h" #include "nsIUploadChannel.h"
#include "nsIURL.h"
#include "nsContentCID.h" #include "nsContentCID.h"
@ -128,8 +129,8 @@ nsWebDAVService::SendPropfindDocumentToChannel(nsIDocument *doc,
nsCOMPtr<nsIStorageStream> storageStream; nsCOMPtr<nsIStorageStream> storageStream;
// Why do I have to pick values for these? I just want to store some data // Why do I have to pick values for these? I just want to store some data
// for stream access! (And how would script set these?) // for stream access! (And how would script set these?)
nsresult rv = NS_NewStorageStream(4 * 1024, 256 * 1024, nsresult rv = NS_NewStorageStream(4096, PR_UINT32_MAX,
getter_AddRefs(storageStream)); getter_AddRefs(storageStream));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIOutputStream> storageOutputStream; nsCOMPtr<nsIOutputStream> storageOutputStream;
@ -243,35 +244,29 @@ nsWebDAVService::CreatePropfindDocument(nsIURI *resourceURI,
} }
nsresult nsresult
nsWebDAVService::ChannelFromResource(nsIWebDAVResource *resource, nsWebDAVService::ChannelFromResource(nsIWebDAVResource *aResource,
nsIHttpChannel **channel, nsIHttpChannel **aChannel,
nsIURI **resourceURI) nsIURI **aResourceURI)
{ {
ENSURE_IO_SERVICE(); ENSURE_IO_SERVICE();
nsCAutoString spec; nsCOMPtr<nsIURL> resourceURL;
nsresult rv = resource->GetUrlSpec(spec); nsresult rv = aResource->GetResourceURL(getter_AddRefs(resourceURL));
NS_ENSURE_SUCCESS(rv, rv);
if (spec.IsEmpty()) {
NS_ASSERTION(0, "non-empty spec!");
return NS_ERROR_INVALID_ARG;
}
nsCOMPtr<nsIURI> uri;
rv = mIOService->NewURI(spec, nsnull, nsnull, getter_AddRefs(uri));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIChannel> baseChannel; nsCOMPtr<nsIChannel> baseChannel;
rv = mIOService->NewChannelFromURI(uri, getter_AddRefs(baseChannel)); rv = mIOService->NewChannelFromURI(resourceURL, getter_AddRefs(baseChannel));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (resourceURI) { rv = CallQueryInterface(baseChannel, aChannel);
*resourceURI = uri.get();
NS_ADDREF(*resourceURI); if (NS_SUCCEEDED(rv) && aResourceURI) {
*aResourceURI = resourceURL.get();
NS_ADDREF(*aResourceURI);
} }
return CallQueryInterface(baseChannel, channel); return rv;
} }
nsWebDAVService::nsWebDAVService() : nsWebDAVService::nsWebDAVService() :

Просмотреть файл

@ -26,9 +26,17 @@ function createInstance(contract, iface)
const davSvc = getService("@mozilla.org/webdav/service;1", const davSvc = getService("@mozilla.org/webdav/service;1",
"nsIWebDAVService"); "nsIWebDAVService");
const ioSvc = getService("@mozilla.org/network/io-service;1",
"nsIIOService");
function URLFromSpec(spec)
{
return ioSvc.newURI(spec, null, null);
}
function Resource(url) function Resource(url)
{ {
this.urlSpec = url; this.resourceURL = URLFromSpec(url);
} }
Resource.prototype = { Resource.prototype = {
@ -94,14 +102,14 @@ OperationListener.prototype =
{ {
onOperationComplete: function (status, resource, op) onOperationComplete: function (status, resource, op)
{ {
dump(OperationListener.opToName[op] + " " + resource.urlSpec + dump(OperationListener.opToName[op] + " " + resource.resourceURL.spec +
" complete: " + status + "\n"); " complete: " + status + "\n");
stopEventPump(); stopEventPump();
}, },
onOperationDetail: function (status, resource, op, detail) onOperationDetail: function (status, resource, op, detail)
{ {
dump(resource + " " + OperationListener.opToName[op] + " (" + dump(resource.spec + " " + OperationListener.opToName[op] + " (" +
status + "):\n"); status + "):\n");
switch(op) { switch(op) {
case CI.nsIWebDAVOperationListener.GET_PROPERTY_NAMES: case CI.nsIWebDAVOperationListener.GET_PROPERTY_NAMES:
@ -125,9 +133,6 @@ OperationListener.prototype =
const evQSvc = getService("@mozilla.org/event-queue-service;1", const evQSvc = getService("@mozilla.org/event-queue-service;1",
"nsIEventQueueService"); "nsIEventQueueService");
const ioSvc = getService("@mozilla.org/network/io-service;1",
"nsIIOService");
const evQ = evQSvc.getSpecialEventQueue(CI.nsIEventQueueService.CURRENT_THREAD_EVENT_QUEUE); const evQ = evQSvc.getSpecialEventQueue(CI.nsIEventQueueService.CURRENT_THREAD_EVENT_QUEUE);
function runEventPump() function runEventPump()