Bug 726434 - Return DOMString for XMLHttpRequest.getAllResponseHeaders(); r=bent

This commit is contained in:
Ms2ger 2012-02-21 10:34:01 +01:00
parent a8e72a0529
commit 4a1b92efc5
3 changed files with 29 additions and 36 deletions

View File

@ -183,9 +183,9 @@ interface nsIXMLHttpRequest : nsISupports
* 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

View File

@ -1317,54 +1317,47 @@ nsXMLHttpRequest::Abort()
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;
}
nsCOMPtr<nsIHttpChannel> httpChannel = GetCurrentHttpChannel();
if (httpChannel) {
if (nsCOMPtr<nsIHttpChannel> httpChannel = GetCurrentHttpChannel()) {
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);
if (NS_SUCCEEDED(httpChannel->VisitResponseHeaders(visitor))) {
aResponseHeaders = NS_ConvertUTF8toUTF16(visitor->Headers());
}
return NS_OK;
}
if (!*_retval) {
*_retval = ToNewCString(EmptyString());
if (!mChannel) {
return NS_OK;
}
// 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');
}
return NS_OK;
}

View File

@ -916,11 +916,11 @@ public:
class GetAllResponseHeadersRunnable : public WorkerThreadProxySyncRunnable
{
nsCString& mResponseHeaders;
nsString& mResponseHeaders;
public:
GetAllResponseHeadersRunnable(WorkerPrivate* aWorkerPrivate, Proxy* aProxy,
nsCString& aResponseHeaders)
nsString& aResponseHeaders)
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy),
mResponseHeaders(aResponseHeaders)
{ }
@ -929,7 +929,7 @@ public:
MainThreadRun()
{
nsresult rv =
mProxy->mXHR->GetAllResponseHeaders(getter_Copies(mResponseHeaders));
mProxy->mXHR->GetAllResponseHeaders(mResponseHeaders);
return GetDOMExceptionCodeFromResult(rv);
}
};
@ -1613,15 +1613,15 @@ XMLHttpRequestPrivate::GetAllResponseHeaders(JSContext* aCx)
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*