From 9626f92332c3ebde122d36d7c49b703dc9220799 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 16 Sep 2009 22:08:41 +0200 Subject: [PATCH] mshtml: Store reference to document node in window object. --- dlls/mshtml/htmldoc.c | 9 +++++---- dlls/mshtml/htmliframe.c | 25 ++++++++++++++++--------- dlls/mshtml/htmlwindow.c | 13 +++++++++++++ dlls/mshtml/mshtml_private.h | 1 + dlls/mshtml/nsembed.c | 8 ++++---- 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c index 37b1d517b18..d083f6be0bb 100644 --- a/dlls/mshtml/htmldoc.c +++ b/dlls/mshtml/htmldoc.c @@ -1783,9 +1783,6 @@ static void destroy_htmldoc(HTMLDocument *This) if(This->hwnd) DestroyWindow(This->hwnd); - if(This->window) - IHTMLWindow2_Release(HTMLWINDOW2(This->window)); - if(This->event_target) release_event_target(This->event_target); @@ -1864,7 +1861,6 @@ HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocumentObj *doc_ob nsIDOMHTMLDocument_AddRef(nsdoc); doc->basedoc.nsdoc = nsdoc; - IHTMLWindow2_AddRef(HTMLWINDOW2(window)); doc->basedoc.window = window; *ret = doc; @@ -1902,6 +1898,11 @@ static ULONG HTMLDocumentObj_Release(HTMLDocument *base) This->basedoc.doc_node->basedoc.doc_obj = NULL; IHTMLDocument2_Release(HTMLDOC(&This->basedoc.doc_node->basedoc)); } + if(This->basedoc.window) { + This->basedoc.window->doc_obj = NULL; + IHTMLWindow2_Release(HTMLWINDOW2(This->basedoc.window)); + } + destroy_htmldoc(&This->basedoc); heap_free(This); } diff --git a/dlls/mshtml/htmliframe.c b/dlls/mshtml/htmliframe.c index 45673dd8e32..9124a0a0630 100644 --- a/dlls/mshtml/htmliframe.c +++ b/dlls/mshtml/htmliframe.c @@ -38,7 +38,7 @@ typedef struct { LONG ref; nsIDOMHTMLIFrameElement *nsiframe; - HTMLDocumentNode *content_doc; + HTMLWindow *content_window; } HTMLIFrame; #define HTMLFRAMEBASE2(x) (&(x)->lpIHTMLFrameBase2Vtbl) @@ -104,8 +104,9 @@ static HRESULT WINAPI HTMLIFrameBase2_get_contentWindow(IHTMLFrameBase2 *iface, TRACE("(%p)->(%p)\n", This, p); - if(!This->content_doc) { + if(!This->content_window) { nsIDOMHTMLDocument *nshtmldoc; + HTMLDocumentNode *content_doc; nsIDOMDocument *nsdoc; HTMLWindow *window; nsresult nsres; @@ -135,16 +136,22 @@ static HRESULT WINAPI HTMLIFrameBase2_get_contentWindow(IHTMLFrameBase2 *iface, return hres; } - hres = create_doc_from_nsdoc(nshtmldoc, This->element.node.doc->doc_obj, window, &This->content_doc); - if(SUCCEEDED(hres)) - window->doc = This->content_doc; - IHTMLWindow2_Release(HTMLWINDOW2(window)); + hres = create_doc_from_nsdoc(nshtmldoc, This->element.node.doc->doc_obj, window, &content_doc); nsIDOMHTMLDocument_Release(nshtmldoc); + if(SUCCEEDED(hres)) + window_set_docnode(window, content_doc); + else + IHTMLWindow2_Release(HTMLWINDOW2(window)); + htmldoc_release(&content_doc->basedoc); if(FAILED(hres)) return hres; + + This->content_window = window; } - return IHTMLDocument2_get_parentWindow(HTMLDOC(&This->content_doc->basedoc), p); + IHTMLWindow2_AddRef(HTMLWINDOW2(This->content_window)); + *p = HTMLWINDOW2(This->content_window); + return S_OK; } static HRESULT WINAPI HTMLIFrameBase2_put_onload(IHTMLFrameBase2 *iface, VARIANT v) @@ -239,8 +246,8 @@ static void HTMLIFrame_destructor(HTMLDOMNode *iface) { HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface); - if(This->content_doc) - htmldoc_release(&This->content_doc->basedoc); + if(This->content_window) + IHTMLWindow2_Release(HTMLWINDOW2(This->content_window)); if(This->nsiframe) nsIDOMHTMLIFrameElement_Release(This->nsiframe); diff --git a/dlls/mshtml/htmlwindow.c b/dlls/mshtml/htmlwindow.c index 5720fe8591c..970e327d2c6 100644 --- a/dlls/mshtml/htmlwindow.c +++ b/dlls/mshtml/htmlwindow.c @@ -36,6 +36,17 @@ WINE_DEFAULT_DEBUG_CHANNEL(mshtml); static struct list window_list = LIST_INIT(window_list); +void window_set_docnode(HTMLWindow *window, HTMLDocumentNode *doc_node) +{ + if(window->doc) { + window->doc->basedoc.window = NULL; + htmldoc_release(&window->doc->basedoc); + } + window->doc = doc_node; + if(doc_node) + htmldoc_addref(&doc_node->basedoc); +} + #define HTMLWINDOW2_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow2, iface) static HRESULT WINAPI HTMLWindow2_QueryInterface(IHTMLWindow2 *iface, REFIID riid, void **ppv) @@ -95,6 +106,8 @@ static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface) if(!ref) { DWORD i; + window_set_docnode(This, NULL); + if(This->option_factory) { This->option_factory->window = NULL; IHTMLOptionElementFactory_Release(HTMLOPTFACTORY(This->option_factory)); diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index 93cf7a65716..71a8c8bfbc0 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -549,6 +549,7 @@ HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**); HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument*,HTMLDocumentObj*,HTMLWindow*,HTMLDocumentNode**); HRESULT HTMLWindow_Create(HTMLDocumentObj*,nsIDOMWindow*,HTMLWindow**); +void window_set_docnode(HTMLWindow*,HTMLDocumentNode*); HTMLWindow *nswindow_to_window(const nsIDOMWindow*); HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLWindow*); HRESULT HTMLLocation_Create(HTMLWindow*,HTMLLocation**); diff --git a/dlls/mshtml/nsembed.c b/dlls/mshtml/nsembed.c index bf063dda2b4..61759e9cb9c 100644 --- a/dlls/mshtml/nsembed.c +++ b/dlls/mshtml/nsembed.c @@ -844,13 +844,13 @@ void update_nsdocument(HTMLDocumentObj *doc) doc_node->basedoc.doc_obj = NULL; IHTMLDocument2_Release(HTMLDOC(&doc_node->basedoc)); doc->basedoc.doc_node = NULL; - - doc->basedoc.window->doc = NULL; } doc->basedoc.nsdoc = nsdoc; - if(!nsdoc) + if(!nsdoc) { + window_set_docnode(doc->basedoc.window, NULL); return; + } set_mutation_observer(doc->basedoc.nscontainer, nsdoc); @@ -861,7 +861,7 @@ void update_nsdocument(HTMLDocumentObj *doc) } doc->basedoc.doc_node = doc_node; - doc->basedoc.window->doc = doc_node; + window_set_docnode(doc->basedoc.window, doc_node); } void close_gecko(void)