wiaservc: COM cleanup for the IWiaDevMgr iface.
[wine] / dlls / mshtml / mutation.c
1 /*
2  * Copyright 2008 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22
23 #define COBJMACROS
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "ole2.h"
30 #include "shlguid.h"
31
32 #include "mshtml_private.h"
33 #include "htmlevent.h"
34
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38
39 enum {
40     MUTATION_BINDTOTREE,
41     MUTATION_COMMENT,
42     MUTATION_ENDLOAD,
43     MUTATION_SCRIPT
44 };
45
46 #define IE_MAJOR_VERSION 7
47 #define IE_MINOR_VERSION 0
48
49 static BOOL handle_insert_comment(HTMLDocumentNode *doc, const PRUnichar *comment)
50 {
51     DWORD len;
52     int majorv = 0, minorv = 0;
53     const PRUnichar *ptr, *end;
54     nsAString nsstr;
55     PRUnichar *buf;
56     nsresult nsres;
57
58     enum {
59         CMP_EQ,
60         CMP_LT,
61         CMP_LTE,
62         CMP_GT,
63         CMP_GTE
64     } cmpt = CMP_EQ;
65
66     static const PRUnichar endifW[] = {'<','!','[','e','n','d','i','f',']'};
67
68     if(comment[0] != '[' || comment[1] != 'i' || comment[2] != 'f')
69         return FALSE;
70
71     ptr = comment+3;
72     while(isspaceW(*ptr))
73         ptr++;
74
75     if(ptr[0] == 'l' && ptr[1] == 't') {
76         ptr += 2;
77         if(*ptr == 'e') {
78             cmpt = CMP_LTE;
79             ptr++;
80         }else {
81             cmpt = CMP_LT;
82         }
83     }else if(ptr[0] == 'g' && ptr[1] == 't') {
84         ptr += 2;
85         if(*ptr == 'e') {
86             cmpt = CMP_GTE;
87             ptr++;
88         }else {
89             cmpt = CMP_GT;
90         }
91     }
92
93     if(!isspaceW(*ptr++))
94         return FALSE;
95     while(isspaceW(*ptr))
96         ptr++;
97
98     if(ptr[0] != 'I' || ptr[1] != 'E')
99         return FALSE;
100
101     ptr +=2;
102     if(!isspaceW(*ptr++))
103         return FALSE;
104     while(isspaceW(*ptr))
105         ptr++;
106
107     if(!isdigitW(*ptr))
108         return FALSE;
109     while(isdigitW(*ptr))
110         majorv = majorv*10 + (*ptr++ - '0');
111
112     if(*ptr == '.') {
113         ptr++;
114         if(!isdigitW(*ptr))
115             return FALSE;
116         while(isdigitW(*ptr))
117             minorv = minorv*10 + (*ptr++ - '0');
118     }
119
120     while(isspaceW(*ptr))
121         ptr++;
122     if(ptr[0] != ']' || ptr[1] != '>')
123         return FALSE;
124     ptr += 2;
125
126     len = strlenW(ptr);
127     if(len < sizeof(endifW)/sizeof(WCHAR))
128         return FALSE;
129
130     end = ptr + len-sizeof(endifW)/sizeof(WCHAR);
131     if(memcmp(end, endifW, sizeof(endifW)))
132         return FALSE;
133
134     switch(cmpt) {
135     case CMP_EQ:
136         if(majorv == IE_MAJOR_VERSION && minorv == IE_MINOR_VERSION)
137             break;
138         return FALSE;
139     case CMP_LT:
140         if(majorv > IE_MAJOR_VERSION)
141             break;
142         if(majorv == IE_MAJOR_VERSION && minorv > IE_MINOR_VERSION)
143             break;
144         return FALSE;
145     case CMP_LTE:
146         if(majorv > IE_MAJOR_VERSION)
147             break;
148         if(majorv == IE_MAJOR_VERSION && minorv >= IE_MINOR_VERSION)
149             break;
150         return FALSE;
151     case CMP_GT:
152         if(majorv < IE_MAJOR_VERSION)
153             break;
154         if(majorv == IE_MAJOR_VERSION && minorv < IE_MINOR_VERSION)
155             break;
156         return FALSE;
157     case CMP_GTE:
158         if(majorv < IE_MAJOR_VERSION)
159             break;
160         if(majorv == IE_MAJOR_VERSION && minorv <= IE_MINOR_VERSION)
161             break;
162         return FALSE;
163     }
164
165     buf = heap_alloc((end-ptr+1)*sizeof(WCHAR));
166     if(!buf)
167         return FALSE;
168
169     memcpy(buf, ptr, (end-ptr)*sizeof(WCHAR));
170     buf[end-ptr] = 0;
171     nsAString_InitDepend(&nsstr, buf);
172
173     /* FIXME: Find better way to insert HTML to document. */
174     nsres = nsIDOMHTMLDocument_Write(doc->nsdoc, &nsstr);
175     nsAString_Finish(&nsstr);
176     heap_free(buf);
177     if(NS_FAILED(nsres)) {
178         ERR("Write failed: %08x\n", nsres);
179         return FALSE;
180     }
181
182     return TRUE;
183 }
184
185 static void add_script_runner(HTMLDocumentNode *This)
186 {
187     nsIDOMNSDocument *nsdoc;
188     nsresult nsres;
189
190     nsres = nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMNSDocument, (void**)&nsdoc);
191     if(NS_FAILED(nsres)) {
192         ERR("Could not get nsIDOMNSDocument: %08x\n", nsres);
193         return;
194     }
195
196     nsIDOMNSDocument_WineAddScriptRunner(nsdoc, &This->nsIRunnable_iface);
197     nsIDOMNSDocument_Release(nsdoc);
198 }
199
200 static inline HTMLDocumentNode *impl_from_nsIRunnable(nsIRunnable *iface)
201 {
202     return CONTAINING_RECORD(iface, HTMLDocumentNode, nsIRunnable_iface);
203 }
204
205 static nsresult NSAPI nsRunnable_QueryInterface(nsIRunnable *iface,
206         nsIIDRef riid, void **result)
207 {
208     HTMLDocumentNode *This = impl_from_nsIRunnable(iface);
209
210     if(IsEqualGUID(riid, &IID_nsISupports)) {
211         TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
212         *result = &This->nsIRunnable_iface;
213     }else if(IsEqualGUID(riid, &IID_nsIRunnable)) {
214         TRACE("(%p)->(IID_nsIRunnable %p)\n", This, result);
215         *result = &This->nsIRunnable_iface;
216     }else {
217         *result = NULL;
218         WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
219         return NS_NOINTERFACE;
220     }
221
222     nsISupports_AddRef((nsISupports*)*result);
223     return NS_OK;
224 }
225
226 static nsrefcnt NSAPI nsRunnable_AddRef(nsIRunnable *iface)
227 {
228     HTMLDocumentNode *This = impl_from_nsIRunnable(iface);
229     return htmldoc_addref(&This->basedoc);
230 }
231
232 static nsrefcnt NSAPI nsRunnable_Release(nsIRunnable *iface)
233 {
234     HTMLDocumentNode *This = impl_from_nsIRunnable(iface);
235     return htmldoc_release(&This->basedoc);
236 }
237
238 static void push_mutation_queue(HTMLDocumentNode *doc, DWORD type, nsISupports *nsiface)
239 {
240     mutation_queue_t *elem;
241
242     elem = heap_alloc(sizeof(mutation_queue_t));
243     if(!elem)
244         return;
245
246     elem->next = NULL;
247     elem->type = type;
248     elem->nsiface = nsiface;
249     if(nsiface)
250         nsISupports_AddRef(nsiface);
251
252     if(doc->mutation_queue_tail) {
253         doc->mutation_queue_tail = doc->mutation_queue_tail->next = elem;
254     }else {
255         doc->mutation_queue = doc->mutation_queue_tail = elem;
256         add_script_runner(doc);
257     }
258 }
259
260 static void pop_mutation_queue(HTMLDocumentNode *doc)
261 {
262     mutation_queue_t *tmp = doc->mutation_queue;
263
264     if(!tmp)
265         return;
266
267     doc->mutation_queue = tmp->next;
268     if(!tmp->next)
269         doc->mutation_queue_tail = NULL;
270
271     if(tmp->nsiface)
272         nsISupports_Release(tmp->nsiface);
273     heap_free(tmp);
274 }
275
276 static void bind_to_tree(HTMLDocumentNode *doc, nsISupports *nsiface)
277 {
278     nsIDOMNode *nsnode;
279     HTMLDOMNode *node;
280     nsresult nsres;
281     HRESULT hres;
282
283     nsres = nsISupports_QueryInterface(nsiface, &IID_nsIDOMNode, (void**)&nsnode);
284     if(NS_FAILED(nsres))
285         return;
286
287     hres = get_node(doc, nsnode, TRUE, &node);
288     nsIDOMNode_Release(nsnode);
289     if(FAILED(hres)) {
290         ERR("Could not get node\n");
291         return;
292     }
293
294     if(node->vtbl->bind_to_tree)
295         node->vtbl->bind_to_tree(node);
296 }
297
298 /* Calls undocumented 69 cmd of CGID_Explorer */
299 static void call_explorer_69(HTMLDocumentObj *doc)
300 {
301     IOleCommandTarget *olecmd;
302     VARIANT var;
303     HRESULT hres;
304
305     if(!doc->client)
306         return;
307
308     hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
309     if(FAILED(hres))
310         return;
311
312     VariantInit(&var);
313     hres = IOleCommandTarget_Exec(olecmd, &CGID_Explorer, 69, 0, NULL, &var);
314     IOleCommandTarget_Release(olecmd);
315     if(SUCCEEDED(hres) && V_VT(&var) != VT_NULL)
316         FIXME("handle result\n");
317 }
318
319 static void parse_complete(HTMLDocumentObj *doc)
320 {
321     TRACE("(%p)\n", doc);
322
323     if(doc->usermode == EDITMODE)
324         init_editor(&doc->basedoc);
325
326     call_explorer_69(doc);
327     if(doc->view_sink)
328         IAdviseSink_OnViewChange(doc->view_sink, DVASPECT_CONTENT, -1);
329     call_property_onchanged(&doc->basedoc.cp_propnotif, 1005);
330     call_explorer_69(doc);
331
332     /* FIXME: IE7 calls EnableModelless(TRUE), EnableModelless(FALSE) and sets interactive state here */
333 }
334
335 static void handle_end_load(HTMLDocumentNode *This)
336 {
337     TRACE("\n");
338
339     if(!This->basedoc.doc_obj)
340         return;
341
342     if(This == This->basedoc.doc_obj->basedoc.doc_node) {
343         /*
344          * This should be done in the worker thread that parses HTML,
345          * but we don't have such thread (Gecko parses HTML for us).
346          */
347         parse_complete(This->basedoc.doc_obj);
348     }
349
350     set_ready_state(This->basedoc.window, READYSTATE_INTERACTIVE);
351 }
352
353 static nsresult NSAPI nsRunnable_Run(nsIRunnable *iface)
354 {
355     HTMLDocumentNode *This = impl_from_nsIRunnable(iface);
356     nsresult nsres;
357
358     TRACE("(%p)\n", This);
359
360     while(This->mutation_queue) {
361         switch(This->mutation_queue->type) {
362         case MUTATION_BINDTOTREE:
363             bind_to_tree(This, This->mutation_queue->nsiface);
364             break;
365
366         case MUTATION_COMMENT: {
367             nsIDOMComment *nscomment;
368             nsAString comment_str;
369             BOOL remove_comment = FALSE;
370
371             nsres = nsISupports_QueryInterface(This->mutation_queue->nsiface, &IID_nsIDOMComment, (void**)&nscomment);
372             if(NS_FAILED(nsres)) {
373                 ERR("Could not get nsIDOMComment iface:%08x\n", nsres);
374                 return NS_OK;
375             }
376
377             nsAString_Init(&comment_str, NULL);
378             nsres = nsIDOMComment_GetData(nscomment, &comment_str);
379             if(NS_SUCCEEDED(nsres)) {
380                 const PRUnichar *comment;
381
382                 nsAString_GetData(&comment_str, &comment);
383                 remove_comment = handle_insert_comment(This, comment);
384             }
385
386             nsAString_Finish(&comment_str);
387
388             if(remove_comment) {
389                 nsIDOMNode *nsparent, *tmp;
390                 nsAString magic_str;
391
392                 static const PRUnichar remove_comment_magicW[] =
393                     {'#','!','w','i','n','e', 'r','e','m','o','v','e','!','#',0};
394
395                 nsAString_InitDepend(&magic_str, remove_comment_magicW);
396                 nsres = nsIDOMComment_SetData(nscomment, &magic_str);
397                 nsAString_Finish(&magic_str);
398                 if(NS_FAILED(nsres))
399                     ERR("SetData failed: %08x\n", nsres);
400
401                 nsIDOMComment_GetParentNode(nscomment, &nsparent);
402                 if(nsparent) {
403                     nsIDOMNode_RemoveChild(nsparent, (nsIDOMNode*)nscomment, &tmp);
404                     nsIDOMNode_Release(nsparent);
405                     nsIDOMNode_Release(tmp);
406                 }
407             }
408
409             nsIDOMComment_Release(nscomment);
410             break;
411         }
412
413         case MUTATION_ENDLOAD:
414             handle_end_load(This);
415             break;
416
417         case MUTATION_SCRIPT: {
418             nsIDOMHTMLScriptElement *nsscript;
419
420             nsres = nsISupports_QueryInterface(This->mutation_queue->nsiface, &IID_nsIDOMHTMLScriptElement,
421                                                (void**)&nsscript);
422             if(NS_FAILED(nsres)) {
423                 ERR("Could not get nsIDOMHTMLScriptElement: %08x\n", nsres);
424                 break;
425             }
426
427             doc_insert_script(This->basedoc.window, nsscript);
428             nsIDOMHTMLScriptElement_Release(nsscript);
429             break;
430         }
431
432         default:
433             ERR("invalid type %d\n", This->mutation_queue->type);
434         }
435
436         pop_mutation_queue(This);
437     }
438
439     return S_OK;
440 }
441
442 static const nsIRunnableVtbl nsRunnableVtbl = {
443     nsRunnable_QueryInterface,
444     nsRunnable_AddRef,
445     nsRunnable_Release,
446     nsRunnable_Run
447 };
448
449 static inline HTMLDocumentNode *impl_from_nsIDocumentObserver(nsIDocumentObserver *iface)
450 {
451     return CONTAINING_RECORD(iface, HTMLDocumentNode, nsIDocumentObserver_iface);
452 }
453
454 static nsresult NSAPI nsDocumentObserver_QueryInterface(nsIDocumentObserver *iface,
455         nsIIDRef riid, void **result)
456 {
457     HTMLDocumentNode *This = impl_from_nsIDocumentObserver(iface);
458
459     if(IsEqualGUID(&IID_nsISupports, riid)) {
460         TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
461         *result = &This->nsIDocumentObserver_iface;
462     }else if(IsEqualGUID(&IID_nsIMutationObserver, riid)) {
463         TRACE("(%p)->(IID_nsIMutationObserver %p)\n", This, result);
464         *result = &This->nsIDocumentObserver_iface;
465     }else if(IsEqualGUID(&IID_nsIDocumentObserver, riid)) {
466         TRACE("(%p)->(IID_nsIDocumentObserver %p)\n", This, result);
467         *result = &This->nsIDocumentObserver_iface;
468     }else {
469         *result = NULL;
470         TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
471         return NS_NOINTERFACE;
472     }
473
474     htmldoc_addref(&This->basedoc);
475     return NS_OK;
476 }
477
478 static nsrefcnt NSAPI nsDocumentObserver_AddRef(nsIDocumentObserver *iface)
479 {
480     HTMLDocumentNode *This = impl_from_nsIDocumentObserver(iface);
481     return htmldoc_addref(&This->basedoc);
482 }
483
484 static nsrefcnt NSAPI nsDocumentObserver_Release(nsIDocumentObserver *iface)
485 {
486     HTMLDocumentNode *This = impl_from_nsIDocumentObserver(iface);
487     return htmldoc_release(&This->basedoc);
488 }
489
490 static void NSAPI nsDocumentObserver_CharacterDataWillChange(nsIDocumentObserver *iface,
491         nsIDocument *aDocument, nsIContent *aContent, void /*CharacterDataChangeInfo*/ *aInfo)
492 {
493 }
494
495 static void NSAPI nsDocumentObserver_CharacterDataChanged(nsIDocumentObserver *iface,
496         nsIDocument *aDocument, nsIContent *aContent, void /*CharacterDataChangeInfo*/ *aInfo)
497 {
498 }
499
500 static void NSAPI nsDocumentObserver_AttributeWillChange(nsIDocumentObserver *iface, nsIDocument *aDocument,
501         nsIContent *aContent, PRInt32 aNameSpaceID, nsIAtom *aAttribute, PRInt32 aModType)
502 {
503 }
504
505 static void NSAPI nsDocumentObserver_AttributeChanged(nsIDocumentObserver *iface, nsIDocument *aDocument,
506         nsIContent *aContent, PRInt32 aNameSpaceID, nsIAtom *aAttribute, PRInt32 aModType)
507 {
508 }
509
510 static void NSAPI nsDocumentObserver_ContentAppended(nsIDocumentObserver *iface, nsIDocument *aDocument,
511         nsIContent *aContainer, nsIContent *aFirstNewContent, PRInt32 aNewIndexInContainer)
512 {
513 }
514
515 static void NSAPI nsDocumentObserver_ContentInserted(nsIDocumentObserver *iface, nsIDocument *aDocument,
516         nsIContent *aContainer, nsIContent *aChild, PRInt32 aIndexInContainer)
517 {
518 }
519
520 static void NSAPI nsDocumentObserver_ContentRemoved(nsIDocumentObserver *iface, nsIDocument *aDocument,
521         nsIContent *aContainer, nsIContent *aChild, PRInt32 aIndexInContainer,
522         nsIContent *aProviousSibling)
523 {
524 }
525
526 static void NSAPI nsDocumentObserver_NodeWillBeDestroyed(nsIDocumentObserver *iface, const nsINode *aNode)
527 {
528 }
529
530 static void NSAPI nsDocumentObserver_ParentChainChanged(nsIDocumentObserver *iface, nsIContent *aContent)
531 {
532 }
533
534 static void NSAPI nsDocumentObserver_BeginUpdate(nsIDocumentObserver *iface, nsIDocument *aDocument,
535         nsUpdateType aUpdateType)
536 {
537 }
538
539 static void NSAPI nsDocumentObserver_EndUpdate(nsIDocumentObserver *iface, nsIDocument *aDocument,
540         nsUpdateType aUpdateType)
541 {
542 }
543
544 static void NSAPI nsDocumentObserver_BeginLoad(nsIDocumentObserver *iface, nsIDocument *aDocument)
545 {
546 }
547
548 static void NSAPI nsDocumentObserver_EndLoad(nsIDocumentObserver *iface, nsIDocument *aDocument)
549 {
550     HTMLDocumentNode *This = impl_from_nsIDocumentObserver(iface);
551
552     TRACE("\n");
553
554     if(This->skip_mutation_notif)
555         return;
556
557     This->content_ready = TRUE;
558     push_mutation_queue(This, MUTATION_ENDLOAD, NULL);
559 }
560
561 static void NSAPI nsDocumentObserver_ContentStatesChanged(nsIDocumentObserver *iface, nsIDocument *aDocument,
562         nsIContent *aContent1, nsIContent *aContent2, PRInt32 aStateMask)
563 {
564 }
565
566 static void NSAPI nsDocumentObserver_DocumentStatesChanged(nsIDocumentObserver *iface, nsIDocument *aDocument,
567         PRInt32 aStateMask)
568 {
569 }
570
571 static void NSAPI nsDocumentObserver_StyleSheetAdded(nsIDocumentObserver *iface, nsIDocument *aDocument,
572         nsIStyleSheet *aStyleSheet, PRBool aDocumentSheet)
573 {
574 }
575
576 static void NSAPI nsDocumentObserver_StyleSheetRemoved(nsIDocumentObserver *iface, nsIDocument *aDocument,
577         nsIStyleSheet *aStyleSheet, PRBool aDocumentSheet)
578 {
579 }
580
581 static void NSAPI nsDocumentObserver_StyleSheetApplicableStateChanged(nsIDocumentObserver *iface,
582         nsIDocument *aDocument, nsIStyleSheet *aStyleSheet, PRBool aApplicable)
583 {
584 }
585
586 static void NSAPI nsDocumentObserver_StyleRuleChanged(nsIDocumentObserver *iface, nsIDocument *aDocument,
587         nsIStyleSheet *aStyleSheet, nsIStyleRule *aOldStyleRule, nsIStyleSheet *aNewStyleRule)
588 {
589 }
590
591 static void NSAPI nsDocumentObserver_StyleRuleAdded(nsIDocumentObserver *iface, nsIDocument *aDocument,
592         nsIStyleSheet *aStyleSheet, nsIStyleRule *aStyleRule)
593 {
594 }
595
596 static void NSAPI nsDocumentObserver_StyleRuleRemoved(nsIDocumentObserver *iface, nsIDocument *aDocument,
597         nsIStyleSheet *aStyleSheet, nsIStyleRule *aStyleRule)
598 {
599 }
600
601 static void NSAPI nsDocumentObserver_BindToDocument(nsIDocumentObserver *iface, nsIDocument *aDocument,
602         nsIContent *aContent)
603 {
604     HTMLDocumentNode *This = impl_from_nsIDocumentObserver(iface);
605     nsIDOMHTMLIFrameElement *nsiframe;
606     nsIDOMHTMLFrameElement *nsframe;
607     nsIDOMComment *nscomment;
608     nsIDOMElement *nselem;
609     nsresult nsres;
610
611     TRACE("(%p)\n", This);
612
613     nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMElement, (void**)&nselem);
614     if(NS_SUCCEEDED(nsres)) {
615         check_event_attr(This, nselem);
616         nsIDOMElement_Release(nselem);
617     }
618
619     nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMComment, (void**)&nscomment);
620     if(NS_SUCCEEDED(nsres)) {
621         TRACE("comment node\n");
622
623         push_mutation_queue(This, MUTATION_COMMENT, (nsISupports*)nscomment);
624         nsIDOMComment_Release(nscomment);
625     }
626
627     nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMHTMLIFrameElement, (void**)&nsiframe);
628     if(NS_SUCCEEDED(nsres)) {
629         TRACE("iframe node\n");
630
631         push_mutation_queue(This, MUTATION_BINDTOTREE, (nsISupports*)nsiframe);
632         nsIDOMHTMLIFrameElement_Release(nsiframe);
633     }
634
635     nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMHTMLFrameElement, (void**)&nsframe);
636     if(NS_SUCCEEDED(nsres)) {
637         TRACE("frame node\n");
638
639         push_mutation_queue(This, MUTATION_BINDTOTREE, (nsISupports*)nsframe);
640         nsIDOMHTMLFrameElement_Release(nsframe);
641     }
642 }
643
644 static void NSAPI nsDocumentObserver_DoneAddingChildren(nsIDocumentObserver *iface, nsIContent *aContent,
645         PRBool aHaveNotified)
646 {
647     HTMLDocumentNode *This = impl_from_nsIDocumentObserver(iface);
648     nsIDOMHTMLScriptElement *nsscript;
649     nsresult nsres;
650
651     TRACE("(%p)->(%p %x)\n", This, aContent, aHaveNotified);
652
653     nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMHTMLScriptElement, (void**)&nsscript);
654     if(NS_SUCCEEDED(nsres)) {
655         TRACE("script node\n");
656
657         push_mutation_queue(This, MUTATION_SCRIPT, (nsISupports*)nsscript);
658         nsIDOMHTMLScriptElement_Release(nsscript);
659     }
660 }
661
662 static const nsIDocumentObserverVtbl nsDocumentObserverVtbl = {
663     nsDocumentObserver_QueryInterface,
664     nsDocumentObserver_AddRef,
665     nsDocumentObserver_Release,
666     nsDocumentObserver_CharacterDataWillChange,
667     nsDocumentObserver_CharacterDataChanged,
668     nsDocumentObserver_AttributeWillChange,
669     nsDocumentObserver_AttributeChanged,
670     nsDocumentObserver_ContentAppended,
671     nsDocumentObserver_ContentInserted,
672     nsDocumentObserver_ContentRemoved,
673     nsDocumentObserver_NodeWillBeDestroyed,
674     nsDocumentObserver_ParentChainChanged,
675     nsDocumentObserver_BeginUpdate,
676     nsDocumentObserver_EndUpdate,
677     nsDocumentObserver_BeginLoad,
678     nsDocumentObserver_EndLoad,
679     nsDocumentObserver_ContentStatesChanged,
680     nsDocumentObserver_DocumentStatesChanged,
681     nsDocumentObserver_StyleSheetAdded,
682     nsDocumentObserver_StyleSheetRemoved,
683     nsDocumentObserver_StyleSheetApplicableStateChanged,
684     nsDocumentObserver_StyleRuleChanged,
685     nsDocumentObserver_StyleRuleAdded,
686     nsDocumentObserver_StyleRuleRemoved,
687     nsDocumentObserver_BindToDocument,
688     nsDocumentObserver_DoneAddingChildren
689 };
690
691 void init_mutation(HTMLDocumentNode *doc)
692 {
693     nsIDOMNSDocument *nsdoc;
694     nsresult nsres;
695
696     doc->nsIDocumentObserver_iface.lpVtbl = &nsDocumentObserverVtbl;
697     doc->nsIRunnable_iface.lpVtbl = &nsRunnableVtbl;
698
699     nsres = nsIDOMHTMLDocument_QueryInterface(doc->nsdoc, &IID_nsIDOMNSDocument, (void**)&nsdoc);
700     if(NS_FAILED(nsres)) {
701         ERR("Could not get nsIDOMNSDocument: %08x\n", nsres);
702         return;
703     }
704
705     nsIDOMNSDocument_WineAddObserver(nsdoc, &doc->nsIDocumentObserver_iface);
706     nsIDOMNSDocument_Release(nsdoc);
707 }
708
709 void release_mutation(HTMLDocumentNode *doc)
710 {
711     nsIDOMNSDocument *nsdoc;
712     nsresult nsres;
713
714     nsres = nsIDOMHTMLDocument_QueryInterface(doc->nsdoc, &IID_nsIDOMNSDocument, (void**)&nsdoc);
715     if(NS_FAILED(nsres)) {
716         ERR("Could not get nsIDOMNSDocument: %08x\n", nsres);
717         return;
718     }
719
720     nsIDOMNSDocument_WineRemoveObserver(nsdoc, &doc->nsIDocumentObserver_iface);
721     nsIDOMNSDocument_Release(nsdoc);
722 }