From 2c354b8bbbd4f59962673894caa8f188cc682eca Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Sun, 20 Jun 2010 14:40:09 +0200 Subject: [PATCH] shdocvw: Return IHTMLDocument2's IDispatch in get_Document. --- dlls/mshtml/tests/htmldoc.c | 5 +++++ dlls/shdocvw/tests/webbrowser.c | 6 ++++++ dlls/shdocvw/webbrowser.c | 22 +++++++++++++++++++--- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/dlls/mshtml/tests/htmldoc.c b/dlls/mshtml/tests/htmldoc.c index 319e5fd575b..2d51262df5d 100644 --- a/dlls/mshtml/tests/htmldoc.c +++ b/dlls/mshtml/tests/htmldoc.c @@ -4515,6 +4515,11 @@ static void test_QueryInterface(IHTMLDocument2 *doc) hres = IUnknown_QueryInterface(doc, &IID_IStdMarshalInfo, (void**)&qi); ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres); ok(qi == NULL, "qi=%p, expected NULL\n", qi); + + hres = IUnknown_QueryInterface(doc, &IID_IDispatch, (void**)&qi); + ok(hres == S_OK, "Could not get IDispatch interface: %08x\n", hres); + ok(qi != (IUnknown*)doc, "disp == doc\n"); + IUnknown_Release(qi); } static void init_test(enum load_state_t ls) { diff --git a/dlls/shdocvw/tests/webbrowser.c b/dlls/shdocvw/tests/webbrowser.c index 17189fc1284..15fc1ec0d72 100644 --- a/dlls/shdocvw/tests/webbrowser.c +++ b/dlls/shdocvw/tests/webbrowser.c @@ -2369,6 +2369,7 @@ static void test_IServiceProvider(IUnknown *unk) #define get_document(u) _get_document(__LINE__,u) static IDispatch *_get_document(unsigned line, IUnknown *unk) { + IHTMLDocument2 *html_doc; IWebBrowser2 *wb; IDispatch *disp; HRESULT hres; @@ -2382,6 +2383,11 @@ static IDispatch *_get_document(unsigned line, IUnknown *unk) ok_(__FILE__,line)(hres == S_OK, "get_Document failed: %08x\n", hres); ok_(__FILE__,line)(disp != NULL, "doc_disp == NULL\n"); + hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&html_doc); + ok_(__FILE__,line)(hres == S_OK, "Could not get IHTMLDocument iface: %08x\n", hres); + ok(disp == (IDispatch*)html_doc, "disp != html_doc\n"); + IHTMLDocument_Release(html_doc); + return disp; } diff --git a/dlls/shdocvw/webbrowser.c b/dlls/shdocvw/webbrowser.c index 0c26a83b55e..20d39bb3764 100644 --- a/dlls/shdocvw/webbrowser.c +++ b/dlls/shdocvw/webbrowser.c @@ -22,6 +22,7 @@ #include "wine/debug.h" #include "shdocvw.h" #include "exdispid.h" +#include "mshtml.h" WINE_DEFAULT_DEBUG_CHANNEL(shdocvw); @@ -334,13 +335,28 @@ static HRESULT WINAPI WebBrowser_get_Container(IWebBrowser2 *iface, IDispatch ** static HRESULT WINAPI WebBrowser_get_Document(IWebBrowser2 *iface, IDispatch **ppDisp) { WebBrowser *This = WEBBROWSER_THIS(iface); + IDispatch *disp = NULL; TRACE("(%p)->(%p)\n", This, ppDisp); - *ppDisp = NULL; - if(This->doc_host.document) - IUnknown_QueryInterface(This->doc_host.document, &IID_IDispatch, (void**)ppDisp); + if(This->doc_host.document) { + HRESULT hres; + hres = IUnknown_QueryInterface(This->doc_host.document, &IID_IDispatch, (void**)&disp); + if(SUCCEEDED(hres)) { + IDispatch *html_doc; + + /* Some broken apps cast returned IDispatch to IHTMLDocument2 + * without QueryInterface call */ + hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&html_doc); + if(SUCCEEDED(hres)) { + IDispatch_Release(disp); + disp = html_doc; + } + } + } + + *ppDisp = disp; return S_OK; }