Jacek Caban : mshtml: Return NULL for document not attached to window in IHTMLDocument7:: get_defaultView.

Alexandre Julliard julliard at winehq.org
Thu Mar 21 17:21:20 CDT 2019


Module: wine
Branch: master
Commit: 51e6cbdbd87293bbcb8f2c45d1a23a0167e8175d
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=51e6cbdbd87293bbcb8f2c45d1a23a0167e8175d

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Thu Mar 21 14:40:54 2019 +0100

mshtml: Return NULL for document not attached to window in IHTMLDocument7::get_defaultView.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/mshtml/htmldoc.c   | 14 ++++++++++----
 dlls/mshtml/tests/dom.c | 12 ++++++++++++
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c
index f08db09..690ab08 100644
--- a/dlls/mshtml/htmldoc.c
+++ b/dlls/mshtml/htmldoc.c
@@ -1627,10 +1627,12 @@ static HRESULT WINAPI HTMLDocument_elementFromPoint(IHTMLDocument2 *iface, LONG
 static HRESULT WINAPI HTMLDocument_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
 {
     HTMLDocument *This = impl_from_IHTMLDocument2(iface);
+    HRESULT hres;
 
     TRACE("(%p)->(%p)\n", This, p);
 
-    return IHTMLDocument7_get_defaultView(&This->IHTMLDocument7_iface, p);
+    hres = IHTMLDocument7_get_defaultView(&This->IHTMLDocument7_iface, p);
+    return hres == S_OK && !*p ? E_FAIL : hres;
 }
 
 static HRESULT WINAPI HTMLDocument_get_styleSheets(IHTMLDocument2 *iface,
@@ -3248,12 +3250,16 @@ static HRESULT WINAPI HTMLDocument7_Invoke(IHTMLDocument7 *iface, DISPID dispIdM
 
 static HRESULT WINAPI HTMLDocument7_get_defaultView(IHTMLDocument7 *iface, IHTMLWindow2 **p)
 {
-    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
+    HTMLDocumentNode *This = impl_from_IHTMLDocument7(iface)->doc_node;
 
     TRACE("(%p)->(%p)\n", This, p);
 
-    *p = &This->window->base.IHTMLWindow2_iface;
-    IHTMLWindow2_AddRef(*p);
+    if(This->window && This->window->base.outer_window) {
+        *p = &This->window->base.outer_window->base.IHTMLWindow2_iface;
+        IHTMLWindow2_AddRef(*p);
+    }else {
+        *p = NULL;
+    }
     return S_OK;
 }
 
diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c
index 52d353f..c4d30ca 100644
--- a/dlls/mshtml/tests/dom.c
+++ b/dlls/mshtml/tests/dom.c
@@ -6924,6 +6924,7 @@ static void test_dom_implementation(IHTMLDocument2 *doc)
         IHTMLDocument2 *new_document2;
         IHTMLDocument7 *new_document;
         IHTMLLocation *location;
+        IHTMLWindow2 *window;
 
         str = a2bstr("test");
         hres = IHTMLDOMImplementation2_createHTMLDocument(dom_implementation2, str, &new_document);
@@ -6932,9 +6933,20 @@ static void test_dom_implementation(IHTMLDocument2 *doc)
         test_disp((IUnknown*)new_document, &DIID_DispHTMLDocument, &CLSID_HTMLDocument, "[object]");
         test_ifaces((IUnknown*)new_document, doc_node_iids);
 
+        hres = IHTMLDocument7_get_defaultView(new_document, &window);
+        ok(hres == S_OK, "get_defaultView returned: %08x\n", hres);
+        ok(!window, "window = %p\n", window);
+
+        hres = IHTMLDocument7_get_parentWindow(new_document, &window);
+        ok(hres == S_OK, "get_parentWindow returned: %08x\n", hres);
+        ok(!window, "window = %p\n", window);
+
         hres = IHTMLDocument7_QueryInterface(new_document, &IID_IHTMLDocument2, (void**)&new_document2);
         ok(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
 
+        hres = IHTMLDocument2_get_parentWindow(new_document2, &window);
+        ok(hres == E_FAIL, "get_parentWindow returned: %08x\n", hres);
+
         hres = IHTMLDocument2_get_location(new_document2, &location);
         ok(hres == E_UNEXPECTED, "get_location returned: %08x\n", hres);
 




More information about the wine-cvs mailing list