From: Gabriel Ivăncescu gabrielopcode@gmail.com
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/mshtml/htmlwindow.c | 230 ++++++++++++++++++++++++++++------- dlls/mshtml/mshtml_private.h | 2 + dlls/mshtml/nsembed.c | 1 + dlls/mshtml/persist.c | 3 +- 4 files changed, 192 insertions(+), 44 deletions(-)
diff --git a/dlls/mshtml/htmlwindow.c b/dlls/mshtml/htmlwindow.c index a6b204881d2..8a5ca5b441c 100644 --- a/dlls/mshtml/htmlwindow.c +++ b/dlls/mshtml/htmlwindow.c @@ -45,6 +45,8 @@
WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
+static ExternalCycleCollectionParticipant outer_window_ccp; + static int window_map_compare(const void *key, const struct wine_rb_entry *entry) { HTMLOuterWindow *window = WINE_RB_ENTRY_VALUE(entry, HTMLOuterWindow, entry); @@ -198,9 +200,12 @@ static HRESULT WINAPI HTMLWindow2_QueryInterface(IHTMLWindow2 *iface, REFIID rii *ppv = NULL; FIXME("(%p)->(IID_IMarshal %p)\n", This, ppv); return E_NOINTERFACE; - }else if(dispex_query_interface(&This->inner_window->event_target.dispex, riid, ppv)) { - assert(!*ppv); - return E_NOINTERFACE; + }else if(IsEqualGUID(&IID_nsXPCOMCycleCollectionParticipant, riid) && is_outer_window(This)) { + *ppv = &outer_window_ccp; + return S_OK; + }else if(IsEqualGUID(&IID_nsCycleCollectionISupports, riid) && is_outer_window(This)) { + *ppv = &This->IHTMLWindow2_iface; + return S_OK; }else { return EventTarget_QI(&This->inner_window->event_target, riid, ppv); } @@ -219,57 +224,36 @@ static ULONG WINAPI HTMLWindow2_AddRef(IHTMLWindow2 *iface) return ref; }
-static void release_outer_window(HTMLOuterWindow *This) +static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface) { - if(This->browser) { - list_remove(&This->browser_entry); - This->browser = NULL; - } + HTMLWindow *This = impl_from_IHTMLWindow2(iface); + LONG ref = InterlockedDecrement(&This->ref);
- if(This->pending_window) { - abort_window_bindings(This->pending_window); - This->pending_window->base.outer_window = NULL; - IHTMLWindow2_Release(&This->pending_window->base.IHTMLWindow2_iface); - } + TRACE("(%p) ref=%ld\n", This, ref);
- remove_target_tasks(This->task_magic); - set_current_mon(This, NULL, 0); - set_current_uri(This, NULL); - if(This->base.inner_window) - detach_inner_window(This->base.inner_window); + if(!ref) + release_dispex(&This->inner_window->event_target.dispex);
- if(This->location) - IHTMLLocation_Release(&This->location->IHTMLLocation_iface); + return ref; +}
- if(This->frame_element) - This->frame_element->content_window = NULL; +static ULONG WINAPI outer_window_AddRef(IHTMLWindow2 *iface) +{ + HTMLOuterWindow *This = impl_from_IHTMLWindow2(iface)->outer_window; + LONG ref = ccref_incr(&This->ccref, (nsISupports*)&This->base.IHTMLWindow2_iface);
- if(This->nswindow) - nsIDOMWindow_Release(This->nswindow); - if(This->window_proxy) - mozIDOMWindowProxy_Release(This->window_proxy); + TRACE("(%p) ref=%ld\n", This, ref);
- wine_rb_remove(&window_map, &This->entry); - free(This); + return ref; }
-static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface) +static ULONG WINAPI outer_window_Release(IHTMLWindow2 *iface) { - HTMLWindow *This = impl_from_IHTMLWindow2(iface); - LONG ref = InterlockedDecrement(&This->ref); + HTMLOuterWindow *This = impl_from_IHTMLWindow2(iface)->outer_window; + LONG ref = ccref_decr(&This->ccref, (nsISupports*)&This->base.IHTMLWindow2_iface, &outer_window_ccp);
TRACE("(%p) ref=%ld\n", This, ref);
- if(!ref) { - if (This->console) - IWineMSHTMLConsole_Release(This->console); - - if(is_outer_window(This)) - release_outer_window(This->outer_window); - else - release_dispex(&This->inner_window->event_target.dispex); - } - return ref; }
@@ -1559,6 +1543,86 @@ static const IHTMLWindow2Vtbl HTMLWindow2Vtbl = { HTMLWindow2_get_external };
+static const IHTMLWindow2Vtbl outer_window_HTMLWindow2Vtbl = { + HTMLWindow2_QueryInterface, + outer_window_AddRef, + outer_window_Release, + HTMLWindow2_GetTypeInfoCount, + HTMLWindow2_GetTypeInfo, + HTMLWindow2_GetIDsOfNames, + HTMLWindow2_Invoke, + HTMLWindow2_item, + HTMLWindow2_get_length, + HTMLWindow2_get_frames, + HTMLWindow2_put_defaultStatus, + HTMLWindow2_get_defaultStatus, + HTMLWindow2_put_status, + HTMLWindow2_get_status, + HTMLWindow2_setTimeout, + HTMLWindow2_clearTimeout, + HTMLWindow2_alert, + HTMLWindow2_confirm, + HTMLWindow2_prompt, + HTMLWindow2_get_Image, + HTMLWindow2_get_location, + HTMLWindow2_get_history, + HTMLWindow2_close, + HTMLWindow2_put_opener, + HTMLWindow2_get_opener, + HTMLWindow2_get_navigator, + HTMLWindow2_put_name, + HTMLWindow2_get_name, + HTMLWindow2_get_parent, + HTMLWindow2_open, + HTMLWindow2_get_self, + HTMLWindow2_get_top, + HTMLWindow2_get_window, + HTMLWindow2_navigate, + HTMLWindow2_put_onfocus, + HTMLWindow2_get_onfocus, + HTMLWindow2_put_onblur, + HTMLWindow2_get_onblur, + HTMLWindow2_put_onload, + HTMLWindow2_get_onload, + HTMLWindow2_put_onbeforeunload, + HTMLWindow2_get_onbeforeunload, + HTMLWindow2_put_onunload, + HTMLWindow2_get_onunload, + HTMLWindow2_put_onhelp, + HTMLWindow2_get_onhelp, + HTMLWindow2_put_onerror, + HTMLWindow2_get_onerror, + HTMLWindow2_put_onresize, + HTMLWindow2_get_onresize, + HTMLWindow2_put_onscroll, + HTMLWindow2_get_onscroll, + HTMLWindow2_get_document, + HTMLWindow2_get_event, + HTMLWindow2_get__newEnum, + HTMLWindow2_showModalDialog, + HTMLWindow2_showHelp, + HTMLWindow2_get_screen, + HTMLWindow2_get_Option, + HTMLWindow2_focus, + HTMLWindow2_get_closed, + HTMLWindow2_blur, + HTMLWindow2_scroll, + HTMLWindow2_get_clientInformation, + HTMLWindow2_setInterval, + HTMLWindow2_clearInterval, + HTMLWindow2_put_offscreenBuffering, + HTMLWindow2_get_offscreenBuffering, + HTMLWindow2_execScript, + HTMLWindow2_toString, + HTMLWindow2_scrollBy, + HTMLWindow2_scrollTo, + HTMLWindow2_moveTo, + HTMLWindow2_moveBy, + HTMLWindow2_resizeTo, + HTMLWindow2_resizeBy, + HTMLWindow2_get_external +}; + static inline HTMLWindow *impl_from_IHTMLWindow3(IHTMLWindow3 *iface) { return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow3_iface); @@ -4081,6 +4145,84 @@ static dispex_static_data_t HTMLWindow_dispex = { HTMLWindow_init_dispex_info };
+static nsresult NSAPI outer_window_traverse(void *ccp, void *p, nsCycleCollectionTraversalCallback *cb) +{ + HTMLOuterWindow *window = impl_from_IHTMLWindow2(p)->outer_window; + + describe_cc_node(&window->ccref, "OuterWindow", cb); + + if(window->base.console) + note_cc_edge((nsISupports*)window->base.console, "console", cb); + if(window->pending_window) + note_cc_edge((nsISupports*)&window->pending_window->base.IHTMLWindow2_iface, "pending_window", cb); + if(window->base.inner_window) + note_cc_edge((nsISupports*)&window->base.inner_window->base.IHTMLWindow2_iface, "inner_window", cb); + if(window->location) + note_cc_edge((nsISupports*)&window->location->IHTMLLocation_iface, "location", cb); + if(window->nswindow) + note_cc_edge((nsISupports*)window->nswindow, "nswindow", cb); + if(window->window_proxy) + note_cc_edge((nsISupports*)window->window_proxy, "window_proxy", cb); + return NS_OK; +} + +static nsresult NSAPI outer_window_unlink(void *p) +{ + HTMLOuterWindow *window = impl_from_IHTMLWindow2(p)->outer_window; + + remove_target_tasks(window->task_magic); + unlink_ref(&window->base.console); + + if(window->browser) { + list_remove(&window->browser_entry); + window->browser = NULL; + } + if(window->pending_window) { + HTMLInnerWindow *pending_window = window->pending_window; + abort_window_bindings(pending_window); + pending_window->base.outer_window = NULL; + window->pending_window = NULL; + IHTMLWindow2_Release(&pending_window->base.IHTMLWindow2_iface); + } + + set_current_mon(window, NULL, 0); + set_current_uri(window, NULL); + if(window->base.inner_window) + detach_inner_window(window->base.inner_window); + if(window->location) { + HTMLLocation *location = window->location; + window->location = NULL; + IHTMLLocation_Release(&location->IHTMLLocation_iface); + } + if(window->frame_element) { + window->frame_element->content_window = NULL; + window->frame_element = NULL; + } + unlink_ref(&window->nswindow); + if(window->window_proxy) { + unlink_ref(&window->window_proxy); + wine_rb_remove(&window_map, &window->entry); + } + return NS_OK; +} + +static void NSAPI outer_window_delete_cycle_collectable(void *p) +{ + HTMLOuterWindow *window = impl_from_IHTMLWindow2(p)->outer_window; + outer_window_unlink(p); + free(window); +} + +void init_window_cc(void) +{ + static const CCObjCallback ccp_callback = { + outer_window_traverse, + outer_window_unlink, + outer_window_delete_cycle_collectable + }; + ccp_init(&outer_window_ccp, &ccp_callback); +} + static void *alloc_window(size_t size) { HTMLWindow *window; @@ -4089,7 +4231,6 @@ static void *alloc_window(size_t size) if(!window) return NULL;
- window->IHTMLWindow2_iface.lpVtbl = &HTMLWindow2Vtbl; window->IHTMLWindow3_iface.lpVtbl = &HTMLWindow3Vtbl; window->IHTMLWindow4_iface.lpVtbl = &HTMLWindow4Vtbl; window->IHTMLWindow5_iface.lpVtbl = &HTMLWindow5Vtbl; @@ -4103,7 +4244,6 @@ static void *alloc_window(size_t size) window->IProvideMultipleClassInfo_iface.lpVtbl = &ProvideMultipleClassInfoVtbl; window->IWineHTMLWindowPrivate_iface.lpVtbl = &WineHTMLWindowPrivateVtbl; window->IWineHTMLWindowCompatPrivate_iface.lpVtbl = &WineHTMLWindowCompatPrivateVtbl; - window->ref = 1;
return window; } @@ -4115,6 +4255,7 @@ static HRESULT create_inner_window(HTMLOuterWindow *outer_window, IMoniker *mon, window = alloc_window(sizeof(HTMLInnerWindow)); if(!window) return E_OUTOFMEMORY; + window->base.IHTMLWindow2_iface.lpVtbl = &HTMLWindow2Vtbl;
list_init(&window->children); list_init(&window->script_hosts); @@ -4124,6 +4265,7 @@ static HRESULT create_inner_window(HTMLOuterWindow *outer_window, IMoniker *mon, window->base.outer_window = outer_window; window->base.inner_window = window;
+ window->base.ref = 1; EventTarget_Init(&window->event_target, (IUnknown*)&window->base.IHTMLWindow2_iface, &HTMLWindow_dispex, COMPAT_MODE_NONE);
@@ -4148,11 +4290,13 @@ HRESULT create_outer_window(GeckoBrowser *browser, mozIDOMWindowProxy *mozwindow window = alloc_window(sizeof(HTMLOuterWindow)); if(!window) return E_OUTOFMEMORY; + window->base.IHTMLWindow2_iface.lpVtbl = &outer_window_HTMLWindow2Vtbl;
window->base.outer_window = window; window->base.inner_window = NULL; window->browser = browser; list_add_head(&browser->outer_windows, &window->browser_entry); + ccref_init(&window->ccref, 1);
mozIDOMWindowProxy_AddRef(mozwindow); window->window_proxy = mozwindow; diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index 32ab0fa871a..47d6f4421e2 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -557,6 +557,7 @@ struct HTMLWindow { struct HTMLOuterWindow { HTMLWindow base;
+ nsCycleCollectingAutoRefCnt ccref; LONG task_magic;
nsIDOMWindow *nswindow; @@ -1070,6 +1071,7 @@ BOOL is_gecko_path(const char*); void set_viewer_zoom(GeckoBrowser*,float); float get_viewer_zoom(GeckoBrowser*);
+void init_window_cc(void); void init_node_cc(void);
HRESULT nsuri_to_url(LPCWSTR,BOOL,BSTR*); diff --git a/dlls/mshtml/nsembed.c b/dlls/mshtml/nsembed.c index 21ddb3cb38f..61d4ec335b4 100644 --- a/dlls/mshtml/nsembed.c +++ b/dlls/mshtml/nsembed.c @@ -596,6 +596,7 @@ static BOOL init_xpcom(const PRUnichar *gre_path) ERR("NS_GetComponentRegistrar failed: %08lx\n", nsres); }
+ init_window_cc(); init_node_cc();
return TRUE; diff --git a/dlls/mshtml/persist.c b/dlls/mshtml/persist.c index bea2ab65750..dd79d85a1c5 100644 --- a/dlls/mshtml/persist.c +++ b/dlls/mshtml/persist.c @@ -466,7 +466,8 @@ static void notif_readystate(HTMLOuterWindow *window)
static void notif_readystate_proc(event_task_t *task) { - notif_readystate(task->window->base.outer_window); + if(task->window->base.outer_window) + notif_readystate(task->window->base.outer_window); }
static void notif_readystate_destr(event_task_t *task)