From 705fb0f239cf74be0d4d10651f440fbcefb17a94 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 9 Sep 2009 21:30:41 +0200 Subject: [PATCH] mshtml: Moved script host objects to HTMLWindow. --- dlls/mshtml/htmldoc.c | 3 --- dlls/mshtml/htmlwindow.c | 4 +++ dlls/mshtml/mshtml_private.h | 22 +++++++-------- dlls/mshtml/nsevents.c | 2 +- dlls/mshtml/persist.c | 2 +- dlls/mshtml/script.c | 52 ++++++++++++++++++------------------ 6 files changed, 43 insertions(+), 42 deletions(-) diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c index 34d5636c8f4..8b810fc0728 100644 --- a/dlls/mshtml/htmldoc.c +++ b/dlls/mshtml/htmldoc.c @@ -178,7 +178,6 @@ static ULONG WINAPI HTMLDocument_Release(IHTMLDocument2 *iface) if(!ref) { remove_doc_tasks(This); - release_script_hosts(This); if(This->client) IOleObject_SetClientSite(OLEOBJ(This), NULL); @@ -1804,10 +1803,8 @@ static HRESULT alloc_doc(HTMLDocument **ret) doc->lpSupportErrorInfoVtbl = &SupportErrorInfoVtbl; doc->ref = 1; doc->readystate = READYSTATE_UNINITIALIZED; - doc->scriptmode = SCRIPTMODE_GECKO; list_init(&doc->bindings); - list_init(&doc->script_hosts); list_init(&doc->selection_list); list_init(&doc->range_list); diff --git a/dlls/mshtml/htmlwindow.c b/dlls/mshtml/htmlwindow.c index 869b13c9944..81bcebdb7be 100644 --- a/dlls/mshtml/htmlwindow.c +++ b/dlls/mshtml/htmlwindow.c @@ -95,6 +95,7 @@ static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface) if(!ref) { if(This->event_target) release_event_target(This->event_target); + release_script_hosts(This); list_remove(&This->entry); release_dispex(&This->dispex); heap_free(This); @@ -1330,6 +1331,9 @@ HRESULT HTMLWindow_Create(HTMLDocument *doc, nsIDOMWindow *nswindow, HTMLWindow window->nswindow = nswindow; } + window->scriptmode = SCRIPTMODE_GECKO; + list_init(&window->script_hosts); + list_add_head(&window_list, &window->entry); *ret = window; diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index 4cf12b035d4..f74b2209aa6 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -153,6 +153,11 @@ void release_dispex(DispatchEx*); BOOL dispex_query_interface(DispatchEx*,REFIID,void**); HRESULT dispex_get_dprop_ref(DispatchEx*,const WCHAR*,BOOL,VARIANT**); +typedef enum { + SCRIPTMODE_GECKO, + SCRIPTMODE_ACTIVESCRIPT +} SCRIPTMODE; + typedef struct { DispatchEx dispex; const IHTMLWindow2Vtbl *lpHTMLWindow2Vtbl; @@ -167,6 +172,9 @@ typedef struct { event_target_t *event_target; IHTMLEventObj *event; + SCRIPTMODE scriptmode; + struct list script_hosts; + struct list entry; } HTMLWindow; @@ -176,11 +184,6 @@ typedef enum { EDITMODE } USERMODE; -typedef enum { - SCRIPTMODE_GECKO, - SCRIPTMODE_ACTIVESCRIPT -} SCRIPTMODE; - typedef struct { const IConnectionPointContainerVtbl *lpConnectionPointContainerVtbl; @@ -265,15 +268,12 @@ struct HTMLDocument { LPOLESTR url; struct list bindings; - struct list script_hosts; - HWND hwnd; HWND tooltips_hwnd; DOCHOSTUIINFO hostinfo; USERMODE usermode; - SCRIPTMODE scriptmode; READYSTATE readystate; BOOL in_place_active; BOOL ui_active; @@ -623,11 +623,11 @@ void HTMLElement_destructor(HTMLDOMNode*); HTMLDOMNode *get_node(HTMLDocument*,nsIDOMNode*,BOOL); void release_nodes(HTMLDocument*); -void release_script_hosts(HTMLDocument*); -void connect_scripts(HTMLDocument*); +void release_script_hosts(HTMLWindow*); +void connect_scripts(HTMLWindow*); void doc_insert_script(HTMLDocument*,nsIDOMHTMLScriptElement*); IDispatch *script_parse_event(HTMLDocument*,LPCWSTR); -void set_script_mode(HTMLDocument*,SCRIPTMODE); +void set_script_mode(HTMLWindow*,SCRIPTMODE); IHTMLElementCollection *create_all_collection(HTMLDOMNode*,BOOL); IHTMLElementCollection *create_collection_from_nodelist(HTMLDocument*,IUnknown*,nsIDOMNodeList*); diff --git a/dlls/mshtml/nsevents.c b/dlls/mshtml/nsevents.c index bacc07e0dbe..40900a75aff 100644 --- a/dlls/mshtml/nsevents.c +++ b/dlls/mshtml/nsevents.c @@ -138,7 +138,7 @@ static nsresult NSAPI handle_load(nsIDOMEventListener *iface, nsIDOMEvent *event return NS_OK; update_nsdocument(This->doc); - connect_scripts(This->doc); + connect_scripts(This->doc->window); if(This->editor_controller) { nsIController_Release(This->editor_controller); diff --git a/dlls/mshtml/persist.c b/dlls/mshtml/persist.c index 6c1a0e5f3b7..875a4e8a743 100644 --- a/dlls/mshtml/persist.c +++ b/dlls/mshtml/persist.c @@ -69,7 +69,7 @@ void set_current_mon(HTMLDocument *This, IMoniker *mon) if(FAILED(hres)) WARN("GetDisplayName failed: %08x\n", hres); - set_script_mode(This, use_gecko_script(This->url) ? SCRIPTMODE_GECKO : SCRIPTMODE_ACTIVESCRIPT); + set_script_mode(This->window, use_gecko_script(This->url) ? SCRIPTMODE_GECKO : SCRIPTMODE_ACTIVESCRIPT); } static HRESULT set_moniker(HTMLDocument *This, IMoniker *mon, IBindCtx *pibc, BOOL *bind_complete) diff --git a/dlls/mshtml/script.c b/dlls/mshtml/script.c index e12588ccd3e..3046a7d12e0 100644 --- a/dlls/mshtml/script.c +++ b/dlls/mshtml/script.c @@ -56,7 +56,7 @@ typedef struct { SCRIPTSTATE script_state; - HTMLDocument *doc; + HTMLWindow *window; GUID guid; struct list entry; @@ -206,11 +206,11 @@ static void release_script_engine(ScriptHost *This) This->script_state = SCRIPTSTATE_UNINITIALIZED; } -void connect_scripts(HTMLDocument *doc) +void connect_scripts(HTMLWindow *window) { ScriptHost *iter; - LIST_FOR_EACH_ENTRY(iter, &doc->script_hosts, ScriptHost, entry) { + LIST_FOR_EACH_ENTRY(iter, &window->script_hosts, ScriptHost, entry) { if(iter->script_state == SCRIPTSTATE_STARTED) IActiveScript_SetScriptState(iter->script, SCRIPTSTATE_CONNECTED); } @@ -270,7 +270,7 @@ static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface) if(!ref) { release_script_engine(This); - if(This->doc) + if(This->window) list_remove(&This->entry); heap_free(This); } @@ -305,11 +305,11 @@ static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPC if(strcmpW(pstrName, windowW)) return DISP_E_MEMBERNOTFOUND; - if(!This->doc) + if(!This->window) return E_FAIL; /* FIXME: Return proxy object */ - *ppiunkItem = (IUnknown*)HTMLWINDOW2(This->doc->window); + *ppiunkItem = (IUnknown*)HTMLWINDOW2(This->window); IUnknown_AddRef(*ppiunkItem); return S_OK; @@ -529,7 +529,7 @@ static const IActiveScriptSiteDebug32Vtbl ActiveScriptSiteDebug32Vtbl = { ActiveScriptSiteDebug32_OnScriptErrorDebug }; -static ScriptHost *create_script_host(HTMLDocument *doc, const GUID *guid) +static ScriptHost *create_script_host(HTMLWindow *window, const GUID *guid) { ScriptHost *ret; HRESULT hres; @@ -540,11 +540,11 @@ static ScriptHost *create_script_host(HTMLDocument *doc, const GUID *guid) ret->lpIActiveScriptSiteWindowVtbl = &ActiveScriptSiteWindowVtbl; ret->lpIActiveScriptSiteDebug32Vtbl = &ActiveScriptSiteDebug32Vtbl; ret->ref = 1; - ret->doc = doc; + ret->window = window; ret->script_state = SCRIPTSTATE_UNINITIALIZED; ret->guid = *guid; - list_add_tail(&doc->script_hosts, &ret->entry); + list_add_tail(&window->script_hosts, &ret->entry); hres = CoCreateInstance(&ret->guid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, &IID_IActiveScript, (void**)&ret->script); @@ -593,7 +593,7 @@ static void parse_extern_script(ScriptHost *script_host, LPCWSTR src) if(FAILED(hres)) return; - hres = bind_mon_to_buffer(script_host->doc, mon, (void**)&buf, &size); + hres = bind_mon_to_buffer(script_host->window->doc, mon, (void**)&buf, &size); IMoniker_Release(mon); if(FAILED(hres)) return; @@ -727,21 +727,21 @@ static BOOL get_script_guid(nsIDOMHTMLScriptElement *nsscript, GUID *guid) return ret; } -static ScriptHost *get_script_host(HTMLDocument *doc, const GUID *guid) +static ScriptHost *get_script_host(HTMLWindow *window, const GUID *guid) { ScriptHost *iter; - if(IsEqualGUID(&CLSID_JScript, guid) && doc->scriptmode != SCRIPTMODE_ACTIVESCRIPT) { + if(IsEqualGUID(&CLSID_JScript, guid) && window->scriptmode != SCRIPTMODE_ACTIVESCRIPT) { TRACE("Ignoring JScript\n"); return NULL; } - LIST_FOR_EACH_ENTRY(iter, &doc->script_hosts, ScriptHost, entry) { + LIST_FOR_EACH_ENTRY(iter, &window->script_hosts, ScriptHost, entry) { if(IsEqualGUID(guid, &iter->guid)) return iter; } - return create_script_host(doc, guid); + return create_script_host(window, guid); } void doc_insert_script(HTMLDocument *doc, nsIDOMHTMLScriptElement *nsscript) @@ -754,7 +754,7 @@ void doc_insert_script(HTMLDocument *doc, nsIDOMHTMLScriptElement *nsscript) return; } - script_host = get_script_host(doc, &guid); + script_host = get_script_host(doc->window, &guid); if(!script_host) return; @@ -795,7 +795,7 @@ IDispatch *script_parse_event(HTMLDocument *doc, LPCWSTR text) ptr = text; } - script_host = get_script_host(doc, &guid); + script_host = get_script_host(doc->window, &guid); if(!script_host || !script_host->parse_proc) return NULL; @@ -831,27 +831,27 @@ static BOOL is_jscript_available(void) return available; } -void set_script_mode(HTMLDocument *doc, SCRIPTMODE mode) +void set_script_mode(HTMLWindow *window, SCRIPTMODE mode) { nsIWebBrowserSetup *setup; nsresult nsres; if(mode == SCRIPTMODE_ACTIVESCRIPT && !is_jscript_available()) { TRACE("jscript.dll not available\n"); - doc->scriptmode = SCRIPTMODE_GECKO; + window->scriptmode = SCRIPTMODE_GECKO; return; } - doc->scriptmode = mode; + window->scriptmode = mode; - if(!doc->nscontainer || !doc->nscontainer->webbrowser) + if(!window->doc->nscontainer || !window->doc->nscontainer->webbrowser) return; - nsres = nsIWebBrowser_QueryInterface(doc->nscontainer->webbrowser, + nsres = nsIWebBrowser_QueryInterface(window->doc->nscontainer->webbrowser, &IID_nsIWebBrowserSetup, (void**)&setup); if(NS_SUCCEEDED(nsres)) { nsres = nsIWebBrowserSetup_SetProperty(setup, SETUP_ALLOW_JAVASCRIPT, - doc->scriptmode == SCRIPTMODE_GECKO); + window->scriptmode == SCRIPTMODE_GECKO); nsIWebBrowserSetup_Release(setup); } @@ -859,16 +859,16 @@ void set_script_mode(HTMLDocument *doc, SCRIPTMODE mode) ERR("JavaScript setup failed: %08x\n", nsres); } -void release_script_hosts(HTMLDocument *doc) +void release_script_hosts(HTMLWindow *window) { ScriptHost *iter; - while(!list_empty(&doc->script_hosts)) { - iter = LIST_ENTRY(list_head(&doc->script_hosts), ScriptHost, entry); + while(!list_empty(&window->script_hosts)) { + iter = LIST_ENTRY(list_head(&window->script_hosts), ScriptHost, entry); release_script_engine(iter); list_remove(&iter->entry); - iter->doc = NULL; + iter->window = NULL; IActiveScript_Release(ACTSCPSITE(iter)); } }