urlmon: Make protocol tests more verbose.
[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, NSRUNNABLE(This));
197     nsIDOMNSDocument_Release(nsdoc);
198 }
199
200 #define NSRUNNABLE_THIS(iface) DEFINE_THIS(HTMLDocumentNode, IRunnable, iface)
201
202 static nsresult NSAPI nsRunnable_QueryInterface(nsIRunnable *iface,
203         nsIIDRef riid, void **result)
204 {
205     HTMLDocumentNode *This = NSRUNNABLE_THIS(iface);
206
207     if(IsEqualGUID(riid, &IID_nsISupports)) {
208         TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
209         *result = NSRUNNABLE(This);
210     }else if(IsEqualGUID(riid, &IID_nsIRunnable)) {
211         TRACE("(%p)->(IID_nsIRunnable %p)\n", This, result);
212         *result = NSRUNNABLE(This);
213     }else {
214         *result = NULL;
215         WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
216         return NS_NOINTERFACE;
217     }
218
219     nsISupports_AddRef((nsISupports*)*result);
220     return NS_OK;
221 }
222
223 static nsrefcnt NSAPI nsRunnable_AddRef(nsIRunnable *iface)
224 {
225     HTMLDocumentNode *This = NSRUNNABLE_THIS(iface);
226     return htmldoc_addref(&This->basedoc);
227 }
228
229 static nsrefcnt NSAPI nsRunnable_Release(nsIRunnable *iface)
230 {
231     HTMLDocumentNode *This = NSRUNNABLE_THIS(iface);
232     return htmldoc_release(&This->basedoc);
233 }
234
235 static void push_mutation_queue(HTMLDocumentNode *doc, DWORD type, nsISupports *nsiface)
236 {
237     mutation_queue_t *elem;
238
239     elem = heap_alloc(sizeof(mutation_queue_t));
240     if(!elem)
241         return;
242
243     elem->next = NULL;
244     elem->type = type;
245     elem->nsiface = nsiface;
246     if(nsiface)
247         nsISupports_AddRef(nsiface);
248
249     if(doc->mutation_queue_tail) {
250         doc->mutation_queue_tail = doc->mutation_queue_tail->next = elem;
251     }else {
252         doc->mutation_queue = doc->mutation_queue_tail = elem;
253         add_script_runner(doc);
254     }
255 }
256
257 static void pop_mutation_queue(HTMLDocumentNode *doc)
258 {
259     mutation_queue_t *tmp = doc->mutation_queue;
260
261     if(!tmp)
262         return;
263
264     doc->mutation_queue = tmp->next;
265     if(!tmp->next)
266         doc->mutation_queue_tail = NULL;
267
268     if(tmp->nsiface)
269         nsISupports_Release(tmp->nsiface);
270     heap_free(tmp);
271 }
272
273 static void bind_to_tree(HTMLDocumentNode *doc, nsISupports *nsiface)
274 {
275     nsIDOMNode *nsnode;
276     HTMLDOMNode *node;
277     nsresult nsres;
278     HRESULT hres;
279
280     nsres = nsISupports_QueryInterface(nsiface, &IID_nsIDOMNode, (void**)&nsnode);
281     if(NS_FAILED(nsres))
282         return;
283
284     hres = get_node(doc, nsnode, TRUE, &node);
285     nsIDOMNode_Release(nsnode);
286     if(FAILED(hres)) {
287         ERR("Could not get node\n");
288         return;
289     }
290
291     if(node->vtbl->bind_to_tree)
292         node->vtbl->bind_to_tree(node);
293 }
294
295 /* Calls undocumented 69 cmd of CGID_Explorer */
296 static void call_explorer_69(HTMLDocumentObj *doc)
297 {
298     IOleCommandTarget *olecmd;
299     VARIANT var;
300     HRESULT hres;
301
302     if(!doc->client)
303         return;
304
305     hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
306     if(FAILED(hres))
307         return;
308
309     VariantInit(&var);
310     hres = IOleCommandTarget_Exec(olecmd, &CGID_Explorer, 69, 0, NULL, &var);
311     IOleCommandTarget_Release(olecmd);
312     if(SUCCEEDED(hres) && V_VT(&var) != VT_NULL)
313         FIXME("handle result\n");
314 }
315
316 static void parse_complete(HTMLDocumentObj *doc)
317 {
318     TRACE("(%p)\n", doc);
319
320     if(doc->usermode == EDITMODE)
321         init_editor(&doc->basedoc);
322
323     call_explorer_69(doc);
324     if(doc->view_sink)
325         IAdviseSink_OnViewChange(doc->view_sink, DVASPECT_CONTENT, -1);
326     call_property_onchanged(&doc->basedoc.cp_propnotif, 1005);
327     call_explorer_69(doc);
328
329     /* FIXME: IE7 calls EnableModelless(TRUE), EnableModelless(FALSE) and sets interactive state here */
330 }
331
332 static void handle_end_load(HTMLDocumentNode *This)
333 {
334     TRACE("\n");
335
336     if(!This->basedoc.doc_obj)
337         return;
338
339     if(This == This->basedoc.doc_obj->basedoc.doc_node) {
340         /*
341          * This should be done in the worker thread that parses HTML,
342          * but we don't have such thread (Gecko parses HTML for us).
343          */
344         parse_complete(This->basedoc.doc_obj);
345     }
346
347     set_ready_state(This->basedoc.window, READYSTATE_INTERACTIVE);
348 }
349
350 static nsresult NSAPI nsRunnable_Run(nsIRunnable *iface)
351 {
352     HTMLDocumentNode *This = NSRUNNABLE_THIS(iface);
353     nsresult nsres;
354
355     TRACE("(%p)\n", This);
356
357     while(This->mutation_queue) {
358         switch(This->mutation_queue->type) {
359         case MUTATION_BINDTOTREE:
360             bind_to_tree(This, This->mutation_queue->nsiface);
361             break;
362
363         case MUTATION_COMMENT: {
364             nsIDOMComment *nscomment;
365             nsAString comment_str;
366             BOOL remove_comment = FALSE;
367
368             nsres = nsISupports_QueryInterface(This->mutation_queue->nsiface, &IID_nsIDOMComment, (void**)&nscomment);
369             if(NS_FAILED(nsres)) {
370                 ERR("Could not get nsIDOMComment iface:%08x\n", nsres);
371                 return NS_OK;
372             }
373
374             nsAString_Init(&comment_str, NULL);
375             nsres = nsIDOMComment_GetData(nscomment, &comment_str);
376             if(NS_SUCCEEDED(nsres)) {
377                 const PRUnichar *comment;
378
379                 nsAString_GetData(&comment_str, &comment);
380                 remove_comment = handle_insert_comment(This, comment);
381             }
382
383             nsAString_Finish(&comment_str);
384
385             if(remove_comment) {
386                 nsIDOMNode *nsparent, *tmp;
387                 nsAString magic_str;
388
389                 static const PRUnichar remove_comment_magicW[] =
390                     {'#','!','w','i','n','e', 'r','e','m','o','v','e','!','#',0};
391
392                 nsAString_InitDepend(&magic_str, remove_comment_magicW);
393                 nsres = nsIDOMComment_SetData(nscomment, &magic_str);
394                 nsAString_Finish(&magic_str);
395                 if(NS_FAILED(nsres))
396                     ERR("SetData failed: %08x\n", nsres);
397
398                 nsIDOMComment_GetParentNode(nscomment, &nsparent);
399                 if(nsparent) {
400                     nsIDOMNode_RemoveChild(nsparent, (nsIDOMNode*)nscomment, &tmp);
401                     nsIDOMNode_Release(nsparent);
402                     nsIDOMNode_Release(tmp);
403                 }
404             }
405
406             nsIDOMComment_Release(nscomment);
407             break;
408         }
409
410         case MUTATION_ENDLOAD:
411             handle_end_load(This);
412             break;
413
414         case MUTATION_SCRIPT: {
415             nsIDOMHTMLScriptElement *nsscript;
416
417             nsres = nsISupports_QueryInterface(This->mutation_queue->nsiface, &IID_nsIDOMHTMLScriptElement,
418                                                (void**)&nsscript);
419             if(NS_FAILED(nsres)) {
420                 ERR("Could not get nsIDOMHTMLScriptElement: %08x\n", nsres);
421                 break;
422             }
423
424             doc_insert_script(This->basedoc.window, nsscript);
425             nsIDOMHTMLScriptElement_Release(nsscript);
426             break;
427         }
428
429         default:
430             ERR("invalid type %d\n", This->mutation_queue->type);
431         }
432
433         pop_mutation_queue(This);
434     }
435
436     return S_OK;
437 }
438
439 #undef NSRUNNABLE_THIS
440
441 static const nsIRunnableVtbl nsRunnableVtbl = {
442     nsRunnable_QueryInterface,
443     nsRunnable_AddRef,
444     nsRunnable_Release,
445     nsRunnable_Run
446 };
447
448 #define NSDOCOBS_THIS(iface) DEFINE_THIS(HTMLDocumentNode, IDocumentObserver, iface)
449
450 static nsresult NSAPI nsDocumentObserver_QueryInterface(nsIDocumentObserver *iface,
451         nsIIDRef riid, void **result)
452 {
453     HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
454
455     if(IsEqualGUID(&IID_nsISupports, riid)) {
456         TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
457         *result = NSDOCOBS(This);
458     }else if(IsEqualGUID(&IID_nsIMutationObserver, riid)) {
459         TRACE("(%p)->(IID_nsIMutationObserver %p)\n", This, result);
460         *result = NSDOCOBS(This);
461     }else if(IsEqualGUID(&IID_nsIDocumentObserver, riid)) {
462         TRACE("(%p)->(IID_nsIDocumentObserver %p)\n", This, result);
463         *result = NSDOCOBS(This);
464     }else {
465         *result = NULL;
466         TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
467         return NS_NOINTERFACE;
468     }
469
470     htmldoc_addref(&This->basedoc);
471     return NS_OK;
472 }
473
474 static nsrefcnt NSAPI nsDocumentObserver_AddRef(nsIDocumentObserver *iface)
475 {
476     HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
477     return htmldoc_addref(&This->basedoc);
478 }
479
480 static nsrefcnt NSAPI nsDocumentObserver_Release(nsIDocumentObserver *iface)
481 {
482     HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
483     return htmldoc_release(&This->basedoc);
484 }
485
486 static void NSAPI nsDocumentObserver_CharacterDataWillChange(nsIDocumentObserver *iface,
487         nsIDocument *aDocument, nsIContent *aContent, void /*CharacterDataChangeInfo*/ *aInfo)
488 {
489 }
490
491 static void NSAPI nsDocumentObserver_CharacterDataChanged(nsIDocumentObserver *iface,
492         nsIDocument *aDocument, nsIContent *aContent, void /*CharacterDataChangeInfo*/ *aInfo)
493 {
494 }
495
496 static void NSAPI nsDocumentObserver_AttributeWillChange(nsIDocumentObserver *iface, nsIDocument *aDocument,
497         nsIContent *aContent, PRInt32 aNameSpaceID, nsIAtom *aAttribute, PRInt32 aModType)
498 {
499 }
500
501 static void NSAPI nsDocumentObserver_AttributeChanged(nsIDocumentObserver *iface, nsIDocument *aDocument,
502         nsIContent *aContent, PRInt32 aNameSpaceID, nsIAtom *aAttribute, PRInt32 aModType)
503 {
504 }
505
506 static void NSAPI nsDocumentObserver_ContentAppended(nsIDocumentObserver *iface, nsIDocument *aDocument,
507         nsIContent *aContainer, nsIContent *aFirstNewContent, PRInt32 aNewIndexInContainer)
508 {
509 }
510
511 static void NSAPI nsDocumentObserver_ContentInserted(nsIDocumentObserver *iface, nsIDocument *aDocument,
512         nsIContent *aContainer, nsIContent *aChild, PRInt32 aIndexInContainer)
513 {
514 }
515
516 static void NSAPI nsDocumentObserver_ContentRemoved(nsIDocumentObserver *iface, nsIDocument *aDocument,
517         nsIContent *aContainer, nsIContent *aChild, PRInt32 aIndexInContainer,
518         nsIContent *aProviousSibling)
519 {
520 }
521
522 static void NSAPI nsDocumentObserver_NodeWillBeDestroyed(nsIDocumentObserver *iface, const nsINode *aNode)
523 {
524 }
525
526 static void NSAPI nsDocumentObserver_ParentChainChanged(nsIDocumentObserver *iface, nsIContent *aContent)
527 {
528 }
529
530 static void NSAPI nsDocumentObserver_BeginUpdate(nsIDocumentObserver *iface, nsIDocument *aDocument,
531         nsUpdateType aUpdateType)
532 {
533 }
534
535 static void NSAPI nsDocumentObserver_EndUpdate(nsIDocumentObserver *iface, nsIDocument *aDocument,
536         nsUpdateType aUpdateType)
537 {
538 }
539
540 static void NSAPI nsDocumentObserver_BeginLoad(nsIDocumentObserver *iface, nsIDocument *aDocument)
541 {
542 }
543
544 static void NSAPI nsDocumentObserver_EndLoad(nsIDocumentObserver *iface, nsIDocument *aDocument)
545 {
546     HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
547
548     TRACE("\n");
549
550     if(This->skip_mutation_notif)
551         return;
552
553     This->content_ready = TRUE;
554     push_mutation_queue(This, MUTATION_ENDLOAD, NULL);
555 }
556
557 static void NSAPI nsDocumentObserver_ContentStatesChanged(nsIDocumentObserver *iface, nsIDocument *aDocument,
558         nsIContent *aContent1, nsIContent *aContent2, PRInt32 aStateMask)
559 {
560 }
561
562 static void NSAPI nsDocumentObserver_DocumentStatesChanged(nsIDocumentObserver *iface, nsIDocument *aDocument,
563         PRInt32 aStateMask)
564 {
565 }
566
567 static void NSAPI nsDocumentObserver_StyleSheetAdded(nsIDocumentObserver *iface, nsIDocument *aDocument,
568         nsIStyleSheet *aStyleSheet, PRBool aDocumentSheet)
569 {
570 }
571
572 static void NSAPI nsDocumentObserver_StyleSheetRemoved(nsIDocumentObserver *iface, nsIDocument *aDocument,
573         nsIStyleSheet *aStyleSheet, PRBool aDocumentSheet)
574 {
575 }
576
577 static void NSAPI nsDocumentObserver_StyleSheetApplicableStateChanged(nsIDocumentObserver *iface,
578         nsIDocument *aDocument, nsIStyleSheet *aStyleSheet, PRBool aApplicable)
579 {
580 }
581
582 static void NSAPI nsDocumentObserver_StyleRuleChanged(nsIDocumentObserver *iface, nsIDocument *aDocument,
583         nsIStyleSheet *aStyleSheet, nsIStyleRule *aOldStyleRule, nsIStyleSheet *aNewStyleRule)
584 {
585 }
586
587 static void NSAPI nsDocumentObserver_StyleRuleAdded(nsIDocumentObserver *iface, nsIDocument *aDocument,
588         nsIStyleSheet *aStyleSheet, nsIStyleRule *aStyleRule)
589 {
590 }
591
592 static void NSAPI nsDocumentObserver_StyleRuleRemoved(nsIDocumentObserver *iface, nsIDocument *aDocument,
593         nsIStyleSheet *aStyleSheet, nsIStyleRule *aStyleRule)
594 {
595 }
596
597 static void NSAPI nsDocumentObserver_BindToDocument(nsIDocumentObserver *iface, nsIDocument *aDocument,
598         nsIContent *aContent)
599 {
600     HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
601     nsIDOMHTMLIFrameElement *nsiframe;
602     nsIDOMHTMLFrameElement *nsframe;
603     nsIDOMComment *nscomment;
604     nsIDOMElement *nselem;
605     nsresult nsres;
606
607     TRACE("(%p)\n", This);
608
609     nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMElement, (void**)&nselem);
610     if(NS_SUCCEEDED(nsres)) {
611         check_event_attr(This, nselem);
612         nsIDOMElement_Release(nselem);
613     }
614
615     nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMComment, (void**)&nscomment);
616     if(NS_SUCCEEDED(nsres)) {
617         TRACE("comment node\n");
618
619         push_mutation_queue(This, MUTATION_COMMENT, (nsISupports*)nscomment);
620         nsIDOMComment_Release(nscomment);
621     }
622
623     nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMHTMLIFrameElement, (void**)&nsiframe);
624     if(NS_SUCCEEDED(nsres)) {
625         TRACE("iframe node\n");
626
627         push_mutation_queue(This, MUTATION_BINDTOTREE, (nsISupports*)nsiframe);
628         nsIDOMHTMLIFrameElement_Release(nsiframe);
629     }
630
631     nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMHTMLFrameElement, (void**)&nsframe);
632     if(NS_SUCCEEDED(nsres)) {
633         TRACE("frame node\n");
634
635         push_mutation_queue(This, MUTATION_BINDTOTREE, (nsISupports*)nsframe);
636         nsIDOMHTMLFrameElement_Release(nsframe);
637     }
638 }
639
640 static void NSAPI nsDocumentObserver_DoneAddingChildren(nsIDocumentObserver *iface, nsIContent *aContent,
641         PRBool aHaveNotified)
642 {
643     HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
644     nsIDOMHTMLScriptElement *nsscript;
645     nsresult nsres;
646
647     TRACE("(%p)->(%p %x)\n", This, aContent, aHaveNotified);
648
649     nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMHTMLScriptElement, (void**)&nsscript);
650     if(NS_SUCCEEDED(nsres)) {
651         TRACE("script node\n");
652
653         push_mutation_queue(This, MUTATION_SCRIPT, (nsISupports*)nsscript);
654         nsIDOMHTMLScriptElement_Release(nsscript);
655     }
656 }
657
658 #undef NSMUTATIONOBS_THIS
659
660 static const nsIDocumentObserverVtbl nsDocumentObserverVtbl = {
661     nsDocumentObserver_QueryInterface,
662     nsDocumentObserver_AddRef,
663     nsDocumentObserver_Release,
664     nsDocumentObserver_CharacterDataWillChange,
665     nsDocumentObserver_CharacterDataChanged,
666     nsDocumentObserver_AttributeWillChange,
667     nsDocumentObserver_AttributeChanged,
668     nsDocumentObserver_ContentAppended,
669     nsDocumentObserver_ContentInserted,
670     nsDocumentObserver_ContentRemoved,
671     nsDocumentObserver_NodeWillBeDestroyed,
672     nsDocumentObserver_ParentChainChanged,
673     nsDocumentObserver_BeginUpdate,
674     nsDocumentObserver_EndUpdate,
675     nsDocumentObserver_BeginLoad,
676     nsDocumentObserver_EndLoad,
677     nsDocumentObserver_ContentStatesChanged,
678     nsDocumentObserver_DocumentStatesChanged,
679     nsDocumentObserver_StyleSheetAdded,
680     nsDocumentObserver_StyleSheetRemoved,
681     nsDocumentObserver_StyleSheetApplicableStateChanged,
682     nsDocumentObserver_StyleRuleChanged,
683     nsDocumentObserver_StyleRuleAdded,
684     nsDocumentObserver_StyleRuleRemoved,
685     nsDocumentObserver_BindToDocument,
686     nsDocumentObserver_DoneAddingChildren
687 };
688
689 void init_mutation(HTMLDocumentNode *doc)
690 {
691     nsIDOMNSDocument *nsdoc;
692     nsresult nsres;
693
694     doc->lpIDocumentObserverVtbl  = &nsDocumentObserverVtbl;
695     doc->lpIRunnableVtbl          = &nsRunnableVtbl;
696
697     nsres = nsIDOMHTMLDocument_QueryInterface(doc->nsdoc, &IID_nsIDOMNSDocument, (void**)&nsdoc);
698     if(NS_FAILED(nsres)) {
699         ERR("Could not get nsIDOMNSDocument: %08x\n", nsres);
700         return;
701     }
702
703     nsIDOMNSDocument_WineAddObserver(nsdoc, NSDOCOBS(doc));
704     nsIDOMNSDocument_Release(nsdoc);
705 }
706
707 void release_mutation(HTMLDocumentNode *doc)
708 {
709     nsIDOMNSDocument *nsdoc;
710     nsresult nsres;
711
712     nsres = nsIDOMHTMLDocument_QueryInterface(doc->nsdoc, &IID_nsIDOMNSDocument, (void**)&nsdoc);
713     if(NS_FAILED(nsres)) {
714         ERR("Could not get nsIDOMNSDocument: %08x\n", nsres);
715         return;
716     }
717
718     nsIDOMNSDocument_WineRemoveObserver(nsdoc, NSDOCOBS(doc));
719     nsIDOMNSDocument_Release(nsdoc);
720 }