From 009bc8414fd3f034aaf970a144f78ff208524bf2 Mon Sep 17 00:00:00 2001 From: "jst%mozilla.jstenback.com" Date: Thu, 20 Apr 2006 03:38:51 +0000 Subject: [PATCH] Fixing bug 232493. Paving the way for DOM Level 3 LS. This is mostly cleanup that will make life easier (and safer) when implementing DOM LS. r=caillon@aillon.org, sr=peterv@propagandism.org git-svn-id: svn://10.0.0.236/trunk@194880 18797224-902f-48f8-a5cc-f745e15eee43 --- .../content/base/public/nsIDOMSerializer.idl | 8 +-- .../content/base/public/nsIXMLHttpRequest.idl | 49 ++++++++++--------- mozilla/content/base/src/nsDOMSerializer.cpp | 42 +++++++--------- mozilla/content/base/src/nsDOMSerializer.h | 5 +- mozilla/content/base/src/nsXMLHttpRequest.cpp | 14 +++--- mozilla/content/base/src/nsXMLHttpRequest.h | 8 +-- 6 files changed, 61 insertions(+), 65 deletions(-) diff --git a/mozilla/content/base/public/nsIDOMSerializer.idl b/mozilla/content/base/public/nsIDOMSerializer.idl index 20ee0539ec6..e1f21c1ae86 100644 --- a/mozilla/content/base/public/nsIDOMSerializer.idl +++ b/mozilla/content/base/public/nsIDOMSerializer.idl @@ -49,7 +49,8 @@ interface nsIDOMNode; */ [scriptable, uuid(a6cf9123-15b3-11d2-932e-00805f8add32)] -interface nsIDOMSerializer : nsISupports { +interface nsIDOMSerializer : nsISupports +{ /** * The subtree rooted by the specified element is serialized to * a string. @@ -58,7 +59,7 @@ interface nsIDOMSerializer : nsISupports { * be any node, including a Document. * @returns The serialized subtree in the form of a Unicode string */ - wstring serializeToString(in nsIDOMNode root); + AString serializeToString(in nsIDOMNode root); /** * The subtree rooted by the specified element is serialized to @@ -69,7 +70,8 @@ interface nsIDOMSerializer : nsISupports { * @param charset The name of the character set to use for the encoding * to a byte stream. */ - void serializeToStream(in nsIDOMNode root, in nsIOutputStream stream, in string charset); + void serializeToStream(in nsIDOMNode root, in nsIOutputStream stream, + in AUTF8String charset); }; %{ C++ diff --git a/mozilla/content/base/public/nsIXMLHttpRequest.idl b/mozilla/content/base/public/nsIXMLHttpRequest.idl index 10cd053b043..aa9a9bf9374 100644 --- a/mozilla/content/base/public/nsIXMLHttpRequest.idl +++ b/mozilla/content/base/public/nsIXMLHttpRequest.idl @@ -73,14 +73,15 @@ interface nsIVariant; * target->AddEventListener(NS_LITERAL_STRING("load"), mylistener, * PR_FALSE) * - * where mylistener is your event listener object that implements the + * where mylistener is your event listener object that implements the * interface nsIDOMEventListener. * * The 'onload' and 'onerror' attributes moved to nsIJSXMLHttRequest, * but if you're coding in C++ you should avoid using those. */ [scriptable, uuid(b7215e70-4157-11d4-9a42-000064657374)] -interface nsIXMLHttpRequest : nsISupports { +interface nsIXMLHttpRequest : nsISupports +{ /** * The request uses a channel in order to perform the * request. This attribute represents the channel used @@ -93,22 +94,22 @@ interface nsIXMLHttpRequest : nsISupports { /** * The response to the request is parsed as if it were a - * text/xml stream. This attributes represents the response as + * 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 response to the request as text. + * The response to the request as text. * NULL if the request is unsuccessful or * has not yet been sent. */ - readonly attribute wstring responseText; + readonly attribute AString responseText; /** - * The status of the response to the request for HTTP requests. + * The status of the response to the request for HTTP requests. */ readonly attribute unsigned long status; @@ -116,7 +117,7 @@ interface nsIXMLHttpRequest : nsISupports { * The string representing the status of the response for * HTTP requests. */ - readonly attribute string statusText; + readonly attribute AUTF8String statusText; /** * If the request has been sent already, this method will @@ -127,11 +128,11 @@ interface nsIXMLHttpRequest : nsISupports { /** * Returns all of the response headers as a string for HTTP * requests. - * - * @returns A string containing all of the response headers. + * + * @returns A string containing all of the response headers. * NULL if the response has not yet been received. */ - string getAllResponseHeaders(); + string getAllResponseHeaders(); /** * Returns the text of the header with the specified name for @@ -142,11 +143,11 @@ interface nsIXMLHttpRequest : nsISupports { * NULL if the response has not yet been received or the * header does not exist in the response. */ - string getResponseHeader(in string header); + ACString getResponseHeader(in AUTF8String header); /** * Native (non-script) method to initialize a request. Note that - * the request is not sent until the send method + * the request is not sent until the send method * is invoked. * * Will abort currently active loads. @@ -165,11 +166,11 @@ interface nsIXMLHttpRequest : nsISupports { * @param user A username for authentication if necessary. * @param password A password for authentication if necessary. */ - [noscript] void openRequest(in string method, - in string url, + [noscript] void openRequest(in AUTF8String method, + in AUTF8String url, in boolean async, - in string user, - in string password); + in AString user, + in AString password); /** * Meant to be a script-only method for initializing a request. @@ -185,18 +186,18 @@ interface nsIXMLHttpRequest : nsISupports { * @param method The HTTP method - either "POST" or "GET". Ignored * if the URL is not a HTTP URL. * @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 + * @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. + * @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); + void open(in AUTF8String method, in AUTF8String url); /** * Sends the request. If the request is asynchronous, returns @@ -224,7 +225,7 @@ interface nsIXMLHttpRequest : nsISupports { * @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); + void setRequestHeader(in AUTF8String header, in AUTF8String value); /** * The state of the request. @@ -247,7 +248,7 @@ interface nsIXMLHttpRequest : nsISupports { * @param mimetype The type used to override that returned by the server * (if any). */ - void overrideMimeType(in string mimetype); + void overrideMimeType(in AUTF8String mimetype); }; @@ -265,7 +266,7 @@ interface nsIJSXMLHttpRequest : nsISupports { /** * 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. + * the load event occurs, the function is invoked. * This attribute should not be used from native code!! * * After the initial response, all event listeners will be cleared. @@ -278,7 +279,7 @@ interface nsIJSXMLHttpRequest : nsISupports { /** * 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. + * the error event occurs, the function is invoked. * This attribute should not be used from native code!! * * After the initial response, all event listeners will be cleared. diff --git a/mozilla/content/base/src/nsDOMSerializer.cpp b/mozilla/content/base/src/nsDOMSerializer.cpp index e1952e9f29e..05798233e3c 100644 --- a/mozilla/content/base/src/nsDOMSerializer.cpp +++ b/mozilla/content/base/src/nsDOMSerializer.cpp @@ -73,12 +73,15 @@ NS_IMPL_ADDREF(nsDOMSerializer) NS_IMPL_RELEASE(nsDOMSerializer) -static nsresult SetUpEncoder(nsIDOMNode *aRoot, const char* aCharset, nsIDocumentEncoder **aEncoder) +static nsresult +SetUpEncoder(nsIDOMNode *aRoot, const nsACString& aCharset, + nsIDocumentEncoder **aEncoder) { *aEncoder = nsnull; nsresult rv; - nsCOMPtr encoder(do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "text/xml",&rv)); + nsCOMPtr encoder = + do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "text/xml", &rv); if (NS_FAILED(rv)) return rv; @@ -94,21 +97,21 @@ static nsresult SetUpEncoder(nsIDOMNode *aRoot, const char* aCharset, nsIDocumen } // This method will fail if no document - rv = encoder->Init(document,NS_LITERAL_STRING("text/xml"),nsIDocumentEncoder::OutputEncodeBasicEntities); + rv = encoder->Init(document, NS_LITERAL_STRING("text/xml"), + nsIDocumentEncoder::OutputEncodeBasicEntities); if (NS_FAILED(rv)) return rv; - nsCAutoString charset; - if (aCharset) { - charset = aCharset; - } else { + nsCAutoString charset(aCharset); + if (charset.IsEmpty()) { charset = document->GetDocumentCharacterSet(); } rv = encoder->SetCharset(charset); if (NS_FAILED(rv)) return rv; - // If we are working on the entire document we do not need to specify which part to serialize + // If we are working on the entire document we do not need to + // specify which part to serialize if (!entireDocument) { rv = encoder->SetNode(aRoot); } @@ -121,7 +124,8 @@ static nsresult SetUpEncoder(nsIDOMNode *aRoot, const char* aCharset, nsIDocumen return rv; } -nsresult CheckSameOrigin(nsIDOMNode *aRoot) +static nsresult +CheckSameOrigin(nsIDOMNode *aRoot) { // Get JSContext from stack. nsCOMPtr stack = @@ -177,38 +181,28 @@ nsresult CheckSameOrigin(nsIDOMNode *aRoot) } NS_IMETHODIMP -nsDOMSerializer::SerializeToString(nsIDOMNode *aRoot, PRUnichar **_retval) +nsDOMSerializer::SerializeToString(nsIDOMNode *aRoot, nsAString& _retval) { NS_ENSURE_ARG_POINTER(aRoot); - NS_ENSURE_ARG_POINTER(_retval); - *_retval = nsnull; + _retval.Truncate(); nsresult rv = CheckSameOrigin(aRoot); if (NS_FAILED(rv)) return rv; nsCOMPtr encoder; - rv = SetUpEncoder(aRoot, nsnull, getter_AddRefs(encoder)); + rv = SetUpEncoder(aRoot, EmptyCString(), getter_AddRefs(encoder)); if (NS_FAILED(rv)) return rv; - nsAutoString str; - rv = encoder->EncodeToString(str); - if (NS_FAILED(rv)) - return rv; - - *_retval = ToNewUnicode(str); - if (!*_retval) - return NS_ERROR_OUT_OF_MEMORY; - - return NS_OK; + return encoder->EncodeToString(_retval); } NS_IMETHODIMP nsDOMSerializer::SerializeToStream(nsIDOMNode *aRoot, nsIOutputStream *aStream, - const char *aCharset) + const nsACString& aCharset) { NS_ENSURE_ARG_POINTER(aRoot); NS_ENSURE_ARG_POINTER(aStream); diff --git a/mozilla/content/base/src/nsDOMSerializer.h b/mozilla/content/base/src/nsDOMSerializer.h index cbd198eff67..e9ed15e43bf 100644 --- a/mozilla/content/base/src/nsDOMSerializer.h +++ b/mozilla/content/base/src/nsDOMSerializer.h @@ -50,10 +50,7 @@ public: NS_DECL_ISUPPORTS // nsIDOMSerializer - NS_IMETHOD SerializeToString(nsIDOMNode *root, PRUnichar **_retval); - NS_IMETHOD SerializeToStream(nsIDOMNode *root, - nsIOutputStream *stream, - const char *charset); + NS_DECL_NSIDOMSERIALIZER }; diff --git a/mozilla/content/base/src/nsXMLHttpRequest.cpp b/mozilla/content/base/src/nsXMLHttpRequest.cpp index ff8ebb17436..de8cc7828ce 100644 --- a/mozilla/content/base/src/nsXMLHttpRequest.cpp +++ b/mozilla/content/base/src/nsXMLHttpRequest.cpp @@ -607,7 +607,7 @@ nsXMLHttpRequest::GetBaseURI() nsCOMPtr doc = GetDocumentFromScriptContext(mScriptContext); if (!doc) { - nsnull; + return nsnull; } return doc->GetBaseURI(); @@ -843,16 +843,18 @@ nsXMLHttpRequest::Open(const nsACString& method, const nsACString& url) JSString* userStr = ::JS_ValueToString(cx, argv[3]); if (userStr) { - user.Assign((PRUnichar *)::JS_GetStringChars(userStr), + user.Assign(NS_REINTERPRET_CAST(PRUnichar *, + ::JS_GetStringChars(userStr)), ::JS_GetStringLength(userStr)); } if (argc > 4) { - JSString* passwordStr = JS_ValueToString(cx, argv[4]); + JSString* passwdStr = JS_ValueToString(cx, argv[4]); - if (passwordStr) { - password.Assign((PRUnichar *)::JS_GetStringChars(passwordStr), - ::JS_GetStringLength(passwordStr)); + if (passwdStr) { + password.Assign(NS_REINTERPRET_CAST(PRUnichar *, + ::JS_GetStringChars(passwdStr)), + ::JS_GetStringLength(passwdStr)); } } } diff --git a/mozilla/content/base/src/nsXMLHttpRequest.h b/mozilla/content/base/src/nsXMLHttpRequest.h index df642a13c52..96345d8ad92 100644 --- a/mozilla/content/base/src/nsXMLHttpRequest.h +++ b/mozilla/content/base/src/nsXMLHttpRequest.h @@ -110,7 +110,7 @@ protected: PRInt32 aLength, nsIInputStream** aStream); nsresult DetectCharset(nsACString& aCharset); - nsresult ConvertBodyToText(PRUnichar **aOutBuffer); + nsresult ConvertBodyToText(nsAString& aOutBuffer); static NS_METHOD StreamReaderFunc(nsIInputStream* in, void* closure, const char* fromRawSegment, @@ -122,16 +122,16 @@ protected: nsresult ChangeState(PRUint32 aState, PRBool aBroadcast = PR_TRUE); nsresult RequestCompleted(); nsresult GetLoadGroup(nsILoadGroup **aLoadGroup); - nsresult GetBaseURI(nsIURI **aBaseURI); + nsIURI *GetBaseURI(); nsresult CreateEvent(PRUint32 msg, nsIDOMEvent** domevent); - void NotifyEventListeners(nsIDOMEventListener* aHandler, nsISupportsArray* aListeners, nsIDOMEvent* aEvent); + void NotifyEventListeners(nsIDOMEventListener* aHandler, + nsISupportsArray* aListeners, nsIDOMEvent* aEvent); void ClearEventListeners(); nsCOMPtr mContext; nsCOMPtr mChannel; nsCOMPtr mReadRequest; nsCOMPtr mDocument; - nsCOMPtr mBaseURI; nsCOMPtr mLoadEventListeners; nsCOMPtr mErrorEventListeners;