Commit 3263ace6 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

mshtml: Initialize iframe windows when added to document.

parent 23891357
......@@ -1990,7 +1990,7 @@ HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject)
ERR("GetContentDOMWindow failed: %08x\n", nsres);
}
hres = HTMLWindow_Create(doc, nswindow, &doc->basedoc.window);
hres = HTMLWindow_Create(doc, nswindow, NULL /* FIXME */, &doc->basedoc.window);
if(nswindow)
nsIDOMWindow_Release(nswindow);
if(FAILED(hres)) {
......
......@@ -45,40 +45,6 @@ typedef struct {
#define HTMLFRAMEBASE(x) (&(x)->lpIHTMLFrameBaseVtbl)
#define HTMLFRAMEBASE2(x) (&(x)->lpIHTMLFrameBase2Vtbl)
static HRESULT create_content_window(HTMLIFrame *This, nsIDOMHTMLDocument *nsdoc, HTMLWindow **ret)
{
nsIDOMDocumentView *nsdocview;
nsIDOMAbstractView *nsview;
nsIDOMWindow *nswindow;
nsresult nsres;
HRESULT hres;
nsres = nsIDOMHTMLDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentView, (void**)&nsdocview);
if(NS_FAILED(nsres)) {
ERR("Could not get nsIDOMDocumentView: %08x\n", nsres);
return E_FAIL;
}
nsres = nsIDOMDocumentView_GetDefaultView(nsdocview, &nsview);
nsIDOMDocumentView_Release(nsdocview);
if(NS_FAILED(nsres)) {
ERR("GetDefaultView failed: %08x\n", nsres);
return E_FAIL;
}
nsres = nsIDOMAbstractView_QueryInterface(nsview, &IID_nsIDOMWindow, (void**)&nswindow);
nsIDOMAbstractView_Release(nsview);
if(NS_FAILED(nsres)) {
ERR("Coult not get nsIDOMWindow iface: %08x\n", nsres);
return E_FAIL;
}
hres = HTMLWindow_Create(This->element.node.doc->basedoc.doc_obj, nswindow, ret);
nsIDOMWindow_Release(nswindow);
return hres;
}
#define HTMLFRAMEBASE_THIS(iface) DEFINE_THIS(HTMLIFrame, IHTMLFrameBase, iface)
static HRESULT WINAPI HTMLIFrameBase_QueryInterface(IHTMLFrameBase *iface, REFIID riid, void **ppv)
......@@ -352,10 +318,9 @@ static HRESULT WINAPI HTMLIFrameBase2_get_contentWindow(IHTMLFrameBase2 *iface,
TRACE("(%p)->(%p)\n", This, p);
if(!This->content_window) {
nsIDOMHTMLDocument *nshtmldoc;
nsIDOMWindow *nswindow;
nsIDOMDocument *nsdoc;
nsresult nsres;
HRESULT hres;
nsres = nsIDOMHTMLIFrameElement_GetContentDocument(This->nsiframe, &nsdoc);
if(NS_FAILED(nsres)) {
......@@ -368,17 +333,19 @@ static HRESULT WINAPI HTMLIFrameBase2_get_contentWindow(IHTMLFrameBase2 *iface,
return E_FAIL;
}
nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
nswindow = get_nsdoc_window(nsdoc);
nsIDOMDocument_Release(nsdoc);
if(NS_FAILED(nsres)) {
ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres);
if(!nswindow)
return E_FAIL;
This->content_window = nswindow_to_window(nswindow);
nsIDOMWindow_Release(nswindow);
if(!This->content_window) {
ERR("Could not get window object\n");
return E_FAIL;
}
hres = create_content_window(This, nshtmldoc, &This->content_window);
nsIDOMHTMLDocument_Release(nshtmldoc);
if(FAILED(hres))
return hres;
IHTMLWindow2_AddRef(HTMLWINDOW2(This->content_window));
}
IHTMLWindow2_AddRef(HTMLWINDOW2(This->content_window));
......
......@@ -55,6 +55,50 @@ static void window_set_docnode(HTMLWindow *window, HTMLDocumentNode *doc_node)
}
}
nsIDOMWindow *get_nsdoc_window(nsIDOMDocument *nsdoc)
{
nsIDOMDocumentView *nsdocview;
nsIDOMAbstractView *nsview;
nsIDOMWindow *nswindow;
nsresult nsres;
nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentView, (void**)&nsdocview);
nsIDOMDocument_Release(nsdoc);
if(NS_FAILED(nsres)) {
ERR("Could not get nsIDOMDocumentView iface: %08x\n", nsres);
return NULL;
}
nsres = nsIDOMDocumentView_GetDefaultView(nsdocview, &nsview);
nsIDOMDocumentView_Release(nsview);
if(NS_FAILED(nsres)) {
ERR("GetDefaultView failed: %08x\n", nsres);
return NULL;
}
nsres = nsIDOMAbstractView_QueryInterface(nsview, &IID_nsIDOMWindow, (void**)&nswindow);
nsIDOMAbstractView_Release(nsview);
if(NS_FAILED(nsres)) {
ERR("Coult not get nsIDOMWindow iface: %08x\n", nsres);
return NULL;
}
return nswindow;
}
static void release_children(HTMLWindow *This)
{
HTMLWindow *child;
while(!list_empty(&This->children)) {
child = LIST_ENTRY(list_tail(&This->children), HTMLWindow, sibling_entry);
list_remove(&child->sibling_entry);
child->parent = NULL;
IHTMLWindow2_Release(HTMLWINDOW2(child));
}
}
#define HTMLWINDOW2_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow2, iface)
static HRESULT WINAPI HTMLWindow2_QueryInterface(IHTMLWindow2 *iface, REFIID riid, void **ppv)
......@@ -115,6 +159,7 @@ static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
DWORD i;
window_set_docnode(This, NULL);
release_children(This);
if(This->option_factory) {
This->option_factory->window = NULL;
......@@ -1500,7 +1545,7 @@ static dispex_static_data_t HTMLWindow_dispex = {
HTMLWindow_iface_tids
};
HRESULT HTMLWindow_Create(HTMLDocumentObj *doc_obj, nsIDOMWindow *nswindow, HTMLWindow **ret)
HRESULT HTMLWindow_Create(HTMLDocumentObj *doc_obj, nsIDOMWindow *nswindow, HTMLWindow *parent, HTMLWindow **ret)
{
HTMLWindow *window;
......@@ -1526,8 +1571,16 @@ HRESULT HTMLWindow_Create(HTMLDocumentObj *doc_obj, nsIDOMWindow *nswindow, HTML
update_window_doc(window);
list_init(&window->children);
list_add_head(&window_list, &window->entry);
if(parent) {
IHTMLWindow2_AddRef(HTMLWINDOW2(window));
window->parent = parent;
list_add_tail(&parent->children, &window->sibling_entry);
}
*ret = window;
return S_OK;
}
......
......@@ -211,6 +211,7 @@ struct HTMLWindow {
HTMLDocumentNode *doc;
HTMLDocumentObj *doc_obj;
nsIDOMWindow *nswindow;
HTMLWindow *parent;
event_target_t *event_target;
IHTMLEventObj *event;
......@@ -227,6 +228,8 @@ struct HTMLWindow {
DWORD global_prop_cnt;
DWORD global_prop_size;
struct list children;
struct list sibling_entry;
struct list entry;
};
......@@ -571,9 +574,10 @@ HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**);
HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**);
HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument*,HTMLDocumentObj*,HTMLWindow*,HTMLDocumentNode**);
HRESULT HTMLWindow_Create(HTMLDocumentObj*,nsIDOMWindow*,HTMLWindow**);
HRESULT HTMLWindow_Create(HTMLDocumentObj*,nsIDOMWindow*,HTMLWindow*,HTMLWindow**);
void update_window_doc(HTMLWindow*);
HTMLWindow *nswindow_to_window(const nsIDOMWindow*);
nsIDOMWindow *get_nsdoc_window(nsIDOMDocument*);
HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLWindow*);
HTMLImageElementFactory *HTMLImageElementFactory_Create(HTMLWindow*);
HRESULT HTMLLocation_Create(HTMLWindow*,HTMLLocation**);
......
......@@ -37,6 +37,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
enum {
MUTATION_COMMENT,
MUTATION_IFRAME,
MUTATION_SCRIPT
};
......@@ -244,6 +245,44 @@ static void pop_mutation_queue(HTMLDocumentNode *doc)
heap_free(tmp);
}
static nsresult init_iframe_window(HTMLDocumentNode *doc, nsISupports *nsunk)
{
nsIDOMHTMLIFrameElement *nsiframe;
nsIDOMWindow *nswindow;
nsIDOMDocument *nsdoc;
nsresult nsres;
nsres = nsISupports_QueryInterface(nsunk, &IID_nsIDOMHTMLIFrameElement, (void**)&nsiframe);
if(NS_FAILED(nsres)) {
ERR("Could not get nsIDOMHTMLIFrameElement: %08x\n", nsres);
return nsres;
}
nsres = nsIDOMHTMLIFrameElement_GetContentDocument(nsiframe, &nsdoc);
nsIDOMHTMLIFrameElement_Release(nsiframe);
if(NS_FAILED(nsres) || !nsdoc) {
ERR("GetContentDocument failed: %08x\n", nsres);
return nsres;
}
nswindow = get_nsdoc_window(nsdoc);
nsIDOMDocument_Release(nsdoc);
if(!nswindow)
return NS_ERROR_FAILURE;
if(!nswindow_to_window(nswindow)) {
HTMLWindow *window;
HRESULT hres;
hres = HTMLWindow_Create(doc->basedoc.doc_obj, nswindow, doc->basedoc.window, &window);
if(SUCCEEDED(hres))
IHTMLWindow2_Release(HTMLWINDOW2(window));
}
nsIDOMWindow_Release(nswindow);
return NS_OK;
}
static nsresult NSAPI nsRunnable_Run(nsIRunnable *iface)
{
HTMLDocumentNode *This = NSRUNNABLE_THIS(iface);
......@@ -300,6 +339,9 @@ static nsresult NSAPI nsRunnable_Run(nsIRunnable *iface)
break;
}
case MUTATION_IFRAME:
return init_iframe_window(This, This->mutation_queue->nsiface);
case MUTATION_SCRIPT: {
nsIDOMHTMLScriptElement *nsscript;
......@@ -511,6 +553,7 @@ static void NSAPI nsDocumentObserver_BindToDocument(nsIDocumentObserver *iface,
nsIContent *aContent)
{
HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
nsIDOMHTMLIFrameElement *nsiframe;
nsIDOMComment *nscomment;
nsIDOMElement *nselem;
nsresult nsres;
......@@ -531,6 +574,13 @@ static void NSAPI nsDocumentObserver_BindToDocument(nsIDocumentObserver *iface,
nsIDOMComment_Release(nscomment);
add_script_runner(This);
}
nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMHTMLIFrameElement, (void**)&nsiframe);
if(NS_SUCCEEDED(nsres)) {
push_mutation_queue(This, MUTATION_IFRAME, (nsISupports*)nsiframe);
nsIDOMHTMLIFrameElement_Release(nsiframe);
add_script_runner(This);
}
}
static void NSAPI nsDocumentObserver_DoneAddingChildren(nsIDocumentObserver *iface, nsIContent *aContent,
......
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