зеркало из https://github.com/mozilla/pjs.git
Commented nsIXMLHttpRequest. Used the new nsIXPCNativeCallContext::SetReturnValueWasSet method to deal with returning event handler function objects to script callers of nsIXMLHttpRequest::Onload and Onerror. Turned on synchronous requests. This is not part of the Seamonkey build.
This commit is contained in:
Родитель
d40030ca55
Коммит
57e9a0d2e6
|
@ -27,26 +27,151 @@ interface nsIDOMEventListener;
|
|||
|
||||
[scriptable, uuid(b7215e70-4157-11d4-9a42-000064657374)]
|
||||
interface nsIXMLHttpRequest : nsISupports {
|
||||
/**
|
||||
* Native (non-script) mechanism for adding an event listener for
|
||||
* either a load or error event.
|
||||
*
|
||||
* @param type The event the listener is added for - either
|
||||
* "load" or "error".
|
||||
* @param listener The listener to be added.
|
||||
*/
|
||||
[noscript] void addEventListener(in string type,
|
||||
in nsIDOMEventListener listener);
|
||||
in nsIDOMEventListener listener);
|
||||
|
||||
/**
|
||||
* Native (non-script) mechanism for removing an event listener for
|
||||
* either a load or error event.
|
||||
*
|
||||
* @param type The event the listener is removed for - either
|
||||
* "load" or "error".
|
||||
* @param listener The listener instance to be removed.
|
||||
*/
|
||||
[noscript] void removeEventListener(in string type,
|
||||
in nsIDOMEventListener listener);
|
||||
in nsIDOMEventListener listener);
|
||||
|
||||
/**
|
||||
* Meant to be a script-only mechanism for setting a load event listener.
|
||||
* The attribute is expected to be JavaScript function object. When
|
||||
* the load event occurs, the function is invoked.
|
||||
* This attribute should not be used from native code!!
|
||||
*/
|
||||
attribute nsISupports onload;
|
||||
|
||||
/**
|
||||
* Meant to be a script-only mechanism for setting an error event listener.
|
||||
* The attribute is expected to be JavaScript function object. When
|
||||
* the error event occurs, the function is invoked.
|
||||
* This attribute should not be used from native code!!
|
||||
*/
|
||||
attribute nsISupports onerror;
|
||||
|
||||
/**
|
||||
* The response to the HTTP request is parsed as if it were a
|
||||
* text/xml stream. This attributes represents the response as
|
||||
* a DOM Document object. NULL if the request is unsuccessful or
|
||||
* has not yet been sent.
|
||||
*/
|
||||
readonly attribute nsIDOMDocument responseXML;
|
||||
|
||||
/**
|
||||
* The status of the response to the HTTP request.
|
||||
*/
|
||||
readonly attribute unsigned long status;
|
||||
|
||||
/**
|
||||
* The string representing the status of the response to the
|
||||
* HTTP request.
|
||||
*/
|
||||
readonly attribute string statusText;
|
||||
|
||||
/**
|
||||
* If the HTTP request has been sent already, this method will
|
||||
* abort the request.
|
||||
*/
|
||||
void abort();
|
||||
|
||||
/**
|
||||
* Returns all of the HTTP response headers as a string string.
|
||||
*
|
||||
* @returns A string containing all of the response headers.
|
||||
* NULL if the response has not yet been received.
|
||||
*/
|
||||
string getAllResponseHeaders();
|
||||
|
||||
/**
|
||||
* Returns the text of the header with the specified name.
|
||||
*
|
||||
* @param header The name of the header to retrieve
|
||||
* @returns A string containing the text of the header specified.
|
||||
* NULL if the response has not yet been received or the
|
||||
* header does not exist in the response.
|
||||
*/
|
||||
string getResponseHeader(in string header);
|
||||
|
||||
/**
|
||||
* Native (non-script) method to initialize a request. Note that
|
||||
* the HTTP request is not sent until the <code>send</code> method
|
||||
* is invoked.
|
||||
*
|
||||
* @param method The HTTP method - either "POST" or "GET".
|
||||
* @param url The URL to which to send the request.
|
||||
* @param async Whether the request is synchronous or asynchronous
|
||||
* i.e. whether send returns only after the response
|
||||
* is received or if it returns immediately after
|
||||
* sending the request. In the latter case, notification
|
||||
* of completion is sent through the event listeners.
|
||||
* @param user A username for authentication if necessary.
|
||||
* @param password A password for authentication if necessary.
|
||||
*/
|
||||
[noscript] void openRequest(in string method,
|
||||
in wstring url,
|
||||
in boolean async,
|
||||
in string user,
|
||||
in string password);
|
||||
void open(in string method, in wstring url);
|
||||
in string url,
|
||||
in boolean async,
|
||||
in string user,
|
||||
in string password);
|
||||
|
||||
/**
|
||||
* Meant to be a script-only method for initializing a request.
|
||||
* The parameters are similar to the ones detailed in the
|
||||
* description of <code>openRequest</code>, but the last
|
||||
* 3 are optional.
|
||||
*
|
||||
* @param method The HTTP method - either "POST" or "GET".
|
||||
* @param url The URL to which to send the request.
|
||||
* @param async (optional) Whether the request is synchronous or
|
||||
* asynchronous i.e. whether send returns only after
|
||||
* the response is received or if it returns immediately after
|
||||
* sending the request. In the latter case, notification
|
||||
* of completion is sent through the event listeners.
|
||||
* The default value is true.
|
||||
* @param user (optional) A username for authentication if necessary.
|
||||
* The default value is the empty string
|
||||
* @param password (optional) A password for authentication if necessary.
|
||||
* The default value is the empty string
|
||||
*/
|
||||
void open(in string method, in string url);
|
||||
|
||||
/**
|
||||
* Sends the HTTP request. If the request is asynchronous, returns
|
||||
* immediately after sending the request. If it is synchronous
|
||||
* returns only after the response has been received.
|
||||
*
|
||||
* @param body Either an instance of nsIDOMDocument, nsIInputStream
|
||||
* or a string (nsISupportsWString in the native calling
|
||||
* case). This is used to populate the body of the
|
||||
* HTTP request if the HTTP request method is "POST".
|
||||
* If the parameter is a nsIDOMDocument, it is serialized.
|
||||
* If the parameter is a nsIInputStream, it is expected
|
||||
* to contain the ContentType: and ContentLength: headers
|
||||
* and trailing carriage-return/line-feed pairs.
|
||||
*/
|
||||
void send(in nsISupports body);
|
||||
|
||||
/**
|
||||
* Sets a HTTP request header.
|
||||
*
|
||||
* @param header The name of the header to set in the request.
|
||||
* @param value The body of the header.
|
||||
*/
|
||||
void setRequestHeader(in string header, in string value);
|
||||
};
|
||||
|
||||
|
|
|
@ -438,6 +438,7 @@ nsXMLHttpRequest::StuffReturnValue(nsIDOMEventListener* aListener)
|
|||
if (jsel) {
|
||||
jsel->GetFunctionObj(&obj);
|
||||
*val = OBJECT_TO_JSVAL(obj);
|
||||
cc->SetReturnValueWasSet(JS_TRUE);
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
@ -579,6 +580,8 @@ nsXMLHttpRequest::GetStatus(PRUint32 *aStatus)
|
|||
NS_IMETHODIMP
|
||||
nsXMLHttpRequest::GetStatusText(char * *aStatusText)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aStatusText);
|
||||
*aStatusText = nsnull;
|
||||
if (mChannel) {
|
||||
return mChannel->GetResponseString(aStatusText);
|
||||
}
|
||||
|
@ -602,6 +605,7 @@ NS_IMETHODIMP
|
|||
nsXMLHttpRequest::GetAllResponseHeaders(char **_retval)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
*_retval = nsnull;
|
||||
if (mChannel) {
|
||||
nsCOMPtr<nsISimpleEnumerator> enumerator;
|
||||
nsCAutoString headers;
|
||||
|
@ -643,6 +647,7 @@ nsXMLHttpRequest::GetResponseHeader(const char *header, char **_retval)
|
|||
NS_ENSURE_ARG(header);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
*_retval = nsnull;
|
||||
if (mChannel) {
|
||||
nsCOMPtr<nsIAtom> headerAtom = dont_AddRef(NS_NewAtom(header));
|
||||
return mChannel->GetResponseHeader(headerAtom, _retval);
|
||||
|
@ -651,10 +656,10 @@ nsXMLHttpRequest::GetResponseHeader(const char *header, char **_retval)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* noscript void openRequest (in string method, in wstring url, in boolean async, in string user, in string password); */
|
||||
/* noscript void openRequest (in string method, in string url, in boolean async, in string user, in string password); */
|
||||
NS_IMETHODIMP
|
||||
nsXMLHttpRequest::OpenRequest(const char *method,
|
||||
const PRUnichar *url,
|
||||
const char *url,
|
||||
PRBool async,
|
||||
const char *user,
|
||||
const char *password)
|
||||
|
@ -680,8 +685,7 @@ nsXMLHttpRequest::OpenRequest(const char *method,
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
nsAutoString urlStr(url);
|
||||
rv = NS_NewURI(getter_AddRefs(uri), urlStr, mBaseURI);
|
||||
rv = NS_NewURI(getter_AddRefs(uri), url, mBaseURI);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Only http URLs are allowed
|
||||
|
@ -723,9 +727,9 @@ nsXMLHttpRequest::OpenRequest(const char *method,
|
|||
return rv;
|
||||
}
|
||||
|
||||
/* void open (in string method, in wstring url); */
|
||||
/* void open (in string method, in string url); */
|
||||
NS_IMETHODIMP
|
||||
nsXMLHttpRequest::Open(const char *method, const PRUnichar *url)
|
||||
nsXMLHttpRequest::Open(const char *method, const char *url)
|
||||
{
|
||||
nsresult rv;
|
||||
PRBool async = PR_TRUE;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#ifndef nsXMLHttpRequest_h__
|
||||
#define nsXMLHttpRequest_h__
|
||||
|
||||
//#define IMPLEMENT_SYNC_LOAD
|
||||
#define IMPLEMENT_SYNC_LOAD
|
||||
|
||||
#include "nsIXMLHttpRequest.h"
|
||||
#include "nsISupportsUtils.h"
|
||||
|
|
Загрузка…
Ссылка в новой задаче