diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c index f6cb876659a..5e34ced52a8 100644 --- a/dlls/mshtml/htmldoc.c +++ b/dlls/mshtml/htmldoc.c @@ -1769,8 +1769,10 @@ static void HTMLDocumentNode_destructor(HTMLDOMNode *iface) detach_ranges(This); release_nodes(This); - if(This->nsdoc) + if(This->nsdoc) { + release_mutation(This); nsIDOMHTMLDocument_Release(This->nsdoc); + } destroy_htmldoc(&This->basedoc); } @@ -1811,7 +1813,6 @@ HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocumentObj *doc_ob doc->basedoc.doc_node = doc; doc->basedoc.doc_obj = doc_obj; - init_mutation(doc); init_dispex(&doc->node.dispex, (IUnknown*)HTMLDOMNODE(&doc->node), &HTMLDocumentNode_dispex); init_doc(&doc->basedoc, (IUnknown*)HTMLDOMNODE(&doc->node), DISPATCHEX(&doc->node.dispex)); HTMLDocumentNode_SecMgr_Init(doc); @@ -1819,6 +1820,7 @@ HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocumentObj *doc_ob nsIDOMHTMLDocument_AddRef(nsdoc); doc->nsdoc = nsdoc; + init_mutation(doc); doc->basedoc.window = window; @@ -1887,8 +1889,6 @@ static ULONG WINAPI CustomDoc_Release(ICustomDoc *iface) set_document_bscallback(&This->basedoc, NULL); set_current_mon(&This->basedoc, NULL); if(This->basedoc.doc_node) { - if(This->basedoc.doc_node->nsdoc) - remove_mutation_observer(This->basedoc.doc_node); This->basedoc.doc_node->basedoc.doc_obj = NULL; IHTMLDocument2_Release(HTMLDOC(&This->basedoc.doc_node->basedoc)); } diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index 92688e1a567..85421d117e9 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -601,8 +601,7 @@ NSContainer *NSContainer_Create(HTMLDocumentObj*,NSContainer*); void NSContainer_Release(NSContainer*); void init_mutation(HTMLDocumentNode*); -void set_mutation_observer(HTMLDocumentNode*); -void remove_mutation_observer(HTMLDocumentNode*); +void release_mutation(HTMLDocumentNode*); void HTMLDocument_LockContainer(HTMLDocumentObj*,BOOL); void show_context_menu(HTMLDocumentObj*,DWORD,POINT*,IDispatch*); diff --git a/dlls/mshtml/mutation.c b/dlls/mshtml/mutation.c index f2c510ac9ed..20ef121baca 100644 --- a/dlls/mshtml/mutation.c +++ b/dlls/mshtml/mutation.c @@ -40,36 +40,6 @@ enum { MUTATION_SCRIPT }; -void set_mutation_observer(HTMLDocumentNode *doc) -{ - nsIDOMNSDocument *nsdoc; - nsresult nsres; - - nsres = nsIDOMHTMLDocument_QueryInterface(doc->nsdoc, &IID_nsIDOMNSDocument, (void**)&nsdoc); - if(NS_FAILED(nsres)) { - ERR("Could not get nsIDOMNSDocument: %08x\n", nsres); - return; - } - - nsIDOMNSDocument_WineAddObserver(nsdoc, NSDOCOBS(doc)); - nsIDOMNSDocument_Release(nsdoc); -} - -void remove_mutation_observer(HTMLDocumentNode *doc) -{ - nsIDOMNSDocument *nsdoc; - nsresult nsres; - - nsres = nsIDOMHTMLDocument_QueryInterface(doc->nsdoc, &IID_nsIDOMNSDocument, (void**)&nsdoc); - if(NS_FAILED(nsres)) { - ERR("Could not get nsIDOMNSDocument: %08x\n", nsres); - return; - } - - nsIDOMNSDocument_WineRemoveObserver(nsdoc, NSDOCOBS(doc)); - nsIDOMNSDocument_Release(nsdoc); -} - #define IE_MAJOR_VERSION 7 #define IE_MINOR_VERSION 0 @@ -612,6 +582,33 @@ static const nsIDocumentObserverVtbl nsDocumentObserverVtbl = { void init_mutation(HTMLDocumentNode *doc) { + nsIDOMNSDocument *nsdoc; + nsresult nsres; + doc->lpIDocumentObserverVtbl = &nsDocumentObserverVtbl; doc->lpIRunnableVtbl = &nsRunnableVtbl; + + nsres = nsIDOMHTMLDocument_QueryInterface(doc->nsdoc, &IID_nsIDOMNSDocument, (void**)&nsdoc); + if(NS_FAILED(nsres)) { + ERR("Could not get nsIDOMNSDocument: %08x\n", nsres); + return; + } + + nsIDOMNSDocument_WineAddObserver(nsdoc, NSDOCOBS(doc)); + nsIDOMNSDocument_Release(nsdoc); +} + +void release_mutation(HTMLDocumentNode *doc) +{ + nsIDOMNSDocument *nsdoc; + nsresult nsres; + + nsres = nsIDOMHTMLDocument_QueryInterface(doc->nsdoc, &IID_nsIDOMNSDocument, (void**)&nsdoc); + if(NS_FAILED(nsres)) { + ERR("Could not get nsIDOMNSDocument: %08x\n", nsres); + return; + } + + nsIDOMNSDocument_WineRemoveObserver(nsdoc, NSDOCOBS(doc)); + nsIDOMNSDocument_Release(nsdoc); } diff --git a/dlls/mshtml/nsembed.c b/dlls/mshtml/nsembed.c index 565b688f89a..463c4eea7b3 100644 --- a/dlls/mshtml/nsembed.c +++ b/dlls/mshtml/nsembed.c @@ -838,7 +838,6 @@ void update_nsdocument(HTMLDocumentObj *doc) if(doc->basedoc.doc_node && doc->basedoc.doc_node->nsdoc) { doc_node = doc->basedoc.doc_node; - remove_mutation_observer(doc_node); doc_node->basedoc.doc_obj = NULL; IHTMLDocument2_Release(HTMLDOC(&doc_node->basedoc)); doc->basedoc.doc_node = NULL; @@ -856,7 +855,6 @@ void update_nsdocument(HTMLDocumentObj *doc) return; } - set_mutation_observer(doc_node); doc->basedoc.doc_node = doc_node; window_set_docnode(doc->basedoc.window, doc_node); }