Commit d6b92300 authored by Zhenbo Li's avatar Zhenbo Li Committed by Alexandre Julliard

mshtml: Add IHTMLXMLHttpRequest:open() method implementation.

parent deb884a6
...@@ -855,6 +855,7 @@ HRESULT call_set_active_object(IOleInPlaceUIWindow*,IOleInPlaceActiveObject*) DE ...@@ -855,6 +855,7 @@ HRESULT call_set_active_object(IOleInPlaceUIWindow*,IOleInPlaceActiveObject*) DE
void *nsalloc(size_t) __WINE_ALLOC_SIZE(1) DECLSPEC_HIDDEN; void *nsalloc(size_t) __WINE_ALLOC_SIZE(1) DECLSPEC_HIDDEN;
void nsfree(void*) DECLSPEC_HIDDEN; void nsfree(void*) DECLSPEC_HIDDEN;
BOOL nsACString_Init(nsACString *str, const char *data) DECLSPEC_HIDDEN;
void nsACString_InitDepend(nsACString*,const char*) DECLSPEC_HIDDEN; void nsACString_InitDepend(nsACString*,const char*) DECLSPEC_HIDDEN;
void nsACString_SetData(nsACString*,const char*) DECLSPEC_HIDDEN; void nsACString_SetData(nsACString*,const char*) DECLSPEC_HIDDEN;
UINT32 nsACString_GetData(const nsACString*,const char**) DECLSPEC_HIDDEN; UINT32 nsACString_GetData(const nsACString*,const char**) DECLSPEC_HIDDEN;
......
...@@ -795,7 +795,7 @@ void nsfree(void *mem) ...@@ -795,7 +795,7 @@ void nsfree(void *mem)
NS_Free(mem); NS_Free(mem);
} }
static BOOL nsACString_Init(nsACString *str, const char *data) BOOL nsACString_Init(nsACString *str, const char *data)
{ {
return NS_SUCCEEDED(NS_CStringContainerInit2(str, data, PR_UINT32_MAX, 0)); return NS_SUCCEEDED(NS_CStringContainerInit2(str, data, PR_UINT32_MAX, 0));
} }
......
...@@ -503,7 +503,7 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url) ...@@ -503,7 +503,7 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url)
SET_EXPECT(xmlhttprequest_onreadystatechange_opened); SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
hres = IHTMLXMLHttpRequest_open(xhr, method, url, vbool, vempty, vempty); hres = IHTMLXMLHttpRequest_open(xhr, method, url, vbool, vempty, vempty);
todo_wine ok(hres == S_OK, "open failed: %08x\n", hres); ok(hres == S_OK, "open failed: %08x\n", hres);
todo_wine CHECK_CALLED(xmlhttprequest_onreadystatechange_opened); todo_wine CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
SysFreeString(method); SysFreeString(method);
...@@ -517,30 +517,37 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url) ...@@ -517,30 +517,37 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url)
val = 0xdeadbeef; val = 0xdeadbeef;
hres = IHTMLXMLHttpRequest_get_status(xhr, &val); hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres); todo_wine ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
ok(val == 0, "Expect 0, got %d\n", val); todo_wine ok(val == 0, "Expect 0, got %d\n", val);
hres = IHTMLXMLHttpRequest_get_statusText(xhr, &text); hres = IHTMLXMLHttpRequest_get_statusText(xhr, &text);
ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres); todo_wine ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
ok(text == NULL, "Expect NULL, got %p\n", text); todo_wine ok(text == NULL, "Expect NULL, got %p\n", text);
val = 0xdeadbeef; val = 0xdeadbeef;
hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val); hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
ok(hres == S_OK, "get_readyState failed: %08x\n", hres); todo_wine ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
ok(val == 1, "Expect OPENED, got %d\n", val); todo_wine ok(val == 1, "Expect OPENED, got %d\n", val);
SET_EXPECT(xmlhttprequest_onreadystatechange_opened); SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
SET_EXPECT(xmlhttprequest_onreadystatechange_headers_received); SET_EXPECT(xmlhttprequest_onreadystatechange_headers_received);
SET_EXPECT(xmlhttprequest_onreadystatechange_loading); SET_EXPECT(xmlhttprequest_onreadystatechange_loading);
SET_EXPECT(xmlhttprequest_onreadystatechange_done); SET_EXPECT(xmlhttprequest_onreadystatechange_done);
hres = IHTMLXMLHttpRequest_send(xhr, vempty); hres = IHTMLXMLHttpRequest_send(xhr, vempty);
ok(hres == S_OK, "send failed: %08x\n", hres);
pump_msgs(&called_xmlhttprequest_onreadystatechange_done); todo_wine ok(hres == S_OK, "send failed: %08x\n", hres);
if(SUCCEEDED(hres))
pump_msgs(&called_xmlhttprequest_onreadystatechange_done);
todo_wine CHECK_CALLED(xmlhttprequest_onreadystatechange_opened); todo_wine CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
todo_wine CHECK_CALLED(xmlhttprequest_onreadystatechange_headers_received); todo_wine CHECK_CALLED(xmlhttprequest_onreadystatechange_headers_received);
todo_wine CHECK_CALLED(xmlhttprequest_onreadystatechange_loading); todo_wine CHECK_CALLED(xmlhttprequest_onreadystatechange_loading);
CHECK_CALLED(xmlhttprequest_onreadystatechange_done); todo_wine CHECK_CALLED(xmlhttprequest_onreadystatechange_done);
if(FAILED(hres)) {
IHTMLXMLHttpRequest_Release(xhr);
xhr = NULL;
return;
}
val = 0xdeadbeef; val = 0xdeadbeef;
hres = IHTMLXMLHttpRequest_get_status(xhr, &val); hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
......
...@@ -33,6 +33,33 @@ ...@@ -33,6 +33,33 @@
WINE_DEFAULT_DEBUG_CHANNEL(mshtml); WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
static HRESULT bstr_to_nsacstr(BSTR bstr, nsACString *str)
{
char *cstr = heap_strdupWtoU(bstr);
if(!cstr)
return E_OUTOFMEMORY;
nsACString_Init(str, cstr);
heap_free(cstr);
return S_OK;
}
static HRESULT variant_to_nsastr(VARIANT var, nsAString *ret)
{
switch(V_VT(&var)) {
case VT_NULL:
case VT_ERROR:
case VT_EMPTY:
nsAString_Init(ret, NULL);
return S_OK;
case VT_BSTR:
nsAString_InitDepend(ret, V_BSTR(&var));
return S_OK;
default:
FIXME("Unsupported VARIANT: %s\n", debugstr_variant(&var));
return E_INVALIDARG;
}
}
/* IHTMLXMLHttpRequest */ /* IHTMLXMLHttpRequest */
typedef struct { typedef struct {
EventTarget event_target; EventTarget event_target;
...@@ -198,8 +225,64 @@ static HRESULT WINAPI HTMLXMLHttpRequest_abort(IHTMLXMLHttpRequest *iface) ...@@ -198,8 +225,64 @@ static HRESULT WINAPI HTMLXMLHttpRequest_abort(IHTMLXMLHttpRequest *iface)
static HRESULT WINAPI HTMLXMLHttpRequest_open(IHTMLXMLHttpRequest *iface, BSTR bstrMethod, BSTR bstrUrl, VARIANT varAsync, VARIANT varUser, VARIANT varPassword) static HRESULT WINAPI HTMLXMLHttpRequest_open(IHTMLXMLHttpRequest *iface, BSTR bstrMethod, BSTR bstrUrl, VARIANT varAsync, VARIANT varUser, VARIANT varPassword)
{ {
HTMLXMLHttpRequest *This = impl_from_IHTMLXMLHttpRequest(iface); HTMLXMLHttpRequest *This = impl_from_IHTMLXMLHttpRequest(iface);
FIXME("(%p)->(%s %s %s %s %s)\n", This, debugstr_w(bstrMethod), debugstr_w(bstrUrl), debugstr_variant(&varAsync), debugstr_variant(&varUser), debugstr_variant(&varPassword)); nsACString method, url;
return E_NOTIMPL; nsAString user, password;
nsresult nsres;
HRESULT hres;
TRACE("(%p)->(%s %s %s %s %s)\n", This, debugstr_w(bstrMethod), debugstr_w(bstrUrl), debugstr_variant(&varAsync), debugstr_variant(&varUser), debugstr_variant(&varPassword));
if(V_VT(&varAsync) != VT_BOOL) {
FIXME("varAsync not supported: %s\n", debugstr_variant(&varAsync));
return E_FAIL;
}
/* Note: Starting with Gecko 30.0 (Firefox 30.0 / Thunderbird 30.0 / SeaMonkey 2.27),
* synchronous requests on the main thread have been deprecated due to the negative
* effects to the user experience.
*/
if(!V_BOOL(&varAsync)) {
FIXME("Synchronous request is not supported yet\n");
return E_FAIL;
}
hres = variant_to_nsastr(varUser, &user);
if(FAILED(hres))
return hres;
hres = variant_to_nsastr(varPassword, &password);
if(FAILED(hres)) {
nsAString_Finish(&user);
return hres;
}
hres = bstr_to_nsacstr(bstrMethod, &method);
if(FAILED(hres)) {
nsAString_Finish(&user);
nsAString_Finish(&password);
return hres;
}
hres = bstr_to_nsacstr(bstrUrl, &url);
if(FAILED(hres)) {
nsAString_Finish(&user);
nsAString_Finish(&password);
nsACString_Finish(&method);
return hres;
}
nsres = nsIXMLHttpRequest_Open(This->nsxhr, &method, &url, TRUE,
&user, &password, 0);
nsACString_Finish(&method);
nsACString_Finish(&url);
nsAString_Finish(&user);
nsAString_Finish(&password);
if(NS_FAILED(nsres)) {
ERR("nsIXMLHttpRequest_Open failed: %08x\n", nsres);
return E_FAIL;
}
return S_OK;
} }
static HRESULT WINAPI HTMLXMLHttpRequest_send(IHTMLXMLHttpRequest *iface, VARIANT varBody) static HRESULT WINAPI HTMLXMLHttpRequest_send(IHTMLXMLHttpRequest *iface, VARIANT varBody)
......
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