kernel32: Add proper English messages for all error codes.
[wine.git] / dlls / mshtml / htmlwindow.c
blob3cbffea19320a095957396eb451adc456183e3f1
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);
1077 FIXME("(%p)->()\n", This);
1078 return E_NOTIMPL;
1081 static HRESULT WINAPI HTMLWindow2_get_closed(IHTMLWindow2 *iface, VARIANT_BOOL *p)
1083 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1084 FIXME("(%p)->(%p)\n", This, p);
1085 return E_NOTIMPL;
1088 static HRESULT WINAPI HTMLWindow2_blur(IHTMLWindow2 *iface)
1090 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1091 FIXME("(%p)->()\n", This);
1092 return E_NOTIMPL;
1095 static HRESULT WINAPI HTMLWindow2_scroll(IHTMLWindow2 *iface, LONG x, LONG y)
1097 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1098 FIXME("(%p)->(%d %d)\n", This, x, y);
1099 return E_NOTIMPL;
1102 static HRESULT WINAPI HTMLWindow2_get_clientInformation(IHTMLWindow2 *iface, IOmNavigator **p)
1104 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1105 FIXME("(%p)->(%p)\n", This, p);
1106 return E_NOTIMPL;
1109 static HRESULT WINAPI HTMLWindow2_setInterval(IHTMLWindow2 *iface, BSTR expression,
1110 LONG msec, VARIANT *language, LONG *timerID)
1112 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1113 VARIANT expr;
1115 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
1117 V_VT(&expr) = VT_BSTR;
1118 V_BSTR(&expr) = expression;
1119 return IHTMLWindow3_setInterval(&This->IHTMLWindow3_iface, &expr, msec, language, timerID);
1122 static HRESULT WINAPI HTMLWindow2_clearInterval(IHTMLWindow2 *iface, LONG timerID)
1124 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1126 TRACE("(%p)->(%d)\n", This, timerID);
1128 return clear_task_timer(&This->doc->basedoc, TRUE, timerID);
1131 static HRESULT WINAPI HTMLWindow2_put_offscreenBuffering(IHTMLWindow2 *iface, VARIANT v)
1133 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1134 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
1135 return E_NOTIMPL;
1138 static HRESULT WINAPI HTMLWindow2_get_offscreenBuffering(IHTMLWindow2 *iface, VARIANT *p)
1140 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1141 FIXME("(%p)->(%p)\n", This, p);
1142 return E_NOTIMPL;
1145 static HRESULT WINAPI HTMLWindow2_execScript(IHTMLWindow2 *iface, BSTR scode, BSTR language,
1146 VARIANT *pvarRet)
1148 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1150 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(scode), debugstr_w(language), pvarRet);
1152 return exec_script(This, scode, language, pvarRet);
1155 static HRESULT WINAPI HTMLWindow2_toString(IHTMLWindow2 *iface, BSTR *String)
1157 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1159 static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
1161 TRACE("(%p)->(%p)\n", This, String);
1163 if(!String)
1164 return E_INVALIDARG;
1166 *String = SysAllocString(objectW);
1167 return *String ? S_OK : E_OUTOFMEMORY;
1170 static HRESULT WINAPI HTMLWindow2_scrollBy(IHTMLWindow2 *iface, LONG x, LONG y)
1172 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1173 nsresult nsres;
1175 TRACE("(%p)->(%d %d)\n", This, x, y);
1177 nsres = nsIDOMWindow_ScrollBy(This->nswindow, x, y);
1178 if(NS_FAILED(nsres))
1179 ERR("ScrollBy failed: %08x\n", nsres);
1181 return S_OK;
1184 static HRESULT WINAPI HTMLWindow2_scrollTo(IHTMLWindow2 *iface, LONG x, LONG y)
1186 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1187 nsresult nsres;
1189 TRACE("(%p)->(%d %d)\n", This, x, y);
1191 nsres = nsIDOMWindow_ScrollTo(This->nswindow, x, y);
1192 if(NS_FAILED(nsres))
1193 ERR("ScrollTo failed: %08x\n", nsres);
1195 return S_OK;
1198 static HRESULT WINAPI HTMLWindow2_moveTo(IHTMLWindow2 *iface, LONG x, LONG y)
1200 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1201 FIXME("(%p)->(%d %d)\n", This, x, y);
1202 return E_NOTIMPL;
1205 static HRESULT WINAPI HTMLWindow2_moveBy(IHTMLWindow2 *iface, LONG x, LONG y)
1207 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1208 FIXME("(%p)->(%d %d)\n", This, x, y);
1209 return E_NOTIMPL;
1212 static HRESULT WINAPI HTMLWindow2_resizeTo(IHTMLWindow2 *iface, LONG x, LONG y)
1214 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1215 FIXME("(%p)->(%d %d)\n", This, x, y);
1216 return E_NOTIMPL;
1219 static HRESULT WINAPI HTMLWindow2_resizeBy(IHTMLWindow2 *iface, LONG x, LONG y)
1221 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1222 FIXME("(%p)->(%d %d)\n", This, x, y);
1223 return E_NOTIMPL;
1226 static HRESULT WINAPI HTMLWindow2_get_external(IHTMLWindow2 *iface, IDispatch **p)
1228 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1230 TRACE("(%p)->(%p)\n", This, p);
1232 *p = NULL;
1234 if(!This->doc_obj->hostui)
1235 return S_OK;
1237 return IDocHostUIHandler_GetExternal(This->doc_obj->hostui, p);
1240 static const IHTMLWindow2Vtbl HTMLWindow2Vtbl = {
1241 HTMLWindow2_QueryInterface,
1242 HTMLWindow2_AddRef,
1243 HTMLWindow2_Release,
1244 HTMLWindow2_GetTypeInfoCount,
1245 HTMLWindow2_GetTypeInfo,
1246 HTMLWindow2_GetIDsOfNames,
1247 HTMLWindow2_Invoke,
1248 HTMLWindow2_item,
1249 HTMLWindow2_get_length,
1250 HTMLWindow2_get_frames,
1251 HTMLWindow2_put_defaultStatus,
1252 HTMLWindow2_get_defaultStatus,
1253 HTMLWindow2_put_status,
1254 HTMLWindow2_get_status,
1255 HTMLWindow2_setTimeout,
1256 HTMLWindow2_clearTimeout,
1257 HTMLWindow2_alert,
1258 HTMLWindow2_confirm,
1259 HTMLWindow2_prompt,
1260 HTMLWindow2_get_Image,
1261 HTMLWindow2_get_location,
1262 HTMLWindow2_get_history,
1263 HTMLWindow2_close,
1264 HTMLWindow2_put_opener,
1265 HTMLWindow2_get_opener,
1266 HTMLWindow2_get_navigator,
1267 HTMLWindow2_put_name,
1268 HTMLWindow2_get_name,
1269 HTMLWindow2_get_parent,
1270 HTMLWindow2_open,
1271 HTMLWindow2_get_self,
1272 HTMLWindow2_get_top,
1273 HTMLWindow2_get_window,
1274 HTMLWindow2_navigate,
1275 HTMLWindow2_put_onfocus,
1276 HTMLWindow2_get_onfocus,
1277 HTMLWindow2_put_onblur,
1278 HTMLWindow2_get_onblur,
1279 HTMLWindow2_put_onload,
1280 HTMLWindow2_get_onload,
1281 HTMLWindow2_put_onbeforeunload,
1282 HTMLWindow2_get_onbeforeunload,
1283 HTMLWindow2_put_onunload,
1284 HTMLWindow2_get_onunload,
1285 HTMLWindow2_put_onhelp,
1286 HTMLWindow2_get_onhelp,
1287 HTMLWindow2_put_onerror,
1288 HTMLWindow2_get_onerror,
1289 HTMLWindow2_put_onresize,
1290 HTMLWindow2_get_onresize,
1291 HTMLWindow2_put_onscroll,
1292 HTMLWindow2_get_onscroll,
1293 HTMLWindow2_get_document,
1294 HTMLWindow2_get_event,
1295 HTMLWindow2_get__newEnum,
1296 HTMLWindow2_showModalDialog,
1297 HTMLWindow2_showHelp,
1298 HTMLWindow2_get_screen,
1299 HTMLWindow2_get_Option,
1300 HTMLWindow2_focus,
1301 HTMLWindow2_get_closed,
1302 HTMLWindow2_blur,
1303 HTMLWindow2_scroll,
1304 HTMLWindow2_get_clientInformation,
1305 HTMLWindow2_setInterval,
1306 HTMLWindow2_clearInterval,
1307 HTMLWindow2_put_offscreenBuffering,
1308 HTMLWindow2_get_offscreenBuffering,
1309 HTMLWindow2_execScript,
1310 HTMLWindow2_toString,
1311 HTMLWindow2_scrollBy,
1312 HTMLWindow2_scrollTo,
1313 HTMLWindow2_moveTo,
1314 HTMLWindow2_moveBy,
1315 HTMLWindow2_resizeTo,
1316 HTMLWindow2_resizeBy,
1317 HTMLWindow2_get_external
1320 static inline HTMLWindow *impl_from_IHTMLWindow3(IHTMLWindow3 *iface)
1322 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow3_iface);
1325 static HRESULT WINAPI HTMLWindow3_QueryInterface(IHTMLWindow3 *iface, REFIID riid, void **ppv)
1327 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1329 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1332 static ULONG WINAPI HTMLWindow3_AddRef(IHTMLWindow3 *iface)
1334 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1336 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1339 static ULONG WINAPI HTMLWindow3_Release(IHTMLWindow3 *iface)
1341 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1343 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1346 static HRESULT WINAPI HTMLWindow3_GetTypeInfoCount(IHTMLWindow3 *iface, UINT *pctinfo)
1348 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1350 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1353 static HRESULT WINAPI HTMLWindow3_GetTypeInfo(IHTMLWindow3 *iface, UINT iTInfo,
1354 LCID lcid, ITypeInfo **ppTInfo)
1356 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1358 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1361 static HRESULT WINAPI HTMLWindow3_GetIDsOfNames(IHTMLWindow3 *iface, REFIID riid,
1362 LPOLESTR *rgszNames, UINT cNames,
1363 LCID lcid, DISPID *rgDispId)
1365 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1367 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1368 rgDispId);
1371 static HRESULT WINAPI HTMLWindow3_Invoke(IHTMLWindow3 *iface, DISPID dispIdMember,
1372 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1373 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1375 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1377 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1378 pDispParams, pVarResult, pExcepInfo, puArgErr);
1381 static HRESULT WINAPI HTMLWindow3_get_screenLeft(IHTMLWindow3 *iface, LONG *p)
1383 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1384 FIXME("(%p)->(%p)\n", This, p);
1385 return E_NOTIMPL;
1388 static HRESULT WINAPI HTMLWindow3_get_screenTop(IHTMLWindow3 *iface, LONG *p)
1390 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1391 FIXME("(%p)->(%p)\n", This, p);
1392 return E_NOTIMPL;
1395 static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp, VARIANT_BOOL *pfResult)
1397 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1399 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
1401 if(!This->doc) {
1402 FIXME("No document\n");
1403 return E_FAIL;
1406 return attach_event(&This->doc->body_event_target, NULL, &This->doc->basedoc, event, pDisp, pfResult);
1409 static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
1411 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1412 FIXME("(%p)->()\n", This);
1413 return E_NOTIMPL;
1416 static HRESULT window_set_timer(HTMLWindow *This, VARIANT *expr, LONG msec, VARIANT *language,
1417 BOOL interval, LONG *timer_id)
1419 IDispatch *disp = NULL;
1421 switch(V_VT(expr)) {
1422 case VT_DISPATCH:
1423 disp = V_DISPATCH(expr);
1424 IDispatch_AddRef(disp);
1425 break;
1427 case VT_BSTR:
1428 disp = script_parse_event(This, V_BSTR(expr));
1429 break;
1431 default:
1432 FIXME("unimplemented vt=%d\n", V_VT(expr));
1433 return E_NOTIMPL;
1436 if(!disp)
1437 return E_FAIL;
1439 *timer_id = set_task_timer(&This->doc->basedoc, msec, interval, disp);
1440 IDispatch_Release(disp);
1442 return S_OK;
1445 static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1446 VARIANT *language, LONG *timerID)
1448 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1450 TRACE("(%p)->(%p(%d) %d %p %p)\n", This, expression, V_VT(expression), msec, language, timerID);
1452 return window_set_timer(This, expression, msec, language, FALSE, timerID);
1455 static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1456 VARIANT *language, LONG *timerID)
1458 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1460 TRACE("(%p)->(%p %d %p %p)\n", This, expression, msec, language, timerID);
1462 return window_set_timer(This, expression, msec, language, TRUE, timerID);
1465 static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)
1467 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1468 FIXME("(%p)\n", This);
1469 return E_NOTIMPL;
1472 static HRESULT WINAPI HTMLWindow3_put_onbeforeprint(IHTMLWindow3 *iface, VARIANT v)
1474 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1475 FIXME("(%p)->()\n", This);
1476 return E_NOTIMPL;
1479 static HRESULT WINAPI HTMLWindow3_get_onbeforeprint(IHTMLWindow3 *iface, VARIANT *p)
1481 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1482 FIXME("(%p)->(%p)\n", This, p);
1483 return E_NOTIMPL;
1486 static HRESULT WINAPI HTMLWindow3_put_onafterprint(IHTMLWindow3 *iface, VARIANT v)
1488 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1489 FIXME("(%p)->()\n", This);
1490 return E_NOTIMPL;
1493 static HRESULT WINAPI HTMLWindow3_get_onafterprint(IHTMLWindow3 *iface, VARIANT *p)
1495 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1496 FIXME("(%p)->(%p)\n", This, p);
1497 return E_NOTIMPL;
1500 static HRESULT WINAPI HTMLWindow3_get_clipboardData(IHTMLWindow3 *iface, IHTMLDataTransfer **p)
1502 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1503 FIXME("(%p)->(%p)\n", This, p);
1504 return E_NOTIMPL;
1507 static HRESULT WINAPI HTMLWindow3_showModelessDialog(IHTMLWindow3 *iface, BSTR url,
1508 VARIANT *varArgIn, VARIANT *options, IHTMLWindow2 **pDialog)
1510 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1511 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(url), varArgIn, options, pDialog);
1512 return E_NOTIMPL;
1515 static const IHTMLWindow3Vtbl HTMLWindow3Vtbl = {
1516 HTMLWindow3_QueryInterface,
1517 HTMLWindow3_AddRef,
1518 HTMLWindow3_Release,
1519 HTMLWindow3_GetTypeInfoCount,
1520 HTMLWindow3_GetTypeInfo,
1521 HTMLWindow3_GetIDsOfNames,
1522 HTMLWindow3_Invoke,
1523 HTMLWindow3_get_screenLeft,
1524 HTMLWindow3_get_screenTop,
1525 HTMLWindow3_attachEvent,
1526 HTMLWindow3_detachEvent,
1527 HTMLWindow3_setTimeout,
1528 HTMLWindow3_setInterval,
1529 HTMLWindow3_print,
1530 HTMLWindow3_put_onbeforeprint,
1531 HTMLWindow3_get_onbeforeprint,
1532 HTMLWindow3_put_onafterprint,
1533 HTMLWindow3_get_onafterprint,
1534 HTMLWindow3_get_clipboardData,
1535 HTMLWindow3_showModelessDialog
1538 static inline HTMLWindow *impl_from_IHTMLWindow4(IHTMLWindow4 *iface)
1540 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow4_iface);
1543 static HRESULT WINAPI HTMLWindow4_QueryInterface(IHTMLWindow4 *iface, REFIID riid, void **ppv)
1545 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1547 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1550 static ULONG WINAPI HTMLWindow4_AddRef(IHTMLWindow4 *iface)
1552 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1554 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1557 static ULONG WINAPI HTMLWindow4_Release(IHTMLWindow4 *iface)
1559 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1561 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1564 static HRESULT WINAPI HTMLWindow4_GetTypeInfoCount(IHTMLWindow4 *iface, UINT *pctinfo)
1566 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1568 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1571 static HRESULT WINAPI HTMLWindow4_GetTypeInfo(IHTMLWindow4 *iface, UINT iTInfo,
1572 LCID lcid, ITypeInfo **ppTInfo)
1574 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1576 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1579 static HRESULT WINAPI HTMLWindow4_GetIDsOfNames(IHTMLWindow4 *iface, REFIID riid,
1580 LPOLESTR *rgszNames, UINT cNames,
1581 LCID lcid, DISPID *rgDispId)
1583 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1585 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1586 rgDispId);
1589 static HRESULT WINAPI HTMLWindow4_Invoke(IHTMLWindow4 *iface, DISPID dispIdMember,
1590 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1591 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1593 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1595 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1596 pDispParams, pVarResult, pExcepInfo, puArgErr);
1599 static HRESULT WINAPI HTMLWindow4_createPopup(IHTMLWindow4 *iface, VARIANT *varArgIn,
1600 IDispatch **ppPopup)
1602 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1603 FIXME("(%p)->(%p %p)\n", This, varArgIn, ppPopup);
1604 return E_NOTIMPL;
1607 static HRESULT WINAPI HTMLWindow4_get_frameElement(IHTMLWindow4 *iface, IHTMLFrameBase **p)
1609 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1610 TRACE("(%p)->(%p)\n", This, p);
1612 if(This->frame_element) {
1613 *p = &This->frame_element->IHTMLFrameBase_iface;
1614 IHTMLFrameBase_AddRef(*p);
1615 }else
1616 *p = NULL;
1618 return S_OK;
1621 static const IHTMLWindow4Vtbl HTMLWindow4Vtbl = {
1622 HTMLWindow4_QueryInterface,
1623 HTMLWindow4_AddRef,
1624 HTMLWindow4_Release,
1625 HTMLWindow4_GetTypeInfoCount,
1626 HTMLWindow4_GetTypeInfo,
1627 HTMLWindow4_GetIDsOfNames,
1628 HTMLWindow4_Invoke,
1629 HTMLWindow4_createPopup,
1630 HTMLWindow4_get_frameElement
1633 static inline HTMLWindow *impl_from_IHTMLPrivateWindow(IHTMLPrivateWindow *iface)
1635 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLPrivateWindow_iface);
1638 static HRESULT WINAPI HTMLPrivateWindow_QueryInterface(IHTMLPrivateWindow *iface, REFIID riid, void **ppv)
1640 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1642 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1645 static ULONG WINAPI HTMLPrivateWindow_AddRef(IHTMLPrivateWindow *iface)
1647 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1649 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1652 static ULONG WINAPI HTMLPrivateWindow_Release(IHTMLPrivateWindow *iface)
1654 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1656 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1659 static HRESULT WINAPI HTMLPrivateWindow_SuperNavigate(IHTMLPrivateWindow *iface, BSTR url, BSTR arg2, BSTR arg3,
1660 BSTR arg4, VARIANT *post_data_var, VARIANT *headers_var, ULONG flags)
1662 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1663 DWORD post_data_size = 0;
1664 BYTE *post_data = NULL;
1665 WCHAR *headers = NULL;
1666 nsChannelBSC *bsc;
1667 IMoniker *mon;
1668 BSTR new_url;
1669 HRESULT hres;
1671 TRACE("(%p)->(%s %s %s %s %s %s %x)\n", This, debugstr_w(url), debugstr_w(arg2), debugstr_w(arg3), debugstr_w(arg4),
1672 debugstr_variant(post_data_var), debugstr_variant(headers_var), flags);
1674 new_url = url;
1675 if(This->doc_obj->hostui) {
1676 OLECHAR *translated_url = NULL;
1678 hres = IDocHostUIHandler_TranslateUrl(This->doc_obj->hostui, 0, url, &translated_url);
1679 if(hres == S_OK && translated_url) {
1680 new_url = SysAllocString(translated_url);
1681 CoTaskMemFree(translated_url);
1685 if(This->doc_obj->client) {
1686 IOleCommandTarget *cmdtrg;
1688 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
1689 if(SUCCEEDED(hres)) {
1690 VARIANT in, out;
1692 V_VT(&in) = VT_BSTR;
1693 V_BSTR(&in) = new_url;
1694 V_VT(&out) = VT_BOOL;
1695 V_BOOL(&out) = VARIANT_TRUE;
1696 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &in, &out);
1697 IOleCommandTarget_Release(cmdtrg);
1698 if(SUCCEEDED(hres))
1699 VariantClear(&out);
1703 /* FIXME: Why not set_ready_state? */
1704 This->readystate = READYSTATE_UNINITIALIZED;
1706 hres = CreateURLMoniker(NULL, new_url, &mon);
1707 if(new_url != url)
1708 SysFreeString(new_url);
1709 if(FAILED(hres))
1710 return hres;
1712 if(post_data_var) {
1713 if(V_VT(post_data_var) == (VT_ARRAY|VT_UI1)) {
1714 SafeArrayAccessData(V_ARRAY(post_data_var), (void**)&post_data);
1715 post_data_size = V_ARRAY(post_data_var)->rgsabound[0].cElements;
1719 if(headers_var && V_VT(headers_var) != VT_EMPTY && V_VT(headers_var) != VT_ERROR) {
1720 if(V_VT(headers_var) != VT_BSTR)
1721 return E_INVALIDARG;
1723 headers = V_BSTR(headers_var);
1726 hres = create_channelbsc(mon, headers, post_data, post_data_size, &bsc);
1727 if(post_data)
1728 SafeArrayUnaccessData(V_ARRAY(post_data_var));
1729 if(FAILED(hres)) {
1730 IMoniker_Release(mon);
1731 return hres;
1734 hres = set_moniker(&This->doc_obj->basedoc, mon, NULL, bsc, TRUE);
1735 if(SUCCEEDED(hres))
1736 hres = async_start_doc_binding(This, bsc);
1738 IUnknown_Release((IUnknown*)bsc);
1739 IMoniker_Release(mon);
1740 return hres;
1743 static HRESULT WINAPI HTMLPrivateWindow_GetPendingUrl(IHTMLPrivateWindow *iface, BSTR *url)
1745 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1746 FIXME("(%p)->(%p)\n", This, url);
1747 return E_NOTIMPL;
1750 static HRESULT WINAPI HTMLPrivateWindow_SetPICSTarget(IHTMLPrivateWindow *iface, IOleCommandTarget *cmdtrg)
1752 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1753 FIXME("(%p)->(%p)\n", This, cmdtrg);
1754 return E_NOTIMPL;
1757 static HRESULT WINAPI HTMLPrivateWindow_PICSComplete(IHTMLPrivateWindow *iface, int arg)
1759 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1760 FIXME("(%p)->(%x)\n", This, arg);
1761 return E_NOTIMPL;
1764 static HRESULT WINAPI HTMLPrivateWindow_FindWindowByName(IHTMLPrivateWindow *iface, LPCWSTR name, IHTMLWindow2 **ret)
1766 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1767 FIXME("(%p)->(%s %p)\n", This, debugstr_w(name), ret);
1768 return E_NOTIMPL;
1771 static HRESULT WINAPI HTMLPrivateWindow_GetAddressBar(IHTMLPrivateWindow *iface, BSTR *url)
1773 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1774 FIXME("(%p)->(%p)\n", This, url);
1775 return E_NOTIMPL;
1778 static const IHTMLPrivateWindowVtbl HTMLPrivateWindowVtbl = {
1779 HTMLPrivateWindow_QueryInterface,
1780 HTMLPrivateWindow_AddRef,
1781 HTMLPrivateWindow_Release,
1782 HTMLPrivateWindow_SuperNavigate,
1783 HTMLPrivateWindow_GetPendingUrl,
1784 HTMLPrivateWindow_SetPICSTarget,
1785 HTMLPrivateWindow_PICSComplete,
1786 HTMLPrivateWindow_FindWindowByName,
1787 HTMLPrivateWindow_GetAddressBar
1790 static inline HTMLWindow *impl_from_IDispatchEx(IDispatchEx *iface)
1792 return CONTAINING_RECORD(iface, HTMLWindow, IDispatchEx_iface);
1795 static HRESULT WINAPI WindowDispEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1797 HTMLWindow *This = impl_from_IDispatchEx(iface);
1799 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1802 static ULONG WINAPI WindowDispEx_AddRef(IDispatchEx *iface)
1804 HTMLWindow *This = impl_from_IDispatchEx(iface);
1806 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1809 static ULONG WINAPI WindowDispEx_Release(IDispatchEx *iface)
1811 HTMLWindow *This = impl_from_IDispatchEx(iface);
1813 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1816 static HRESULT WINAPI WindowDispEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1818 HTMLWindow *This = impl_from_IDispatchEx(iface);
1820 TRACE("(%p)->(%p)\n", This, pctinfo);
1822 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
1825 static HRESULT WINAPI WindowDispEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1826 LCID lcid, ITypeInfo **ppTInfo)
1828 HTMLWindow *This = impl_from_IDispatchEx(iface);
1830 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1832 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1835 static HRESULT WINAPI WindowDispEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1836 LPOLESTR *rgszNames, UINT cNames,
1837 LCID lcid, DISPID *rgDispId)
1839 HTMLWindow *This = impl_from_IDispatchEx(iface);
1840 UINT i;
1841 HRESULT hres;
1843 WARN("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1844 lcid, rgDispId);
1846 for(i=0; i < cNames; i++) {
1847 /* We shouldn't use script's IDispatchEx here, so we shouldn't use GetDispID */
1848 hres = IDispatchEx_GetDispID(&This->IDispatchEx_iface, rgszNames[i], 0, rgDispId+i);
1849 if(FAILED(hres))
1850 return hres;
1853 return S_OK;
1856 static HRESULT WINAPI WindowDispEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1857 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1858 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1860 HTMLWindow *This = impl_from_IDispatchEx(iface);
1862 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1863 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1865 /* FIXME: Use script dispatch */
1867 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1868 pDispParams, pVarResult, pExcepInfo, puArgErr);
1871 static global_prop_t *alloc_global_prop(HTMLWindow *This, global_prop_type_t type, BSTR name)
1873 if(This->global_prop_cnt == This->global_prop_size) {
1874 global_prop_t *new_props;
1875 DWORD new_size;
1877 if(This->global_props) {
1878 new_size = This->global_prop_size*2;
1879 new_props = heap_realloc(This->global_props, new_size*sizeof(global_prop_t));
1880 }else {
1881 new_size = 16;
1882 new_props = heap_alloc(new_size*sizeof(global_prop_t));
1884 if(!new_props)
1885 return NULL;
1886 This->global_props = new_props;
1887 This->global_prop_size = new_size;
1890 This->global_props[This->global_prop_cnt].name = heap_strdupW(name);
1891 if(!This->global_props[This->global_prop_cnt].name)
1892 return NULL;
1894 This->global_props[This->global_prop_cnt].type = type;
1895 return This->global_props + This->global_prop_cnt++;
1898 static inline DWORD prop_to_dispid(HTMLWindow *This, global_prop_t *prop)
1900 return MSHTML_DISPID_CUSTOM_MIN + (prop-This->global_props);
1903 HRESULT search_window_props(HTMLWindow *This, BSTR bstrName, DWORD grfdex, DISPID *pid)
1905 DWORD i;
1906 ScriptHost *script_host;
1907 DISPID id;
1909 for(i=0; i < This->global_prop_cnt; i++) {
1910 /* FIXME: case sensitivity */
1911 if(!strcmpW(This->global_props[i].name, bstrName)) {
1912 *pid = MSHTML_DISPID_CUSTOM_MIN+i;
1913 return S_OK;
1917 if(find_global_prop(This, bstrName, grfdex, &script_host, &id)) {
1918 global_prop_t *prop;
1920 prop = alloc_global_prop(This, GLOBAL_SCRIPTVAR, bstrName);
1921 if(!prop)
1922 return E_OUTOFMEMORY;
1924 prop->script_host = script_host;
1925 prop->id = id;
1927 *pid = prop_to_dispid(This, prop);
1928 return S_OK;
1931 return DISP_E_UNKNOWNNAME;
1934 static HRESULT WINAPI WindowDispEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1936 HTMLWindow *This = impl_from_IDispatchEx(iface);
1937 HRESULT hres;
1939 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
1941 hres = search_window_props(This, bstrName, grfdex, pid);
1942 if(hres != DISP_E_UNKNOWNNAME)
1943 return hres;
1945 hres = IDispatchEx_GetDispID(&This->dispex.IDispatchEx_iface, bstrName, grfdex, pid);
1946 if(hres != DISP_E_UNKNOWNNAME)
1947 return hres;
1949 if(This->doc) {
1950 global_prop_t *prop;
1951 IHTMLElement *elem;
1953 hres = IHTMLDocument3_getElementById(&This->doc->basedoc.IHTMLDocument3_iface,
1954 bstrName, &elem);
1955 if(SUCCEEDED(hres) && elem) {
1956 IHTMLElement_Release(elem);
1958 prop = alloc_global_prop(This, GLOBAL_ELEMENTVAR, bstrName);
1959 if(!prop)
1960 return E_OUTOFMEMORY;
1962 *pid = prop_to_dispid(This, prop);
1963 return S_OK;
1967 return DISP_E_UNKNOWNNAME;
1970 static HRESULT WINAPI WindowDispEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1971 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1973 HTMLWindow *This = impl_from_IDispatchEx(iface);
1975 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1977 if(id == DISPID_IHTMLWINDOW2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT)) {
1978 HTMLLocation *location;
1979 HRESULT hres;
1981 TRACE("forwarding to location.href\n");
1983 hres = get_location(This, &location);
1984 if(FAILED(hres))
1985 return hres;
1987 hres = IDispatchEx_InvokeEx(&location->dispex.IDispatchEx_iface, DISPID_VALUE, lcid,
1988 wFlags, pdp, pvarRes, pei, pspCaller);
1989 IHTMLLocation_Release(&location->IHTMLLocation_iface);
1990 return hres;
1993 return IDispatchEx_InvokeEx(&This->dispex.IDispatchEx_iface, id, lcid, wFlags, pdp, pvarRes,
1994 pei, pspCaller);
1997 static HRESULT WINAPI WindowDispEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1999 HTMLWindow *This = impl_from_IDispatchEx(iface);
2001 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
2003 return IDispatchEx_DeleteMemberByName(&This->dispex.IDispatchEx_iface, bstrName, grfdex);
2006 static HRESULT WINAPI WindowDispEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
2008 HTMLWindow *This = impl_from_IDispatchEx(iface);
2010 TRACE("(%p)->(%x)\n", This, id);
2012 return IDispatchEx_DeleteMemberByDispID(&This->dispex.IDispatchEx_iface, id);
2015 static HRESULT WINAPI WindowDispEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
2017 HTMLWindow *This = impl_from_IDispatchEx(iface);
2019 TRACE("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
2021 return IDispatchEx_GetMemberProperties(&This->dispex.IDispatchEx_iface, id, grfdexFetch,
2022 pgrfdex);
2025 static HRESULT WINAPI WindowDispEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
2027 HTMLWindow *This = impl_from_IDispatchEx(iface);
2029 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
2031 return IDispatchEx_GetMemberName(&This->dispex.IDispatchEx_iface, id, pbstrName);
2034 static HRESULT WINAPI WindowDispEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
2036 HTMLWindow *This = impl_from_IDispatchEx(iface);
2038 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
2040 return IDispatchEx_GetNextDispID(&This->dispex.IDispatchEx_iface, grfdex, id, pid);
2043 static HRESULT WINAPI WindowDispEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
2045 HTMLWindow *This = impl_from_IDispatchEx(iface);
2047 TRACE("(%p)->(%p)\n", This, ppunk);
2049 *ppunk = NULL;
2050 return S_OK;
2053 static const IDispatchExVtbl WindowDispExVtbl = {
2054 WindowDispEx_QueryInterface,
2055 WindowDispEx_AddRef,
2056 WindowDispEx_Release,
2057 WindowDispEx_GetTypeInfoCount,
2058 WindowDispEx_GetTypeInfo,
2059 WindowDispEx_GetIDsOfNames,
2060 WindowDispEx_Invoke,
2061 WindowDispEx_GetDispID,
2062 WindowDispEx_InvokeEx,
2063 WindowDispEx_DeleteMemberByName,
2064 WindowDispEx_DeleteMemberByDispID,
2065 WindowDispEx_GetMemberProperties,
2066 WindowDispEx_GetMemberName,
2067 WindowDispEx_GetNextDispID,
2068 WindowDispEx_GetNameSpaceParent
2071 static inline HTMLWindow *impl_from_IServiceProvider(IServiceProvider *iface)
2073 return CONTAINING_RECORD(iface, HTMLWindow, IServiceProvider_iface);
2076 static HRESULT WINAPI HTMLWindowSP_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
2078 HTMLWindow *This = impl_from_IServiceProvider(iface);
2079 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2082 static ULONG WINAPI HTMLWindowSP_AddRef(IServiceProvider *iface)
2084 HTMLWindow *This = impl_from_IServiceProvider(iface);
2085 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2088 static ULONG WINAPI HTMLWindowSP_Release(IServiceProvider *iface)
2090 HTMLWindow *This = impl_from_IServiceProvider(iface);
2091 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2094 static HRESULT WINAPI HTMLWindowSP_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
2096 HTMLWindow *This = impl_from_IServiceProvider(iface);
2098 if(IsEqualGUID(guidService, &IID_IHTMLWindow2)) {
2099 TRACE("IID_IHTMLWindow2\n");
2100 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2103 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
2105 if(!This->doc_obj)
2106 return E_NOINTERFACE;
2108 return IServiceProvider_QueryService(&This->doc_obj->basedoc.IServiceProvider_iface,
2109 guidService, riid, ppv);
2112 static const IServiceProviderVtbl ServiceProviderVtbl = {
2113 HTMLWindowSP_QueryInterface,
2114 HTMLWindowSP_AddRef,
2115 HTMLWindowSP_Release,
2116 HTMLWindowSP_QueryService
2119 static inline HTMLWindow *impl_from_DispatchEx(DispatchEx *iface)
2121 return CONTAINING_RECORD(iface, HTMLWindow, dispex);
2124 static HRESULT HTMLWindow_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2125 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2127 HTMLWindow *This = impl_from_DispatchEx(dispex);
2128 global_prop_t *prop;
2129 DWORD idx;
2130 HRESULT hres;
2132 idx = id - MSHTML_DISPID_CUSTOM_MIN;
2133 if(idx >= This->global_prop_cnt)
2134 return DISP_E_MEMBERNOTFOUND;
2136 prop = This->global_props+idx;
2138 switch(prop->type) {
2139 case GLOBAL_SCRIPTVAR: {
2140 IDispatchEx *dispex;
2141 IDispatch *disp;
2143 disp = get_script_disp(prop->script_host);
2144 if(!disp)
2145 return E_UNEXPECTED;
2147 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
2148 if(SUCCEEDED(hres)) {
2149 TRACE("%s >>>\n", debugstr_w(prop->name));
2150 hres = IDispatchEx_InvokeEx(dispex, prop->id, lcid, flags, params, res, ei, caller);
2151 if(hres == S_OK)
2152 TRACE("%s <<<\n", debugstr_w(prop->name));
2153 else
2154 WARN("%s <<< %08x\n", debugstr_w(prop->name), hres);
2155 IDispatchEx_Release(dispex);
2156 }else {
2157 FIXME("No IDispatchEx\n");
2159 IDispatch_Release(disp);
2160 break;
2162 case GLOBAL_ELEMENTVAR: {
2163 IHTMLElement *elem;
2165 hres = IHTMLDocument3_getElementById(&This->doc->basedoc.IHTMLDocument3_iface,
2166 prop->name, &elem);
2167 if(FAILED(hres))
2168 return hres;
2170 if(!elem)
2171 return DISP_E_MEMBERNOTFOUND;
2173 V_VT(res) = VT_DISPATCH;
2174 V_DISPATCH(res) = (IDispatch*)elem;
2175 break;
2177 default:
2178 ERR("invalid type %d\n", prop->type);
2179 hres = DISP_E_MEMBERNOTFOUND;
2182 return hres;
2186 static const dispex_static_data_vtbl_t HTMLWindow_dispex_vtbl = {
2187 NULL,
2188 NULL,
2189 HTMLWindow_invoke
2192 static const tid_t HTMLWindow_iface_tids[] = {
2193 IHTMLWindow2_tid,
2194 IHTMLWindow3_tid,
2195 IHTMLWindow4_tid,
2199 static dispex_static_data_t HTMLWindow_dispex = {
2200 &HTMLWindow_dispex_vtbl,
2201 DispHTMLWindow2_tid,
2202 NULL,
2203 HTMLWindow_iface_tids
2206 HRESULT HTMLWindow_Create(HTMLDocumentObj *doc_obj, nsIDOMWindow *nswindow, HTMLWindow *parent, HTMLWindow **ret)
2208 HTMLWindow *window;
2210 window = heap_alloc_zero(sizeof(HTMLWindow));
2211 if(!window)
2212 return E_OUTOFMEMORY;
2214 window->window_ref = heap_alloc(sizeof(windowref_t));
2215 if(!window->window_ref) {
2216 heap_free(window);
2217 return E_OUTOFMEMORY;
2220 window->IHTMLWindow2_iface.lpVtbl = &HTMLWindow2Vtbl;
2221 window->IHTMLWindow3_iface.lpVtbl = &HTMLWindow3Vtbl;
2222 window->IHTMLWindow4_iface.lpVtbl = &HTMLWindow4Vtbl;
2223 window->IHTMLPrivateWindow_iface.lpVtbl = &HTMLPrivateWindowVtbl;
2224 window->IDispatchEx_iface.lpVtbl = &WindowDispExVtbl;
2225 window->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
2226 window->ref = 1;
2227 window->doc_obj = doc_obj;
2229 window->window_ref->window = window;
2230 window->window_ref->ref = 1;
2232 init_dispex(&window->dispex, (IUnknown*)&window->IHTMLWindow2_iface, &HTMLWindow_dispex);
2234 if(nswindow) {
2235 nsIDOMWindow_AddRef(nswindow);
2236 window->nswindow = nswindow;
2239 window->scriptmode = parent ? parent->scriptmode : SCRIPTMODE_GECKO;
2240 window->readystate = READYSTATE_UNINITIALIZED;
2241 list_init(&window->script_hosts);
2243 window->task_magic = get_task_target_magic();
2244 update_window_doc(window);
2246 list_init(&window->children);
2247 list_add_head(&window_list, &window->entry);
2249 if(parent) {
2250 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
2252 window->parent = parent;
2253 list_add_tail(&parent->children, &window->sibling_entry);
2256 *ret = window;
2257 return S_OK;
2260 void update_window_doc(HTMLWindow *window)
2262 nsIDOMHTMLDocument *nshtmldoc;
2263 nsIDOMDocument *nsdoc;
2264 nsresult nsres;
2266 nsres = nsIDOMWindow_GetDocument(window->nswindow, &nsdoc);
2267 if(NS_FAILED(nsres) || !nsdoc) {
2268 ERR("GetDocument failed: %08x\n", nsres);
2269 return;
2272 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
2273 nsIDOMDocument_Release(nsdoc);
2274 if(NS_FAILED(nsres)) {
2275 ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres);
2276 return;
2279 if(!window->doc || window->doc->nsdoc != nshtmldoc) {
2280 HTMLDocumentNode *doc;
2281 HRESULT hres;
2283 hres = create_doc_from_nsdoc(nshtmldoc, window->doc_obj, window, &doc);
2284 if(SUCCEEDED(hres)) {
2285 window_set_docnode(window, doc);
2286 htmldoc_release(&doc->basedoc);
2287 }else {
2288 ERR("create_doc_from_nsdoc failed: %08x\n", hres);
2292 nsIDOMHTMLDocument_Release(nshtmldoc);
2295 HTMLWindow *nswindow_to_window(const nsIDOMWindow *nswindow)
2297 HTMLWindow *iter;
2299 LIST_FOR_EACH_ENTRY(iter, &window_list, HTMLWindow, entry) {
2300 if(iter->nswindow == nswindow)
2301 return iter;
2304 return NULL;