2008-12-30 06:48:59 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "ole2.h"
|
2009-11-08 15:40:11 +01:00
|
|
|
#include "shlguid.h"
|
2008-12-30 06:48:59 +01:00
|
|
|
|
|
|
|
#include "mshtml_private.h"
|
|
|
|
#include "htmlevent.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
|
|
|
|
|
|
|
|
enum {
|
2009-12-03 01:12:12 +01:00
|
|
|
MUTATION_BINDTOTREE,
|
2008-12-30 06:48:59 +01:00
|
|
|
MUTATION_COMMENT,
|
2009-11-01 19:24:34 +01:00
|
|
|
MUTATION_ENDLOAD,
|
2008-12-30 06:48:59 +01:00
|
|
|
MUTATION_SCRIPT
|
|
|
|
};
|
|
|
|
|
2008-12-30 21:20:57 +01:00
|
|
|
#define IE_MAJOR_VERSION 7
|
|
|
|
#define IE_MINOR_VERSION 0
|
|
|
|
|
2009-10-21 21:27:42 +02:00
|
|
|
static BOOL handle_insert_comment(HTMLDocumentNode *doc, const PRUnichar *comment)
|
2008-12-30 21:20:57 +01:00
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
int majorv = 0, minorv = 0;
|
|
|
|
const PRUnichar *ptr, *end;
|
|
|
|
nsAString nsstr;
|
|
|
|
PRUnichar *buf;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CMP_EQ,
|
|
|
|
CMP_LT,
|
|
|
|
CMP_LTE,
|
|
|
|
CMP_GT,
|
|
|
|
CMP_GTE
|
|
|
|
} cmpt = CMP_EQ;
|
|
|
|
|
|
|
|
static const PRUnichar endifW[] = {'<','!','[','e','n','d','i','f',']'};
|
|
|
|
|
|
|
|
if(comment[0] != '[' || comment[1] != 'i' || comment[2] != 'f')
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
ptr = comment+3;
|
|
|
|
while(isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
if(ptr[0] == 'l' && ptr[1] == 't') {
|
|
|
|
ptr += 2;
|
|
|
|
if(*ptr == 'e') {
|
|
|
|
cmpt = CMP_LTE;
|
|
|
|
ptr++;
|
|
|
|
}else {
|
|
|
|
cmpt = CMP_LT;
|
|
|
|
}
|
|
|
|
}else if(ptr[0] == 'g' && ptr[1] == 't') {
|
|
|
|
ptr += 2;
|
|
|
|
if(*ptr == 'e') {
|
|
|
|
cmpt = CMP_GTE;
|
|
|
|
ptr++;
|
|
|
|
}else {
|
|
|
|
cmpt = CMP_GT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!isspaceW(*ptr++))
|
|
|
|
return FALSE;
|
|
|
|
while(isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
if(ptr[0] != 'I' || ptr[1] != 'E')
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
ptr +=2;
|
|
|
|
if(!isspaceW(*ptr++))
|
|
|
|
return FALSE;
|
|
|
|
while(isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
if(!isdigitW(*ptr))
|
|
|
|
return FALSE;
|
|
|
|
while(isdigitW(*ptr))
|
|
|
|
majorv = majorv*10 + (*ptr++ - '0');
|
|
|
|
|
|
|
|
if(*ptr == '.') {
|
2008-12-31 17:16:23 +01:00
|
|
|
ptr++;
|
2008-12-30 21:20:57 +01:00
|
|
|
if(!isdigitW(*ptr))
|
|
|
|
return FALSE;
|
|
|
|
while(isdigitW(*ptr))
|
|
|
|
minorv = minorv*10 + (*ptr++ - '0');
|
|
|
|
}
|
|
|
|
|
|
|
|
while(isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
if(ptr[0] != ']' || ptr[1] != '>')
|
|
|
|
return FALSE;
|
|
|
|
ptr += 2;
|
|
|
|
|
|
|
|
len = strlenW(ptr);
|
|
|
|
if(len < sizeof(endifW)/sizeof(WCHAR))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
end = ptr + len-sizeof(endifW)/sizeof(WCHAR);
|
|
|
|
if(memcmp(end, endifW, sizeof(endifW)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch(cmpt) {
|
|
|
|
case CMP_EQ:
|
|
|
|
if(majorv == IE_MAJOR_VERSION && minorv == IE_MINOR_VERSION)
|
|
|
|
break;
|
|
|
|
return FALSE;
|
|
|
|
case CMP_LT:
|
|
|
|
if(majorv > IE_MAJOR_VERSION)
|
|
|
|
break;
|
|
|
|
if(majorv == IE_MAJOR_VERSION && minorv > IE_MINOR_VERSION)
|
|
|
|
break;
|
|
|
|
return FALSE;
|
|
|
|
case CMP_LTE:
|
|
|
|
if(majorv > IE_MAJOR_VERSION)
|
|
|
|
break;
|
|
|
|
if(majorv == IE_MAJOR_VERSION && minorv >= IE_MINOR_VERSION)
|
|
|
|
break;
|
|
|
|
return FALSE;
|
|
|
|
case CMP_GT:
|
|
|
|
if(majorv < IE_MAJOR_VERSION)
|
|
|
|
break;
|
|
|
|
if(majorv == IE_MAJOR_VERSION && minorv < IE_MINOR_VERSION)
|
|
|
|
break;
|
|
|
|
return FALSE;
|
|
|
|
case CMP_GTE:
|
|
|
|
if(majorv < IE_MAJOR_VERSION)
|
|
|
|
break;
|
|
|
|
if(majorv == IE_MAJOR_VERSION && minorv <= IE_MINOR_VERSION)
|
|
|
|
break;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = heap_alloc((end-ptr+1)*sizeof(WCHAR));
|
|
|
|
if(!buf)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
memcpy(buf, ptr, (end-ptr)*sizeof(WCHAR));
|
|
|
|
buf[end-ptr] = 0;
|
2010-01-28 23:56:31 +01:00
|
|
|
nsAString_InitDepend(&nsstr, buf);
|
2008-12-30 21:20:57 +01:00
|
|
|
|
|
|
|
/* FIXME: Find better way to insert HTML to document. */
|
|
|
|
nsres = nsIDOMHTMLDocument_Write(doc->nsdoc, &nsstr);
|
|
|
|
nsAString_Finish(&nsstr);
|
2010-01-28 23:56:31 +01:00
|
|
|
heap_free(buf);
|
2008-12-30 21:20:57 +01:00
|
|
|
if(NS_FAILED(nsres)) {
|
|
|
|
ERR("Write failed: %08x\n", nsres);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-10-21 21:28:09 +02:00
|
|
|
static void add_script_runner(HTMLDocumentNode *This)
|
2008-12-30 06:48:59 +01:00
|
|
|
{
|
|
|
|
nsIDOMNSDocument *nsdoc;
|
|
|
|
nsresult nsres;
|
|
|
|
|
2009-10-21 21:28:09 +02:00
|
|
|
nsres = nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMNSDocument, (void**)&nsdoc);
|
2008-12-30 06:48:59 +01:00
|
|
|
if(NS_FAILED(nsres)) {
|
|
|
|
ERR("Could not get nsIDOMNSDocument: %08x\n", nsres);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMNSDocument_WineAddScriptRunner(nsdoc, NSRUNNABLE(This));
|
|
|
|
nsIDOMNSDocument_Release(nsdoc);
|
|
|
|
}
|
|
|
|
|
2009-10-21 21:28:09 +02:00
|
|
|
#define NSRUNNABLE_THIS(iface) DEFINE_THIS(HTMLDocumentNode, IRunnable, iface)
|
2008-12-30 06:48:59 +01:00
|
|
|
|
|
|
|
static nsresult NSAPI nsRunnable_QueryInterface(nsIRunnable *iface,
|
2010-08-02 11:08:26 +02:00
|
|
|
nsIIDRef riid, void **result)
|
2008-12-30 06:48:59 +01:00
|
|
|
{
|
2009-10-21 21:28:09 +02:00
|
|
|
HTMLDocumentNode *This = NSRUNNABLE_THIS(iface);
|
2008-12-30 06:48:59 +01:00
|
|
|
|
|
|
|
if(IsEqualGUID(riid, &IID_nsISupports)) {
|
|
|
|
TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
|
|
|
|
*result = NSRUNNABLE(This);
|
|
|
|
}else if(IsEqualGUID(riid, &IID_nsIRunnable)) {
|
|
|
|
TRACE("(%p)->(IID_nsIRunnable %p)\n", This, result);
|
|
|
|
*result = NSRUNNABLE(This);
|
|
|
|
}else {
|
|
|
|
*result = NULL;
|
|
|
|
WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsISupports_AddRef((nsISupports*)*result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsrefcnt NSAPI nsRunnable_AddRef(nsIRunnable *iface)
|
|
|
|
{
|
2009-10-21 21:28:09 +02:00
|
|
|
HTMLDocumentNode *This = NSRUNNABLE_THIS(iface);
|
|
|
|
return htmldoc_addref(&This->basedoc);
|
2008-12-30 06:48:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsrefcnt NSAPI nsRunnable_Release(nsIRunnable *iface)
|
|
|
|
{
|
2009-10-21 21:28:09 +02:00
|
|
|
HTMLDocumentNode *This = NSRUNNABLE_THIS(iface);
|
|
|
|
return htmldoc_release(&This->basedoc);
|
2008-12-30 06:48:59 +01:00
|
|
|
}
|
|
|
|
|
2009-11-01 19:24:34 +01:00
|
|
|
static void push_mutation_queue(HTMLDocumentNode *doc, DWORD type, nsISupports *nsiface)
|
|
|
|
{
|
|
|
|
mutation_queue_t *elem;
|
|
|
|
|
|
|
|
elem = heap_alloc(sizeof(mutation_queue_t));
|
|
|
|
if(!elem)
|
|
|
|
return;
|
|
|
|
|
|
|
|
elem->next = NULL;
|
|
|
|
elem->type = type;
|
|
|
|
elem->nsiface = nsiface;
|
|
|
|
if(nsiface)
|
|
|
|
nsISupports_AddRef(nsiface);
|
|
|
|
|
2009-11-01 19:24:55 +01:00
|
|
|
if(doc->mutation_queue_tail) {
|
2009-11-01 19:24:34 +01:00
|
|
|
doc->mutation_queue_tail = doc->mutation_queue_tail->next = elem;
|
2009-11-01 19:24:55 +01:00
|
|
|
}else {
|
2009-11-01 19:24:34 +01:00
|
|
|
doc->mutation_queue = doc->mutation_queue_tail = elem;
|
2009-11-01 19:24:55 +01:00
|
|
|
add_script_runner(doc);
|
|
|
|
}
|
2009-11-01 19:24:34 +01:00
|
|
|
}
|
|
|
|
|
2009-10-21 21:28:09 +02:00
|
|
|
static void pop_mutation_queue(HTMLDocumentNode *doc)
|
2008-12-30 06:48:59 +01:00
|
|
|
{
|
2009-10-21 21:28:09 +02:00
|
|
|
mutation_queue_t *tmp = doc->mutation_queue;
|
2008-12-30 06:48:59 +01:00
|
|
|
|
|
|
|
if(!tmp)
|
|
|
|
return;
|
|
|
|
|
2009-10-21 21:28:09 +02:00
|
|
|
doc->mutation_queue = tmp->next;
|
2008-12-30 06:48:59 +01:00
|
|
|
if(!tmp->next)
|
2009-10-21 21:28:09 +02:00
|
|
|
doc->mutation_queue_tail = NULL;
|
2008-12-30 06:48:59 +01:00
|
|
|
|
2009-11-01 19:24:34 +01:00
|
|
|
if(tmp->nsiface)
|
|
|
|
nsISupports_Release(tmp->nsiface);
|
2008-12-30 06:48:59 +01:00
|
|
|
heap_free(tmp);
|
|
|
|
}
|
|
|
|
|
2009-12-03 01:12:12 +01:00
|
|
|
static void bind_to_tree(HTMLDocumentNode *doc, nsISupports *nsiface)
|
2009-10-27 21:17:08 +01:00
|
|
|
{
|
2009-12-03 01:12:12 +01:00
|
|
|
nsIDOMNode *nsnode;
|
|
|
|
HTMLDOMNode *node;
|
2009-10-21 21:30:20 +02:00
|
|
|
nsresult nsres;
|
|
|
|
|
2009-12-03 01:12:12 +01:00
|
|
|
nsres = nsISupports_QueryInterface(nsiface, &IID_nsIDOMNode, (void**)&nsnode);
|
|
|
|
if(NS_FAILED(nsres))
|
|
|
|
return;
|
2009-11-01 19:19:41 +01:00
|
|
|
|
2009-12-03 01:12:12 +01:00
|
|
|
node = get_node(doc, nsnode, TRUE);
|
|
|
|
nsIDOMNode_Release(nsnode);
|
|
|
|
if(!node) {
|
|
|
|
ERR("Could not get node\n");
|
|
|
|
return;
|
2009-11-01 19:19:41 +01:00
|
|
|
}
|
2009-10-27 21:17:08 +01:00
|
|
|
|
2009-12-03 01:12:12 +01:00
|
|
|
if(node->vtbl->bind_to_tree)
|
|
|
|
node->vtbl->bind_to_tree(node);
|
2009-10-21 21:30:20 +02:00
|
|
|
}
|
|
|
|
|
2009-11-08 15:40:11 +01:00
|
|
|
/* Calls undocumented 69 cmd of CGID_Explorer */
|
|
|
|
static void call_explorer_69(HTMLDocumentObj *doc)
|
2009-11-01 19:24:34 +01:00
|
|
|
{
|
2009-11-08 15:40:11 +01:00
|
|
|
IOleCommandTarget *olecmd;
|
|
|
|
VARIANT var;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(!doc->client)
|
|
|
|
return;
|
|
|
|
|
|
|
|
hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return;
|
|
|
|
|
|
|
|
VariantInit(&var);
|
|
|
|
hres = IOleCommandTarget_Exec(olecmd, &CGID_Explorer, 69, 0, NULL, &var);
|
|
|
|
IOleCommandTarget_Release(olecmd);
|
|
|
|
if(SUCCEEDED(hres) && V_VT(&var) != VT_NULL)
|
|
|
|
FIXME("handle result\n");
|
|
|
|
}
|
|
|
|
|
2010-08-18 13:39:29 +02:00
|
|
|
static void parse_complete(HTMLDocumentObj *doc)
|
2009-11-08 15:40:11 +01:00
|
|
|
{
|
|
|
|
TRACE("(%p)\n", doc);
|
|
|
|
|
|
|
|
if(doc->usermode == EDITMODE)
|
|
|
|
init_editor(&doc->basedoc);
|
|
|
|
|
|
|
|
call_explorer_69(doc);
|
2010-02-15 16:03:25 +01:00
|
|
|
if(doc->view_sink)
|
|
|
|
IAdviseSink_OnViewChange(doc->view_sink, DVASPECT_CONTENT, -1);
|
2009-11-08 15:40:11 +01:00
|
|
|
call_property_onchanged(&doc->basedoc.cp_propnotif, 1005);
|
|
|
|
call_explorer_69(doc);
|
|
|
|
|
|
|
|
/* FIXME: IE7 calls EnableModelless(TRUE), EnableModelless(FALSE) and sets interactive state here */
|
2009-11-01 19:24:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_end_load(HTMLDocumentNode *This)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
|
2010-03-13 16:42:45 +01:00
|
|
|
if(!This->basedoc.doc_obj)
|
|
|
|
return;
|
|
|
|
|
2010-08-18 13:39:29 +02:00
|
|
|
if(This == This->basedoc.doc_obj->basedoc.doc_node) {
|
|
|
|
/*
|
|
|
|
* This should be done in the worker thread that parses HTML,
|
|
|
|
* but we don't have such thread (Gecko parses HTML for us).
|
|
|
|
*/
|
|
|
|
parse_complete(This->basedoc.doc_obj);
|
2009-11-01 19:24:55 +01:00
|
|
|
}
|
2009-11-01 19:24:34 +01:00
|
|
|
|
2010-08-18 13:39:29 +02:00
|
|
|
set_ready_state(This->basedoc.window, READYSTATE_INTERACTIVE);
|
2009-11-01 19:24:34 +01:00
|
|
|
}
|
|
|
|
|
2008-12-30 06:48:59 +01:00
|
|
|
static nsresult NSAPI nsRunnable_Run(nsIRunnable *iface)
|
|
|
|
{
|
2009-10-21 21:28:09 +02:00
|
|
|
HTMLDocumentNode *This = NSRUNNABLE_THIS(iface);
|
2008-12-30 06:48:59 +01:00
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
while(This->mutation_queue) {
|
|
|
|
switch(This->mutation_queue->type) {
|
2009-12-03 01:12:12 +01:00
|
|
|
case MUTATION_BINDTOTREE:
|
|
|
|
bind_to_tree(This, This->mutation_queue->nsiface);
|
|
|
|
break;
|
|
|
|
|
2008-12-30 06:48:59 +01:00
|
|
|
case MUTATION_COMMENT: {
|
|
|
|
nsIDOMComment *nscomment;
|
|
|
|
nsAString comment_str;
|
|
|
|
BOOL remove_comment = FALSE;
|
|
|
|
|
|
|
|
nsres = nsISupports_QueryInterface(This->mutation_queue->nsiface, &IID_nsIDOMComment, (void**)&nscomment);
|
|
|
|
if(NS_FAILED(nsres)) {
|
|
|
|
ERR("Could not get nsIDOMComment iface:%08x\n", nsres);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAString_Init(&comment_str, NULL);
|
|
|
|
nsres = nsIDOMComment_GetData(nscomment, &comment_str);
|
|
|
|
if(NS_SUCCEEDED(nsres)) {
|
|
|
|
const PRUnichar *comment;
|
|
|
|
|
|
|
|
nsAString_GetData(&comment_str, &comment);
|
2009-10-21 21:28:09 +02:00
|
|
|
remove_comment = handle_insert_comment(This, comment);
|
2008-12-30 06:48:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAString_Finish(&comment_str);
|
|
|
|
|
|
|
|
if(remove_comment) {
|
|
|
|
nsIDOMNode *nsparent, *tmp;
|
|
|
|
nsAString magic_str;
|
|
|
|
|
|
|
|
static const PRUnichar remove_comment_magicW[] =
|
|
|
|
{'#','!','w','i','n','e', 'r','e','m','o','v','e','!','#',0};
|
|
|
|
|
2010-01-28 23:56:31 +01:00
|
|
|
nsAString_InitDepend(&magic_str, remove_comment_magicW);
|
2008-12-30 06:48:59 +01:00
|
|
|
nsres = nsIDOMComment_SetData(nscomment, &magic_str);
|
|
|
|
nsAString_Finish(&magic_str);
|
|
|
|
if(NS_FAILED(nsres))
|
|
|
|
ERR("SetData failed: %08x\n", nsres);
|
|
|
|
|
|
|
|
nsIDOMComment_GetParentNode(nscomment, &nsparent);
|
|
|
|
if(nsparent) {
|
|
|
|
nsIDOMNode_RemoveChild(nsparent, (nsIDOMNode*)nscomment, &tmp);
|
|
|
|
nsIDOMNode_Release(nsparent);
|
|
|
|
nsIDOMNode_Release(tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMComment_Release(nscomment);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-11-01 19:24:34 +01:00
|
|
|
case MUTATION_ENDLOAD:
|
|
|
|
handle_end_load(This);
|
|
|
|
break;
|
|
|
|
|
2008-12-30 06:48:59 +01:00
|
|
|
case MUTATION_SCRIPT: {
|
|
|
|
nsIDOMHTMLScriptElement *nsscript;
|
|
|
|
|
|
|
|
nsres = nsISupports_QueryInterface(This->mutation_queue->nsiface, &IID_nsIDOMHTMLScriptElement,
|
|
|
|
(void**)&nsscript);
|
|
|
|
if(NS_FAILED(nsres)) {
|
|
|
|
ERR("Could not get nsIDOMHTMLScriptElement: %08x\n", nsres);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-21 21:28:09 +02:00
|
|
|
doc_insert_script(This->basedoc.window, nsscript);
|
2008-12-30 06:48:59 +01:00
|
|
|
nsIDOMHTMLScriptElement_Release(nsscript);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR("invalid type %d\n", This->mutation_queue->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
pop_mutation_queue(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef NSRUNNABLE_THIS
|
|
|
|
|
|
|
|
static const nsIRunnableVtbl nsRunnableVtbl = {
|
|
|
|
nsRunnable_QueryInterface,
|
|
|
|
nsRunnable_AddRef,
|
|
|
|
nsRunnable_Release,
|
|
|
|
nsRunnable_Run
|
|
|
|
};
|
|
|
|
|
2009-10-21 21:28:09 +02:00
|
|
|
#define NSDOCOBS_THIS(iface) DEFINE_THIS(HTMLDocumentNode, IDocumentObserver, iface)
|
2008-12-30 06:48:59 +01:00
|
|
|
|
|
|
|
static nsresult NSAPI nsDocumentObserver_QueryInterface(nsIDocumentObserver *iface,
|
2010-08-02 11:08:26 +02:00
|
|
|
nsIIDRef riid, void **result)
|
2008-12-30 06:48:59 +01:00
|
|
|
{
|
2009-10-21 21:28:09 +02:00
|
|
|
HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
|
2008-12-30 06:48:59 +01:00
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_nsISupports, riid)) {
|
|
|
|
TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
|
2009-02-05 00:53:54 +01:00
|
|
|
*result = NSDOCOBS(This);
|
2008-12-30 06:48:59 +01:00
|
|
|
}else if(IsEqualGUID(&IID_nsIMutationObserver, riid)) {
|
|
|
|
TRACE("(%p)->(IID_nsIMutationObserver %p)\n", This, result);
|
|
|
|
*result = NSDOCOBS(This);
|
|
|
|
}else if(IsEqualGUID(&IID_nsIDocumentObserver, riid)) {
|
|
|
|
TRACE("(%p)->(IID_nsIDocumentObserver %p)\n", This, result);
|
|
|
|
*result = NSDOCOBS(This);
|
|
|
|
}else {
|
|
|
|
*result = NULL;
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2009-10-21 21:28:09 +02:00
|
|
|
htmldoc_addref(&This->basedoc);
|
2008-12-30 06:48:59 +01:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsrefcnt NSAPI nsDocumentObserver_AddRef(nsIDocumentObserver *iface)
|
|
|
|
{
|
2009-10-21 21:28:09 +02:00
|
|
|
HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
|
|
|
|
return htmldoc_addref(&This->basedoc);
|
2008-12-30 06:48:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsrefcnt NSAPI nsDocumentObserver_Release(nsIDocumentObserver *iface)
|
|
|
|
{
|
2009-10-21 21:28:09 +02:00
|
|
|
HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
|
|
|
|
return htmldoc_release(&This->basedoc);
|
2008-12-30 06:48:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_CharacterDataWillChange(nsIDocumentObserver *iface,
|
|
|
|
nsIDocument *aDocument, nsIContent *aContent, void /*CharacterDataChangeInfo*/ *aInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_CharacterDataChanged(nsIDocumentObserver *iface,
|
|
|
|
nsIDocument *aDocument, nsIContent *aContent, void /*CharacterDataChangeInfo*/ *aInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-08-04 14:05:05 +02:00
|
|
|
static void NSAPI nsDocumentObserver_AttributeWillChange(nsIDocumentObserver *iface, nsIDocument *aDocument,
|
|
|
|
nsIContent *aContent, PRInt32 aNameSpaceID, nsIAtom *aAttribute, PRInt32 aModType)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-12-30 06:48:59 +01:00
|
|
|
static void NSAPI nsDocumentObserver_AttributeChanged(nsIDocumentObserver *iface, nsIDocument *aDocument,
|
|
|
|
nsIContent *aContent, PRInt32 aNameSpaceID, nsIAtom *aAttribute, PRInt32 aModType, PRUint32 aStateMask)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_ContentAppended(nsIDocumentObserver *iface, nsIDocument *aDocument,
|
|
|
|
nsIContent *aContainer, PRInt32 aNewIndexInContainer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_ContentInserted(nsIDocumentObserver *iface, nsIDocument *aDocument,
|
|
|
|
nsIContent *aContainer, nsIContent *aChild, PRInt32 aIndexInContainer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_ContentRemoved(nsIDocumentObserver *iface, nsIDocument *aDocument,
|
|
|
|
nsIContent *aContainer, nsIContent *aChild, PRInt32 aIndexInContainer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_NodeWillBeDestroyed(nsIDocumentObserver *iface, const nsINode *aNode)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_ParentChainChanged(nsIDocumentObserver *iface, nsIContent *aContent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_BeginUpdate(nsIDocumentObserver *iface, nsIDocument *aDocument,
|
|
|
|
nsUpdateType aUpdateType)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_EndUpdate(nsIDocumentObserver *iface, nsIDocument *aDocument,
|
|
|
|
nsUpdateType aUpdateType)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_BeginLoad(nsIDocumentObserver *iface, nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_EndLoad(nsIDocumentObserver *iface, nsIDocument *aDocument)
|
|
|
|
{
|
2009-10-21 21:28:09 +02:00
|
|
|
HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
|
2009-08-11 19:14:17 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2010-08-18 13:39:04 +02:00
|
|
|
if(This->skip_mutation_notif)
|
|
|
|
return;
|
|
|
|
|
2009-10-21 21:28:09 +02:00
|
|
|
This->content_ready = TRUE;
|
2009-11-01 19:24:34 +01:00
|
|
|
push_mutation_queue(This, MUTATION_ENDLOAD, NULL);
|
2008-12-30 06:48:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_ContentStatesChanged(nsIDocumentObserver *iface, nsIDocument *aDocument,
|
|
|
|
nsIContent *aContent1, nsIContent *aContent2, PRInt32 aStateMask)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_StyleSheetAdded(nsIDocumentObserver *iface, nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet *aStyleSheet, PRBool aDocumentSheet)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_StyleSheetRemoved(nsIDocumentObserver *iface, nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet *aStyleSheet, PRBool aDocumentSheet)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_StyleSheetApplicableStateChanged(nsIDocumentObserver *iface,
|
|
|
|
nsIDocument *aDocument, nsIStyleSheet *aStyleSheet, PRBool aApplicable)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_StyleRuleChanged(nsIDocumentObserver *iface, nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet *aStyleSheet, nsIStyleRule *aOldStyleRule, nsIStyleSheet *aNewStyleRule)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_StyleRuleAdded(nsIDocumentObserver *iface, nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet *aStyleSheet, nsIStyleRule *aStyleRule)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_StyleRuleRemoved(nsIDocumentObserver *iface, nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet *aStyleSheet, nsIStyleRule *aStyleRule)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_BindToDocument(nsIDocumentObserver *iface, nsIDocument *aDocument,
|
|
|
|
nsIContent *aContent)
|
|
|
|
{
|
2009-10-21 21:28:09 +02:00
|
|
|
HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
|
2009-10-21 21:30:20 +02:00
|
|
|
nsIDOMHTMLIFrameElement *nsiframe;
|
2009-10-27 21:17:08 +01:00
|
|
|
nsIDOMHTMLFrameElement *nsframe;
|
2008-12-30 06:48:59 +01:00
|
|
|
nsIDOMComment *nscomment;
|
|
|
|
nsIDOMElement *nselem;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMElement, (void**)&nselem);
|
|
|
|
if(NS_SUCCEEDED(nsres)) {
|
2009-10-21 21:28:09 +02:00
|
|
|
check_event_attr(This, nselem);
|
2008-12-30 06:48:59 +01:00
|
|
|
nsIDOMElement_Release(nselem);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMComment, (void**)&nscomment);
|
|
|
|
if(NS_SUCCEEDED(nsres)) {
|
|
|
|
TRACE("comment node\n");
|
|
|
|
|
|
|
|
push_mutation_queue(This, MUTATION_COMMENT, (nsISupports*)nscomment);
|
|
|
|
nsIDOMComment_Release(nscomment);
|
|
|
|
}
|
2009-10-21 21:30:20 +02:00
|
|
|
|
|
|
|
nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMHTMLIFrameElement, (void**)&nsiframe);
|
|
|
|
if(NS_SUCCEEDED(nsres)) {
|
2009-10-22 23:35:51 +02:00
|
|
|
TRACE("iframe node\n");
|
|
|
|
|
2009-12-03 01:12:12 +01:00
|
|
|
push_mutation_queue(This, MUTATION_BINDTOTREE, (nsISupports*)nsiframe);
|
2009-10-21 21:30:20 +02:00
|
|
|
nsIDOMHTMLIFrameElement_Release(nsiframe);
|
|
|
|
}
|
2009-10-27 21:17:08 +01:00
|
|
|
|
|
|
|
nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMHTMLFrameElement, (void**)&nsframe);
|
|
|
|
if(NS_SUCCEEDED(nsres)) {
|
|
|
|
TRACE("frame node\n");
|
|
|
|
|
2009-12-03 01:12:12 +01:00
|
|
|
push_mutation_queue(This, MUTATION_BINDTOTREE, (nsISupports*)nsframe);
|
2009-10-27 21:17:08 +01:00
|
|
|
nsIDOMHTMLFrameElement_Release(nsframe);
|
|
|
|
}
|
2008-12-30 06:48:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void NSAPI nsDocumentObserver_DoneAddingChildren(nsIDocumentObserver *iface, nsIContent *aContent,
|
|
|
|
PRBool aHaveNotified)
|
|
|
|
{
|
2009-10-21 21:28:09 +02:00
|
|
|
HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
|
2008-12-30 06:48:59 +01:00
|
|
|
nsIDOMHTMLScriptElement *nsscript;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p %x)\n", This, aContent, aHaveNotified);
|
|
|
|
|
|
|
|
nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMHTMLScriptElement, (void**)&nsscript);
|
|
|
|
if(NS_SUCCEEDED(nsres)) {
|
2009-10-22 23:35:51 +02:00
|
|
|
TRACE("script node\n");
|
|
|
|
|
2008-12-30 06:48:59 +01:00
|
|
|
push_mutation_queue(This, MUTATION_SCRIPT, (nsISupports*)nsscript);
|
|
|
|
nsIDOMHTMLScriptElement_Release(nsscript);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef NSMUTATIONOBS_THIS
|
|
|
|
|
|
|
|
static const nsIDocumentObserverVtbl nsDocumentObserverVtbl = {
|
|
|
|
nsDocumentObserver_QueryInterface,
|
|
|
|
nsDocumentObserver_AddRef,
|
|
|
|
nsDocumentObserver_Release,
|
|
|
|
nsDocumentObserver_CharacterDataWillChange,
|
|
|
|
nsDocumentObserver_CharacterDataChanged,
|
2009-08-04 14:05:05 +02:00
|
|
|
nsDocumentObserver_AttributeWillChange,
|
2008-12-30 06:48:59 +01:00
|
|
|
nsDocumentObserver_AttributeChanged,
|
|
|
|
nsDocumentObserver_ContentAppended,
|
|
|
|
nsDocumentObserver_ContentInserted,
|
|
|
|
nsDocumentObserver_ContentRemoved,
|
|
|
|
nsDocumentObserver_NodeWillBeDestroyed,
|
|
|
|
nsDocumentObserver_ParentChainChanged,
|
|
|
|
nsDocumentObserver_BeginUpdate,
|
|
|
|
nsDocumentObserver_EndUpdate,
|
|
|
|
nsDocumentObserver_BeginLoad,
|
|
|
|
nsDocumentObserver_EndLoad,
|
|
|
|
nsDocumentObserver_ContentStatesChanged,
|
|
|
|
nsDocumentObserver_StyleSheetAdded,
|
|
|
|
nsDocumentObserver_StyleSheetRemoved,
|
|
|
|
nsDocumentObserver_StyleSheetApplicableStateChanged,
|
|
|
|
nsDocumentObserver_StyleRuleChanged,
|
|
|
|
nsDocumentObserver_StyleRuleAdded,
|
|
|
|
nsDocumentObserver_StyleRuleRemoved,
|
|
|
|
nsDocumentObserver_BindToDocument,
|
|
|
|
nsDocumentObserver_DoneAddingChildren
|
|
|
|
};
|
|
|
|
|
2009-10-21 21:28:09 +02:00
|
|
|
void init_mutation(HTMLDocumentNode *doc)
|
2008-12-30 06:48:59 +01:00
|
|
|
{
|
2009-10-21 21:28:39 +02:00
|
|
|
nsIDOMNSDocument *nsdoc;
|
|
|
|
nsresult nsres;
|
|
|
|
|
2009-10-21 21:28:09 +02:00
|
|
|
doc->lpIDocumentObserverVtbl = &nsDocumentObserverVtbl;
|
|
|
|
doc->lpIRunnableVtbl = &nsRunnableVtbl;
|
2009-10-21 21:28:39 +02:00
|
|
|
|
|
|
|
nsres = nsIDOMHTMLDocument_QueryInterface(doc->nsdoc, &IID_nsIDOMNSDocument, (void**)&nsdoc);
|
|
|
|
if(NS_FAILED(nsres)) {
|
|
|
|
ERR("Could not get nsIDOMNSDocument: %08x\n", nsres);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMNSDocument_WineAddObserver(nsdoc, NSDOCOBS(doc));
|
|
|
|
nsIDOMNSDocument_Release(nsdoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void release_mutation(HTMLDocumentNode *doc)
|
|
|
|
{
|
|
|
|
nsIDOMNSDocument *nsdoc;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
nsres = nsIDOMHTMLDocument_QueryInterface(doc->nsdoc, &IID_nsIDOMNSDocument, (void**)&nsdoc);
|
|
|
|
if(NS_FAILED(nsres)) {
|
|
|
|
ERR("Could not get nsIDOMNSDocument: %08x\n", nsres);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMNSDocument_WineRemoveObserver(nsdoc, NSDOCOBS(doc));
|
|
|
|
nsIDOMNSDocument_Release(nsdoc);
|
2008-12-30 06:48:59 +01:00
|
|
|
}
|