mshtml: Moved script host objects to HTMLWindow.

This commit is contained in:
Jacek Caban 2009-09-09 21:30:41 +02:00 committed by Alexandre Julliard
parent 43256560e9
commit 705fb0f239
6 changed files with 43 additions and 42 deletions

View File

@ -178,7 +178,6 @@ static ULONG WINAPI HTMLDocument_Release(IHTMLDocument2 *iface)
if(!ref) { if(!ref) {
remove_doc_tasks(This); remove_doc_tasks(This);
release_script_hosts(This);
if(This->client) if(This->client)
IOleObject_SetClientSite(OLEOBJ(This), NULL); IOleObject_SetClientSite(OLEOBJ(This), NULL);
@ -1804,10 +1803,8 @@ static HRESULT alloc_doc(HTMLDocument **ret)
doc->lpSupportErrorInfoVtbl = &SupportErrorInfoVtbl; doc->lpSupportErrorInfoVtbl = &SupportErrorInfoVtbl;
doc->ref = 1; doc->ref = 1;
doc->readystate = READYSTATE_UNINITIALIZED; doc->readystate = READYSTATE_UNINITIALIZED;
doc->scriptmode = SCRIPTMODE_GECKO;
list_init(&doc->bindings); list_init(&doc->bindings);
list_init(&doc->script_hosts);
list_init(&doc->selection_list); list_init(&doc->selection_list);
list_init(&doc->range_list); list_init(&doc->range_list);

View File

@ -95,6 +95,7 @@ static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
if(!ref) { if(!ref) {
if(This->event_target) if(This->event_target)
release_event_target(This->event_target); release_event_target(This->event_target);
release_script_hosts(This);
list_remove(&This->entry); list_remove(&This->entry);
release_dispex(&This->dispex); release_dispex(&This->dispex);
heap_free(This); heap_free(This);
@ -1330,6 +1331,9 @@ HRESULT HTMLWindow_Create(HTMLDocument *doc, nsIDOMWindow *nswindow, HTMLWindow
window->nswindow = nswindow; window->nswindow = nswindow;
} }
window->scriptmode = SCRIPTMODE_GECKO;
list_init(&window->script_hosts);
list_add_head(&window_list, &window->entry); list_add_head(&window_list, &window->entry);
*ret = window; *ret = window;

View File

@ -153,6 +153,11 @@ void release_dispex(DispatchEx*);
BOOL dispex_query_interface(DispatchEx*,REFIID,void**); BOOL dispex_query_interface(DispatchEx*,REFIID,void**);
HRESULT dispex_get_dprop_ref(DispatchEx*,const WCHAR*,BOOL,VARIANT**); HRESULT dispex_get_dprop_ref(DispatchEx*,const WCHAR*,BOOL,VARIANT**);
typedef enum {
SCRIPTMODE_GECKO,
SCRIPTMODE_ACTIVESCRIPT
} SCRIPTMODE;
typedef struct { typedef struct {
DispatchEx dispex; DispatchEx dispex;
const IHTMLWindow2Vtbl *lpHTMLWindow2Vtbl; const IHTMLWindow2Vtbl *lpHTMLWindow2Vtbl;
@ -167,6 +172,9 @@ typedef struct {
event_target_t *event_target; event_target_t *event_target;
IHTMLEventObj *event; IHTMLEventObj *event;
SCRIPTMODE scriptmode;
struct list script_hosts;
struct list entry; struct list entry;
} HTMLWindow; } HTMLWindow;
@ -176,11 +184,6 @@ typedef enum {
EDITMODE EDITMODE
} USERMODE; } USERMODE;
typedef enum {
SCRIPTMODE_GECKO,
SCRIPTMODE_ACTIVESCRIPT
} SCRIPTMODE;
typedef struct { typedef struct {
const IConnectionPointContainerVtbl *lpConnectionPointContainerVtbl; const IConnectionPointContainerVtbl *lpConnectionPointContainerVtbl;
@ -265,15 +268,12 @@ struct HTMLDocument {
LPOLESTR url; LPOLESTR url;
struct list bindings; struct list bindings;
struct list script_hosts;
HWND hwnd; HWND hwnd;
HWND tooltips_hwnd; HWND tooltips_hwnd;
DOCHOSTUIINFO hostinfo; DOCHOSTUIINFO hostinfo;
USERMODE usermode; USERMODE usermode;
SCRIPTMODE scriptmode;
READYSTATE readystate; READYSTATE readystate;
BOOL in_place_active; BOOL in_place_active;
BOOL ui_active; BOOL ui_active;
@ -623,11 +623,11 @@ void HTMLElement_destructor(HTMLDOMNode*);
HTMLDOMNode *get_node(HTMLDocument*,nsIDOMNode*,BOOL); HTMLDOMNode *get_node(HTMLDocument*,nsIDOMNode*,BOOL);
void release_nodes(HTMLDocument*); void release_nodes(HTMLDocument*);
void release_script_hosts(HTMLDocument*); void release_script_hosts(HTMLWindow*);
void connect_scripts(HTMLDocument*); void connect_scripts(HTMLWindow*);
void doc_insert_script(HTMLDocument*,nsIDOMHTMLScriptElement*); void doc_insert_script(HTMLDocument*,nsIDOMHTMLScriptElement*);
IDispatch *script_parse_event(HTMLDocument*,LPCWSTR); 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_all_collection(HTMLDOMNode*,BOOL);
IHTMLElementCollection *create_collection_from_nodelist(HTMLDocument*,IUnknown*,nsIDOMNodeList*); IHTMLElementCollection *create_collection_from_nodelist(HTMLDocument*,IUnknown*,nsIDOMNodeList*);

View File

@ -138,7 +138,7 @@ static nsresult NSAPI handle_load(nsIDOMEventListener *iface, nsIDOMEvent *event
return NS_OK; return NS_OK;
update_nsdocument(This->doc); update_nsdocument(This->doc);
connect_scripts(This->doc); connect_scripts(This->doc->window);
if(This->editor_controller) { if(This->editor_controller) {
nsIController_Release(This->editor_controller); nsIController_Release(This->editor_controller);

View File

@ -69,7 +69,7 @@ void set_current_mon(HTMLDocument *This, IMoniker *mon)
if(FAILED(hres)) if(FAILED(hres))
WARN("GetDisplayName failed: %08x\n", 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) static HRESULT set_moniker(HTMLDocument *This, IMoniker *mon, IBindCtx *pibc, BOOL *bind_complete)

View File

@ -56,7 +56,7 @@ typedef struct {
SCRIPTSTATE script_state; SCRIPTSTATE script_state;
HTMLDocument *doc; HTMLWindow *window;
GUID guid; GUID guid;
struct list entry; struct list entry;
@ -206,11 +206,11 @@ static void release_script_engine(ScriptHost *This)
This->script_state = SCRIPTSTATE_UNINITIALIZED; This->script_state = SCRIPTSTATE_UNINITIALIZED;
} }
void connect_scripts(HTMLDocument *doc) void connect_scripts(HTMLWindow *window)
{ {
ScriptHost *iter; 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) if(iter->script_state == SCRIPTSTATE_STARTED)
IActiveScript_SetScriptState(iter->script, SCRIPTSTATE_CONNECTED); IActiveScript_SetScriptState(iter->script, SCRIPTSTATE_CONNECTED);
} }
@ -270,7 +270,7 @@ static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
if(!ref) { if(!ref) {
release_script_engine(This); release_script_engine(This);
if(This->doc) if(This->window)
list_remove(&This->entry); list_remove(&This->entry);
heap_free(This); heap_free(This);
} }
@ -305,11 +305,11 @@ static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPC
if(strcmpW(pstrName, windowW)) if(strcmpW(pstrName, windowW))
return DISP_E_MEMBERNOTFOUND; return DISP_E_MEMBERNOTFOUND;
if(!This->doc) if(!This->window)
return E_FAIL; return E_FAIL;
/* FIXME: Return proxy object */ /* FIXME: Return proxy object */
*ppiunkItem = (IUnknown*)HTMLWINDOW2(This->doc->window); *ppiunkItem = (IUnknown*)HTMLWINDOW2(This->window);
IUnknown_AddRef(*ppiunkItem); IUnknown_AddRef(*ppiunkItem);
return S_OK; return S_OK;
@ -529,7 +529,7 @@ static const IActiveScriptSiteDebug32Vtbl ActiveScriptSiteDebug32Vtbl = {
ActiveScriptSiteDebug32_OnScriptErrorDebug ActiveScriptSiteDebug32_OnScriptErrorDebug
}; };
static ScriptHost *create_script_host(HTMLDocument *doc, const GUID *guid) static ScriptHost *create_script_host(HTMLWindow *window, const GUID *guid)
{ {
ScriptHost *ret; ScriptHost *ret;
HRESULT hres; HRESULT hres;
@ -540,11 +540,11 @@ static ScriptHost *create_script_host(HTMLDocument *doc, const GUID *guid)
ret->lpIActiveScriptSiteWindowVtbl = &ActiveScriptSiteWindowVtbl; ret->lpIActiveScriptSiteWindowVtbl = &ActiveScriptSiteWindowVtbl;
ret->lpIActiveScriptSiteDebug32Vtbl = &ActiveScriptSiteDebug32Vtbl; ret->lpIActiveScriptSiteDebug32Vtbl = &ActiveScriptSiteDebug32Vtbl;
ret->ref = 1; ret->ref = 1;
ret->doc = doc; ret->window = window;
ret->script_state = SCRIPTSTATE_UNINITIALIZED; ret->script_state = SCRIPTSTATE_UNINITIALIZED;
ret->guid = *guid; 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, hres = CoCreateInstance(&ret->guid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
&IID_IActiveScript, (void**)&ret->script); &IID_IActiveScript, (void**)&ret->script);
@ -593,7 +593,7 @@ static void parse_extern_script(ScriptHost *script_host, LPCWSTR src)
if(FAILED(hres)) if(FAILED(hres))
return; 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); IMoniker_Release(mon);
if(FAILED(hres)) if(FAILED(hres))
return; return;
@ -727,21 +727,21 @@ static BOOL get_script_guid(nsIDOMHTMLScriptElement *nsscript, GUID *guid)
return ret; return ret;
} }
static ScriptHost *get_script_host(HTMLDocument *doc, const GUID *guid) static ScriptHost *get_script_host(HTMLWindow *window, const GUID *guid)
{ {
ScriptHost *iter; ScriptHost *iter;
if(IsEqualGUID(&CLSID_JScript, guid) && doc->scriptmode != SCRIPTMODE_ACTIVESCRIPT) { if(IsEqualGUID(&CLSID_JScript, guid) && window->scriptmode != SCRIPTMODE_ACTIVESCRIPT) {
TRACE("Ignoring JScript\n"); TRACE("Ignoring JScript\n");
return NULL; 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)) if(IsEqualGUID(guid, &iter->guid))
return iter; return iter;
} }
return create_script_host(doc, guid); return create_script_host(window, guid);
} }
void doc_insert_script(HTMLDocument *doc, nsIDOMHTMLScriptElement *nsscript) void doc_insert_script(HTMLDocument *doc, nsIDOMHTMLScriptElement *nsscript)
@ -754,7 +754,7 @@ void doc_insert_script(HTMLDocument *doc, nsIDOMHTMLScriptElement *nsscript)
return; return;
} }
script_host = get_script_host(doc, &guid); script_host = get_script_host(doc->window, &guid);
if(!script_host) if(!script_host)
return; return;
@ -795,7 +795,7 @@ IDispatch *script_parse_event(HTMLDocument *doc, LPCWSTR text)
ptr = 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) if(!script_host || !script_host->parse_proc)
return NULL; return NULL;
@ -831,27 +831,27 @@ static BOOL is_jscript_available(void)
return available; return available;
} }
void set_script_mode(HTMLDocument *doc, SCRIPTMODE mode) void set_script_mode(HTMLWindow *window, SCRIPTMODE mode)
{ {
nsIWebBrowserSetup *setup; nsIWebBrowserSetup *setup;
nsresult nsres; nsresult nsres;
if(mode == SCRIPTMODE_ACTIVESCRIPT && !is_jscript_available()) { if(mode == SCRIPTMODE_ACTIVESCRIPT && !is_jscript_available()) {
TRACE("jscript.dll not available\n"); TRACE("jscript.dll not available\n");
doc->scriptmode = SCRIPTMODE_GECKO; window->scriptmode = SCRIPTMODE_GECKO;
return; return;
} }
doc->scriptmode = mode; window->scriptmode = mode;
if(!doc->nscontainer || !doc->nscontainer->webbrowser) if(!window->doc->nscontainer || !window->doc->nscontainer->webbrowser)
return; return;
nsres = nsIWebBrowser_QueryInterface(doc->nscontainer->webbrowser, nsres = nsIWebBrowser_QueryInterface(window->doc->nscontainer->webbrowser,
&IID_nsIWebBrowserSetup, (void**)&setup); &IID_nsIWebBrowserSetup, (void**)&setup);
if(NS_SUCCEEDED(nsres)) { if(NS_SUCCEEDED(nsres)) {
nsres = nsIWebBrowserSetup_SetProperty(setup, SETUP_ALLOW_JAVASCRIPT, nsres = nsIWebBrowserSetup_SetProperty(setup, SETUP_ALLOW_JAVASCRIPT,
doc->scriptmode == SCRIPTMODE_GECKO); window->scriptmode == SCRIPTMODE_GECKO);
nsIWebBrowserSetup_Release(setup); nsIWebBrowserSetup_Release(setup);
} }
@ -859,16 +859,16 @@ void set_script_mode(HTMLDocument *doc, SCRIPTMODE mode)
ERR("JavaScript setup failed: %08x\n", nsres); ERR("JavaScript setup failed: %08x\n", nsres);
} }
void release_script_hosts(HTMLDocument *doc) void release_script_hosts(HTMLWindow *window)
{ {
ScriptHost *iter; ScriptHost *iter;
while(!list_empty(&doc->script_hosts)) { while(!list_empty(&window->script_hosts)) {
iter = LIST_ENTRY(list_head(&doc->script_hosts), ScriptHost, entry); iter = LIST_ENTRY(list_head(&window->script_hosts), ScriptHost, entry);
release_script_engine(iter); release_script_engine(iter);
list_remove(&iter->entry); list_remove(&iter->entry);
iter->doc = NULL; iter->window = NULL;
IActiveScript_Release(ACTSCPSITE(iter)); IActiveScript_Release(ACTSCPSITE(iter));
} }
} }