Module: wine Branch: master Commit: c0fda9824e213e5a779bddfba6052dfc20b9c8d3 URL: http://source.winehq.org/git/wine.git/?a=commit;h=c0fda9824e213e5a779bddfba6...
Author: Jacek Caban jacek@codeweavers.com Date: Wed Feb 24 15:21:24 2016 +0100
mshtml: Expose XMLHttpRequest constructor to scripts.
Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/mshtml/dispex.c | 52 +++++++++++++++++++++++++++---------------- dlls/mshtml/htmlwindow.c | 3 ++- dlls/mshtml/mshtml_private.h | 1 + dlls/mshtml/tests/dom.c | 24 ++++++++++++++++++++ dlls/mshtml/tests/jstest.html | 9 ++++++++ 5 files changed, 69 insertions(+), 20 deletions(-)
diff --git a/dlls/mshtml/dispex.c b/dlls/mshtml/dispex.c index 3980daf..90e5c72 100644 --- a/dlls/mshtml/dispex.c +++ b/dlls/mshtml/dispex.c @@ -241,8 +241,8 @@ static void add_func_info(dispex_data_t *data, DWORD *size, tid_t tid, const FUN if(info == data->funcs+data->func_cnt) { if(data->func_cnt == *size) data->funcs = heap_realloc_zero(data->funcs, (*size <<= 1)*sizeof(func_info_t)); - info = data->funcs+data->func_cnt; + hres = ITypeInfo_GetDocumentation(dti, desc->memid, &info->name, NULL, NULL, NULL); if(FAILED(hres)) return; @@ -315,6 +315,31 @@ static void add_func_info(dispex_data_t *data, DWORD *size, tid_t tid, const FUN } }
+static HRESULT process_interface(dispex_data_t *data, tid_t tid, ITypeInfo *disp_typeinfo, DWORD *size) +{ + unsigned i = 7; /* skip IDispatch functions */ + ITypeInfo *typeinfo; + FUNCDESC *funcdesc; + HRESULT hres; + + hres = get_typeinfo(tid, &typeinfo); + if(FAILED(hres)) + return hres; + + while(1) { + hres = ITypeInfo_GetFuncDesc(typeinfo, i++, &funcdesc); + if(FAILED(hres)) + break; + + TRACE("adding...\n"); + + add_func_info(data, size, tid, funcdesc, disp_typeinfo ? disp_typeinfo : typeinfo); + ITypeInfo_ReleaseFuncDesc(typeinfo, funcdesc); + } + + return S_OK; +} + static int dispid_cmp(const void *p1, const void *p2) { return ((const func_info_t*)p1)->id - ((const func_info_t*)p2)->id; @@ -327,11 +352,10 @@ static int func_name_cmp(const void *p1, const void *p2)
static dispex_data_t *preprocess_dispex_data(DispatchEx *This) { - const tid_t *tid = This->data->iface_tids; - FUNCDESC *funcdesc; + const tid_t *tid; dispex_data_t *data; DWORD size = 16, i; - ITypeInfo *ti, *dti; + ITypeInfo *dti; HRESULT hres;
TRACE("(%p)\n", This); @@ -359,24 +383,15 @@ static dispex_data_t *preprocess_dispex_data(DispatchEx *This) } list_add_tail(&dispex_data_list, &data->entry);
- while(*tid) { - hres = get_typeinfo(*tid, &ti); + for(tid = This->data->iface_tids; *tid; tid++) { + hres = process_interface(data, *tid, dti, &size); if(FAILED(hres)) break; - - i=7; - while(1) { - hres = ITypeInfo_GetFuncDesc(ti, i++, &funcdesc); - if(FAILED(hres)) - break; - - add_func_info(data, &size, *tid, funcdesc, dti); - ITypeInfo_ReleaseFuncDesc(ti, funcdesc); - } - - tid++; }
+ if(This->data->additional_tid) + process_interface(data, This->data->additional_tid, NULL, &size); + if(!data->func_cnt) { heap_free(data->funcs); data->name_table = NULL; @@ -392,7 +407,6 @@ static dispex_data_t *preprocess_dispex_data(DispatchEx *This) for(i=0; i < data->func_cnt; i++) data->name_table[i] = data->funcs+i; qsort(data->name_table, data->func_cnt, sizeof(func_info_t*), func_name_cmp); - return data; }
diff --git a/dlls/mshtml/htmlwindow.c b/dlls/mshtml/htmlwindow.c index d7d133a..f203405 100644 --- a/dlls/mshtml/htmlwindow.c +++ b/dlls/mshtml/htmlwindow.c @@ -2939,7 +2939,8 @@ static dispex_static_data_t HTMLWindow_dispex = { &HTMLWindow_dispex_vtbl, DispHTMLWindow2_tid, NULL, - HTMLWindow_iface_tids + HTMLWindow_iface_tids, + IHTMLWindow5_tid };
static void *alloc_window(size_t size) diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index 1f0255f..f4e6668 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -248,6 +248,7 @@ typedef struct { const tid_t disp_tid; dispex_data_t *data; const tid_t* const iface_tids; + const tid_t additional_tid; } dispex_static_data_t;
struct DispatchEx { diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index 4b2b825..e27339a 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -6598,6 +6598,28 @@ static void test_dom_implementation(IHTMLDocument2 *doc) IHTMLDOMImplementation_Release(dom_implementation); }
+static void test_xhr(IHTMLDocument2 *doc) +{ + IHTMLWindow2 *window; + IDispatchEx *dispex; + DISPID id; + BSTR str; + HRESULT hres; + + hres = IHTMLDocument2_get_parentWindow(doc, &window); + ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres); + + hres = IHTMLWindow2_QueryInterface(window, &IID_IDispatchEx, (void**)&dispex); + ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres); + + str = a2bstr("XMLHttpRequest"); + hres = IDispatchEx_GetDispID(dispex, str, 0, &id); + ok(hres == S_OK, "GetDispID failed: %08x\n", hres); + SysFreeString(str); + + IHTMLWindow2_Release(window); +} + static void test_defaults(IHTMLDocument2 *doc) { IHTMLStyleSheetsCollection *stylesheetcol; @@ -6670,6 +6692,8 @@ static void test_defaults(IHTMLDocument2 *doc) IHTMLElementCollection_Release(collection); }
+ test_xhr(doc); + hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body); ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres); test_default_body(body); diff --git a/dlls/mshtml/tests/jstest.html b/dlls/mshtml/tests/jstest.html index f0d3e3b..2a5a447 100644 --- a/dlls/mshtml/tests/jstest.html +++ b/dlls/mshtml/tests/jstest.html @@ -354,6 +354,14 @@ function test_text_node() { ok(text2.data == "testing", "text2.data = " + text2.data); }
+function test_xhr() { + ok("XMLHttpRequest" in window, "XMLHttpRequest not found in window object\n"); + ok(typeof(XMLHttpRequest) === "object", "typeof(XMLHttpRequest) = " + typeof(XMLHttpRequest)); + + var xhr = new XMLHttpRequest(); + ok(typeof(xhr) === "object", "typeof(xhr) = " + typeof(xhr)); +} + var globalVar = false;
function runTests() { @@ -379,6 +387,7 @@ function runTests() { test_whitespace_nodes(); test_language_attribute(); test_text_node(); + test_xhr();
var r = window.execScript("globalVar = true;"); ok(r === undefined, "execScript returned " + r);