mshtml: Fixed typos in IHTMLInputElement::value tests.
[wine] / dlls / mshtml / htmlwindow.c
1 /*
2  * Copyright 2006-2010 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include <stdarg.h>
20
21 #define COBJMACROS
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
27 #include "mshtmdid.h"
28 #include "shlguid.h"
29
30 #include "wine/debug.h"
31
32 #include "mshtml_private.h"
33 #include "htmlevent.h"
34 #include "resource.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
37
38 static struct list window_list = LIST_INIT(window_list);
39
40 static void window_set_docnode(HTMLWindow *window, HTMLDocumentNode *doc_node)
41 {
42     if(window->doc) {
43         abort_document_bindings(window->doc);
44         window->doc->basedoc.window = NULL;
45         htmldoc_release(&window->doc->basedoc);
46     }
47     window->doc = doc_node;
48     if(doc_node)
49         htmldoc_addref(&doc_node->basedoc);
50
51     if(window->doc_obj && window->doc_obj->basedoc.window == window) {
52         if(window->doc_obj->basedoc.doc_node)
53             htmldoc_release(&window->doc_obj->basedoc.doc_node->basedoc);
54         window->doc_obj->basedoc.doc_node = doc_node;
55         if(doc_node)
56             htmldoc_addref(&doc_node->basedoc);
57     }
58
59     if(doc_node && window->doc_obj && window->doc_obj->usermode == EDITMODE) {
60         nsIDOMNSHTMLDocument *nshtmldoc;
61         nsAString mode_str;
62         nsresult nsres;
63
64         static const PRUnichar onW[] = {'o','n',0};
65
66         nsres = nsIDOMHTMLDocument_QueryInterface(doc_node->nsdoc, &IID_nsIDOMNSHTMLDocument, (void**)&nshtmldoc);
67         if(NS_SUCCEEDED(nsres)) {
68             nsAString_Init(&mode_str, onW);
69             nsres = nsIDOMNSHTMLDocument_SetDesignMode(nshtmldoc, &mode_str);
70             nsAString_Finish(&mode_str);
71             nsIDOMNSHTMLDocument_Release(nshtmldoc);
72             if(NS_FAILED(nsres))
73                 ERR("SetDesignMode failed: %08x\n", nsres);
74         }else {
75             ERR("Could not get nsIDOMNSHTMLDocument interface: %08x\n", nsres);
76         }
77     }
78 }
79
80 nsIDOMWindow *get_nsdoc_window(nsIDOMDocument *nsdoc)
81 {
82     nsIDOMDocumentView *nsdocview;
83     nsIDOMAbstractView *nsview;
84     nsIDOMWindow *nswindow;
85     nsresult nsres;
86
87     nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentView, (void**)&nsdocview);
88     nsIDOMDocument_Release(nsdoc);
89     if(NS_FAILED(nsres)) {
90         ERR("Could not get nsIDOMDocumentView iface: %08x\n", nsres);
91         return NULL;
92     }
93
94     nsres = nsIDOMDocumentView_GetDefaultView(nsdocview, &nsview);
95     nsIDOMDocumentView_Release(nsview);
96     if(NS_FAILED(nsres)) {
97         ERR("GetDefaultView failed: %08x\n", nsres);
98         return NULL;
99     }
100
101     nsres = nsIDOMAbstractView_QueryInterface(nsview, &IID_nsIDOMWindow, (void**)&nswindow);
102     nsIDOMAbstractView_Release(nsview);
103     if(NS_FAILED(nsres)) {
104         ERR("Coult not get nsIDOMWindow iface: %08x\n", nsres);
105         return NULL;
106     }
107
108     return nswindow;
109 }
110
111 static void release_children(HTMLWindow *This)
112 {
113     HTMLWindow *child;
114
115     while(!list_empty(&This->children)) {
116         child = LIST_ENTRY(list_tail(&This->children), HTMLWindow, sibling_entry);
117
118         list_remove(&child->sibling_entry);
119         child->parent = NULL;
120         IHTMLWindow2_Release(&child->IHTMLWindow2_iface);
121     }
122 }
123
124 static HRESULT get_location(HTMLWindow *This, HTMLLocation **ret)
125 {
126     if(This->location) {
127         IHTMLLocation_AddRef(&This->location->IHTMLLocation_iface);
128     }else {
129         HRESULT hres;
130
131         hres = HTMLLocation_Create(This, &This->location);
132         if(FAILED(hres))
133             return hres;
134     }
135
136     *ret = This->location;
137     return S_OK;
138 }
139
140 static inline HRESULT set_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
141 {
142     if(!window->doc) {
143         FIXME("No document\n");
144         return E_FAIL;
145     }
146
147     return set_event_handler(&window->doc->body_event_target, NULL, window->doc, eid, var);
148 }
149
150 static inline HRESULT get_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
151 {
152     if(!window->doc) {
153         FIXME("No document\n");
154         return E_FAIL;
155     }
156
157     return get_event_handler(&window->doc->body_event_target, eid, var);
158 }
159
160 static inline HTMLWindow *impl_from_IHTMLWindow2(IHTMLWindow2 *iface)
161 {
162     return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow2_iface);
163 }
164
165 static HRESULT WINAPI HTMLWindow2_QueryInterface(IHTMLWindow2 *iface, REFIID riid, void **ppv)
166 {
167     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
168
169     *ppv = NULL;
170
171     if(IsEqualGUID(&IID_IUnknown, riid)) {
172         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
173         *ppv = &This->IHTMLWindow2_iface;
174     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
175         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
176         *ppv = &This->IHTMLWindow2_iface;
177     }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
178         TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
179         *ppv = &This->IDispatchEx_iface;
180     }else if(IsEqualGUID(&IID_IHTMLFramesCollection2, riid)) {
181         TRACE("(%p)->(IID_IHTMLFramesCollection2 %p)\n", This, ppv);
182         *ppv = &This->IHTMLWindow2_iface;
183     }else if(IsEqualGUID(&IID_IHTMLWindow2, riid)) {
184         TRACE("(%p)->(IID_IHTMLWindow2 %p)\n", This, ppv);
185         *ppv = &This->IHTMLWindow2_iface;
186     }else if(IsEqualGUID(&IID_IHTMLWindow3, riid)) {
187         TRACE("(%p)->(IID_IHTMLWindow3 %p)\n", This, ppv);
188         *ppv = &This->IHTMLWindow3_iface;
189     }else if(IsEqualGUID(&IID_IHTMLWindow4, riid)) {
190         TRACE("(%p)->(IID_IHTMLWindow4 %p)\n", This, ppv);
191         *ppv = &This->IHTMLWindow4_iface;
192     }else if(IsEqualGUID(&IID_IHTMLPrivateWindow, riid)) {
193         TRACE("(%p)->(IID_IHTMLPrivateWindow %p)\n", This, ppv);
194         *ppv = &This->IHTMLPrivateWindow_iface;
195     }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
196         TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
197         *ppv = &This->IServiceProvider_iface;
198     }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
199         return *ppv ? S_OK : E_NOINTERFACE;
200     }
201
202     if(*ppv) {
203         IUnknown_AddRef((IUnknown*)*ppv);
204         return S_OK;
205     }
206
207     WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
208     return E_NOINTERFACE;
209 }
210
211 static ULONG WINAPI HTMLWindow2_AddRef(IHTMLWindow2 *iface)
212 {
213     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
214     LONG ref = InterlockedIncrement(&This->ref);
215
216     TRACE("(%p) ref=%d\n", This, ref);
217
218     return ref;
219 }
220
221 static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
222 {
223     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
224     LONG ref = InterlockedDecrement(&This->ref);
225
226     TRACE("(%p) ref=%d\n", This, ref);
227
228     if(!ref) {
229         DWORD i;
230
231         remove_target_tasks(This->task_magic);
232         set_window_bscallback(This, NULL);
233         set_current_mon(This, NULL);
234         window_set_docnode(This, NULL);
235         release_children(This);
236
237         if(This->frame_element)
238             This->frame_element->content_window = NULL;
239
240         if(This->option_factory) {
241             This->option_factory->window = NULL;
242             IHTMLOptionElementFactory_Release(&This->option_factory->IHTMLOptionElementFactory_iface);
243         }
244
245         if(This->image_factory) {
246             This->image_factory->window = NULL;
247             IHTMLImageElementFactory_Release(&This->image_factory->IHTMLImageElementFactory_iface);
248         }
249
250         if(This->location) {
251             This->location->window = NULL;
252             IHTMLLocation_Release(&This->location->IHTMLLocation_iface);
253         }
254
255         if(This->screen)
256             IHTMLScreen_Release(This->screen);
257
258         for(i=0; i < This->global_prop_cnt; i++)
259             heap_free(This->global_props[i].name);
260
261         This->window_ref->window = NULL;
262         windowref_release(This->window_ref);
263
264         heap_free(This->global_props);
265         release_script_hosts(This);
266
267         if(This->nswindow)
268             nsIDOMWindow_Release(This->nswindow);
269
270         list_remove(&This->entry);
271         release_dispex(&This->dispex);
272         heap_free(This);
273     }
274
275     return ref;
276 }
277
278 static HRESULT WINAPI HTMLWindow2_GetTypeInfoCount(IHTMLWindow2 *iface, UINT *pctinfo)
279 {
280     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
281
282     return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
283 }
284
285 static HRESULT WINAPI HTMLWindow2_GetTypeInfo(IHTMLWindow2 *iface, UINT iTInfo,
286                                               LCID lcid, ITypeInfo **ppTInfo)
287 {
288     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
289
290     return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
291 }
292
293 static HRESULT WINAPI HTMLWindow2_GetIDsOfNames(IHTMLWindow2 *iface, REFIID riid,
294                                                 LPOLESTR *rgszNames, UINT cNames,
295                                                 LCID lcid, DISPID *rgDispId)
296 {
297     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
298
299     return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
300             rgDispId);
301 }
302
303 static HRESULT WINAPI HTMLWindow2_Invoke(IHTMLWindow2 *iface, DISPID dispIdMember,
304                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
305                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
306 {
307     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
308
309     return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
310             pDispParams, pVarResult, pExcepInfo, puArgErr);
311 }
312
313 static HRESULT get_frame_by_index(nsIDOMWindowCollection *nsFrames, PRUint32 index, HTMLWindow **ret)
314 {
315     PRUint32 length;
316     nsIDOMWindow *nsWindow;
317     nsresult nsres;
318
319     nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
320     if(NS_FAILED(nsres)) {
321         FIXME("nsIDOMWindowCollection_GetLength failed: 0x%08x\n", nsres);
322         return E_FAIL;
323     }
324
325     if(index >= length)
326         return DISP_E_MEMBERNOTFOUND;
327
328     nsres = nsIDOMWindowCollection_Item(nsFrames, index, &nsWindow);
329     if(NS_FAILED(nsres)) {
330         FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
331         return E_FAIL;
332     }
333
334     *ret = nswindow_to_window(nsWindow);
335
336     nsIDOMWindow_Release(nsWindow);
337
338     return S_OK;
339 }
340
341 static HRESULT WINAPI HTMLWindow2_item(IHTMLWindow2 *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
342 {
343     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
344     nsIDOMWindowCollection *nsFrames;
345     HTMLWindow *window;
346     HRESULT hres;
347     nsresult nsres;
348
349     TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
350
351     nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsFrames);
352     if(NS_FAILED(nsres)) {
353         FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
354         return E_FAIL;
355     }
356
357     if(V_VT(pvarIndex) == VT_I4) {
358         int index = V_I4(pvarIndex);
359         TRACE("Getting index %d\n", index);
360         if(index < 0) {
361             hres = DISP_E_MEMBERNOTFOUND;
362             goto cleanup;
363         }
364         hres = get_frame_by_index(nsFrames, index, &window);
365         if(FAILED(hres))
366             goto cleanup;
367     }else if(V_VT(pvarIndex) == VT_UINT) {
368         unsigned int index = V_UINT(pvarIndex);
369         TRACE("Getting index %u\n", index);
370         hres = get_frame_by_index(nsFrames, index, &window);
371         if(FAILED(hres))
372             goto cleanup;
373     }else if(V_VT(pvarIndex) == VT_BSTR) {
374         BSTR str = V_BSTR(pvarIndex);
375         PRUint32 length, i;
376
377         TRACE("Getting name %s\n", wine_dbgstr_w(str));
378
379         nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
380
381         window = NULL;
382         for(i = 0; i < length && !window; ++i) {
383             HTMLWindow *cur_window;
384             nsIDOMWindow *nsWindow;
385             BSTR id;
386
387             nsres = nsIDOMWindowCollection_Item(nsFrames, i, &nsWindow);
388             if(NS_FAILED(nsres)) {
389                 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
390                 hres = E_FAIL;
391                 goto cleanup;
392             }
393
394             cur_window = nswindow_to_window(nsWindow);
395
396             nsIDOMWindow_Release(nsWindow);
397
398             hres = IHTMLElement_get_id(&cur_window->frame_element->element.IHTMLElement_iface, &id);
399             if(FAILED(hres)) {
400                 FIXME("IHTMLElement_get_id failed: 0x%08x\n", hres);
401                 goto cleanup;
402             }
403
404             if(!strcmpW(id, str))
405                 window = cur_window;
406
407             SysFreeString(id);
408         }
409
410         if(!window) {
411             hres = DISP_E_MEMBERNOTFOUND;
412             goto cleanup;
413         }
414     }else {
415         hres = E_INVALIDARG;
416         goto cleanup;
417     }
418
419     IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
420     V_VT(pvarResult) = VT_DISPATCH;
421     V_DISPATCH(pvarResult) = (IDispatch*)window;
422
423     hres = S_OK;
424
425 cleanup:
426     nsIDOMWindowCollection_Release(nsFrames);
427
428     return hres;
429 }
430
431 static HRESULT WINAPI HTMLWindow2_get_length(IHTMLWindow2 *iface, LONG *p)
432 {
433     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
434     nsIDOMWindowCollection *nscollection;
435     PRUint32 length;
436     nsresult nsres;
437
438     TRACE("(%p)->(%p)\n", This, p);
439
440     nsres = nsIDOMWindow_GetFrames(This->nswindow, &nscollection);
441     if(NS_FAILED(nsres)) {
442         ERR("GetFrames failed: %08x\n", nsres);
443         return E_FAIL;
444     }
445
446     nsres = nsIDOMWindowCollection_GetLength(nscollection, &length);
447     nsIDOMWindowCollection_Release(nscollection);
448     if(NS_FAILED(nsres)) {
449         ERR("GetLength failed: %08x\n", nsres);
450         return E_FAIL;
451     }
452
453     *p = length;
454     return S_OK;
455 }
456
457 static HRESULT WINAPI HTMLWindow2_get_frames(IHTMLWindow2 *iface, IHTMLFramesCollection2 **p)
458 {
459     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
460     FIXME("(%p)->(%p): semi-stub\n", This, p);
461
462     /* FIXME: Should return a separate Window object */
463     *p = (IHTMLFramesCollection2*)&This->IHTMLWindow2_iface;
464     HTMLWindow2_AddRef(iface);
465     return S_OK;
466 }
467
468 static HRESULT WINAPI HTMLWindow2_put_defaultStatus(IHTMLWindow2 *iface, BSTR v)
469 {
470     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
471     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
472     return E_NOTIMPL;
473 }
474
475 static HRESULT WINAPI HTMLWindow2_get_defaultStatus(IHTMLWindow2 *iface, BSTR *p)
476 {
477     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
478     FIXME("(%p)->(%p)\n", This, p);
479     return E_NOTIMPL;
480 }
481
482 static HRESULT WINAPI HTMLWindow2_put_status(IHTMLWindow2 *iface, BSTR v)
483 {
484     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
485     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
486     return E_NOTIMPL;
487 }
488
489 static HRESULT WINAPI HTMLWindow2_get_status(IHTMLWindow2 *iface, BSTR *p)
490 {
491     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
492     FIXME("(%p)->(%p)\n", This, p);
493     return E_NOTIMPL;
494 }
495
496 static HRESULT WINAPI HTMLWindow2_setTimeout(IHTMLWindow2 *iface, BSTR expression,
497         LONG msec, VARIANT *language, LONG *timerID)
498 {
499     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
500     VARIANT expr_var;
501
502     TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
503
504     V_VT(&expr_var) = VT_BSTR;
505     V_BSTR(&expr_var) = expression;
506
507     return IHTMLWindow3_setTimeout(&This->IHTMLWindow3_iface, &expr_var, msec, language, timerID);
508 }
509
510 static HRESULT WINAPI HTMLWindow2_clearTimeout(IHTMLWindow2 *iface, LONG timerID)
511 {
512     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
513
514     TRACE("(%p)->(%d)\n", This, timerID);
515
516     return clear_task_timer(&This->doc->basedoc, FALSE, timerID);
517 }
518
519 #define MAX_MESSAGE_LEN 2000
520
521 static HRESULT WINAPI HTMLWindow2_alert(IHTMLWindow2 *iface, BSTR message)
522 {
523     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
524     WCHAR title[100], *msg = message;
525     DWORD len;
526
527     TRACE("(%p)->(%s)\n", This, debugstr_w(message));
528
529     if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, title,
530                     sizeof(title)/sizeof(WCHAR))) {
531         WARN("Could not load message box title: %d\n", GetLastError());
532         return S_OK;
533     }
534
535     len = SysStringLen(message);
536     if(len > MAX_MESSAGE_LEN) {
537         msg = heap_alloc((MAX_MESSAGE_LEN+1)*sizeof(WCHAR));
538         if(!msg)
539             return E_OUTOFMEMORY;
540         memcpy(msg, message, MAX_MESSAGE_LEN*sizeof(WCHAR));
541         msg[MAX_MESSAGE_LEN] = 0;
542     }
543
544     MessageBoxW(This->doc_obj->hwnd, msg, title, MB_ICONWARNING);
545     if(msg != message)
546         heap_free(msg);
547     return S_OK;
548 }
549
550 static HRESULT WINAPI HTMLWindow2_confirm(IHTMLWindow2 *iface, BSTR message,
551         VARIANT_BOOL *confirmed)
552 {
553     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
554     WCHAR wszTitle[100];
555
556     TRACE("(%p)->(%s %p)\n", This, debugstr_w(message), confirmed);
557
558     if(!confirmed) return E_INVALIDARG;
559
560     if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
561                 sizeof(wszTitle)/sizeof(WCHAR))) {
562         WARN("Could not load message box title: %d\n", GetLastError());
563         *confirmed = VARIANT_TRUE;
564         return S_OK;
565     }
566
567     if(MessageBoxW(This->doc_obj->hwnd, message, wszTitle,
568                 MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
569         *confirmed = VARIANT_TRUE;
570     else *confirmed = VARIANT_FALSE;
571
572     return S_OK;
573 }
574
575 typedef struct
576 {
577     BSTR message;
578     BSTR dststr;
579     VARIANT *textdata;
580 }prompt_arg;
581
582 static INT_PTR CALLBACK prompt_dlgproc(HWND hwnd, UINT msg,
583         WPARAM wparam, LPARAM lparam)
584 {
585     switch(msg)
586     {
587         case WM_INITDIALOG:
588         {
589             prompt_arg *arg = (prompt_arg*)lparam;
590             WCHAR wszTitle[100];
591
592             if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
593                         sizeof(wszTitle)/sizeof(WCHAR))) {
594                 WARN("Could not load message box title: %d\n", GetLastError());
595                 EndDialog(hwnd, wparam);
596                 return FALSE;
597             }
598
599             SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
600             SetWindowTextW(hwnd, wszTitle);
601             SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_PROMPT), arg->message);
602             SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_EDIT), arg->dststr);
603             return FALSE;
604         }
605         case WM_COMMAND:
606             switch(wparam)
607             {
608                 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
609                     EndDialog(hwnd, wparam);
610                     return TRUE;
611                 case MAKEWPARAM(IDOK, BN_CLICKED):
612                 {
613                     prompt_arg *arg =
614                         (prompt_arg*)GetWindowLongPtrW(hwnd, DWLP_USER);
615                     HWND hwndPrompt = GetDlgItem(hwnd, ID_PROMPT_EDIT);
616                     INT len = GetWindowTextLengthW(hwndPrompt);
617
618                     if(!arg->textdata)
619                     {
620                         EndDialog(hwnd, wparam);
621                         return TRUE;
622                     }
623
624                     V_VT(arg->textdata) = VT_BSTR;
625                     if(!len && !arg->dststr)
626                         V_BSTR(arg->textdata) = NULL;
627                     else
628                     {
629                         V_BSTR(arg->textdata) = SysAllocStringLen(NULL, len);
630                         GetWindowTextW(hwndPrompt, V_BSTR(arg->textdata), len+1);
631                     }
632                     EndDialog(hwnd, wparam);
633                     return TRUE;
634                 }
635             }
636             return FALSE;
637         case WM_CLOSE:
638             EndDialog(hwnd, IDCANCEL);
639             return TRUE;
640         default:
641             return FALSE;
642     }
643 }
644
645 static HRESULT WINAPI HTMLWindow2_prompt(IHTMLWindow2 *iface, BSTR message,
646         BSTR dststr, VARIANT *textdata)
647 {
648     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
649     prompt_arg arg;
650
651     TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(message), debugstr_w(dststr), textdata);
652
653     if(textdata) V_VT(textdata) = VT_NULL;
654
655     arg.message = message;
656     arg.dststr = dststr;
657     arg.textdata = textdata;
658
659     DialogBoxParamW(hInst, MAKEINTRESOURCEW(ID_PROMPT_DIALOG),
660             This->doc_obj->hwnd, prompt_dlgproc, (LPARAM)&arg);
661     return S_OK;
662 }
663
664 static HRESULT WINAPI HTMLWindow2_get_Image(IHTMLWindow2 *iface, IHTMLImageElementFactory **p)
665 {
666     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
667
668     TRACE("(%p)->(%p)\n", This, p);
669
670     if(!This->image_factory)
671         This->image_factory = HTMLImageElementFactory_Create(This);
672
673     *p = &This->image_factory->IHTMLImageElementFactory_iface;
674     IHTMLImageElementFactory_AddRef(*p);
675
676     return S_OK;
677 }
678
679 static HRESULT WINAPI HTMLWindow2_get_location(IHTMLWindow2 *iface, IHTMLLocation **p)
680 {
681     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
682     HTMLLocation *location;
683     HRESULT hres;
684
685     TRACE("(%p)->(%p)\n", This, p);
686
687     hres = get_location(This, &location);
688     if(FAILED(hres))
689         return hres;
690
691     *p = &location->IHTMLLocation_iface;
692     return S_OK;
693 }
694
695 static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p)
696 {
697     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
698     FIXME("(%p)->(%p)\n", This, p);
699     return E_NOTIMPL;
700 }
701
702 static HRESULT WINAPI HTMLWindow2_close(IHTMLWindow2 *iface)
703 {
704     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
705     FIXME("(%p)->()\n", This);
706     return E_NOTIMPL;
707 }
708
709 static HRESULT WINAPI HTMLWindow2_put_opener(IHTMLWindow2 *iface, VARIANT v)
710 {
711     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
712     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
713     return E_NOTIMPL;
714 }
715
716 static HRESULT WINAPI HTMLWindow2_get_opener(IHTMLWindow2 *iface, VARIANT *p)
717 {
718     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
719     FIXME("(%p)->(%p)\n", This, p);
720     return E_NOTIMPL;
721 }
722
723 static HRESULT WINAPI HTMLWindow2_get_navigator(IHTMLWindow2 *iface, IOmNavigator **p)
724 {
725     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
726
727     TRACE("(%p)->(%p)\n", This, p);
728
729     *p = OmNavigator_Create();
730     return S_OK;
731 }
732
733 static HRESULT WINAPI HTMLWindow2_put_name(IHTMLWindow2 *iface, BSTR v)
734 {
735     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
736     nsAString name_str;
737     nsresult nsres;
738
739     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
740
741     nsAString_InitDepend(&name_str, v);
742     nsres = nsIDOMWindow_SetName(This->nswindow, &name_str);
743     nsAString_Finish(&name_str);
744     if(NS_FAILED(nsres))
745         ERR("SetName failed: %08x\n", nsres);
746
747     return S_OK;
748 }
749
750 static HRESULT WINAPI HTMLWindow2_get_name(IHTMLWindow2 *iface, BSTR *p)
751 {
752     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
753     nsAString name_str;
754     nsresult nsres;
755     HRESULT hres;
756
757     TRACE("(%p)->(%p)\n", This, p);
758
759     nsAString_Init(&name_str, NULL);
760     nsres = nsIDOMWindow_GetName(This->nswindow, &name_str);
761     if(NS_SUCCEEDED(nsres)) {
762         const PRUnichar *name;
763
764         nsAString_GetData(&name_str, &name);
765         if(*name) {
766             *p = SysAllocString(name);
767             hres = *p ? S_OK : E_OUTOFMEMORY;
768         }else {
769             *p = NULL;
770             hres = S_OK;
771         }
772     }else {
773         ERR("GetName failed: %08x\n", nsres);
774         hres = E_FAIL;
775     }
776     nsAString_Finish(&name_str);
777
778     return hres;
779 }
780
781 static HRESULT WINAPI HTMLWindow2_get_parent(IHTMLWindow2 *iface, IHTMLWindow2 **p)
782 {
783     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
784     TRACE("(%p)->(%p)\n", This, p);
785
786     if(This->parent) {
787         *p = &This->parent->IHTMLWindow2_iface;
788         IHTMLWindow2_AddRef(*p);
789     }else
790         *p = NULL;
791
792     return S_OK;
793 }
794
795 static HRESULT WINAPI HTMLWindow2_open(IHTMLWindow2 *iface, BSTR url, BSTR name,
796          BSTR features, VARIANT_BOOL replace, IHTMLWindow2 **pomWindowResult)
797 {
798     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
799     FIXME("(%p)->(%s %s %s %x %p)\n", This, debugstr_w(url), debugstr_w(name),
800           debugstr_w(features), replace, pomWindowResult);
801     return E_NOTIMPL;
802 }
803
804 static HRESULT WINAPI HTMLWindow2_get_self(IHTMLWindow2 *iface, IHTMLWindow2 **p)
805 {
806     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
807
808     TRACE("(%p)->(%p)\n", This, p);
809
810     /* FIXME: We should return kind of proxy window here. */
811     IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
812     *p = &This->IHTMLWindow2_iface;
813     return S_OK;
814 }
815
816 static HRESULT WINAPI HTMLWindow2_get_top(IHTMLWindow2 *iface, IHTMLWindow2 **p)
817 {
818     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
819     HTMLWindow *curr;
820     TRACE("(%p)->(%p)\n", This, p);
821
822     curr = This;
823     while(curr->parent)
824         curr = curr->parent;
825     *p = &curr->IHTMLWindow2_iface;
826     IHTMLWindow2_AddRef(*p);
827
828     return S_OK;
829 }
830
831 static HRESULT WINAPI HTMLWindow2_get_window(IHTMLWindow2 *iface, IHTMLWindow2 **p)
832 {
833     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
834
835     TRACE("(%p)->(%p)\n", This, p);
836
837     /* FIXME: We should return kind of proxy window here. */
838     IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
839     *p = &This->IHTMLWindow2_iface;
840     return S_OK;
841 }
842
843 static HRESULT WINAPI HTMLWindow2_navigate(IHTMLWindow2 *iface, BSTR url)
844 {
845     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
846     FIXME("(%p)->(%s)\n", This, debugstr_w(url));
847     return E_NOTIMPL;
848 }
849
850 static HRESULT WINAPI HTMLWindow2_put_onfocus(IHTMLWindow2 *iface, VARIANT v)
851 {
852     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
853     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
854     return E_NOTIMPL;
855 }
856
857 static HRESULT WINAPI HTMLWindow2_get_onfocus(IHTMLWindow2 *iface, VARIANT *p)
858 {
859     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
860     FIXME("(%p)->(%p)\n", This, p);
861     return E_NOTIMPL;
862 }
863
864 static HRESULT WINAPI HTMLWindow2_put_onblur(IHTMLWindow2 *iface, VARIANT v)
865 {
866     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
867     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
868     return E_NOTIMPL;
869 }
870
871 static HRESULT WINAPI HTMLWindow2_get_onblur(IHTMLWindow2 *iface, VARIANT *p)
872 {
873     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
874     FIXME("(%p)->(%p)\n", This, p);
875     return E_NOTIMPL;
876 }
877
878 static HRESULT WINAPI HTMLWindow2_put_onload(IHTMLWindow2 *iface, VARIANT v)
879 {
880     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
881
882     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
883
884     return set_window_event(This, EVENTID_LOAD, &v);
885 }
886
887 static HRESULT WINAPI HTMLWindow2_get_onload(IHTMLWindow2 *iface, VARIANT *p)
888 {
889     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
890
891     TRACE("(%p)->(%p)\n", This, p);
892
893     return get_window_event(This, EVENTID_LOAD, p);
894 }
895
896 static HRESULT WINAPI HTMLWindow2_put_onbeforeunload(IHTMLWindow2 *iface, VARIANT v)
897 {
898     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
899
900     TRACE("(%p)->(v(%d))\n", This, V_VT(&v));
901
902     return set_window_event(This, EVENTID_BEFOREUNLOAD, &v);
903 }
904
905 static HRESULT WINAPI HTMLWindow2_get_onbeforeunload(IHTMLWindow2 *iface, VARIANT *p)
906 {
907     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
908
909     TRACE("(%p)->(%p)\n", This, p);
910
911     return get_window_event(This, EVENTID_BEFOREUNLOAD, p);
912 }
913
914 static HRESULT WINAPI HTMLWindow2_put_onunload(IHTMLWindow2 *iface, VARIANT v)
915 {
916     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
917     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
918     return E_NOTIMPL;
919 }
920
921 static HRESULT WINAPI HTMLWindow2_get_onunload(IHTMLWindow2 *iface, VARIANT *p)
922 {
923     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
924     FIXME("(%p)->(%p)\n", This, p);
925     return E_NOTIMPL;
926 }
927
928 static HRESULT WINAPI HTMLWindow2_put_onhelp(IHTMLWindow2 *iface, VARIANT v)
929 {
930     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
931     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
932     return E_NOTIMPL;
933 }
934
935 static HRESULT WINAPI HTMLWindow2_get_onhelp(IHTMLWindow2 *iface, VARIANT *p)
936 {
937     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
938     FIXME("(%p)->(%p)\n", This, p);
939     return E_NOTIMPL;
940 }
941
942 static HRESULT WINAPI HTMLWindow2_put_onerror(IHTMLWindow2 *iface, VARIANT v)
943 {
944     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
945     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
946     return E_NOTIMPL;
947 }
948
949 static HRESULT WINAPI HTMLWindow2_get_onerror(IHTMLWindow2 *iface, VARIANT *p)
950 {
951     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
952     FIXME("(%p)->(%p)\n", This, p);
953     return E_NOTIMPL;
954 }
955
956 static HRESULT WINAPI HTMLWindow2_put_onresize(IHTMLWindow2 *iface, VARIANT v)
957 {
958     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
959
960     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
961
962     return set_window_event(This, EVENTID_RESIZE, &v);
963 }
964
965 static HRESULT WINAPI HTMLWindow2_get_onresize(IHTMLWindow2 *iface, VARIANT *p)
966 {
967     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
968
969     TRACE("(%p)->(%p)\n", This, p);
970
971     return get_window_event(This, EVENTID_RESIZE, p);
972 }
973
974 static HRESULT WINAPI HTMLWindow2_put_onscroll(IHTMLWindow2 *iface, VARIANT v)
975 {
976     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
977     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
978     return E_NOTIMPL;
979 }
980
981 static HRESULT WINAPI HTMLWindow2_get_onscroll(IHTMLWindow2 *iface, VARIANT *p)
982 {
983     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
984     FIXME("(%p)->(%p)\n", This, p);
985     return E_NOTIMPL;
986 }
987
988 static HRESULT WINAPI HTMLWindow2_get_document(IHTMLWindow2 *iface, IHTMLDocument2 **p)
989 {
990     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
991
992     TRACE("(%p)->(%p)\n", This, p);
993
994     if(This->doc) {
995         /* FIXME: We should return a wrapper object here */
996         *p = &This->doc->basedoc.IHTMLDocument2_iface;
997         IHTMLDocument2_AddRef(*p);
998     }else {
999         *p = NULL;
1000     }
1001
1002     return S_OK;
1003 }
1004
1005 static HRESULT WINAPI HTMLWindow2_get_event(IHTMLWindow2 *iface, IHTMLEventObj **p)
1006 {
1007     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1008
1009     TRACE("(%p)->(%p)\n", This, p);
1010
1011     if(This->event)
1012         IHTMLEventObj_AddRef(This->event);
1013     *p = This->event;
1014     return S_OK;
1015 }
1016
1017 static HRESULT WINAPI HTMLWindow2_get__newEnum(IHTMLWindow2 *iface, IUnknown **p)
1018 {
1019     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1020     FIXME("(%p)->(%p)\n", This, p);
1021     return E_NOTIMPL;
1022 }
1023
1024 static HRESULT WINAPI HTMLWindow2_showModalDialog(IHTMLWindow2 *iface, BSTR dialog,
1025         VARIANT *varArgIn, VARIANT *varOptions, VARIANT *varArgOut)
1026 {
1027     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1028     FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(dialog), varArgIn, varOptions, varArgOut);
1029     return E_NOTIMPL;
1030 }
1031
1032 static HRESULT WINAPI HTMLWindow2_showHelp(IHTMLWindow2 *iface, BSTR helpURL, VARIANT helpArg,
1033         BSTR features)
1034 {
1035     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1036     FIXME("(%p)->(%s v(%d) %s)\n", This, debugstr_w(helpURL), V_VT(&helpArg), debugstr_w(features));
1037     return E_NOTIMPL;
1038 }
1039
1040 static HRESULT WINAPI HTMLWindow2_get_screen(IHTMLWindow2 *iface, IHTMLScreen **p)
1041 {
1042     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1043
1044     TRACE("(%p)->(%p)\n", This, p);
1045
1046     if(!This->screen) {
1047         HRESULT hres;
1048
1049         hres = HTMLScreen_Create(&This->screen);
1050         if(FAILED(hres))
1051             return hres;
1052     }
1053
1054     *p = This->screen;
1055     IHTMLScreen_AddRef(This->screen);
1056     return S_OK;
1057 }
1058
1059 static HRESULT WINAPI HTMLWindow2_get_Option(IHTMLWindow2 *iface, IHTMLOptionElementFactory **p)
1060 {
1061     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1062
1063     TRACE("(%p)->(%p)\n", This, p);
1064
1065     if(!This->option_factory)
1066         This->option_factory = HTMLOptionElementFactory_Create(This);
1067
1068     *p = &This->option_factory->IHTMLOptionElementFactory_iface;
1069     IHTMLOptionElementFactory_AddRef(*p);
1070
1071     return S_OK;
1072 }
1073
1074 static HRESULT WINAPI HTMLWindow2_focus(IHTMLWindow2 *iface)
1075 {
1076     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1077
1078     TRACE("(%p)->()\n", This);
1079
1080     if(This->doc_obj)
1081         SetFocus(This->doc_obj->hwnd);
1082     return S_OK;
1083 }
1084
1085 static HRESULT WINAPI HTMLWindow2_get_closed(IHTMLWindow2 *iface, VARIANT_BOOL *p)
1086 {
1087     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1088     FIXME("(%p)->(%p)\n", This, p);
1089     return E_NOTIMPL;
1090 }
1091
1092 static HRESULT WINAPI HTMLWindow2_blur(IHTMLWindow2 *iface)
1093 {
1094     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1095     FIXME("(%p)->()\n", This);
1096     return E_NOTIMPL;
1097 }
1098
1099 static HRESULT WINAPI HTMLWindow2_scroll(IHTMLWindow2 *iface, LONG x, LONG y)
1100 {
1101     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1102     FIXME("(%p)->(%d %d)\n", This, x, y);
1103     return E_NOTIMPL;
1104 }
1105
1106 static HRESULT WINAPI HTMLWindow2_get_clientInformation(IHTMLWindow2 *iface, IOmNavigator **p)
1107 {
1108     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1109     FIXME("(%p)->(%p)\n", This, p);
1110     return E_NOTIMPL;
1111 }
1112
1113 static HRESULT WINAPI HTMLWindow2_setInterval(IHTMLWindow2 *iface, BSTR expression,
1114         LONG msec, VARIANT *language, LONG *timerID)
1115 {
1116     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1117     VARIANT expr;
1118
1119     TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
1120
1121     V_VT(&expr) = VT_BSTR;
1122     V_BSTR(&expr) = expression;
1123     return IHTMLWindow3_setInterval(&This->IHTMLWindow3_iface, &expr, msec, language, timerID);
1124 }
1125
1126 static HRESULT WINAPI HTMLWindow2_clearInterval(IHTMLWindow2 *iface, LONG timerID)
1127 {
1128     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1129
1130     TRACE("(%p)->(%d)\n", This, timerID);
1131
1132     return clear_task_timer(&This->doc->basedoc, TRUE, timerID);
1133 }
1134
1135 static HRESULT WINAPI HTMLWindow2_put_offscreenBuffering(IHTMLWindow2 *iface, VARIANT v)
1136 {
1137     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1138     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
1139     return E_NOTIMPL;
1140 }
1141
1142 static HRESULT WINAPI HTMLWindow2_get_offscreenBuffering(IHTMLWindow2 *iface, VARIANT *p)
1143 {
1144     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1145     FIXME("(%p)->(%p)\n", This, p);
1146     return E_NOTIMPL;
1147 }
1148
1149 static HRESULT WINAPI HTMLWindow2_execScript(IHTMLWindow2 *iface, BSTR scode, BSTR language,
1150         VARIANT *pvarRet)
1151 {
1152     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1153
1154     TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(scode), debugstr_w(language), pvarRet);
1155
1156     return exec_script(This, scode, language, pvarRet);
1157 }
1158
1159 static HRESULT WINAPI HTMLWindow2_toString(IHTMLWindow2 *iface, BSTR *String)
1160 {
1161     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1162
1163     static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
1164
1165     TRACE("(%p)->(%p)\n", This, String);
1166
1167     if(!String)
1168         return E_INVALIDARG;
1169
1170     *String = SysAllocString(objectW);
1171     return *String ? S_OK : E_OUTOFMEMORY;
1172 }
1173
1174 static HRESULT WINAPI HTMLWindow2_scrollBy(IHTMLWindow2 *iface, LONG x, LONG y)
1175 {
1176     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1177     nsresult nsres;
1178
1179     TRACE("(%p)->(%d %d)\n", This, x, y);
1180
1181     nsres = nsIDOMWindow_ScrollBy(This->nswindow, x, y);
1182     if(NS_FAILED(nsres))
1183         ERR("ScrollBy failed: %08x\n", nsres);
1184
1185     return S_OK;
1186 }
1187
1188 static HRESULT WINAPI HTMLWindow2_scrollTo(IHTMLWindow2 *iface, LONG x, LONG y)
1189 {
1190     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1191     nsresult nsres;
1192
1193     TRACE("(%p)->(%d %d)\n", This, x, y);
1194
1195     nsres = nsIDOMWindow_ScrollTo(This->nswindow, x, y);
1196     if(NS_FAILED(nsres))
1197         ERR("ScrollTo failed: %08x\n", nsres);
1198
1199     return S_OK;
1200 }
1201
1202 static HRESULT WINAPI HTMLWindow2_moveTo(IHTMLWindow2 *iface, LONG x, LONG y)
1203 {
1204     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1205     FIXME("(%p)->(%d %d)\n", This, x, y);
1206     return E_NOTIMPL;
1207 }
1208
1209 static HRESULT WINAPI HTMLWindow2_moveBy(IHTMLWindow2 *iface, LONG x, LONG y)
1210 {
1211     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1212     FIXME("(%p)->(%d %d)\n", This, x, y);
1213     return E_NOTIMPL;
1214 }
1215
1216 static HRESULT WINAPI HTMLWindow2_resizeTo(IHTMLWindow2 *iface, LONG x, LONG y)
1217 {
1218     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1219     FIXME("(%p)->(%d %d)\n", This, x, y);
1220     return E_NOTIMPL;
1221 }
1222
1223 static HRESULT WINAPI HTMLWindow2_resizeBy(IHTMLWindow2 *iface, LONG x, LONG y)
1224 {
1225     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1226     FIXME("(%p)->(%d %d)\n", This, x, y);
1227     return E_NOTIMPL;
1228 }
1229
1230 static HRESULT WINAPI HTMLWindow2_get_external(IHTMLWindow2 *iface, IDispatch **p)
1231 {
1232     HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1233
1234     TRACE("(%p)->(%p)\n", This, p);
1235
1236     *p = NULL;
1237
1238     if(!This->doc_obj->hostui)
1239         return S_OK;
1240
1241     return IDocHostUIHandler_GetExternal(This->doc_obj->hostui, p);
1242 }
1243
1244 static const IHTMLWindow2Vtbl HTMLWindow2Vtbl = {
1245     HTMLWindow2_QueryInterface,
1246     HTMLWindow2_AddRef,
1247     HTMLWindow2_Release,
1248     HTMLWindow2_GetTypeInfoCount,
1249     HTMLWindow2_GetTypeInfo,
1250     HTMLWindow2_GetIDsOfNames,
1251     HTMLWindow2_Invoke,
1252     HTMLWindow2_item,
1253     HTMLWindow2_get_length,
1254     HTMLWindow2_get_frames,
1255     HTMLWindow2_put_defaultStatus,
1256     HTMLWindow2_get_defaultStatus,
1257     HTMLWindow2_put_status,
1258     HTMLWindow2_get_status,
1259     HTMLWindow2_setTimeout,
1260     HTMLWindow2_clearTimeout,
1261     HTMLWindow2_alert,
1262     HTMLWindow2_confirm,
1263     HTMLWindow2_prompt,
1264     HTMLWindow2_get_Image,
1265     HTMLWindow2_get_location,
1266     HTMLWindow2_get_history,
1267     HTMLWindow2_close,
1268     HTMLWindow2_put_opener,
1269     HTMLWindow2_get_opener,
1270     HTMLWindow2_get_navigator,
1271     HTMLWindow2_put_name,
1272     HTMLWindow2_get_name,
1273     HTMLWindow2_get_parent,
1274     HTMLWindow2_open,
1275     HTMLWindow2_get_self,
1276     HTMLWindow2_get_top,
1277     HTMLWindow2_get_window,
1278     HTMLWindow2_navigate,
1279     HTMLWindow2_put_onfocus,
1280     HTMLWindow2_get_onfocus,
1281     HTMLWindow2_put_onblur,
1282     HTMLWindow2_get_onblur,
1283     HTMLWindow2_put_onload,
1284     HTMLWindow2_get_onload,
1285     HTMLWindow2_put_onbeforeunload,
1286     HTMLWindow2_get_onbeforeunload,
1287     HTMLWindow2_put_onunload,
1288     HTMLWindow2_get_onunload,
1289     HTMLWindow2_put_onhelp,
1290     HTMLWindow2_get_onhelp,
1291     HTMLWindow2_put_onerror,
1292     HTMLWindow2_get_onerror,
1293     HTMLWindow2_put_onresize,
1294     HTMLWindow2_get_onresize,
1295     HTMLWindow2_put_onscroll,
1296     HTMLWindow2_get_onscroll,
1297     HTMLWindow2_get_document,
1298     HTMLWindow2_get_event,
1299     HTMLWindow2_get__newEnum,
1300     HTMLWindow2_showModalDialog,
1301     HTMLWindow2_showHelp,
1302     HTMLWindow2_get_screen,
1303     HTMLWindow2_get_Option,
1304     HTMLWindow2_focus,
1305     HTMLWindow2_get_closed,
1306     HTMLWindow2_blur,
1307     HTMLWindow2_scroll,
1308     HTMLWindow2_get_clientInformation,
1309     HTMLWindow2_setInterval,
1310     HTMLWindow2_clearInterval,
1311     HTMLWindow2_put_offscreenBuffering,
1312     HTMLWindow2_get_offscreenBuffering,
1313     HTMLWindow2_execScript,
1314     HTMLWindow2_toString,
1315     HTMLWindow2_scrollBy,
1316     HTMLWindow2_scrollTo,
1317     HTMLWindow2_moveTo,
1318     HTMLWindow2_moveBy,
1319     HTMLWindow2_resizeTo,
1320     HTMLWindow2_resizeBy,
1321     HTMLWindow2_get_external
1322 };
1323
1324 static inline HTMLWindow *impl_from_IHTMLWindow3(IHTMLWindow3 *iface)
1325 {
1326     return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow3_iface);
1327 }
1328
1329 static HRESULT WINAPI HTMLWindow3_QueryInterface(IHTMLWindow3 *iface, REFIID riid, void **ppv)
1330 {
1331     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1332
1333     return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1334 }
1335
1336 static ULONG WINAPI HTMLWindow3_AddRef(IHTMLWindow3 *iface)
1337 {
1338     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1339
1340     return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1341 }
1342
1343 static ULONG WINAPI HTMLWindow3_Release(IHTMLWindow3 *iface)
1344 {
1345     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1346
1347     return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1348 }
1349
1350 static HRESULT WINAPI HTMLWindow3_GetTypeInfoCount(IHTMLWindow3 *iface, UINT *pctinfo)
1351 {
1352     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1353
1354     return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1355 }
1356
1357 static HRESULT WINAPI HTMLWindow3_GetTypeInfo(IHTMLWindow3 *iface, UINT iTInfo,
1358                                               LCID lcid, ITypeInfo **ppTInfo)
1359 {
1360     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1361
1362     return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1363 }
1364
1365 static HRESULT WINAPI HTMLWindow3_GetIDsOfNames(IHTMLWindow3 *iface, REFIID riid,
1366                                                 LPOLESTR *rgszNames, UINT cNames,
1367                                                 LCID lcid, DISPID *rgDispId)
1368 {
1369     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1370
1371     return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1372             rgDispId);
1373 }
1374
1375 static HRESULT WINAPI HTMLWindow3_Invoke(IHTMLWindow3 *iface, DISPID dispIdMember,
1376                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1377                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1378 {
1379     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1380
1381     return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1382             pDispParams, pVarResult, pExcepInfo, puArgErr);
1383 }
1384
1385 static HRESULT WINAPI HTMLWindow3_get_screenLeft(IHTMLWindow3 *iface, LONG *p)
1386 {
1387     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1388     FIXME("(%p)->(%p)\n", This, p);
1389     return E_NOTIMPL;
1390 }
1391
1392 static HRESULT WINAPI HTMLWindow3_get_screenTop(IHTMLWindow3 *iface, LONG *p)
1393 {
1394     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1395     FIXME("(%p)->(%p)\n", This, p);
1396     return E_NOTIMPL;
1397 }
1398
1399 static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp, VARIANT_BOOL *pfResult)
1400 {
1401     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1402
1403     TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
1404
1405     if(!This->doc) {
1406         FIXME("No document\n");
1407         return E_FAIL;
1408     }
1409
1410     return attach_event(&This->doc->body_event_target, NULL, &This->doc->basedoc, event, pDisp, pfResult);
1411 }
1412
1413 static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
1414 {
1415     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1416     FIXME("(%p)->()\n", This);
1417     return E_NOTIMPL;
1418 }
1419
1420 static HRESULT window_set_timer(HTMLWindow *This, VARIANT *expr, LONG msec, VARIANT *language,
1421         BOOL interval, LONG *timer_id)
1422 {
1423     IDispatch *disp = NULL;
1424
1425     switch(V_VT(expr)) {
1426     case VT_DISPATCH:
1427         disp = V_DISPATCH(expr);
1428         IDispatch_AddRef(disp);
1429         break;
1430
1431     case VT_BSTR:
1432         disp = script_parse_event(This, V_BSTR(expr));
1433         break;
1434
1435     default:
1436         FIXME("unimplemented vt=%d\n", V_VT(expr));
1437         return E_NOTIMPL;
1438     }
1439
1440     if(!disp)
1441         return E_FAIL;
1442
1443     *timer_id = set_task_timer(&This->doc->basedoc, msec, interval, disp);
1444     IDispatch_Release(disp);
1445
1446     return S_OK;
1447 }
1448
1449 static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1450         VARIANT *language, LONG *timerID)
1451 {
1452     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1453
1454     TRACE("(%p)->(%p(%d) %d %p %p)\n", This, expression, V_VT(expression), msec, language, timerID);
1455
1456     return window_set_timer(This, expression, msec, language, FALSE, timerID);
1457 }
1458
1459 static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1460         VARIANT *language, LONG *timerID)
1461 {
1462     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1463
1464     TRACE("(%p)->(%p %d %p %p)\n", This, expression, msec, language, timerID);
1465
1466     return window_set_timer(This, expression, msec, language, TRUE, timerID);
1467 }
1468
1469 static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)
1470 {
1471     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1472     FIXME("(%p)\n", This);
1473     return E_NOTIMPL;
1474 }
1475
1476 static HRESULT WINAPI HTMLWindow3_put_onbeforeprint(IHTMLWindow3 *iface, VARIANT v)
1477 {
1478     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1479     FIXME("(%p)->()\n", This);
1480     return E_NOTIMPL;
1481 }
1482
1483 static HRESULT WINAPI HTMLWindow3_get_onbeforeprint(IHTMLWindow3 *iface, VARIANT *p)
1484 {
1485     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1486     FIXME("(%p)->(%p)\n", This, p);
1487     return E_NOTIMPL;
1488 }
1489
1490 static HRESULT WINAPI HTMLWindow3_put_onafterprint(IHTMLWindow3 *iface, VARIANT v)
1491 {
1492     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1493     FIXME("(%p)->()\n", This);
1494     return E_NOTIMPL;
1495 }
1496
1497 static HRESULT WINAPI HTMLWindow3_get_onafterprint(IHTMLWindow3 *iface, VARIANT *p)
1498 {
1499     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1500     FIXME("(%p)->(%p)\n", This, p);
1501     return E_NOTIMPL;
1502 }
1503
1504 static HRESULT WINAPI HTMLWindow3_get_clipboardData(IHTMLWindow3 *iface, IHTMLDataTransfer **p)
1505 {
1506     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1507     FIXME("(%p)->(%p)\n", This, p);
1508     return E_NOTIMPL;
1509 }
1510
1511 static HRESULT WINAPI HTMLWindow3_showModelessDialog(IHTMLWindow3 *iface, BSTR url,
1512         VARIANT *varArgIn, VARIANT *options, IHTMLWindow2 **pDialog)
1513 {
1514     HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1515     FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(url), varArgIn, options, pDialog);
1516     return E_NOTIMPL;
1517 }
1518
1519 static const IHTMLWindow3Vtbl HTMLWindow3Vtbl = {
1520     HTMLWindow3_QueryInterface,
1521     HTMLWindow3_AddRef,
1522     HTMLWindow3_Release,
1523     HTMLWindow3_GetTypeInfoCount,
1524     HTMLWindow3_GetTypeInfo,
1525     HTMLWindow3_GetIDsOfNames,
1526     HTMLWindow3_Invoke,
1527     HTMLWindow3_get_screenLeft,
1528     HTMLWindow3_get_screenTop,
1529     HTMLWindow3_attachEvent,
1530     HTMLWindow3_detachEvent,
1531     HTMLWindow3_setTimeout,
1532     HTMLWindow3_setInterval,
1533     HTMLWindow3_print,
1534     HTMLWindow3_put_onbeforeprint,
1535     HTMLWindow3_get_onbeforeprint,
1536     HTMLWindow3_put_onafterprint,
1537     HTMLWindow3_get_onafterprint,
1538     HTMLWindow3_get_clipboardData,
1539     HTMLWindow3_showModelessDialog
1540 };
1541
1542 static inline HTMLWindow *impl_from_IHTMLWindow4(IHTMLWindow4 *iface)
1543 {
1544     return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow4_iface);
1545 }
1546
1547 static HRESULT WINAPI HTMLWindow4_QueryInterface(IHTMLWindow4 *iface, REFIID riid, void **ppv)
1548 {
1549     HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1550
1551     return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1552 }
1553
1554 static ULONG WINAPI HTMLWindow4_AddRef(IHTMLWindow4 *iface)
1555 {
1556     HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1557
1558     return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1559 }
1560
1561 static ULONG WINAPI HTMLWindow4_Release(IHTMLWindow4 *iface)
1562 {
1563     HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1564
1565     return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1566 }
1567
1568 static HRESULT WINAPI HTMLWindow4_GetTypeInfoCount(IHTMLWindow4 *iface, UINT *pctinfo)
1569 {
1570     HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1571
1572     return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1573 }
1574
1575 static HRESULT WINAPI HTMLWindow4_GetTypeInfo(IHTMLWindow4 *iface, UINT iTInfo,
1576                                               LCID lcid, ITypeInfo **ppTInfo)
1577 {
1578     HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1579
1580     return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1581 }
1582
1583 static HRESULT WINAPI HTMLWindow4_GetIDsOfNames(IHTMLWindow4 *iface, REFIID riid,
1584                                                 LPOLESTR *rgszNames, UINT cNames,
1585                                                 LCID lcid, DISPID *rgDispId)
1586 {
1587     HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1588
1589     return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1590             rgDispId);
1591 }
1592
1593 static HRESULT WINAPI HTMLWindow4_Invoke(IHTMLWindow4 *iface, DISPID dispIdMember,
1594                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1595                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1596 {
1597     HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1598
1599     return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1600             pDispParams, pVarResult, pExcepInfo, puArgErr);
1601 }
1602
1603 static HRESULT WINAPI HTMLWindow4_createPopup(IHTMLWindow4 *iface, VARIANT *varArgIn,
1604                             IDispatch **ppPopup)
1605 {
1606     HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1607     FIXME("(%p)->(%p %p)\n", This, varArgIn, ppPopup);
1608     return E_NOTIMPL;
1609 }
1610
1611 static HRESULT WINAPI HTMLWindow4_get_frameElement(IHTMLWindow4 *iface, IHTMLFrameBase **p)
1612 {
1613     HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1614     TRACE("(%p)->(%p)\n", This, p);
1615
1616     if(This->frame_element) {
1617         *p = &This->frame_element->IHTMLFrameBase_iface;
1618         IHTMLFrameBase_AddRef(*p);
1619     }else
1620         *p = NULL;
1621
1622     return S_OK;
1623 }
1624
1625 static const IHTMLWindow4Vtbl HTMLWindow4Vtbl = {
1626     HTMLWindow4_QueryInterface,
1627     HTMLWindow4_AddRef,
1628     HTMLWindow4_Release,
1629     HTMLWindow4_GetTypeInfoCount,
1630     HTMLWindow4_GetTypeInfo,
1631     HTMLWindow4_GetIDsOfNames,
1632     HTMLWindow4_Invoke,
1633     HTMLWindow4_createPopup,
1634     HTMLWindow4_get_frameElement
1635 };
1636
1637 static inline HTMLWindow *impl_from_IHTMLPrivateWindow(IHTMLPrivateWindow *iface)
1638 {
1639     return CONTAINING_RECORD(iface, HTMLWindow, IHTMLPrivateWindow_iface);
1640 }
1641
1642 static HRESULT WINAPI HTMLPrivateWindow_QueryInterface(IHTMLPrivateWindow *iface, REFIID riid, void **ppv)
1643 {
1644     HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1645
1646     return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1647 }
1648
1649 static ULONG WINAPI HTMLPrivateWindow_AddRef(IHTMLPrivateWindow *iface)
1650 {
1651     HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1652
1653     return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1654 }
1655
1656 static ULONG WINAPI HTMLPrivateWindow_Release(IHTMLPrivateWindow *iface)
1657 {
1658     HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1659
1660     return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1661 }
1662
1663 static HRESULT WINAPI HTMLPrivateWindow_SuperNavigate(IHTMLPrivateWindow *iface, BSTR url, BSTR arg2, BSTR arg3,
1664         BSTR arg4, VARIANT *post_data_var, VARIANT *headers_var, ULONG flags)
1665 {
1666     HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1667     DWORD post_data_size = 0;
1668     BYTE *post_data = NULL;
1669     WCHAR *headers = NULL;
1670     nsChannelBSC *bsc;
1671     IMoniker *mon;
1672     BSTR new_url;
1673     HRESULT hres;
1674
1675     TRACE("(%p)->(%s %s %s %s %s %s %x)\n", This, debugstr_w(url), debugstr_w(arg2), debugstr_w(arg3), debugstr_w(arg4),
1676           debugstr_variant(post_data_var), debugstr_variant(headers_var), flags);
1677
1678     new_url = url;
1679     if(This->doc_obj->hostui) {
1680         OLECHAR *translated_url = NULL;
1681
1682         hres = IDocHostUIHandler_TranslateUrl(This->doc_obj->hostui, 0, url, &translated_url);
1683         if(hres == S_OK && translated_url) {
1684             new_url = SysAllocString(translated_url);
1685             CoTaskMemFree(translated_url);
1686         }
1687     }
1688
1689     if(This->doc_obj->client) {
1690         IOleCommandTarget *cmdtrg;
1691
1692         hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
1693         if(SUCCEEDED(hres)) {
1694             VARIANT in, out;
1695
1696             V_VT(&in) = VT_BSTR;
1697             V_BSTR(&in) = new_url;
1698             V_VT(&out) = VT_BOOL;
1699             V_BOOL(&out) = VARIANT_TRUE;
1700             hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &in, &out);
1701             IOleCommandTarget_Release(cmdtrg);
1702             if(SUCCEEDED(hres))
1703                 VariantClear(&out);
1704         }
1705     }
1706
1707     /* FIXME: Why not set_ready_state? */
1708     This->readystate = READYSTATE_UNINITIALIZED;
1709
1710     hres = CreateURLMoniker(NULL, new_url, &mon);
1711     if(new_url != url)
1712         SysFreeString(new_url);
1713     if(FAILED(hres))
1714         return hres;
1715
1716     if(post_data_var) {
1717         if(V_VT(post_data_var) == (VT_ARRAY|VT_UI1)) {
1718             SafeArrayAccessData(V_ARRAY(post_data_var), (void**)&post_data);
1719             post_data_size = V_ARRAY(post_data_var)->rgsabound[0].cElements;
1720         }
1721     }
1722
1723     if(headers_var && V_VT(headers_var) != VT_EMPTY && V_VT(headers_var) != VT_ERROR) {
1724         if(V_VT(headers_var) != VT_BSTR)
1725             return E_INVALIDARG;
1726
1727         headers = V_BSTR(headers_var);
1728     }
1729
1730     hres = create_channelbsc(mon, headers, post_data, post_data_size, &bsc);
1731     if(post_data)
1732         SafeArrayUnaccessData(V_ARRAY(post_data_var));
1733     if(FAILED(hres)) {
1734         IMoniker_Release(mon);
1735         return hres;
1736     }
1737
1738     hres = set_moniker(&This->doc_obj->basedoc, mon, NULL, bsc, TRUE);
1739     if(SUCCEEDED(hres))
1740         hres = async_start_doc_binding(This, bsc);
1741
1742     IUnknown_Release((IUnknown*)bsc);
1743     IMoniker_Release(mon);
1744     return hres;
1745 }
1746
1747 static HRESULT WINAPI HTMLPrivateWindow_GetPendingUrl(IHTMLPrivateWindow *iface, BSTR *url)
1748 {
1749     HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1750     FIXME("(%p)->(%p)\n", This, url);
1751     return E_NOTIMPL;
1752 }
1753
1754 static HRESULT WINAPI HTMLPrivateWindow_SetPICSTarget(IHTMLPrivateWindow *iface, IOleCommandTarget *cmdtrg)
1755 {
1756     HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1757     FIXME("(%p)->(%p)\n", This, cmdtrg);
1758     return E_NOTIMPL;
1759 }
1760
1761 static HRESULT WINAPI HTMLPrivateWindow_PICSComplete(IHTMLPrivateWindow *iface, int arg)
1762 {
1763     HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1764     FIXME("(%p)->(%x)\n", This, arg);
1765     return E_NOTIMPL;
1766 }
1767
1768 static HRESULT WINAPI HTMLPrivateWindow_FindWindowByName(IHTMLPrivateWindow *iface, LPCWSTR name, IHTMLWindow2 **ret)
1769 {
1770     HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1771     FIXME("(%p)->(%s %p)\n", This, debugstr_w(name), ret);
1772     return E_NOTIMPL;
1773 }
1774
1775 static HRESULT WINAPI HTMLPrivateWindow_GetAddressBar(IHTMLPrivateWindow *iface, BSTR *url)
1776 {
1777     HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1778     FIXME("(%p)->(%p)\n", This, url);
1779     return E_NOTIMPL;
1780 }
1781
1782 static const IHTMLPrivateWindowVtbl HTMLPrivateWindowVtbl = {
1783     HTMLPrivateWindow_QueryInterface,
1784     HTMLPrivateWindow_AddRef,
1785     HTMLPrivateWindow_Release,
1786     HTMLPrivateWindow_SuperNavigate,
1787     HTMLPrivateWindow_GetPendingUrl,
1788     HTMLPrivateWindow_SetPICSTarget,
1789     HTMLPrivateWindow_PICSComplete,
1790     HTMLPrivateWindow_FindWindowByName,
1791     HTMLPrivateWindow_GetAddressBar
1792 };
1793
1794 static inline HTMLWindow *impl_from_IDispatchEx(IDispatchEx *iface)
1795 {
1796     return CONTAINING_RECORD(iface, HTMLWindow, IDispatchEx_iface);
1797 }
1798
1799 static HRESULT WINAPI WindowDispEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1800 {
1801     HTMLWindow *This = impl_from_IDispatchEx(iface);
1802
1803     return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1804 }
1805
1806 static ULONG WINAPI WindowDispEx_AddRef(IDispatchEx *iface)
1807 {
1808     HTMLWindow *This = impl_from_IDispatchEx(iface);
1809
1810     return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1811 }
1812
1813 static ULONG WINAPI WindowDispEx_Release(IDispatchEx *iface)
1814 {
1815     HTMLWindow *This = impl_from_IDispatchEx(iface);
1816
1817     return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1818 }
1819
1820 static HRESULT WINAPI WindowDispEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1821 {
1822     HTMLWindow *This = impl_from_IDispatchEx(iface);
1823
1824     TRACE("(%p)->(%p)\n", This, pctinfo);
1825
1826     return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
1827 }
1828
1829 static HRESULT WINAPI WindowDispEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1830                                                LCID lcid, ITypeInfo **ppTInfo)
1831 {
1832     HTMLWindow *This = impl_from_IDispatchEx(iface);
1833
1834     TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1835
1836     return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1837 }
1838
1839 static HRESULT WINAPI WindowDispEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1840                                                  LPOLESTR *rgszNames, UINT cNames,
1841                                                  LCID lcid, DISPID *rgDispId)
1842 {
1843     HTMLWindow *This = impl_from_IDispatchEx(iface);
1844     UINT i;
1845     HRESULT hres;
1846
1847     WARN("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1848           lcid, rgDispId);
1849
1850     for(i=0; i < cNames; i++) {
1851         /* We shouldn't use script's IDispatchEx here, so we shouldn't use GetDispID */
1852         hres = IDispatchEx_GetDispID(&This->IDispatchEx_iface, rgszNames[i], 0, rgDispId+i);
1853         if(FAILED(hres))
1854             return hres;
1855     }
1856
1857     return S_OK;
1858 }
1859
1860 static HRESULT WINAPI WindowDispEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1861                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1862                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1863 {
1864     HTMLWindow *This = impl_from_IDispatchEx(iface);
1865
1866     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1867           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1868
1869     /* FIXME: Use script dispatch */
1870
1871     return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1872             pDispParams, pVarResult, pExcepInfo, puArgErr);
1873 }
1874
1875 static global_prop_t *alloc_global_prop(HTMLWindow *This, global_prop_type_t type, BSTR name)
1876 {
1877     if(This->global_prop_cnt == This->global_prop_size) {
1878         global_prop_t *new_props;
1879         DWORD new_size;
1880
1881         if(This->global_props) {
1882             new_size = This->global_prop_size*2;
1883             new_props = heap_realloc(This->global_props, new_size*sizeof(global_prop_t));
1884         }else {
1885             new_size = 16;
1886             new_props = heap_alloc(new_size*sizeof(global_prop_t));
1887         }
1888         if(!new_props)
1889             return NULL;
1890         This->global_props = new_props;
1891         This->global_prop_size = new_size;
1892     }
1893
1894     This->global_props[This->global_prop_cnt].name = heap_strdupW(name);
1895     if(!This->global_props[This->global_prop_cnt].name)
1896         return NULL;
1897
1898     This->global_props[This->global_prop_cnt].type = type;
1899     return This->global_props + This->global_prop_cnt++;
1900 }
1901
1902 static inline DWORD prop_to_dispid(HTMLWindow *This, global_prop_t *prop)
1903 {
1904     return MSHTML_DISPID_CUSTOM_MIN + (prop-This->global_props);
1905 }
1906
1907 HRESULT search_window_props(HTMLWindow *This, BSTR bstrName, DWORD grfdex, DISPID *pid)
1908 {
1909     DWORD i;
1910     ScriptHost *script_host;
1911     DISPID id;
1912
1913     for(i=0; i < This->global_prop_cnt; i++) {
1914         /* FIXME: case sensitivity */
1915         if(!strcmpW(This->global_props[i].name, bstrName)) {
1916             *pid = MSHTML_DISPID_CUSTOM_MIN+i;
1917             return S_OK;
1918         }
1919     }
1920
1921     if(find_global_prop(This, bstrName, grfdex, &script_host, &id)) {
1922         global_prop_t *prop;
1923
1924         prop = alloc_global_prop(This, GLOBAL_SCRIPTVAR, bstrName);
1925         if(!prop)
1926             return E_OUTOFMEMORY;
1927
1928         prop->script_host = script_host;
1929         prop->id = id;
1930
1931         *pid = prop_to_dispid(This, prop);
1932         return S_OK;
1933     }
1934
1935     return DISP_E_UNKNOWNNAME;
1936 }
1937
1938 static HRESULT WINAPI WindowDispEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1939 {
1940     HTMLWindow *This = impl_from_IDispatchEx(iface);
1941     HRESULT hres;
1942
1943     TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
1944
1945     hres = search_window_props(This, bstrName, grfdex, pid);
1946     if(hres != DISP_E_UNKNOWNNAME)
1947         return hres;
1948
1949     hres = IDispatchEx_GetDispID(&This->dispex.IDispatchEx_iface, bstrName, grfdex, pid);
1950     if(hres != DISP_E_UNKNOWNNAME)
1951         return hres;
1952
1953     if(This->doc) {
1954         global_prop_t *prop;
1955         IHTMLElement *elem;
1956
1957         hres = IHTMLDocument3_getElementById(&This->doc->basedoc.IHTMLDocument3_iface,
1958                                              bstrName, &elem);
1959         if(SUCCEEDED(hres) && elem) {
1960             IHTMLElement_Release(elem);
1961
1962             prop = alloc_global_prop(This, GLOBAL_ELEMENTVAR, bstrName);
1963             if(!prop)
1964                 return E_OUTOFMEMORY;
1965
1966             *pid = prop_to_dispid(This, prop);
1967             return S_OK;
1968         }
1969     }
1970
1971     return DISP_E_UNKNOWNNAME;
1972 }
1973
1974 static HRESULT WINAPI WindowDispEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1975         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1976 {
1977     HTMLWindow *This = impl_from_IDispatchEx(iface);
1978
1979     TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1980
1981     if(id == DISPID_IHTMLWINDOW2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT)) {
1982         HTMLLocation *location;
1983         HRESULT hres;
1984
1985         TRACE("forwarding to location.href\n");
1986
1987         hres = get_location(This, &location);
1988         if(FAILED(hres))
1989             return hres;
1990
1991         hres = IDispatchEx_InvokeEx(&location->dispex.IDispatchEx_iface, DISPID_VALUE, lcid,
1992                 wFlags, pdp, pvarRes, pei, pspCaller);
1993         IHTMLLocation_Release(&location->IHTMLLocation_iface);
1994         return hres;
1995     }
1996
1997     return IDispatchEx_InvokeEx(&This->dispex.IDispatchEx_iface, id, lcid, wFlags, pdp, pvarRes,
1998             pei, pspCaller);
1999 }
2000
2001 static HRESULT WINAPI WindowDispEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
2002 {
2003     HTMLWindow *This = impl_from_IDispatchEx(iface);
2004
2005     TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
2006
2007     return IDispatchEx_DeleteMemberByName(&This->dispex.IDispatchEx_iface, bstrName, grfdex);
2008 }
2009
2010 static HRESULT WINAPI WindowDispEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
2011 {
2012     HTMLWindow *This = impl_from_IDispatchEx(iface);
2013
2014     TRACE("(%p)->(%x)\n", This, id);
2015
2016     return IDispatchEx_DeleteMemberByDispID(&This->dispex.IDispatchEx_iface, id);
2017 }
2018
2019 static HRESULT WINAPI WindowDispEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
2020 {
2021     HTMLWindow *This = impl_from_IDispatchEx(iface);
2022
2023     TRACE("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
2024
2025     return IDispatchEx_GetMemberProperties(&This->dispex.IDispatchEx_iface, id, grfdexFetch,
2026             pgrfdex);
2027 }
2028
2029 static HRESULT WINAPI WindowDispEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
2030 {
2031     HTMLWindow *This = impl_from_IDispatchEx(iface);
2032
2033     TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
2034
2035     return IDispatchEx_GetMemberName(&This->dispex.IDispatchEx_iface, id, pbstrName);
2036 }
2037
2038 static HRESULT WINAPI WindowDispEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
2039 {
2040     HTMLWindow *This = impl_from_IDispatchEx(iface);
2041
2042     TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
2043
2044     return IDispatchEx_GetNextDispID(&This->dispex.IDispatchEx_iface, grfdex, id, pid);
2045 }
2046
2047 static HRESULT WINAPI WindowDispEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
2048 {
2049     HTMLWindow *This = impl_from_IDispatchEx(iface);
2050
2051     TRACE("(%p)->(%p)\n", This, ppunk);
2052
2053     *ppunk = NULL;
2054     return S_OK;
2055 }
2056
2057 static const IDispatchExVtbl WindowDispExVtbl = {
2058     WindowDispEx_QueryInterface,
2059     WindowDispEx_AddRef,
2060     WindowDispEx_Release,
2061     WindowDispEx_GetTypeInfoCount,
2062     WindowDispEx_GetTypeInfo,
2063     WindowDispEx_GetIDsOfNames,
2064     WindowDispEx_Invoke,
2065     WindowDispEx_GetDispID,
2066     WindowDispEx_InvokeEx,
2067     WindowDispEx_DeleteMemberByName,
2068     WindowDispEx_DeleteMemberByDispID,
2069     WindowDispEx_GetMemberProperties,
2070     WindowDispEx_GetMemberName,
2071     WindowDispEx_GetNextDispID,
2072     WindowDispEx_GetNameSpaceParent
2073 };
2074
2075 static inline HTMLWindow *impl_from_IServiceProvider(IServiceProvider *iface)
2076 {
2077     return CONTAINING_RECORD(iface, HTMLWindow, IServiceProvider_iface);
2078 }
2079
2080 static HRESULT WINAPI HTMLWindowSP_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
2081 {
2082     HTMLWindow *This = impl_from_IServiceProvider(iface);
2083     return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2084 }
2085
2086 static ULONG WINAPI HTMLWindowSP_AddRef(IServiceProvider *iface)
2087 {
2088     HTMLWindow *This = impl_from_IServiceProvider(iface);
2089     return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2090 }
2091
2092 static ULONG WINAPI HTMLWindowSP_Release(IServiceProvider *iface)
2093 {
2094     HTMLWindow *This = impl_from_IServiceProvider(iface);
2095     return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2096 }
2097
2098 static HRESULT WINAPI HTMLWindowSP_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
2099 {
2100     HTMLWindow *This = impl_from_IServiceProvider(iface);
2101
2102     if(IsEqualGUID(guidService, &IID_IHTMLWindow2)) {
2103         TRACE("IID_IHTMLWindow2\n");
2104         return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2105     }
2106
2107     TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
2108
2109     if(!This->doc_obj)
2110         return E_NOINTERFACE;
2111
2112     return IServiceProvider_QueryService(&This->doc_obj->basedoc.IServiceProvider_iface,
2113             guidService, riid, ppv);
2114 }
2115
2116 static const IServiceProviderVtbl ServiceProviderVtbl = {
2117     HTMLWindowSP_QueryInterface,
2118     HTMLWindowSP_AddRef,
2119     HTMLWindowSP_Release,
2120     HTMLWindowSP_QueryService
2121 };
2122
2123 static inline HTMLWindow *impl_from_DispatchEx(DispatchEx *iface)
2124 {
2125     return CONTAINING_RECORD(iface, HTMLWindow, dispex);
2126 }
2127
2128 static HRESULT HTMLWindow_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2129         VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2130 {
2131     HTMLWindow *This = impl_from_DispatchEx(dispex);
2132     global_prop_t *prop;
2133     DWORD idx;
2134     HRESULT hres;
2135
2136     idx = id - MSHTML_DISPID_CUSTOM_MIN;
2137     if(idx >= This->global_prop_cnt)
2138         return DISP_E_MEMBERNOTFOUND;
2139
2140     prop = This->global_props+idx;
2141
2142     switch(prop->type) {
2143     case GLOBAL_SCRIPTVAR: {
2144         IDispatchEx *dispex;
2145         IDispatch *disp;
2146
2147         disp = get_script_disp(prop->script_host);
2148         if(!disp)
2149             return E_UNEXPECTED;
2150
2151         hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
2152         if(SUCCEEDED(hres)) {
2153             TRACE("%s >>>\n", debugstr_w(prop->name));
2154             hres = IDispatchEx_InvokeEx(dispex, prop->id, lcid, flags, params, res, ei, caller);
2155             if(hres == S_OK)
2156                 TRACE("%s <<<\n", debugstr_w(prop->name));
2157             else
2158                 WARN("%s <<< %08x\n", debugstr_w(prop->name), hres);
2159             IDispatchEx_Release(dispex);
2160         }else {
2161             FIXME("No IDispatchEx\n");
2162         }
2163         IDispatch_Release(disp);
2164         break;
2165     }
2166     case GLOBAL_ELEMENTVAR: {
2167         IHTMLElement *elem;
2168
2169         hres = IHTMLDocument3_getElementById(&This->doc->basedoc.IHTMLDocument3_iface,
2170                                              prop->name, &elem);
2171         if(FAILED(hres))
2172             return hres;
2173
2174         if(!elem)
2175             return DISP_E_MEMBERNOTFOUND;
2176
2177         V_VT(res) = VT_DISPATCH;
2178         V_DISPATCH(res) = (IDispatch*)elem;
2179         break;
2180     }
2181     default:
2182         ERR("invalid type %d\n", prop->type);
2183         hres = DISP_E_MEMBERNOTFOUND;
2184     }
2185
2186     return hres;
2187 }
2188
2189
2190 static const dispex_static_data_vtbl_t HTMLWindow_dispex_vtbl = {
2191     NULL,
2192     NULL,
2193     HTMLWindow_invoke
2194 };
2195
2196 static const tid_t HTMLWindow_iface_tids[] = {
2197     IHTMLWindow2_tid,
2198     IHTMLWindow3_tid,
2199     IHTMLWindow4_tid,
2200     0
2201 };
2202
2203 static dispex_static_data_t HTMLWindow_dispex = {
2204     &HTMLWindow_dispex_vtbl,
2205     DispHTMLWindow2_tid,
2206     NULL,
2207     HTMLWindow_iface_tids
2208 };
2209
2210 HRESULT HTMLWindow_Create(HTMLDocumentObj *doc_obj, nsIDOMWindow *nswindow, HTMLWindow *parent, HTMLWindow **ret)
2211 {
2212     HTMLWindow *window;
2213
2214     window = heap_alloc_zero(sizeof(HTMLWindow));
2215     if(!window)
2216         return E_OUTOFMEMORY;
2217
2218     window->window_ref = heap_alloc(sizeof(windowref_t));
2219     if(!window->window_ref) {
2220         heap_free(window);
2221         return E_OUTOFMEMORY;
2222     }
2223
2224     window->IHTMLWindow2_iface.lpVtbl = &HTMLWindow2Vtbl;
2225     window->IHTMLWindow3_iface.lpVtbl = &HTMLWindow3Vtbl;
2226     window->IHTMLWindow4_iface.lpVtbl = &HTMLWindow4Vtbl;
2227     window->IHTMLPrivateWindow_iface.lpVtbl = &HTMLPrivateWindowVtbl;
2228     window->IDispatchEx_iface.lpVtbl = &WindowDispExVtbl;
2229     window->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
2230     window->ref = 1;
2231     window->doc_obj = doc_obj;
2232
2233     window->window_ref->window = window;
2234     window->window_ref->ref = 1;
2235
2236     init_dispex(&window->dispex, (IUnknown*)&window->IHTMLWindow2_iface, &HTMLWindow_dispex);
2237
2238     if(nswindow) {
2239         nsIDOMWindow_AddRef(nswindow);
2240         window->nswindow = nswindow;
2241     }
2242
2243     window->scriptmode = parent ? parent->scriptmode : SCRIPTMODE_GECKO;
2244     window->readystate = READYSTATE_UNINITIALIZED;
2245     list_init(&window->script_hosts);
2246
2247     window->task_magic = get_task_target_magic();
2248     update_window_doc(window);
2249
2250     list_init(&window->children);
2251     list_add_head(&window_list, &window->entry);
2252
2253     if(parent) {
2254         IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
2255
2256         window->parent = parent;
2257         list_add_tail(&parent->children, &window->sibling_entry);
2258     }
2259
2260     *ret = window;
2261     return S_OK;
2262 }
2263
2264 void update_window_doc(HTMLWindow *window)
2265 {
2266     nsIDOMHTMLDocument *nshtmldoc;
2267     nsIDOMDocument *nsdoc;
2268     nsresult nsres;
2269
2270     nsres = nsIDOMWindow_GetDocument(window->nswindow, &nsdoc);
2271     if(NS_FAILED(nsres) || !nsdoc) {
2272         ERR("GetDocument failed: %08x\n", nsres);
2273         return;
2274     }
2275
2276     nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
2277     nsIDOMDocument_Release(nsdoc);
2278     if(NS_FAILED(nsres)) {
2279         ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres);
2280         return;
2281     }
2282
2283     if(!window->doc || window->doc->nsdoc != nshtmldoc) {
2284         HTMLDocumentNode *doc;
2285         HRESULT hres;
2286
2287         hres = create_doc_from_nsdoc(nshtmldoc, window->doc_obj, window, &doc);
2288         if(SUCCEEDED(hres)) {
2289             window_set_docnode(window, doc);
2290             htmldoc_release(&doc->basedoc);
2291         }else {
2292             ERR("create_doc_from_nsdoc failed: %08x\n", hres);
2293         }
2294     }
2295
2296     nsIDOMHTMLDocument_Release(nshtmldoc);
2297 }
2298
2299 HTMLWindow *nswindow_to_window(const nsIDOMWindow *nswindow)
2300 {
2301     HTMLWindow *iter;
2302
2303     LIST_FOR_EACH_ENTRY(iter, &window_list, HTMLWindow, entry) {
2304         if(iter->nswindow == nswindow)
2305             return iter;
2306     }
2307
2308     return NULL;
2309 }