mshtml: Pass DispatchEx pointer instead of outer IUnknown to DispatchEx's vtbl functions.
[wine.git] / dlls / mshtml / htmlwindow.c
blobc98eb1da68d98aa693024a6104e537be15f5ba27
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(HTMLLOCATION(This->location));
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 = DISPATCHEX(This);
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(HTMLOPTFACTORY(This->option_factory));
245 if(This->image_factory) {
246 This->image_factory->window = NULL;
247 IHTMLImageElementFactory_Release(HTMLIMGFACTORY(This->image_factory));
250 if(This->location) {
251 This->location->window = NULL;
252 IHTMLLocation_Release(HTMLLOCATION(This->location));
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(DISPATCHEX(This), 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(DISPATCHEX(This), 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(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
302 static HRESULT WINAPI HTMLWindow2_Invoke(IHTMLWindow2 *iface, DISPID dispIdMember,
303 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
304 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
306 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
308 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
309 pVarResult, pExcepInfo, puArgErr);
312 static HRESULT get_frame_by_index(nsIDOMWindowCollection *nsFrames, PRUint32 index, HTMLWindow **ret)
314 PRUint32 length;
315 nsIDOMWindow *nsWindow;
316 nsresult nsres;
318 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
319 if(NS_FAILED(nsres)) {
320 FIXME("nsIDOMWindowCollection_GetLength failed: 0x%08x\n", nsres);
321 return E_FAIL;
324 if(index >= length)
325 return DISP_E_MEMBERNOTFOUND;
327 nsres = nsIDOMWindowCollection_Item(nsFrames, index, &nsWindow);
328 if(NS_FAILED(nsres)) {
329 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
330 return E_FAIL;
333 *ret = nswindow_to_window(nsWindow);
335 nsIDOMWindow_Release(nsWindow);
337 return S_OK;
340 static HRESULT WINAPI HTMLWindow2_item(IHTMLWindow2 *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
342 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
343 nsIDOMWindowCollection *nsFrames;
344 HTMLWindow *window;
345 HRESULT hres;
346 nsresult nsres;
348 TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
350 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsFrames);
351 if(NS_FAILED(nsres)) {
352 FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
353 return E_FAIL;
356 if(V_VT(pvarIndex) == VT_I4) {
357 int index = V_I4(pvarIndex);
358 TRACE("Getting index %d\n", index);
359 if(index < 0) {
360 hres = DISP_E_MEMBERNOTFOUND;
361 goto cleanup;
363 hres = get_frame_by_index(nsFrames, index, &window);
364 if(FAILED(hres))
365 goto cleanup;
366 }else if(V_VT(pvarIndex) == VT_UINT) {
367 unsigned int index = V_UINT(pvarIndex);
368 TRACE("Getting index %u\n", index);
369 hres = get_frame_by_index(nsFrames, index, &window);
370 if(FAILED(hres))
371 goto cleanup;
372 }else if(V_VT(pvarIndex) == VT_BSTR) {
373 BSTR str = V_BSTR(pvarIndex);
374 PRUint32 length, i;
376 TRACE("Getting name %s\n", wine_dbgstr_w(str));
378 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
380 window = NULL;
381 for(i = 0; i < length && !window; ++i) {
382 HTMLWindow *cur_window;
383 nsIDOMWindow *nsWindow;
384 BSTR id;
386 nsres = nsIDOMWindowCollection_Item(nsFrames, i, &nsWindow);
387 if(NS_FAILED(nsres)) {
388 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
389 hres = E_FAIL;
390 goto cleanup;
393 cur_window = nswindow_to_window(nsWindow);
395 nsIDOMWindow_Release(nsWindow);
397 hres = IHTMLElement_get_id(HTMLELEM(&cur_window->frame_element->element), &id);
398 if(FAILED(hres)) {
399 FIXME("IHTMLElement_get_id failed: 0x%08x\n", hres);
400 goto cleanup;
403 if(!strcmpW(id, str))
404 window = cur_window;
406 SysFreeString(id);
409 if(!window) {
410 hres = DISP_E_MEMBERNOTFOUND;
411 goto cleanup;
413 }else {
414 hres = E_INVALIDARG;
415 goto cleanup;
418 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
419 V_VT(pvarResult) = VT_DISPATCH;
420 V_DISPATCH(pvarResult) = (IDispatch*)window;
422 hres = S_OK;
424 cleanup:
425 nsIDOMWindowCollection_Release(nsFrames);
427 return hres;
430 static HRESULT WINAPI HTMLWindow2_get_length(IHTMLWindow2 *iface, LONG *p)
432 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
433 nsIDOMWindowCollection *nscollection;
434 PRUint32 length;
435 nsresult nsres;
437 TRACE("(%p)->(%p)\n", This, p);
439 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nscollection);
440 if(NS_FAILED(nsres)) {
441 ERR("GetFrames failed: %08x\n", nsres);
442 return E_FAIL;
445 nsres = nsIDOMWindowCollection_GetLength(nscollection, &length);
446 nsIDOMWindowCollection_Release(nscollection);
447 if(NS_FAILED(nsres)) {
448 ERR("GetLength failed: %08x\n", nsres);
449 return E_FAIL;
452 *p = length;
453 return S_OK;
456 static HRESULT WINAPI HTMLWindow2_get_frames(IHTMLWindow2 *iface, IHTMLFramesCollection2 **p)
458 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
459 FIXME("(%p)->(%p): semi-stub\n", This, p);
461 /* FIXME: Should return a separate Window object */
462 *p = (IHTMLFramesCollection2*)&This->IHTMLWindow2_iface;
463 HTMLWindow2_AddRef(iface);
464 return S_OK;
467 static HRESULT WINAPI HTMLWindow2_put_defaultStatus(IHTMLWindow2 *iface, BSTR v)
469 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
470 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
471 return E_NOTIMPL;
474 static HRESULT WINAPI HTMLWindow2_get_defaultStatus(IHTMLWindow2 *iface, BSTR *p)
476 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
477 FIXME("(%p)->(%p)\n", This, p);
478 return E_NOTIMPL;
481 static HRESULT WINAPI HTMLWindow2_put_status(IHTMLWindow2 *iface, BSTR v)
483 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
484 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
485 return E_NOTIMPL;
488 static HRESULT WINAPI HTMLWindow2_get_status(IHTMLWindow2 *iface, BSTR *p)
490 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
491 FIXME("(%p)->(%p)\n", This, p);
492 return E_NOTIMPL;
495 static HRESULT WINAPI HTMLWindow2_setTimeout(IHTMLWindow2 *iface, BSTR expression,
496 LONG msec, VARIANT *language, LONG *timerID)
498 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
499 VARIANT expr_var;
501 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
503 V_VT(&expr_var) = VT_BSTR;
504 V_BSTR(&expr_var) = expression;
506 return IHTMLWindow3_setTimeout(&This->IHTMLWindow3_iface, &expr_var, msec, language, timerID);
509 static HRESULT WINAPI HTMLWindow2_clearTimeout(IHTMLWindow2 *iface, LONG timerID)
511 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
513 TRACE("(%p)->(%d)\n", This, timerID);
515 return clear_task_timer(&This->doc->basedoc, FALSE, timerID);
518 #define MAX_MESSAGE_LEN 2000
520 static HRESULT WINAPI HTMLWindow2_alert(IHTMLWindow2 *iface, BSTR message)
522 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
523 WCHAR title[100], *msg = message;
524 DWORD len;
526 TRACE("(%p)->(%s)\n", This, debugstr_w(message));
528 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, title,
529 sizeof(title)/sizeof(WCHAR))) {
530 WARN("Could not load message box title: %d\n", GetLastError());
531 return S_OK;
534 len = SysStringLen(message);
535 if(len > MAX_MESSAGE_LEN) {
536 msg = heap_alloc((MAX_MESSAGE_LEN+1)*sizeof(WCHAR));
537 if(!msg)
538 return E_OUTOFMEMORY;
539 memcpy(msg, message, MAX_MESSAGE_LEN*sizeof(WCHAR));
540 msg[MAX_MESSAGE_LEN] = 0;
543 MessageBoxW(This->doc_obj->hwnd, msg, title, MB_ICONWARNING);
544 if(msg != message)
545 heap_free(msg);
546 return S_OK;
549 static HRESULT WINAPI HTMLWindow2_confirm(IHTMLWindow2 *iface, BSTR message,
550 VARIANT_BOOL *confirmed)
552 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
553 WCHAR wszTitle[100];
555 TRACE("(%p)->(%s %p)\n", This, debugstr_w(message), confirmed);
557 if(!confirmed) return E_INVALIDARG;
559 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
560 sizeof(wszTitle)/sizeof(WCHAR))) {
561 WARN("Could not load message box title: %d\n", GetLastError());
562 *confirmed = VARIANT_TRUE;
563 return S_OK;
566 if(MessageBoxW(This->doc_obj->hwnd, message, wszTitle,
567 MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
568 *confirmed = VARIANT_TRUE;
569 else *confirmed = VARIANT_FALSE;
571 return S_OK;
574 typedef struct
576 BSTR message;
577 BSTR dststr;
578 VARIANT *textdata;
579 }prompt_arg;
581 static INT_PTR CALLBACK prompt_dlgproc(HWND hwnd, UINT msg,
582 WPARAM wparam, LPARAM lparam)
584 switch(msg)
586 case WM_INITDIALOG:
588 prompt_arg *arg = (prompt_arg*)lparam;
589 WCHAR wszTitle[100];
591 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
592 sizeof(wszTitle)/sizeof(WCHAR))) {
593 WARN("Could not load message box title: %d\n", GetLastError());
594 EndDialog(hwnd, wparam);
595 return FALSE;
598 SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
599 SetWindowTextW(hwnd, wszTitle);
600 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_PROMPT), arg->message);
601 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_EDIT), arg->dststr);
602 return FALSE;
604 case WM_COMMAND:
605 switch(wparam)
607 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
608 EndDialog(hwnd, wparam);
609 return TRUE;
610 case MAKEWPARAM(IDOK, BN_CLICKED):
612 prompt_arg *arg =
613 (prompt_arg*)GetWindowLongPtrW(hwnd, DWLP_USER);
614 HWND hwndPrompt = GetDlgItem(hwnd, ID_PROMPT_EDIT);
615 INT len = GetWindowTextLengthW(hwndPrompt);
617 if(!arg->textdata)
619 EndDialog(hwnd, wparam);
620 return TRUE;
623 V_VT(arg->textdata) = VT_BSTR;
624 if(!len && !arg->dststr)
625 V_BSTR(arg->textdata) = NULL;
626 else
628 V_BSTR(arg->textdata) = SysAllocStringLen(NULL, len);
629 GetWindowTextW(hwndPrompt, V_BSTR(arg->textdata), len+1);
631 EndDialog(hwnd, wparam);
632 return TRUE;
635 return FALSE;
636 case WM_CLOSE:
637 EndDialog(hwnd, IDCANCEL);
638 return TRUE;
639 default:
640 return FALSE;
644 static HRESULT WINAPI HTMLWindow2_prompt(IHTMLWindow2 *iface, BSTR message,
645 BSTR dststr, VARIANT *textdata)
647 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
648 prompt_arg arg;
650 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(message), debugstr_w(dststr), textdata);
652 if(textdata) V_VT(textdata) = VT_NULL;
654 arg.message = message;
655 arg.dststr = dststr;
656 arg.textdata = textdata;
658 DialogBoxParamW(hInst, MAKEINTRESOURCEW(ID_PROMPT_DIALOG),
659 This->doc_obj->hwnd, prompt_dlgproc, (LPARAM)&arg);
660 return S_OK;
663 static HRESULT WINAPI HTMLWindow2_get_Image(IHTMLWindow2 *iface, IHTMLImageElementFactory **p)
665 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
667 TRACE("(%p)->(%p)\n", This, p);
669 if(!This->image_factory)
670 This->image_factory = HTMLImageElementFactory_Create(This);
672 *p = HTMLIMGFACTORY(This->image_factory);
673 IHTMLImageElementFactory_AddRef(*p);
675 return S_OK;
678 static HRESULT WINAPI HTMLWindow2_get_location(IHTMLWindow2 *iface, IHTMLLocation **p)
680 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
681 HTMLLocation *location;
682 HRESULT hres;
684 TRACE("(%p)->(%p)\n", This, p);
686 hres = get_location(This, &location);
687 if(FAILED(hres))
688 return hres;
690 *p = HTMLLOCATION(location);
691 return S_OK;
694 static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p)
696 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
697 FIXME("(%p)->(%p)\n", This, p);
698 return E_NOTIMPL;
701 static HRESULT WINAPI HTMLWindow2_close(IHTMLWindow2 *iface)
703 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
704 FIXME("(%p)->()\n", This);
705 return E_NOTIMPL;
708 static HRESULT WINAPI HTMLWindow2_put_opener(IHTMLWindow2 *iface, VARIANT v)
710 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
711 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
712 return E_NOTIMPL;
715 static HRESULT WINAPI HTMLWindow2_get_opener(IHTMLWindow2 *iface, VARIANT *p)
717 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
718 FIXME("(%p)->(%p)\n", This, p);
719 return E_NOTIMPL;
722 static HRESULT WINAPI HTMLWindow2_get_navigator(IHTMLWindow2 *iface, IOmNavigator **p)
724 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
726 TRACE("(%p)->(%p)\n", This, p);
728 *p = OmNavigator_Create();
729 return S_OK;
732 static HRESULT WINAPI HTMLWindow2_put_name(IHTMLWindow2 *iface, BSTR v)
734 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
735 nsAString name_str;
736 nsresult nsres;
738 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
740 nsAString_InitDepend(&name_str, v);
741 nsres = nsIDOMWindow_SetName(This->nswindow, &name_str);
742 nsAString_Finish(&name_str);
743 if(NS_FAILED(nsres))
744 ERR("SetName failed: %08x\n", nsres);
746 return S_OK;
749 static HRESULT WINAPI HTMLWindow2_get_name(IHTMLWindow2 *iface, BSTR *p)
751 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
752 nsAString name_str;
753 nsresult nsres;
754 HRESULT hres;
756 TRACE("(%p)->(%p)\n", This, p);
758 nsAString_Init(&name_str, NULL);
759 nsres = nsIDOMWindow_GetName(This->nswindow, &name_str);
760 if(NS_SUCCEEDED(nsres)) {
761 const PRUnichar *name;
763 nsAString_GetData(&name_str, &name);
764 if(*name) {
765 *p = SysAllocString(name);
766 hres = *p ? S_OK : E_OUTOFMEMORY;
767 }else {
768 *p = NULL;
769 hres = S_OK;
771 }else {
772 ERR("GetName failed: %08x\n", nsres);
773 hres = E_FAIL;
775 nsAString_Finish(&name_str);
777 return hres;
780 static HRESULT WINAPI HTMLWindow2_get_parent(IHTMLWindow2 *iface, IHTMLWindow2 **p)
782 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
783 TRACE("(%p)->(%p)\n", This, p);
785 if(This->parent) {
786 *p = &This->parent->IHTMLWindow2_iface;
787 IHTMLWindow2_AddRef(*p);
788 }else
789 *p = NULL;
791 return S_OK;
794 static HRESULT WINAPI HTMLWindow2_open(IHTMLWindow2 *iface, BSTR url, BSTR name,
795 BSTR features, VARIANT_BOOL replace, IHTMLWindow2 **pomWindowResult)
797 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
798 FIXME("(%p)->(%s %s %s %x %p)\n", This, debugstr_w(url), debugstr_w(name),
799 debugstr_w(features), replace, pomWindowResult);
800 return E_NOTIMPL;
803 static HRESULT WINAPI HTMLWindow2_get_self(IHTMLWindow2 *iface, IHTMLWindow2 **p)
805 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
807 TRACE("(%p)->(%p)\n", This, p);
809 /* FIXME: We should return kind of proxy window here. */
810 IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
811 *p = &This->IHTMLWindow2_iface;
812 return S_OK;
815 static HRESULT WINAPI HTMLWindow2_get_top(IHTMLWindow2 *iface, IHTMLWindow2 **p)
817 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
818 HTMLWindow *curr;
819 TRACE("(%p)->(%p)\n", This, p);
821 curr = This;
822 while(curr->parent)
823 curr = curr->parent;
824 *p = &curr->IHTMLWindow2_iface;
825 IHTMLWindow2_AddRef(*p);
827 return S_OK;
830 static HRESULT WINAPI HTMLWindow2_get_window(IHTMLWindow2 *iface, IHTMLWindow2 **p)
832 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
834 TRACE("(%p)->(%p)\n", This, p);
836 /* FIXME: We should return kind of proxy window here. */
837 IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
838 *p = &This->IHTMLWindow2_iface;
839 return S_OK;
842 static HRESULT WINAPI HTMLWindow2_navigate(IHTMLWindow2 *iface, BSTR url)
844 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
845 FIXME("(%p)->(%s)\n", This, debugstr_w(url));
846 return E_NOTIMPL;
849 static HRESULT WINAPI HTMLWindow2_put_onfocus(IHTMLWindow2 *iface, VARIANT v)
851 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
852 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
853 return E_NOTIMPL;
856 static HRESULT WINAPI HTMLWindow2_get_onfocus(IHTMLWindow2 *iface, VARIANT *p)
858 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
859 FIXME("(%p)->(%p)\n", This, p);
860 return E_NOTIMPL;
863 static HRESULT WINAPI HTMLWindow2_put_onblur(IHTMLWindow2 *iface, VARIANT v)
865 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
866 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
867 return E_NOTIMPL;
870 static HRESULT WINAPI HTMLWindow2_get_onblur(IHTMLWindow2 *iface, VARIANT *p)
872 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
873 FIXME("(%p)->(%p)\n", This, p);
874 return E_NOTIMPL;
877 static HRESULT WINAPI HTMLWindow2_put_onload(IHTMLWindow2 *iface, VARIANT v)
879 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
881 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
883 return set_window_event(This, EVENTID_LOAD, &v);
886 static HRESULT WINAPI HTMLWindow2_get_onload(IHTMLWindow2 *iface, VARIANT *p)
888 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
890 TRACE("(%p)->(%p)\n", This, p);
892 return get_window_event(This, EVENTID_LOAD, p);
895 static HRESULT WINAPI HTMLWindow2_put_onbeforeunload(IHTMLWindow2 *iface, VARIANT v)
897 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
899 TRACE("(%p)->(v(%d))\n", This, V_VT(&v));
901 return set_window_event(This, EVENTID_BEFOREUNLOAD, &v);
904 static HRESULT WINAPI HTMLWindow2_get_onbeforeunload(IHTMLWindow2 *iface, VARIANT *p)
906 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
908 TRACE("(%p)->(%p)\n", This, p);
910 return get_window_event(This, EVENTID_BEFOREUNLOAD, p);
913 static HRESULT WINAPI HTMLWindow2_put_onunload(IHTMLWindow2 *iface, VARIANT v)
915 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
916 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
917 return E_NOTIMPL;
920 static HRESULT WINAPI HTMLWindow2_get_onunload(IHTMLWindow2 *iface, VARIANT *p)
922 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
923 FIXME("(%p)->(%p)\n", This, p);
924 return E_NOTIMPL;
927 static HRESULT WINAPI HTMLWindow2_put_onhelp(IHTMLWindow2 *iface, VARIANT v)
929 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
930 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
931 return E_NOTIMPL;
934 static HRESULT WINAPI HTMLWindow2_get_onhelp(IHTMLWindow2 *iface, VARIANT *p)
936 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
937 FIXME("(%p)->(%p)\n", This, p);
938 return E_NOTIMPL;
941 static HRESULT WINAPI HTMLWindow2_put_onerror(IHTMLWindow2 *iface, VARIANT v)
943 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
944 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
945 return E_NOTIMPL;
948 static HRESULT WINAPI HTMLWindow2_get_onerror(IHTMLWindow2 *iface, VARIANT *p)
950 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
951 FIXME("(%p)->(%p)\n", This, p);
952 return E_NOTIMPL;
955 static HRESULT WINAPI HTMLWindow2_put_onresize(IHTMLWindow2 *iface, VARIANT v)
957 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
959 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
961 return set_window_event(This, EVENTID_RESIZE, &v);
964 static HRESULT WINAPI HTMLWindow2_get_onresize(IHTMLWindow2 *iface, VARIANT *p)
966 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
968 TRACE("(%p)->(%p)\n", This, p);
970 return get_window_event(This, EVENTID_RESIZE, p);
973 static HRESULT WINAPI HTMLWindow2_put_onscroll(IHTMLWindow2 *iface, VARIANT v)
975 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
976 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
977 return E_NOTIMPL;
980 static HRESULT WINAPI HTMLWindow2_get_onscroll(IHTMLWindow2 *iface, VARIANT *p)
982 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
983 FIXME("(%p)->(%p)\n", This, p);
984 return E_NOTIMPL;
987 static HRESULT WINAPI HTMLWindow2_get_document(IHTMLWindow2 *iface, IHTMLDocument2 **p)
989 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
991 TRACE("(%p)->(%p)\n", This, p);
993 if(This->doc) {
994 /* FIXME: We should return a wrapper object here */
995 *p = &This->doc->basedoc.IHTMLDocument2_iface;
996 IHTMLDocument2_AddRef(*p);
997 }else {
998 *p = NULL;
1001 return S_OK;
1004 static HRESULT WINAPI HTMLWindow2_get_event(IHTMLWindow2 *iface, IHTMLEventObj **p)
1006 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1008 TRACE("(%p)->(%p)\n", This, p);
1010 if(This->event)
1011 IHTMLEventObj_AddRef(This->event);
1012 *p = This->event;
1013 return S_OK;
1016 static HRESULT WINAPI HTMLWindow2_get__newEnum(IHTMLWindow2 *iface, IUnknown **p)
1018 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1019 FIXME("(%p)->(%p)\n", This, p);
1020 return E_NOTIMPL;
1023 static HRESULT WINAPI HTMLWindow2_showModalDialog(IHTMLWindow2 *iface, BSTR dialog,
1024 VARIANT *varArgIn, VARIANT *varOptions, VARIANT *varArgOut)
1026 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1027 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(dialog), varArgIn, varOptions, varArgOut);
1028 return E_NOTIMPL;
1031 static HRESULT WINAPI HTMLWindow2_showHelp(IHTMLWindow2 *iface, BSTR helpURL, VARIANT helpArg,
1032 BSTR features)
1034 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1035 FIXME("(%p)->(%s v(%d) %s)\n", This, debugstr_w(helpURL), V_VT(&helpArg), debugstr_w(features));
1036 return E_NOTIMPL;
1039 static HRESULT WINAPI HTMLWindow2_get_screen(IHTMLWindow2 *iface, IHTMLScreen **p)
1041 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1043 TRACE("(%p)->(%p)\n", This, p);
1045 if(!This->screen) {
1046 HRESULT hres;
1048 hres = HTMLScreen_Create(&This->screen);
1049 if(FAILED(hres))
1050 return hres;
1053 *p = This->screen;
1054 IHTMLScreen_AddRef(This->screen);
1055 return S_OK;
1058 static HRESULT WINAPI HTMLWindow2_get_Option(IHTMLWindow2 *iface, IHTMLOptionElementFactory **p)
1060 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1062 TRACE("(%p)->(%p)\n", This, p);
1064 if(!This->option_factory)
1065 This->option_factory = HTMLOptionElementFactory_Create(This);
1067 *p = HTMLOPTFACTORY(This->option_factory);
1068 IHTMLOptionElementFactory_AddRef(*p);
1070 return S_OK;
1073 static HRESULT WINAPI HTMLWindow2_focus(IHTMLWindow2 *iface)
1075 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1076 FIXME("(%p)->()\n", This);
1077 return E_NOTIMPL;
1080 static HRESULT WINAPI HTMLWindow2_get_closed(IHTMLWindow2 *iface, VARIANT_BOOL *p)
1082 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1083 FIXME("(%p)->(%p)\n", This, p);
1084 return E_NOTIMPL;
1087 static HRESULT WINAPI HTMLWindow2_blur(IHTMLWindow2 *iface)
1089 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1090 FIXME("(%p)->()\n", This);
1091 return E_NOTIMPL;
1094 static HRESULT WINAPI HTMLWindow2_scroll(IHTMLWindow2 *iface, LONG x, LONG y)
1096 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1097 FIXME("(%p)->(%d %d)\n", This, x, y);
1098 return E_NOTIMPL;
1101 static HRESULT WINAPI HTMLWindow2_get_clientInformation(IHTMLWindow2 *iface, IOmNavigator **p)
1103 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1104 FIXME("(%p)->(%p)\n", This, p);
1105 return E_NOTIMPL;
1108 static HRESULT WINAPI HTMLWindow2_setInterval(IHTMLWindow2 *iface, BSTR expression,
1109 LONG msec, VARIANT *language, LONG *timerID)
1111 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1112 VARIANT expr;
1114 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
1116 V_VT(&expr) = VT_BSTR;
1117 V_BSTR(&expr) = expression;
1118 return IHTMLWindow3_setInterval(&This->IHTMLWindow3_iface, &expr, msec, language, timerID);
1121 static HRESULT WINAPI HTMLWindow2_clearInterval(IHTMLWindow2 *iface, LONG timerID)
1123 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1125 TRACE("(%p)->(%d)\n", This, timerID);
1127 return clear_task_timer(&This->doc->basedoc, TRUE, timerID);
1130 static HRESULT WINAPI HTMLWindow2_put_offscreenBuffering(IHTMLWindow2 *iface, VARIANT v)
1132 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1133 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
1134 return E_NOTIMPL;
1137 static HRESULT WINAPI HTMLWindow2_get_offscreenBuffering(IHTMLWindow2 *iface, VARIANT *p)
1139 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1140 FIXME("(%p)->(%p)\n", This, p);
1141 return E_NOTIMPL;
1144 static HRESULT WINAPI HTMLWindow2_execScript(IHTMLWindow2 *iface, BSTR scode, BSTR language,
1145 VARIANT *pvarRet)
1147 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1149 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(scode), debugstr_w(language), pvarRet);
1151 return exec_script(This, scode, language, pvarRet);
1154 static HRESULT WINAPI HTMLWindow2_toString(IHTMLWindow2 *iface, BSTR *String)
1156 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1158 static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
1160 TRACE("(%p)->(%p)\n", This, String);
1162 if(!String)
1163 return E_INVALIDARG;
1165 *String = SysAllocString(objectW);
1166 return *String ? S_OK : E_OUTOFMEMORY;
1169 static HRESULT WINAPI HTMLWindow2_scrollBy(IHTMLWindow2 *iface, LONG x, LONG y)
1171 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1172 nsresult nsres;
1174 TRACE("(%p)->(%d %d)\n", This, x, y);
1176 nsres = nsIDOMWindow_ScrollBy(This->nswindow, x, y);
1177 if(NS_FAILED(nsres))
1178 ERR("ScrollBy failed: %08x\n", nsres);
1180 return S_OK;
1183 static HRESULT WINAPI HTMLWindow2_scrollTo(IHTMLWindow2 *iface, LONG x, LONG y)
1185 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1186 nsresult nsres;
1188 TRACE("(%p)->(%d %d)\n", This, x, y);
1190 nsres = nsIDOMWindow_ScrollTo(This->nswindow, x, y);
1191 if(NS_FAILED(nsres))
1192 ERR("ScrollTo failed: %08x\n", nsres);
1194 return S_OK;
1197 static HRESULT WINAPI HTMLWindow2_moveTo(IHTMLWindow2 *iface, LONG x, LONG y)
1199 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1200 FIXME("(%p)->(%d %d)\n", This, x, y);
1201 return E_NOTIMPL;
1204 static HRESULT WINAPI HTMLWindow2_moveBy(IHTMLWindow2 *iface, LONG x, LONG y)
1206 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1207 FIXME("(%p)->(%d %d)\n", This, x, y);
1208 return E_NOTIMPL;
1211 static HRESULT WINAPI HTMLWindow2_resizeTo(IHTMLWindow2 *iface, LONG x, LONG y)
1213 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1214 FIXME("(%p)->(%d %d)\n", This, x, y);
1215 return E_NOTIMPL;
1218 static HRESULT WINAPI HTMLWindow2_resizeBy(IHTMLWindow2 *iface, LONG x, LONG y)
1220 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1221 FIXME("(%p)->(%d %d)\n", This, x, y);
1222 return E_NOTIMPL;
1225 static HRESULT WINAPI HTMLWindow2_get_external(IHTMLWindow2 *iface, IDispatch **p)
1227 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1229 TRACE("(%p)->(%p)\n", This, p);
1231 *p = NULL;
1233 if(!This->doc_obj->hostui)
1234 return S_OK;
1236 return IDocHostUIHandler_GetExternal(This->doc_obj->hostui, p);
1239 static const IHTMLWindow2Vtbl HTMLWindow2Vtbl = {
1240 HTMLWindow2_QueryInterface,
1241 HTMLWindow2_AddRef,
1242 HTMLWindow2_Release,
1243 HTMLWindow2_GetTypeInfoCount,
1244 HTMLWindow2_GetTypeInfo,
1245 HTMLWindow2_GetIDsOfNames,
1246 HTMLWindow2_Invoke,
1247 HTMLWindow2_item,
1248 HTMLWindow2_get_length,
1249 HTMLWindow2_get_frames,
1250 HTMLWindow2_put_defaultStatus,
1251 HTMLWindow2_get_defaultStatus,
1252 HTMLWindow2_put_status,
1253 HTMLWindow2_get_status,
1254 HTMLWindow2_setTimeout,
1255 HTMLWindow2_clearTimeout,
1256 HTMLWindow2_alert,
1257 HTMLWindow2_confirm,
1258 HTMLWindow2_prompt,
1259 HTMLWindow2_get_Image,
1260 HTMLWindow2_get_location,
1261 HTMLWindow2_get_history,
1262 HTMLWindow2_close,
1263 HTMLWindow2_put_opener,
1264 HTMLWindow2_get_opener,
1265 HTMLWindow2_get_navigator,
1266 HTMLWindow2_put_name,
1267 HTMLWindow2_get_name,
1268 HTMLWindow2_get_parent,
1269 HTMLWindow2_open,
1270 HTMLWindow2_get_self,
1271 HTMLWindow2_get_top,
1272 HTMLWindow2_get_window,
1273 HTMLWindow2_navigate,
1274 HTMLWindow2_put_onfocus,
1275 HTMLWindow2_get_onfocus,
1276 HTMLWindow2_put_onblur,
1277 HTMLWindow2_get_onblur,
1278 HTMLWindow2_put_onload,
1279 HTMLWindow2_get_onload,
1280 HTMLWindow2_put_onbeforeunload,
1281 HTMLWindow2_get_onbeforeunload,
1282 HTMLWindow2_put_onunload,
1283 HTMLWindow2_get_onunload,
1284 HTMLWindow2_put_onhelp,
1285 HTMLWindow2_get_onhelp,
1286 HTMLWindow2_put_onerror,
1287 HTMLWindow2_get_onerror,
1288 HTMLWindow2_put_onresize,
1289 HTMLWindow2_get_onresize,
1290 HTMLWindow2_put_onscroll,
1291 HTMLWindow2_get_onscroll,
1292 HTMLWindow2_get_document,
1293 HTMLWindow2_get_event,
1294 HTMLWindow2_get__newEnum,
1295 HTMLWindow2_showModalDialog,
1296 HTMLWindow2_showHelp,
1297 HTMLWindow2_get_screen,
1298 HTMLWindow2_get_Option,
1299 HTMLWindow2_focus,
1300 HTMLWindow2_get_closed,
1301 HTMLWindow2_blur,
1302 HTMLWindow2_scroll,
1303 HTMLWindow2_get_clientInformation,
1304 HTMLWindow2_setInterval,
1305 HTMLWindow2_clearInterval,
1306 HTMLWindow2_put_offscreenBuffering,
1307 HTMLWindow2_get_offscreenBuffering,
1308 HTMLWindow2_execScript,
1309 HTMLWindow2_toString,
1310 HTMLWindow2_scrollBy,
1311 HTMLWindow2_scrollTo,
1312 HTMLWindow2_moveTo,
1313 HTMLWindow2_moveBy,
1314 HTMLWindow2_resizeTo,
1315 HTMLWindow2_resizeBy,
1316 HTMLWindow2_get_external
1319 static inline HTMLWindow *impl_from_IHTMLWindow3(IHTMLWindow3 *iface)
1321 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow3_iface);
1324 static HRESULT WINAPI HTMLWindow3_QueryInterface(IHTMLWindow3 *iface, REFIID riid, void **ppv)
1326 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1328 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1331 static ULONG WINAPI HTMLWindow3_AddRef(IHTMLWindow3 *iface)
1333 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1335 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1338 static ULONG WINAPI HTMLWindow3_Release(IHTMLWindow3 *iface)
1340 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1342 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1345 static HRESULT WINAPI HTMLWindow3_GetTypeInfoCount(IHTMLWindow3 *iface, UINT *pctinfo)
1347 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1349 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
1352 static HRESULT WINAPI HTMLWindow3_GetTypeInfo(IHTMLWindow3 *iface, UINT iTInfo,
1353 LCID lcid, ITypeInfo **ppTInfo)
1355 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1357 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
1360 static HRESULT WINAPI HTMLWindow3_GetIDsOfNames(IHTMLWindow3 *iface, REFIID riid,
1361 LPOLESTR *rgszNames, UINT cNames,
1362 LCID lcid, DISPID *rgDispId)
1364 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1366 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
1369 static HRESULT WINAPI HTMLWindow3_Invoke(IHTMLWindow3 *iface, DISPID dispIdMember,
1370 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1371 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1373 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1375 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
1376 pVarResult, pExcepInfo, puArgErr);
1379 static HRESULT WINAPI HTMLWindow3_get_screenLeft(IHTMLWindow3 *iface, LONG *p)
1381 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1382 FIXME("(%p)->(%p)\n", This, p);
1383 return E_NOTIMPL;
1386 static HRESULT WINAPI HTMLWindow3_get_screenTop(IHTMLWindow3 *iface, LONG *p)
1388 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1389 FIXME("(%p)->(%p)\n", This, p);
1390 return E_NOTIMPL;
1393 static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp, VARIANT_BOOL *pfResult)
1395 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1397 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
1399 if(!This->doc) {
1400 FIXME("No document\n");
1401 return E_FAIL;
1404 return attach_event(&This->doc->body_event_target, NULL, &This->doc->basedoc, event, pDisp, pfResult);
1407 static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
1409 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1410 FIXME("(%p)->()\n", This);
1411 return E_NOTIMPL;
1414 static HRESULT window_set_timer(HTMLWindow *This, VARIANT *expr, LONG msec, VARIANT *language,
1415 BOOL interval, LONG *timer_id)
1417 IDispatch *disp = NULL;
1419 switch(V_VT(expr)) {
1420 case VT_DISPATCH:
1421 disp = V_DISPATCH(expr);
1422 IDispatch_AddRef(disp);
1423 break;
1425 case VT_BSTR:
1426 disp = script_parse_event(This, V_BSTR(expr));
1427 break;
1429 default:
1430 FIXME("unimplemented vt=%d\n", V_VT(expr));
1431 return E_NOTIMPL;
1434 if(!disp)
1435 return E_FAIL;
1437 *timer_id = set_task_timer(&This->doc->basedoc, msec, interval, disp);
1438 IDispatch_Release(disp);
1440 return S_OK;
1443 static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1444 VARIANT *language, LONG *timerID)
1446 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1448 TRACE("(%p)->(%p(%d) %d %p %p)\n", This, expression, V_VT(expression), msec, language, timerID);
1450 return window_set_timer(This, expression, msec, language, FALSE, timerID);
1453 static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1454 VARIANT *language, LONG *timerID)
1456 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1458 TRACE("(%p)->(%p %d %p %p)\n", This, expression, msec, language, timerID);
1460 return window_set_timer(This, expression, msec, language, TRUE, timerID);
1463 static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)
1465 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1466 FIXME("(%p)\n", This);
1467 return E_NOTIMPL;
1470 static HRESULT WINAPI HTMLWindow3_put_onbeforeprint(IHTMLWindow3 *iface, VARIANT v)
1472 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1473 FIXME("(%p)->()\n", This);
1474 return E_NOTIMPL;
1477 static HRESULT WINAPI HTMLWindow3_get_onbeforeprint(IHTMLWindow3 *iface, VARIANT *p)
1479 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1480 FIXME("(%p)->(%p)\n", This, p);
1481 return E_NOTIMPL;
1484 static HRESULT WINAPI HTMLWindow3_put_onafterprint(IHTMLWindow3 *iface, VARIANT v)
1486 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1487 FIXME("(%p)->()\n", This);
1488 return E_NOTIMPL;
1491 static HRESULT WINAPI HTMLWindow3_get_onafterprint(IHTMLWindow3 *iface, VARIANT *p)
1493 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1494 FIXME("(%p)->(%p)\n", This, p);
1495 return E_NOTIMPL;
1498 static HRESULT WINAPI HTMLWindow3_get_clipboardData(IHTMLWindow3 *iface, IHTMLDataTransfer **p)
1500 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1501 FIXME("(%p)->(%p)\n", This, p);
1502 return E_NOTIMPL;
1505 static HRESULT WINAPI HTMLWindow3_showModelessDialog(IHTMLWindow3 *iface, BSTR url,
1506 VARIANT *varArgIn, VARIANT *options, IHTMLWindow2 **pDialog)
1508 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1509 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(url), varArgIn, options, pDialog);
1510 return E_NOTIMPL;
1513 static const IHTMLWindow3Vtbl HTMLWindow3Vtbl = {
1514 HTMLWindow3_QueryInterface,
1515 HTMLWindow3_AddRef,
1516 HTMLWindow3_Release,
1517 HTMLWindow3_GetTypeInfoCount,
1518 HTMLWindow3_GetTypeInfo,
1519 HTMLWindow3_GetIDsOfNames,
1520 HTMLWindow3_Invoke,
1521 HTMLWindow3_get_screenLeft,
1522 HTMLWindow3_get_screenTop,
1523 HTMLWindow3_attachEvent,
1524 HTMLWindow3_detachEvent,
1525 HTMLWindow3_setTimeout,
1526 HTMLWindow3_setInterval,
1527 HTMLWindow3_print,
1528 HTMLWindow3_put_onbeforeprint,
1529 HTMLWindow3_get_onbeforeprint,
1530 HTMLWindow3_put_onafterprint,
1531 HTMLWindow3_get_onafterprint,
1532 HTMLWindow3_get_clipboardData,
1533 HTMLWindow3_showModelessDialog
1536 static inline HTMLWindow *impl_from_IHTMLWindow4(IHTMLWindow4 *iface)
1538 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow4_iface);
1541 static HRESULT WINAPI HTMLWindow4_QueryInterface(IHTMLWindow4 *iface, REFIID riid, void **ppv)
1543 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1545 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1548 static ULONG WINAPI HTMLWindow4_AddRef(IHTMLWindow4 *iface)
1550 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1552 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1555 static ULONG WINAPI HTMLWindow4_Release(IHTMLWindow4 *iface)
1557 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1559 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1562 static HRESULT WINAPI HTMLWindow4_GetTypeInfoCount(IHTMLWindow4 *iface, UINT *pctinfo)
1564 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1566 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
1569 static HRESULT WINAPI HTMLWindow4_GetTypeInfo(IHTMLWindow4 *iface, UINT iTInfo,
1570 LCID lcid, ITypeInfo **ppTInfo)
1572 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1574 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
1577 static HRESULT WINAPI HTMLWindow4_GetIDsOfNames(IHTMLWindow4 *iface, REFIID riid,
1578 LPOLESTR *rgszNames, UINT cNames,
1579 LCID lcid, DISPID *rgDispId)
1581 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1583 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
1586 static HRESULT WINAPI HTMLWindow4_Invoke(IHTMLWindow4 *iface, DISPID dispIdMember,
1587 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1588 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1590 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1592 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
1593 pVarResult, pExcepInfo, puArgErr);
1596 static HRESULT WINAPI HTMLWindow4_createPopup(IHTMLWindow4 *iface, VARIANT *varArgIn,
1597 IDispatch **ppPopup)
1599 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1600 FIXME("(%p)->(%p %p)\n", This, varArgIn, ppPopup);
1601 return E_NOTIMPL;
1604 static HRESULT WINAPI HTMLWindow4_get_frameElement(IHTMLWindow4 *iface, IHTMLFrameBase **p)
1606 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1607 TRACE("(%p)->(%p)\n", This, p);
1609 if(This->frame_element) {
1610 *p = HTMLFRAMEBASE(This->frame_element);
1611 IHTMLFrameBase_AddRef(*p);
1612 }else
1613 *p = NULL;
1615 return S_OK;
1618 static const IHTMLWindow4Vtbl HTMLWindow4Vtbl = {
1619 HTMLWindow4_QueryInterface,
1620 HTMLWindow4_AddRef,
1621 HTMLWindow4_Release,
1622 HTMLWindow4_GetTypeInfoCount,
1623 HTMLWindow4_GetTypeInfo,
1624 HTMLWindow4_GetIDsOfNames,
1625 HTMLWindow4_Invoke,
1626 HTMLWindow4_createPopup,
1627 HTMLWindow4_get_frameElement
1630 static inline HTMLWindow *impl_from_IHTMLPrivateWindow(IHTMLPrivateWindow *iface)
1632 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLPrivateWindow_iface);
1635 static HRESULT WINAPI HTMLPrivateWindow_QueryInterface(IHTMLPrivateWindow *iface, REFIID riid, void **ppv)
1637 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1639 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1642 static ULONG WINAPI HTMLPrivateWindow_AddRef(IHTMLPrivateWindow *iface)
1644 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1646 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1649 static ULONG WINAPI HTMLPrivateWindow_Release(IHTMLPrivateWindow *iface)
1651 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1653 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1656 static HRESULT WINAPI HTMLPrivateWindow_SuperNavigate(IHTMLPrivateWindow *iface, BSTR url, BSTR arg2, BSTR arg3,
1657 BSTR arg4, VARIANT *post_data_var, VARIANT *headers_var, ULONG flags)
1659 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1660 DWORD post_data_size = 0;
1661 BYTE *post_data = NULL;
1662 WCHAR *headers = NULL;
1663 nsChannelBSC *bsc;
1664 IMoniker *mon;
1665 BSTR new_url;
1666 HRESULT hres;
1668 TRACE("(%p)->(%s %s %s %s %s %s %x)\n", This, debugstr_w(url), debugstr_w(arg2), debugstr_w(arg3), debugstr_w(arg4),
1669 debugstr_variant(post_data_var), debugstr_variant(headers_var), flags);
1671 new_url = url;
1672 if(This->doc_obj->hostui) {
1673 OLECHAR *translated_url = NULL;
1675 hres = IDocHostUIHandler_TranslateUrl(This->doc_obj->hostui, 0, url, &translated_url);
1676 if(hres == S_OK && translated_url) {
1677 new_url = SysAllocString(translated_url);
1678 CoTaskMemFree(translated_url);
1682 if(This->doc_obj->client) {
1683 IOleCommandTarget *cmdtrg;
1685 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
1686 if(SUCCEEDED(hres)) {
1687 VARIANT in, out;
1689 V_VT(&in) = VT_BSTR;
1690 V_BSTR(&in) = new_url;
1691 V_VT(&out) = VT_BOOL;
1692 V_BOOL(&out) = VARIANT_TRUE;
1693 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &in, &out);
1694 IOleCommandTarget_Release(cmdtrg);
1695 if(SUCCEEDED(hres))
1696 VariantClear(&out);
1700 /* FIXME: Why not set_ready_state? */
1701 This->readystate = READYSTATE_UNINITIALIZED;
1703 hres = CreateURLMoniker(NULL, new_url, &mon);
1704 if(new_url != url)
1705 SysFreeString(new_url);
1706 if(FAILED(hres))
1707 return hres;
1709 if(post_data_var) {
1710 if(V_VT(post_data_var) == (VT_ARRAY|VT_UI1)) {
1711 SafeArrayAccessData(V_ARRAY(post_data_var), (void**)&post_data);
1712 post_data_size = V_ARRAY(post_data_var)->rgsabound[0].cElements;
1716 if(headers_var && V_VT(headers_var) != VT_EMPTY && V_VT(headers_var) != VT_ERROR) {
1717 if(V_VT(headers_var) != VT_BSTR)
1718 return E_INVALIDARG;
1720 headers = V_BSTR(headers_var);
1723 hres = create_channelbsc(mon, headers, post_data, post_data_size, &bsc);
1724 if(post_data)
1725 SafeArrayUnaccessData(V_ARRAY(post_data_var));
1726 if(FAILED(hres)) {
1727 IMoniker_Release(mon);
1728 return hres;
1731 hres = set_moniker(&This->doc_obj->basedoc, mon, NULL, bsc, TRUE);
1732 if(SUCCEEDED(hres))
1733 hres = async_start_doc_binding(This, bsc);
1735 IUnknown_Release((IUnknown*)bsc);
1736 IMoniker_Release(mon);
1737 return hres;
1740 static HRESULT WINAPI HTMLPrivateWindow_GetPendingUrl(IHTMLPrivateWindow *iface, BSTR *url)
1742 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1743 FIXME("(%p)->(%p)\n", This, url);
1744 return E_NOTIMPL;
1747 static HRESULT WINAPI HTMLPrivateWindow_SetPICSTarget(IHTMLPrivateWindow *iface, IOleCommandTarget *cmdtrg)
1749 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1750 FIXME("(%p)->(%p)\n", This, cmdtrg);
1751 return E_NOTIMPL;
1754 static HRESULT WINAPI HTMLPrivateWindow_PICSComplete(IHTMLPrivateWindow *iface, int arg)
1756 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1757 FIXME("(%p)->(%x)\n", This, arg);
1758 return E_NOTIMPL;
1761 static HRESULT WINAPI HTMLPrivateWindow_FindWindowByName(IHTMLPrivateWindow *iface, LPCWSTR name, IHTMLWindow2 **ret)
1763 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1764 FIXME("(%p)->(%s %p)\n", This, debugstr_w(name), ret);
1765 return E_NOTIMPL;
1768 static HRESULT WINAPI HTMLPrivateWindow_GetAddressBar(IHTMLPrivateWindow *iface, BSTR *url)
1770 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
1771 FIXME("(%p)->(%p)\n", This, url);
1772 return E_NOTIMPL;
1775 static const IHTMLPrivateWindowVtbl HTMLPrivateWindowVtbl = {
1776 HTMLPrivateWindow_QueryInterface,
1777 HTMLPrivateWindow_AddRef,
1778 HTMLPrivateWindow_Release,
1779 HTMLPrivateWindow_SuperNavigate,
1780 HTMLPrivateWindow_GetPendingUrl,
1781 HTMLPrivateWindow_SetPICSTarget,
1782 HTMLPrivateWindow_PICSComplete,
1783 HTMLPrivateWindow_FindWindowByName,
1784 HTMLPrivateWindow_GetAddressBar
1787 #define DISPEX_THIS(iface) DEFINE_THIS(HTMLWindow, IDispatchEx, iface)
1789 static HRESULT WINAPI WindowDispEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1791 HTMLWindow *This = DISPEX_THIS(iface);
1793 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1796 static ULONG WINAPI WindowDispEx_AddRef(IDispatchEx *iface)
1798 HTMLWindow *This = DISPEX_THIS(iface);
1800 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1803 static ULONG WINAPI WindowDispEx_Release(IDispatchEx *iface)
1805 HTMLWindow *This = DISPEX_THIS(iface);
1807 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1810 static HRESULT WINAPI WindowDispEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1812 HTMLWindow *This = DISPEX_THIS(iface);
1814 TRACE("(%p)->(%p)\n", This, pctinfo);
1816 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
1819 static HRESULT WINAPI WindowDispEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1820 LCID lcid, ITypeInfo **ppTInfo)
1822 HTMLWindow *This = DISPEX_THIS(iface);
1824 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1826 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
1829 static HRESULT WINAPI WindowDispEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1830 LPOLESTR *rgszNames, UINT cNames,
1831 LCID lcid, DISPID *rgDispId)
1833 HTMLWindow *This = DISPEX_THIS(iface);
1834 UINT i;
1835 HRESULT hres;
1837 WARN("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1838 lcid, rgDispId);
1840 for(i=0; i < cNames; i++) {
1841 /* We shouldn't use script's IDispatchEx here, so we shouldn't use GetDispID */
1842 hres = IDispatchEx_GetDispID(DISPATCHEX(This), rgszNames[i], 0, rgDispId+i);
1843 if(FAILED(hres))
1844 return hres;
1847 return S_OK;
1850 static HRESULT WINAPI WindowDispEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1851 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1852 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1854 HTMLWindow *This = DISPEX_THIS(iface);
1856 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1857 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1859 /* FIXME: Use script dispatch */
1861 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
1862 pVarResult, pExcepInfo, puArgErr);
1865 static global_prop_t *alloc_global_prop(HTMLWindow *This, global_prop_type_t type, BSTR name)
1867 if(This->global_prop_cnt == This->global_prop_size) {
1868 global_prop_t *new_props;
1869 DWORD new_size;
1871 if(This->global_props) {
1872 new_size = This->global_prop_size*2;
1873 new_props = heap_realloc(This->global_props, new_size*sizeof(global_prop_t));
1874 }else {
1875 new_size = 16;
1876 new_props = heap_alloc(new_size*sizeof(global_prop_t));
1878 if(!new_props)
1879 return NULL;
1880 This->global_props = new_props;
1881 This->global_prop_size = new_size;
1884 This->global_props[This->global_prop_cnt].name = heap_strdupW(name);
1885 if(!This->global_props[This->global_prop_cnt].name)
1886 return NULL;
1888 This->global_props[This->global_prop_cnt].type = type;
1889 return This->global_props + This->global_prop_cnt++;
1892 static inline DWORD prop_to_dispid(HTMLWindow *This, global_prop_t *prop)
1894 return MSHTML_DISPID_CUSTOM_MIN + (prop-This->global_props);
1897 HRESULT search_window_props(HTMLWindow *This, BSTR bstrName, DWORD grfdex, DISPID *pid)
1899 DWORD i;
1900 ScriptHost *script_host;
1901 DISPID id;
1903 for(i=0; i < This->global_prop_cnt; i++) {
1904 /* FIXME: case sensitivity */
1905 if(!strcmpW(This->global_props[i].name, bstrName)) {
1906 *pid = MSHTML_DISPID_CUSTOM_MIN+i;
1907 return S_OK;
1911 if(find_global_prop(This, bstrName, grfdex, &script_host, &id)) {
1912 global_prop_t *prop;
1914 prop = alloc_global_prop(This, GLOBAL_SCRIPTVAR, bstrName);
1915 if(!prop)
1916 return E_OUTOFMEMORY;
1918 prop->script_host = script_host;
1919 prop->id = id;
1921 *pid = prop_to_dispid(This, prop);
1922 return S_OK;
1925 return DISP_E_UNKNOWNNAME;
1928 static HRESULT WINAPI WindowDispEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1930 HTMLWindow *This = DISPEX_THIS(iface);
1931 HRESULT hres;
1933 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
1935 hres = search_window_props(This, bstrName, grfdex, pid);
1936 if(hres != DISP_E_UNKNOWNNAME)
1937 return hres;
1939 hres = IDispatchEx_GetDispID(DISPATCHEX(&This->dispex), bstrName, grfdex, pid);
1940 if(hres != DISP_E_UNKNOWNNAME)
1941 return hres;
1943 if(This->doc) {
1944 global_prop_t *prop;
1945 IHTMLElement *elem;
1947 hres = IHTMLDocument3_getElementById(&This->doc->basedoc.IHTMLDocument3_iface,
1948 bstrName, &elem);
1949 if(SUCCEEDED(hres) && elem) {
1950 IHTMLElement_Release(elem);
1952 prop = alloc_global_prop(This, GLOBAL_ELEMENTVAR, bstrName);
1953 if(!prop)
1954 return E_OUTOFMEMORY;
1956 *pid = prop_to_dispid(This, prop);
1957 return S_OK;
1961 return DISP_E_UNKNOWNNAME;
1964 static HRESULT WINAPI WindowDispEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1965 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1967 HTMLWindow *This = DISPEX_THIS(iface);
1969 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1971 if(id == DISPID_IHTMLWINDOW2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT)) {
1972 HTMLLocation *location;
1973 HRESULT hres;
1975 TRACE("forwarding to location.href\n");
1977 hres = get_location(This, &location);
1978 if(FAILED(hres))
1979 return hres;
1981 hres = IDispatchEx_InvokeEx(DISPATCHEX(&location->dispex), DISPID_VALUE, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1982 IHTMLLocation_Release(HTMLLOCATION(location));
1983 return hres;
1986 return IDispatchEx_InvokeEx(DISPATCHEX(&This->dispex), id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1989 static HRESULT WINAPI WindowDispEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1991 HTMLWindow *This = DISPEX_THIS(iface);
1993 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
1995 return IDispatchEx_DeleteMemberByName(DISPATCHEX(&This->dispex), bstrName, grfdex);
1998 static HRESULT WINAPI WindowDispEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
2000 HTMLWindow *This = DISPEX_THIS(iface);
2002 TRACE("(%p)->(%x)\n", This, id);
2004 return IDispatchEx_DeleteMemberByDispID(DISPATCHEX(&This->dispex), id);
2007 static HRESULT WINAPI WindowDispEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
2009 HTMLWindow *This = DISPEX_THIS(iface);
2011 TRACE("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
2013 return IDispatchEx_GetMemberProperties(DISPATCHEX(&This->dispex), id, grfdexFetch, pgrfdex);
2016 static HRESULT WINAPI WindowDispEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
2018 HTMLWindow *This = DISPEX_THIS(iface);
2020 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
2022 return IDispatchEx_GetMemberName(DISPATCHEX(&This->dispex), id, pbstrName);
2025 static HRESULT WINAPI WindowDispEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
2027 HTMLWindow *This = DISPEX_THIS(iface);
2029 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
2031 return IDispatchEx_GetNextDispID(DISPATCHEX(&This->dispex), grfdex, id, pid);
2034 static HRESULT WINAPI WindowDispEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
2036 HTMLWindow *This = DISPEX_THIS(iface);
2038 TRACE("(%p)->(%p)\n", This, ppunk);
2040 *ppunk = NULL;
2041 return S_OK;
2044 #undef DISPEX_THIS
2046 static const IDispatchExVtbl WindowDispExVtbl = {
2047 WindowDispEx_QueryInterface,
2048 WindowDispEx_AddRef,
2049 WindowDispEx_Release,
2050 WindowDispEx_GetTypeInfoCount,
2051 WindowDispEx_GetTypeInfo,
2052 WindowDispEx_GetIDsOfNames,
2053 WindowDispEx_Invoke,
2054 WindowDispEx_GetDispID,
2055 WindowDispEx_InvokeEx,
2056 WindowDispEx_DeleteMemberByName,
2057 WindowDispEx_DeleteMemberByDispID,
2058 WindowDispEx_GetMemberProperties,
2059 WindowDispEx_GetMemberName,
2060 WindowDispEx_GetNextDispID,
2061 WindowDispEx_GetNameSpaceParent
2064 static inline HTMLWindow *impl_from_IServiceProvider(IServiceProvider *iface)
2066 return CONTAINING_RECORD(iface, HTMLWindow, IServiceProvider_iface);
2069 static HRESULT WINAPI HTMLWindowSP_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
2071 HTMLWindow *This = impl_from_IServiceProvider(iface);
2072 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2075 static ULONG WINAPI HTMLWindowSP_AddRef(IServiceProvider *iface)
2077 HTMLWindow *This = impl_from_IServiceProvider(iface);
2078 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2081 static ULONG WINAPI HTMLWindowSP_Release(IServiceProvider *iface)
2083 HTMLWindow *This = impl_from_IServiceProvider(iface);
2084 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2087 static HRESULT WINAPI HTMLWindowSP_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
2089 HTMLWindow *This = impl_from_IServiceProvider(iface);
2091 if(IsEqualGUID(guidService, &IID_IHTMLWindow2)) {
2092 TRACE("IID_IHTMLWindow2\n");
2093 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2096 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
2098 if(!This->doc_obj)
2099 return E_NOINTERFACE;
2101 return IServiceProvider_QueryService(&This->doc_obj->basedoc.IServiceProvider_iface,
2102 guidService, riid, ppv);
2105 static const IServiceProviderVtbl ServiceProviderVtbl = {
2106 HTMLWindowSP_QueryInterface,
2107 HTMLWindowSP_AddRef,
2108 HTMLWindowSP_Release,
2109 HTMLWindowSP_QueryService
2112 static inline HTMLWindow *impl_from_DispatchEx(DispatchEx *iface)
2114 return CONTAINING_RECORD(iface, HTMLWindow, dispex);
2117 static HRESULT HTMLWindow_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2118 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2120 HTMLWindow *This = impl_from_DispatchEx(dispex);
2121 global_prop_t *prop;
2122 DWORD idx;
2123 HRESULT hres;
2125 idx = id - MSHTML_DISPID_CUSTOM_MIN;
2126 if(idx >= This->global_prop_cnt)
2127 return DISP_E_MEMBERNOTFOUND;
2129 prop = This->global_props+idx;
2131 switch(prop->type) {
2132 case GLOBAL_SCRIPTVAR: {
2133 IDispatchEx *dispex;
2134 IDispatch *disp;
2136 disp = get_script_disp(prop->script_host);
2137 if(!disp)
2138 return E_UNEXPECTED;
2140 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
2141 if(SUCCEEDED(hres)) {
2142 TRACE("%s >>>\n", debugstr_w(prop->name));
2143 hres = IDispatchEx_InvokeEx(dispex, prop->id, lcid, flags, params, res, ei, caller);
2144 if(hres == S_OK)
2145 TRACE("%s <<<\n", debugstr_w(prop->name));
2146 else
2147 WARN("%s <<< %08x\n", debugstr_w(prop->name), hres);
2148 IDispatchEx_Release(dispex);
2149 }else {
2150 FIXME("No IDispatchEx\n");
2152 IDispatch_Release(disp);
2153 break;
2155 case GLOBAL_ELEMENTVAR: {
2156 IHTMLElement *elem;
2158 hres = IHTMLDocument3_getElementById(&This->doc->basedoc.IHTMLDocument3_iface,
2159 prop->name, &elem);
2160 if(FAILED(hres))
2161 return hres;
2163 if(!elem)
2164 return DISP_E_MEMBERNOTFOUND;
2166 V_VT(res) = VT_DISPATCH;
2167 V_DISPATCH(res) = (IDispatch*)elem;
2168 break;
2170 default:
2171 ERR("invalid type %d\n", prop->type);
2172 hres = DISP_E_MEMBERNOTFOUND;
2175 return hres;
2179 static const dispex_static_data_vtbl_t HTMLWindow_dispex_vtbl = {
2180 NULL,
2181 NULL,
2182 HTMLWindow_invoke
2185 static const tid_t HTMLWindow_iface_tids[] = {
2186 IHTMLWindow2_tid,
2187 IHTMLWindow3_tid,
2188 IHTMLWindow4_tid,
2192 static dispex_static_data_t HTMLWindow_dispex = {
2193 &HTMLWindow_dispex_vtbl,
2194 DispHTMLWindow2_tid,
2195 NULL,
2196 HTMLWindow_iface_tids
2199 HRESULT HTMLWindow_Create(HTMLDocumentObj *doc_obj, nsIDOMWindow *nswindow, HTMLWindow *parent, HTMLWindow **ret)
2201 HTMLWindow *window;
2203 window = heap_alloc_zero(sizeof(HTMLWindow));
2204 if(!window)
2205 return E_OUTOFMEMORY;
2207 window->window_ref = heap_alloc(sizeof(windowref_t));
2208 if(!window->window_ref) {
2209 heap_free(window);
2210 return E_OUTOFMEMORY;
2213 window->IHTMLWindow2_iface.lpVtbl = &HTMLWindow2Vtbl;
2214 window->IHTMLWindow3_iface.lpVtbl = &HTMLWindow3Vtbl;
2215 window->IHTMLWindow4_iface.lpVtbl = &HTMLWindow4Vtbl;
2216 window->IHTMLPrivateWindow_iface.lpVtbl = &HTMLPrivateWindowVtbl;
2217 window->lpIDispatchExVtbl = &WindowDispExVtbl;
2218 window->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
2219 window->ref = 1;
2220 window->doc_obj = doc_obj;
2222 window->window_ref->window = window;
2223 window->window_ref->ref = 1;
2225 init_dispex(&window->dispex, (IUnknown*)&window->IHTMLWindow2_iface, &HTMLWindow_dispex);
2227 if(nswindow) {
2228 nsIDOMWindow_AddRef(nswindow);
2229 window->nswindow = nswindow;
2232 window->scriptmode = parent ? parent->scriptmode : SCRIPTMODE_GECKO;
2233 window->readystate = READYSTATE_UNINITIALIZED;
2234 list_init(&window->script_hosts);
2236 window->task_magic = get_task_target_magic();
2237 update_window_doc(window);
2239 list_init(&window->children);
2240 list_add_head(&window_list, &window->entry);
2242 if(parent) {
2243 IHTMLWindow2_AddRef(&window->IHTMLWindow2_iface);
2245 window->parent = parent;
2246 list_add_tail(&parent->children, &window->sibling_entry);
2249 *ret = window;
2250 return S_OK;
2253 void update_window_doc(HTMLWindow *window)
2255 nsIDOMHTMLDocument *nshtmldoc;
2256 nsIDOMDocument *nsdoc;
2257 nsresult nsres;
2259 nsres = nsIDOMWindow_GetDocument(window->nswindow, &nsdoc);
2260 if(NS_FAILED(nsres) || !nsdoc) {
2261 ERR("GetDocument failed: %08x\n", nsres);
2262 return;
2265 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
2266 nsIDOMDocument_Release(nsdoc);
2267 if(NS_FAILED(nsres)) {
2268 ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres);
2269 return;
2272 if(!window->doc || window->doc->nsdoc != nshtmldoc) {
2273 HTMLDocumentNode *doc;
2274 HRESULT hres;
2276 hres = create_doc_from_nsdoc(nshtmldoc, window->doc_obj, window, &doc);
2277 if(SUCCEEDED(hres)) {
2278 window_set_docnode(window, doc);
2279 htmldoc_release(&doc->basedoc);
2280 }else {
2281 ERR("create_doc_from_nsdoc failed: %08x\n", hres);
2285 nsIDOMHTMLDocument_Release(nshtmldoc);
2288 HTMLWindow *nswindow_to_window(const nsIDOMWindow *nswindow)
2290 HTMLWindow *iter;
2292 LIST_FOR_EACH_ENTRY(iter, &window_list, HTMLWindow, entry) {
2293 if(iter->nswindow == nswindow)
2294 return iter;
2297 return NULL;