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
19 #include "mshtml_private.h"
21 #define IE_MAJOR_VERSION 7
22 #define IE_MINOR_VERSION 0
24 static const IID NS_ICONTENTUTILS_CID
=
25 {0x762C4AE7,0xB923,0x422F,{0xB9,0x7E,0xB9,0xBF,0xC1,0xEF,0x7B,0xF0}};
27 static nsIContentUtils
*content_utils
;
29 static PRUnichar
*handle_insert_comment(HTMLDocumentNode
*doc
, const PRUnichar
*comment
)
31 int majorv
= 0, minorv
= 0;
32 const PRUnichar
*ptr
, *end
;
44 static const PRUnichar endifW
[] = {'<','!','[','e','n','d','i','f',']'};
46 if(comment
[0] != '[' || comment
[1] != 'i' || comment
[2] != 'f')
53 if(ptr
[0] == 'l' && ptr
[1] == 't') {
61 }else if(ptr
[0] == 'g' && ptr
[1] == 't') {
76 if(ptr
[0] != 'I' || ptr
[1] != 'E')
88 majorv
= majorv
*10 + (*ptr
++ - '0');
95 minorv
= minorv
*10 + (*ptr
++ - '0');
100 if(ptr
[0] != ']' || ptr
[1] != '>')
105 if(len
< sizeof(endifW
)/sizeof(WCHAR
))
108 end
= ptr
+ len
-sizeof(endifW
)/sizeof(WCHAR
);
109 if(memcmp(end
, endifW
, sizeof(endifW
)))
114 if(majorv
== IE_MAJOR_VERSION
&& minorv
== IE_MINOR_VERSION
)
118 if(majorv
> IE_MAJOR_VERSION
)
120 if(majorv
== IE_MAJOR_VERSION
&& minorv
> IE_MINOR_VERSION
)
124 if(majorv
> IE_MAJOR_VERSION
)
126 if(majorv
== IE_MAJOR_VERSION
&& minorv
>= IE_MINOR_VERSION
)
130 if(majorv
< IE_MAJOR_VERSION
)
132 if(majorv
== IE_MAJOR_VERSION
&& minorv
< IE_MINOR_VERSION
)
136 if(majorv
< IE_MAJOR_VERSION
)
138 if(majorv
== IE_MAJOR_VERSION
&& minorv
<= IE_MINOR_VERSION
)
143 buf
= heap_alloc((end
-ptr
+1)*sizeof(WCHAR
));
147 memcpy(buf
, ptr
, (end
-ptr
)*sizeof(WCHAR
));
153 static nsresult
run_insert_comment(HTMLDocumentNode
*doc
, nsISupports
*comment_iface
, nsISupports
*arg2
)
155 const PRUnichar
*comment
;
156 nsIDOMComment
*nscomment
;
157 PRUnichar
*replace_html
;
158 nsAString comment_str
;
161 nsres
= nsISupports_QueryInterface(comment_iface
, &IID_nsIDOMComment
, (void**)&nscomment
);
162 if(NS_FAILED(nsres
)) {
163 ERR("Could not get nsIDOMComment iface:%08x\n", nsres
);
167 nsAString_Init(&comment_str
, NULL
);
168 nsres
= nsIDOMComment_GetData(nscomment
, &comment_str
);
172 nsAString_GetData(&comment_str
, &comment
);
173 replace_html
= handle_insert_comment(doc
, comment
);
174 nsAString_Finish(&comment_str
);
179 hres
= replace_node_by_html(doc
->nsdoc
, (nsIDOMNode
*)nscomment
, replace_html
);
180 heap_free(replace_html
);
182 nsres
= NS_ERROR_FAILURE
;
186 nsIDOMComment_Release(nscomment
);
190 static nsresult
run_bind_to_tree(HTMLDocumentNode
*doc
, nsISupports
*nsiface
, nsISupports
*arg2
)
197 TRACE("(%p)->(%p)\n", doc
, nsiface
);
199 nsres
= nsISupports_QueryInterface(nsiface
, &IID_nsIDOMNode
, (void**)&nsnode
);
203 hres
= get_node(doc
, nsnode
, TRUE
, &node
);
204 nsIDOMNode_Release(nsnode
);
206 ERR("Could not get node\n");
210 if(node
->vtbl
->bind_to_tree
)
211 node
->vtbl
->bind_to_tree(node
);
217 /* Calls undocumented 69 cmd of CGID_Explorer */
218 static void call_explorer_69(HTMLDocumentObj
*doc
)
220 IOleCommandTarget
*olecmd
;
227 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&olecmd
);
232 hres
= IOleCommandTarget_Exec(olecmd
, &CGID_Explorer
, 69, 0, NULL
, &var
);
233 IOleCommandTarget_Release(olecmd
);
234 if(SUCCEEDED(hres
) && V_VT(&var
) != VT_NULL
)
235 FIXME("handle result\n");
238 static void parse_complete(HTMLDocumentObj
*doc
)
240 TRACE("(%p)\n", doc
);
242 if(doc
->usermode
== EDITMODE
)
243 init_editor(&doc
->basedoc
);
245 call_explorer_69(doc
);
247 IAdviseSink_OnViewChange(doc
->view_sink
, DVASPECT_CONTENT
, -1);
248 call_property_onchanged(&doc
->basedoc
.cp_container
, 1005);
249 call_explorer_69(doc
);
251 if(doc
->webbrowser
&& doc
->usermode
!= EDITMODE
&& !(doc
->basedoc
.window
->load_flags
& BINDING_REFRESH
))
252 IDocObjectService_FireNavigateComplete2(doc
->doc_object_service
, &doc
->basedoc
.window
->base
.IHTMLWindow2_iface
, 0);
254 /* FIXME: IE7 calls EnableModelless(TRUE), EnableModelless(FALSE) and sets interactive state here */
257 static nsresult
run_end_load(HTMLDocumentNode
*This
, nsISupports
*arg1
, nsISupports
*arg2
)
259 TRACE("(%p)\n", This
);
261 if(!This
->basedoc
.doc_obj
)
264 if(This
== This
->basedoc
.doc_obj
->basedoc
.doc_node
) {
266 * This should be done in the worker thread that parses HTML,
267 * but we don't have such thread (Gecko parses HTML for us).
269 parse_complete(This
->basedoc
.doc_obj
);
272 bind_event_scripts(This
);
273 set_ready_state(This
->basedoc
.window
, READYSTATE_INTERACTIVE
);
277 static nsresult
run_insert_script(HTMLDocumentNode
*doc
, nsISupports
*script_iface
, nsISupports
*parser_iface
)
279 nsIDOMHTMLScriptElement
*nsscript
;
280 HTMLScriptElement
*script_elem
;
281 nsIParser
*nsparser
= NULL
;
282 script_queue_entry_t
*iter
;
283 HTMLInnerWindow
*window
;
287 TRACE("(%p)->(%p)\n", doc
, script_iface
);
289 window
= doc
->window
;
293 nsres
= nsISupports_QueryInterface(script_iface
, &IID_nsIDOMHTMLScriptElement
, (void**)&nsscript
);
294 if(NS_FAILED(nsres
)) {
295 ERR("Could not get nsIDOMHTMLScriptElement: %08x\n", nsres
);
300 nsres
= nsISupports_QueryInterface(parser_iface
, &IID_nsIParser
, (void**)&nsparser
);
301 if(NS_FAILED(nsres
)) {
302 ERR("Could not get nsIParser iface: %08x\n", nsres
);
307 hres
= script_elem_from_nsscript(doc
, nsscript
, &script_elem
);
308 nsIDOMHTMLScriptElement_Release(nsscript
);
310 return NS_ERROR_FAILURE
;
313 nsIParser_BeginEvaluatingParserInsertedScript(nsparser
);
314 window
->parser_callback_cnt
++;
317 IHTMLWindow2_AddRef(&window
->base
.IHTMLWindow2_iface
);
319 doc_insert_script(window
, script_elem
);
321 while(!list_empty(&window
->script_queue
)) {
322 iter
= LIST_ENTRY(list_head(&window
->script_queue
), script_queue_entry_t
, entry
);
323 list_remove(&iter
->entry
);
324 if(!iter
->script
->parsed
)
325 doc_insert_script(window
, iter
->script
);
326 IHTMLScriptElement_Release(&iter
->script
->IHTMLScriptElement_iface
);
330 IHTMLWindow2_Release(&window
->base
.IHTMLWindow2_iface
);
333 window
->parser_callback_cnt
--;
334 nsIParser_EndEvaluatingParserInsertedScript(nsparser
);
335 nsIParser_Release(nsparser
);
338 IHTMLScriptElement_Release(&script_elem
->IHTMLScriptElement_iface
);
343 typedef struct nsRunnable nsRunnable
;
345 typedef nsresult (*runnable_proc_t
)(HTMLDocumentNode
*,nsISupports
*,nsISupports
*);
348 nsIRunnable nsIRunnable_iface
;
352 runnable_proc_t proc
;
354 HTMLDocumentNode
*doc
;
359 static inline nsRunnable
*impl_from_nsIRunnable(nsIRunnable
*iface
)
361 return CONTAINING_RECORD(iface
, nsRunnable
, nsIRunnable_iface
);
364 static nsresult NSAPI
nsRunnable_QueryInterface(nsIRunnable
*iface
,
365 nsIIDRef riid
, void **result
)
367 nsRunnable
*This
= impl_from_nsIRunnable(iface
);
369 if(IsEqualGUID(riid
, &IID_nsISupports
)) {
370 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
371 *result
= &This
->nsIRunnable_iface
;
372 }else if(IsEqualGUID(riid
, &IID_nsIRunnable
)) {
373 TRACE("(%p)->(IID_nsIRunnable %p)\n", This
, result
);
374 *result
= &This
->nsIRunnable_iface
;
377 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
378 return NS_NOINTERFACE
;
381 nsISupports_AddRef((nsISupports
*)*result
);
385 static nsrefcnt NSAPI
nsRunnable_AddRef(nsIRunnable
*iface
)
387 nsRunnable
*This
= impl_from_nsIRunnable(iface
);
388 LONG ref
= InterlockedIncrement(&This
->ref
);
390 TRACE("(%p) ref=%d\n", This
, ref
);
395 static nsrefcnt NSAPI
nsRunnable_Release(nsIRunnable
*iface
)
397 nsRunnable
*This
= impl_from_nsIRunnable(iface
);
398 LONG ref
= InterlockedDecrement(&This
->ref
);
400 TRACE("(%p) ref=%d\n", This
, ref
);
403 htmldoc_release(&This
->doc
->basedoc
);
405 nsISupports_Release(This
->arg1
);
407 nsISupports_Release(This
->arg2
);
414 static nsresult NSAPI
nsRunnable_Run(nsIRunnable
*iface
)
416 nsRunnable
*This
= impl_from_nsIRunnable(iface
);
418 return This
->proc(This
->doc
, This
->arg1
, This
->arg2
);
421 static const nsIRunnableVtbl nsRunnableVtbl
= {
422 nsRunnable_QueryInterface
,
428 static void add_script_runner(HTMLDocumentNode
*This
, runnable_proc_t proc
, nsISupports
*arg1
, nsISupports
*arg2
)
430 nsRunnable
*runnable
;
432 runnable
= heap_alloc_zero(sizeof(*runnable
));
436 runnable
->nsIRunnable_iface
.lpVtbl
= &nsRunnableVtbl
;
439 htmldoc_addref(&This
->basedoc
);
440 runnable
->doc
= This
;
441 runnable
->proc
= proc
;
444 nsISupports_AddRef(arg1
);
445 runnable
->arg1
= arg1
;
448 nsISupports_AddRef(arg2
);
449 runnable
->arg2
= arg2
;
451 nsIContentUtils_AddScriptRunner(content_utils
, &runnable
->nsIRunnable_iface
);
453 nsIRunnable_Release(&runnable
->nsIRunnable_iface
);
456 static inline HTMLDocumentNode
*impl_from_nsIDocumentObserver(nsIDocumentObserver
*iface
)
458 return CONTAINING_RECORD(iface
, HTMLDocumentNode
, nsIDocumentObserver_iface
);
461 static nsresult NSAPI
nsDocumentObserver_QueryInterface(nsIDocumentObserver
*iface
,
462 nsIIDRef riid
, void **result
)
464 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
466 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
467 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
468 *result
= &This
->nsIDocumentObserver_iface
;
469 }else if(IsEqualGUID(&IID_nsIMutationObserver
, riid
)) {
470 TRACE("(%p)->(IID_nsIMutationObserver %p)\n", This
, result
);
471 *result
= &This
->nsIDocumentObserver_iface
;
472 }else if(IsEqualGUID(&IID_nsIDocumentObserver
, riid
)) {
473 TRACE("(%p)->(IID_nsIDocumentObserver %p)\n", This
, result
);
474 *result
= &This
->nsIDocumentObserver_iface
;
477 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
478 return NS_NOINTERFACE
;
481 htmldoc_addref(&This
->basedoc
);
485 static nsrefcnt NSAPI
nsDocumentObserver_AddRef(nsIDocumentObserver
*iface
)
487 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
488 return htmldoc_addref(&This
->basedoc
);
491 static nsrefcnt NSAPI
nsDocumentObserver_Release(nsIDocumentObserver
*iface
)
493 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
494 return htmldoc_release(&This
->basedoc
);
497 static void NSAPI
nsDocumentObserver_CharacterDataWillChange(nsIDocumentObserver
*iface
,
498 nsIDocument
*aDocument
, nsIContent
*aContent
, void /*CharacterDataChangeInfo*/ *aInfo
)
502 static void NSAPI
nsDocumentObserver_CharacterDataChanged(nsIDocumentObserver
*iface
,
503 nsIDocument
*aDocument
, nsIContent
*aContent
, void /*CharacterDataChangeInfo*/ *aInfo
)
507 static void NSAPI
nsDocumentObserver_AttributeWillChange(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
508 nsIContent
*aContent
, LONG aNameSpaceID
, nsIAtom
*aAttribute
, LONG aModType
)
512 static void NSAPI
nsDocumentObserver_AttributeChanged(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
513 nsIContent
*aContent
, LONG aNameSpaceID
, nsIAtom
*aAttribute
, LONG aModType
)
517 static void NSAPI
nsDocumentObserver_AttributeSetToCurrentValue(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
518 void *aElement
, LONG aNameSpaceID
, nsIAtom
*aAttribute
)
522 static void NSAPI
nsDocumentObserver_ContentAppended(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
523 nsIContent
*aContainer
, nsIContent
*aFirstNewContent
, LONG aNewIndexInContainer
)
527 static void NSAPI
nsDocumentObserver_ContentInserted(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
528 nsIContent
*aContainer
, nsIContent
*aChild
, LONG aIndexInContainer
)
532 static void NSAPI
nsDocumentObserver_ContentRemoved(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
533 nsIContent
*aContainer
, nsIContent
*aChild
, LONG aIndexInContainer
,
534 nsIContent
*aProviousSibling
)
538 static void NSAPI
nsDocumentObserver_NodeWillBeDestroyed(nsIDocumentObserver
*iface
, const nsINode
*aNode
)
542 static void NSAPI
nsDocumentObserver_ParentChainChanged(nsIDocumentObserver
*iface
, nsIContent
*aContent
)
546 static void NSAPI
nsDocumentObserver_BeginUpdate(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
547 nsUpdateType aUpdateType
)
551 static void NSAPI
nsDocumentObserver_EndUpdate(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
552 nsUpdateType aUpdateType
)
556 static void NSAPI
nsDocumentObserver_BeginLoad(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
)
560 static void NSAPI
nsDocumentObserver_EndLoad(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
)
562 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
564 TRACE("(%p)\n", This
);
566 if(This
->skip_mutation_notif
)
569 This
->content_ready
= TRUE
;
570 add_script_runner(This
, run_end_load
, NULL
, NULL
);
573 static void NSAPI
nsDocumentObserver_ContentStatesChanged(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
574 nsIContent
*aContent
, nsEventStates
*aStateMask
)
578 static void NSAPI
nsDocumentObserver_DocumentStatesChanged(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
579 nsEventStates
*aStateMask
)
583 static void NSAPI
nsDocumentObserver_StyleSheetAdded(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
584 nsIStyleSheet
*aStyleSheet
, cpp_bool aDocumentSheet
)
588 static void NSAPI
nsDocumentObserver_StyleSheetRemoved(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
589 nsIStyleSheet
*aStyleSheet
, cpp_bool aDocumentSheet
)
593 static void NSAPI
nsDocumentObserver_StyleSheetApplicableStateChanged(nsIDocumentObserver
*iface
,
594 nsIDocument
*aDocument
, nsIStyleSheet
*aStyleSheet
, cpp_bool aApplicable
)
598 static void NSAPI
nsDocumentObserver_StyleRuleChanged(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
599 nsIStyleSheet
*aStyleSheet
, nsIStyleRule
*aOldStyleRule
, nsIStyleSheet
*aNewStyleRule
)
603 static void NSAPI
nsDocumentObserver_StyleRuleAdded(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
604 nsIStyleSheet
*aStyleSheet
, nsIStyleRule
*aStyleRule
)
608 static void NSAPI
nsDocumentObserver_StyleRuleRemoved(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
609 nsIStyleSheet
*aStyleSheet
, nsIStyleRule
*aStyleRule
)
613 static void NSAPI
nsDocumentObserver_BindToDocument(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
614 nsIContent
*aContent
)
616 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
617 nsIDOMHTMLIFrameElement
*nsiframe
;
618 nsIDOMHTMLFrameElement
*nsframe
;
619 nsIDOMHTMLScriptElement
*nsscript
;
620 nsIDOMHTMLElement
*nselem
;
621 nsIDOMComment
*nscomment
;
624 TRACE("(%p)->(%p %p)\n", This
, aDocument
, aContent
);
626 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLElement
, (void**)&nselem
);
627 if(NS_SUCCEEDED(nsres
)) {
628 check_event_attr(This
, nselem
);
629 nsIDOMHTMLElement_Release(nselem
);
632 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMComment
, (void**)&nscomment
);
633 if(NS_SUCCEEDED(nsres
)) {
634 TRACE("comment node\n");
636 add_script_runner(This
, run_insert_comment
, (nsISupports
*)nscomment
, NULL
);
637 nsIDOMComment_Release(nscomment
);
641 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLIFrameElement
, (void**)&nsiframe
);
642 if(NS_SUCCEEDED(nsres
)) {
643 TRACE("iframe node\n");
645 add_script_runner(This
, run_bind_to_tree
, (nsISupports
*)nsiframe
, NULL
);
646 nsIDOMHTMLIFrameElement_Release(nsiframe
);
650 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLFrameElement
, (void**)&nsframe
);
651 if(NS_SUCCEEDED(nsres
)) {
652 TRACE("frame node\n");
654 add_script_runner(This
, run_bind_to_tree
, (nsISupports
*)nsframe
, NULL
);
655 nsIDOMHTMLFrameElement_Release(nsframe
);
659 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLScriptElement
, (void**)&nsscript
);
660 if(NS_SUCCEEDED(nsres
)) {
661 HTMLScriptElement
*script_elem
;
664 TRACE("script element\n");
666 hres
= script_elem_from_nsscript(This
, nsscript
, &script_elem
);
667 nsIDOMHTMLScriptElement_Release(nsscript
);
671 if(script_elem
->parse_on_bind
)
672 add_script_runner(This
, run_insert_script
, (nsISupports
*)nsscript
, NULL
);
674 IHTMLScriptElement_Release(&script_elem
->IHTMLScriptElement_iface
);
678 static void NSAPI
nsDocumentObserver_AttemptToExecuteScript(nsIDocumentObserver
*iface
, nsIContent
*aContent
,
679 nsIParser
*aParser
, cpp_bool
*aBlock
)
681 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
682 nsIDOMHTMLScriptElement
*nsscript
;
685 TRACE("(%p)->(%p %p %p)\n", This
, aContent
, aParser
, aBlock
);
687 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLScriptElement
, (void**)&nsscript
);
688 if(NS_SUCCEEDED(nsres
)) {
689 TRACE("script node\n");
691 add_script_runner(This
, run_insert_script
, (nsISupports
*)nsscript
, (nsISupports
*)aParser
);
692 nsIDOMHTMLScriptElement_Release(nsscript
);
696 static const nsIDocumentObserverVtbl nsDocumentObserverVtbl
= {
697 nsDocumentObserver_QueryInterface
,
698 nsDocumentObserver_AddRef
,
699 nsDocumentObserver_Release
,
700 nsDocumentObserver_CharacterDataWillChange
,
701 nsDocumentObserver_CharacterDataChanged
,
702 nsDocumentObserver_AttributeWillChange
,
703 nsDocumentObserver_AttributeChanged
,
704 nsDocumentObserver_AttributeSetToCurrentValue
,
705 nsDocumentObserver_ContentAppended
,
706 nsDocumentObserver_ContentInserted
,
707 nsDocumentObserver_ContentRemoved
,
708 nsDocumentObserver_NodeWillBeDestroyed
,
709 nsDocumentObserver_ParentChainChanged
,
710 nsDocumentObserver_BeginUpdate
,
711 nsDocumentObserver_EndUpdate
,
712 nsDocumentObserver_BeginLoad
,
713 nsDocumentObserver_EndLoad
,
714 nsDocumentObserver_ContentStatesChanged
,
715 nsDocumentObserver_DocumentStatesChanged
,
716 nsDocumentObserver_StyleSheetAdded
,
717 nsDocumentObserver_StyleSheetRemoved
,
718 nsDocumentObserver_StyleSheetApplicableStateChanged
,
719 nsDocumentObserver_StyleRuleChanged
,
720 nsDocumentObserver_StyleRuleAdded
,
721 nsDocumentObserver_StyleRuleRemoved
,
722 nsDocumentObserver_BindToDocument
,
723 nsDocumentObserver_AttemptToExecuteScript
726 void init_document_mutation(HTMLDocumentNode
*doc
)
731 doc
->nsIDocumentObserver_iface
.lpVtbl
= &nsDocumentObserverVtbl
;
733 nsres
= nsIDOMHTMLDocument_QueryInterface(doc
->nsdoc
, &IID_nsIDocument
, (void**)&nsdoc
);
734 if(NS_FAILED(nsres
)) {
735 ERR("Could not get nsIDocument: %08x\n", nsres
);
739 nsIContentUtils_AddDocumentObserver(content_utils
, nsdoc
, &doc
->nsIDocumentObserver_iface
);
740 nsIDocument_Release(nsdoc
);
743 void release_document_mutation(HTMLDocumentNode
*doc
)
748 nsres
= nsIDOMHTMLDocument_QueryInterface(doc
->nsdoc
, &IID_nsIDocument
, (void**)&nsdoc
);
749 if(NS_FAILED(nsres
)) {
750 ERR("Could not get nsIDocument: %08x\n", nsres
);
754 nsIContentUtils_RemoveDocumentObserver(content_utils
, nsdoc
, &doc
->nsIDocumentObserver_iface
);
755 nsIDocument_Release(nsdoc
);
758 JSContext
*get_context_from_document(nsIDOMHTMLDocument
*nsdoc
)
764 nsres
= nsIDOMHTMLDocument_QueryInterface(nsdoc
, &IID_nsIDocument
, (void**)&doc
);
765 assert(nsres
== NS_OK
);
767 ctx
= nsIContentUtils_GetContextFromDocument(content_utils
, doc
);
768 nsIDocument_Release(doc
);
770 TRACE("ret %p\n", ctx
);
774 void init_mutation(nsIComponentManager
*component_manager
)
779 if(!component_manager
) {
781 nsIContentUtils_Release(content_utils
);
782 content_utils
= NULL
;
787 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_ICONTENTUTILS_CID
,
788 &IID_nsIFactory
, (void**)&factory
);
789 if(NS_FAILED(nsres
)) {
790 ERR("Could not create nsIContentUtils service: %08x\n", nsres
);
794 nsres
= nsIFactory_CreateInstance(factory
, NULL
, &IID_nsIContentUtils
, (void**)&content_utils
);
795 nsIFactory_Release(factory
);
797 ERR("Could not create nsIContentUtils instance: %08x\n", nsres
);