diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c index 00bc68c331a..f39688bf471 100644 --- a/dlls/mshtml/htmldoc.c +++ b/dlls/mshtml/htmldoc.c @@ -1551,6 +1551,7 @@ static dispex_static_data_t HTMLDocument_dispex = { HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject) { + nsIDOMWindow *nswindow; HTMLDocument *ret; HRESULT hres; @@ -1596,7 +1597,12 @@ HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject) ret->nscontainer = NSContainer_Create(ret, NULL); update_nsdocument(ret); - ret->window = HTMLWindow_Create(ret); + if(ret->nscontainer) + nsIWebBrowser_GetContentDOMWindow(ret->nscontainer->webbrowser, &nswindow); + + HTMLWindow_Create(ret, nswindow, &ret->window); + if(nswindow) + nsIDOMWindow_Release(nswindow); get_thread_hwnd(); diff --git a/dlls/mshtml/htmlwindow.c b/dlls/mshtml/htmlwindow.c index 6e8a8eadbfd..b73811a9ecb 100644 --- a/dlls/mshtml/htmlwindow.c +++ b/dlls/mshtml/htmlwindow.c @@ -1182,29 +1182,31 @@ static dispex_static_data_t HTMLWindow_dispex = { HTMLWindow_iface_tids }; -HTMLWindow *HTMLWindow_Create(HTMLDocument *doc) +HRESULT HTMLWindow_Create(HTMLDocument *doc, nsIDOMWindow *nswindow, HTMLWindow **ret) { - HTMLWindow *ret = heap_alloc_zero(sizeof(HTMLWindow)); + HTMLWindow *window; - ret->lpHTMLWindow2Vtbl = &HTMLWindow2Vtbl; - ret->lpHTMLWindow3Vtbl = &HTMLWindow3Vtbl; - ret->lpIDispatchExVtbl = &WindowDispExVtbl; - ret->ref = 1; - ret->doc = doc; + window = heap_alloc_zero(sizeof(HTMLWindow)); + if(!window) + return E_OUTOFMEMORY; - init_dispex(&ret->dispex, (IUnknown*)HTMLWINDOW2(ret), &HTMLWindow_dispex); + window->lpHTMLWindow2Vtbl = &HTMLWindow2Vtbl; + window->lpHTMLWindow3Vtbl = &HTMLWindow3Vtbl; + window->lpIDispatchExVtbl = &WindowDispExVtbl; + window->ref = 1; + window->doc = doc; - if(doc->nscontainer) { - nsresult nsres; + init_dispex(&window->dispex, (IUnknown*)HTMLWINDOW2(window), &HTMLWindow_dispex); - nsres = nsIWebBrowser_GetContentDOMWindow(doc->nscontainer->webbrowser, &ret->nswindow); - if(NS_FAILED(nsres)) - ERR("GetContentDOMWindow failed: %08x\n", nsres); + if(nswindow) { + nsIDOMWindow_AddRef(nswindow); + window->nswindow = nswindow; } - list_add_head(&window_list, &ret->entry); + list_add_head(&window_list, &window->entry); - return ret; + *ret = window; + return S_OK; } HTMLWindow *nswindow_to_window(const nsIDOMWindow *nswindow) diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index 79c954d414e..c39d245d56b 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -460,7 +460,7 @@ typedef struct { HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**); HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**); -HTMLWindow *HTMLWindow_Create(HTMLDocument*); +HRESULT HTMLWindow_Create(HTMLDocument*,nsIDOMWindow*,HTMLWindow**); HTMLWindow *nswindow_to_window(const nsIDOMWindow*); HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLDocument*); HTMLLocation *HTMLLocation_Create(HTMLDocument*);