зеркало из https://github.com/mozilla/gecko-dev.git
Add getToString for convenience of callers.
a=dbaron for closed-tree checkin, npotb, ymmv, hand.
This commit is contained in:
Родитель
e4e798d7e1
Коммит
a1d56454ee
|
@ -54,6 +54,7 @@ interface nsIWebDAVOperationListener : nsISupports
|
|||
const unsigned long MAKE_COLLECTION = 6;
|
||||
const unsigned long LOCK = 7; // XXX need a different listener for token?
|
||||
const unsigned long UNLOCK = 8;
|
||||
|
||||
/**
|
||||
* @param detail will be nsIProperties of the properties.
|
||||
*/
|
||||
|
@ -67,6 +68,11 @@ interface nsIWebDAVOperationListener : nsISupports
|
|||
*/
|
||||
const unsigned long GET_OPTIONS = 11;
|
||||
|
||||
/**
|
||||
* @param detail will be nsISupportsCString of content.
|
||||
*/
|
||||
const unsigned long GET_TO_STRING = 12;
|
||||
|
||||
void onOperationComplete(in unsigned long statusCode,
|
||||
in nsIWebDAVResource resource,
|
||||
in unsigned long operation,
|
||||
|
|
|
@ -108,6 +108,15 @@ interface nsIWebDAVService : nsISupports
|
|||
in nsIWebDAVOperationListener listener,
|
||||
in nsISupports closure);
|
||||
|
||||
/**
|
||||
* GET the resource and return it to the listener as a string.
|
||||
*
|
||||
* @param closure caller-private data returned via listener
|
||||
*/
|
||||
void getToString(in nsIWebDAVResource resource,
|
||||
in nsIWebDAVOperationListener listener,
|
||||
in nsISupports closure);
|
||||
|
||||
/**
|
||||
* @param closure caller-private data returned via listener
|
||||
*/
|
||||
|
|
|
@ -92,7 +92,7 @@ protected:
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
virtual void SignalDetail(PRUint32 statusCode, nsACString &resource,
|
||||
virtual void SignalDetail(PRUint32 statusCode, const nsACString &resource,
|
||||
nsISupports *detail);
|
||||
|
||||
virtual nsresult ProcessResponse(nsIDOMElement *responseElt);
|
||||
|
@ -214,18 +214,24 @@ OperationStreamListener::OnDataAvailable(nsIRequest *aRequest,
|
|||
|
||||
void
|
||||
OperationStreamListener::SignalDetail(PRUint32 statusCode,
|
||||
nsACString &resource,
|
||||
const nsACString &resource,
|
||||
nsISupports *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,
|
||||
mClosure);
|
||||
if (NS_FAILED(mResource->GetResourceURL(getter_AddRefs(resourceURL))))
|
||||
return;
|
||||
if (resource.IsEmpty()) {
|
||||
detailURL = resourceURL;
|
||||
} else {
|
||||
if (NS_FAILED(resourceURL->Clone(getter_AddRefs(detailURI))) ||
|
||||
!(detailURL = do_QueryInterface(detailURI)) ||
|
||||
NS_FAILED(detailURI->SetSpec(resource))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
mListener->OnOperationDetail(statusCode, detailURL, mOperation, detail,
|
||||
mClosure);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -425,6 +431,56 @@ PropfindStreamListener::ProcessResponse(nsIDOMElement *responseElt)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
class GetToStringStreamListener : public OperationStreamListener
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
GetToStringStreamListener(nsIWebDAVResource *resource,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
nsISupports *closure) :
|
||||
OperationStreamListener(resource, listener, closure, nsnull,
|
||||
nsIWebDAVOperationListener::GET_TO_STRING)
|
||||
{ }
|
||||
|
||||
virtual ~GetToStringStreamListener() { }
|
||||
protected:
|
||||
virtual nsresult OnStopRequest(nsIRequest *aRequest,
|
||||
nsISupports *aContext,
|
||||
nsresult aStatusCode);
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED0(GetToStringStreamListener, OperationStreamListener)
|
||||
|
||||
NS_IMETHODIMP
|
||||
GetToStringStreamListener::OnStopRequest(nsIRequest *aRequest,
|
||||
nsISupports *aContext,
|
||||
nsresult aStatusCode)
|
||||
{
|
||||
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))
|
||||
return SignalCompletion(rv);
|
||||
|
||||
if (status != 200)
|
||||
return SignalCompletion(status);
|
||||
|
||||
nsCOMPtr<nsISupportsCString>
|
||||
suppString(do_CreateInstance("@mozilla.org/supports-cstring;1",
|
||||
&rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
suppString->SetData(mBody);
|
||||
|
||||
SignalDetail(status, nsCAutoString(""), suppString);
|
||||
SignalCompletion(status);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIStreamListener *
|
||||
NS_WD_NewPropfindStreamListener(nsIWebDAVResource *resource,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
|
@ -463,3 +519,17 @@ NS_WD_NewGetOperationRequestObserver(nsIWebDAVResource *resource,
|
|||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
return CallQueryInterface(osl, observer);
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_WD_NewGetToStringOperationRequestObserver(nsIWebDAVResource *resource,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
nsISupports *closure,
|
||||
nsIStreamListener **streamListener)
|
||||
{
|
||||
nsCOMPtr<nsIRequestObserver> osl =
|
||||
new GetToStringStreamListener(resource, listener, closure);
|
||||
if (!osl)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
return CallQueryInterface(osl, streamListener);
|
||||
}
|
||||
|
||||
|
|
|
@ -80,6 +80,12 @@ NS_WD_NewGetOperationRequestObserver(nsIWebDAVResource *resource,
|
|||
nsIOutputStream *outstream,
|
||||
nsIRequestObserver **observer);
|
||||
|
||||
nsresult
|
||||
NS_WD_NewGetToStringOperationRequestObserver(nsIWebDAVResource *resource,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
nsISupports *closure,
|
||||
nsIStreamListener **streamListener);
|
||||
|
||||
nsresult
|
||||
NS_WD_GetElementByTagName(nsIDOMElement *parentElt, const nsAString &tagName,
|
||||
nsIDOMElement **elt);
|
||||
|
|
|
@ -461,6 +461,26 @@ nsWebDAVService::GetToOutputStream(nsIWebDAVResource *resource,
|
|||
return Get(resource, streamListener);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWebDAVService::GetToString(nsIWebDAVResource *resource,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
nsISupports *closure)
|
||||
{
|
||||
nsCOMPtr<nsIStreamListener> getListener;
|
||||
nsresult rv;
|
||||
|
||||
rv = NS_WD_NewGetToStringOperationRequestObserver(resource, listener,
|
||||
closure,
|
||||
getter_AddRefs(getListener));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIHttpChannel> channel;
|
||||
rv = ChannelFromResource(resource, getter_AddRefs(channel));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return channel->AsyncOpen(getListener, channel);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWebDAVService::Put(nsIWebDAVResource *resource,
|
||||
const nsACString& contentType, nsIInputStream *data,
|
||||
|
|
|
@ -131,7 +131,7 @@ OperationListener.opToName = { };
|
|||
OperationListener.opNames =
|
||||
["PUT", "GET", "MOVE", "COPY", "REMOVE",
|
||||
"MAKE_COLLECTION", "LOCK", "UNLOCK", "GET_PROPERTIES",
|
||||
"GET_PROPERTY_NAMES"];
|
||||
"GET_PROPERTY_NAMES", "GET_TO_STRING"];
|
||||
for (var i in OperationListener.opNames) {
|
||||
var opName = OperationListener.opNames[i];
|
||||
OperationListener.opToName[CI.nsIWebDAVOperationListener[opName]] = opName;
|
||||
|
@ -166,6 +166,9 @@ OperationListener.prototype =
|
|||
dump(" " + i + " = " + propObj[i] + "\n");
|
||||
|
||||
break;
|
||||
case CI.nsIWebDAVOperationListener.GET_TO_STRING:
|
||||
this.mGetToStringResult = detail.QueryInterface(CI.nsISupportsCString).data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -246,25 +249,10 @@ function GET(url, filename)
|
|||
|
||||
function GET_string(url)
|
||||
{
|
||||
var storageStream = createInstance("@mozilla.org/storagestream;1",
|
||||
"nsIStorageStream");
|
||||
storageStream.init(4096, 0xFFFFFFFF /* PR_UINT32_MAX */, null);
|
||||
|
||||
var buffered =
|
||||
createInstance("@mozilla.org/network/buffered-output-stream;1",
|
||||
"nsIBufferedOutputStream");
|
||||
|
||||
buffered.init(storageStream.getOutputStream(0), 64 * 1024);
|
||||
|
||||
davSvc.getToOutputStream(new Resource(url), buffered,
|
||||
new OperationListener());
|
||||
var listener = new OperationListener();
|
||||
davSvc.getToString(new Resource(url), listener, null);
|
||||
runEventPump();
|
||||
var scriptable = createInstance("@mozilla.org/scriptableinputstream;1",
|
||||
"nsIScriptableInputStream");
|
||||
scriptable.init(storageStream.newInputStream(0));
|
||||
|
||||
var str = scriptable.read(scriptable.available());
|
||||
return str;
|
||||
return listener.mGetToStringResult;
|
||||
}
|
||||
|
||||
function COPY(url, target, recursive, overwrite)
|
||||
|
|
Загрузка…
Ссылка в новой задаче