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
31 #include "mshtml_private.h"
32 #include "htmlscript.h"
33 #include "htmlevent.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
40 const compat_mode_info_t compat_mode_info
[] = {
41 { 5, 7 }, /* DOCMODE_QUIRKS */
42 { 5, 5 }, /* DOCMODE_IE5 */
43 { 7, 7 }, /* DOCMODE_IE7 */
44 { 8, 8 }, /* DOCMODE_IE8 */
45 { 9, 9 }, /* DOCMODE_IE8 */
46 { 10, 10 }, /* DOCMODE_IE10 */
47 { 11, 11 } /* DOCMODE_IE11 */
50 static const IID NS_ICONTENTUTILS_CID
=
51 {0x762C4AE7,0xB923,0x422F,{0xB9,0x7E,0xB9,0xBF,0xC1,0xEF,0x7B,0xF0}};
53 static nsIContentUtils
*content_utils
;
55 static PRUnichar
*handle_insert_comment(HTMLDocumentNode
*doc
, const PRUnichar
*comment
)
57 unsigned majorv
= 0, minorv
= 0, compat_version
;
58 const PRUnichar
*ptr
, *end
;
70 static const PRUnichar endifW
[] = {'<','!','[','e','n','d','i','f',']'};
72 if(comment
[0] != '[' || comment
[1] != 'i' || comment
[2] != 'f')
79 if(ptr
[0] == 'l' && ptr
[1] == 't') {
87 }else if(ptr
[0] == 'g' && ptr
[1] == 't') {
102 if(ptr
[0] != 'I' || ptr
[1] != 'E')
106 if(!iswspace(*ptr
++))
108 while(iswspace(*ptr
))
113 while(is_digit(*ptr
))
114 majorv
= majorv
*10 + (*ptr
++ - '0');
120 while(is_digit(*ptr
))
121 minorv
= minorv
*10 + (*ptr
++ - '0');
124 while(iswspace(*ptr
))
126 if(ptr
[0] != ']' || ptr
[1] != '>')
131 if(len
< ARRAY_SIZE(endifW
))
134 end
= ptr
+ len
- ARRAY_SIZE(endifW
);
135 if(memcmp(end
, endifW
, sizeof(endifW
)))
138 compat_version
= compat_mode_info
[doc
->document_mode
].ie_version
;
142 if(compat_version
== majorv
&& !minorv
)
146 if(compat_version
< majorv
|| (compat_version
== majorv
&& minorv
))
150 if(compat_version
<= majorv
)
154 if(compat_version
> majorv
)
158 if(compat_version
>= majorv
|| (compat_version
== majorv
&& !minorv
))
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(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
->nscontainer
->usermode
== EDITMODE
)
263 init_editor(doc
->basedoc
.doc_node
);
265 call_explorer_69(doc
);
267 IAdviseSink_OnViewChange(doc
->view_sink
, DVASPECT_CONTENT
, -1);
268 call_property_onchanged(&doc
->basedoc
.cp_container
, 1005);
269 call_explorer_69(doc
);
271 if(doc
->webbrowser
&& doc
->nscontainer
->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(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
, TRUE
);
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 if(!iter
->script
->parsed
)
345 doc_insert_script(window
, iter
->script
, TRUE
);
346 IHTMLScriptElement_Release(&iter
->script
->IHTMLScriptElement_iface
);
350 IHTMLWindow2_Release(&window
->base
.IHTMLWindow2_iface
);
353 window
->parser_callback_cnt
--;
354 nsIParser_EndEvaluatingParserInsertedScript(nsparser
);
355 nsIParser_Release(nsparser
);
358 IHTMLScriptElement_Release(&script_elem
->IHTMLScriptElement_iface
);
364 * We may change document mode only in early stage of document lifetime.
365 * Later attempts will not have an effect.
367 compat_mode_t
lock_document_mode(HTMLDocumentNode
*doc
)
369 TRACE("%p: %d\n", doc
, doc
->document_mode
);
371 doc
->document_mode_locked
= TRUE
;
372 return doc
->document_mode
;
375 static void set_document_mode(HTMLDocumentNode
*doc
, compat_mode_t document_mode
, BOOL lock
)
377 compat_mode_t max_compat_mode
;
379 if(doc
->document_mode_locked
) {
380 WARN("attempting to set document mode %d on locked document %p\n", document_mode
, doc
);
384 TRACE("%p: %d\n", doc
, document_mode
);
386 max_compat_mode
= doc
->window
&& doc
->window
->base
.outer_window
387 ? get_max_compat_mode(doc
->window
->base
.outer_window
->uri
)
389 if(max_compat_mode
< document_mode
) {
390 WARN("Tried to set compat mode %u higher than maximal configured %u\n",
391 document_mode
, max_compat_mode
);
392 document_mode
= max_compat_mode
;
395 doc
->document_mode
= document_mode
;
397 lock_document_mode(doc
);
400 BOOL
parse_compat_version(const WCHAR
*version_string
, compat_mode_t
*r
)
405 for(p
= version_string
; '0' <= *p
&& *p
<= '9'; p
++)
406 version
= version
* 10 + *p
-'0';
407 if((*p
&& *p
!= ';') || p
== version_string
)
413 *r
= COMPAT_MODE_IE5
;
416 *r
= COMPAT_MODE_IE7
;
419 *r
= COMPAT_MODE_IE8
;
422 *r
= COMPAT_MODE_IE9
;
425 *r
= COMPAT_MODE_IE10
;
428 *r
= version
< 5 ? COMPAT_MODE_QUIRKS
: COMPAT_MODE_IE11
;
433 static BOOL
parse_ua_compatible(const WCHAR
*p
, compat_mode_t
*r
)
435 static const WCHAR ie_eqW
[] = {'I','E','='};
436 static const WCHAR edgeW
[] = {'e','d','g','e'};
438 TRACE("%s\n", debugstr_w(p
));
440 if(wcsnicmp(ie_eqW
, p
, ARRAY_SIZE(ie_eqW
)))
444 if(!wcsnicmp(p
, edgeW
, ARRAY_SIZE(edgeW
))) {
445 p
+= ARRAY_SIZE(edgeW
);
448 *r
= COMPAT_MODE_IE11
;
452 return parse_compat_version(p
, r
);
455 void process_document_response_headers(HTMLDocumentNode
*doc
, IBinding
*binding
)
457 IWinInetHttpInfo
*http_info
;
462 hres
= IBinding_QueryInterface(binding
, &IID_IWinInetHttpInfo
, (void**)&http_info
);
464 TRACE("No IWinInetHttpInfo\n");
469 strcpy(buf
, "X-UA-Compatible");
470 hres
= IWinInetHttpInfo_QueryInfo(http_info
, HTTP_QUERY_CUSTOM
, buf
, &size
, NULL
, NULL
);
471 if(hres
== S_OK
&& size
) {
472 compat_mode_t document_mode
;
475 TRACE("size %u\n", size
);
477 header
= heap_strdupAtoW(buf
);
478 if(header
&& parse_ua_compatible(header
, &document_mode
)) {
479 TRACE("setting document mode %d\n", document_mode
);
480 set_document_mode(doc
, document_mode
, FALSE
);
485 IWinInetHttpInfo_Release(http_info
);
488 static void process_meta_element(HTMLDocumentNode
*doc
, nsIDOMHTMLMetaElement
*meta_element
)
490 nsAString http_equiv_str
, content_str
;
493 nsAString_Init(&http_equiv_str
, NULL
);
494 nsAString_Init(&content_str
, NULL
);
495 nsres
= nsIDOMHTMLMetaElement_GetHttpEquiv(meta_element
, &http_equiv_str
);
496 if(NS_SUCCEEDED(nsres
))
497 nsres
= nsIDOMHTMLMetaElement_GetContent(meta_element
, &content_str
);
499 if(NS_SUCCEEDED(nsres
)) {
500 const PRUnichar
*http_equiv
, *content
;
502 nsAString_GetData(&http_equiv_str
, &http_equiv
);
503 nsAString_GetData(&content_str
, &content
);
505 TRACE("%s: %s\n", debugstr_w(http_equiv
), debugstr_w(content
));
507 if(!wcsicmp(http_equiv
, L
"x-ua-compatible")) {
508 compat_mode_t document_mode
;
509 if(parse_ua_compatible(content
, &document_mode
))
510 set_document_mode(doc
, document_mode
, TRUE
);
512 FIXME("Unsupported document mode %s\n", debugstr_w(content
));
516 nsAString_Finish(&http_equiv_str
);
517 nsAString_Finish(&content_str
);
520 typedef struct nsRunnable nsRunnable
;
522 typedef nsresult (*runnable_proc_t
)(HTMLDocumentNode
*,nsISupports
*,nsISupports
*);
525 nsIRunnable nsIRunnable_iface
;
529 runnable_proc_t proc
;
531 HTMLDocumentNode
*doc
;
536 static inline nsRunnable
*impl_from_nsIRunnable(nsIRunnable
*iface
)
538 return CONTAINING_RECORD(iface
, nsRunnable
, nsIRunnable_iface
);
541 static nsresult NSAPI
nsRunnable_QueryInterface(nsIRunnable
*iface
,
542 nsIIDRef riid
, void **result
)
544 nsRunnable
*This
= impl_from_nsIRunnable(iface
);
546 if(IsEqualGUID(riid
, &IID_nsISupports
)) {
547 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
548 *result
= &This
->nsIRunnable_iface
;
549 }else if(IsEqualGUID(riid
, &IID_nsIRunnable
)) {
550 TRACE("(%p)->(IID_nsIRunnable %p)\n", This
, result
);
551 *result
= &This
->nsIRunnable_iface
;
554 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
555 return NS_NOINTERFACE
;
558 nsISupports_AddRef((nsISupports
*)*result
);
562 static nsrefcnt NSAPI
nsRunnable_AddRef(nsIRunnable
*iface
)
564 nsRunnable
*This
= impl_from_nsIRunnable(iface
);
565 LONG ref
= InterlockedIncrement(&This
->ref
);
567 TRACE("(%p) ref=%d\n", This
, ref
);
572 static nsrefcnt NSAPI
nsRunnable_Release(nsIRunnable
*iface
)
574 nsRunnable
*This
= impl_from_nsIRunnable(iface
);
575 LONG ref
= InterlockedDecrement(&This
->ref
);
577 TRACE("(%p) ref=%d\n", This
, ref
);
580 htmldoc_release(&This
->doc
->basedoc
);
582 nsISupports_Release(This
->arg1
);
584 nsISupports_Release(This
->arg2
);
591 static nsresult NSAPI
nsRunnable_Run(nsIRunnable
*iface
)
593 nsRunnable
*This
= impl_from_nsIRunnable(iface
);
595 return This
->proc(This
->doc
, This
->arg1
, This
->arg2
);
598 static const nsIRunnableVtbl nsRunnableVtbl
= {
599 nsRunnable_QueryInterface
,
605 static void add_script_runner(HTMLDocumentNode
*This
, runnable_proc_t proc
, nsISupports
*arg1
, nsISupports
*arg2
)
607 nsRunnable
*runnable
;
609 runnable
= heap_alloc_zero(sizeof(*runnable
));
613 runnable
->nsIRunnable_iface
.lpVtbl
= &nsRunnableVtbl
;
616 htmldoc_addref(&This
->basedoc
);
617 runnable
->doc
= This
;
618 runnable
->proc
= proc
;
621 nsISupports_AddRef(arg1
);
622 runnable
->arg1
= arg1
;
625 nsISupports_AddRef(arg2
);
626 runnable
->arg2
= arg2
;
628 nsIContentUtils_AddScriptRunner(content_utils
, &runnable
->nsIRunnable_iface
);
630 nsIRunnable_Release(&runnable
->nsIRunnable_iface
);
633 static inline HTMLDocumentNode
*impl_from_nsIDocumentObserver(nsIDocumentObserver
*iface
)
635 return CONTAINING_RECORD(iface
, HTMLDocumentNode
, nsIDocumentObserver_iface
);
638 static nsresult NSAPI
nsDocumentObserver_QueryInterface(nsIDocumentObserver
*iface
,
639 nsIIDRef riid
, void **result
)
641 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
643 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
644 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
645 *result
= &This
->nsIDocumentObserver_iface
;
646 }else if(IsEqualGUID(&IID_nsIMutationObserver
, riid
)) {
647 TRACE("(%p)->(IID_nsIMutationObserver %p)\n", This
, result
);
648 *result
= &This
->nsIDocumentObserver_iface
;
649 }else if(IsEqualGUID(&IID_nsIDocumentObserver
, riid
)) {
650 TRACE("(%p)->(IID_nsIDocumentObserver %p)\n", This
, result
);
651 *result
= &This
->nsIDocumentObserver_iface
;
654 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
655 return NS_NOINTERFACE
;
658 htmldoc_addref(&This
->basedoc
);
662 static nsrefcnt NSAPI
nsDocumentObserver_AddRef(nsIDocumentObserver
*iface
)
664 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
665 return htmldoc_addref(&This
->basedoc
);
668 static nsrefcnt NSAPI
nsDocumentObserver_Release(nsIDocumentObserver
*iface
)
670 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
671 return htmldoc_release(&This
->basedoc
);
674 static void NSAPI
nsDocumentObserver_CharacterDataWillChange(nsIDocumentObserver
*iface
,
675 nsIDocument
*aDocument
, nsIContent
*aContent
, void /*CharacterDataChangeInfo*/ *aInfo
)
679 static void NSAPI
nsDocumentObserver_CharacterDataChanged(nsIDocumentObserver
*iface
,
680 nsIDocument
*aDocument
, nsIContent
*aContent
, void /*CharacterDataChangeInfo*/ *aInfo
)
684 static void NSAPI
nsDocumentObserver_AttributeWillChange(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
685 void *aElement
, LONG aNameSpaceID
, nsIAtom
*aAttribute
, LONG aModType
, const nsAttrValue
*aNewValue
)
689 static void NSAPI
nsDocumentObserver_AttributeChanged(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
690 void *aElement
, LONG aNameSpaceID
, nsIAtom
*aAttribute
, LONG aModType
, const nsAttrValue
*aOldValue
)
694 static void NSAPI
nsDocumentObserver_NativeAnonymousChildListChange(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
695 nsIContent
*aContent
, cpp_bool aIsRemove
)
699 static void NSAPI
nsDocumentObserver_AttributeSetToCurrentValue(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
700 void *aElement
, LONG aNameSpaceID
, nsIAtom
*aAttribute
)
704 static void NSAPI
nsDocumentObserver_ContentAppended(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
705 nsIContent
*aContainer
, nsIContent
*aFirstNewContent
, LONG aNewIndexInContainer
)
709 static void NSAPI
nsDocumentObserver_ContentInserted(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
710 nsIContent
*aContainer
, nsIContent
*aChild
, LONG aIndexInContainer
)
714 static void NSAPI
nsDocumentObserver_ContentRemoved(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
715 nsIContent
*aContainer
, nsIContent
*aChild
, LONG aIndexInContainer
,
716 nsIContent
*aProviousSibling
)
720 static void NSAPI
nsDocumentObserver_NodeWillBeDestroyed(nsIDocumentObserver
*iface
, const nsINode
*aNode
)
724 static void NSAPI
nsDocumentObserver_ParentChainChanged(nsIDocumentObserver
*iface
, nsIContent
*aContent
)
728 static void NSAPI
nsDocumentObserver_BeginUpdate(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
729 nsUpdateType aUpdateType
)
733 static void NSAPI
nsDocumentObserver_EndUpdate(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
734 nsUpdateType aUpdateType
)
738 static void NSAPI
nsDocumentObserver_BeginLoad(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
)
742 static void NSAPI
nsDocumentObserver_EndLoad(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
)
744 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
746 TRACE("(%p)\n", This
);
748 if(This
->skip_mutation_notif
)
751 This
->content_ready
= TRUE
;
752 add_script_runner(This
, run_end_load
, NULL
, NULL
);
755 static void NSAPI
nsDocumentObserver_ContentStatesChanged(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
756 nsIContent
*aContent
, EventStates aStateMask
)
760 static void NSAPI
nsDocumentObserver_DocumentStatesChanged(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
761 EventStates aStateMask
)
765 static void NSAPI
nsDocumentObserver_StyleSheetAdded(nsIDocumentObserver
*iface
, mozilla_StyleSheetHandle aStyleSheet
,
766 cpp_bool aDocumentSheet
)
770 static void NSAPI
nsDocumentObserver_StyleSheetRemoved(nsIDocumentObserver
*iface
, mozilla_StyleSheetHandle aStyleSheet
,
771 cpp_bool aDocumentSheet
)
775 static void NSAPI
nsDocumentObserver_StyleSheetApplicableStateChanged(nsIDocumentObserver
*iface
,
776 mozilla_StyleSheetHandle aStyleSheet
)
780 static void NSAPI
nsDocumentObserver_StyleRuleChanged(nsIDocumentObserver
*iface
, mozilla_StyleSheetHandle aStyleSheet
)
784 static void NSAPI
nsDocumentObserver_StyleRuleAdded(nsIDocumentObserver
*iface
, mozilla_StyleSheetHandle aStyleSheet
)
788 static void NSAPI
nsDocumentObserver_StyleRuleRemoved(nsIDocumentObserver
*iface
, mozilla_StyleSheetHandle aStyleSheet
)
792 static void NSAPI
nsDocumentObserver_BindToDocument(nsIDocumentObserver
*iface
, nsIDocument
*aDocument
,
793 nsIContent
*aContent
)
795 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
796 nsIDOMHTMLIFrameElement
*nsiframe
;
797 nsIDOMHTMLFrameElement
*nsframe
;
798 nsIDOMHTMLScriptElement
*nsscript
;
799 nsIDOMHTMLMetaElement
*nsmeta
;
800 nsIDOMElement
*nselem
;
801 nsIDOMComment
*nscomment
;
804 TRACE("(%p)->(%p %p)\n", This
, aDocument
, aContent
);
806 if(This
->document_mode
< COMPAT_MODE_IE10
) {
807 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMComment
, (void**)&nscomment
);
808 if(NS_SUCCEEDED(nsres
)) {
809 TRACE("comment node\n");
811 add_script_runner(This
, run_insert_comment
, (nsISupports
*)nscomment
, NULL
);
812 nsIDOMComment_Release(nscomment
);
817 if(This
->document_mode
== COMPAT_MODE_QUIRKS
) {
818 nsIDOMDocumentType
*nsdoctype
;
820 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMDocumentType
, (void**)&nsdoctype
);
821 if(NS_SUCCEEDED(nsres
)) {
822 compat_mode_t mode
= COMPAT_MODE_IE7
;
824 TRACE("doctype node\n");
826 if(This
->window
&& This
->window
->base
.outer_window
) {
827 HTMLOuterWindow
*window
= This
->window
->base
.outer_window
;
831 /* Internet URL zone is treated differently and defaults to the latest supported mode. */
832 hres
= IInternetSecurityManager_MapUrlToZone(get_security_manager(), window
->url
, &zone
, 0);
833 if(SUCCEEDED(hres
) && zone
== URLZONE_INTERNET
)
834 mode
= COMPAT_MODE_IE11
;
837 set_document_mode(This
, mode
, FALSE
);
838 nsIDOMDocumentType_Release(nsdoctype
);
842 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMElement
, (void**)&nselem
);
846 check_event_attr(This
, nselem
);
847 nsIDOMElement_Release(nselem
);
849 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLIFrameElement
, (void**)&nsiframe
);
850 if(NS_SUCCEEDED(nsres
)) {
851 TRACE("iframe node\n");
853 add_script_runner(This
, run_bind_to_tree
, (nsISupports
*)nsiframe
, NULL
);
854 nsIDOMHTMLIFrameElement_Release(nsiframe
);
858 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLFrameElement
, (void**)&nsframe
);
859 if(NS_SUCCEEDED(nsres
)) {
860 TRACE("frame node\n");
862 add_script_runner(This
, run_bind_to_tree
, (nsISupports
*)nsframe
, NULL
);
863 nsIDOMHTMLFrameElement_Release(nsframe
);
867 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLScriptElement
, (void**)&nsscript
);
868 if(NS_SUCCEEDED(nsres
)) {
869 TRACE("script element\n");
871 add_script_runner(This
, run_bind_to_tree
, (nsISupports
*)nsscript
, NULL
);
872 nsIDOMHTMLScriptElement_Release(nsscript
);
876 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLMetaElement
, (void**)&nsmeta
);
877 if(NS_SUCCEEDED(nsres
)) {
878 process_meta_element(This
, nsmeta
);
879 nsIDOMHTMLMetaElement_Release(nsmeta
);
883 static void NSAPI
nsDocumentObserver_AttemptToExecuteScript(nsIDocumentObserver
*iface
, nsIContent
*aContent
,
884 nsIParser
*aParser
, cpp_bool
*aBlock
)
886 HTMLDocumentNode
*This
= impl_from_nsIDocumentObserver(iface
);
887 nsIDOMHTMLScriptElement
*nsscript
;
890 TRACE("(%p)->(%p %p %p)\n", This
, aContent
, aParser
, aBlock
);
892 nsres
= nsIContent_QueryInterface(aContent
, &IID_nsIDOMHTMLScriptElement
, (void**)&nsscript
);
893 if(NS_SUCCEEDED(nsres
)) {
894 TRACE("script node\n");
896 lock_document_mode(This
);
897 add_script_runner(This
, run_insert_script
, (nsISupports
*)nsscript
, (nsISupports
*)aParser
);
898 nsIDOMHTMLScriptElement_Release(nsscript
);
902 static const nsIDocumentObserverVtbl nsDocumentObserverVtbl
= {
903 nsDocumentObserver_QueryInterface
,
904 nsDocumentObserver_AddRef
,
905 nsDocumentObserver_Release
,
906 nsDocumentObserver_CharacterDataWillChange
,
907 nsDocumentObserver_CharacterDataChanged
,
908 nsDocumentObserver_AttributeWillChange
,
909 nsDocumentObserver_AttributeChanged
,
910 nsDocumentObserver_NativeAnonymousChildListChange
,
911 nsDocumentObserver_AttributeSetToCurrentValue
,
912 nsDocumentObserver_ContentAppended
,
913 nsDocumentObserver_ContentInserted
,
914 nsDocumentObserver_ContentRemoved
,
915 nsDocumentObserver_NodeWillBeDestroyed
,
916 nsDocumentObserver_ParentChainChanged
,
917 nsDocumentObserver_BeginUpdate
,
918 nsDocumentObserver_EndUpdate
,
919 nsDocumentObserver_BeginLoad
,
920 nsDocumentObserver_EndLoad
,
921 nsDocumentObserver_ContentStatesChanged
,
922 nsDocumentObserver_DocumentStatesChanged
,
923 nsDocumentObserver_StyleSheetAdded
,
924 nsDocumentObserver_StyleSheetRemoved
,
925 nsDocumentObserver_StyleSheetApplicableStateChanged
,
926 nsDocumentObserver_StyleRuleChanged
,
927 nsDocumentObserver_StyleRuleAdded
,
928 nsDocumentObserver_StyleRuleRemoved
,
929 nsDocumentObserver_BindToDocument
,
930 nsDocumentObserver_AttemptToExecuteScript
933 void init_document_mutation(HTMLDocumentNode
*doc
)
938 doc
->nsIDocumentObserver_iface
.lpVtbl
= &nsDocumentObserverVtbl
;
940 nsres
= nsIDOMHTMLDocument_QueryInterface(doc
->nsdoc
, &IID_nsIDocument
, (void**)&nsdoc
);
941 if(NS_FAILED(nsres
)) {
942 ERR("Could not get nsIDocument: %08x\n", nsres
);
946 nsIContentUtils_AddDocumentObserver(content_utils
, nsdoc
, &doc
->nsIDocumentObserver_iface
);
947 nsIDocument_Release(nsdoc
);
950 void release_document_mutation(HTMLDocumentNode
*doc
)
955 nsres
= nsIDOMHTMLDocument_QueryInterface(doc
->nsdoc
, &IID_nsIDocument
, (void**)&nsdoc
);
956 if(NS_FAILED(nsres
)) {
957 ERR("Could not get nsIDocument: %08x\n", nsres
);
961 nsIContentUtils_RemoveDocumentObserver(content_utils
, nsdoc
, &doc
->nsIDocumentObserver_iface
);
962 nsIDocument_Release(nsdoc
);
965 JSContext
*get_context_from_document(nsIDOMHTMLDocument
*nsdoc
)
971 nsres
= nsIDOMHTMLDocument_QueryInterface(nsdoc
, &IID_nsIDocument
, (void**)&doc
);
972 assert(nsres
== NS_OK
);
974 ctx
= nsIContentUtils_GetContextFromDocument(content_utils
, doc
);
975 nsIDocument_Release(doc
);
977 TRACE("ret %p\n", ctx
);
981 void init_mutation(nsIComponentManager
*component_manager
)
986 if(!component_manager
) {
988 nsIContentUtils_Release(content_utils
);
989 content_utils
= NULL
;
994 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_ICONTENTUTILS_CID
,
995 &IID_nsIFactory
, (void**)&factory
);
996 if(NS_FAILED(nsres
)) {
997 ERR("Could not create nsIContentUtils service: %08x\n", nsres
);
1001 nsres
= nsIFactory_CreateInstance(factory
, NULL
, &IID_nsIContentUtils
, (void**)&content_utils
);
1002 nsIFactory_Release(factory
);
1003 if(NS_FAILED(nsres
))
1004 ERR("Could not create nsIContentUtils instance: %08x\n", nsres
);