зеркало из https://github.com/mozilla/pjs.git
Fix for bug 122305. XMLHttpRequest now has a way to override the mime type of the incoming stream. r=heikki, sr=jst
This commit is contained in:
Родитель
a54c1a0fe5
Коммит
320300e702
|
@ -224,6 +224,17 @@ interface nsIXMLHttpRequest : nsISupports {
|
|||
* 4 COMPLETED Finished with all operations.
|
||||
*/
|
||||
readonly attribute long readyState;
|
||||
|
||||
/**
|
||||
* Override the mime type returned by the server (if any). This may
|
||||
* be used, for example, to force a stream to be treated and parsed
|
||||
* as text/xml, even if the server does not report it as such. This
|
||||
* must be done before the <code>send</code> method is invoked.
|
||||
*
|
||||
* @param mimetype The type used to override that returned by the server
|
||||
* (if any).
|
||||
*/
|
||||
void overrideMimeType(in string mimetype);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -814,6 +814,14 @@ nsXMLHttpRequest::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
|
|||
mReadRequest = request;
|
||||
mContext = ctxt;
|
||||
ChangeState(XML_HTTP_REQUEST_LOADED);
|
||||
if (!mOverrideMimeType.IsEmpty()) {
|
||||
nsresult status;
|
||||
request->GetStatus(&status);
|
||||
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
|
||||
if (channel && NS_SUCCEEDED(status)) {
|
||||
channel->SetContentType(mOverrideMimeType.get());
|
||||
}
|
||||
}
|
||||
return mXMLParserStreamListener->OnStartRequest(request,ctxt);
|
||||
}
|
||||
|
||||
|
@ -1214,6 +1222,15 @@ nsXMLHttpRequest::GetReadyState(PRInt32 *aState)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void overrideMimeType(in string mimetype); */
|
||||
NS_IMETHODIMP
|
||||
nsXMLHttpRequest::OverrideMimeType(const char* aMimeType)
|
||||
{
|
||||
// XXX Should we do some validation here?
|
||||
mOverrideMimeType.Assign(aMimeType);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIDOMEventListener
|
||||
nsresult
|
||||
nsXMLHttpRequest::HandleEvent(nsIDOMEvent* aEvent)
|
||||
|
|
|
@ -161,6 +161,7 @@ protected:
|
|||
|
||||
PRInt32 mStatus;
|
||||
PRBool mAsync;
|
||||
nsCString mOverrideMimeType;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче