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
33 #include "mshtml_private.h"
34 #include "htmlscript.h"
35 #include "htmlevent.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
42 #define IE_MAJOR_VERSION 7
43 #define IE_MINOR_VERSION 0
45 static const IID NS_ICONTENTUTILS_CID
=
46 {0x762C4AE7,0xB923,0x422F,{0xB9,0x7E,0xB9,0xBF,0xC1,0xEF,0x7B,0xF0}};
48 static nsIContentUtils
*content_utils
;
50 static PRUnichar
*handle_insert_comment(HTMLDocumentNode
*doc
, const PRUnichar
*comment
)
52 int majorv
= 0, minorv
= 0;
53 const PRUnichar
*ptr
, *end
;
65 static const PRUnichar endifW
[] = {'<','!','[','e','n','d','i','f',']'};
67 if(comment
[0] != '[' || comment
[1] != 'i' || comment
[2] != 'f')
74 if(ptr
[0] == 'l' && ptr
[1] == 't') {
82 }else if(ptr
[0] == 'g' && ptr
[1] == 't') {
97 if(ptr
[0] != 'I' || ptr
[1] != 'E')
101 if(!isspaceW(*ptr
++))
103 while(isspaceW(*ptr
))
108 while(isdigitW(*ptr
))
109 majorv
= majorv
*10 + (*ptr
++ - '0');
115 while(isdigitW(*ptr
))
116 minorv
= minorv
*10 + (*ptr
++ - '0');
119 while(isspaceW(*ptr
))
121 if(ptr
[0] != ']' || ptr
[1] != '>')
126 if(len
< sizeof(endifW
)/sizeof(WCHAR
))
129 end
= ptr
+ len
-sizeof(endifW
)/sizeof(WCHAR
);
130 if(memcmp(end
, endifW
, sizeof(endifW
)))
135 if(majorv
== IE_MAJOR_VERSION
&& minorv
== IE_MINOR_VERSION
)
139 if(majorv
> IE_MAJOR_VERSION
)
141 if(majorv
== IE_MAJOR_VERSION
&& minorv
> IE_MINOR_VERSION
)
145 if(majorv
> IE_MAJOR_VERSION
)
147 if(majorv
== IE_MAJOR_VERSION
&& minorv
>= IE_MINOR_VERSION
)
151 if(majorv
< IE_MAJOR_VERSION
)
153 if(majorv
== IE_MAJOR_VERSION
&& minorv
< IE_MINOR_VERSION
)
157 if(majorv
< IE_MAJOR_VERSION
)
159 if(majorv
== IE_MAJOR_VERSION
&& minorv
<= IE_MINOR_VERSION
)
164 buf
= heap_alloc((end
-ptr
+1)*sizeof(WCHAR
));
168 memcpy(buf
, ptr
, (end
-ptr
)*sizeof(WCHAR
));
174 static nsresult
run_insert_comment(HTMLDocumentNode
*doc
, nsISupports
*comment_iface
, nsISupports
*arg2
)
176 const PRUnichar
*comment
;
177 nsIDOMComment
*nscomment
;
178 PRUnichar
*replace_html
;
179 nsAString comment_str
;
182 nsres
= nsISupports_QueryInterface(comment_iface
, &IID_nsIDOMComment
, (void**)&nscomment
);
183 if(NS_FAILED(nsres
)) {
184 ERR("Could not get nsIDOMComment iface:%08x\n", nsres
);
188 nsAString_Init(&comment_str
, NULL
);
189 nsres
= nsIDOMComment_GetData(nscomment
, &comment_str
);
193 nsAString_GetData(&comment_str
, &comment
);
194 replace_html
= handle_insert_comment(doc
, comment
);
195 nsAString_Finish(&comment_str
);
200 hres
= replace_node_by_html(doc
->nsdoc
, (nsIDOMNode
*)nscomment
, replace_html
);
201 heap_free(replace_html
);
203 nsres
= NS_ERROR_FAILURE
;
207 nsIDOMComment_Release(nscomment
);
211 static nsresult
run_bind_to_tree(HTMLDocumentNode
*doc
, nsISupports
*nsiface
, nsISupports
*arg2
)
218 TRACE("(%p)->(%p)\n", doc
, nsiface
);
220 nsres
= nsISupports_QueryInterface(nsiface
, &IID_nsIDOMNode
, (void**)&nsnode
);
224 hres
= get_node(doc
, nsnode
, TRUE
, &node
);
225 nsIDOMNode_Release(nsnode
);
227 ERR("Could not get node\n");
231 if(node
->vtbl
->bind_to_tree
)
232 node
->vtbl
->bind_to_tree(node
);
238 /* Calls undocumented 69 cmd of CGID_Explorer */
239 static void call_explorer_69(HTMLDocumentObj
*doc
)
241 IOleCommandTarget
*olecmd
;
248 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&olecmd
);
253 hres
= IOleCommandTarget_Exec(olecmd
, &CGID_Explorer
, 69, 0, NULL
, &var
);
254 IOleCommandTarget_Release(olecmd
);
255 if(SUCCEEDED(hres
) && V_VT(&var
) != VT_NULL
)
256 FIXME("handle result\n");
259 static void parse_complete(HTMLDocumentObj
*doc
)
261 TRACE("(%p)\n", doc
);
263 if(doc
->usermode
== EDITMODE
)
264 init_editor(&doc
->basedoc
);
266 call_explorer_69(doc
);
268 IAdviseSink_OnViewChange(doc
->view_sink
, DVASPECT_CONTENT
, -1);
269 call_property_onchanged(&doc
->basedoc
.cp_container
, 1005);
270 call_explorer_69(doc
);
272 if(doc
->webbrowser
&& doc
->usermode
!= EDITMODE
&& !(doc
->basedoc
.window
->load_flags
& BINDING_REFRESH
))
273 IDocObjectService_FireNavigateComplete2(doc
->doc_object_service
, &doc
->basedoc
.window
->base
.IHTMLWindow2_iface
, 0);
275 /* FIXME: IE7 calls EnableModelless(TRUE), EnableModelless(FALSE) and sets interactive state here */
278 static nsresult
run_end_load(HTMLDocumentNode
*This
, nsISupports
*arg1
, nsISupports
*arg2
)
280 TRACE("(%p)\n", This
);
282 if(!This
->basedoc
.doc_obj
)
285 if(This
== This
->basedoc
.doc_obj
->basedoc
.doc_node
) {
287 * This should be done in the worker thread that parses HTML,
288 * but we don't have such thread (Gecko parses HTML for us).
290 parse_complete(This
->basedoc
.doc_obj
);
293 bind_event_scripts(This
);
294 set_ready_state(This
->basedoc
.window
, READYSTATE_INTERACTIVE
);
298 static nsresult
run_insert_script(HTMLDocumentNode
*doc
, nsISupports
*script_iface
, nsISupports
*parser_iface
)
300 nsIDOMHTMLScriptElement
*nsscript
;
301 HTMLScriptElement
*script_elem
;
302 nsIParser
*nsparser
= NULL
;
303 script_queue_entry_t
*iter
;
304 HTMLInnerWindow
*window
;
308 TRACE("(%p)->(%p)\n", doc
, script_iface
);
310 window
= doc
->window
;
314 nsres
= nsISupports_QueryInterface(script_iface
, &IID_nsIDOMHTMLScriptElement
, (void**)&nsscript
);
315 if(NS_FAILED(nsres
)) {
316 ERR("Could not get nsIDOMHTMLScriptElement: %08x\n", nsres
);
321 nsres
= nsISupports_QueryInterface(parser_iface
, &IID_nsIParser
, (void**)&nsparser
);
322 if(NS_FAILED(nsres
)) {
323 ERR("Could not get nsIParser iface: %08x\n", nsres
);
328 hres
= script_elem_from_nsscript(doc
, nsscript
, &script_elem
);
329 nsIDOMHTMLScriptElement_Release(nsscript
);
331 return NS_ERROR_FAILURE
;
334 nsIParser_BeginEvaluatingParserInsertedScript(nsparser
);
335 window
->parser_callback_cnt
++;
338 IHTMLWindow2_AddRef(&window
->base
.IHTMLWindow2_iface
);
340 doc_insert_script(window
, script_elem
);
342 while(!list_empty(&window
->script_queue
)) {
343 iter
= LIST_ENTRY(list_head(&window
->script_queue
), script_queue_entry_t
, entry
);
344 list_remove(&iter
->entry
);
345 if(!iter
->script
->parsed
)
346 doc_insert_script(window
, iter
->script
);
347 IHTMLScriptElement_Release(&iter
->script
->IHTMLScriptElement_iface
);
351 IHTMLWindow2_Release(&window
->base
.IHTMLWindow2_iface
);
354 window
->parser_callback_cnt
--;
355 nsIParser_EndEvaluatingParserInsertedScript(nsparser
);
356 nsIParser_Release(nsparser
);
359 IHTMLScriptElement_Release(&script_elem
->IHTMLScriptElement_iface
);
364 typedef struct nsRunnable nsRunnable
;
366 typedef nsresult (*runnable_proc_t
)(HTMLDocumentNode
*,nsISupports
*,nsISupports
*);
369 nsIRunnable nsIRunnable_iface
;
373 runnable_proc_t proc
;
375 HTMLDocumentNode
*doc
;
380 static inline nsRunnable
*impl_from_nsIRunnable(nsIRunnable
*iface
)
382 return CONTAINING_RECORD(iface
, nsRunnable
, nsIRunnable_iface
);
385 static nsresult NSAPI
nsRunnable_QueryInterface(nsIRunnable
*iface
,
386 nsIIDRef riid
, void **result
)
388 nsRunnable
*This
= impl_from_nsIRunnable(iface
);
390 if(IsEqualGUID(riid
, &IID_nsISupports
)) {
391 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
392 *result
= &This
->nsIRunnable_iface
;
393 }else if(IsEqualGUID(riid
, &IID_nsIRunnable
)) {
394 TRACE("(%p)->(IID_nsIRunnable %p)\n", This
, result
);
395 *result
= &This
->nsIRunnable_iface
;
398 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
399 return NS_NOINTERFACE
;
402 nsISupports_AddRef((nsISupports
*)*result
);
406 static nsrefcnt NSAPI
nsRunnable_AddRef(nsIRunnable
*iface
)
408 nsRunnable
*This
= impl_from_nsIRunnable(iface
);
409 LONG ref
= InterlockedIncrement(&This
->ref
);
411 TRACE("(%p) ref=%d\n", This
, ref
);
416 static nsrefcnt NSAPI
nsRunnable_Release(nsIRunnable
*iface
)
418 nsRunnable
*This
= impl_from_nsIRunnable(iface
);
419 LONG ref
= InterlockedDecrement(&This
->ref
);
421 TRACE("(%p) ref=%d\n", This
, ref
);
424 htmldoc_release(&This
->doc
->basedoc
);
426 nsISupports_Release(This
->arg1
);
428 nsISupports_Release(This
->arg2
);
435 static nsresult NSAPI
nsRunnable_Run(nsIRunnable
*iface
)
437 nsRunnable
*This
= impl_from_nsIRunnable(iface
);
439 return This
->proc(This
->doc
, This
->arg1
, This
->arg2
);
442 static const nsIRunnableVtbl nsRunnableVtbl
= {
443 nsRunnable_QueryInterface
,
449 static void add_script_runner(HTMLDocumentNode
*This
, runnable_proc_t proc
, nsISupports
*arg1
, nsISupports
*arg2
)
451 nsRunnable
*runnable
;
453 runnable
= heap_alloc_zero(sizeof(*runnable
));
457 runnable
->nsIRunnable_iface
.lpVtbl
= &nsRunnableVtbl
;
460 htmldoc_addref(&This
->basedoc
);
461 runnable
->doc
= This
;
462 runnable
->proc
= proc
;
465 nsISupports_AddRef(arg1
);
466 runnable
->arg1
= arg1
;
469 nsISupports_AddRef(arg2
);
470 runnable
->arg2
= arg2
;
472 nsIContentUtils_AddScriptRunner(content_utils
, &runnable
->nsIRunnable_iface
);
474 nsIRunnable_Release(&runnable
->nsIRunnable_iface
);
477 static inline HTMLDocumentNode
*impl_from_nsIDocumentObserver(nsIDocumentObserver
*iface
)
479 return CONTAINING_RECORD(iface
, HTMLDocumentNode
, nsIDocumentObserver_iface
);
482 static nsresult NSAPI
nsDocumentObserver_QueryInterface(nsIDocumentObserver
*iface
,
483 nsIIDRef riid
, void **result
)
485 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
487 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
488 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
489 *result
= &This
->nsIDocumentObserver_iface
;
490 }else if(IsEqualGUID(&IID_nsIMutationObserver
, riid
)) {
491 TRACE("(%p)->(IID_nsIMutationObserver %p)\n", This
, result
);
492 *result
= &This
->nsIDocumentObserver_iface
;
493 }else if(IsEqualGUID(&IID_nsIDocumentObserver
, riid
)) {
494 TRACE("(%p)->(IID_nsIDocumentObserver %p)\n", This
, result
);
495 *result
= &This
->nsIDocumentObserver_iface
;
498 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
499 return NS_NOINTERFACE
;
502 htmldoc_addref(&This
->basedoc
);
506 static nsrefcnt NSAPI
nsDocumentObserver_AddRef(nsIDocumentObserver
*iface
)
508 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
509 return htmldoc_addref(&This
->basedoc
);
512 static nsrefcnt NSAPI
nsDocumentObserver_Release(nsIDocumentObserver
*iface
)
514 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
515 return htmldoc_release(&This
->basedoc
);
518 static void NSAPI
nsDocumentObserver_CharacterDataWillChange(nsIDocumentObserver
*iface
,
519 nsIDocument
*aDocument
, nsIContent
*aContent
, void /*CharacterDataChangeInfo*/ *aInfo
)
523 static void NSAPI
nsDocumentObserver_CharacterDataChanged(nsIDocumentObserver
*iface
,
524 nsIDocument
*aDocument
, nsIContent
*aContent
, void /*CharacterDataChangeInfo*/ *aInfo
)
528 static void NSAPI
nsDocumentObserver_AttributeWillChange(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
529 nsIContent
*aContent
, LONG aNameSpaceID
, nsIAtom
*aAttribute
, LONG aModType
)
533 static void NSAPI
nsDocumentObserver_AttributeChanged(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
534 nsIContent
*aContent
, LONG aNameSpaceID
, nsIAtom
*aAttribute
, LONG aModType
)
538 static void NSAPI
nsDocumentObserver_AttributeSetToCurrentValue(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
539 void *aElement
, LONG aNameSpaceID
, nsIAtom
*aAttribute
)
543 static void NSAPI
nsDocumentObserver_ContentAppended(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
544 nsIContent
*aContainer
, nsIContent
*aFirstNewContent
, LONG aNewIndexInContainer
)
548 static void NSAPI
nsDocumentObserver_ContentInserted(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
549 nsIContent
*aContainer
, nsIContent
*aChild
, LONG aIndexInContainer
)
553 static void NSAPI
nsDocumentObserver_ContentRemoved(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
554 nsIContent
*aContainer
, nsIContent
*aChild
, LONG aIndexInContainer
,
555 nsIContent
*aProviousSibling
)
559 static void NSAPI
nsDocumentObserver_NodeWillBeDestroyed(nsIDocumentObserver
*iface
, const nsINode
*aNode
)
563 static void NSAPI
nsDocumentObserver_ParentChainChanged(nsIDocumentObserver
*iface
, nsIContent
*aContent
)
567 static void NSAPI
nsDocumentObserver_BeginUpdate(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
568 nsUpdateType aUpdateType
)
572 static void NSAPI
nsDocumentObserver_EndUpdate(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
573 nsUpdateType aUpdateType
)
577 static void NSAPI
nsDocumentObserver_BeginLoad(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
)
581 static void NSAPI
nsDocumentObserver_EndLoad(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
)
583 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
585 TRACE("(%p)\n", This
);
587 if(This
->skip_mutation_notif
)
590 This
->content_ready
= TRUE
;
591 add_script_runner(This
, run_end_load
, NULL
, NULL
);
594 static void NSAPI
nsDocumentObserver_ContentStatesChanged(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
595 nsIContent
*aContent
, EventStates aStateMask
)
599 static void NSAPI
nsDocumentObserver_DocumentStatesChanged(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
600 EventStates aStateMask
)
604 static void NSAPI
nsDocumentObserver_StyleSheetAdded(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
605 nsIStyleSheet
*aStyleSheet
, cpp_bool aDocumentSheet
)
609 static void NSAPI
nsDocumentObserver_StyleSheetRemoved(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
610 nsIStyleSheet
*aStyleSheet
, cpp_bool aDocumentSheet
)
614 static void NSAPI
nsDocumentObserver_StyleSheetApplicableStateChanged(nsIDocumentObserver
*iface
,
615 nsIDocument
*aDocument
, nsIStyleSheet
*aStyleSheet
, cpp_bool aApplicable
)
619 static void NSAPI
nsDocumentObserver_StyleRuleChanged(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
620 nsIStyleSheet
*aStyleSheet
, nsIStyleRule
*aOldStyleRule
, nsIStyleSheet
*aNewStyleRule
)
624 static void NSAPI
nsDocumentObserver_StyleRuleAdded(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
625 nsIStyleSheet
*aStyleSheet
, nsIStyleRule
*aStyleRule
)
629 static void NSAPI
nsDocumentObserver_StyleRuleRemoved(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
630 nsIStyleSheet
*aStyleSheet
, nsIStyleRule
*aStyleRule
)
634 static void NSAPI
nsDocumentObserver_BindToDocument(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
635 nsIContent
*aContent
)
637 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
638 nsIDOMHTMLIFrameElement
*nsiframe
;
639 nsIDOMHTMLFrameElement
*nsframe
;
640 nsIDOMHTMLScriptElement
*nsscript
;
641 nsIDOMHTMLElement
*nselem
;
642 nsIDOMComment
*nscomment
;
645 TRACE("(%p)->(%p %p)\n", This
, aDocument
, aContent
);
647 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLElement
, (void**)&nselem
);
648 if(NS_SUCCEEDED(nsres
)) {
649 check_event_attr(This
, nselem
);
650 nsIDOMHTMLElement_Release(nselem
);
653 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMComment
, (void**)&nscomment
);
654 if(NS_SUCCEEDED(nsres
)) {
655 TRACE("comment node\n");
657 add_script_runner(This
, run_insert_comment
, (nsISupports
*)nscomment
, NULL
);
658 nsIDOMComment_Release(nscomment
);
662 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLIFrameElement
, (void**)&nsiframe
);
663 if(NS_SUCCEEDED(nsres
)) {
664 TRACE("iframe node\n");
666 add_script_runner(This
, run_bind_to_tree
, (nsISupports
*)nsiframe
, NULL
);
667 nsIDOMHTMLIFrameElement_Release(nsiframe
);
671 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLFrameElement
, (void**)&nsframe
);
672 if(NS_SUCCEEDED(nsres
)) {
673 TRACE("frame node\n");
675 add_script_runner(This
, run_bind_to_tree
, (nsISupports
*)nsframe
, NULL
);
676 nsIDOMHTMLFrameElement_Release(nsframe
);
680 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLScriptElement
, (void**)&nsscript
);
681 if(NS_SUCCEEDED(nsres
)) {
682 HTMLScriptElement
*script_elem
;
685 TRACE("script element\n");
687 hres
= script_elem_from_nsscript(This
, nsscript
, &script_elem
);
688 nsIDOMHTMLScriptElement_Release(nsscript
);
692 if(script_elem
->parse_on_bind
)
693 add_script_runner(This
, run_insert_script
, (nsISupports
*)nsscript
, NULL
);
695 IHTMLScriptElement_Release(&script_elem
->IHTMLScriptElement_iface
);
699 static void NSAPI
nsDocumentObserver_AttemptToExecuteScript(nsIDocumentObserver
*iface
, nsIContent
*aContent
,
700 nsIParser
*aParser
, cpp_bool
*aBlock
)
702 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
703 nsIDOMHTMLScriptElement
*nsscript
;
706 TRACE("(%p)->(%p %p %p)\n", This
, aContent
, aParser
, aBlock
);
708 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLScriptElement
, (void**)&nsscript
);
709 if(NS_SUCCEEDED(nsres
)) {
710 TRACE("script node\n");
712 add_script_runner(This
, run_insert_script
, (nsISupports
*)nsscript
, (nsISupports
*)aParser
);
713 nsIDOMHTMLScriptElement_Release(nsscript
);
717 static const nsIDocumentObserverVtbl nsDocumentObserverVtbl
= {
718 nsDocumentObserver_QueryInterface
,
719 nsDocumentObserver_AddRef
,
720 nsDocumentObserver_Release
,
721 nsDocumentObserver_CharacterDataWillChange
,
722 nsDocumentObserver_CharacterDataChanged
,
723 nsDocumentObserver_AttributeWillChange
,
724 nsDocumentObserver_AttributeChanged
,
725 nsDocumentObserver_AttributeSetToCurrentValue
,
726 nsDocumentObserver_ContentAppended
,
727 nsDocumentObserver_ContentInserted
,
728 nsDocumentObserver_ContentRemoved
,
729 nsDocumentObserver_NodeWillBeDestroyed
,
730 nsDocumentObserver_ParentChainChanged
,
731 nsDocumentObserver_BeginUpdate
,
732 nsDocumentObserver_EndUpdate
,
733 nsDocumentObserver_BeginLoad
,
734 nsDocumentObserver_EndLoad
,
735 nsDocumentObserver_ContentStatesChanged
,
736 nsDocumentObserver_DocumentStatesChanged
,
737 nsDocumentObserver_StyleSheetAdded
,
738 nsDocumentObserver_StyleSheetRemoved
,
739 nsDocumentObserver_StyleSheetApplicableStateChanged
,
740 nsDocumentObserver_StyleRuleChanged
,
741 nsDocumentObserver_StyleRuleAdded
,
742 nsDocumentObserver_StyleRuleRemoved
,
743 nsDocumentObserver_BindToDocument
,
744 nsDocumentObserver_AttemptToExecuteScript
747 void init_document_mutation(HTMLDocumentNode
*doc
)
752 doc
->nsIDocumentObserver_iface
.lpVtbl
= &nsDocumentObserverVtbl
;
754 nsres
= nsIDOMHTMLDocument_QueryInterface(doc
->nsdoc
, &IID_nsIDocument
, (void**)&nsdoc
);
755 if(NS_FAILED(nsres
)) {
756 ERR("Could not get nsIDocument: %08x\n", nsres
);
760 nsIContentUtils_AddDocumentObserver(content_utils
, nsdoc
, &doc
->nsIDocumentObserver_iface
);
761 nsIDocument_Release(nsdoc
);
764 void release_document_mutation(HTMLDocumentNode
*doc
)
769 nsres
= nsIDOMHTMLDocument_QueryInterface(doc
->nsdoc
, &IID_nsIDocument
, (void**)&nsdoc
);
770 if(NS_FAILED(nsres
)) {
771 ERR("Could not get nsIDocument: %08x\n", nsres
);
775 nsIContentUtils_RemoveDocumentObserver(content_utils
, nsdoc
, &doc
->nsIDocumentObserver_iface
);
776 nsIDocument_Release(nsdoc
);
779 JSContext
*get_context_from_document(nsIDOMHTMLDocument
*nsdoc
)
785 nsres
= nsIDOMHTMLDocument_QueryInterface(nsdoc
, &IID_nsIDocument
, (void**)&doc
);
786 assert(nsres
== NS_OK
);
788 ctx
= nsIContentUtils_GetContextFromDocument(content_utils
, doc
);
789 nsIDocument_Release(doc
);
791 TRACE("ret %p\n", ctx
);
795 void init_mutation(nsIComponentManager
*component_manager
)
800 if(!component_manager
) {
802 nsIContentUtils_Release(content_utils
);
803 content_utils
= NULL
;
808 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_ICONTENTUTILS_CID
,
809 &IID_nsIFactory
, (void**)&factory
);
810 if(NS_FAILED(nsres
)) {
811 ERR("Could not create nsIContentUtils service: %08x\n", nsres
);
815 nsres
= nsIFactory_CreateInstance(factory
, NULL
, &IID_nsIContentUtils
, (void**)&content_utils
);
816 nsIFactory_Release(factory
);
818 ERR("Could not create nsIContentUtils instance: %08x\n", nsres
);