Commit 13d25529 authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

mshtml: Track readyState in XHRs and report it manually.

So it can be forced to specific values during synchronous XHRs. Signed-off-by: 's avatarGabriel Ivăncescu <gabrielopcode@gmail.com>
parent 06b1679e
......@@ -137,6 +137,7 @@ struct HTMLXMLHttpRequest {
IWineXMLHttpRequestPrivate IWineXMLHttpRequestPrivate_iface;
IProvideClassInfo2 IProvideClassInfo2_iface;
LONG ref;
LONG ready_state;
response_type_t response_type;
nsIXMLHttpRequest *nsxhr;
XMLHttpReqEventListener *event_listener;
......@@ -220,6 +221,7 @@ static nsrefcnt NSAPI XMLHttpReqEventListener_Release(nsIDOMEventListener *iface
static nsresult NSAPI XMLHttpReqEventListener_HandleEvent(nsIDOMEventListener *iface, nsIDOMEvent *nsevent)
{
XMLHttpReqEventListener *This = impl_from_nsIDOMEventListener(iface);
UINT16 ready_state;
DOMEvent *event;
HRESULT hres;
......@@ -228,6 +230,9 @@ static nsresult NSAPI XMLHttpReqEventListener_HandleEvent(nsIDOMEventListener *i
if(!This->xhr)
return NS_OK;
if(NS_SUCCEEDED(nsIXMLHttpRequest_GetReadyState(This->xhr->nsxhr, &ready_state)))
This->xhr->ready_state = ready_state;
hres = create_event_from_nsevent(nsevent, dispex_compat_mode(&This->xhr->event_target.dispex), &event);
if(SUCCEEDED(hres) ){
dispatch_event(&This->xhr->event_target, event);
......@@ -339,19 +344,12 @@ static HRESULT WINAPI HTMLXMLHttpRequest_Invoke(IHTMLXMLHttpRequest *iface, DISP
static HRESULT WINAPI HTMLXMLHttpRequest_get_readyState(IHTMLXMLHttpRequest *iface, LONG *p)
{
HTMLXMLHttpRequest *This = impl_from_IHTMLXMLHttpRequest(iface);
UINT16 val;
nsresult nsres;
TRACE("(%p)->(%p)\n", This, p);
if(!p)
return E_POINTER;
nsres = nsIXMLHttpRequest_GetReadyState(This->nsxhr, &val);
if(NS_FAILED(nsres)) {
ERR("nsIXMLHttpRequest_GetReadyState failed: %08lx\n", nsres);
return E_FAIL;
}
*p = val;
*p = This->ready_state;
return S_OK;
}
......@@ -373,6 +371,11 @@ static HRESULT WINAPI HTMLXMLHttpRequest_get_responseText(IHTMLXMLHttpRequest *i
if(!p)
return E_POINTER;
if(This->ready_state < READYSTATE_INTERACTIVE) {
*p = NULL;
return S_OK;
}
nsAString_Init(&nsstr, NULL);
nsres = nsIXMLHttpRequest_GetResponseText(This->nsxhr, &nsstr);
return return_nsstr(nsres, &nsstr, p);
......@@ -389,6 +392,11 @@ static HRESULT WINAPI HTMLXMLHttpRequest_get_responseXML(IHTMLXMLHttpRequest *if
TRACE("(%p)->(%p)\n", This, p);
if(This->ready_state < READYSTATE_COMPLETE) {
*p = NULL;
return S_OK;
}
if(dispex_compat_mode(&This->event_target.dispex) >= COMPAT_MODE_IE10) {
nsIDOMDocument *nsdoc;
nsresult nsres;
......@@ -443,6 +451,11 @@ static HRESULT WINAPI HTMLXMLHttpRequest_get_status(IHTMLXMLHttpRequest *iface,
if(!p)
return E_POINTER;
if(This->ready_state < READYSTATE_LOADED) {
*p = 0;
return E_FAIL;
}
nsres = nsIXMLHttpRequest_GetStatus(This->nsxhr, &val);
if(NS_FAILED(nsres)) {
ERR("nsIXMLHttpRequest_GetStatus failed: %08lx\n", nsres);
......@@ -460,19 +473,13 @@ static HRESULT WINAPI HTMLXMLHttpRequest_get_statusText(IHTMLXMLHttpRequest *ifa
HTMLXMLHttpRequest *This = impl_from_IHTMLXMLHttpRequest(iface);
nsACString nscstr;
nsresult nsres;
HRESULT hres;
LONG state;
TRACE("(%p)->(%p)\n", This, p);
if(!p)
return E_POINTER;
hres = IHTMLXMLHttpRequest_get_readyState(iface, &state);
if(FAILED(hres))
return hres;
if(state < 2) {
if(This->ready_state < READYSTATE_LOADED) {
*p = NULL;
return E_FAIL;
}
......@@ -503,6 +510,7 @@ static HRESULT WINAPI HTMLXMLHttpRequest_get_onreadystatechange(IHTMLXMLHttpRequ
static HRESULT WINAPI HTMLXMLHttpRequest_abort(IHTMLXMLHttpRequest *iface)
{
HTMLXMLHttpRequest *This = impl_from_IHTMLXMLHttpRequest(iface);
UINT16 ready_state;
nsresult nsres;
TRACE("(%p)->()\n", This);
......@@ -513,6 +521,10 @@ static HRESULT WINAPI HTMLXMLHttpRequest_abort(IHTMLXMLHttpRequest *iface)
return E_FAIL;
}
/* Gecko changed to READYSTATE_UNINITIALIZED if it did abort */
nsres = nsIXMLHttpRequest_GetReadyState(This->nsxhr, &ready_state);
if(NS_SUCCEEDED(nsres))
This->ready_state = ready_state;
return S_OK;
}
......@@ -656,19 +668,13 @@ static HRESULT WINAPI HTMLXMLHttpRequest_getAllResponseHeaders(IHTMLXMLHttpReque
HTMLXMLHttpRequest *This = impl_from_IHTMLXMLHttpRequest(iface);
nsACString nscstr;
nsresult nsres;
HRESULT hres;
LONG state;
TRACE("(%p)->(%p)\n", This, p);
if(!p)
return E_POINTER;
hres = IHTMLXMLHttpRequest_get_readyState(iface, &state);
if(FAILED(hres))
return hres;
if(state < 2) {
if(This->ready_state < READYSTATE_LOADED) {
*p = NULL;
return E_FAIL;
}
......@@ -684,8 +690,6 @@ static HRESULT WINAPI HTMLXMLHttpRequest_getResponseHeader(IHTMLXMLHttpRequest *
nsACString header, ret;
char *cstr;
nsresult nsres;
HRESULT hres;
LONG state;
TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrHeader), p);
if(!p)
......@@ -693,11 +697,7 @@ static HRESULT WINAPI HTMLXMLHttpRequest_getResponseHeader(IHTMLXMLHttpRequest *
if(!bstrHeader)
return E_INVALIDARG;
hres = IHTMLXMLHttpRequest_get_readyState(iface, &state);
if(FAILED(hres))
return hres;
if(state < 2) {
if(This->ready_state < READYSTATE_LOADED) {
*p = NULL;
return E_FAIL;
}
......@@ -938,8 +938,6 @@ static HRESULT WINAPI HTMLXMLHttpRequest_private_get_response(IWineXMLHttpReques
{
HTMLXMLHttpRequest *This = impl_from_IWineXMLHttpRequestPrivate(iface);
HRESULT hres = S_OK;
nsresult nsres;
UINT16 state;
TRACE("(%p)->(%p)\n", This, p);
......@@ -957,8 +955,7 @@ static HRESULT WINAPI HTMLXMLHttpRequest_private_get_response(IWineXMLHttpReques
case response_type_arraybuf:
case response_type_blob:
nsres = nsIXMLHttpRequest_GetReadyState(This->nsxhr, &state);
if(NS_FAILED(nsres) || state < 4) {
if(This->ready_state < READYSTATE_COMPLETE) {
V_VT(p) = VT_EMPTY;
break;
}
......@@ -985,17 +982,11 @@ static HRESULT WINAPI HTMLXMLHttpRequest_private_put_responseType(IWineXMLHttpRe
HTMLXMLHttpRequest *This = impl_from_IWineXMLHttpRequestPrivate(iface);
nsAString nsstr;
nsresult nsres;
HRESULT hres;
unsigned i;
LONG state;
TRACE("(%p)->(%s)\n", This, debugstr_w(v));
hres = IHTMLXMLHttpRequest_get_readyState(&This->IHTMLXMLHttpRequest_iface, &state);
if(FAILED(hres))
return hres;
if(state < 1 || state > 2) {
if(This->ready_state < READYSTATE_LOADING || This->ready_state > READYSTATE_INTERACTIVE) {
/* FIXME: Return InvalidStateError */
return E_FAIL;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment