Module: wine Branch: master Commit: f48709cfe4a271ca45b03c6e183d466776d35efe URL: https://gitlab.winehq.org/wine/wine/-/commit/f48709cfe4a271ca45b03c6e183d466...
Author: Gabriel Ivăncescu gabrielopcode@gmail.com Date: Fri Jul 29 17:30:05 2022 +0300
mshtml: Handle lack of window in methods for detached documents.
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com
---
dlls/mshtml/htmldoc.c | 25 +++++++++++++++++++---- dlls/mshtml/tests/dom.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 4 deletions(-)
diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c index 9092186bcf6..0cf19388481 100644 --- a/dlls/mshtml/htmldoc.c +++ b/dlls/mshtml/htmldoc.c @@ -877,7 +877,7 @@ static HRESULT WINAPI HTMLDocument_get_selection(IHTMLDocument2 *iface, IHTMLSel
TRACE("(%p)->(%p)\n", This, p);
- nsres = nsIDOMWindow_GetSelection(This->window->nswindow, &nsselection); + nsres = nsIDOMHTMLDocument_GetSelection(This->doc_node->nsdoc, &nsselection); if(NS_FAILED(nsres)) { ERR("GetSelection failed: %08lx\n", nsres); return E_FAIL; @@ -896,7 +896,7 @@ static HRESULT WINAPI HTMLDocument_get_readyState(IHTMLDocument2 *iface, BSTR *p if(!p) return E_POINTER;
- return get_readystate_string(This->window->readystate, p); + return get_readystate_string(This->window ? This->window->readystate : 0, p); }
static HRESULT WINAPI HTMLDocument_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p) @@ -905,6 +905,10 @@ static HRESULT WINAPI HTMLDocument_get_frames(IHTMLDocument2 *iface, IHTMLFrames
TRACE("(%p)->(%p)\n", This, p);
+ if(!This->window) { + /* Not implemented by IE */ + return E_NOTIMPL; + } return IHTMLWindow2_get_frames(&This->window->base.IHTMLWindow2_iface, p); }
@@ -1087,7 +1091,7 @@ static HRESULT WINAPI HTMLDocument_get_URL(IHTMLDocument2 *iface, BSTR *p)
TRACE("(%p)->(%p)\n", iface, p);
- *p = SysAllocString(This->window->url ? This->window->url : L"about:blank"); + *p = SysAllocString(This->window && This->window->url ? This->window->url : L"about:blank"); return *p ? S_OK : E_OUTOFMEMORY; }
@@ -1143,6 +1147,9 @@ static HRESULT WINAPI HTMLDocument_put_cookie(IHTMLDocument2 *iface, BSTR v)
TRACE("(%p)->(%s)\n", This, debugstr_w(v));
+ if(!This->window) + return S_OK; + bret = InternetSetCookieExW(This->window->url, NULL, v, 0, 0); if(!bret) { FIXME("InternetSetCookieExW failed: %lu\n", GetLastError()); @@ -1160,6 +1167,11 @@ static HRESULT WINAPI HTMLDocument_get_cookie(IHTMLDocument2 *iface, BSTR *p)
TRACE("(%p)->(%p)\n", This, p);
+ if(!This->window) { + *p = NULL; + return S_OK; + } + size = 0; bret = InternetGetCookieExW(This->window->url, NULL, NULL, &size, 0, NULL); if(!bret && GetLastError() != ERROR_INSUFFICIENT_BUFFER) { @@ -1380,6 +1392,11 @@ static HRESULT WINAPI HTMLDocument_open(IHTMLDocument2 *iface, BSTR url, VARIANT TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_w(url), debugstr_variant(&name), debugstr_variant(&features), debugstr_variant(&replace), pomWindowResult);
+ *pomWindowResult = NULL; + + if(!This->window) + return E_FAIL; + if(!This->doc_node->nsdoc) { ERR("!nsdoc\n"); return E_NOTIMPL; @@ -2263,7 +2280,7 @@ static HRESULT WINAPI HTMLDocument3_get_documentElement(IHTMLDocument3 *iface, I
TRACE("(%p)->(%p)\n", This, p);
- if(This->window->readystate == READYSTATE_UNINITIALIZED) { + if(This->window && This->window->readystate == READYSTATE_UNINITIALIZED) { *p = NULL; return S_OK; } diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index d25c7ac0df8..e3ac177205c 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -7322,10 +7322,14 @@ static void test_dom_implementation(IHTMLDocument2 *doc) hres = IHTMLDOMImplementation_QueryInterface(dom_implementation, &IID_IHTMLDOMImplementation2, (void**)&dom_implementation2); if(SUCCEEDED(hres)) { + IHTMLSelectionObject *selection; + IHTMLFramesCollection2 *frames; IHTMLDocument2 *new_document2; + IHTMLDocument3 *new_document3; IHTMLDocument7 *new_document; IHTMLLocation *location; IHTMLWindow2 *window; + IHTMLElement *elem; VARIANT v; IDispatch *disp;
@@ -7334,6 +7338,7 @@ static void test_dom_implementation(IHTMLDocument2 *doc) str = SysAllocString(L"test"); hres = IHTMLDOMImplementation2_createHTMLDocument(dom_implementation2, str, &new_document); ok(hres == S_OK, "createHTMLDocument failed: %08lx\n", hres); + SysFreeString(str);
test_disp((IUnknown*)new_document, &DIID_DispHTMLDocument, &CLSID_HTMLDocument, L"[object]"); test_ifaces((IUnknown*)new_document, doc_node_iids); @@ -7349,15 +7354,63 @@ static void test_dom_implementation(IHTMLDocument2 *doc) hres = IHTMLDocument7_QueryInterface(new_document, &IID_IHTMLDocument2, (void**)&new_document2); ok(hres == S_OK, "Could not get IHTMLDocument2 iface: %08lx\n", hres);
+ hres = IHTMLDocument7_QueryInterface(new_document, &IID_IHTMLDocument3, (void**)&new_document3); + ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08lx\n", hres); + hres = IHTMLDocument2_get_parentWindow(new_document2, &window); ok(hres == E_FAIL, "get_parentWindow returned: %08lx\n", hres);
+ hres = IHTMLDocument2_get_readyState(new_document2, &str); + ok(hres == S_OK, "get_readyState returned: %08lx\n", hres); + ok(!lstrcmpW(str, L"uninitialized"), "readyState = %s\n", wine_dbgstr_w(str)); + SysFreeString(str); + hres = IHTMLDocument2_get_Script(new_document2, &disp); ok(hres == E_PENDING, "get_Script returned: %08lx\n", hres);
+ str = SysAllocString(L"test=testval"); + hres = IHTMLDocument2_put_cookie(new_document2, str); + ok(hres == S_OK, "put_cookie returned: %08lx\n", hres); + SysFreeString(str); + + hres = IHTMLDocument2_get_cookie(doc, &str); + ok(hres == S_OK, "get_cookie returned: %08lx\n", hres); + ok(str == NULL, "cookie = %s\n", wine_dbgstr_w(str)); + SysFreeString(str); + + hres = IHTMLDocument3_get_documentElement(new_document3, &elem); + ok(hres == S_OK, "get_documentElement returned: %08lx\n", hres); + ok(elem != NULL, "documentElement = NULL\n"); + IHTMLElement_Release(elem); + + hres = IHTMLDocument2_get_frames(new_document2, &frames); + ok(hres == E_NOTIMPL, "get_frames returned: %08lx\n", hres); + hres = IHTMLDocument2_get_location(new_document2, &location); ok(hres == E_UNEXPECTED, "get_location returned: %08lx\n", hres);
+ hres = IHTMLDocument2_get_selection(new_document2, &selection); + ok(hres == S_OK, "get_selection returned: %08lx\n", hres); + ok(selection != NULL, "selection = NULL\n"); + hres = IHTMLSelectionObject_get_type(selection, &str); + ok(hres == S_OK, "selection get_type returned: %08lx\n", hres); + ok(!lstrcmpW(str, L"None"), "selection type = %s\n", wine_dbgstr_w(str)); + IHTMLSelectionObject_Release(selection); + SysFreeString(str); + + hres = IHTMLDocument2_get_URL(new_document2, &str); + ok(hres == S_OK, "get_URL returned: %08lx\n", hres); + ok(!lstrcmpW(str, L"about:blank"), "URL = %s\n", wine_dbgstr_w(str)); + SysFreeString(str); + + str = SysAllocString(L"text/html"); + V_VT(&v) = VT_ERROR; + disp = (IDispatch*)0xdeadbeef; + hres = IHTMLDocument2_open(new_document2, str, v, v, v, &disp); + ok(hres == E_FAIL, "open returned: %08lx\n", hres); + ok(disp == NULL, "disp = %p\n", disp); + SysFreeString(str); + memset(&v, 0xcc, sizeof(v)); hres = IHTMLDocument7_get_onmsthumbnailclick(new_document, &v); ok(hres == S_OK, "get_onmsthumbnailclick returned: %08lx\n", hres); @@ -7365,6 +7418,7 @@ static void test_dom_implementation(IHTMLDocument2 *doc) ok((DWORD)(DWORD_PTR)V_DISPATCH(&v) == 0xcccccccc, "got %p\n", V_DISPATCH(&v));
IHTMLDocument2_Release(new_document2); + IHTMLDocument3_Release(new_document3); IHTMLDocument7_Release(new_document); IHTMLDOMImplementation2_Release(dom_implementation2); }else {