Commit d9f49ba2 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

shdocvw: Use task destructors for releasing task params.

parent dda91ac0
......@@ -31,9 +31,10 @@ DEFINE_OLEGUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0);
static ATOM doc_view_atom = 0;
void push_dochost_task(DocHost *This, task_header_t *task, task_proc_t proc, BOOL send)
void push_dochost_task(DocHost *This, task_header_t *task, task_proc_t proc, task_destr_t destr, BOOL send)
{
task->proc = proc;
task->destr = destr;
/* FIXME: Don't use lParam */
if(send)
......@@ -48,6 +49,9 @@ LRESULT process_dochost_task(DocHost *This, LPARAM lparam)
task->proc(This, task);
if(task->destr)
task->destr(task);
else
heap_free(task);
return 0;
}
......@@ -185,14 +189,20 @@ typedef struct {
READYSTATE ready_state;
} ready_state_task_t;
static void ready_state_task_destr(task_header_t *_task)
{
ready_state_task_t *task = (ready_state_task_t*)_task;
IUnknown_Release(task->doc);
heap_free(task);
}
static void ready_state_proc(DocHost *This, task_header_t *_task)
{
ready_state_task_t *task = (ready_state_task_t*)_task;
if(task->doc == This->document)
update_ready_state(This, task->ready_state);
IUnknown_Release(task->doc);
}
static void push_ready_state_task(DocHost *This, READYSTATE ready_state)
......@@ -203,7 +213,12 @@ static void push_ready_state_task(DocHost *This, READYSTATE ready_state)
task->doc = This->document;
task->ready_state = ready_state;
push_dochost_task(This, &task->header, ready_state_proc, FALSE);
push_dochost_task(This, &task->header, ready_state_proc, ready_state_task_destr, FALSE);
}
static void object_available_task_destr(task_header_t *task)
{
heap_free(task);
}
static void object_available_proc(DocHost *This, task_header_t *task)
......@@ -242,7 +257,7 @@ HRESULT dochost_object_available(DocHost *This, IUnknown *doc)
/* FIXME: Call SetAdvise */
task = heap_alloc(sizeof(*task));
push_dochost_task(This, task, object_available_proc, FALSE);
push_dochost_task(This, task, object_available_proc, object_available_task_destr, FALSE);
hres = get_doc_ready_state(This, &ready_state);
if(SUCCEEDED(hres)) {
......
......@@ -674,15 +674,15 @@ typedef struct {
BOOL async_notif;
} task_doc_navigate_t;
static HRESULT free_doc_navigate_task(task_doc_navigate_t *task, BOOL free_task)
static void doc_navigate_task_destr(task_header_t *t)
{
task_doc_navigate_t *task = (task_doc_navigate_t*)t;
SysFreeString(task->url);
SysFreeString(task->headers);
if(task->post_data)
SafeArrayDestroy(task->post_data);
if(free_task)
heap_free(task);
return E_OUTOFMEMORY;
}
static void doc_navigate_proc(DocHost *This, task_header_t *t)
......@@ -691,15 +691,16 @@ static void doc_navigate_proc(DocHost *This, task_header_t *t)
IHTMLPrivateWindow *priv_window;
HRESULT hres;
if(!This->doc_navigate)
if(!This->doc_navigate) {
ERR("Skip nav\n");
return;
}
if(task->async_notif) {
VARIANT_BOOL cancel = VARIANT_FALSE;
on_before_navigate2(This, task->url, task->post_data, task->headers, &cancel);
if(cancel) {
TRACE("Navigation calnceled\n");
free_doc_navigate_task(task, FALSE);
return;
}
}
......@@ -711,8 +712,6 @@ static void doc_navigate_proc(DocHost *This, task_header_t *t)
}else {
WARN("Could not get IHTMLPrivateWindow iface: %08x\n", hres);
}
free_doc_navigate_task(task, FALSE);
}
static HRESULT async_doc_navigate(DocHost *This, LPCWSTR url, LPCWSTR headers, PBYTE post_data, ULONG post_data_size,
......@@ -720,24 +719,33 @@ static HRESULT async_doc_navigate(DocHost *This, LPCWSTR url, LPCWSTR headers, P
{
task_doc_navigate_t *task;
TRACE("%s\n", debugstr_w(url));
task = heap_alloc_zero(sizeof(*task));
if(!task)
return E_OUTOFMEMORY;
task->url = SysAllocString(url);
if(!task->url)
return free_doc_navigate_task(task, TRUE);
if(!task->url) {
doc_navigate_task_destr(&task->header);
return E_OUTOFMEMORY;
}
if(headers) {
task->headers = SysAllocString(headers);
if(!task->headers)
return free_doc_navigate_task(task, TRUE);
if(!task->headers) {
doc_navigate_task_destr(&task->header);
return E_OUTOFMEMORY;
}
}
if(post_data) {
task->post_data = SafeArrayCreateVector(VT_UI1, 0, post_data_size);
if(!task->post_data)
return free_doc_navigate_task(task, TRUE);
if(!task->post_data) {
doc_navigate_task_destr(&task->header);
return E_OUTOFMEMORY;
}
memcpy(task->post_data->pvData, post_data, post_data_size);
}
......@@ -747,13 +755,13 @@ static HRESULT async_doc_navigate(DocHost *This, LPCWSTR url, LPCWSTR headers, P
on_before_navigate2(This, task->url, task->post_data, task->headers, &cancel);
if(cancel) {
TRACE("Navigation calnceled\n");
free_doc_navigate_task(task, TRUE);
doc_navigate_task_destr(&task->header);
return S_OK;
}
}
task->async_notif = async_notif;
push_dochost_task(This, &task->header, doc_navigate_proc, FALSE);
push_dochost_task(This, &task->header, doc_navigate_proc, doc_navigate_task_destr, FALSE);
return S_OK;
}
......@@ -802,6 +810,14 @@ typedef struct {
BindStatusCallback *bsc;
} task_navigate_bsc_t;
static void navigate_bsc_task_destr(task_header_t *t)
{
task_navigate_bsc_t *task = (task_navigate_bsc_t*)t;
IBindStatusCallback_Release(&task->bsc->IBindStatusCallback_iface);
heap_free(task);
}
static void navigate_bsc_proc(DocHost *This, task_header_t *t)
{
task_navigate_bsc_t *task = (task_navigate_bsc_t*)t;
......@@ -810,8 +826,6 @@ static void navigate_bsc_proc(DocHost *This, task_header_t *t)
create_doc_view_hwnd(This);
navigate_bsc(This, task->bsc, NULL);
IBindStatusCallback_Release(&task->bsc->IBindStatusCallback_iface);
}
......@@ -868,7 +882,7 @@ HRESULT navigate_url(DocHost *This, LPCWSTR url, const VARIANT *Flags,
task = heap_alloc(sizeof(*task));
task->bsc = create_callback(This, url, post_data, post_data_len, headers);
push_dochost_task(This, &task->header, navigate_bsc_proc, This->url == NULL);
push_dochost_task(This, &task->header, navigate_bsc_proc, navigate_bsc_task_destr, This->url == NULL);
}
if(post_data)
......@@ -889,6 +903,8 @@ static HRESULT navigate_hlink(DocHost *This, IMoniker *mon, IBindCtx *bindctx,
DWORD bindf = 0;
HRESULT hres;
TRACE("\n");
hres = IMoniker_GetDisplayName(mon, 0, NULL, &url);
if(FAILED(hres))
FIXME("GetDisplayName failed: %08x\n", hres);
......
......@@ -80,9 +80,11 @@ typedef struct {
struct _task_header_t;
typedef void (*task_proc_t)(DocHost*, struct _task_header_t*);
typedef void (*task_destr_t)(struct _task_header_t*);
typedef struct _task_header_t {
task_proc_t proc;
task_destr_t destr;
} task_header_t;
typedef struct _IDocHostContainerVtbl
......@@ -244,7 +246,7 @@ HRESULT get_location_url(DocHost*,BSTR*) DECLSPEC_HIDDEN;
void handle_navigation_error(DocHost*,HRESULT,BSTR,IHTMLWindow2*) DECLSPEC_HIDDEN;
#define WM_DOCHOSTTASK (WM_USER+0x300)
void push_dochost_task(DocHost*,task_header_t*,task_proc_t,BOOL) DECLSPEC_HIDDEN;
void push_dochost_task(DocHost*,task_header_t*,task_proc_t,task_destr_t,BOOL) DECLSPEC_HIDDEN;
LRESULT process_dochost_task(DocHost*,LPARAM) DECLSPEC_HIDDEN;
HRESULT InternetExplorer_Create(IUnknown*,REFIID,void**) DECLSPEC_HIDDEN;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment