зеркало из 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:
Родитель
580e33204e
Коммит
24f25e6829
|
@ -586,6 +586,12 @@ nsSchemaLoader::Load(const nsAReadableString& schemaURI,
|
|||
return rv;
|
||||
}
|
||||
|
||||
// Force the mimetype of the returned stream to be xml.
|
||||
rv = request->OverrideMimeType("text/xml");
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = request->Send(nsnull);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
|
@ -636,6 +642,12 @@ nsSchemaLoader::LoadAsync(const nsAReadableString& schemaURI,
|
|||
return rv;
|
||||
}
|
||||
|
||||
// Force the mimetype of the returned stream to be xml.
|
||||
rv = request->OverrideMimeType("text/xml");
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMEventListener> listener;
|
||||
LoadListener* listenerInst = new LoadListener(this, aListener, request);
|
||||
if (!listenerInst) {
|
||||
|
|
|
@ -326,6 +326,12 @@ nsWSDLLoadRequest::LoadDefinition(const nsAReadableString& aURI)
|
|||
return rv;
|
||||
}
|
||||
|
||||
// Force the mimetype of the returned stream to be xml.
|
||||
rv = mRequest->OverrideMimeType("text/xml");
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (!mIsSync) {
|
||||
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(mRequest));
|
||||
if (!target) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -586,6 +586,12 @@ nsSchemaLoader::Load(const nsAReadableString& schemaURI,
|
|||
return rv;
|
||||
}
|
||||
|
||||
// Force the mimetype of the returned stream to be xml.
|
||||
rv = request->OverrideMimeType("text/xml");
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = request->Send(nsnull);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
|
@ -636,6 +642,12 @@ nsSchemaLoader::LoadAsync(const nsAReadableString& schemaURI,
|
|||
return rv;
|
||||
}
|
||||
|
||||
// Force the mimetype of the returned stream to be xml.
|
||||
rv = request->OverrideMimeType("text/xml");
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMEventListener> listener;
|
||||
LoadListener* listenerInst = new LoadListener(this, aListener, request);
|
||||
if (!listenerInst) {
|
||||
|
|
|
@ -326,6 +326,12 @@ nsWSDLLoadRequest::LoadDefinition(const nsAReadableString& aURI)
|
|||
return rv;
|
||||
}
|
||||
|
||||
// Force the mimetype of the returned stream to be xml.
|
||||
rv = mRequest->OverrideMimeType("text/xml");
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (!mIsSync) {
|
||||
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(mRequest));
|
||||
if (!target) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче