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