wininet: Support the Cache-Control max-age directive for setting url cache entry...
[wine/testsucceed.git] / dlls / mshtml / htmlwindow.c
blobd0d378f5ec2a1f12ab406160add227eb40ab1934
1 /*
2 * Copyright 2006-2010 Jacek Caban for CodeWeavers
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.
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.
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
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
27 #include "mshtmdid.h"
28 #include "shlguid.h"
30 #include "wine/debug.h"
32 #include "mshtml_private.h"
33 #include "htmlevent.h"
34 #include "resource.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 static struct list window_list = LIST_INIT(window_list);
40 static void window_set_docnode(HTMLWindow *window, HTMLDocumentNode *doc_node)
42 if(window->doc) {
43 abort_document_bindings(window->doc);
44 window->doc->basedoc.window = NULL;
45 htmldoc_release(&window->doc->basedoc);
47 window->doc = doc_node;
48 if(doc_node)
49 htmldoc_addref(&doc_node->basedoc);
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);
59 if(doc_node && window->doc_obj && window->doc_obj->usermode == EDITMODE) {
60 nsIDOMNSHTMLDocument *nshtmldoc;
61 nsAString mode_str;
62 nsresult nsres;
64 static const PRUnichar onW[] = {'o','n',0};
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);
80 nsIDOMWindow *get_nsdoc_window(nsIDOMDocument *nsdoc)
82 nsIDOMDocumentView *nsdocview;
83 nsIDOMAbstractView *nsview;
84 nsIDOMWindow *nswindow;
85 nsresult nsres;
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;
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;
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;
108 return nswindow;
111 static void release_children(HTMLWindow *This)
113 HTMLWindow *child;
115 while(!list_empty(&This->children)) {
116 child = LIST_ENTRY(list_tail(&This->children), HTMLWindow, sibling_entry);
118 list_remove(&child->sibling_entry);
119 child->parent = NULL;
120 IHTMLWindow2_Release(&child->IHTMLWindow2_iface);
124 static HRESULT get_location(HTMLWindow *This, HTMLLocation **ret)
126 if(This->location) {
127 IHTMLLocation_AddRef(&This->location->IHTMLLocation_iface);
128 }else {
129 HRESULT hres;
131 hres = HTMLLocation_Create(This, &This->location);
132 if(FAILED(hres))
133 return hres;
136 *ret = This->location;
137 return S_OK;
140 static inline HRESULT set_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
142 if(!window->doc) {
143 FIXME("No document\n");
144 return E_FAIL;
147 return set_event_handler(&window->doc->body_event_target, NULL, window->doc, eid, var);
150 static inline HRESULT get_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
152 if(!window->doc) {
153 FIXME("No document\n");
154 return E_FAIL;
157 return get_event_handler(&window->doc->body_event_target, eid, var);
160 static inline HTMLWindow *impl_from_IHTMLWindow2(IHTMLWindow2 *iface)
162 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow2_iface);
165 static HRESULT WINAPI HTMLWindow2_QueryInterface(IHTMLWindow2 *iface, REFIID riid, void **ppv)
167 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
169 *ppv = NULL;
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;
202 if(*ppv) {
203 IUnknown_AddRef((IUnknown*)*ppv);
204 return S_OK;
207 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
208 return E_NOINTERFACE;
211 static ULONG WINAPI HTMLWindow2_AddRef(IHTMLWindow2 *iface)
213 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
214 LONG ref = InterlockedIncrement(&This->ref);
216 TRACE("(%p) ref=%d\n", This, ref);
218 return ref;
221 static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
223 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
224 LONG ref = InterlockedDecrement(&This->ref);
226 TRACE("(%p) ref=%d\n", This, ref);
228 if(!ref) {
229 DWORD i;
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);
237 if(This->frame_element)
238 This->frame_element->content_window = NULL;
240 if(This->option_factory) {
241 This->option_factory->window = NULL;
242 IHTMLOptionElementFactory_Release(&This->option_factory->IHTMLOptionElementFactory_iface);
245 if(This->image_factory) {
246 This->image_factory->window = NULL;
247 IHTMLImageElementFactory_Release(&This->image_factory->IHTMLImageElementFactory_iface);
250 if(This->location) {
251 This->location->window = NULL;
252 IHTMLLocation_Release(&This->location->IHTMLLocation_iface);
255 if(This->screen)
256 IHTMLScreen_Release(This->screen);
258 for(i=0; i < This->global_prop_cnt; i++)
259 heap_free(This->global_props[i].name);
261 This->window_ref->window = NULL;
262 windowref_release(This->window_ref);
264 heap_free(This->global_props);
265 release_script_hosts(This);
267 if(This->nswindow)
268 nsIDOMWindow_Release(This->nswindow);
270 list_remove(&This->entry);
271 release_dispex(&This->dispex);
272 heap_free(This);
275 return ref;
278 static HRESULT WINAPI HTMLWindow2_GetTypeInfoCount(IHTMLWindow2 *iface, UINT *pctinfo)
280 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
282 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
285 static HRESULT WINAPI HTMLWindow2_GetTypeInfo(IHTMLWindow2 *iface, UINT iTInfo,
286 LCID lcid, ITypeInfo **ppTInfo)
288 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
290 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
293 static HRESULT WINAPI HTMLWindow2_GetIDsOfNames(IHTMLWindow2 *iface, REFIID riid,
294 LPOLESTR *rgszNames, UINT cNames,
295 LCID lcid, DISPID *rgDispId)
297 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
299 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
300 rgDispId);
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)
307 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
309 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
310 pDispParams, pVarResult, pExcepInfo, puArgErr);
313 static HRESULT get_frame_by_index(nsIDOMWindowCollection *nsFrames, PRUint32 index, HTMLWindow **ret)
315 PRUint32 length;
316 nsIDOMWindow *nsWindow;
317 nsresult nsres;
319 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
320 if(NS_FAILED(nsres)) {
321 FIXME("nsIDOMWindowCollection_GetLength failed: 0x%08x\n", nsres);
322 return E_FAIL;
325 if(index >= length)
326 return DISP_E_MEMBERNOTFOUND;
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;
334 *ret = nswindow_to_window(nsWindow);
336 nsIDOMWindow_Release(nsWindow);
338 return S_OK;
341 static HRESULT WINAPI HTMLWindow2_item(IHTMLWindow2 *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
343 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
344 nsIDOMWindowCollection *nsFrames;
345 HTMLWindow *window;
346 HRESULT hres;
347 nsresult nsres;
349 TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
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;
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;
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;
377 TRACE("Getting name %s\n", wine_dbgstr_w(str));
379 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
381 window = NULL;
382 for(i = 0; i < length && !window; ++i) {
383 HTMLWindow *cur_window;
384 nsIDOMWindow *nsWindow;
385 BSTR id;
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;
394 cur_window = nswindow_to_window(nsWindow);
396 nsIDOMWindow_Release(nsWindow);
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;
404 if(!strcmpW(id, str))
405 window = cur_window;
407 SysFreeString(id);
410 if(!window) {
411 hres = DISP_E_MEMBERNOTFOUND;
412 goto cleanup;
414 }else {
415 hres = E_INVALIDARG;
416 goto cleanup;
419 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
420 V_VT(pvarResult) = VT_DISPATCH;
421 V_DISPATCH(pvarResult) = (IDispatch*)window;
423 hres = S_OK;
425 cleanup:
426 nsIDOMWindowCollection_Release(nsFrames);
428 return hres;
431 static HRESULT WINAPI HTMLWindow2_get_length(IHTMLWindow2 *iface, LONG *p)
433 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
434 nsIDOMWindowCollection *nscollection;
435 PRUint32 length;
436 nsresult nsres;
438 TRACE("(%p)->(%p)\n", This, p);
440 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nscollection);
441 if(NS_FAILED(nsres)) {
442 ERR("GetFrames failed: %08x\n", nsres);
443 return E_FAIL;
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;
453 *p = length;
454 return S_OK;
457 static HRESULT WINAPI HTMLWindow2_get_frames(IHTMLWindow2 *iface, IHTMLFramesCollection2 **p)
459 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
460 FIXME("(%p)->(%p): semi-stub\n", This, p);
462 /* FIXME: Should return a separate Window object */
463 *p = (IHTMLFramesCollection2*)&This->IHTMLWindow2_iface;
464 HTMLWindow2_AddRef(iface);
465 return S_OK;
468 static HRESULT WINAPI HTMLWindow2_put_defaultStatus(IHTMLWindow2 *iface, BSTR v)
470 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
471 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
472 return E_NOTIMPL;
475 static HRESULT WINAPI HTMLWindow2_get_defaultStatus(IHTMLWindow2 *iface, BSTR *p)
477 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
478 FIXME("(%p)->(%p)\n", This, p);
479 return E_NOTIMPL;
482 static HRESULT WINAPI HTMLWindow2_put_status(IHTMLWindow2 *iface, BSTR v)
484 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
485 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
486 return E_NOTIMPL;
489 static HRESULT WINAPI HTMLWindow2_get_status(IHTMLWindow2 *iface, BSTR *p)
491 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
492 FIXME("(%p)->(%p)\n", This, p);
493 return E_NOTIMPL;
496 static HRESULT WINAPI HTMLWindow2_setTimeout(IHTMLWindow2 *iface, BSTR expression,
497 LONG msec, VARIANT *language, LONG *timerID)
499 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
500 VARIANT expr_var;
502 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
504 V_VT(&expr_var) = VT_BSTR;
505 V_BSTR(&expr_var) = expression;
507 return IHTMLWindow3_setTimeout(&This->IHTMLWindow3_iface, &expr_var, msec, language, timerID);
510 static HRESULT WINAPI HTMLWindow2_clearTimeout(IHTMLWindow2 *iface, LONG timerID)
512 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
514 TRACE("(%p)->(%d)\n", This, timerID);
516 return clear_task_timer(&This->doc->basedoc, FALSE, timerID);
519 #define MAX_MESSAGE_LEN 2000
521 static HRESULT WINAPI HTMLWindow2_alert(IHTMLWindow2 *iface, BSTR message)
523 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
524 WCHAR title[100], *msg = message;
525 DWORD len;
527 TRACE("(%p)->(%s)\n", This, debugstr_w(message));
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;
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;
544 MessageBoxW(This->doc_obj->hwnd, msg, title, MB_ICONWARNING);
545 if(msg != message)
546 heap_free(msg);
547 return S_OK;
550 static HRESULT WINAPI HTMLWindow2_confirm(IHTMLWindow2 *iface, BSTR message,
551 VARIANT_BOOL *confirmed)
553 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
554 WCHAR wszTitle[100];
556 TRACE("(%p)->(%s %p)\n", This, debugstr_w(message), confirmed);
558 if(!confirmed) return E_INVALIDARG;
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;
567 if(MessageBoxW(This->doc_obj->hwnd, message, wszTitle,
568 MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
569 *confirmed = VARIANT_TRUE;
570 else *confirmed = VARIANT_FALSE;
572 return S_OK;
575 typedef struct
577 BSTR message;
578 BSTR dststr;
579 VARIANT *textdata;
580 }prompt_arg;
582 static INT_PTR CALLBACK prompt_dlgproc(HWND hwnd, UINT msg,
583 WPARAM wparam, LPARAM lparam)
585 switch(msg)
587 case WM_INITDIALOG:
589 prompt_arg *arg = (prompt_arg*)lparam;
590 WCHAR wszTitle[100];
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;
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;
605 case WM_COMMAND:
606 switch(wparam)
608 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
609 EndDialog(hwnd, wparam);
610 return TRUE;
611 case MAKEWPARAM(IDOK, BN_CLICKED):
613 prompt_arg *arg =
614 (prompt_arg*)GetWindowLongPtrW(hwnd, DWLP_USER);
615 HWND hwndPrompt = GetDlgItem(hwnd, ID_PROMPT_EDIT);
616 INT len = GetWindowTextLengthW(hwndPrompt);
618 if(!arg->textdata)
620 EndDialog(hwnd, wparam);
621 return TRUE;
624 V_VT(arg->textdata) = VT_BSTR;
625 if(!len && !arg->dststr)
626 V_BSTR(arg->textdata) = NULL;
627 else
629 V_BSTR(arg->textdata) = SysAllocStringLen(NULL, len);
630 GetWindowTextW(hwndPrompt, V_BSTR(arg->textdata), len+1);
632 EndDialog(hwnd, wparam);
633 return TRUE;
636 return FALSE;
637 case WM_CLOSE:
638 EndDialog(hwnd, IDCANCEL);
639 return TRUE;
640 default:
641 return FALSE;
645 static HRESULT WINAPI HTMLWindow2_prompt(IHTMLWindow2 *iface, BSTR message,
646 BSTR dststr, VARIANT *textdata)
648 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
649 prompt_arg arg;
651 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(message), debugstr_w(dststr), textdata);
653 if(textdata) V_VT(textdata) = VT_NULL;
655 arg.message = message;
656 arg.dststr = dststr;
657 arg.textdata = textdata;
659 DialogBoxParamW(hInst, MAKEINTRESOURCEW(ID_PROMPT_DIALOG),
660 This->doc_obj->hwnd, prompt_dlgproc, (LPARAM)&arg);
661 return S_OK;
664 static HRESULT WINAPI HTMLWindow2_get_Image(IHTMLWindow2 *iface, IHTMLImageElementFactory **p)
666 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
668 TRACE("(%p)->(%p)\n", This, p);
670 if(!This->image_factory)
671 This->image_factory = HTMLImageElementFactory_Create(This);
673 *p = &This->image_factory->IHTMLImageElementFactory_iface;
674 IHTMLImageElementFactory_AddRef(*p);
676 return S_OK;
679 static HRESULT WINAPI HTMLWindow2_get_location(IHTMLWindow2 *iface, IHTMLLocation **p)
681 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
682 HTMLLocation *location;
683 HRESULT hres;
685 TRACE("(%p)->(%p)\n", This, p);
687 hres = get_location(This, &location);
688 if(FAILED(hres))
689 return hres;
691 *p = &location->IHTMLLocation_iface;
692 return S_OK;
695 static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p)
697 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
698 FIXME("(%p)->(%p)\n", This, p);
699 return E_NOTIMPL;
702 static HRESULT WINAPI HTMLWindow2_close(IHTMLWindow2 *iface)
704 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
705 FIXME("(%p)->()\n", This);
706 return E_NOTIMPL;
709 static HRESULT WINAPI HTMLWindow2_put_opener(IHTMLWindow2 *iface, VARIANT v)
711 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
712 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
713 return E_NOTIMPL;
716 static HRESULT WINAPI HTMLWindow2_get_opener(IHTMLWindow2 *iface, VARIANT *p)
718 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
719 FIXME("(%p)->(%p)\n", This, p);
720 return E_NOTIMPL;
723 static HRESULT WINAPI HTMLWindow2_get_navigator(IHTMLWindow2 *iface, IOmNavigator **p)
725 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
727 TRACE("(%p)->(%p)\n", This, p);
729 *p = OmNavigator_Create();
730 return S_OK;
733 static HRESULT WINAPI HTMLWindow2_put_name(IHTMLWindow2 *iface, BSTR v)
735 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
736 nsAString name_str;
737 nsresult nsres;
739 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
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);
747 return S_OK;
750 static HRESULT WINAPI HTMLWindow2_get_name(IHTMLWindow2 *iface, BSTR *p)
752 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
753 nsAString name_str;
754 nsresult nsres;
755 HRESULT hres;
757 TRACE("(%p)->(%p)\n", This, p);
759 nsAString_Init(&name_str, NULL);
760 nsres = nsIDOMWindow_GetName(This->nswindow, &name_str);
761 if(NS_SUCCEEDED(nsres)) {
762 const PRUnichar *name;
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;
772 }else {
773 ERR("GetName failed: %08x\n", nsres);
774 hres = E_FAIL;
776 nsAString_Finish(&name_str);
778 return hres;
781 static HRESULT WINAPI HTMLWindow2_get_parent(IHTMLWindow2 *iface, IHTMLWindow2 **p)
783 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
784 TRACE("(%p)->(%p)\n", This, p);
786 if(This->parent) {
787 *p = &This->parent->IHTMLWindow2_iface;
788 IHTMLWindow2_AddRef(*p);
789 }else
790 *p = NULL;
792 return S_OK;
795 static HRESULT WINAPI HTMLWindow2_open(IHTMLWindow2 *iface, BSTR url, BSTR name,
796 BSTR features, VARIANT_BOOL replace, IHTMLWindow2 **pomWindowResult)
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;
804 static HRESULT WINAPI HTMLWindow2_get_self(IHTMLWindow2 *iface, IHTMLWindow2 **p)
806 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
808 TRACE("(%p)->(%p)\n", This, p);
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;
816 static HRESULT WINAPI HTMLWindow2_get_top(IHTMLWindow2 *iface, IHTMLWindow2 **p)
818 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
819 HTMLWindow *curr;
820 TRACE("(%p)->(%p)\n", This, p);
822 curr = This;
823 while(curr->parent)
824 curr = curr->parent;
825 *p = &curr->IHTMLWindow2_iface;
826 IHTMLWindow2_AddRef(*p);
828 return S_OK;
831 static HRESULT WINAPI HTMLWindow2_get_window(IHTMLWindow2 *iface, IHTMLWindow2 **p)
833 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
835 TRACE("(%p)->(%p)\n", This, p);
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;
843 static HRESULT WINAPI HTMLWindow2_navigate(IHTMLWindow2 *iface, BSTR url)
845 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
846 FIXME("(%p)->(%s)\n", This, debugstr_w(url));
847 return E_NOTIMPL;
850 static HRESULT WINAPI HTMLWindow2_put_onfocus(IHTMLWindow2 *iface, VARIANT v)
852 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
853 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
854 return E_NOTIMPL;
857 static HRESULT WINAPI HTMLWindow2_get_onfocus(IHTMLWindow2 *iface, VARIANT *p)
859 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
860 FIXME("(%p)->(%p)\n", This, p);
861 return E_NOTIMPL;
864 static HRESULT WINAPI HTMLWindow2_put_onblur(IHTMLWindow2 *iface, VARIANT v)
866 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
867 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
868 return E_NOTIMPL;
871 static HRESULT WINAPI HTMLWindow2_get_onblur(IHTMLWindow2 *iface, VARIANT *p)
873 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
874 FIXME("(%p)->(%p)\n", This, p);
875 return E_NOTIMPL;
878 static HRESULT WINAPI HTMLWindow2_put_onload(IHTMLWindow2 *iface, VARIANT v)
880 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
882 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
884 return set_window_event(This, EVENTID_LOAD, &v);
887 static HRESULT WINAPI HTMLWindow2_get_onload(IHTMLWindow2 *iface, VARIANT *p)
889 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
891 TRACE("(%p)->(%p)\n", This, p);
893 return get_window_event(This, EVENTID_LOAD, p);
896 static HRESULT WINAPI HTMLWindow2_put_onbeforeunload(IHTMLWindow2 *iface, VARIANT v)
898 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
900 TRACE("(%p)->(v(%d))\n", This, V_VT(&v));
902 return set_window_event(This, EVENTID_BEFOREUNLOAD, &v);
905 static HRESULT WINAPI HTMLWindow2_get_onbeforeunload(IHTMLWindow2 *iface, VARIANT *p)
907 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
909 TRACE("(%p)->(%p)\n", This, p);
911 return get_window_event(This, EVENTID_BEFOREUNLOAD, p);
914 static HRESULT WINAPI HTMLWindow2_put_onunload(IHTMLWindow2 *iface, VARIANT v)
916 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
917 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
918 return E_NOTIMPL;
921 static HRESULT WINAPI HTMLWindow2_get_onunload(IHTMLWindow2 *iface, VARIANT *p)
923 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
924 FIXME("(%p)->(%p)\n", This, p);
925 return E_NOTIMPL;
928 static HRESULT WINAPI HTMLWindow2_put_onhelp(IHTMLWindow2 *iface, VARIANT v)
930 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
931 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
932 return E_NOTIMPL;
935 static HRESULT WINAPI HTMLWindow2_get_onhelp(IHTMLWindow2 *iface, VARIANT *p)
937 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
938 FIXME("(%p)->(%p)\n", This, p);
939 return E_NOTIMPL;
942 static HRESULT WINAPI HTMLWindow2_put_onerror(IHTMLWindow2 *iface, VARIANT v)
944 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
945 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
946 return E_NOTIMPL;
949 static HRESULT WINAPI HTMLWindow2_get_onerror(IHTMLWindow2 *iface, VARIANT *p)
951 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
952 FIXME("(%p)->(%p)\n", This, p);
953 return E_NOTIMPL;
956 static HRESULT WINAPI HTMLWindow2_put_onresize(IHTMLWindow2 *iface, VARIANT v)
958 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
960 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
962 return set_window_event(This, EVENTID_RESIZE, &v);
965 static HRESULT WINAPI HTMLWindow2_get_onresize(IHTMLWindow2 *iface, VARIANT *p)
967 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
969 TRACE("(%p)->(%p)\n", This, p);
971 return get_window_event(This, EVENTID_RESIZE, p);
974 static HRESULT WINAPI HTMLWindow2_put_onscroll(IHTMLWindow2 *iface, VARIANT v)
976 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
977 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
978 return E_NOTIMPL;
981 static HRESULT WINAPI HTMLWindow2_get_onscroll(IHTMLWindow2 *iface, VARIANT *p)
983 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
984 FIXME("(%p)->(%p)\n", This, p);
985 return E_NOTIMPL;
988 static HRESULT WINAPI HTMLWindow2_get_document(IHTMLWindow2 *iface, IHTMLDocument2 **p)
990 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
992 TRACE("(%p)->(%p)\n", This, p);
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;
1002 return S_OK;
1005 static HRESULT WINAPI HTMLWindow2_get_event(IHTMLWindow2 *iface, IHTMLEventObj **p)
1007 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1009 TRACE("(%p)->(%p)\n", This, p);
1011 if(This->event)
1012 IHTMLEventObj_AddRef(This->event);
1013 *p = This->event;
1014 return S_OK;
1017 static HRESULT WINAPI HTMLWindow2_get__newEnum(IHTMLWindow2 *iface, IUnknown **p)
1019 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1020 FIXME("(%p)->(%p)\n", This, p);
1021 return E_NOTIMPL;
1024 static HRESULT WINAPI HTMLWindow2_showModalDialog(IHTMLWindow2 *iface, BSTR dialog,
1025 VARIANT *varArgIn, VARIANT *varOptions, VARIANT *varArgOut)
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;
1032 static HRESULT WINAPI HTMLWindow2_showHelp(IHTMLWindow2 *iface, BSTR helpURL, VARIANT helpArg,
1033 BSTR features)
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;
1040 static HRESULT WINAPI HTMLWindow2_get_screen(IHTMLWindow2 *iface, IHTMLScreen **p)
1042 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1044 TRACE("(%p)->(%p)\n", This, p);
1046 if(!This->screen) {
1047 HRESULT hres;
1049 hres = HTMLScreen_Create(&This->screen);
1050 if(FAILED(hres))
1051 return hres;
1054 *p = This->screen;
1055 IHTMLScreen_AddRef(This->screen);
1056 return S_OK;
1059 static HRESULT WINAPI HTMLWindow2_get_Option(IHTMLWindow2 *iface, IHTMLOptionElementFactory **p)
1061 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1063 TRACE("(%p)->(%p)\n", This, p);
1065 if(!This->option_factory)
1066 This->option_factory = HTMLOptionElementFactory_Create(This);
1068 *p = &This->option_factory->IHTMLOptionElementFactory_iface;
1069 IHTMLOptionElementFactory_AddRef(*p);
1071 return S_OK;
1074 static HRESULT WINAPI HTMLWindow2_focus(IHTMLWindow2 *iface)
1076 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1078 TRACE("(%p)->()\n", This);
1080 if(This->doc_obj)
1081 SetFocus(This->doc_obj->hwnd);
1082 return S_OK;
1085 static HRESULT WINAPI HTMLWindow2_get_closed(IHTMLWindow2 *iface, VARIANT_BOOL *p)
1087 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1088 FIXME("(%p)->(%p)\n", This, p);
1089 return E_NOTIMPL;
1092 static HRESULT WINAPI HTMLWindow2_blur(IHTMLWindow2 *iface)
1094 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1095 FIXME("(%p)->()\n", This);
1096 return E_NOTIMPL;
1099 static HRESULT WINAPI HTMLWindow2_scroll(IHTMLWindow2 *iface, LONG x, LONG y)
1101 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1102 FIXME("(%p)->(%d %d)\n", This, x, y);
1103 return E_NOTIMPL;
1106 static HRESULT WINAPI HTMLWindow2_get_clientInformation(IHTMLWindow2 *iface, IOmNavigator **p)
1108 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1109 FIXME("(%p)->(%p)\n", This, p);
1110 return E_NOTIMPL;
1113 static HRESULT WINAPI HTMLWindow2_setInterval(IHTMLWindow2 *iface, BSTR expression,
1114 LONG msec, VARIANT *language, LONG *timerID)
1116 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1117 VARIANT expr;
1119 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
1121 V_VT(&expr) = VT_BSTR;
1122 V_BSTR(&expr) = expression;
1123 return IHTMLWindow3_setInterval(&This->IHTMLWindow3_iface, &expr, msec, language, timerID);
1126 static HRESULT WINAPI HTMLWindow2_clearInterval(IHTMLWindow2 *iface, LONG timerID)
1128 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1130 TRACE("(%p)->(%d)\n", This, timerID);
1132 return clear_task_timer(&This->doc->basedoc, TRUE, timerID);
1135 static HRESULT WINAPI HTMLWindow2_put_offscreenBuffering(IHTMLWindow2 *iface, VARIANT v)
1137 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1138 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
1139 return E_NOTIMPL;
1142 static HRESULT WINAPI HTMLWindow2_get_offscreenBuffering(IHTMLWindow2 *iface, VARIANT *p)
1144 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1145 FIXME("(%p)->(%p)\n", This, p);
1146 return E_NOTIMPL;
1149 static HRESULT WINAPI HTMLWindow2_execScript(IHTMLWindow2 *iface, BSTR scode, BSTR language,
1150 VARIANT *pvarRet)
1152 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1154 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(scode), debugstr_w(language), pvarRet);
1156 return exec_script(This, scode, language, pvarRet);
1159 static HRESULT WINAPI HTMLWindow2_toString(IHTMLWindow2 *iface, BSTR *String)
1161 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1163 static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
1165 TRACE("(%p)->(%p)\n", This, String);
1167 if(!String)
1168 return E_INVALIDARG;
1170 *String = SysAllocString(objectW);
1171 return *String ? S_OK : E_OUTOFMEMORY;
1174 static HRESULT WINAPI HTMLWindow2_scrollBy(IHTMLWindow2 *iface, LONG x, LONG y)
1176 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1177 nsresult nsres;
1179 TRACE("(%p)->(%d %d)\n", This, x, y);
1181 nsres = nsIDOMWindow_ScrollBy(This->nswindow, x, y);
1182 if(NS_FAILED(nsres))
1183 ERR("ScrollBy failed: %08x\n", nsres);
1185 return S_OK;
1188 static HRESULT WINAPI HTMLWindow2_scrollTo(IHTMLWindow2 *iface, LONG x, LONG y)
1190 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1191 nsresult nsres;
1193 TRACE("(%p)->(%d %d)\n", This, x, y);
1195 nsres = nsIDOMWindow_ScrollTo(This->nswindow, x, y);
1196 if(NS_FAILED(nsres))
1197 ERR("ScrollTo failed: %08x\n", nsres);
1199 return S_OK;
1202 static HRESULT WINAPI HTMLWindow2_moveTo(IHTMLWindow2 *iface, LONG x, LONG y)
1204 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1205 FIXME("(%p)->(%d %d)\n", This, x, y);
1206 return E_NOTIMPL;
1209 static HRESULT WINAPI HTMLWindow2_moveBy(IHTMLWindow2 *iface, LONG x, LONG y)
1211 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1212 FIXME("(%p)->(%d %d)\n", This, x, y);
1213 return E_NOTIMPL;
1216 static HRESULT WINAPI HTMLWindow2_resizeTo(IHTMLWindow2 *iface, LONG x, LONG y)
1218 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1219 FIXME("(%p)->(%d %d)\n", This, x, y);
1220 return E_NOTIMPL;
1223 static HRESULT WINAPI HTMLWindow2_resizeBy(IHTMLWindow2 *iface, LONG x, LONG y)
1225 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1226 FIXME("(%p)->(%d %d)\n", This, x, y);
1227 return E_NOTIMPL;
1230 static HRESULT WINAPI HTMLWindow2_get_external(IHTMLWindow2 *iface, IDispatch **p)
1232 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1234 TRACE("(%p)->(%p)\n", This, p);
1236 *p = NULL;
1238 if(!This->doc_obj->hostui)
1239 return S_OK;
1241 return IDocHostUIHandler_GetExternal(This->doc_obj->hostui, p);
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
1324 static inline HTMLWindow *impl_from_IHTMLWindow3(IHTMLWindow3 *iface)
1326 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow3_iface);
1329 static HRESULT WINAPI HTMLWindow3_QueryInterface(IHTMLWindow3 *iface, REFIID riid, void **ppv)
1331 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1333 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1336 static ULONG WINAPI HTMLWindow3_AddRef(IHTMLWindow3 *iface)
1338 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1340 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1343 static ULONG WINAPI HTMLWindow3_Release(IHTMLWindow3 *iface)
1345 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1347 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1350 static HRESULT WINAPI HTMLWindow3_GetTypeInfoCount(IHTMLWindow3 *iface, UINT *pctinfo)
1352 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1354 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1357 static HRESULT WINAPI HTMLWindow3_GetTypeInfo(IHTMLWindow3 *iface, UINT iTInfo,
1358 LCID lcid, ITypeInfo **ppTInfo)
1360 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1362 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1365 static HRESULT WINAPI HTMLWindow3_GetIDsOfNames(IHTMLWindow3 *iface, REFIID riid,
1366 LPOLESTR *rgszNames, UINT cNames,
1367 LCID lcid, DISPID *rgDispId)
1369 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1371 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1372 rgDispId);
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)
1379 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1381 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1382 pDispParams, pVarResult, pExcepInfo, puArgErr);
1385 static HRESULT WINAPI HTMLWindow3_get_screenLeft(IHTMLWindow3 *iface, LONG *p)
1387 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1388 FIXME("(%p)->(%p)\n", This, p);
1389 return E_NOTIMPL;
1392 static HRESULT WINAPI HTMLWindow3_get_screenTop(IHTMLWindow3 *iface, LONG *p)
1394 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1395 FIXME("(%p)->(%p)\n", This, p);
1396 return E_NOTIMPL;
1399 static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp, VARIANT_BOOL *pfResult)
1401 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1403 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
1405 if(!This->doc) {
1406 FIXME("No document\n");
1407 return E_FAIL;
1410 return attach_event(&This->doc->body_event_target, NULL, &This->doc->basedoc, event, pDisp, pfResult);
1413 static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
1415 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1416 FIXME("(%p)->()\n", This);
1417 return E_NOTIMPL;
1420 static HRESULT window_set_timer(HTMLWindow *This, VARIANT *expr, LONG msec, VARIANT *language,
1421 BOOL interval, LONG *timer_id)
1423 IDispatch *disp = NULL;
1425 switch(V_VT(expr)) {
1426 case VT_DISPATCH:
1427 disp = V_DISPATCH(expr);
1428 IDispatch_AddRef(disp);
1429 break;
1431 case VT_BSTR:
1432 disp = script_parse_event(This, V_BSTR(expr));
1433 break;
1435 default:
1436 FIXME("unimplemented vt=%d\n", V_VT(expr));
1437 return E_NOTIMPL;
1440 if(!disp)
1441 return E_FAIL;
1443 *timer_id = set_task_timer(&This->doc->basedoc, msec, interval, disp);
1444 IDispatch_Release(disp);
1446 return S_OK;
1449 static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1450 VARIANT *language, LONG *timerID)
1452 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1454 TRACE("(%p)->(%p(%d) %d %p %p)\n", This, expression, V_VT(expression), msec, language, timerID);
1456 return window_set_timer(This, expression, msec, language, FALSE, timerID);
1459 static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1460 VARIANT *language, LONG *timerID)
1462 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1464 TRACE("(%p)->(%p %d %p %p)\n", This, expression, msec, language, timerID);
1466 return window_set_timer(This, expression, msec, language, TRUE, timerID);
1469 static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)
1471 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1472 FIXME("(%p)\n", This);
1473 return E_NOTIMPL;
1476 static HRESULT WINAPI HTMLWindow3_put_onbeforeprint(IHTMLWindow3 *iface, VARIANT v)
1478 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1479 FIXME("(%p)->()\n", This);
1480 return E_NOTIMPL;
1483 static HRESULT WINAPI HTMLWindow3_get_onbeforeprint(IHTMLWindow3 *iface, VARIANT *p)
1485 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1486 FIXME("(%p)->(%p)\n", This, p);
1487 return E_NOTIMPL;
1490 static HRESULT WINAPI HTMLWindow3_put_onafterprint(IHTMLWindow3 *iface, VARIANT v)
1492 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1493 FIXME("(%p)->()\n", This);
1494 return E_NOTIMPL;
1497 static HRESULT WINAPI HTMLWindow3_get_onafterprint(IHTMLWindow3 *iface, VARIANT *p)
1499 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1500 FIXME("(%p)->(%p)\n", This, p);
1501 return E_NOTIMPL;
1504 static HRESULT WINAPI HTMLWindow3_get_clipboardData(IHTMLWindow3 *iface, IHTMLDataTransfer **p)
1506 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1507 FIXME("(%p)->(%p)\n", This, p);
1508 return E_NOTIMPL;
1511 static HRESULT WINAPI HTMLWindow3_showModelessDialog(IHTMLWindow3 *iface, BSTR url,
1512 VARIANT *varArgIn, VARIANT *options, IHTMLWindow2 **pDialog)
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;
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
1542 static inline HTMLWindow *impl_from_IHTMLWindow4(IHTMLWindow4 *iface)
1544 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow4_iface);
1547 static HRESULT WINAPI HTMLWindow4_QueryInterface(IHTMLWindow4 *iface, REFIID riid, void **ppv)
1549 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1551 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1554 static ULONG WINAPI HTMLWindow4_AddRef(IHTMLWindow4 *iface)
1556 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1558 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1561 static ULONG WINAPI HTMLWindow4_Release(IHTMLWindow4 *iface)
1563 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1565 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1568 static HRESULT WINAPI HTMLWindow4_GetTypeInfoCount(IHTMLWindow4 *iface, UINT *pctinfo)
1570 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1572 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1575 static HRESULT WINAPI HTMLWindow4_GetTypeInfo(IHTMLWindow4 *iface, UINT iTInfo,
1576 LCID lcid, ITypeInfo **ppTInfo)
1578 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1580 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1583 static HRESULT WINAPI HTMLWindow4_GetIDsOfNames(IHTMLWindow4 *iface, REFIID riid,
1584 LPOLESTR *rgszNames, UINT cNames,
1585 LCID lcid, DISPID *rgDispId)
1587 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1589 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1590 rgDispId);
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)
1597 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1599 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1600 pDispParams, pVarResult, pExcepInfo, puArgErr);
1603 static HRESULT WINAPI HTMLWindow4_createPopup(IHTMLWindow4 *iface, VARIANT *varArgIn,
1604 IDispatch **ppPopup)
1606 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1607 FIXME("(%p)->(%p %p)\n", This, varArgIn, ppPopup);
1608 return E_NOTIMPL;
1611 static HRESULT WINAPI HTMLWindow4_get_frameElement(IHTMLWindow4 *iface, IHTMLFrameBase **p)
1613 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1614 TRACE("(%p)->(%p)\n", This, p);
1616 if(This->frame_element) {
1617 *p = &This->frame_element->IHTMLFrameBase_iface;
1618 IHTMLFrameBase_AddRef(*p);
1619 }else
1620 *p = NULL;
1622 return S_OK;
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
1637 static inline HTMLWindow *impl_from_IHTMLPrivateWindow(IHTMLPrivateWindow *iface)
1639 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLPrivateWindow_iface);
1642 static HRESULT WINAPI HTMLPrivateWindow_QueryInterface(IHTMLPrivateWindow *iface, REFIID riid, void **ppv)
1644 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1646 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1649 static ULONG WINAPI HTMLPrivateWindow_AddRef(IHTMLPrivateWindow *iface)
1651 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1653 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1656 static ULONG WINAPI HTMLPrivateWindow_Release(IHTMLPrivateWindow *iface)
1658 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1660 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
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)
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;
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);
1678 new_url = url;
1679 if(This->doc_obj->hostui) {
1680 OLECHAR *translated_url = NULL;
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);
1689 if(This->doc_obj->client) {
1690 IOleCommandTarget *cmdtrg;
1692 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
1693 if(SUCCEEDED(hres)) {
1694 VARIANT in, out;
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);
1707 /* FIXME: Why not set_ready_state? */
1708 This->readystate = READYSTATE_UNINITIALIZED;
1710 hres = CreateURLMoniker(NULL, new_url, &mon);
1711 if(new_url != url)
1712 SysFreeString(new_url);
1713 if(FAILED(hres))
1714 return hres;
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;
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;
1727 headers = V_BSTR(headers_var);
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;
1738 hres = set_moniker(&This->doc_obj->basedoc, mon, NULL, bsc, TRUE);
1739 if(SUCCEEDED(hres))
1740 hres = async_start_doc_binding(This, bsc);
1742 IUnknown_Release((IUnknown*)bsc);
1743 IMoniker_Release(mon);
1744 return hres;
1747 static HRESULT WINAPI HTMLPrivateWindow_GetPendingUrl(IHTMLPrivateWindow *iface, BSTR *url)
1749 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1750 FIXME("(%p)->(%p)\n", This, url);
1751 return E_NOTIMPL;
1754 static HRESULT WINAPI HTMLPrivateWindow_SetPICSTarget(IHTMLPrivateWindow *iface, IOleCommandTarget *cmdtrg)
1756 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1757 FIXME("(%p)->(%p)\n", This, cmdtrg);
1758 return E_NOTIMPL;
1761 static HRESULT WINAPI HTMLPrivateWindow_PICSComplete(IHTMLPrivateWindow *iface, int arg)
1763 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1764 FIXME("(%p)->(%x)\n", This, arg);
1765 return E_NOTIMPL;
1768 static HRESULT WINAPI HTMLPrivateWindow_FindWindowByName(IHTMLPrivateWindow *iface, LPCWSTR name, IHTMLWindow2 **ret)
1770 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1771 FIXME("(%p)->(%s %p)\n", This, debugstr_w(name), ret);
1772 return E_NOTIMPL;
1775 static HRESULT WINAPI HTMLPrivateWindow_GetAddressBar(IHTMLPrivateWindow *iface, BSTR *url)
1777 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1778 FIXME("(%p)->(%p)\n", This, url);
1779 return E_NOTIMPL;
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
1794 static inline HTMLWindow *impl_from_IDispatchEx(IDispatchEx *iface)
1796 return CONTAINING_RECORD(iface, HTMLWindow, IDispatchEx_iface);
1799 static HRESULT WINAPI WindowDispEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1801 HTMLWindow *This = impl_from_IDispatchEx(iface);
1803 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1806 static ULONG WINAPI WindowDispEx_AddRef(IDispatchEx *iface)
1808 HTMLWindow *This = impl_from_IDispatchEx(iface);
1810 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1813 static ULONG WINAPI WindowDispEx_Release(IDispatchEx *iface)
1815 HTMLWindow *This = impl_from_IDispatchEx(iface);
1817 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1820 static HRESULT WINAPI WindowDispEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1822 HTMLWindow *This = impl_from_IDispatchEx(iface);
1824 TRACE("(%p)->(%p)\n", This, pctinfo);
1826 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
1829 static HRESULT WINAPI WindowDispEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1830 LCID lcid, ITypeInfo **ppTInfo)
1832 HTMLWindow *This = impl_from_IDispatchEx(iface);
1834 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1836 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1839 static HRESULT WINAPI WindowDispEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1840 LPOLESTR *rgszNames, UINT cNames,
1841 LCID lcid, DISPID *rgDispId)
1843 HTMLWindow *This = impl_from_IDispatchEx(iface);
1844 UINT i;
1845 HRESULT hres;
1847 WARN("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1848 lcid, rgDispId);
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;
1857 return S_OK;
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)
1864 HTMLWindow *This = impl_from_IDispatchEx(iface);
1866 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1867 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1869 /* FIXME: Use script dispatch */
1871 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1872 pDispParams, pVarResult, pExcepInfo, puArgErr);
1875 static global_prop_t *alloc_global_prop(HTMLWindow *This, global_prop_type_t type, BSTR name)
1877 if(This->global_prop_cnt == This->global_prop_size) {
1878 global_prop_t *new_props;
1879 DWORD new_size;
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));
1888 if(!new_props)
1889 return NULL;
1890 This->global_props = new_props;
1891 This->global_prop_size = new_size;
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;
1898 This->global_props[This->global_prop_cnt].type = type;
1899 return This->global_props + This->global_prop_cnt++;
1902 static inline DWORD prop_to_dispid(HTMLWindow *This, global_prop_t *prop)
1904 return MSHTML_DISPID_CUSTOM_MIN + (prop-This->global_props);
1907 HRESULT search_window_props(HTMLWindow *This, BSTR bstrName, DWORD grfdex, DISPID *pid)
1909 DWORD i;
1910 ScriptHost *script_host;
1911 DISPID id;
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;
1921 if(find_global_prop(This, bstrName, grfdex, &script_host, &id)) {
1922 global_prop_t *prop;
1924 prop = alloc_global_prop(This, GLOBAL_SCRIPTVAR, bstrName);
1925 if(!prop)
1926 return E_OUTOFMEMORY;
1928 prop->script_host = script_host;
1929 prop->id = id;
1931 *pid = prop_to_dispid(This, prop);
1932 return S_OK;
1935 return DISP_E_UNKNOWNNAME;
1938 static HRESULT WINAPI WindowDispEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1940 HTMLWindow *This = impl_from_IDispatchEx(iface);
1941 HRESULT hres;
1943 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
1945 hres = search_window_props(This, bstrName, grfdex, pid);
1946 if(hres != DISP_E_UNKNOWNNAME)
1947 return hres;
1949 hres = IDispatchEx_GetDispID(&This->dispex.IDispatchEx_iface, bstrName, grfdex, pid);
1950 if(hres != DISP_E_UNKNOWNNAME)
1951 return hres;
1953 if(This->doc) {
1954 global_prop_t *prop;
1955 IHTMLElement *elem;
1957 hres = IHTMLDocument3_getElementById(&This->doc->basedoc.IHTMLDocument3_iface,
1958 bstrName, &elem);
1959 if(SUCCEEDED(hres) && elem) {
1960 IHTMLElement_Release(elem);
1962 prop = alloc_global_prop(This, GLOBAL_ELEMENTVAR, bstrName);
1963 if(!prop)
1964 return E_OUTOFMEMORY;
1966 *pid = prop_to_dispid(This, prop);
1967 return S_OK;
1971 return DISP_E_UNKNOWNNAME;
1974 static HRESULT WINAPI WindowDispEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1975 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1977 HTMLWindow *This = impl_from_IDispatchEx(iface);
1979 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1981 if(id == DISPID_IHTMLWINDOW2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT)) {
1982 HTMLLocation *location;
1983 HRESULT hres;
1985 TRACE("forwarding to location.href\n");
1987 hres = get_location(This, &location);
1988 if(FAILED(hres))
1989 return hres;
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;
1997 return IDispatchEx_InvokeEx(&This->dispex.IDispatchEx_iface, id, lcid, wFlags, pdp, pvarRes,
1998 pei, pspCaller);
2001 static HRESULT WINAPI WindowDispEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
2003 HTMLWindow *This = impl_from_IDispatchEx(iface);
2005 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
2007 return IDispatchEx_DeleteMemberByName(&This->dispex.IDispatchEx_iface, bstrName, grfdex);
2010 static HRESULT WINAPI WindowDispEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
2012 HTMLWindow *This = impl_from_IDispatchEx(iface);
2014 TRACE("(%p)->(%x)\n", This, id);
2016 return IDispatchEx_DeleteMemberByDispID(&This->dispex.IDispatchEx_iface, id);
2019 static HRESULT WINAPI WindowDispEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
2021 HTMLWindow *This = impl_from_IDispatchEx(iface);
2023 TRACE("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
2025 return IDispatchEx_GetMemberProperties(&This->dispex.IDispatchEx_iface, id, grfdexFetch,
2026 pgrfdex);
2029 static HRESULT WINAPI WindowDispEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
2031 HTMLWindow *This = impl_from_IDispatchEx(iface);
2033 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
2035 return IDispatchEx_GetMemberName(&This->dispex.IDispatchEx_iface, id, pbstrName);
2038 static HRESULT WINAPI WindowDispEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
2040 HTMLWindow *This = impl_from_IDispatchEx(iface);
2042 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
2044 return IDispatchEx_GetNextDispID(&This->dispex.IDispatchEx_iface, grfdex, id, pid);
2047 static HRESULT WINAPI WindowDispEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
2049 HTMLWindow *This = impl_from_IDispatchEx(iface);
2051 TRACE("(%p)->(%p)\n", This, ppunk);
2053 *ppunk = NULL;
2054 return S_OK;
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
2075 static inline HTMLWindow *impl_from_IServiceProvider(IServiceProvider *iface)
2077 return CONTAINING_RECORD(iface, HTMLWindow, IServiceProvider_iface);
2080 static HRESULT WINAPI HTMLWindowSP_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
2082 HTMLWindow *This = impl_from_IServiceProvider(iface);
2083 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2086 static ULONG WINAPI HTMLWindowSP_AddRef(IServiceProvider *iface)
2088 HTMLWindow *This = impl_from_IServiceProvider(iface);
2089 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2092 static ULONG WINAPI HTMLWindowSP_Release(IServiceProvider *iface)
2094 HTMLWindow *This = impl_from_IServiceProvider(iface);
2095 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2098 static HRESULT WINAPI HTMLWindowSP_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
2100 HTMLWindow *This = impl_from_IServiceProvider(iface);
2102 if(IsEqualGUID(guidService, &IID_IHTMLWindow2)) {
2103 TRACE("IID_IHTMLWindow2\n");
2104 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2107 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
2109 if(!This->doc_obj)
2110 return E_NOINTERFACE;
2112 return IServiceProvider_QueryService(&This->doc_obj->basedoc.IServiceProvider_iface,
2113 guidService, riid, ppv);
2116 static const IServiceProviderVtbl ServiceProviderVtbl = {
2117 HTMLWindowSP_QueryInterface,
2118 HTMLWindowSP_AddRef,
2119 HTMLWindowSP_Release,
2120 HTMLWindowSP_QueryService
2123 static inline HTMLWindow *impl_from_DispatchEx(DispatchEx *iface)
2125 return CONTAINING_RECORD(iface, HTMLWindow, dispex);
2128 static HRESULT HTMLWindow_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2129 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2131 HTMLWindow *This = impl_from_DispatchEx(dispex);
2132 global_prop_t *prop;
2133 DWORD idx;
2134 HRESULT hres;
2136 idx = id - MSHTML_DISPID_CUSTOM_MIN;
2137 if(idx >= This->global_prop_cnt)
2138 return DISP_E_MEMBERNOTFOUND;
2140 prop = This->global_props+idx;
2142 switch(prop->type) {
2143 case GLOBAL_SCRIPTVAR: {
2144 IDispatchEx *dispex;
2145 IDispatch *disp;
2147 disp = get_script_disp(prop->script_host);
2148 if(!disp)
2149 return E_UNEXPECTED;
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");
2163 IDispatch_Release(disp);
2164 break;
2166 case GLOBAL_ELEMENTVAR: {
2167 IHTMLElement *elem;
2169 hres = IHTMLDocument3_getElementById(&This->doc->basedoc.IHTMLDocument3_iface,
2170 prop->name, &elem);
2171 if(FAILED(hres))
2172 return hres;
2174 if(!elem)
2175 return DISP_E_MEMBERNOTFOUND;
2177 V_VT(res) = VT_DISPATCH;
2178 V_DISPATCH(res) = (IDispatch*)elem;
2179 break;
2181 default:
2182 ERR("invalid type %d\n", prop->type);
2183 hres = DISP_E_MEMBERNOTFOUND;
2186 return hres;
2190 static const dispex_static_data_vtbl_t HTMLWindow_dispex_vtbl = {
2191 NULL,
2192 NULL,
2193 HTMLWindow_invoke
2196 static const tid_t HTMLWindow_iface_tids[] = {
2197 IHTMLWindow2_tid,
2198 IHTMLWindow3_tid,
2199 IHTMLWindow4_tid,
2203 static dispex_static_data_t HTMLWindow_dispex = {
2204 &HTMLWindow_dispex_vtbl,
2205 DispHTMLWindow2_tid,
2206 NULL,
2207 HTMLWindow_iface_tids
2210 HRESULT HTMLWindow_Create(HTMLDocumentObj *doc_obj, nsIDOMWindow *nswindow, HTMLWindow *parent, HTMLWindow **ret)
2212 HTMLWindow *window;
2214 window = heap_alloc_zero(sizeof(HTMLWindow));
2215 if(!window)
2216 return E_OUTOFMEMORY;
2218 window->window_ref = heap_alloc(sizeof(windowref_t));
2219 if(!window->window_ref) {
2220 heap_free(window);
2221 return E_OUTOFMEMORY;
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;
2233 window->window_ref->window = window;
2234 window->window_ref->ref = 1;
2236 init_dispex(&window->dispex, (IUnknown*)&window->IHTMLWindow2_iface, &HTMLWindow_dispex);
2238 if(nswindow) {
2239 nsIDOMWindow_AddRef(nswindow);
2240 window->nswindow = nswindow;
2243 window->scriptmode = parent ? parent->scriptmode : SCRIPTMODE_GECKO;
2244 window->readystate = READYSTATE_UNINITIALIZED;
2245 list_init(&window->script_hosts);
2247 window->task_magic = get_task_target_magic();
2248 update_window_doc(window);
2250 list_init(&window->children);
2251 list_add_head(&window_list, &window->entry);
2253 if(parent) {
2254 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
2256 window->parent = parent;
2257 list_add_tail(&parent->children, &window->sibling_entry);
2260 *ret = window;
2261 return S_OK;
2264 void update_window_doc(HTMLWindow *window)
2266 nsIDOMHTMLDocument *nshtmldoc;
2267 nsIDOMDocument *nsdoc;
2268 nsresult nsres;
2270 nsres = nsIDOMWindow_GetDocument(window->nswindow, &nsdoc);
2271 if(NS_FAILED(nsres) || !nsdoc) {
2272 ERR("GetDocument failed: %08x\n", nsres);
2273 return;
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;
2283 if(!window->doc || window->doc->nsdoc != nshtmldoc) {
2284 HTMLDocumentNode *doc;
2285 HRESULT hres;
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);
2296 nsIDOMHTMLDocument_Release(nshtmldoc);
2299 HTMLWindow *nswindow_to_window(const nsIDOMWindow *nswindow)
2301 HTMLWindow *iter;
2303 LIST_FOR_EACH_ENTRY(iter, &window_list, HTMLWindow, entry) {
2304 if(iter->nswindow == nswindow)
2305 return iter;
2308 return NULL;