Bug 726434 - Return DOMString for XMLHttpRequest.getAllResponseHeaders(); r=bent
authorMs2ger <ms2ger@gmail.com>
Tue, 21 Feb 2012 10:34:01 +0100
changeset 88725 be00940ec6459724287713fa329e1f015e3bc438
parent 88724 b2e52f75b118f0c110c2101a4d46ad4e093807fd
child 88726 7717885da054a4fcf8dd3200d4a410e26262bced
push id975
push userffxbld
push dateTue, 13 Mar 2012 21:39:16 +0000
treeherdermozilla-aurora@99faebf9dc36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs726434
milestone13.0a1
Bug 726434 - Return DOMString for XMLHttpRequest.getAllResponseHeaders(); r=bent
content/base/public/nsIXMLHttpRequest.idl
content/base/src/nsXMLHttpRequest.cpp
dom/workers/XMLHttpRequestPrivate.cpp
--- a/content/base/public/nsIXMLHttpRequest.idl
+++ b/content/base/public/nsIXMLHttpRequest.idl
@@ -178,19 +178,19 @@ interface nsIXMLHttpRequest : nsISupport
   /**
    * Returns all of the response headers as a string for HTTP
    * requests.
    *
    * Note that this will return all the headers from the *current*
    * part of a multipart request, not from the original channel.
    *
    * @returns A string containing all of the response headers.
-   *          NULL if the response has not yet been received.
+   *          The empty string if the response has not yet been received.
    */
-  string getAllResponseHeaders();
+  DOMString getAllResponseHeaders();
 
   /**
    * Returns the text of the header with the specified name for
    * HTTP requests.
    *
    * @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
--- a/content/base/src/nsXMLHttpRequest.cpp
+++ b/content/base/src/nsXMLHttpRequest.cpp
@@ -1312,64 +1312,57 @@ nsXMLHttpRequest::CloseRequestWithError(
 /* void abort (); */
 NS_IMETHODIMP
 nsXMLHttpRequest::Abort()
 {
   CloseRequestWithError(NS_LITERAL_STRING(ABORT_STR), XML_HTTP_REQUEST_ABORTED);
   return NS_OK;
 }
 
-/* string getAllResponseHeaders (); */
+/* DOMString getAllResponseHeaders(); */
 NS_IMETHODIMP
