From: Gabriel Ivăncescu gabrielopcode@gmail.com
And get rid of the dispex since it's useless now.
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/mshtml/mshtml_private.h | 1 - dlls/mshtml/oleobj.c | 165 ++++++----------------------------- dlls/mshtml/tests/dom.c | 27 ++++++ dlls/mshtml/tests/events.c | 99 ++++++++++++++++++++- 4 files changed, 151 insertions(+), 141 deletions(-)
diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index e7f5481b886..e3971258b13 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -640,7 +640,6 @@ struct ConnectionPoint { };
struct HTMLDocumentObj { - DispatchEx dispex; IUnknown IUnknown_inner; IDispatchEx IDispatchEx_iface; ICustomDoc ICustomDoc_iface; diff --git a/dlls/mshtml/oleobj.c b/dlls/mshtml/oleobj.c index 7821abdb390..54ce4e0a159 100644 --- a/dlls/mshtml/oleobj.c +++ b/dlls/mshtml/oleobj.c @@ -27,6 +27,7 @@ #include "ole2.h" #include "shlguid.h" #include "shdeprecated.h" +#include "mscoree.h" #include "mshtmdid.h" #include "idispids.h"
@@ -3410,8 +3411,12 @@ static HRESULT WINAPI HTMLDocumentObj_QueryInterface(IUnknown *iface, REFIID rii TRACE("(%p)->(IID_IStdMarshalInfo %p) returning NULL\n", This, ppv); *ppv = NULL; return E_NOINTERFACE; - }else if(dispex_query_interface(&This->dispex, riid, ppv)) { - return *ppv ? S_OK : E_NOINTERFACE; + }else if(IsEqualGUID(&IID_IDispatchJS, riid) || + IsEqualGUID(&IID_UndocumentedScriptIface, riid) || + IsEqualGUID(&IID_IMarshal, riid) || + IsEqualGUID(&IID_IManagedObject, riid)) { + *ppv = NULL; + return E_NOINTERFACE; }else { FIXME("Unimplemented interface %s\n", debugstr_mshtml_guid(riid)); *ppv = NULL; @@ -3472,7 +3477,6 @@ static ULONG WINAPI HTMLDocumentObj_Release(IUnknown *iface)
remove_target_tasks(This->task_magic); ConnectionPointContainer_Destroy(&This->cp_container); - release_dispex(&This->dispex);
if(This->nscontainer) detach_gecko_browser(This->nscontainer); @@ -3490,123 +3494,50 @@ static const IUnknownVtbl HTMLDocumentObjVtbl = {
/********************************************************** * IDispatchEx implementation + * + * Forwarding this breaks Dispatch rules by potentially retrieving + * a different DISPID for the same name, if the node was changed + * while using the same doc obj, but it is how native works. */ static inline HTMLDocumentObj *impl_from_IDispatchEx(IDispatchEx *iface) { return CONTAINING_RECORD(iface, HTMLDocumentObj, IDispatchEx_iface); }
-static HRESULT WINAPI DocObjDispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv) -{ - HTMLDocumentObj *This = impl_from_IDispatchEx(iface); - return IUnknown_QueryInterface(This->outer_unk, riid, ppv); -} - -static ULONG WINAPI DocObjDispatchEx_AddRef(IDispatchEx *iface) -{ - HTMLDocumentObj *This = impl_from_IDispatchEx(iface); - return IUnknown_AddRef(This->outer_unk); -} - -static ULONG WINAPI DocObjDispatchEx_Release(IDispatchEx *iface) -{ - HTMLDocumentObj *This = impl_from_IDispatchEx(iface); - return IUnknown_Release(This->outer_unk); -} - -static HRESULT WINAPI DocObjDispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo) -{ - HTMLDocumentObj *This = impl_from_IDispatchEx(iface); - return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo); -} - -static HRESULT WINAPI DocObjDispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo, LCID lcid, - ITypeInfo **ppTInfo) -{ - HTMLDocumentObj *This = impl_from_IDispatchEx(iface); - return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo); -} - -static HRESULT WINAPI DocObjDispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid, LPOLESTR *rgszNames, - UINT cNames, LCID lcid, DISPID *rgDispId) -{ - HTMLDocumentObj *This = impl_from_IDispatchEx(iface); - return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames, lcid, rgDispId); -} +HTMLDOCUMENTOBJ_IUNKNOWN_METHODS(DispatchEx) +HTMLDOCUMENTOBJ_FWD_TO_NODE_1(DispatchEx, GetTypeInfoCount, UINT*) +HTMLDOCUMENTOBJ_FWD_TO_NODE_3(DispatchEx, GetTypeInfo, UINT,LCID,ITypeInfo**) +HTMLDOCUMENTOBJ_FWD_TO_NODE_5(DispatchEx, GetIDsOfNames, REFIID,LPOLESTR*,UINT,LCID,DISPID*)
static HRESULT WINAPI DocObjDispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr) { HTMLDocumentObj *This = impl_from_IDispatchEx(iface); - return IDispatchEx_InvokeEx(&This->IDispatchEx_iface, dispIdMember, lcid, wFlags, pDispParams, + + if(!This->doc_node) + return E_UNEXPECTED; + return IDispatchEx_InvokeEx(&This->doc_node->IDispatchEx_iface, dispIdMember, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, NULL); }
-static HRESULT WINAPI DocObjDispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid) -{ - HTMLDocumentObj *This = impl_from_IDispatchEx(iface); - return IDispatchEx_GetDispID(&This->dispex.IDispatchEx_iface, bstrName, grfdex, pid); -} +HTMLDOCUMENTOBJ_FWD_TO_NODE_3(DispatchEx, GetDispID, BSTR,DWORD,DISPID*)
static HRESULT WINAPI DocObjDispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp, VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller) { HTMLDocumentObj *This = impl_from_IDispatchEx(iface);
- if(This->window) { - switch(id) { - case DISPID_READYSTATE: - TRACE("DISPID_READYSTATE\n"); - - if(!(wFlags & DISPATCH_PROPERTYGET)) - return E_INVALIDARG; - - V_VT(pvarRes) = VT_I4; - V_I4(pvarRes) = This->window->readystate; - return S_OK; - default: - break; - } - } - - return IDispatchEx_InvokeEx(&This->dispex.IDispatchEx_iface, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller); -} - -static HRESULT WINAPI DocObjDispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex) -{ - HTMLDocumentObj *This = impl_from_IDispatchEx(iface); - return IDispatchEx_DeleteMemberByName(&This->dispex.IDispatchEx_iface, bstrName, grfdex); -} - -static HRESULT WINAPI DocObjDispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id) -{ - HTMLDocumentObj *This = impl_from_IDispatchEx(iface); - return IDispatchEx_DeleteMemberByDispID(&This->dispex.IDispatchEx_iface, id); -} - -static HRESULT WINAPI DocObjDispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex) -{ - HTMLDocumentObj *This = impl_from_IDispatchEx(iface); - return IDispatchEx_GetMemberProperties(&This->dispex.IDispatchEx_iface, id, grfdexFetch, pgrfdex); -} - -static HRESULT WINAPI DocObjDispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName) -{ - HTMLDocumentObj *This = impl_from_IDispatchEx(iface); - return IDispatchEx_GetMemberName(&This->dispex.IDispatchEx_iface, id, pbstrName); -} - -static HRESULT WINAPI DocObjDispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid) -{ - HTMLDocumentObj *This = impl_from_IDispatchEx(iface); - return IDispatchEx_GetNextDispID(&This->dispex.IDispatchEx_iface, grfdex, id, pid); + if(!This->doc_node) + return E_UNEXPECTED; + return IDispatchEx_InvokeEx(&This->doc_node->IDispatchEx_iface, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller); }
-static HRESULT WINAPI DocObjDispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk) -{ - HTMLDocumentObj *This = impl_from_IDispatchEx(iface); - return IDispatchEx_GetNameSpaceParent(&This->dispex.IDispatchEx_iface, ppunk); -} +HTMLDOCUMENTOBJ_FWD_TO_NODE_2(DispatchEx, DeleteMemberByName, BSTR,DWORD) +HTMLDOCUMENTOBJ_FWD_TO_NODE_1(DispatchEx, DeleteMemberByDispID, DISPID) +HTMLDOCUMENTOBJ_FWD_TO_NODE_3(DispatchEx, GetMemberProperties, DISPID,DWORD,DWORD*) +HTMLDOCUMENTOBJ_FWD_TO_NODE_2(DispatchEx, GetMemberName, DISPID,BSTR*) +HTMLDOCUMENTOBJ_FWD_TO_NODE_3(DispatchEx, GetNextDispID, DWORD,DISPID,DISPID*) +HTMLDOCUMENTOBJ_FWD_TO_NODE_1(DispatchEx, GetNameSpaceParent, IUnknown**)
static const IDispatchExVtbl DocObjDispatchExVtbl = { DocObjDispatchEx_QueryInterface, @@ -3712,43 +3643,6 @@ static const cpc_entry_t HTMLDocumentObj_cpc[] = { {NULL} };
-static HRESULT HTMLDocumentObj_location_hook(DispatchEx *dispex, WORD flags, DISPPARAMS *dp, VARIANT *res, - EXCEPINFO *ei, IServiceProvider *caller) -{ - HTMLDocumentObj *This = CONTAINING_RECORD(dispex, HTMLDocumentObj, dispex); - - if(!(flags & DISPATCH_PROPERTYPUT) || !This->window) - return S_FALSE; - - return IDispatchEx_InvokeEx(&This->window->base.IDispatchEx_iface, DISPID_IHTMLWINDOW2_LOCATION, - 0, flags, dp, res, ei, caller); -} - -static const tid_t HTMLDocumentObj_iface_tids[] = { - IHTMLDocument3_tid, - IHTMLDocument4_tid, - IHTMLDocument5_tid, - 0 -}; - -static void HTMLDocumentObj_init_dispex_info(dispex_data_t *info, compat_mode_t mode) -{ - static const dispex_hook_t document2_hooks[] = { - {DISPID_IHTMLDOCUMENT2_URL, NULL, L"URL"}, - {DISPID_IHTMLDOCUMENT2_LOCATION, HTMLDocumentObj_location_hook}, - {DISPID_UNKNOWN} - }; - dispex_info_add_interface(info, IHTMLDocument2_tid, document2_hooks); -} - -static dispex_static_data_t HTMLDocumentObj_dispex = { - L"HTMLDocumentObj", - NULL, - DispHTMLDocument_tid, - HTMLDocumentObj_iface_tids, - HTMLDocumentObj_init_dispex_info -}; - static HRESULT create_document_object(BOOL is_mhtml, IUnknown *outer, REFIID riid, void **ppv) { HTMLDocumentObj *doc; @@ -3789,7 +3683,6 @@ static HRESULT create_document_object(BOOL is_mhtml, IUnknown *outer, REFIID rii
doc->outer_unk = outer ? outer : &doc->IUnknown_inner;
- init_dispatch(&doc->dispex, (IUnknown*)&doc->ICustomDoc_iface, &HTMLDocumentObj_dispex, COMPAT_MODE_QUIRKS); ConnectionPointContainer_Init(&doc->cp_container, &doc->IUnknown_inner, HTMLDocumentObj_cpc); HTMLDocumentObj_Persist_Init(doc); HTMLDocumentObj_Service_Init(doc); diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index 70b047ccbe1..c31de136cd8 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -9477,10 +9477,37 @@ static void test_elems(IHTMLDocument2 *doc) elem = get_doc_elem_by_id(doc, L"objid"); ok(elem != NULL, "elem == NULL\n"); if(elem) { + IDispatchEx *dispex = get_dispex_iface((IUnknown*)doc); + DISPPARAMS dp = { 0 }; + DISPID dispid; + VARIANT var; + BSTR name; + test_object_vspace((IUnknown*)elem, 100); test_object_name(elem, L"objname"); + + name = SysAllocString(L"objname"); + hres = IDispatchEx_GetDispID(dispex, name, fdexNameCaseSensitive, &dispid); + ok(hres == S_OK, "GetDispID(objname) returned: %08lx\n", hres); + SysFreeString(name); + + hres = IDispatchEx_Invoke(dispex, dispid, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dp, &var, NULL, NULL); + ok(hres == S_OK, "Invoke(objname) failed: %08lx\n", hres); + ok(V_VT(&var) == VT_DISPATCH, "VT = %d\n", V_VT(&var)); + ok(V_DISPATCH(&var) != NULL, "objname = null\n"); + + elem2 = get_elem_iface((IUnknown*)V_DISPATCH(&var)); + IDispatch_Release(V_DISPATCH(&var)); + + test_object_vspace((IUnknown*)elem2, 100); + test_object_name(elem2, L"objname"); + todo_wine + ok(elem != elem2, "elem == elem2\n"); + IHTMLElement_Release(elem2); + set_object_name(elem, L"test"); set_object_name(elem, NULL); + IDispatchEx_Release(dispex); IHTMLElement_Release(elem); }
diff --git a/dlls/mshtml/tests/events.c b/dlls/mshtml/tests/events.c index b6a0c32d8a8..b9ae375640b 100644 --- a/dlls/mshtml/tests/events.c +++ b/dlls/mshtml/tests/events.c @@ -133,6 +133,14 @@ static const char readystate_doc_ie9_str[] = "<head><meta http-equiv="x-ua-compatible" content="IE=9" /></head>" "<body><iframe id="iframe"></iframe></body></html>";
+static const char doc_with_prop_str[] = + "<html><body onload="document.prop = 137;"></body></html>"; + +static const char doc_with_prop_ie9_str[] = + "<html>" + "<head><meta http-equiv="x-ua-compatible" content="IE=9" /></head>" + "<body onload="document.prop = 137;"></body></html>"; + static const char img_doc_str[] = "<html><body><img id="imgid"></img></body></html>";
@@ -4257,11 +4265,14 @@ done: static void test_doc_obj(const char *doc_str) { IHTMLDocument2 *doc = create_document_with_origin(L"http://winetest.example.org", doc_str); + DISPID dispid, import_node_id, has_own_prop_id; IEventTarget *event_target; + DISPPARAMS dp = { 0 }; IHTMLDocument6 *doc6; + IDispatchEx *dispex; IHTMLElement *body; + VARIANT res, arg; HRESULT hres; - VARIANT res; BSTR bstr;
hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument6, (void**)&doc6); @@ -4313,9 +4324,74 @@ static void test_doc_obj(const char *doc_str) ok(!wcscmp(bstr, (document_mode < 9 ? L"[object]" : L"[object Document]")), "toString returned %s\n", wine_dbgstr_w(bstr)); SysFreeString(bstr);
+ /* IHTMLDocument6 prop */ + bstr = SysAllocString(L"onstoragecommit"); + hres = IHTMLDocument2_GetIDsOfNames(doc, &IID_NULL, &bstr, 1, 0, &dispid); + ok(hres == S_OK, "GetIDsOfNames(onstoragecommit) returned: %08lx\n", hres); + SysFreeString(bstr); + + /* IHTMLDocument7 method */ + bstr = SysAllocString(L"importNode"); + hres = IHTMLDocument2_GetIDsOfNames(doc, &IID_NULL, &bstr, 1, 0, &dispid); + ok(hres == (document_mode < 9 ? DISP_E_UNKNOWNNAME : S_OK), "GetIDsOfNames(importNode) returned: %08lx\n", hres); + + hres = IHTMLDocument2_QueryInterface(doc, &IID_IDispatchEx, (void**)&dispex); + ok(hres == S_OK, "Could not get IDispatchEx: %08lx\n", hres); + + hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameEnsure, &import_node_id); + ok(hres == S_OK, "GetDispID(importNode) returned: %08lx\n", hres); + if(document_mode >= 9) + ok(import_node_id == dispid, "GetDispID(importNode) != GetIDsOfNames(importNode)\n"); + IDispatchEx_Release(dispex); + SysFreeString(bstr); + + /* prop set via script on node */ + bstr = SysAllocString(L"prop"); + hres = IHTMLDocument2_GetIDsOfNames(doc, &IID_NULL, &bstr, 1, 0, &dispid); + ok(hres == S_OK, "GetIDsOfNames(prop) returned: %08lx\n", hres); + SysFreeString(bstr); + + hres = IHTMLDocument2_Invoke(doc, dispid, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dp, &res, NULL, NULL); + ok(hres == S_OK, "Invoke(prop) failed: %08lx\n", hres); + ok(V_VT(&res) == VT_I4, "VT(prop) = %d\n", V_VT(&res)); + ok(V_I4(&res) == 137, "prop = %ld\n", V_I4(&res)); + + /* jscript prop on prototype chain */ + bstr = SysAllocString(L"hasOwnProperty"); + hres = IHTMLDocument2_GetIDsOfNames(doc, &IID_NULL, &bstr, 1, 0, &has_own_prop_id); + todo_wine_if(document_mode >= 9) + ok(hres == (document_mode < 9 ? DISP_E_UNKNOWNNAME : S_OK), "GetIDsOfNames(hasOwnProperty) returned: %08lx\n", hres); + SysFreeString(bstr); + + if(hres == S_OK) { + dp.cArgs = 1; + dp.rgvarg = &arg; + V_VT(&arg) = VT_BSTR; + V_BSTR(&arg) = SysAllocString(L"createElement"); + hres = IHTMLDocument2_Invoke(doc, has_own_prop_id, &IID_NULL, 0, DISPATCH_METHOD, &dp, &res, NULL, NULL); + ok(hres == S_OK, "Invoke(hasOwnProperty("createElement")) failed: %08lx\n", hres); + ok(V_VT(&res) == VT_BOOL, "VT = %d\n", V_VT(&res)); + todo_wine + ok(V_BOOL(&res) == VARIANT_FALSE, "hasOwnProperty("createElement") = %d\n", V_BOOL(&res)); + + hres = IHTMLDocument2_GetIDsOfNames(doc, &IID_NULL, &V_BSTR(&arg), 1, 0, &dispid); + ok(hres == S_OK, "GetIDsOfNames(createElement) returned: %08lx\n", hres); + SysFreeString(V_BSTR(&arg)); + + V_BSTR(&arg) = SysAllocString(L"prop"); + hres = IHTMLDocument2_Invoke(doc, has_own_prop_id, &IID_NULL, 0, DISPATCH_METHOD, &dp, &res, NULL, NULL); + ok(hres == S_OK, "Invoke(hasOwnProperty("prop")) failed: %08lx\n", hres); + ok(V_VT(&res) == VT_BOOL, "VT = %d\n", V_VT(&res)); + ok(V_BOOL(&res) == VARIANT_TRUE, "hasOwnProperty("prop") = %d\n", V_BOOL(&res)); + SysFreeString(V_BSTR(&arg)); + } + /* Navigate to a different document mode page, checking using the same doc obj. Test that it breaks COM rules, since IEventTarget is conditionally exposed. - All the events registered on the old doc node are also removed. */ + All the events registered on the old doc node are also removed. + + DISPIDs are forwarded to the node, and thus it also breaks Dispatch rules, + where the same name will potentially receive a different DISPID. */ protocol_doc_str = document_mode < 9 ? empty_doc_ie9_str : empty_doc_str; navigate(doc, L"http://winetest.example.org/foobar");
@@ -4340,10 +4416,25 @@ static void test_doc_obj(const char *doc_str) ok(hres == S_OK, "click failed: %08lx\n", hres); IHTMLElement_Release(body); pump_msgs(NULL); + + hres = IHTMLDocument2_QueryInterface(doc, &IID_IDispatchEx, (void**)&dispex); + ok(hres == S_OK, "Could not get IDispatchEx: %08lx\n", hres); + + bstr = SysAllocString(L"importNode"); + hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameEnsure, &dispid); + ok(hres == S_OK, "GetDispID(importNode) returned: %08lx\n", hres); + ok(dispid != import_node_id, "importNode on new doc node == old importNode\n"); + IDispatchEx_Release(dispex); + SysFreeString(bstr); }else { ok(hres == S_OK, "hres = %08lx, expected S_OK\n", hres); ok(!!event_target, "event_target = NULL\n"); IEventTarget_Release(event_target); + + bstr = SysAllocString(L"importNode"); + hres = IHTMLDocument2_GetIDsOfNames(doc, &IID_NULL, &bstr, 1, 0, &dispid); + ok(hres == S_OK, "GetIDsOfNames(importNode) returned: %08lx\n", hres); + ok(dispid != import_node_id, "importNode on new doc node == old created importNode\n"); }
set_client_site(doc, FALSE); @@ -4405,8 +4496,8 @@ START_TEST(events) test_storage_events(empty_doc_str); if(is_ie9plus) { test_storage_events(empty_doc_ie9_str); - test_doc_obj(empty_doc_str); - test_doc_obj(empty_doc_ie9_str); + test_doc_obj(doc_with_prop_str); + test_doc_obj(doc_with_prop_ie9_str); }
DestroyWindow(container_hwnd);