forked from Mirrors/wine-wine
mshtml: Moved script binding callback to script.c.
parent
7e4db7df48
commit
87efdc3047
|
@ -102,6 +102,17 @@ struct nsChannelBSC {
|
|||
nsProtocolStream *nsstream;
|
||||
};
|
||||
|
||||
struct BSCallbackVtbl {
|
||||
void (*destroy)(BSCallback*);
|
||||
HRESULT (*init_bindinfo)(BSCallback*);
|
||||
HRESULT (*start_binding)(BSCallback*);
|
||||
HRESULT (*stop_binding)(BSCallback*,HRESULT);
|
||||
HRESULT (*read_data)(BSCallback*,IStream*);
|
||||
HRESULT (*on_progress)(BSCallback*,ULONG,LPCWSTR);
|
||||
HRESULT (*on_response)(BSCallback*,DWORD,LPCWSTR);
|
||||
HRESULT (*beginning_transaction)(BSCallback*,WCHAR**);
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct list entry;
|
||||
WCHAR *header;
|
||||
|
@ -130,16 +141,17 @@ HRESULT navigate_new_window(HTMLOuterWindow*,IUri*,const WCHAR*,IHTMLWindow2**)
|
|||
HRESULT navigate_url(HTMLOuterWindow*,const WCHAR*,IUri*,DWORD) DECLSPEC_HIDDEN;
|
||||
HRESULT submit_form(HTMLOuterWindow*,IUri*,nsIInputStream*) DECLSPEC_HIDDEN;
|
||||
|
||||
void init_bscallback(BSCallback*,const BSCallbackVtbl*,IMoniker*,DWORD) DECLSPEC_HIDDEN;
|
||||
HRESULT create_channelbsc(IMoniker*,const WCHAR*,BYTE*,DWORD,BOOL,nsChannelBSC**) DECLSPEC_HIDDEN;
|
||||
HRESULT channelbsc_load_stream(HTMLInnerWindow*,IMoniker*,IStream*) DECLSPEC_HIDDEN;
|
||||
void channelbsc_set_channel(nsChannelBSC*,nsChannel*,nsIStreamListener*,nsISupports*) DECLSPEC_HIDDEN;
|
||||
IUri *nsuri_get_uri(nsWineURI*) DECLSPEC_HIDDEN;
|
||||
|
||||
HRESULT read_stream(BSCallback*,IStream*,void*,DWORD,DWORD*) DECLSPEC_HIDDEN;
|
||||
|
||||
HRESULT create_relative_uri(HTMLOuterWindow*,const WCHAR*,IUri**) DECLSPEC_HIDDEN;
|
||||
HRESULT create_uri(const WCHAR*,DWORD,IUri**) DECLSPEC_HIDDEN;
|
||||
IUri *get_uri_nofrag(IUri*) DECLSPEC_HIDDEN;
|
||||
|
||||
void set_current_mon(HTMLOuterWindow*,IMoniker*,DWORD) DECLSPEC_HIDDEN;
|
||||
void set_current_uri(HTMLOuterWindow*,IUri*) DECLSPEC_HIDDEN;
|
||||
|
||||
HRESULT bind_mon_to_wstr(HTMLInnerWindow*,IMoniker*,WCHAR**) DECLSPEC_HIDDEN;
|
||||
|
|
|
@ -61,17 +61,6 @@ struct nsProtocolStream {
|
|||
DWORD buf_size;
|
||||
};
|
||||
|
||||
struct BSCallbackVtbl {
|
||||
void (*destroy)(BSCallback*);
|
||||
HRESULT (*init_bindinfo)(BSCallback*);
|
||||
HRESULT (*start_binding)(BSCallback*);
|
||||
HRESULT (*stop_binding)(BSCallback*,HRESULT);
|
||||
HRESULT (*read_data)(BSCallback*,IStream*);
|
||||
HRESULT (*on_progress)(BSCallback*,ULONG,LPCWSTR);
|
||||
HRESULT (*on_response)(BSCallback*,DWORD,LPCWSTR);
|
||||
HRESULT (*beginning_transaction)(BSCallback*,WCHAR**);
|
||||
};
|
||||
|
||||
static inline nsProtocolStream *impl_from_nsIInputStream(nsIInputStream *iface)
|
||||
{
|
||||
return CONTAINING_RECORD(iface, nsProtocolStream, nsIInputStream_iface);
|
||||
|
@ -614,7 +603,7 @@ static const IServiceProviderVtbl ServiceProviderVtbl = {
|
|||
BSCServiceProvider_QueryService
|
||||
};
|
||||
|
||||
static void init_bscallback(BSCallback *This, const BSCallbackVtbl *vtbl, IMoniker *mon, DWORD bindf)
|
||||
void init_bscallback(BSCallback *This, const BSCallbackVtbl *vtbl, IMoniker *mon, DWORD bindf)
|
||||
{
|
||||
This->IBindStatusCallback_iface.lpVtbl = &BindStatusCallbackVtbl;
|
||||
This->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
|
||||
|
@ -632,7 +621,7 @@ static void init_bscallback(BSCallback *This, const BSCallbackVtbl *vtbl, IMonik
|
|||
This->mon = mon;
|
||||
}
|
||||
|
||||
static HRESULT read_stream(BSCallback *This, IStream *stream, void *buf, DWORD size, DWORD *ret_size)
|
||||
HRESULT read_stream(BSCallback *This, IStream *stream, void *buf, DWORD size, DWORD *ret_size)
|
||||
{
|
||||
DWORD read_size = 0, skip=0;
|
||||
BYTE *data = buf;
|
||||
|
@ -830,173 +819,6 @@ HRESULT start_binding(HTMLInnerWindow *inner_window, BSCallback *bscallback, IBi
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
BSCallback bsc;
|
||||
|
||||
DWORD size;
|
||||
char *buf;
|
||||
HRESULT hres;
|
||||
} BufferBSC;
|
||||
|
||||
static inline BufferBSC *BufferBSC_from_BSCallback(BSCallback *iface)
|
||||
{
|
||||
return CONTAINING_RECORD(iface, BufferBSC, bsc);
|
||||
}
|
||||
|
||||
static void BufferBSC_destroy(BSCallback *bsc)
|
||||
{
|
||||
BufferBSC *This = BufferBSC_from_BSCallback(bsc);
|
||||
|
||||
heap_free(This->buf);
|
||||
heap_free(This);
|
||||
}
|
||||
|
||||
static HRESULT BufferBSC_init_bindinfo(BSCallback *bsc)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT BufferBSC_start_binding(BSCallback *bsc)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT BufferBSC_stop_binding(BSCallback *bsc, HRESULT result)
|
||||
{
|
||||
BufferBSC *This = BufferBSC_from_BSCallback(bsc);
|
||||
|
||||
This->hres = result;
|
||||
|
||||
if(FAILED(result)) {
|
||||
heap_free(This->buf);
|
||||
This->buf = NULL;
|
||||
This->size = 0;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT BufferBSC_read_data(BSCallback *bsc, IStream *stream)
|
||||
{
|
||||
BufferBSC *This = BufferBSC_from_BSCallback(bsc);
|
||||
DWORD readed;
|
||||
HRESULT hres;
|
||||
|
||||
if(!This->buf) {
|
||||
This->buf = heap_alloc(128);
|
||||
if(!This->buf)
|
||||
return E_OUTOFMEMORY;
|
||||
This->size = 128;
|
||||
}
|
||||
|
||||
do {
|
||||
if(This->bsc.readed >= This->size) {
|
||||
This->size <<= 1;
|
||||
This->buf = heap_realloc(This->buf, This->size);
|
||||
}
|
||||
|
||||
hres = read_stream(&This->bsc, stream, This->buf+This->bsc.readed, This->size-This->bsc.readed, &readed);
|
||||
}while(hres == S_OK);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT BufferBSC_on_progress(BSCallback *bsc, ULONG status_code, LPCWSTR status_text)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT BufferBSC_on_response(BSCallback *bsc, DWORD response_code,
|
||||
LPCWSTR response_headers)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT BufferBSC_beginning_transaction(BSCallback *bsc, WCHAR **additional_headers)
|
||||
{
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
static const BSCallbackVtbl BufferBSCVtbl = {
|
||||
BufferBSC_destroy,
|
||||
BufferBSC_init_bindinfo,
|
||||
BufferBSC_start_binding,
|
||||
BufferBSC_stop_binding,
|
||||
BufferBSC_read_data,
|
||||
BufferBSC_on_progress,
|
||||
BufferBSC_on_response,
|
||||
BufferBSC_beginning_transaction
|
||||
};
|
||||
|
||||
|
||||
HRESULT bind_mon_to_wstr(HTMLInnerWindow *window, IMoniker *mon, WCHAR **ret)
|
||||
{
|
||||
BufferBSC *bsc;
|
||||
WCHAR *text;
|
||||
HRESULT hres;
|
||||
|
||||
bsc = heap_alloc_zero(sizeof(*bsc));
|
||||
if(!bsc)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
init_bscallback(&bsc->bsc, &BufferBSCVtbl, mon, 0);
|
||||
bsc->hres = E_FAIL;
|
||||
|
||||
hres = start_binding(window, &bsc->bsc, NULL);
|
||||
if(SUCCEEDED(hres))
|
||||
hres = bsc->hres;
|
||||
if(FAILED(hres)) {
|
||||
IBindStatusCallback_Release(&bsc->bsc.IBindStatusCallback_iface);
|
||||
return hres;
|
||||
}
|
||||
|
||||
if(!bsc->bsc.readed) {
|
||||
*ret = NULL;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
switch(bsc->bsc.bom) {
|
||||
case BOM_UTF16:
|
||||
if(bsc->bsc.readed % sizeof(WCHAR)) {
|
||||
FIXME("The buffer is not a valid utf16 string\n");
|
||||
hres = E_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
text = heap_alloc(bsc->bsc.readed+sizeof(WCHAR));
|
||||
if(!text) {
|
||||
hres = E_OUTOFMEMORY;
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(text, bsc->buf, bsc->bsc.readed);
|
||||
text[bsc->bsc.readed/sizeof(WCHAR)] = 0;
|
||||
break;
|
||||
|
||||
case BOM_UTF8:
|
||||
default: {
|
||||
DWORD len;
|
||||
|
||||
len = MultiByteToWideChar(CP_UTF8, 0, bsc->buf, bsc->bsc.readed, NULL, 0);
|
||||
text = heap_alloc((len+1)*sizeof(WCHAR));
|
||||
if(!text) {
|
||||
hres = E_OUTOFMEMORY;
|
||||
break;
|
||||
}
|
||||
|
||||
MultiByteToWideChar(CP_UTF8, 0, bsc->buf, bsc->bsc.readed, text, len);
|
||||
text[len] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
IBindStatusCallback_Release(&bsc->bsc.IBindStatusCallback_iface);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
*ret = text;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT read_post_data_stream(nsIInputStream *stream, BOOL contains_headers, struct list *headers_list,
|
||||
request_data_t *request_data)
|
||||
{
|
||||
|
|
|
@ -722,7 +722,180 @@ static void parse_text(ScriptHost *script_host, LPCWSTR text)
|
|||
|
||||
}
|
||||
|
||||
static void parse_extern_script(ScriptHost *script_host, LPCWSTR src)
|
||||
typedef struct {
|
||||
BSCallback bsc;
|
||||
|
||||
DWORD size;
|
||||
char *buf;
|
||||
HRESULT hres;
|
||||
} ScriptBSC;
|
||||
|
||||
static inline ScriptBSC *impl_from_BSCallback(BSCallback *iface)
|
||||
{
|
||||
return CONTAINING_RECORD(iface, ScriptBSC, bsc);
|
||||
}
|
||||
|
||||
static void ScriptBSC_destroy(BSCallback *bsc)
|
||||
{
|
||||
ScriptBSC *This = impl_from_BSCallback(bsc);
|
||||
|
||||
heap_free(This->buf);
|
||||
heap_free(This);
|
||||
}
|
||||
|
||||
static HRESULT ScriptBSC_init_bindinfo(BSCallback *bsc)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT ScriptBSC_start_binding(BSCallback *bsc)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT ScriptBSC_stop_binding(BSCallback *bsc, HRESULT result)
|
||||
{
|
||||
ScriptBSC *This = impl_from_BSCallback(bsc);
|
||||
|
||||
This->hres = result;
|
||||
|
||||
if(FAILED(result)) {
|
||||
FIXME("binding failed %08x\n", result);
|
||||
heap_free(This->buf);
|
||||
This->buf = NULL;
|
||||
This->size = 0;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT ScriptBSC_read_data(BSCallback *bsc, IStream *stream)
|
||||
{
|
||||
ScriptBSC *This = impl_from_BSCallback(bsc);
|
||||
DWORD readed;
|
||||
HRESULT hres;
|
||||
|
||||
if(!This->buf) {
|
||||
This->buf = heap_alloc(128);
|
||||
if(!This->buf)
|
||||
return E_OUTOFMEMORY;
|
||||
This->size = 128;
|
||||
}
|
||||
|
||||
do {
|
||||
if(This->bsc.readed >= This->size) {
|
||||
void *new_buf;
|
||||
new_buf = heap_realloc(This->buf, This->size << 1);
|
||||
if(!new_buf)
|
||||
return E_OUTOFMEMORY;
|
||||
This->size <<= 1;
|
||||
This->buf = new_buf;
|
||||
}
|
||||
|
||||
hres = read_stream(&This->bsc, stream, This->buf+This->bsc.readed, This->size-This->bsc.readed, &readed);
|
||||
}while(hres == S_OK);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT ScriptBSC_on_progress(BSCallback *bsc, ULONG status_code, LPCWSTR status_text)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT ScriptBSC_on_response(BSCallback *bsc, DWORD response_code,
|
||||
LPCWSTR response_headers)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT ScriptBSC_beginning_transaction(BSCallback *bsc, WCHAR **additional_headers)
|
||||
{
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
static const BSCallbackVtbl ScriptBSCVtbl = {
|
||||
ScriptBSC_destroy,
|
||||
ScriptBSC_init_bindinfo,
|
||||
ScriptBSC_start_binding,
|
||||
ScriptBSC_stop_binding,
|
||||
ScriptBSC_read_data,
|
||||
ScriptBSC_on_progress,
|
||||
ScriptBSC_on_response,
|
||||
ScriptBSC_beginning_transaction
|
||||
};
|
||||
|
||||
|
||||
static HRESULT bind_script_to_text(HTMLInnerWindow *window, IMoniker *mon, WCHAR **ret)
|
||||
{
|
||||
ScriptBSC *bsc;
|
||||
WCHAR *text;
|
||||
HRESULT hres;
|
||||
|
||||
bsc = heap_alloc_zero(sizeof(*bsc));
|
||||
if(!bsc)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
init_bscallback(&bsc->bsc, &ScriptBSCVtbl, mon, 0);
|
||||
bsc->hres = E_FAIL;
|
||||
|
||||
hres = start_binding(window, &bsc->bsc, NULL);
|
||||
if(SUCCEEDED(hres))
|
||||
hres = bsc->hres;
|
||||
if(FAILED(hres)) {
|
||||
IBindStatusCallback_Release(&bsc->bsc.IBindStatusCallback_iface);
|
||||
return hres;
|
||||
}
|
||||
|
||||
if(!bsc->bsc.readed) {
|
||||
*ret = NULL;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
switch(bsc->bsc.bom) {
|
||||
case BOM_UTF16:
|
||||
if(bsc->bsc.readed % sizeof(WCHAR)) {
|
||||
FIXME("The buffer is not a valid utf16 string\n");
|
||||
hres = E_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
text = heap_alloc(bsc->bsc.readed+sizeof(WCHAR));
|
||||
if(!text) {
|
||||
hres = E_OUTOFMEMORY;
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(text, bsc->buf, bsc->bsc.readed);
|
||||
text[bsc->bsc.readed/sizeof(WCHAR)] = 0;
|
||||
break;
|
||||
|
||||
case BOM_UTF8:
|
||||
default: {
|
||||
DWORD len;
|
||||
|
||||
len = MultiByteToWideChar(CP_UTF8, 0, bsc->buf, bsc->bsc.readed, NULL, 0);
|
||||
text = heap_alloc((len+1)*sizeof(WCHAR));
|
||||
if(!text) {
|
||||
hres = E_OUTOFMEMORY;
|
||||
break;
|
||||
}
|
||||
|
||||
MultiByteToWideChar(CP_UTF8, 0, bsc->buf, bsc->bsc.readed, text, len);
|
||||
text[len] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
IBindStatusCallback_Release(&bsc->bsc.IBindStatusCallback_iface);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
*ret = text;
|
||||
return S_OK;
|
||||
|
||||
}
|
||||
|
||||
static void parse_extern_script(ScriptHost *script_host, const WCHAR *src)
|
||||
{
|
||||
IMoniker *mon;
|
||||
WCHAR *text;
|
||||
|
@ -737,7 +910,7 @@ static void parse_extern_script(ScriptHost *script_host, LPCWSTR src)
|
|||
if(FAILED(hres))
|
||||
return;
|
||||
|
||||
hres = bind_mon_to_wstr(script_host->window, mon, &text);
|
||||
hres = bind_script_to_text(script_host->window, mon, &text);
|
||||
IMoniker_Release(mon);
|
||||
if(FAILED(hres) || !text)
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue