mshtml: Moved parsing external script to OnStopBinding callback.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2016-07-19 18:37:11 +02:00 committed by Alexandre Julliard
parent 2dd15b59d1
commit 718a415aa1
1 changed files with 32 additions and 19 deletions

View File

@ -92,6 +92,8 @@ struct ScriptHost {
struct list entry; struct list entry;
}; };
static ScriptHost *get_elem_script_host(HTMLInnerWindow*,HTMLScriptElement*);
static void set_script_prop(ScriptHost *script_host, DWORD property, VARIANT *val) static void set_script_prop(ScriptHost *script_host, DWORD property, VARIANT *val)
{ {
IActiveScriptProperty *script_prop; IActiveScriptProperty *script_prop;
@ -807,7 +809,6 @@ typedef struct {
DWORD size; DWORD size;
char *buf; char *buf;
HRESULT hres;
} ScriptBSC; } ScriptBSC;
static HRESULT get_binding_text(ScriptBSC *bsc, WCHAR **ret) static HRESULT get_binding_text(ScriptBSC *bsc, WCHAR **ret)
@ -841,7 +842,6 @@ static HRESULT get_binding_text(ScriptBSC *bsc, WCHAR **ret)
default: default:
/* FIXME: Try to use charset from HTTP headers first */ /* FIXME: Try to use charset from HTTP headers first */
if(bsc->script_elem)
cp = get_document_charset(bsc->script_elem->element.node.doc); cp = get_document_charset(bsc->script_elem->element.node.doc);
/* fall through */ /* fall through */
case BOM_UTF8: { case BOM_UTF8: {
@ -861,6 +861,29 @@ static HRESULT get_binding_text(ScriptBSC *bsc, WCHAR **ret)
return S_OK; return S_OK;
} }
static void script_file_available(ScriptBSC *bsc)
{
HTMLScriptElement *script_elem = bsc->script_elem;
HTMLInnerWindow *window = bsc->bsc.window;
ScriptHost *script_host;
WCHAR *text;
HRESULT hres;
hres = get_binding_text(bsc, &text);
if(FAILED(hres))
return;
script_host = get_elem_script_host(window, script_elem);
if(!script_host) {
heap_free(text);
return;
}
script_elem->parsed = TRUE;
parse_elem_text(script_host, script_elem, text);
heap_free(text);
}
static inline ScriptBSC *impl_from_BSCallback(BSCallback *iface) static inline ScriptBSC *impl_from_BSCallback(BSCallback *iface)
{ {
return CONTAINING_RECORD(iface, ScriptBSC, bsc); return CONTAINING_RECORD(iface, ScriptBSC, bsc);
@ -899,11 +922,14 @@ static HRESULT ScriptBSC_stop_binding(BSCallback *bsc, HRESULT result)
{ {
ScriptBSC *This = impl_from_BSCallback(bsc); ScriptBSC *This = impl_from_BSCallback(bsc);
This->hres = result; if(SUCCEEDED(result) && !This->script_elem)
result = E_UNEXPECTED;
if(SUCCEEDED(result)) { if(SUCCEEDED(result)) {
if(This->script_elem->readystate == READYSTATE_LOADING) if(This->script_elem->readystate == READYSTATE_LOADING)
set_script_elem_readystate(This->script_elem, READYSTATE_LOADED); set_script_elem_readystate(This->script_elem, READYSTATE_LOADED);
script_file_available(This);
}else { }else {
FIXME("binding failed %08x\n", result); FIXME("binding failed %08x\n", result);
heap_free(This->buf); heap_free(This->buf);
@ -973,7 +999,7 @@ static const BSCallbackVtbl ScriptBSCVtbl = {
}; };
static HRESULT bind_script_to_text(HTMLInnerWindow *window, IUri *uri, HTMLScriptElement *script_elem, WCHAR **ret) static HRESULT bind_script(HTMLInnerWindow *window, IUri *uri, HTMLScriptElement *script_elem)
{ {
ScriptBSC *bsc; ScriptBSC *bsc;
IMoniker *mon; IMoniker *mon;
@ -991,7 +1017,6 @@ static HRESULT bind_script_to_text(HTMLInnerWindow *window, IUri *uri, HTMLScrip
init_bscallback(&bsc->bsc, &ScriptBSCVtbl, mon, 0); init_bscallback(&bsc->bsc, &ScriptBSCVtbl, mon, 0);
IMoniker_Release(mon); IMoniker_Release(mon);
bsc->hres = E_FAIL;
hres = IUri_GetScheme(uri, &bsc->scheme); hres = IUri_GetScheme(uri, &bsc->scheme);
if(FAILED(hres)) if(FAILED(hres))
@ -1001,10 +1026,6 @@ static HRESULT bind_script_to_text(HTMLInnerWindow *window, IUri *uri, HTMLScrip
bsc->script_elem = script_elem; bsc->script_elem = script_elem;
hres = start_binding(window, &bsc->bsc, NULL); hres = start_binding(window, &bsc->bsc, NULL);
if(SUCCEEDED(hres))
hres = bsc->hres;
if(SUCCEEDED(hres))
hres = get_binding_text(bsc, ret);
IBindStatusCallback_Release(&bsc->bsc.IBindStatusCallback_iface); IBindStatusCallback_Release(&bsc->bsc.IBindStatusCallback_iface);
return hres; return hres;
@ -1012,7 +1033,6 @@ static HRESULT bind_script_to_text(HTMLInnerWindow *window, IUri *uri, HTMLScrip
static void parse_extern_script(ScriptHost *script_host, HTMLScriptElement *script_elem, LPCWSTR src) static void parse_extern_script(ScriptHost *script_host, HTMLScriptElement *script_elem, LPCWSTR src)
{ {
WCHAR *text;
IUri *uri; IUri *uri;
HRESULT hres; HRESULT hres;
@ -1025,14 +1045,8 @@ static void parse_extern_script(ScriptHost *script_host, HTMLScriptElement *scri
if(FAILED(hres)) if(FAILED(hres))
return; return;
hres = bind_script_to_text(script_host->window, uri, script_elem, &text); hres = bind_script(script_host->window, uri, script_elem);
IUri_Release(uri); IUri_Release(uri);
if(FAILED(hres) || !text)
return;
parse_elem_text(script_host, script_elem, text);
heap_free(text);
} }
static void parse_inline_script(ScriptHost *script_host, HTMLScriptElement *script_elem) static void parse_inline_script(ScriptHost *script_host, HTMLScriptElement *script_elem)
@ -1083,7 +1097,6 @@ static void parse_script_elem(ScriptHost *script_host, HTMLScriptElement *script
if(NS_FAILED(nsres)) { if(NS_FAILED(nsres)) {
ERR("GetSrc failed: %08x\n", nsres); ERR("GetSrc failed: %08x\n", nsres);
}else if(*src) { }else if(*src) {
script_elem->parsed = TRUE;
parse_extern_script(script_host, script_elem, src); parse_extern_script(script_host, script_elem, src);
}else { }else {
parse_inline_script(script_host, script_elem); parse_inline_script(script_host, script_elem);