-nsXMLHttpRequest::GetAllResponseHeaders(char **_retval)
+nsXMLHttpRequest::GetAllResponseHeaders(nsAString& aResponseHeaders)
 {
-  NS_ENSURE_ARG_POINTER(_retval);
-  *_retval = nsnull;
+  aResponseHeaders.Truncate();
 
   // If the state is UNSENT or OPENED,
   // return the empty string and terminate these steps.
   if (mState & (XML_HTTP_REQUEST_UNSENT |
                 XML_HTTP_REQUEST_OPENED | XML_HTTP_REQUEST_SENT)) {
-    *_retval = ToNewCString(EmptyString());
     return NS_OK;
   }
 
   if (mState & XML_HTTP_REQUEST_USE_XSITE_AC) {
-    *_retval = ToNewCString(EmptyString());
+    return NS_OK;
+  }
+
+  if (nsCOMPtr<nsIHttpChannel> httpChannel = GetCurrentHttpChannel()) {
+    nsRefPtr<nsHeaderVisitor> visitor = new nsHeaderVisitor();
+    if (NS_SUCCEEDED(httpChannel->VisitResponseHeaders(visitor))) {
+      aResponseHeaders = NS_ConvertUTF8toUTF16(visitor->Headers());
+    }
+    return NS_OK;
+  }
+
+  if (!mChannel) {
     return NS_OK;
   }
 
-  nsCOMPtr<nsIHttpChannel> httpChannel = GetCurrentHttpChannel();
-
-  if (httpChannel) {
-    nsRefPtr<nsHeaderVisitor> visitor = new nsHeaderVisitor();
-    nsresult rv = httpChannel->VisitResponseHeaders(visitor);
-    if (NS_SUCCEEDED(rv))
-      *_retval = ToNewCString(visitor->Headers());
-  } else if (mChannel) {
-    // Even non-http channels supply content type.
-    nsCString value;
-    if (NS_SUCCEEDED(mChannel->GetContentType(value))) {
-      nsCString headers;
-      headers.Append("Content-Type: ");
-      headers.Append(value);
-      if (NS_SUCCEEDED(mChannel->GetContentCharset(value)) &&
-          !value.IsEmpty()) {
-        headers.Append(";charset=");
-        headers.Append(value);
-      }
-      headers.Append('\n');
-      *_retval = ToNewCString(headers);
+  // Even non-http channels supply content type.
+  nsCAutoString value;
+  if (NS_SUCCEEDED(mChannel->GetContentType(value))) {
+    aResponseHeaders.AppendLiteral("Content-Type: ");
+    aResponseHeaders.Append(NS_ConvertUTF8toUTF16(value));
+    if (NS_SUCCEEDED(mChannel->GetContentCharset(value)) &&
+        !value.IsEmpty()) {
+      aResponseHeaders.AppendLiteral(";charset=");
+      aResponseHeaders.Append(NS_ConvertUTF8toUTF16(value));
     }
+    aResponseHeaders.Append('\n');
   }
-
-  if (!*_retval) {
-    *_retval = ToNewCString(EmptyString());
-  }
-
   return NS_OK;
 }
 
 /* ACString getResponseHeader (in AUTF8String header); */
 NS_IMETHODIMP
 nsXMLHttpRequest::GetResponseHeader(const nsACString& header,
                                     nsACString& _retval)
 {
--- a/dom/workers/XMLHttpRequestPrivate.cpp
+++ b/dom/workers/XMLHttpRequestPrivate.cpp
@@ -911,30 +911,30 @@ public:
     mProxy->Reset();
 
     return GetDOMExceptionCodeFromResult(rv);
   }
 };
 
 class GetAllResponseHeadersRunnable : public WorkerThreadProxySyncRunnable
 {
-  nsCString& mResponseHeaders;
+  nsString& mResponseHeaders;
 
 public:
   GetAllResponseHeadersRunnable(WorkerPrivate* aWorkerPrivate, Proxy* aProxy,
-                                nsCString& aResponseHeaders)
+                                nsString& aResponseHeaders)
   : WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy),
     mResponseHeaders(aResponseHeaders)
   { }
 
   intN
   MainThreadRun()
   {
     nsresult rv =
-      mProxy->mXHR->GetAllResponseHeaders(getter_Copies(mResponseHeaders));
+      mProxy->mXHR->GetAllResponseHeaders(mResponseHeaders);
     return GetDOMExceptionCodeFromResult(rv);
   }
 };
 
 class GetResponseHeaderRunnable : public WorkerThreadProxySyncRunnable
 {
   const nsCString mHeader;
   nsCString& mValue;
@@ -1608,25 +1608,25 @@ XMLHttpRequestPrivate::GetAllResponseHea
     return nsnull;
   }
 
   if (!mProxy) {
     ThrowDOMExceptionForCode(aCx, INVALID_STATE_ERR);
     return nsnull;
   }
 
-  nsCString responseHeaders;
+  nsString responseHeaders;
   nsRefPtr<GetAllResponseHeadersRunnable> runnable =
     new GetAllResponseHeadersRunnable(mWorkerPrivate, mProxy, responseHeaders);
   if (!runnable->Dispatch(aCx)) {
     return nsnull;
   }
 
-  return JS_NewStringCopyN(aCx, responseHeaders.get(),
-                           responseHeaders.Length());
+  return JS_NewUCStringCopyN(aCx, responseHeaders.get(),
+                             responseHeaders.Length());
 }
 
 JSString*
 XMLHttpRequestPrivate::GetResponseHeader(JSContext* aCx, JSString* aHeader)
 {
   mWorkerPrivate->AssertIsOnWorkerThread();
 
   if (mCanceled) {