mshtml: Store information if script was already parsed in script element object.

This commit is contained in:
Jacek Caban 2012-10-02 15:45:40 +02:00 committed by Alexandre Julliard
parent a420b5dad8
commit 4503edd614
4 changed files with 54 additions and 28 deletions

View File

@ -32,14 +32,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
typedef struct {
HTMLElement element;
IHTMLScriptElement IHTMLScriptElement_iface;
nsIDOMHTMLScriptElement *nsscript;
} HTMLScriptElement;
static inline HTMLScriptElement *impl_from_IHTMLScriptElement(IHTMLScriptElement *iface)
{
return CONTAINING_RECORD(iface, HTMLScriptElement, IHTMLScriptElement_iface);
@ -327,6 +319,20 @@ static const NodeImplVtbl HTMLScriptElementImplVtbl = {
HTMLScriptElement_get_readystate
};
HRESULT script_elem_from_nsscript(HTMLDocumentNode *doc, nsIDOMHTMLScriptElement *nsscript, HTMLScriptElement **ret)
{
HTMLDOMNode *node;
HRESULT hres;
hres = get_node(doc, (nsIDOMNode*)nsscript, TRUE, &node);
if(FAILED(hres))
return hres;
assert(node->vtbl == &HTMLScriptElementImplVtbl);
*ret = impl_from_HTMLDOMNode(node);
return S_OK;
}
static const tid_t HTMLScriptElement_iface_tids[] = {
HTMLELEMENT_TIDS,
IHTMLScriptElement_tid,

View File

@ -741,6 +741,17 @@ void init_binding_ui(HTMLDocumentObj*) DECLSPEC_HIDDEN;
void HTMLDocumentNode_SecMgr_Init(HTMLDocumentNode*) DECLSPEC_HIDDEN;
typedef struct {
HTMLElement element;
IHTMLScriptElement IHTMLScriptElement_iface;
nsIDOMHTMLScriptElement *nsscript;
BOOL parsed;
} HTMLScriptElement;
HRESULT script_elem_from_nsscript(HTMLDocumentNode*,nsIDOMHTMLScriptElement*,HTMLScriptElement**) DECLSPEC_HIDDEN;
HRESULT HTMLCurrentStyle_Create(HTMLElement*,IHTMLCurrentStyle**) DECLSPEC_HIDDEN;
void ConnectionPoint_Init(ConnectionPoint*,ConnectionPointContainer*,REFIID,cp_static_data_t*) DECLSPEC_HIDDEN;
@ -904,7 +915,7 @@ HTMLElement *unsafe_impl_from_IHTMLElement(IHTMLElement*) DECLSPEC_HIDDEN;
void release_script_hosts(HTMLInnerWindow*) DECLSPEC_HIDDEN;
void connect_scripts(HTMLInnerWindow*) DECLSPEC_HIDDEN;
void doc_insert_script(HTMLInnerWindow*,nsIDOMHTMLScriptElement*) DECLSPEC_HIDDEN;
void doc_insert_script(HTMLInnerWindow*,HTMLScriptElement*) DECLSPEC_HIDDEN;
IDispatch *script_parse_event(HTMLInnerWindow*,LPCWSTR) DECLSPEC_HIDDEN;
HRESULT exec_script(HTMLInnerWindow*,const WCHAR*,const WCHAR*,VARIANT*) DECLSPEC_HIDDEN;
void set_script_mode(HTMLOuterWindow*,SCRIPTMODE) DECLSPEC_HIDDEN;

View File

@ -294,8 +294,10 @@ static nsresult run_end_load(HTMLDocumentNode *This, nsISupports *arg1, nsISuppo
static nsresult run_insert_script(HTMLDocumentNode *doc, nsISupports *script_iface, nsISupports *parser_iface)
{
nsIDOMHTMLScriptElement *nsscript;
HTMLScriptElement *script_elem;
nsIParser *nsparser = NULL;
nsresult nsres;
HRESULT hres;
TRACE("(%p)->(%p)\n", doc, script_iface);
@ -313,17 +315,22 @@ static nsresult run_insert_script(HTMLDocumentNode *doc, nsISupports *script_ifa
}
}
hres = script_elem_from_nsscript(doc, nsscript, &script_elem);
nsIDOMHTMLScriptElement_Release(nsscript);
if(FAILED(hres))
return NS_ERROR_FAILURE;
if(nsparser)
nsIParser_BeginEvaluatingParserInsertedScript(nsparser);
doc_insert_script(doc->window, nsscript);
doc_insert_script(doc->window, script_elem);
if(nsparser) {
nsIParser_EndEvaluatingParserInsertedScript(nsparser);
nsIParser_Release(nsparser);
}
nsIDOMHTMLScriptElement_Release(nsscript);
IHTMLScriptElement_Release(&script_elem->IHTMLScriptElement_iface);
return NS_OK;
}

View File

@ -731,34 +731,34 @@ static void parse_extern_script(ScriptHost *script_host, LPCWSTR src)
heap_free(text);
}
static void parse_inline_script(ScriptHost *script_host, nsIDOMHTMLScriptElement *nsscript)
static void parse_inline_script(ScriptHost *script_host, HTMLScriptElement *script_elem)
{
const PRUnichar *text;
nsAString text_str;
nsresult nsres;
nsAString_Init(&text_str, NULL);
nsres = nsIDOMHTMLScriptElement_GetText(script_elem->nsscript, &text_str);
nsAString_GetData(&text_str, &text);
nsres = nsIDOMHTMLScriptElement_GetText(nsscript, &text_str);
if(NS_SUCCEEDED(nsres)) {
nsAString_GetData(&text_str, &text);
parse_text(script_host, text);
}else {
if(NS_FAILED(nsres)) {
ERR("GetText failed: %08x\n", nsres);
}else if(*text) {
script_elem->parsed = TRUE;
parse_text(script_host, text);
}
nsAString_Finish(&text_str);
}
static void parse_script_elem(ScriptHost *script_host, nsIDOMHTMLScriptElement *nsscript)
static void parse_script_elem(ScriptHost *script_host, HTMLScriptElement *script_elem)
{
nsAString src_str, event_str;
const PRUnichar *src;
nsresult nsres;
nsAString_Init(&event_str, NULL);
nsres = nsIDOMHTMLScriptElement_GetEvent(nsscript, &event_str);
nsres = nsIDOMHTMLScriptElement_GetEvent(script_elem->nsscript, &event_str);
if(NS_SUCCEEDED(nsres)) {
const PRUnichar *event;
@ -774,15 +774,17 @@ static void parse_script_elem(ScriptHost *script_host, nsIDOMHTMLScriptElement *
nsAString_Finish(&event_str);
nsAString_Init(&src_str, NULL);
nsres = nsIDOMHTMLScriptElement_GetSrc(nsscript, &src_str);
nsres = nsIDOMHTMLScriptElement_GetSrc(script_elem->nsscript, &src_str);
nsAString_GetData(&src_str, &src);
if(NS_FAILED(nsres))
if(NS_FAILED(nsres)) {
ERR("GetSrc failed: %08x\n", nsres);
else if(*src)
}else if(*src) {
script_elem->parsed = TRUE;
parse_extern_script(script_host, src);
else
parse_inline_script(script_host, nsscript);
}else {
parse_inline_script(script_host, script_elem);
}
nsAString_Finish(&src_str);
}
@ -887,12 +889,12 @@ static ScriptHost *get_script_host(HTMLInnerWindow *window, const GUID *guid)
return create_script_host(window, guid);
}
void doc_insert_script(HTMLInnerWindow *window, nsIDOMHTMLScriptElement *nsscript)
void doc_insert_script(HTMLInnerWindow *window, HTMLScriptElement *script_elem)
{
ScriptHost *script_host;
GUID guid;
if(!get_script_guid(window, nsscript, &guid)) {
if(!get_script_guid(window, script_elem->nsscript, &guid)) {
WARN("Could not find script GUID\n");
return;
}
@ -908,7 +910,7 @@ void doc_insert_script(HTMLInnerWindow *window, nsIDOMHTMLScriptElement *nsscrip
return;
if(script_host->parse)
parse_script_elem(script_host, nsscript);
parse_script_elem(script_host, script_elem);
}
IDispatch *script_parse_event(HTMLInnerWindow *window, LPCWSTR text)