2 * Copyright 2008 Jacek Caban for CodeWeavers
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.
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.
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
32 #include "mshtml_private.h"
33 #include "htmlscript.h"
34 #include "htmlevent.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
41 #define IE_MAJOR_VERSION 7
42 #define IE_MINOR_VERSION 0
44 static const IID NS_ICONTENTUTILS_CID
=
45 {0x762C4AE7,0xB923,0x422F,{0xB9,0x7E,0xB9,0xBF,0xC1,0xEF,0x7B,0xF0}};
47 static nsIContentUtils
*content_utils
;
49 static PRUnichar
*handle_insert_comment(HTMLDocumentNode
*doc
, const PRUnichar
*comment
)
51 int majorv
= 0, minorv
= 0;
52 const PRUnichar
*ptr
, *end
;
64 static const PRUnichar endifW
[] = {'<','!','[','e','n','d','i','f',']'};
66 if(comment
[0] != '[' || comment
[1] != 'i' || comment
[2] != 'f')
73 if(ptr
[0] == 'l' && ptr
[1] == 't') {
81 }else if(ptr
[0] == 'g' && ptr
[1] == 't') {
96 if(ptr
[0] != 'I' || ptr
[1] != 'E')
100 if(!isspaceW(*ptr
++))
102 while(isspaceW(*ptr
))
107 while(isdigitW(*ptr
))
108 majorv
= majorv
*10 + (*ptr
++ - '0');
114 while(isdigitW(*ptr
))
115 minorv
= minorv
*10 + (*ptr
++ - '0');
118 while(isspaceW(*ptr
))
120 if(ptr
[0] != ']' || ptr
[1] != '>')
125 if(len
< sizeof(endifW
)/sizeof(WCHAR
))
128 end
= ptr
+ len
-sizeof(endifW
)/sizeof(WCHAR
);
129 if(memcmp(end
, endifW
, sizeof(endifW
)))
134 if(majorv
== IE_MAJOR_VERSION
&& minorv
== IE_MINOR_VERSION
)
138 if(majorv
> IE_MAJOR_VERSION
)
140 if(majorv
== IE_MAJOR_VERSION
&& minorv
> IE_MINOR_VERSION
)
144 if(majorv
> IE_MAJOR_VERSION
)
146 if(majorv
== IE_MAJOR_VERSION
&& minorv
>= IE_MINOR_VERSION
)
150 if(majorv
< IE_MAJOR_VERSION
)
152 if(majorv
== IE_MAJOR_VERSION
&& minorv
< IE_MINOR_VERSION
)
156 if(majorv
< IE_MAJOR_VERSION
)
158 if(majorv
== IE_MAJOR_VERSION
&& minorv
<= IE_MINOR_VERSION
)
163 buf
= heap_alloc((end
-ptr
+1)*sizeof(WCHAR
));
167 memcpy(buf
, ptr
, (end
-ptr
)*sizeof(WCHAR
));
173 static nsresult
run_insert_comment(HTMLDocumentNode
*doc
, nsISupports
*comment_iface
, nsISupports
*arg2
)
175 const PRUnichar
*comment
;
176 nsIDOMComment
*nscomment
;
177 PRUnichar
*replace_html
;
178 nsAString comment_str
;
181 nsres
= nsISupports_QueryInterface(comment_iface
, &IID_nsIDOMComment
, (void**)&nscomment
);
182 if(NS_FAILED(nsres
)) {
183 ERR("Could not get nsIDOMComment iface:%08x\n", nsres
);
187 nsAString_Init(&comment_str
, NULL
);
188 nsres
= nsIDOMComment_GetData(nscomment
, &comment_str
);
192 nsAString_GetData(&comment_str
, &comment
);
193 replace_html
= handle_insert_comment(doc
, comment
);
194 nsAString_Finish(&comment_str
);
199 hres
= replace_node_by_html(doc
->nsdoc
, (nsIDOMNode
*)nscomment
, replace_html
);
200 heap_free(replace_html
);
202 nsres
= NS_ERROR_FAILURE
;
206 nsIDOMComment_Release(nscomment
);
210 static nsresult
run_bind_to_tree(HTMLDocumentNode
*doc
, nsISupports
*nsiface
, nsISupports
*arg2
)
217 TRACE("(%p)->(%p)\n", doc
, nsiface
);
219 nsres
= nsISupports_QueryInterface(nsiface
, &IID_nsIDOMNode
, (void**)&nsnode
);
223 hres
= get_node(doc
, nsnode
, TRUE
, &node
);
224 nsIDOMNode_Release(nsnode
);
226 ERR("Could not get node\n");
230 if(node
->vtbl
->bind_to_tree
)
231 node
->vtbl
->bind_to_tree(node
);
237 /* Calls undocumented 69 cmd of CGID_Explorer */
238 static void call_explorer_69(HTMLDocumentObj
*doc
)
240 IOleCommandTarget
*olecmd
;
247 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&olecmd
);
252 hres
= IOleCommandTarget_Exec(olecmd
, &CGID_Explorer
, 69, 0, NULL
, &var
);
253 IOleCommandTarget_Release(olecmd
);
254 if(SUCCEEDED(hres
) && V_VT(&var
) != VT_NULL
)
255 FIXME("handle result\n");
258 static void parse_complete(HTMLDocumentObj
*doc
)
260 TRACE("(%p)\n", doc
);
262 if(doc
->usermode
== EDITMODE
)
263 init_editor(&doc
->basedoc
);
265 call_explorer_69(doc
);
267 IAdviseSink_OnViewChange(doc
->view_sink
, DVASPECT_CONTENT
, -1);
268 call_property_onchanged(&doc
->basedoc
.cp_propnotif
, 1005);
269 call_explorer_69(doc
);
271 if(doc
->is_webbrowser
&& doc
->usermode
!= EDITMODE
&& !(doc
->basedoc
.window
->load_flags
& BINDING_REFRESH
))
272 IDocObjectService_FireNavigateComplete2(doc
->doc_object_service
, &doc
->basedoc
.window
->base
.IHTMLWindow2_iface
, 0);
274 /* FIXME: IE7 calls EnableModelless(TRUE), EnableModelless(FALSE) and sets interactive state here */
277 static nsresult
run_end_load(HTMLDocumentNode
*This
, nsISupports
*arg1
, nsISupports
*arg2
)
279 TRACE("(%p)\n", This
);
281 if(!This
->basedoc
.doc_obj
)
284 if(This
== This
->basedoc
.doc_obj
->basedoc
.doc_node
) {
286 * This should be done in the worker thread that parses HTML,
287 * but we don't have such thread (Gecko parses HTML for us).
289 parse_complete(This
->basedoc
.doc_obj
);
292 bind_event_scripts(This
);
293 set_ready_state(This
->basedoc
.window
, READYSTATE_INTERACTIVE
);
297 static nsresult
run_insert_script(HTMLDocumentNode
*doc
, nsISupports
*script_iface
, nsISupports
*parser_iface
)
299 nsIDOMHTMLScriptElement
*nsscript
;
300 HTMLScriptElement
*script_elem
;
301 nsIParser
*nsparser
= NULL
;
302 script_queue_entry_t
*iter
;
303 HTMLInnerWindow
*window
;
307 TRACE("(%p)->(%p)\n", doc
, script_iface
);
309 window
= doc
->window
;
313 nsres
= nsISupports_QueryInterface(script_iface
, &IID_nsIDOMHTMLScriptElement
, (void**)&nsscript
);
314 if(NS_FAILED(nsres
)) {
315 ERR("Could not get nsIDOMHTMLScriptElement: %08x\n", nsres
);
320 nsres
= nsISupports_QueryInterface(parser_iface
, &IID_nsIParser
, (void**)&nsparser
);
321 if(NS_FAILED(nsres
)) {
322 ERR("Could not get nsIParser iface: %08x\n", nsres
);
327 hres
= script_elem_from_nsscript(doc
, nsscript
, &script_elem
);
328 nsIDOMHTMLScriptElement_Release(nsscript
);
330 return NS_ERROR_FAILURE
;
333 nsIParser_BeginEvaluatingParserInsertedScript(nsparser
);
334 window
->parser_callback_cnt
++;
337 IHTMLWindow2_AddRef(&window
->base
.IHTMLWindow2_iface
);
339 doc_insert_script(window
, script_elem
);
341 while(!list_empty(&window
->script_queue
)) {
342 iter
= LIST_ENTRY(list_head(&window
->script_queue
), script_queue_entry_t
, entry
);
343 list_remove(&iter
->entry
);
344 doc_insert_script(window
, iter
->script
);
345 IHTMLScriptElement_Release(&iter
->script
->IHTMLScriptElement_iface
);
349 IHTMLWindow2_Release(&window
->base
.IHTMLWindow2_iface
);
352 window
->parser_callback_cnt
--;
353 nsIParser_EndEvaluatingParserInsertedScript(nsparser
);
354 nsIParser_Release(nsparser
);
357 IHTMLScriptElement_Release(&script_elem
->IHTMLScriptElement_iface
);
362 typedef struct nsRunnable nsRunnable
;
364 typedef nsresult (*runnable_proc_t
)(HTMLDocumentNode
*,nsISupports
*,nsISupports
*);
367 nsIRunnable nsIRunnable_iface
;
371 runnable_proc_t proc
;
373 HTMLDocumentNode
*doc
;
378 static inline nsRunnable
*impl_from_nsIRunnable(nsIRunnable
*iface
)
380 return CONTAINING_RECORD(iface
, nsRunnable
, nsIRunnable_iface
);
383 static nsresult NSAPI
nsRunnable_QueryInterface(nsIRunnable
*iface
,
384 nsIIDRef riid
, void **result
)
386 nsRunnable
*This
= impl_from_nsIRunnable(iface
);
388 if(IsEqualGUID(riid
, &IID_nsISupports
)) {
389 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
390 *result
= &This
->nsIRunnable_iface
;
391 }else if(IsEqualGUID(riid
, &IID_nsIRunnable
)) {
392 TRACE("(%p)->(IID_nsIRunnable %p)\n", This
, result
);
393 *result
= &This
->nsIRunnable_iface
;
396 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
397 return NS_NOINTERFACE
;
400 nsISupports_AddRef((nsISupports
*)*result
);
404 static nsrefcnt NSAPI
nsRunnable_AddRef(nsIRunnable
*iface
)
406 nsRunnable
*This
= impl_from_nsIRunnable(iface
);
407 LONG ref
= InterlockedIncrement(&This
->ref
);
409 TRACE("(%p) ref=%d\n", This
, ref
);
414 static nsrefcnt NSAPI
nsRunnable_Release(nsIRunnable
*iface
)
416 nsRunnable
*This
= impl_from_nsIRunnable(iface
);
417 LONG ref
= InterlockedDecrement(&This
->ref
);
419 TRACE("(%p) ref=%d\n", This
, ref
);
422 htmldoc_release(&This
->doc
->basedoc
);
424 nsISupports_Release(This
->arg1
);
426 nsISupports_Release(This
->arg2
);
433 static nsresult NSAPI
nsRunnable_Run(nsIRunnable
*iface
)
435 nsRunnable
*This
= impl_from_nsIRunnable(iface
);
437 return This
->proc(This
->doc
, This
->arg1
, This
->arg2
);
440 static const nsIRunnableVtbl nsRunnableVtbl
= {
441 nsRunnable_QueryInterface
,
447 static void add_script_runner(HTMLDocumentNode
*This
, runnable_proc_t proc
, nsISupports
*arg1
, nsISupports
*arg2
)
449 nsRunnable
*runnable
;
451 runnable
= heap_alloc_zero(sizeof(*runnable
));
455 runnable
->nsIRunnable_iface
.lpVtbl
= &nsRunnableVtbl
;
458 htmldoc_addref(&This
->basedoc
);
459 runnable
->doc
= This
;
460 runnable
->proc
= proc
;
463 nsISupports_AddRef(arg1
);
464 runnable
->arg1
= arg1
;
467 nsISupports_AddRef(arg2
);
468 runnable
->arg2
= arg2
;
470 nsIContentUtils_AddScriptRunner(content_utils
, &runnable
->nsIRunnable_iface
);
472 nsIRunnable_Release(&runnable
->nsIRunnable_iface
);
475 static inline HTMLDocumentNode
*impl_from_nsIDocumentObserver(nsIDocumentObserver
*iface
)
477 return CONTAINING_RECORD(iface
, HTMLDocumentNode
, nsIDocumentObserver_iface
);
480 static nsresult NSAPI
nsDocumentObserver_QueryInterface(nsIDocumentObserver
*iface
,
481 nsIIDRef riid
, void **result
)
483 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
485 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
486 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
487 *result
= &This
->nsIDocumentObserver_iface
;
488 }else if(IsEqualGUID(&IID_nsIMutationObserver
, riid
)) {
489 TRACE("(%p)->(IID_nsIMutationObserver %p)\n", This
, result
);
490 *result
= &This
->nsIDocumentObserver_iface
;
491 }else if(IsEqualGUID(&IID_nsIDocumentObserver
, riid
)) {
492 TRACE("(%p)->(IID_nsIDocumentObserver %p)\n", This
, result
);
493 *result
= &This
->nsIDocumentObserver_iface
;
496 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
497 return NS_NOINTERFACE
;
500 htmldoc_addref(&This
->basedoc
);
504 static nsrefcnt NSAPI
nsDocumentObserver_AddRef(nsIDocumentObserver
*iface
)
506 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
507 return htmldoc_addref(&This
->basedoc
);
510 static nsrefcnt NSAPI
nsDocumentObserver_Release(nsIDocumentObserver
*iface
)
512 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
513 return htmldoc_release(&This
->basedoc
);
516 static void NSAPI
nsDocumentObserver_CharacterDataWillChange(nsIDocumentObserver
*iface
,
517 nsIDocument
*aDocument
, nsIContent
*aContent
, void /*CharacterDataChangeInfo*/ *aInfo
)
521 static void NSAPI
nsDocumentObserver_CharacterDataChanged(nsIDocumentObserver
*iface
,
522 nsIDocument
*aDocument
, nsIContent
*aContent
, void /*CharacterDataChangeInfo*/ *aInfo
)
526 static void NSAPI
nsDocumentObserver_AttributeWillChange(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
527 nsIContent
*aContent
, PRInt32 aNameSpaceID
, nsIAtom
*aAttribute
, PRInt32 aModType
)
531 static void NSAPI
nsDocumentObserver_AttributeChanged(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
532 nsIContent
*aContent
, PRInt32 aNameSpaceID
, nsIAtom
*aAttribute
, PRInt32 aModType
)
536 static void NSAPI
nsDocumentObserver_ContentAppended(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
537 nsIContent
*aContainer
, nsIContent
*aFirstNewContent
, PRInt32 aNewIndexInContainer
)
541 static void NSAPI
nsDocumentObserver_ContentInserted(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
542 nsIContent
*aContainer
, nsIContent
*aChild
, PRInt32 aIndexInContainer
)
546 static void NSAPI
nsDocumentObserver_ContentRemoved(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
547 nsIContent
*aContainer
, nsIContent
*aChild
, PRInt32 aIndexInContainer
,
548 nsIContent
*aProviousSibling
)
552 static void NSAPI
nsDocumentObserver_NodeWillBeDestroyed(nsIDocumentObserver
*iface
, const nsINode
*aNode
)
556 static void NSAPI
nsDocumentObserver_ParentChainChanged(nsIDocumentObserver
*iface
, nsIContent
*aContent
)
560 static void NSAPI
nsDocumentObserver_BeginUpdate(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
561 nsUpdateType aUpdateType
)
565 static void NSAPI
nsDocumentObserver_EndUpdate(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
566 nsUpdateType aUpdateType
)
570 static void NSAPI
nsDocumentObserver_BeginLoad(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
)
574 static void NSAPI
nsDocumentObserver_EndLoad(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
)
576 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
578 TRACE("(%p)\n", This
);
580 if(This
->skip_mutation_notif
)
583 This
->content_ready
= TRUE
;
584 add_script_runner(This
, run_end_load
, NULL
, NULL
);
587 static void NSAPI
nsDocumentObserver_ContentStatesChanged(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
588 nsIContent
*aContent
, nsEventStates
*aStateMask
)
592 static void NSAPI
nsDocumentObserver_DocumentStatesChanged(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
593 nsEventStates
*aStateMask
)
597 static void NSAPI
nsDocumentObserver_StyleSheetAdded(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
598 nsIStyleSheet
*aStyleSheet
, cpp_bool aDocumentSheet
)
602 static void NSAPI
nsDocumentObserver_StyleSheetRemoved(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
603 nsIStyleSheet
*aStyleSheet
, cpp_bool aDocumentSheet
)
607 static void NSAPI
nsDocumentObserver_StyleSheetApplicableStateChanged(nsIDocumentObserver
*iface
,
608 nsIDocument
*aDocument
, nsIStyleSheet
*aStyleSheet
, cpp_bool aApplicable
)
612 static void NSAPI
nsDocumentObserver_StyleRuleChanged(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
613 nsIStyleSheet
*aStyleSheet
, nsIStyleRule
*aOldStyleRule
, nsIStyleSheet
*aNewStyleRule
)
617 static void NSAPI
nsDocumentObserver_StyleRuleAdded(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
618 nsIStyleSheet
*aStyleSheet
, nsIStyleRule
*aStyleRule
)
622 static void NSAPI
nsDocumentObserver_StyleRuleRemoved(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
623 nsIStyleSheet
*aStyleSheet
, nsIStyleRule
*aStyleRule
)
627 static void NSAPI
nsDocumentObserver_BindToDocument(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
628 nsIContent
*aContent
)
630 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
631 nsIDOMHTMLIFrameElement
*nsiframe
;
632 nsIDOMHTMLFrameElement
*nsframe
;
633 nsIDOMHTMLScriptElement
*nsscript
;
634 nsIDOMComment
*nscomment
;
635 nsIDOMElement
*nselem
;
638 TRACE("(%p)\n", This
);
640 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMElement
, (void**)&nselem
);
641 if(NS_SUCCEEDED(nsres
)) {
642 check_event_attr(This
, nselem
);
643 nsIDOMElement_Release(nselem
);
646 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMComment
, (void**)&nscomment
);
647 if(NS_SUCCEEDED(nsres
)) {
648 TRACE("comment node\n");
650 add_script_runner(This
, run_insert_comment
, (nsISupports
*)nscomment
, NULL
);
651 nsIDOMComment_Release(nscomment
);
655 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLIFrameElement
, (void**)&nsiframe
);
656 if(NS_SUCCEEDED(nsres
)) {
657 TRACE("iframe node\n");
659 add_script_runner(This
, run_bind_to_tree
, (nsISupports
*)nsiframe
, NULL
);
660 nsIDOMHTMLIFrameElement_Release(nsiframe
);
664 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLFrameElement
, (void**)&nsframe
);
665 if(NS_SUCCEEDED(nsres
)) {
666 TRACE("frame node\n");
668 add_script_runner(This
, run_bind_to_tree
, (nsISupports
*)nsframe
, NULL
);
669 nsIDOMHTMLFrameElement_Release(nsframe
);
673 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLScriptElement
, (void**)&nsscript
);
674 if(NS_SUCCEEDED(nsres
)) {
675 HTMLScriptElement
*script_elem
;
678 TRACE("script element\n");
680 hres
= script_elem_from_nsscript(This
, nsscript
, &script_elem
);
681 nsIDOMHTMLScriptElement_Release(nsscript
);
685 if(script_elem
->parse_on_bind
)
686 add_script_runner(This
, run_insert_script
, (nsISupports
*)nsscript
, NULL
);
688 IHTMLScriptElement_Release(&script_elem
->IHTMLScriptElement_iface
);
692 static void NSAPI
nsDocumentObserver_AttemptToExecuteScript(nsIDocumentObserver
*iface
, nsIContent
*aContent
,
693 nsIParser
*aParser
, cpp_bool
*aBlock
)
695 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
696 nsIDOMHTMLScriptElement
*nsscript
;
699 TRACE("(%p)->(%p %p %p)\n", This
, aContent
, aParser
, aBlock
);
701 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLScriptElement
, (void**)&nsscript
);
702 if(NS_SUCCEEDED(nsres
)) {
703 TRACE("script node\n");
705 add_script_runner(This
, run_insert_script
, (nsISupports
*)nsscript
, (nsISupports
*)aParser
);
706 nsIDOMHTMLScriptElement_Release(nsscript
);
710 static const nsIDocumentObserverVtbl nsDocumentObserverVtbl
= {
711 nsDocumentObserver_QueryInterface
,
712 nsDocumentObserver_AddRef
,
713 nsDocumentObserver_Release
,
714 nsDocumentObserver_CharacterDataWillChange
,
715 nsDocumentObserver_CharacterDataChanged
,
716 nsDocumentObserver_AttributeWillChange
,
717 nsDocumentObserver_AttributeChanged
,
718 nsDocumentObserver_ContentAppended
,
719 nsDocumentObserver_ContentInserted
,
720 nsDocumentObserver_ContentRemoved
,
721 nsDocumentObserver_NodeWillBeDestroyed
,
722 nsDocumentObserver_ParentChainChanged
,
723 nsDocumentObserver_BeginUpdate
,
724 nsDocumentObserver_EndUpdate
,
725 nsDocumentObserver_BeginLoad
,
726 nsDocumentObserver_EndLoad
,
727 nsDocumentObserver_ContentStatesChanged
,
728 nsDocumentObserver_DocumentStatesChanged
,
729 nsDocumentObserver_StyleSheetAdded
,
730 nsDocumentObserver_StyleSheetRemoved
,
731 nsDocumentObserver_StyleSheetApplicableStateChanged
,
732 nsDocumentObserver_StyleRuleChanged
,
733 nsDocumentObserver_StyleRuleAdded
,
734 nsDocumentObserver_StyleRuleRemoved
,
735 nsDocumentObserver_BindToDocument
,
736 nsDocumentObserver_AttemptToExecuteScript
739 void init_document_mutation(HTMLDocumentNode
*doc
)
744 doc
->nsIDocumentObserver_iface
.lpVtbl
= &nsDocumentObserverVtbl
;
746 nsres
= nsIDOMHTMLDocument_QueryInterface(doc
->nsdoc
, &IID_nsIDocument
, (void**)&nsdoc
);
747 if(NS_FAILED(nsres
)) {
748 ERR("Could not get nsIDocument: %08x\n", nsres
);
752 nsIContentUtils_AddDocumentObserver(content_utils
, nsdoc
, &doc
->nsIDocumentObserver_iface
);
753 nsIDocument_Release(nsdoc
);
756 void release_document_mutation(HTMLDocumentNode
*doc
)
761 nsres
= nsIDOMHTMLDocument_QueryInterface(doc
->nsdoc
, &IID_nsIDocument
, (void**)&nsdoc
);
762 if(NS_FAILED(nsres
)) {
763 ERR("Could not get nsIDocument: %08x\n", nsres
);
767 nsIContentUtils_RemoveDocumentObserver(content_utils
, nsdoc
, &doc
->nsIDocumentObserver_iface
);
768 nsIDocument_Release(nsdoc
);
771 void init_mutation(nsIComponentManager
*component_manager
)
776 if(!component_manager
) {
778 nsIContentUtils_Release(content_utils
);
779 content_utils
= NULL
;
784 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_ICONTENTUTILS_CID
,
785 &IID_nsIFactory
, (void**)&factory
);
786 if(NS_FAILED(nsres
)) {
787 ERR("Could not create nsIContentUtils service: %08x\n", nsres
);
791 nsres
= nsIFactory_CreateInstance(factory
, NULL
, &IID_nsIContentUtils
, (void**)&content_utils
);
792 nsIFactory_Release(factory
);
794 ERR("Could not create nsIContentUtils instance: %08x\n", nsres
);