wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / mshtml / htmlwindow.c
blob9da2f7ccbae5d1f81dda86a5a698a6673d6ff462
1 /*
2 * Copyright 2006-2012 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>
20 #include <assert.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
28 #include "mshtmdid.h"
29 #include "shlguid.h"
30 #include "shobjidl.h"
31 #include "exdispid.h"
33 #define NO_SHLWAPI_REG
34 #include "shlwapi.h"
36 #include "wine/debug.h"
38 #include "mshtml_private.h"
39 #include "htmlevent.h"
40 #include "htmlscript.h"
41 #include "htmlstyle.h"
42 #include "pluginhost.h"
43 #include "binding.h"
44 #include "resource.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
48 static int window_map_compare(const void *key, const struct wine_rb_entry *entry)
50 HTMLOuterWindow *window = WINE_RB_ENTRY_VALUE(entry, HTMLOuterWindow, entry);
52 if(window->window_proxy == key)
53 return 0;
54 return (void*)window->window_proxy > key ? -1 : 1;
57 static struct wine_rb_tree window_map = { window_map_compare };
59 HTMLOuterWindow *mozwindow_to_window(const mozIDOMWindowProxy *mozwindow)
61 struct wine_rb_entry *entry = wine_rb_get(&window_map, mozwindow);
62 return entry ? WINE_RB_ENTRY_VALUE(entry, HTMLOuterWindow, entry) : NULL;
65 static inline BOOL is_outer_window(HTMLWindow *window)
67 return &window->outer_window->base == window;
70 static HRESULT get_location(HTMLInnerWindow *This, HTMLLocation **ret)
72 if(This->location) {
73 IHTMLLocation_AddRef(&This->location->IHTMLLocation_iface);
74 }else {
75 HRESULT hres;
77 hres = HTMLLocation_Create(This, &This->location);
78 if(FAILED(hres))
79 return hres;
82 *ret = This->location;
83 return S_OK;
86 void get_top_window(HTMLOuterWindow *window, HTMLOuterWindow **ret)
88 HTMLOuterWindow *iter;
90 for(iter = window; iter->parent && iter->parent; iter = iter->parent);
91 *ret = iter;
94 static inline HRESULT set_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
96 if(!window->inner_window->doc) {
97 FIXME("No document\n");
98 return E_FAIL;
101 return set_event_handler(&window->inner_window->event_target, eid, var);
104 static inline HRESULT get_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
106 if(!window->inner_window->doc) {
107 FIXME("No document\n");
108 return E_FAIL;
111 return get_event_handler(&window->inner_window->event_target, eid, var);
114 static void detach_inner_window(HTMLInnerWindow *window)
116 HTMLOuterWindow *outer_window = window->base.outer_window;
117 HTMLDocumentNode *doc = window->doc;
119 while(!list_empty(&window->children)) {
120 HTMLOuterWindow *child = LIST_ENTRY(list_tail(&window->children), HTMLOuterWindow, sibling_entry);
122 list_remove(&child->sibling_entry);
123 child->parent = NULL;
125 if(child->base.inner_window)
126 detach_inner_window(child->base.inner_window);
128 IHTMLWindow2_Release(&child->base.IHTMLWindow2_iface);
131 if(outer_window && is_main_content_window(outer_window))
132 window->doc->basedoc.cp_container.forward_container = NULL;
134 if(doc)
135 detach_document_node(doc);
137 abort_window_bindings(window);
138 remove_target_tasks(window->task_magic);
139 release_script_hosts(window);
140 window->base.outer_window = NULL;
142 if(outer_window && outer_window->base.inner_window == window) {
143 outer_window->base.inner_window = NULL;
144 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
148 static inline HTMLWindow *impl_from_IHTMLWindow2(IHTMLWindow2 *iface)
150 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow2_iface);
153 static HRESULT WINAPI HTMLWindow2_QueryInterface(IHTMLWindow2 *iface, REFIID riid, void **ppv)
155 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
157 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
159 if(IsEqualGUID(&IID_IUnknown, riid)) {
160 *ppv = &This->IHTMLWindow2_iface;
161 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
162 *ppv = &This->IHTMLWindow2_iface;
163 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
164 *ppv = &This->IDispatchEx_iface;
165 }else if(IsEqualGUID(&IID_IHTMLFramesCollection2, riid)) {
166 *ppv = &This->IHTMLWindow2_iface;
167 }else if(IsEqualGUID(&IID_IHTMLWindow2, riid)) {
168 *ppv = &This->IHTMLWindow2_iface;
169 }else if(IsEqualGUID(&IID_IHTMLWindow3, riid)) {
170 *ppv = &This->IHTMLWindow3_iface;
171 }else if(IsEqualGUID(&IID_IHTMLWindow4, riid)) {
172 *ppv = &This->IHTMLWindow4_iface;
173 }else if(IsEqualGUID(&IID_IHTMLWindow5, riid)) {
174 *ppv = &This->IHTMLWindow5_iface;
175 }else if(IsEqualGUID(&IID_IHTMLWindow6, riid)) {
176 *ppv = &This->IHTMLWindow6_iface;
177 }else if(IsEqualGUID(&IID_IHTMLWindow7, riid)) {
178 *ppv = &This->IHTMLWindow7_iface;
179 }else if(IsEqualGUID(&IID_IHTMLPrivateWindow, riid)) {
180 *ppv = &This->IHTMLPrivateWindow_iface;
181 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
182 *ppv = &This->IServiceProvider_iface;
183 }else if(IsEqualGUID(&IID_ITravelLogClient, riid)) {
184 *ppv = &This->ITravelLogClient_iface;
185 }else if(IsEqualGUID(&IID_IObjectIdentity, riid)) {
186 *ppv = &This->IObjectIdentity_iface;
187 }else if(IsEqualGUID(&IID_IProvideClassInfo, riid)) {
188 *ppv = &This->IProvideMultipleClassInfo_iface;
189 }else if(IsEqualGUID(&IID_IProvideClassInfo2, riid)) {
190 *ppv = &This->IProvideMultipleClassInfo_iface;
191 }else if(IsEqualGUID(&IID_IProvideMultipleClassInfo, riid)) {
192 *ppv = &This->IProvideMultipleClassInfo_iface;
193 }else if(IsEqualGUID(&IID_IMarshal, riid)) {
194 *ppv = NULL;
195 FIXME("(%p)->(IID_IMarshal %p)\n", This, ppv);
196 return E_NOINTERFACE;
197 }else if(dispex_query_interface(&This->inner_window->event_target.dispex, riid, ppv)) {
198 assert(!*ppv);
199 return E_NOINTERFACE;
200 }else {
201 return EventTarget_QI(&This->inner_window->event_target, riid, ppv);
204 IUnknown_AddRef((IUnknown*)*ppv);
205 return S_OK;
208 static ULONG WINAPI HTMLWindow2_AddRef(IHTMLWindow2 *iface)
210 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
211 LONG ref = InterlockedIncrement(&This->ref);
213 TRACE("(%p) ref=%d\n", This, ref);
215 return ref;
218 static void release_outer_window(HTMLOuterWindow *This)
220 if(This->browser) {
221 list_remove(&This->browser_entry);
222 This->browser = NULL;
225 if(This->pending_window) {
226 abort_window_bindings(This->pending_window);
227 This->pending_window->base.outer_window = NULL;
228 IHTMLWindow2_Release(&This->pending_window->base.IHTMLWindow2_iface);
231 remove_target_tasks(This->task_magic);
232 set_current_mon(This, NULL, 0);
233 set_current_uri(This, NULL);
234 if(This->base.inner_window)
235 detach_inner_window(This->base.inner_window);
237 if(This->frame_element)
238 This->frame_element->content_window = NULL;
240 if(This->nswindow)
241 nsIDOMWindow_Release(This->nswindow);
242 if(This->window_proxy)
243 mozIDOMWindowProxy_Release(This->window_proxy);
245 wine_rb_remove(&window_map, &This->entry);
246 heap_free(This);
249 static void release_inner_window(HTMLInnerWindow *This)
251 unsigned i;
253 TRACE("%p\n", This);
255 detach_inner_window(This);
257 if(This->doc) {
258 This->doc->window = NULL;
259 htmldoc_release(&This->doc->basedoc);
262 release_event_target(&This->event_target);
263 release_dispex(&This->event_target.dispex);
265 for(i=0; i < This->global_prop_cnt; i++)
266 heap_free(This->global_props[i].name);
267 heap_free(This->global_props);
269 if(This->location) {
270 This->location->window = NULL;
271 IHTMLLocation_Release(&This->location->IHTMLLocation_iface);
274 if(This->image_factory) {
275 This->image_factory->window = NULL;
276 IHTMLImageElementFactory_Release(&This->image_factory->IHTMLImageElementFactory_iface);
279 if(This->option_factory) {
280 This->option_factory->window = NULL;
281 IHTMLOptionElementFactory_Release(&This->option_factory->IHTMLOptionElementFactory_iface);
284 if(This->xhr_factory) {
285 This->xhr_factory->window = NULL;
286 IHTMLXMLHttpRequestFactory_Release(&This->xhr_factory->IHTMLXMLHttpRequestFactory_iface);
289 if(This->screen)
290 IHTMLScreen_Release(This->screen);
292 if(This->history) {
293 This->history->window = NULL;
294 IOmHistory_Release(&This->history->IOmHistory_iface);
297 if(This->navigator)
298 IOmNavigator_Release(This->navigator);
299 if(This->session_storage)
300 IHTMLStorage_Release(This->session_storage);
301 if(This->local_storage)
302 IHTMLStorage_Release(This->local_storage);
304 if(This->mon)
305 IMoniker_Release(This->mon);
307 heap_free(This);
310 static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
312 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
313 LONG ref = InterlockedDecrement(&This->ref);
315 TRACE("(%p) ref=%d\n", This, ref);
317 if(!ref) {
318 if(is_outer_window(This))
319 release_outer_window(This->outer_window);
320 else
321 release_inner_window(This->inner_window);
324 return ref;
327 static HRESULT WINAPI HTMLWindow2_GetTypeInfoCount(IHTMLWindow2 *iface, UINT *pctinfo)
329 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
331 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
334 static HRESULT WINAPI HTMLWindow2_GetTypeInfo(IHTMLWindow2 *iface, UINT iTInfo,
335 LCID lcid, ITypeInfo **ppTInfo)
337 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
339 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
342 static HRESULT WINAPI HTMLWindow2_GetIDsOfNames(IHTMLWindow2 *iface, REFIID riid,
343 LPOLESTR *rgszNames, UINT cNames,
344 LCID lcid, DISPID *rgDispId)
346 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
348 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
349 rgDispId);
352 static HRESULT WINAPI HTMLWindow2_Invoke(IHTMLWindow2 *iface, DISPID dispIdMember,
353 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
354 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
356 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
358 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
359 pDispParams, pVarResult, pExcepInfo, puArgErr);
362 static HRESULT get_frame_by_index(HTMLOuterWindow *This, UINT32 index, HTMLOuterWindow **ret)
364 nsIDOMWindowCollection *nsframes;
365 mozIDOMWindowProxy *mozwindow;
366 UINT32 length;
367 nsresult nsres;
369 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsframes);
370 if(NS_FAILED(nsres)) {
371 FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
372 return E_FAIL;
375 nsres = nsIDOMWindowCollection_GetLength(nsframes, &length);
376 assert(nsres == NS_OK);
378 if(index >= length) {
379 nsIDOMWindowCollection_Release(nsframes);
380 return DISP_E_MEMBERNOTFOUND;
383 nsres = nsIDOMWindowCollection_Item(nsframes, index, &mozwindow);
384 nsIDOMWindowCollection_Release(nsframes);
385 if(NS_FAILED(nsres)) {
386 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
387 return E_FAIL;
390 *ret = mozwindow_to_window(mozwindow);
392 mozIDOMWindowProxy_Release(mozwindow);
393 return S_OK;
396 HRESULT get_frame_by_name(HTMLOuterWindow *This, const WCHAR *name, BOOL deep, HTMLOuterWindow **ret)
398 nsIDOMWindowCollection *nsframes;
399 HTMLOuterWindow *window = NULL;
400 mozIDOMWindowProxy *mozwindow;
401 nsAString name_str;
402 UINT32 length, i;
403 nsresult nsres;
404 HRESULT hres = S_OK;
406 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsframes);
407 if(NS_FAILED(nsres)) {
408 FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
409 return E_FAIL;
412 if(!nsframes) {
413 WARN("nsIDOMWindow_GetFrames returned NULL nsframes: %p\n", This->nswindow);
414 return DISP_E_MEMBERNOTFOUND;
417 nsAString_InitDepend(&name_str, name);
418 nsres = nsIDOMWindowCollection_NamedItem(nsframes, &name_str, &mozwindow);
419 nsAString_Finish(&name_str);
420 if(NS_FAILED(nsres)) {
421 nsIDOMWindowCollection_Release(nsframes);
422 return E_FAIL;
425 if(mozwindow) {
426 *ret = mozwindow_to_window(mozwindow);
427 return S_OK;
430 nsres = nsIDOMWindowCollection_GetLength(nsframes, &length);
431 assert(nsres == NS_OK);
433 for(i = 0; i < length && !window; ++i) {
434 HTMLOuterWindow *window_iter;
435 BSTR id;
437 nsres = nsIDOMWindowCollection_Item(nsframes, i, &mozwindow);
438 if(NS_FAILED(nsres)) {
439 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
440 hres = E_FAIL;
441 break;
444 window_iter = mozwindow_to_window(mozwindow);
446 mozIDOMWindowProxy_Release(mozwindow);
448 if(!window_iter) {
449 WARN("nsIDOMWindow without HTMLOuterWindow: %p\n", mozwindow);
450 continue;
453 hres = IHTMLElement_get_id(&window_iter->frame_element->element.IHTMLElement_iface, &id);
454 if(FAILED(hres)) {
455 FIXME("IHTMLElement_get_id failed: 0x%08x\n", hres);
456 break;
459 if(id && !wcsicmp(id, name))
460 window = window_iter;
462 SysFreeString(id);
464 if(!window && deep)
465 get_frame_by_name(window_iter, name, TRUE, &window);
468 nsIDOMWindowCollection_Release(nsframes);
469 if(FAILED(hres))
470 return hres;
472 *ret = window;
473 return S_OK;
476 static HRESULT WINAPI HTMLWindow2_item(IHTMLWindow2 *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
478 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
479 HTMLOuterWindow *window = NULL;
480 HRESULT hres;
482 TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
484 switch(V_VT(pvarIndex)) {
485 case VT_I4: {
486 int index = V_I4(pvarIndex);
487 TRACE("Getting index %d\n", index);
488 if(index < 0)
489 return DISP_E_MEMBERNOTFOUND;
490 hres = get_frame_by_index(This->outer_window, index, &window);
491 break;
493 case VT_UINT: {
494 unsigned int index = V_UINT(pvarIndex);
495 TRACE("Getting index %u\n", index);
496 hres = get_frame_by_index(This->outer_window, index, &window);
497 break;
499 case VT_BSTR: {
500 BSTR str = V_BSTR(pvarIndex);
501 TRACE("Getting name %s\n", wine_dbgstr_w(str));
502 hres = get_frame_by_name(This->outer_window, str, FALSE, &window);
503 break;
505 default:
506 WARN("Invalid index %s\n", debugstr_variant(pvarIndex));
507 return E_INVALIDARG;
510 if(FAILED(hres))
511 return hres;
512 if(!window)
513 return DISP_E_MEMBERNOTFOUND;
515 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
516 V_VT(pvarResult) = VT_DISPATCH;
517 V_DISPATCH(pvarResult) = (IDispatch*)window;
518 return S_OK;
521 static HRESULT WINAPI HTMLWindow2_get_length(IHTMLWindow2 *iface, LONG *p)
523 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
524 nsIDOMWindowCollection *nscollection;
525 UINT32 length;
526 nsresult nsres;
528 TRACE("(%p)->(%p)\n", This, p);
530 nsres = nsIDOMWindow_GetFrames(This->outer_window->nswindow, &nscollection);
531 if(NS_FAILED(nsres)) {
532 ERR("GetFrames failed: %08x\n", nsres);
533 return E_FAIL;
536 nsres = nsIDOMWindowCollection_GetLength(nscollection, &length);
537 nsIDOMWindowCollection_Release(nscollection);
538 if(NS_FAILED(nsres)) {
539 ERR("GetLength failed: %08x\n", nsres);
540 return E_FAIL;
543 *p = length;
544 return S_OK;
547 static HRESULT WINAPI HTMLWindow2_get_frames(IHTMLWindow2 *iface, IHTMLFramesCollection2 **p)
549 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
550 FIXME("(%p)->(%p): semi-stub\n", This, p);
552 /* FIXME: Should return a separate Window object */
553 *p = (IHTMLFramesCollection2*)&This->IHTMLWindow2_iface;
554 IHTMLWindow2_AddRef(iface);
555 return S_OK;
558 static HRESULT WINAPI HTMLWindow2_put_defaultStatus(IHTMLWindow2 *iface, BSTR v)
560 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
561 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
562 return E_NOTIMPL;
565 static HRESULT WINAPI HTMLWindow2_get_defaultStatus(IHTMLWindow2 *iface, BSTR *p)
567 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
568 FIXME("(%p)->(%p)\n", This, p);
569 return E_NOTIMPL;
572 static HRESULT WINAPI HTMLWindow2_put_status(IHTMLWindow2 *iface, BSTR v)
574 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
576 WARN("(%p)->(%s)\n", This, debugstr_w(v));
579 * FIXME: Since IE7, setting status is blocked, but still possible in certain circumstances.
580 * Ignoring the call should be enough for us.
582 return S_OK;
585 static HRESULT WINAPI HTMLWindow2_get_status(IHTMLWindow2 *iface, BSTR *p)
587 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
589 TRACE("(%p)->(%p)\n", This, p);
591 /* See put_status */
592 *p = NULL;
593 return S_OK;
596 static HRESULT WINAPI HTMLWindow2_setTimeout(IHTMLWindow2 *iface, BSTR expression,
597 LONG msec, VARIANT *language, LONG *timerID)
599 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
600 VARIANT expr_var;
602 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
604 V_VT(&expr_var) = VT_BSTR;
605 V_BSTR(&expr_var) = expression;
607 return IHTMLWindow3_setTimeout(&This->IHTMLWindow3_iface, &expr_var, msec, language, timerID);
610 static HRESULT WINAPI HTMLWindow2_clearTimeout(IHTMLWindow2 *iface, LONG timerID)
612 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
614 TRACE("(%p)->(%d)\n", This, timerID);
616 return clear_task_timer(This->inner_window, timerID);
619 #define MAX_MESSAGE_LEN 2000
621 static HRESULT WINAPI HTMLWindow2_alert(IHTMLWindow2 *iface, BSTR message)
623 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
624 WCHAR title[100], *msg = message;
625 DWORD len;
627 TRACE("(%p)->(%s)\n", This, debugstr_w(message));
629 if(!This->outer_window || !This->outer_window->browser)
630 return E_UNEXPECTED;
632 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, title, ARRAY_SIZE(title))) {
633 WARN("Could not load message box title: %d\n", GetLastError());
634 return S_OK;
637 len = SysStringLen(message);
638 if(len > MAX_MESSAGE_LEN) {
639 msg = heap_alloc((MAX_MESSAGE_LEN+1)*sizeof(WCHAR));
640 if(!msg)
641 return E_OUTOFMEMORY;
642 memcpy(msg, message, MAX_MESSAGE_LEN*sizeof(WCHAR));
643 msg[MAX_MESSAGE_LEN] = 0;
646 MessageBoxW(This->outer_window->browser->doc->hwnd, msg, title, MB_ICONWARNING);
647 if(msg != message)
648 heap_free(msg);
649 return S_OK;
652 static HRESULT WINAPI HTMLWindow2_confirm(IHTMLWindow2 *iface, BSTR message,
653 VARIANT_BOOL *confirmed)
655 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
656 WCHAR wszTitle[100];
658 TRACE("(%p)->(%s %p)\n", This, debugstr_w(message), confirmed);
660 if(!confirmed)
661 return E_INVALIDARG;
662 if(!This->outer_window || !This->outer_window->browser)
663 return E_UNEXPECTED;
665 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle, ARRAY_SIZE(wszTitle))) {
666 WARN("Could not load message box title: %d\n", GetLastError());
667 *confirmed = VARIANT_TRUE;
668 return S_OK;
671 if(MessageBoxW(This->outer_window->browser->doc->hwnd, message, wszTitle,
672 MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
673 *confirmed = VARIANT_TRUE;
674 else *confirmed = VARIANT_FALSE;
676 return S_OK;
679 typedef struct
681 BSTR message;
682 BSTR dststr;
683 VARIANT *textdata;
684 }prompt_arg;
686 static INT_PTR CALLBACK prompt_dlgproc(HWND hwnd, UINT msg,
687 WPARAM wparam, LPARAM lparam)
689 switch(msg)
691 case WM_INITDIALOG:
693 prompt_arg *arg = (prompt_arg*)lparam;
694 WCHAR wszTitle[100];
696 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle, ARRAY_SIZE(wszTitle))) {
697 WARN("Could not load message box title: %d\n", GetLastError());
698 EndDialog(hwnd, wparam);
699 return FALSE;
702 SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
703 SetWindowTextW(hwnd, wszTitle);
704 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_PROMPT), arg->message);
705 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_EDIT), arg->dststr);
706 return FALSE;
708 case WM_COMMAND:
709 switch(wparam)
711 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
712 EndDialog(hwnd, wparam);
713 return TRUE;
714 case MAKEWPARAM(IDOK, BN_CLICKED):
716 prompt_arg *arg =
717 (prompt_arg*)GetWindowLongPtrW(hwnd, DWLP_USER);
718 HWND hwndPrompt = GetDlgItem(hwnd, ID_PROMPT_EDIT);
719 INT len = GetWindowTextLengthW(hwndPrompt);
721 if(!arg->textdata)
723 EndDialog(hwnd, wparam);
724 return TRUE;
727 V_VT(arg->textdata) = VT_BSTR;
728 if(!len && !arg->dststr)
729 V_BSTR(arg->textdata) = NULL;
730 else
732 V_BSTR(arg->textdata) = SysAllocStringLen(NULL, len);
733 GetWindowTextW(hwndPrompt, V_BSTR(arg->textdata), len+1);
735 EndDialog(hwnd, wparam);
736 return TRUE;
739 return FALSE;
740 case WM_CLOSE:
741 EndDialog(hwnd, IDCANCEL);
742 return TRUE;
743 default:
744 return FALSE;
748 static HRESULT WINAPI HTMLWindow2_prompt(IHTMLWindow2 *iface, BSTR message,
749 BSTR dststr, VARIANT *textdata)
751 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
752 prompt_arg arg;
754 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(message), debugstr_w(dststr), textdata);
756 if(!This->outer_window || !This->outer_window->browser)
757 return E_UNEXPECTED;
759 if(textdata) V_VT(textdata) = VT_NULL;
761 arg.message = message;
762 arg.dststr = dststr;
763 arg.textdata = textdata;
765 DialogBoxParamW(hInst, MAKEINTRESOURCEW(ID_PROMPT_DIALOG),
766 This->outer_window->browser->doc->hwnd, prompt_dlgproc, (LPARAM)&arg);
767 return S_OK;
770 static HRESULT WINAPI HTMLWindow2_get_Image(IHTMLWindow2 *iface, IHTMLImageElementFactory **p)
772 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
773 HTMLInnerWindow *window = This->inner_window;
775 TRACE("(%p)->(%p)\n", This, p);
777 if(!window->image_factory) {
778 HRESULT hres;
780 hres = HTMLImageElementFactory_Create(window, &window->image_factory);
781 if(FAILED(hres))
782 return hres;
785 *p = &window->image_factory->IHTMLImageElementFactory_iface;
786 IHTMLImageElementFactory_AddRef(*p);
788 return S_OK;
791 static HRESULT WINAPI HTMLWindow2_get_location(IHTMLWindow2 *iface, IHTMLLocation **p)
793 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
794 HTMLLocation *location;
795 HRESULT hres;
797 TRACE("(%p)->(%p)\n", This, p);
799 hres = get_location(This->inner_window, &location);
800 if(FAILED(hres))
801 return hres;
803 *p = &location->IHTMLLocation_iface;
804 return S_OK;
807 static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p)
809 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
810 HTMLInnerWindow *window = This->inner_window;
812 TRACE("(%p)->(%p)\n", This, p);
814 if(!window->history) {
815 HRESULT hres;
817 hres = create_history(window, &window->history);
818 if(FAILED(hres))
819 return hres;
822 IOmHistory_AddRef(&window->history->IOmHistory_iface);
823 *p = &window->history->IOmHistory_iface;
824 return S_OK;
827 static BOOL notify_webbrowser_close(HTMLOuterWindow *window, HTMLDocumentObj *doc)
829 IConnectionPointContainer *cp_container;
830 VARIANT_BOOL cancel = VARIANT_FALSE;
831 IEnumConnections *enum_conn;
832 VARIANT args[2];
833 DISPPARAMS dp = {args, NULL, 2, 0};
834 CONNECTDATA conn_data;
835 IConnectionPoint *cp;
836 IDispatch *disp;
837 ULONG fetched;
838 HRESULT hres;
840 if(!doc->webbrowser)
841 return TRUE;
843 hres = IUnknown_QueryInterface(doc->webbrowser, &IID_IConnectionPointContainer, (void**)&cp_container);
844 if(FAILED(hres))
845 return TRUE;
847 hres = IConnectionPointContainer_FindConnectionPoint(cp_container, &DIID_DWebBrowserEvents2, &cp);
848 IConnectionPointContainer_Release(cp_container);
849 if(FAILED(hres))
850 return TRUE;
852 hres = IConnectionPoint_EnumConnections(cp, &enum_conn);
853 IConnectionPoint_Release(cp);
854 if(FAILED(hres))
855 return TRUE;
857 while(!cancel) {
858 conn_data.pUnk = NULL;
859 conn_data.dwCookie = 0;
860 fetched = 0;
861 hres = IEnumConnections_Next(enum_conn, 1, &conn_data, &fetched);
862 if(hres != S_OK)
863 break;
865 hres = IUnknown_QueryInterface(conn_data.pUnk, &IID_IDispatch, (void**)&disp);
866 IUnknown_Release(conn_data.pUnk);
867 if(FAILED(hres))
868 continue;
870 V_VT(args) = VT_BYREF|VT_BOOL;
871 V_BOOLREF(args) = &cancel;
872 V_VT(args+1) = VT_BOOL;
873 V_BOOL(args+1) = variant_bool(window->parent != NULL);
874 hres = IDispatch_Invoke(disp, DISPID_WINDOWCLOSING, &IID_NULL, 0, DISPATCH_METHOD, &dp, NULL, NULL, NULL);
875 IDispatch_Release(disp);
876 if(FAILED(hres))
877 cancel = VARIANT_FALSE;
880 IEnumConnections_Release(enum_conn);
881 return !cancel;
884 static HRESULT WINAPI HTMLWindow2_close(IHTMLWindow2 *iface)
886 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
887 HTMLOuterWindow *window = This->outer_window;
889 TRACE("(%p)\n", This);
891 if(!window || !window->browser) {
892 FIXME("No document object\n");
893 return E_FAIL;
896 if(!notify_webbrowser_close(window, window->browser->doc))
897 return S_OK;
899 FIXME("default action not implemented\n");
900 return E_NOTIMPL;
903 static HRESULT WINAPI HTMLWindow2_put_opener(IHTMLWindow2 *iface, VARIANT v)
905 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
906 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
907 return E_NOTIMPL;
910 static HRESULT WINAPI HTMLWindow2_get_opener(IHTMLWindow2 *iface, VARIANT *p)
912 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
914 FIXME("(%p)->(%p) returning empty\n", This, p);
916 V_VT(p) = VT_EMPTY;
917 return S_OK;
920 static HRESULT WINAPI HTMLWindow2_get_navigator(IHTMLWindow2 *iface, IOmNavigator **p)
922 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
923 HTMLInnerWindow *window = This->inner_window;
925 TRACE("(%p)->(%p)\n", This, p);
927 if(!window->navigator) {
928 HRESULT hres;
929 hres = create_navigator(dispex_compat_mode(&window->event_target.dispex), &window->navigator);
930 if(FAILED(hres))
931 return hres;
934 IOmNavigator_AddRef(*p = window->navigator);
935 return S_OK;
938 static HRESULT WINAPI HTMLWindow2_put_name(IHTMLWindow2 *iface, BSTR v)
940 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
941 nsAString name_str;
942 nsresult nsres;
944 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
946 nsAString_InitDepend(&name_str, v);
947 nsres = nsIDOMWindow_SetName(This->outer_window->nswindow, &name_str);
948 nsAString_Finish(&name_str);
949 if(NS_FAILED(nsres))
950 ERR("SetName failed: %08x\n", nsres);
952 return S_OK;
955 static HRESULT WINAPI HTMLWindow2_get_name(IHTMLWindow2 *iface, BSTR *p)
957 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
958 nsAString name_str;
959 nsresult nsres;
961 TRACE("(%p)->(%p)\n", This, p);
963 nsAString_Init(&name_str, NULL);
964 nsres = nsIDOMWindow_GetName(This->outer_window->nswindow, &name_str);
965 return return_nsstr(nsres, &name_str, p);
968 static HRESULT WINAPI HTMLWindow2_get_parent(IHTMLWindow2 *iface, IHTMLWindow2 **p)
970 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
971 HTMLOuterWindow *window = This->outer_window;
973 TRACE("(%p)->(%p)\n", This, p);
975 if(!window->parent)
976 return IHTMLWindow2_get_self(&This->IHTMLWindow2_iface, p);
978 *p = &window->parent->base.IHTMLWindow2_iface;
979 IHTMLWindow2_AddRef(*p);
980 return S_OK;
983 static HRESULT WINAPI HTMLWindow2_open(IHTMLWindow2 *iface, BSTR url, BSTR name,
984 BSTR features, VARIANT_BOOL replace, IHTMLWindow2 **pomWindowResult)
986 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
987 HTMLOuterWindow *window = This->outer_window;
988 IUri *uri;
989 HRESULT hres;
991 TRACE("(%p)->(%s %s %s %x %p)\n", This, debugstr_w(url), debugstr_w(name),
992 debugstr_w(features), replace, pomWindowResult);
993 if(features)
994 FIXME("unsupported features argument %s\n", debugstr_w(features));
995 if(replace)
996 FIXME("unsupported relace argument\n");
998 if(!window || !window->browser || !window->uri_nofrag)
999 return E_UNEXPECTED;
1001 if(name && *name == '_') {
1002 if(!wcscmp(name, L"_self")) {
1003 if((features && *features) || replace)
1004 FIXME("Unsupported arguments for _self target\n");
1006 hres = IHTMLWindow2_navigate(&This->IHTMLWindow2_iface, url);
1007 if(FAILED(hres))
1008 return hres;
1010 if(pomWindowResult) {
1011 FIXME("Returning this window for _self target\n");
1012 *pomWindowResult = &This->IHTMLWindow2_iface;
1013 IHTMLWindow2_AddRef(*pomWindowResult);
1016 return S_OK;
1019 FIXME("Unsupported name %s\n", debugstr_w(name));
1020 return E_NOTIMPL;
1023 hres = create_relative_uri(window, url, &uri);
1024 if(FAILED(hres))
1025 return hres;
1027 hres = navigate_new_window(window, uri, name, NULL, pomWindowResult);
1028 IUri_Release(uri);
1029 return hres;
1032 static HRESULT WINAPI HTMLWindow2_get_self(IHTMLWindow2 *iface, IHTMLWindow2 **p)
1034 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1036 TRACE("(%p)->(%p)\n", This, p);
1038 /* FIXME: We should return kind of proxy window here. */
1039 IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1040 *p = &This->IHTMLWindow2_iface;
1041 return S_OK;
1044 static HRESULT WINAPI HTMLWindow2_get_top(IHTMLWindow2 *iface, IHTMLWindow2 **p)
1046 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1047 HTMLOuterWindow *top;
1049 TRACE("(%p)->(%p)\n", This, p);
1051 get_top_window(This->outer_window, &top);
1052 *p = &top->base.IHTMLWindow2_iface;
1053 IHTMLWindow2_AddRef(*p);
1055 return S_OK;
1058 static HRESULT WINAPI HTMLWindow2_get_window(IHTMLWindow2 *iface, IHTMLWindow2 **p)
1060 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1062 TRACE("(%p)->(%p)\n", This, p);
1064 /* FIXME: We should return kind of proxy window here. */
1065 IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1066 *p = &This->IHTMLWindow2_iface;
1067 return S_OK;
1070 static HRESULT WINAPI HTMLWindow2_navigate(IHTMLWindow2 *iface, BSTR url)
1072 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1074 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
1076 return navigate_url(This->outer_window, url, This->outer_window->uri, BINDING_NAVIGATED);
1079 static HRESULT WINAPI HTMLWindow2_put_onfocus(IHTMLWindow2 *iface, VARIANT v)
1081 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1083 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1085 return set_window_event(This, EVENTID_FOCUS, &v);
1088 static HRESULT WINAPI HTMLWindow2_get_onfocus(IHTMLWindow2 *iface, VARIANT *p)
1090 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1092 TRACE("(%p)->(%p)\n", This, p);
1094 return get_window_event(This, EVENTID_FOCUS, p);
1097 static HRESULT WINAPI HTMLWindow2_put_onblur(IHTMLWindow2 *iface, VARIANT v)
1099 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1101 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1103 return set_window_event(This, EVENTID_BLUR, &v);
1106 static HRESULT WINAPI HTMLWindow2_get_onblur(IHTMLWindow2 *iface, VARIANT *p)
1108 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1110 TRACE("(%p)->(%p)\n", This, p);
1112 return get_window_event(This, EVENTID_BLUR, p);
1115 static HRESULT WINAPI HTMLWindow2_put_onload(IHTMLWindow2 *iface, VARIANT v)
1117 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1119 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1121 return set_window_event(This, EVENTID_LOAD, &v);
1124 static HRESULT WINAPI HTMLWindow2_get_onload(IHTMLWindow2 *iface, VARIANT *p)
1126 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1128 TRACE("(%p)->(%p)\n", This, p);
1130 return get_window_event(This, EVENTID_LOAD, p);
1133 static HRESULT WINAPI HTMLWindow2_put_onbeforeunload(IHTMLWindow2 *iface, VARIANT v)
1135 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1137 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1139 return set_window_event(This, EVENTID_BEFOREUNLOAD, &v);
1142 static HRESULT WINAPI HTMLWindow2_get_onbeforeunload(IHTMLWindow2 *iface, VARIANT *p)
1144 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1146 TRACE("(%p)->(%p)\n", This, p);
1148 return get_window_event(This, EVENTID_BEFOREUNLOAD, p);
1151 static HRESULT WINAPI HTMLWindow2_put_onunload(IHTMLWindow2 *iface, VARIANT v)
1153 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1155 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1157 return set_window_event(This, EVENTID_UNLOAD, &v);
1160 static HRESULT WINAPI HTMLWindow2_get_onunload(IHTMLWindow2 *iface, VARIANT *p)
1162 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1164 TRACE("(%p)->(%p)\n", This, p);
1166 return get_window_event(This, EVENTID_UNLOAD, p);
1169 static HRESULT WINAPI HTMLWindow2_put_onhelp(IHTMLWindow2 *iface, VARIANT v)
1171 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1173 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1175 return set_window_event(This, EVENTID_HELP, &v);
1178 static HRESULT WINAPI HTMLWindow2_get_onhelp(IHTMLWindow2 *iface, VARIANT *p)
1180 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1182 TRACE("(%p)->(%p)\n", This, p);
1184 return get_window_event(This, EVENTID_HELP, p);
1187 static HRESULT WINAPI HTMLWindow2_put_onerror(IHTMLWindow2 *iface, VARIANT v)
1189 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1191 FIXME("(%p)->(%s) semi-stub\n", This, debugstr_variant(&v));
1193 return set_window_event(This, EVENTID_ERROR, &v);
1196 static HRESULT WINAPI HTMLWindow2_get_onerror(IHTMLWindow2 *iface, VARIANT *p)
1198 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1200 TRACE("(%p)->(%p)\n", This, p);
1202 return get_window_event(This, EVENTID_ERROR, p);
1205 static HRESULT WINAPI HTMLWindow2_put_onresize(IHTMLWindow2 *iface, VARIANT v)
1207 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1209 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1211 return set_window_event(This, EVENTID_RESIZE, &v);
1214 static HRESULT WINAPI HTMLWindow2_get_onresize(IHTMLWindow2 *iface, VARIANT *p)
1216 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1218 TRACE("(%p)->(%p)\n", This, p);
1220 return get_window_event(This, EVENTID_RESIZE, p);
1223 static HRESULT WINAPI HTMLWindow2_put_onscroll(IHTMLWindow2 *iface, VARIANT v)
1225 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1227 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1229 return set_window_event(This, EVENTID_SCROLL, &v);
1232 static HRESULT WINAPI HTMLWindow2_get_onscroll(IHTMLWindow2 *iface, VARIANT *p)
1234 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1236 TRACE("(%p)->(%p)\n", This, p);
1238 return get_window_event(This, EVENTID_SCROLL, p);
1241 static HRESULT WINAPI HTMLWindow2_get_document(IHTMLWindow2 *iface, IHTMLDocument2 **p)
1243 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1245 TRACE("(%p)->(%p)\n", This, p);
1247 if(This->inner_window->doc) {
1248 /* FIXME: We should return a wrapper object here */
1249 *p = &This->inner_window->doc->basedoc.IHTMLDocument2_iface;
1250 IHTMLDocument2_AddRef(*p);
1251 }else {
1252 *p = NULL;
1255 return S_OK;
1258 IHTMLEventObj *default_set_current_event(HTMLInnerWindow *window, IHTMLEventObj *event_obj)
1260 IHTMLEventObj *prev_event = NULL;
1262 if(window) {
1263 if(event_obj)
1264 IHTMLEventObj_AddRef(event_obj);
1265 prev_event = window->event;
1266 window->event = event_obj;
1269 return prev_event;
1272 static HRESULT WINAPI HTMLWindow2_get_event(IHTMLWindow2 *iface, IHTMLEventObj **p)
1274 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1275 HTMLInnerWindow *window = This->inner_window;
1277 TRACE("(%p)->(%p)\n", This, p);
1279 if(window->event)
1280 IHTMLEventObj_AddRef(window->event);
1281 *p = window->event;
1282 return S_OK;
1285 static HRESULT WINAPI HTMLWindow2_get__newEnum(IHTMLWindow2 *iface, IUnknown **p)
1287 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1288 FIXME("(%p)->(%p)\n", This, p);
1289 return E_NOTIMPL;
1292 static HRESULT WINAPI HTMLWindow2_showModalDialog(IHTMLWindow2 *iface, BSTR dialog,
1293 VARIANT *varArgIn, VARIANT *varOptions, VARIANT *varArgOut)
1295 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1296 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(dialog), varArgIn, varOptions, varArgOut);
1297 return E_NOTIMPL;
1300 static HRESULT WINAPI HTMLWindow2_showHelp(IHTMLWindow2 *iface, BSTR helpURL, VARIANT helpArg,
1301 BSTR features)
1303 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1304 FIXME("(%p)->(%s %s %s)\n", This, debugstr_w(helpURL), debugstr_variant(&helpArg), debugstr_w(features));
1305 return E_NOTIMPL;
1308 static HRESULT WINAPI HTMLWindow2_get_screen(IHTMLWindow2 *iface, IHTMLScreen **p)
1310 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1311 HTMLInnerWindow *window = This->inner_window;
1313 TRACE("(%p)->(%p)\n", This, p);
1315 if(!window->screen) {
1316 HRESULT hres;
1318 hres = create_html_screen(dispex_compat_mode(&window->event_target.dispex), &window->screen);
1319 if(FAILED(hres))
1320 return hres;
1323 *p = window->screen;
1324 IHTMLScreen_AddRef(window->screen);
1325 return S_OK;
1328 static HRESULT WINAPI HTMLWindow2_get_Option(IHTMLWindow2 *iface, IHTMLOptionElementFactory **p)
1330 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1331 HTMLInnerWindow *window = This->inner_window;
1333 TRACE("(%p)->(%p)\n", This, p);
1335 if(!window->option_factory) {
1336 HRESULT hres;
1338 hres = HTMLOptionElementFactory_Create(window, &window->option_factory);
1339 if(FAILED(hres))
1340 return hres;
1343 *p = &window->option_factory->IHTMLOptionElementFactory_iface;
1344 IHTMLOptionElementFactory_AddRef(*p);
1346 return S_OK;
1349 static HRESULT WINAPI HTMLWindow2_focus(IHTMLWindow2 *iface)
1351 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1353 TRACE("(%p)->()\n", This);
1355 if(!This->outer_window || !This->outer_window->browser)
1356 return E_UNEXPECTED;
1358 SetFocus(This->outer_window->browser->doc->hwnd);
1359 return S_OK;
1362 static HRESULT WINAPI HTMLWindow2_get_closed(IHTMLWindow2 *iface, VARIANT_BOOL *p)
1364 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1365 FIXME("(%p)->(%p)\n", This, p);
1366 return E_NOTIMPL;
1369 static HRESULT WINAPI HTMLWindow2_blur(IHTMLWindow2 *iface)
1371 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1372 FIXME("(%p)->()\n", This);
1373 return E_NOTIMPL;
1376 static HRESULT WINAPI HTMLWindow2_scroll(IHTMLWindow2 *iface, LONG x, LONG y)
1378 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1379 nsresult nsres;
1381 TRACE("(%p)->(%d %d)\n", This, x, y);
1383 nsres = nsIDOMWindow_Scroll(This->outer_window->nswindow, x, y);
1384 if(NS_FAILED(nsres)) {
1385 ERR("ScrollBy failed: %08x\n", nsres);
1386 return E_FAIL;
1389 return S_OK;
1392 static HRESULT WINAPI HTMLWindow2_get_clientInformation(IHTMLWindow2 *iface, IOmNavigator **p)
1394 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1396 TRACE("(%p)->(%p)\n", This, p);
1398 return IHTMLWindow2_get_navigator(&This->IHTMLWindow2_iface, p);
1401 static HRESULT WINAPI HTMLWindow2_setInterval(IHTMLWindow2 *iface, BSTR expression,
1402 LONG msec, VARIANT *language, LONG *timerID)
1404 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1405 VARIANT expr;
1407 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
1409 V_VT(&expr) = VT_BSTR;
1410 V_BSTR(&expr) = expression;
1411 return IHTMLWindow3_setInterval(&This->IHTMLWindow3_iface, &expr, msec, language, timerID);
1414 static HRESULT WINAPI HTMLWindow2_clearInterval(IHTMLWindow2 *iface, LONG timerID)
1416 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1418 TRACE("(%p)->(%d)\n", This, timerID);
1420 return clear_task_timer(This->inner_window, timerID);
1423 static HRESULT WINAPI HTMLWindow2_put_offscreenBuffering(IHTMLWindow2 *iface, VARIANT v)
1425 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1426 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1427 return E_NOTIMPL;
1430 static HRESULT WINAPI HTMLWindow2_get_offscreenBuffering(IHTMLWindow2 *iface, VARIANT *p)
1432 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1433 FIXME("(%p)->(%p)\n", This, p);
1434 return E_NOTIMPL;
1437 static HRESULT WINAPI HTMLWindow2_execScript(IHTMLWindow2 *iface, BSTR scode, BSTR language,
1438 VARIANT *pvarRet)
1440 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1442 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(scode), debugstr_w(language), pvarRet);
1444 return exec_script(This->inner_window, scode, language, pvarRet);
1447 static HRESULT WINAPI HTMLWindow2_toString(IHTMLWindow2 *iface, BSTR *String)
1449 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1451 TRACE("(%p)->(%p)\n", This, String);
1453 if(!String)
1454 return E_INVALIDARG;
1456 *String = SysAllocString(L"[object]");
1457 return *String ? S_OK : E_OUTOFMEMORY;
1460 static HRESULT WINAPI HTMLWindow2_scrollBy(IHTMLWindow2 *iface, LONG x, LONG y)
1462 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1463 nsresult nsres;
1465 TRACE("(%p)->(%d %d)\n", This, x, y);
1467 nsres = nsIDOMWindow_ScrollBy(This->outer_window->nswindow, x, y);
1468 if(NS_FAILED(nsres))
1469 ERR("ScrollBy failed: %08x\n", nsres);
1471 return S_OK;
1474 static HRESULT WINAPI HTMLWindow2_scrollTo(IHTMLWindow2 *iface, LONG x, LONG y)
1476 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1477 nsresult nsres;
1479 TRACE("(%p)->(%d %d)\n", This, x, y);
1481 nsres = nsIDOMWindow_ScrollTo(This->outer_window->nswindow, x, y);
1482 if(NS_FAILED(nsres))
1483 ERR("ScrollTo failed: %08x\n", nsres);
1485 return S_OK;
1488 static HRESULT WINAPI HTMLWindow2_moveTo(IHTMLWindow2 *iface, LONG x, LONG y)
1490 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1491 FIXME("(%p)->(%d %d)\n", This, x, y);
1492 return E_NOTIMPL;
1495 static HRESULT WINAPI HTMLWindow2_moveBy(IHTMLWindow2 *iface, LONG x, LONG y)
1497 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1498 FIXME("(%p)->(%d %d)\n", This, x, y);
1499 return S_FALSE;
1502 static HRESULT WINAPI HTMLWindow2_resizeTo(IHTMLWindow2 *iface, LONG x, LONG y)
1504 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1505 FIXME("(%p)->(%d %d)\n", This, x, y);
1506 return E_NOTIMPL;
1509 static HRESULT WINAPI HTMLWindow2_resizeBy(IHTMLWindow2 *iface, LONG x, LONG y)
1511 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1512 FIXME("(%p)->(%d %d)\n", This, x, y);
1513 return S_FALSE;
1516 static HRESULT WINAPI HTMLWindow2_get_external(IHTMLWindow2 *iface, IDispatch **p)
1518 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1520 TRACE("(%p)->(%p)\n", This, p);
1522 if(!This->outer_window || !This->outer_window->browser)
1523 return E_UNEXPECTED;
1525 *p = NULL;
1527 if(!This->outer_window->browser->doc->hostui)
1528 return S_OK;
1530 return IDocHostUIHandler_GetExternal(This->outer_window->browser->doc->hostui, p);
1533 static const IHTMLWindow2Vtbl HTMLWindow2Vtbl = {
1534 HTMLWindow2_QueryInterface,
1535 HTMLWindow2_AddRef,
1536 HTMLWindow2_Release,
1537 HTMLWindow2_GetTypeInfoCount,
1538 HTMLWindow2_GetTypeInfo,
1539 HTMLWindow2_GetIDsOfNames,
1540 HTMLWindow2_Invoke,
1541 HTMLWindow2_item,
1542 HTMLWindow2_get_length,
1543 HTMLWindow2_get_frames,
1544 HTMLWindow2_put_defaultStatus,
1545 HTMLWindow2_get_defaultStatus,
1546 HTMLWindow2_put_status,
1547 HTMLWindow2_get_status,
1548 HTMLWindow2_setTimeout,
1549 HTMLWindow2_clearTimeout,
1550 HTMLWindow2_alert,
1551 HTMLWindow2_confirm,
1552 HTMLWindow2_prompt,
1553 HTMLWindow2_get_Image,
1554 HTMLWindow2_get_location,
1555 HTMLWindow2_get_history,
1556 HTMLWindow2_close,
1557 HTMLWindow2_put_opener,
1558 HTMLWindow2_get_opener,
1559 HTMLWindow2_get_navigator,
1560 HTMLWindow2_put_name,
1561 HTMLWindow2_get_name,
1562 HTMLWindow2_get_parent,
1563 HTMLWindow2_open,
1564 HTMLWindow2_get_self,
1565 HTMLWindow2_get_top,
1566 HTMLWindow2_get_window,
1567 HTMLWindow2_navigate,
1568 HTMLWindow2_put_onfocus,
1569 HTMLWindow2_get_onfocus,
1570 HTMLWindow2_put_onblur,
1571 HTMLWindow2_get_onblur,
1572 HTMLWindow2_put_onload,
1573 HTMLWindow2_get_onload,
1574 HTMLWindow2_put_onbeforeunload,
1575 HTMLWindow2_get_onbeforeunload,
1576 HTMLWindow2_put_onunload,
1577 HTMLWindow2_get_onunload,
1578 HTMLWindow2_put_onhelp,
1579 HTMLWindow2_get_onhelp,
1580 HTMLWindow2_put_onerror,
1581 HTMLWindow2_get_onerror,
1582 HTMLWindow2_put_onresize,
1583 HTMLWindow2_get_onresize,
1584 HTMLWindow2_put_onscroll,
1585 HTMLWindow2_get_onscroll,
1586 HTMLWindow2_get_document,
1587 HTMLWindow2_get_event,
1588 HTMLWindow2_get__newEnum,
1589 HTMLWindow2_showModalDialog,
1590 HTMLWindow2_showHelp,
1591 HTMLWindow2_get_screen,
1592 HTMLWindow2_get_Option,
1593 HTMLWindow2_focus,
1594 HTMLWindow2_get_closed,
1595 HTMLWindow2_blur,
1596 HTMLWindow2_scroll,
1597 HTMLWindow2_get_clientInformation,
1598 HTMLWindow2_setInterval,
1599 HTMLWindow2_clearInterval,
1600 HTMLWindow2_put_offscreenBuffering,
1601 HTMLWindow2_get_offscreenBuffering,
1602 HTMLWindow2_execScript,
1603 HTMLWindow2_toString,
1604 HTMLWindow2_scrollBy,
1605 HTMLWindow2_scrollTo,
1606 HTMLWindow2_moveTo,
1607 HTMLWindow2_moveBy,
1608 HTMLWindow2_resizeTo,
1609 HTMLWindow2_resizeBy,
1610 HTMLWindow2_get_external
1613 static inline HTMLWindow *impl_from_IHTMLWindow3(IHTMLWindow3 *iface)
1615 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow3_iface);
1618 static HRESULT WINAPI HTMLWindow3_QueryInterface(IHTMLWindow3 *iface, REFIID riid, void **ppv)
1620 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1622 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1625 static ULONG WINAPI HTMLWindow3_AddRef(IHTMLWindow3 *iface)
1627 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1629 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1632 static ULONG WINAPI HTMLWindow3_Release(IHTMLWindow3 *iface)
1634 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1636 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1639 static HRESULT WINAPI HTMLWindow3_GetTypeInfoCount(IHTMLWindow3 *iface, UINT *pctinfo)
1641 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1643 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1646 static HRESULT WINAPI HTMLWindow3_GetTypeInfo(IHTMLWindow3 *iface, UINT iTInfo,
1647 LCID lcid, ITypeInfo **ppTInfo)
1649 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1651 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1654 static HRESULT WINAPI HTMLWindow3_GetIDsOfNames(IHTMLWindow3 *iface, REFIID riid,
1655 LPOLESTR *rgszNames, UINT cNames,
1656 LCID lcid, DISPID *rgDispId)
1658 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1660 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1661 rgDispId);
1664 static HRESULT WINAPI HTMLWindow3_Invoke(IHTMLWindow3 *iface, DISPID dispIdMember,
1665 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1666 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1668 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1670 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1671 pDispParams, pVarResult, pExcepInfo, puArgErr);
1674 static HRESULT WINAPI HTMLWindow3_get_screenLeft(IHTMLWindow3 *iface, LONG *p)
1676 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1677 nsresult nsres;
1679 TRACE("(%p)->(%p)\n", This, p);
1681 nsres = nsIDOMWindow_GetScreenX(This->outer_window->nswindow, p);
1682 if(NS_FAILED(nsres)) {
1683 ERR("GetScreenX failed: %08x\n", nsres);
1684 return E_FAIL;
1687 return S_OK;
1690 static HRESULT WINAPI HTMLWindow3_get_screenTop(IHTMLWindow3 *iface, LONG *p)
1692 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1693 nsresult nsres;
1695 TRACE("(%p)->(%p)\n", This, p);
1697 nsres = nsIDOMWindow_GetScreenY(This->outer_window->nswindow, p);
1698 if(NS_FAILED(nsres)) {
1699 ERR("GetScreenY failed: %08x\n", nsres);
1700 return E_FAIL;
1703 return S_OK;
1706 static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp, VARIANT_BOOL *pfResult)
1708 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1709 HTMLInnerWindow *window = This->inner_window;
1711 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
1713 if(!window->doc) {
1714 FIXME("No document\n");
1715 return E_FAIL;
1718 return attach_event(&window->event_target, event, pDisp, pfResult);
1721 static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
1723 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1724 HTMLInnerWindow *window = This->inner_window;
1726 TRACE("(%p)->()\n", This);
1728 if(!window->doc) {
1729 FIXME("No document\n");
1730 return E_FAIL;
1733 return detach_event(&window->event_target, event, pDisp);
1736 static HRESULT window_set_timer(HTMLInnerWindow *This, VARIANT *expr, LONG msec, VARIANT *language,
1737 BOOL interval, LONG *timer_id)
1739 IDispatch *disp = NULL;
1740 HRESULT hres;
1742 switch(V_VT(expr)) {
1743 case VT_DISPATCH:
1744 disp = V_DISPATCH(expr);
1745 IDispatch_AddRef(disp);
1746 break;
1748 case VT_BSTR:
1749 disp = script_parse_event(This->base.inner_window, V_BSTR(expr));
1750 break;
1752 default:
1753 FIXME("unimplemented expr %s\n", debugstr_variant(expr));
1754 return E_NOTIMPL;
1757 if(!disp)
1758 return E_FAIL;
1760 hres = set_task_timer(This, msec, interval, disp, timer_id);
1761 IDispatch_Release(disp);
1763 return hres;
1766 static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1767 VARIANT *language, LONG *timerID)
1769 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1771 TRACE("(%p)->(%s %d %s %p)\n", This, debugstr_variant(expression), msec, debugstr_variant(language), timerID);
1773 return window_set_timer(This->inner_window, expression, msec, language, FALSE, timerID);
1776 static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1777 VARIANT *language, LONG *timerID)
1779 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1781 TRACE("(%p)->(%p %d %p %p)\n", This, expression, msec, language, timerID);
1783 return window_set_timer(This->inner_window, expression, msec, language, TRUE, timerID);
1786 static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)
1788 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1789 FIXME("(%p)\n", This);
1790 return E_NOTIMPL;
1793 static HRESULT WINAPI HTMLWindow3_put_onbeforeprint(IHTMLWindow3 *iface, VARIANT v)
1795 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1796 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1797 return E_NOTIMPL;
1800 static HRESULT WINAPI HTMLWindow3_get_onbeforeprint(IHTMLWindow3 *iface, VARIANT *p)
1802 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1803 FIXME("(%p)->(%p)\n", This, p);
1804 return E_NOTIMPL;
1807 static HRESULT WINAPI HTMLWindow3_put_onafterprint(IHTMLWindow3 *iface, VARIANT v)
1809 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1810 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1811 return E_NOTIMPL;
1814 static HRESULT WINAPI HTMLWindow3_get_onafterprint(IHTMLWindow3 *iface, VARIANT *p)
1816 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1817 FIXME("(%p)->(%p)\n", This, p);
1818 return E_NOTIMPL;
1821 static HRESULT WINAPI HTMLWindow3_get_clipboardData(IHTMLWindow3 *iface, IHTMLDataTransfer **p)
1823 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1824 FIXME("(%p)->(%p)\n", This, p);
1825 return E_NOTIMPL;
1828 static HRESULT WINAPI HTMLWindow3_showModelessDialog(IHTMLWindow3 *iface, BSTR url,
1829 VARIANT *varArgIn, VARIANT *options, IHTMLWindow2 **pDialog)
1831 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1832 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(url), varArgIn, options, pDialog);
1833 return E_NOTIMPL;
1836 static const IHTMLWindow3Vtbl HTMLWindow3Vtbl = {
1837 HTMLWindow3_QueryInterface,
1838 HTMLWindow3_AddRef,
1839 HTMLWindow3_Release,
1840 HTMLWindow3_GetTypeInfoCount,
1841 HTMLWindow3_GetTypeInfo,
1842 HTMLWindow3_GetIDsOfNames,
1843 HTMLWindow3_Invoke,
1844 HTMLWindow3_get_screenLeft,
1845 HTMLWindow3_get_screenTop,
1846 HTMLWindow3_attachEvent,
1847 HTMLWindow3_detachEvent,
1848 HTMLWindow3_setTimeout,
1849 HTMLWindow3_setInterval,
1850 HTMLWindow3_print,
1851 HTMLWindow3_put_onbeforeprint,
1852 HTMLWindow3_get_onbeforeprint,
1853 HTMLWindow3_put_onafterprint,
1854 HTMLWindow3_get_onafterprint,
1855 HTMLWindow3_get_clipboardData,
1856 HTMLWindow3_showModelessDialog
1859 static inline HTMLWindow *impl_from_IHTMLWindow4(IHTMLWindow4 *iface)
1861 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow4_iface);
1864 static HRESULT WINAPI HTMLWindow4_QueryInterface(IHTMLWindow4 *iface, REFIID riid, void **ppv)
1866 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1868 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1871 static ULONG WINAPI HTMLWindow4_AddRef(IHTMLWindow4 *iface)
1873 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1875 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1878 static ULONG WINAPI HTMLWindow4_Release(IHTMLWindow4 *iface)
1880 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1882 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1885 static HRESULT WINAPI HTMLWindow4_GetTypeInfoCount(IHTMLWindow4 *iface, UINT *pctinfo)
1887 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1889 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1892 static HRESULT WINAPI HTMLWindow4_GetTypeInfo(IHTMLWindow4 *iface, UINT iTInfo,
1893 LCID lcid, ITypeInfo **ppTInfo)
1895 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1897 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1900 static HRESULT WINAPI HTMLWindow4_GetIDsOfNames(IHTMLWindow4 *iface, REFIID riid,
1901 LPOLESTR *rgszNames, UINT cNames,
1902 LCID lcid, DISPID *rgDispId)
1904 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1906 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1907 rgDispId);
1910 static HRESULT WINAPI HTMLWindow4_Invoke(IHTMLWindow4 *iface, DISPID dispIdMember,
1911 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1912 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1914 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1916 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1917 pDispParams, pVarResult, pExcepInfo, puArgErr);
1920 static HRESULT WINAPI HTMLWindow4_createPopup(IHTMLWindow4 *iface, VARIANT *varArgIn,
1921 IDispatch **ppPopup)
1923 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1924 FIXME("(%p)->(%p %p)\n", This, varArgIn, ppPopup);
1925 return E_NOTIMPL;
1928 static HRESULT WINAPI HTMLWindow4_get_frameElement(IHTMLWindow4 *iface, IHTMLFrameBase **p)
1930 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1931 TRACE("(%p)->(%p)\n", This, p);
1933 if(This->outer_window->frame_element) {
1934 *p = &This->outer_window->frame_element->IHTMLFrameBase_iface;
1935 IHTMLFrameBase_AddRef(*p);
1936 }else
1937 *p = NULL;
1939 return S_OK;
1942 static const IHTMLWindow4Vtbl HTMLWindow4Vtbl = {
1943 HTMLWindow4_QueryInterface,
1944 HTMLWindow4_AddRef,
1945 HTMLWindow4_Release,
1946 HTMLWindow4_GetTypeInfoCount,
1947 HTMLWindow4_GetTypeInfo,
1948 HTMLWindow4_GetIDsOfNames,
1949 HTMLWindow4_Invoke,
1950 HTMLWindow4_createPopup,
1951 HTMLWindow4_get_frameElement
1954 static inline HTMLWindow *impl_from_IHTMLWindow5(IHTMLWindow5 *iface)
1956 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow5_iface);
1959 static HRESULT WINAPI HTMLWindow5_QueryInterface(IHTMLWindow5 *iface, REFIID riid, void **ppv)
1961 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1963 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1966 static ULONG WINAPI HTMLWindow5_AddRef(IHTMLWindow5 *iface)
1968 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1970 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1973 static ULONG WINAPI HTMLWindow5_Release(IHTMLWindow5 *iface)
1975 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1977 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1980 static HRESULT WINAPI HTMLWindow5_GetTypeInfoCount(IHTMLWindow5 *iface, UINT *pctinfo)
1982 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1984 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1987 static HRESULT WINAPI HTMLWindow5_GetTypeInfo(IHTMLWindow5 *iface, UINT iTInfo,
1988 LCID lcid, ITypeInfo **ppTInfo)
1990 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1992 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1995 static HRESULT WINAPI HTMLWindow5_GetIDsOfNames(IHTMLWindow5 *iface, REFIID riid,
1996 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1998 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
2000 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
2001 rgDispId);
2004 static HRESULT WINAPI HTMLWindow5_Invoke(IHTMLWindow5 *iface, DISPID dispIdMember,
2005 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2006 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2008 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
2010 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
2011 pDispParams, pVarResult, pExcepInfo, puArgErr);
2014 static HRESULT WINAPI HTMLWindow5_put_XMLHttpRequest(IHTMLWindow5 *iface, VARIANT v)
2016 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
2017 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
2018 return E_NOTIMPL;
2021 static HRESULT WINAPI HTMLWindow5_get_XMLHttpRequest(IHTMLWindow5 *iface, VARIANT *p)
2023 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
2024 HTMLInnerWindow *window = This->inner_window;
2026 TRACE("(%p)->(%p)\n", This, p);
2028 if(!window->xhr_factory) {
2029 HRESULT hres;
2031 hres = HTMLXMLHttpRequestFactory_Create(window, &window->xhr_factory);
2032 if(FAILED(hres)) {
2033 return hres;
2037 V_VT(p) = VT_DISPATCH;
2038 V_DISPATCH(p) = (IDispatch*)&window->xhr_factory->IHTMLXMLHttpRequestFactory_iface;
2039 IDispatch_AddRef(V_DISPATCH(p));
2041 return S_OK;
2044 static const IHTMLWindow5Vtbl HTMLWindow5Vtbl = {
2045 HTMLWindow5_QueryInterface,
2046 HTMLWindow5_AddRef,
2047 HTMLWindow5_Release,
2048 HTMLWindow5_GetTypeInfoCount,
2049 HTMLWindow5_GetTypeInfo,
2050 HTMLWindow5_GetIDsOfNames,
2051 HTMLWindow5_Invoke,
2052 HTMLWindow5_put_XMLHttpRequest,
2053 HTMLWindow5_get_XMLHttpRequest
2056 static inline HTMLWindow *impl_from_IHTMLWindow6(IHTMLWindow6 *iface)
2058 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow6_iface);
2061 static HRESULT WINAPI HTMLWindow6_QueryInterface(IHTMLWindow6 *iface, REFIID riid, void **ppv)
2063 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2065 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2068 static ULONG WINAPI HTMLWindow6_AddRef(IHTMLWindow6 *iface)
2070 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2072 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2075 static ULONG WINAPI HTMLWindow6_Release(IHTMLWindow6 *iface)
2077 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2079 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2082 static HRESULT WINAPI HTMLWindow6_GetTypeInfoCount(IHTMLWindow6 *iface, UINT *pctinfo)
2084 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2086 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
2089 static HRESULT WINAPI HTMLWindow6_GetTypeInfo(IHTMLWindow6 *iface, UINT iTInfo,
2090 LCID lcid, ITypeInfo **ppTInfo)
2092 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2094 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2097 static HRESULT WINAPI HTMLWindow6_GetIDsOfNames(IHTMLWindow6 *iface, REFIID riid,
2098 LPOLESTR *rgszNames, UINT cNames,
2099 LCID lcid, DISPID *rgDispId)
2101 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2103 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
2104 rgDispId);
2107 static HRESULT WINAPI HTMLWindow6_Invoke(IHTMLWindow6 *iface, DISPID dispIdMember,
2108 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2109 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2111 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2113 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
2114 pDispParams, pVarResult, pExcepInfo, puArgErr);
2117 static HRESULT WINAPI HTMLWindow6_put_XDomainRequest(IHTMLWindow6 *iface, VARIANT v)
2119 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2120 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
2121 return E_NOTIMPL;
2124 static HRESULT WINAPI HTMLWindow6_get_XDomainRequest(IHTMLWindow6 *iface, VARIANT *p)
2126 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2127 FIXME("(%p)->(%p)\n", This, p);
2128 return E_NOTIMPL;
2131 static HRESULT WINAPI HTMLWindow6_get_sessionStorage(IHTMLWindow6 *iface, IHTMLStorage **p)
2133 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2135 TRACE("(%p)->(%p)\n", This, p);
2137 if(!This->inner_window->session_storage) {
2138 HRESULT hres;
2140 hres = create_html_storage(dispex_compat_mode(&This->inner_window->event_target.dispex),
2141 &This->inner_window->session_storage);
2142 if(FAILED(hres))
2143 return hres;
2146 IHTMLStorage_AddRef(This->inner_window->session_storage);
2147 *p = This->inner_window->session_storage;
2148 return S_OK;
2151 static HRESULT WINAPI HTMLWindow6_get_localStorage(IHTMLWindow6 *iface, IHTMLStorage **p)
2153 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2155 TRACE("(%p)->(%p)\n", This, p);
2157 if(!This->inner_window->local_storage) {
2158 HRESULT hres;
2160 hres = create_html_storage(dispex_compat_mode(&This->inner_window->event_target.dispex),
2161 &This->inner_window->local_storage);
2162 if(FAILED(hres))
2163 return hres;
2166 IHTMLStorage_AddRef(This->inner_window->local_storage);
2167 *p = This->inner_window->local_storage;
2168 return S_OK;
2171 static HRESULT WINAPI HTMLWindow6_put_onhashchange(IHTMLWindow6 *iface, VARIANT v)
2173 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2174 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
2175 return E_NOTIMPL;
2178 static HRESULT WINAPI HTMLWindow6_get_onhashchange(IHTMLWindow6 *iface, VARIANT *p)
2180 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2181 FIXME("(%p)->(%p)\n", This, p);
2182 return E_NOTIMPL;
2185 static HRESULT WINAPI HTMLWindow6_get_maxConnectionsPerServer(IHTMLWindow6 *iface, LONG *p)
2187 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2188 FIXME("(%p)->(%p)\n", This, p);
2189 return E_NOTIMPL;
2192 static HRESULT WINAPI HTMLWindow6_postMessage(IHTMLWindow6 *iface, BSTR msg, VARIANT targetOrigin)
2194 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2195 DOMEvent *event;
2196 HRESULT hres;
2198 FIXME("(%p)->(%s %s) semi-stub\n", This, debugstr_w(msg), debugstr_variant(&targetOrigin));
2200 if(!This->inner_window->doc) {
2201 FIXME("No document\n");
2202 return E_FAIL;
2205 hres = create_document_event(This->inner_window->doc, EVENTID_MESSAGE, &event);
2206 if(FAILED(hres))
2207 return hres;
2209 dispatch_event(&This->inner_window->event_target, event);
2210 IDOMEvent_Release(&event->IDOMEvent_iface);
2211 return S_OK;
2214 static HRESULT WINAPI HTMLWindow6_toStaticHTML(IHTMLWindow6 *iface, BSTR bstrHTML, BSTR *pbstrStaticHTML)
2216 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2217 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrHTML), pbstrStaticHTML);
2218 return E_NOTIMPL;
2221 static HRESULT WINAPI HTMLWindow6_put_onmessage(IHTMLWindow6 *iface, VARIANT v)
2223 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2225 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
2227 return set_window_event(This, EVENTID_MESSAGE, &v);
2230 static HRESULT WINAPI HTMLWindow6_get_onmessage(IHTMLWindow6 *iface, VARIANT *p)
2232 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2234 TRACE("(%p)->(%p)\n", This, p);
2236 return get_window_event(This, EVENTID_MESSAGE, p);
2239 static HRESULT WINAPI HTMLWindow6_msWriteProfilerMark(IHTMLWindow6 *iface, BSTR bstrProfilerMark)
2241 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2242 FIXME("(%p)->(%s)\n", This, debugstr_w(bstrProfilerMark));
2243 return E_NOTIMPL;
2246 static const IHTMLWindow6Vtbl HTMLWindow6Vtbl = {
2247 HTMLWindow6_QueryInterface,
2248 HTMLWindow6_AddRef,
2249 HTMLWindow6_Release,
2250 HTMLWindow6_GetTypeInfoCount,
2251 HTMLWindow6_GetTypeInfo,
2252 HTMLWindow6_GetIDsOfNames,
2253 HTMLWindow6_Invoke,
2254 HTMLWindow6_put_XDomainRequest,
2255 HTMLWindow6_get_XDomainRequest,
2256 HTMLWindow6_get_sessionStorage,
2257 HTMLWindow6_get_localStorage,
2258 HTMLWindow6_put_onhashchange,
2259 HTMLWindow6_get_onhashchange,
2260 HTMLWindow6_get_maxConnectionsPerServer,
2261 HTMLWindow6_postMessage,
2262 HTMLWindow6_toStaticHTML,
2263 HTMLWindow6_put_onmessage,
2264 HTMLWindow6_get_onmessage,
2265 HTMLWindow6_msWriteProfilerMark
2268 static inline HTMLWindow *impl_from_IHTMLWindow7(IHTMLWindow7 *iface)
2270 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow7_iface);
2273 static HRESULT WINAPI HTMLWindow7_QueryInterface(IHTMLWindow7 *iface, REFIID riid, void **ppv)
2275 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2277 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2280 static ULONG WINAPI HTMLWindow7_AddRef(IHTMLWindow7 *iface)
2282 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2283 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2286 static ULONG WINAPI HTMLWindow7_Release(IHTMLWindow7 *iface)
2288 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2289 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2292 static HRESULT WINAPI HTMLWindow7_GetTypeInfoCount(IHTMLWindow7 *iface, UINT *pctinfo)
2294 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2295 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
2298 static HRESULT WINAPI HTMLWindow7_GetTypeInfo(IHTMLWindow7 *iface, UINT iTInfo,
2299 LCID lcid, ITypeInfo **ppTInfo)
2301 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2302 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2305 static HRESULT WINAPI HTMLWindow7_GetIDsOfNames(IHTMLWindow7 *iface, REFIID riid,
2306 LPOLESTR *rgszNames, UINT cNames,
2307 LCID lcid, DISPID *rgDispId)
2309 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2310 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
2311 rgDispId);
2314 static HRESULT WINAPI HTMLWindow7_Invoke(IHTMLWindow7 *iface, DISPID dispIdMember,
2315 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2316 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2318 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2319 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
2320 pDispParams, pVarResult, pExcepInfo, puArgErr);
2323 static HRESULT WINAPI HTMLWindow7_getSelection(IHTMLWindow7 *iface, IHTMLSelection **p)
2325 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2326 FIXME("(%p)->(%p)\n", This, p);
2327 return E_NOTIMPL;
2330 static HRESULT WINAPI HTMLWindow7_getComputedStyle(IHTMLWindow7 *iface, IHTMLDOMNode *node,
2331 BSTR pseudo_elt, IHTMLCSSStyleDeclaration **p)
2333 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2334 nsIDOMCSSStyleDeclaration *nsstyle;
2335 nsAString pseudo_elt_str;
2336 HTMLElement *element;
2337 IHTMLElement *elem;
2338 nsresult nsres;
2339 HRESULT hres;
2341 TRACE("(%p)->(%p %s %p)\n", This, node, debugstr_w(pseudo_elt), p);
2343 if(!This->outer_window || !This->inner_window)
2344 return E_UNEXPECTED;
2346 hres = IHTMLDOMNode_QueryInterface(node, &IID_IHTMLElement, (void**)&elem);
2347 if(FAILED(hres))
2348 return hres;
2350 element = unsafe_impl_from_IHTMLElement(elem);
2351 if(!element) {
2352 WARN("Not our element\n");
2353 IHTMLElement_Release(elem);
2354 return E_INVALIDARG;
2357 nsAString_Init(&pseudo_elt_str, NULL);
2358 nsres = nsIDOMWindow_GetComputedStyle(This->outer_window->nswindow, element->dom_element,
2359 &pseudo_elt_str, &nsstyle);
2360 IHTMLElement_Release(elem);
2361 nsAString_Finish(&pseudo_elt_str);
2362 if(NS_FAILED(nsres)) {
2363 FIXME("GetComputedStyle failed: %08x\n", nsres);
2364 return E_FAIL;
2367 hres = create_computed_style(nsstyle, dispex_compat_mode(&This->inner_window->event_target.dispex), p);
2368 nsIDOMCSSStyleDeclaration_Release(nsstyle);
2369 return hres;
2372 static HRESULT WINAPI HTMLWindow7_get_styleMedia(IHTMLWindow7 *iface, IHTMLStyleMedia **p)
2374 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2375 FIXME("(%p)->(%p)\n", This, p);
2376 return E_NOTIMPL;
2379 static HRESULT WINAPI HTMLWindow7_put_performance(IHTMLWindow7 *iface, VARIANT v)
2381 HTMLInnerWindow *This = impl_from_IHTMLWindow7(iface)->inner_window;
2383 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
2385 if(!This->performance_initialized) {
2386 V_VT(&This->performance) = VT_EMPTY;
2387 This->performance_initialized = TRUE;
2390 return VariantCopy(&This->performance, &v);
2393 static HRESULT WINAPI HTMLWindow7_get_performance(IHTMLWindow7 *iface, VARIANT *p)
2395 HTMLInnerWindow *This = impl_from_IHTMLWindow7(iface)->inner_window;
2396 HRESULT hres;
2398 TRACE("(%p)->(%p)\n", This, p);
2400 if(!This->performance_initialized) {
2401 IHTMLPerformance *performance;
2403 hres = create_performance(dispex_compat_mode(&This->event_target.dispex), &performance);
2404 if(FAILED(hres))
2405 return hres;
2407 V_VT(&This->performance) = VT_DISPATCH;
2408 V_DISPATCH(&This->performance) = (IDispatch*)performance;
2409 This->performance_initialized = TRUE;
2412 V_VT(p) = VT_NULL;
2413 return VariantCopy(p, &This->performance);
2416 static HRESULT WINAPI HTMLWindow7_get_innerWidth(IHTMLWindow7 *iface, LONG *p)
2418 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2419 INT32 ret;
2420 nsresult nsres;
2422 TRACE("(%p)->(%p)\n", This, p);
2424 nsres = nsIDOMWindow_GetInnerWidth(This->outer_window->nswindow, &ret);
2425 if(NS_FAILED(nsres)) {
2426 ERR("GetInnerWidth failed: %08x\n", nsres);
2427 return E_FAIL;
2430 *p = ret;
2431 return S_OK;
2434 static HRESULT WINAPI HTMLWindow7_get_innerHeight(IHTMLWindow7 *iface, LONG *p)
2436 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2437 INT32 ret;
2438 nsresult nsres;
2440 TRACE("(%p)->(%p)\n", This, p);
2442 nsres = nsIDOMWindow_GetInnerHeight(This->outer_window->nswindow, &ret);
2443 if(NS_FAILED(nsres)) {
2444 ERR("GetInnerWidth failed: %08x\n", nsres);
2445 return E_FAIL;
2448 *p = ret;
2449 return S_OK;
2452 static HRESULT WINAPI HTMLWindow7_get_pageXOffset(IHTMLWindow7 *iface, LONG *p)
2454 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2455 nsresult nsres;
2456 INT32 ret;
2458 TRACE("(%p)->(%p)\n", This, p);
2460 nsres = nsIDOMWindow_GetPageXOffset(This->outer_window->nswindow, &ret);
2461 if(NS_FAILED(nsres)) {
2462 ERR("GetPageXOffset failed: %08x\n", nsres);
2463 return E_FAIL;
2466 *p = ret;
2467 return S_OK;
2470 static HRESULT WINAPI HTMLWindow7_get_pageYOffset(IHTMLWindow7 *iface, LONG *p)
2472 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2473 nsresult nsres;
2474 INT32 ret;
2476 TRACE("(%p)->(%p)\n", This, p);
2478 nsres = nsIDOMWindow_GetPageYOffset(This->outer_window->nswindow, &ret);
2479 if(NS_FAILED(nsres)) {
2480 ERR("GetPageYOffset failed: %08x\n", nsres);
2481 return E_FAIL;
2484 *p = ret;
2485 return S_OK;
2488 static HRESULT WINAPI HTMLWindow7_get_screenX(IHTMLWindow7 *iface, LONG *p)
2490 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2491 FIXME("(%p)->(%p)\n", This, p);
2492 return E_NOTIMPL;
2495 static HRESULT WINAPI HTMLWindow7_get_screenY(IHTMLWindow7 *iface, LONG *p)
2497 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2498 FIXME("(%p)->(%p)\n", This, p);
2499 return E_NOTIMPL;
2502 static HRESULT WINAPI HTMLWindow7_get_outerWidth(IHTMLWindow7 *iface, LONG *p)
2504 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2505 FIXME("(%p)->(%p)\n", This, p);
2506 return E_NOTIMPL;
2509 static HRESULT WINAPI HTMLWindow7_get_outerHeight(IHTMLWindow7 *iface, LONG *p)
2511 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2512 FIXME("(%p)->(%p)\n", This, p);
2513 return E_NOTIMPL;
2516 #define HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(name, event_id) \
2517 static HRESULT WINAPI HTMLWindow7_put_on##name(IHTMLWindow7 *iface, VARIANT v) \
2519 HTMLWindow *This = impl_from_IHTMLWindow7(iface); \
2520 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v)); \
2521 return set_window_event(This, event_id, &v); \
2523 static HRESULT WINAPI HTMLWindow7_get_on##name(IHTMLWindow7 *iface, VARIANT *p) \
2525 HTMLWindow *This = impl_from_IHTMLWindow7(iface); \
2526 TRACE("(%p)->(%p)\n", This, p); \
2527 return get_window_event(This, event_id, p); \
2530 #define HTMLWINDOW7_ONEVENT_PROPERTY_STUB(name) \
2531 static HRESULT WINAPI HTMLWindow7_put_on##name(IHTMLWindow7 *iface, VARIANT v) \
2533 HTMLWindow *This = impl_from_IHTMLWindow7(iface); \
2534 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v)); \
2535 return E_NOTIMPL; \
2537 static HRESULT WINAPI HTMLWindow7_get_on##name(IHTMLWindow7 *iface, VARIANT *p) \
2539 HTMLWindow *This = impl_from_IHTMLWindow7(iface); \
2540 FIXME("(%p)->(%p)\n", This, p); \
2541 return E_NOTIMPL; \
2544 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(abort, EVENTID_ABORT)
2545 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(canplay)
2546 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(canplaythrough)
2547 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(change)
2548 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(click)
2549 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(contextmenu, EVENTID_CONTEXTMENU)
2550 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(dblclick, EVENTID_DBLCLICK)
2551 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(drag, EVENTID_DRAG)
2552 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(dragend)
2553 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(dragenter)
2554 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(dragleave)
2555 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(dragover)
2556 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(dragstart, EVENTID_DRAGSTART)
2557 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(drop)
2558 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(durationchange)
2559 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(focusin, EVENTID_FOCUSIN)
2560 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(focusout, EVENTID_FOCUSOUT)
2561 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(input, EVENTID_INPUT)
2562 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(emptied)
2563 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(ended)
2564 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(keydown, EVENTID_KEYDOWN)
2565 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(keypress, EVENTID_KEYPRESS)
2566 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(keyup)
2567 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(loadeddata)
2568 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(loadedmetadata)
2569 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(loadstart)
2570 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(mousedown, EVENTID_MOUSEDOWN)
2571 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(mouseenter)
2572 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(mouseleave)
2573 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(mousemove, EVENTID_MOUSEMOVE)
2574 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(mouseout, EVENTID_MOUSEOUT)
2575 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(mouseover, EVENTID_MOUSEOVER)
2576 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(mouseup, EVENTID_MOUSEUP)
2577 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(mousewheel, EVENTID_MOUSEWHEEL)
2578 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(offline)
2579 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(online)
2580 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(progress)
2581 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(ratechange)
2582 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(readystatechange, EVENTID_READYSTATECHANGE)
2583 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(reset)
2584 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(seeked)
2585 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(seeking)
2586 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(select)
2587 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(stalled)
2588 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(storage)
2589 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(submit, EVENTID_SUBMIT)
2590 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(suspend)
2591 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(timeupdate)
2592 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(pause)
2593 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(play)
2594 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(playing)
2595 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(volumechange)
2596 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(waiting)
2598 static const IHTMLWindow7Vtbl HTMLWindow7Vtbl = {
2599 HTMLWindow7_QueryInterface,
2600 HTMLWindow7_AddRef,
2601 HTMLWindow7_Release,
2602 HTMLWindow7_GetTypeInfoCount,
2603 HTMLWindow7_GetTypeInfo,
2604 HTMLWindow7_GetIDsOfNames,
2605 HTMLWindow7_Invoke,
2606 HTMLWindow7_getSelection,
2607 HTMLWindow7_getComputedStyle,
2608 HTMLWindow7_get_styleMedia,
2609 HTMLWindow7_put_performance,
2610 HTMLWindow7_get_performance,
2611 HTMLWindow7_get_innerWidth,
2612 HTMLWindow7_get_innerHeight,
2613 HTMLWindow7_get_pageXOffset,
2614 HTMLWindow7_get_pageYOffset,
2615 HTMLWindow7_get_screenX,
2616 HTMLWindow7_get_screenY,
2617 HTMLWindow7_get_outerWidth,
2618 HTMLWindow7_get_outerHeight,
2619 HTMLWindow7_put_onabort,
2620 HTMLWindow7_get_onabort,
2621 HTMLWindow7_put_oncanplay,
2622 HTMLWindow7_get_oncanplay,
2623 HTMLWindow7_put_oncanplaythrough,
2624 HTMLWindow7_get_oncanplaythrough,
2625 HTMLWindow7_put_onchange,
2626 HTMLWindow7_get_onchange,
2627 HTMLWindow7_put_onclick,
2628 HTMLWindow7_get_onclick,
2629 HTMLWindow7_put_oncontextmenu,
2630 HTMLWindow7_get_oncontextmenu,
2631 HTMLWindow7_put_ondblclick,
2632 HTMLWindow7_get_ondblclick,
2633 HTMLWindow7_put_ondrag,
2634 HTMLWindow7_get_ondrag,
2635 HTMLWindow7_put_ondragend,
2636 HTMLWindow7_get_ondragend,
2637 HTMLWindow7_put_ondragenter,
2638 HTMLWindow7_get_ondragenter,
2639 HTMLWindow7_put_ondragleave,
2640 HTMLWindow7_get_ondragleave,
2641 HTMLWindow7_put_ondragover,
2642 HTMLWindow7_get_ondragover,
2643 HTMLWindow7_put_ondragstart,
2644 HTMLWindow7_get_ondragstart,
2645 HTMLWindow7_put_ondrop,
2646 HTMLWindow7_get_ondrop,
2647 HTMLWindow7_put_ondurationchange,
2648 HTMLWindow7_get_ondurationchange,
2649 HTMLWindow7_put_onfocusin,
2650 HTMLWindow7_get_onfocusin,
2651 HTMLWindow7_put_onfocusout,
2652 HTMLWindow7_get_onfocusout,
2653 HTMLWindow7_put_oninput,
2654 HTMLWindow7_get_oninput,
2655 HTMLWindow7_put_onemptied,
2656 HTMLWindow7_get_onemptied,
2657 HTMLWindow7_put_onended,
2658 HTMLWindow7_get_onended,
2659 HTMLWindow7_put_onkeydown,
2660 HTMLWindow7_get_onkeydown,
2661 HTMLWindow7_put_onkeypress,
2662 HTMLWindow7_get_onkeypress,
2663 HTMLWindow7_put_onkeyup,
2664 HTMLWindow7_get_onkeyup,
2665 HTMLWindow7_put_onloadeddata,
2666 HTMLWindow7_get_onloadeddata,
2667 HTMLWindow7_put_onloadedmetadata,
2668 HTMLWindow7_get_onloadedmetadata,
2669 HTMLWindow7_put_onloadstart,
2670 HTMLWindow7_get_onloadstart,
2671 HTMLWindow7_put_onmousedown,
2672 HTMLWindow7_get_onmousedown,
2673 HTMLWindow7_put_onmouseenter,
2674 HTMLWindow7_get_onmouseenter,
2675 HTMLWindow7_put_onmouseleave,
2676 HTMLWindow7_get_onmouseleave,
2677 HTMLWindow7_put_onmousemove,
2678 HTMLWindow7_get_onmousemove,
2679 HTMLWindow7_put_onmouseout,
2680 HTMLWindow7_get_onmouseout,
2681 HTMLWindow7_put_onmouseover,
2682 HTMLWindow7_get_onmouseover,
2683 HTMLWindow7_put_onmouseup,
2684 HTMLWindow7_get_onmouseup,
2685 HTMLWindow7_put_onmousewheel,
2686 HTMLWindow7_get_onmousewheel,
2687 HTMLWindow7_put_onoffline,
2688 HTMLWindow7_get_onoffline,
2689 HTMLWindow7_put_ononline,
2690 HTMLWindow7_get_ononline,
2691 HTMLWindow7_put_onprogress,
2692 HTMLWindow7_get_onprogress,
2693 HTMLWindow7_put_onratechange,
2694 HTMLWindow7_get_onratechange,
2695 HTMLWindow7_put_onreadystatechange,
2696 HTMLWindow7_get_onreadystatechange,
2697 HTMLWindow7_put_onreset,
2698 HTMLWindow7_get_onreset,
2699 HTMLWindow7_put_onseeked,
2700 HTMLWindow7_get_onseeked,
2701 HTMLWindow7_put_onseeking,
2702 HTMLWindow7_get_onseeking,
2703 HTMLWindow7_put_onselect,
2704 HTMLWindow7_get_onselect,
2705 HTMLWindow7_put_onstalled,
2706 HTMLWindow7_get_onstalled,
2707 HTMLWindow7_put_onstorage,
2708 HTMLWindow7_get_onstorage,
2709 HTMLWindow7_put_onsubmit,
2710 HTMLWindow7_get_onsubmit,
2711 HTMLWindow7_put_onsuspend,
2712 HTMLWindow7_get_onsuspend,
2713 HTMLWindow7_put_ontimeupdate,
2714 HTMLWindow7_get_ontimeupdate,
2715 HTMLWindow7_put_onpause,
2716 HTMLWindow7_get_onpause,
2717 HTMLWindow7_put_onplay,
2718 HTMLWindow7_get_onplay,
2719 HTMLWindow7_put_onplaying,
2720 HTMLWindow7_get_onplaying,
2721 HTMLWindow7_put_onvolumechange,
2722 HTMLWindow7_get_onvolumechange,
2723 HTMLWindow7_put_onwaiting,
2724 HTMLWindow7_get_onwaiting
2727 static inline HTMLWindow *impl_from_IHTMLPrivateWindow(IHTMLPrivateWindow *iface)
2729 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLPrivateWindow_iface);
2732 static HRESULT WINAPI HTMLPrivateWindow_QueryInterface(IHTMLPrivateWindow *iface, REFIID riid, void **ppv)
2734 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2736 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2739 static ULONG WINAPI HTMLPrivateWindow_AddRef(IHTMLPrivateWindow *iface)
2741 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2743 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2746 static ULONG WINAPI HTMLPrivateWindow_Release(IHTMLPrivateWindow *iface)
2748 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2750 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2753 static HRESULT WINAPI HTMLPrivateWindow_SuperNavigate(IHTMLPrivateWindow *iface, BSTR url, BSTR arg2, BSTR arg3,
2754 BSTR arg4, VARIANT *post_data_var, VARIANT *headers_var, ULONG flags)
2756 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2757 HTMLOuterWindow *window = This->outer_window;
2758 OLECHAR *translated_url = NULL;
2759 DWORD post_data_size = 0;
2760 BYTE *post_data = NULL;
2761 WCHAR *headers = NULL;
2762 IUri *uri;
2763 HRESULT hres;
2765 TRACE("(%p)->(%s %s %s %s %s %s %x)\n", This, debugstr_w(url), debugstr_w(arg2), debugstr_w(arg3), debugstr_w(arg4),
2766 debugstr_variant(post_data_var), debugstr_variant(headers_var), flags);
2768 if(!window || !window->browser)
2769 return E_UNEXPECTED;
2771 if(window->browser->doc->hostui) {
2772 hres = IDocHostUIHandler_TranslateUrl(window->browser->doc->hostui, 0, url, &translated_url);
2773 if(hres != S_OK)
2774 translated_url = NULL;
2777 hres = create_uri(translated_url ? translated_url : url, 0, &uri);
2778 CoTaskMemFree(translated_url);
2779 if(FAILED(hres))
2780 return hres;
2782 if(post_data_var) {
2783 if(V_VT(post_data_var) == (VT_ARRAY|VT_UI1)) {
2784 SafeArrayAccessData(V_ARRAY(post_data_var), (void**)&post_data);
2785 post_data_size = V_ARRAY(post_data_var)->rgsabound[0].cElements;
2789 if(headers_var && V_VT(headers_var) != VT_EMPTY && V_VT(headers_var) != VT_ERROR) {
2790 if(V_VT(headers_var) != VT_BSTR)
2791 return E_INVALIDARG;
2793 headers = V_BSTR(headers_var);
2796 hres = super_navigate(window, uri, BINDING_NAVIGATED|BINDING_NOFRAG, headers, post_data, post_data_size);
2797 IUri_Release(uri);
2798 if(post_data)
2799 SafeArrayUnaccessData(V_ARRAY(post_data_var));
2801 return hres;
2804 static HRESULT WINAPI HTMLPrivateWindow_GetPendingUrl(IHTMLPrivateWindow *iface, BSTR *url)
2806 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2807 FIXME("(%p)->(%p)\n", This, url);
2808 return E_NOTIMPL;
2811 static HRESULT WINAPI HTMLPrivateWindow_SetPICSTarget(IHTMLPrivateWindow *iface, IOleCommandTarget *cmdtrg)
2813 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2814 FIXME("(%p)->(%p)\n", This, cmdtrg);
2815 return E_NOTIMPL;
2818 static HRESULT WINAPI HTMLPrivateWindow_PICSComplete(IHTMLPrivateWindow *iface, int arg)
2820 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2821 FIXME("(%p)->(%x)\n", This, arg);
2822 return E_NOTIMPL;
2825 static HRESULT WINAPI HTMLPrivateWindow_FindWindowByName(IHTMLPrivateWindow *iface, LPCWSTR name, IHTMLWindow2 **ret)
2827 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2828 FIXME("(%p)->(%s %p)\n", This, debugstr_w(name), ret);
2829 return E_NOTIMPL;
2832 static HRESULT WINAPI HTMLPrivateWindow_GetAddressBarUrl(IHTMLPrivateWindow *iface, BSTR *url)
2834 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2835 TRACE("(%p)->(%p)\n", This, url);
2837 if(!url)
2838 return E_INVALIDARG;
2840 *url = SysAllocString(This->outer_window->url);
2841 return S_OK;
2844 static const IHTMLPrivateWindowVtbl HTMLPrivateWindowVtbl = {
2845 HTMLPrivateWindow_QueryInterface,
2846 HTMLPrivateWindow_AddRef,
2847 HTMLPrivateWindow_Release,
2848 HTMLPrivateWindow_SuperNavigate,
2849 HTMLPrivateWindow_GetPendingUrl,
2850 HTMLPrivateWindow_SetPICSTarget,
2851 HTMLPrivateWindow_PICSComplete,
2852 HTMLPrivateWindow_FindWindowByName,
2853 HTMLPrivateWindow_GetAddressBarUrl
2856 static inline HTMLWindow *impl_from_ITravelLogClient(ITravelLogClient *iface)
2858 return CONTAINING_RECORD(iface, HTMLWindow, ITravelLogClient_iface);
2861 static HRESULT WINAPI TravelLogClient_QueryInterface(ITravelLogClient *iface, REFIID riid, void **ppv)
2863 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2865 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2868 static ULONG WINAPI TravelLogClient_AddRef(ITravelLogClient *iface)
2870 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2872 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2875 static ULONG WINAPI TravelLogClient_Release(ITravelLogClient *iface)
2877 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2879 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2882 static HRESULT WINAPI TravelLogClient_FindWindowByIndex(ITravelLogClient *iface, DWORD dwID, IUnknown **ppunk)
2884 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2886 FIXME("(%p)->(%d %p) semi-stub\n", This, dwID, ppunk);
2888 *ppunk = NULL;
2889 return E_FAIL;
2892 static HRESULT WINAPI TravelLogClient_GetWindowData(ITravelLogClient *iface, IStream *pStream, LPWINDOWDATA pWinData)
2894 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2895 FIXME("(%p)->(%p %p)\n", This, pStream, pWinData);
2896 return E_NOTIMPL;
2899 static HRESULT WINAPI TravelLogClient_LoadHistoryPosition(ITravelLogClient *iface, LPWSTR pszUrlLocation, DWORD dwPosition)
2901 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2902 FIXME("(%p)->(%s %d)\n", This, debugstr_w(pszUrlLocation), dwPosition);
2903 return E_NOTIMPL;
2906 static const ITravelLogClientVtbl TravelLogClientVtbl = {
2907 TravelLogClient_QueryInterface,
2908 TravelLogClient_AddRef,
2909 TravelLogClient_Release,
2910 TravelLogClient_FindWindowByIndex,
2911 TravelLogClient_GetWindowData,
2912 TravelLogClient_LoadHistoryPosition
2915 static inline HTMLWindow *impl_from_IObjectIdentity(IObjectIdentity *iface)
2917 return CONTAINING_RECORD(iface, HTMLWindow, IObjectIdentity_iface);
2920 static HRESULT WINAPI ObjectIdentity_QueryInterface(IObjectIdentity *iface, REFIID riid, void **ppv)
2922 HTMLWindow *This = impl_from_IObjectIdentity(iface);
2924 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2927 static ULONG WINAPI ObjectIdentity_AddRef(IObjectIdentity *iface)
2929 HTMLWindow *This = impl_from_IObjectIdentity(iface);
2931 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2934 static ULONG WINAPI ObjectIdentity_Release(IObjectIdentity *iface)
2936 HTMLWindow *This = impl_from_IObjectIdentity(iface);
2938 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2941 static HRESULT WINAPI ObjectIdentity_IsEqualObject(IObjectIdentity *iface, IUnknown *unk)
2943 HTMLWindow *This = impl_from_IObjectIdentity(iface);
2944 IServiceProvider *sp;
2945 HRESULT hres;
2947 TRACE("(%p)->(%p)\n", This, unk);
2949 hres = IUnknown_QueryInterface(unk, &IID_IServiceProvider, (void**)&sp);
2950 if(hres != S_OK)
2951 return hres;
2953 hres = &This->inner_window->base.IServiceProvider_iface==sp ||
2954 &This->outer_window->base.IServiceProvider_iface==sp ? S_OK : S_FALSE;
2955 IServiceProvider_Release(sp);
2956 return hres;
2959 static const IObjectIdentityVtbl ObjectIdentityVtbl = {
2960 ObjectIdentity_QueryInterface,
2961 ObjectIdentity_AddRef,
2962 ObjectIdentity_Release,
2963 ObjectIdentity_IsEqualObject
2966 static inline HTMLWindow *impl_from_IProvideMultipleClassInfo(IProvideMultipleClassInfo *iface)
2968 return CONTAINING_RECORD(iface, HTMLWindow, IProvideMultipleClassInfo_iface);
2971 static HRESULT WINAPI ProvideClassInfo_QueryInterface(IProvideMultipleClassInfo *iface,
2972 REFIID riid, void **ppv)
2974 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
2975 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2978 static ULONG WINAPI ProvideClassInfo_AddRef(IProvideMultipleClassInfo *iface)
2980 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
2981 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2984 static ULONG WINAPI ProvideClassInfo_Release(IProvideMultipleClassInfo *iface)
2986 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
2987 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2990 static HRESULT WINAPI ProvideClassInfo_GetClassInfo(IProvideMultipleClassInfo *iface, ITypeInfo **ppTI)
2992 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
2993 TRACE("(%p)->(%p)\n", This, ppTI);
2994 return get_class_typeinfo(&CLSID_HTMLWindow2, ppTI);
2997 static HRESULT WINAPI ProvideClassInfo2_GetGUID(IProvideMultipleClassInfo *iface, DWORD dwGuidKind, GUID *pGUID)
2999 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
3000 FIXME("(%p)->(%u %p)\n", This, dwGuidKind, pGUID);
3001 return E_NOTIMPL;
3004 static HRESULT WINAPI ProvideMultipleClassInfo_GetMultiTypeInfoCount(IProvideMultipleClassInfo *iface, ULONG *pcti)
3006 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
3007 FIXME("(%p)->(%p)\n", This, pcti);
3008 *pcti = 1;
3009 return S_OK;
3012 static HRESULT WINAPI ProvideMultipleClassInfo_GetInfoOfIndex(IProvideMultipleClassInfo *iface, ULONG iti,
3013 DWORD dwFlags, ITypeInfo **pptiCoClass, DWORD *pdwTIFlags, ULONG *pcdispidReserved, IID *piidPrimary, IID *piidSource)
3015 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
3016 FIXME("(%p)->(%u %x %p %p %p %p %p)\n", This, iti, dwFlags, pptiCoClass, pdwTIFlags, pcdispidReserved, piidPrimary, piidSource);
3017 return E_NOTIMPL;
3020 static const IProvideMultipleClassInfoVtbl ProvideMultipleClassInfoVtbl = {
3021 ProvideClassInfo_QueryInterface,
3022 ProvideClassInfo_AddRef,
3023 ProvideClassInfo_Release,
3024 ProvideClassInfo_GetClassInfo,
3025 ProvideClassInfo2_GetGUID,
3026 ProvideMultipleClassInfo_GetMultiTypeInfoCount,
3027 ProvideMultipleClassInfo_GetInfoOfIndex
3030 static inline HTMLWindow *impl_from_IDispatchEx(IDispatchEx *iface)
3032 return CONTAINING_RECORD(iface, HTMLWindow, IDispatchEx_iface);
3035 static HRESULT WINAPI WindowDispEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
3037 HTMLWindow *This = impl_from_IDispatchEx(iface);
3039 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
3042 static ULONG WINAPI WindowDispEx_AddRef(IDispatchEx *iface)
3044 HTMLWindow *This = impl_from_IDispatchEx(iface);
3046 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
3049 static ULONG WINAPI WindowDispEx_Release(IDispatchEx *iface)
3051 HTMLWindow *This = impl_from_IDispatchEx(iface);
3053 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
3056 static HRESULT WINAPI WindowDispEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
3058 HTMLWindow *This = impl_from_IDispatchEx(iface);
3060 TRACE("(%p)->(%p)\n", This, pctinfo);
3062 return IDispatchEx_GetTypeInfoCount(&This->inner_window->event_target.dispex.IDispatchEx_iface, pctinfo);
3065 static HRESULT WINAPI WindowDispEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
3066 LCID lcid, ITypeInfo **ppTInfo)
3068 HTMLWindow *This = impl_from_IDispatchEx(iface);
3070 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
3072 return IDispatchEx_GetTypeInfo(&This->inner_window->event_target.dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
3075 static HRESULT WINAPI WindowDispEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
3076 LPOLESTR *rgszNames, UINT cNames,
3077 LCID lcid, DISPID *rgDispId)
3079 HTMLWindow *This = impl_from_IDispatchEx(iface);
3080 UINT i;
3081 HRESULT hres;
3083 WARN("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
3085 for(i=0; i < cNames; i++) {
3086 /* We shouldn't use script's IDispatchEx here, so we shouldn't use GetDispID */
3087 hres = IDispatchEx_GetDispID(&This->IDispatchEx_iface, rgszNames[i], 0, rgDispId+i);
3088 if(FAILED(hres))
3089 return hres;
3092 return S_OK;
3095 static HRESULT WINAPI WindowDispEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
3096 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
3097 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
3099 HTMLWindow *This = impl_from_IDispatchEx(iface);
3101 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
3102 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3104 /* FIXME: Use script dispatch */
3106 return IDispatchEx_Invoke(&This->inner_window->event_target.dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
3107 pDispParams, pVarResult, pExcepInfo, puArgErr);
3110 static global_prop_t *alloc_global_prop(HTMLInnerWindow *This, global_prop_type_t type, BSTR name)
3112 if(This->global_prop_cnt == This->global_prop_size) {
3113 global_prop_t *new_props;
3114 DWORD new_size;
3116 if(This->global_props) {
3117 new_size = This->global_prop_size*2;
3118 new_props = heap_realloc(This->global_props, new_size*sizeof(global_prop_t));
3119 }else {
3120 new_size = 16;
3121 new_props = heap_alloc(new_size*sizeof(global_prop_t));
3123 if(!new_props)
3124 return NULL;
3125 This->global_props = new_props;
3126 This->global_prop_size = new_size;
3129 This->global_props[This->global_prop_cnt].name = heap_strdupW(name);
3130 if(!This->global_props[This->global_prop_cnt].name)
3131 return NULL;
3133 This->global_props[This->global_prop_cnt].type = type;
3134 return This->global_props + This->global_prop_cnt++;
3137 static inline DWORD prop_to_dispid(HTMLInnerWindow *This, global_prop_t *prop)
3139 return MSHTML_DISPID_CUSTOM_MIN + (prop-This->global_props);
3142 HRESULT search_window_props(HTMLInnerWindow *This, BSTR bstrName, DWORD grfdex, DISPID *pid)
3144 DWORD i;
3145 ScriptHost *script_host;
3146 DISPID id;
3148 for(i=0; i < This->global_prop_cnt; i++) {
3149 /* FIXME: case sensitivity */
3150 if(!wcscmp(This->global_props[i].name, bstrName)) {
3151 *pid = MSHTML_DISPID_CUSTOM_MIN+i;
3152 return S_OK;
3156 if(find_global_prop(This->base.inner_window, bstrName, grfdex, &script_host, &id)) {
3157 global_prop_t *prop;
3159 prop = alloc_global_prop(This, GLOBAL_SCRIPTVAR, bstrName);
3160 if(!prop)
3161 return E_OUTOFMEMORY;
3163 prop->script_host = script_host;
3164 prop->id = id;
3166 *pid = prop_to_dispid(This, prop);
3167 return S_OK;
3170 return DISP_E_UNKNOWNNAME;
3173 static HRESULT WINAPI WindowDispEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
3175 HTMLWindow *This = impl_from_IDispatchEx(iface);
3176 HTMLInnerWindow *window = This->inner_window;
3177 HRESULT hres;
3179 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
3181 hres = search_window_props(window, bstrName, grfdex, pid);
3182 if(hres != DISP_E_UNKNOWNNAME)
3183 return hres;
3185 hres = IDispatchEx_GetDispID(&window->base.inner_window->event_target.dispex.IDispatchEx_iface, bstrName, grfdex, pid);
3186 if(hres != DISP_E_UNKNOWNNAME)
3187 return hres;
3189 if(This->outer_window) {
3190 HTMLOuterWindow *frame;
3192 hres = get_frame_by_name(This->outer_window, bstrName, FALSE, &frame);
3193 if(SUCCEEDED(hres) && frame) {
3194 global_prop_t *prop;
3196 IHTMLWindow2_Release(&frame->base.IHTMLWindow2_iface);
3198 prop = alloc_global_prop(window, GLOBAL_FRAMEVAR, bstrName);
3199 if(!prop)
3200 return E_OUTOFMEMORY;
3202 *pid = prop_to_dispid(window, prop);
3203 return S_OK;
3207 if(window->doc) {
3208 global_prop_t *prop;
3209 IHTMLElement *elem;
3211 hres = IHTMLDocument3_getElementById(&window->base.inner_window->doc->basedoc.IHTMLDocument3_iface,
3212 bstrName, &elem);
3213 if(SUCCEEDED(hres) && elem) {
3214 IHTMLElement_Release(elem);
3216 prop = alloc_global_prop(window, GLOBAL_ELEMENTVAR, bstrName);
3217 if(!prop)
3218 return E_OUTOFMEMORY;
3220 *pid = prop_to_dispid(window, prop);
3221 return S_OK;
3225 return DISP_E_UNKNOWNNAME;
3228 static HRESULT WINAPI WindowDispEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
3229 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
3231 HTMLWindow *This = impl_from_IDispatchEx(iface);
3232 HTMLInnerWindow *window = This->inner_window;
3234 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
3236 switch(id) {
3237 case DISPID_IHTMLWINDOW2_LOCATION: {
3238 HTMLLocation *location;
3239 HRESULT hres;
3241 if(!(wFlags & DISPATCH_PROPERTYPUT))
3242 break;
3244 TRACE("forwarding to location.href\n");
3246 hres = get_location(window, &location);
3247 if(FAILED(hres))
3248 return hres;
3250 hres = IDispatchEx_InvokeEx(&location->dispex.IDispatchEx_iface, DISPID_VALUE, lcid,
3251 wFlags, pdp, pvarRes, pei, pspCaller);
3252 IHTMLLocation_Release(&location->IHTMLLocation_iface);
3253 return hres;
3255 case DISPID_IHTMLWINDOW2_SETTIMEOUT:
3256 case DISPID_IHTMLWINDOW3_SETTIMEOUT: {
3257 VARIANT args[2];
3258 DISPPARAMS dp = {args, NULL, 2, 0};
3261 * setTimeout calls should use default value 0 for the second argument if only one is provided,
3262 * but IDL file does not reflect that. We fixup arguments here instead.
3264 if(!(wFlags & DISPATCH_METHOD) || pdp->cArgs != 1 || pdp->cNamedArgs)
3265 break;
3267 TRACE("Fixing args\n");
3269 V_VT(args) = VT_I4;
3270 V_I4(args) = 0;
3271 args[1] = *pdp->rgvarg;
3272 return IDispatchEx_InvokeEx(&window->event_target.dispex.IDispatchEx_iface, id, lcid,
3273 wFlags, &dp, pvarRes, pei, pspCaller);
3277 return IDispatchEx_InvokeEx(&window->event_target.dispex.IDispatchEx_iface, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
3280 static HRESULT WINAPI WindowDispEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
3282 HTMLWindow *This = impl_from_IDispatchEx(iface);
3284 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
3286 return IDispatchEx_DeleteMemberByName(&This->inner_window->event_target.dispex.IDispatchEx_iface, bstrName, grfdex);
3289 static HRESULT WINAPI WindowDispEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
3291 HTMLWindow *This = impl_from_IDispatchEx(iface);
3293 TRACE("(%p)->(%x)\n", This, id);
3295 return IDispatchEx_DeleteMemberByDispID(&This->inner_window->event_target.dispex.IDispatchEx_iface, id);
3298 static HRESULT WINAPI WindowDispEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
3300 HTMLWindow *This = impl_from_IDispatchEx(iface);
3302 TRACE("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
3304 return IDispatchEx_GetMemberProperties(&This->inner_window->event_target.dispex.IDispatchEx_iface, id, grfdexFetch,
3305 pgrfdex);
3308 static HRESULT WINAPI WindowDispEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
3310 HTMLWindow *This = impl_from_IDispatchEx(iface);
3312 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
3314 return IDispatchEx_GetMemberName(&This->inner_window->event_target.dispex.IDispatchEx_iface, id, pbstrName);
3317 static HRESULT WINAPI WindowDispEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
3319 HTMLWindow *This = impl_from_IDispatchEx(iface);
3321 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
3323 return IDispatchEx_GetNextDispID(&This->inner_window->event_target.dispex.IDispatchEx_iface, grfdex, id, pid);
3326 static HRESULT WINAPI WindowDispEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
3328 HTMLWindow *This = impl_from_IDispatchEx(iface);
3330 TRACE("(%p)->(%p)\n", This, ppunk);
3332 *ppunk = NULL;
3333 return S_OK;
3336 static const IDispatchExVtbl WindowDispExVtbl = {
3337 WindowDispEx_QueryInterface,
3338 WindowDispEx_AddRef,
3339 WindowDispEx_Release,
3340 WindowDispEx_GetTypeInfoCount,
3341 WindowDispEx_GetTypeInfo,
3342 WindowDispEx_GetIDsOfNames,
3343 WindowDispEx_Invoke,
3344 WindowDispEx_GetDispID,
3345 WindowDispEx_InvokeEx,
3346 WindowDispEx_DeleteMemberByName,
3347 WindowDispEx_DeleteMemberByDispID,
3348 WindowDispEx_GetMemberProperties,
3349 WindowDispEx_GetMemberName,
3350 WindowDispEx_GetNextDispID,
3351 WindowDispEx_GetNameSpaceParent
3354 static inline HTMLWindow *impl_from_IServiceProvider(IServiceProvider *iface)
3356 return CONTAINING_RECORD(iface, HTMLWindow, IServiceProvider_iface);
3359 static HRESULT WINAPI HTMLWindowSP_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
3361 HTMLWindow *This = impl_from_IServiceProvider(iface);
3362 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
3365 static ULONG WINAPI HTMLWindowSP_AddRef(IServiceProvider *iface)
3367 HTMLWindow *This = impl_from_IServiceProvider(iface);
3368 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
3371 static ULONG WINAPI HTMLWindowSP_Release(IServiceProvider *iface)
3373 HTMLWindow *This = impl_from_IServiceProvider(iface);
3374 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
3377 static HRESULT WINAPI HTMLWindowSP_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
3379 HTMLWindow *This = impl_from_IServiceProvider(iface);
3381 if(IsEqualGUID(guidService, &IID_IHTMLWindow2)) {
3382 TRACE("IID_IHTMLWindow2\n");
3383 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
3386 TRACE("(%p)->(%s %s %p)\n", This, debugstr_mshtml_guid(guidService), debugstr_mshtml_guid(riid), ppv);
3388 if(!This->outer_window || !This->outer_window->browser)
3389 return E_NOINTERFACE;
3391 return IServiceProvider_QueryService(&This->outer_window->browser->doc->basedoc.IServiceProvider_iface,
3392 guidService, riid, ppv);
3395 static const IServiceProviderVtbl ServiceProviderVtbl = {
3396 HTMLWindowSP_QueryInterface,
3397 HTMLWindowSP_AddRef,
3398 HTMLWindowSP_Release,
3399 HTMLWindowSP_QueryService
3402 static inline HTMLInnerWindow *impl_from_DispatchEx(DispatchEx *iface)
3404 return CONTAINING_RECORD(iface, HTMLInnerWindow, event_target.dispex);
3407 static HRESULT HTMLWindow_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
3408 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
3410 HTMLInnerWindow *This = impl_from_DispatchEx(dispex);
3411 global_prop_t *prop;
3412 DWORD idx;
3413 HRESULT hres;
3415 idx = id - MSHTML_DISPID_CUSTOM_MIN;
3416 if(idx >= This->global_prop_cnt)
3417 return DISP_E_MEMBERNOTFOUND;
3419 prop = This->global_props+idx;
3421 switch(prop->type) {
3422 case GLOBAL_SCRIPTVAR: {
3423 IDispatchEx *iface;
3424 IDispatch *disp;
3426 disp = get_script_disp(prop->script_host);
3427 if(!disp)
3428 return E_UNEXPECTED;
3430 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&iface);
3431 if(SUCCEEDED(hres)) {
3432 TRACE("%s >>>\n", debugstr_w(prop->name));
3433 hres = IDispatchEx_InvokeEx(iface, prop->id, lcid, flags, params, res, ei, caller);
3434 if(hres == S_OK)
3435 TRACE("%s <<<\n", debugstr_w(prop->name));
3436 else
3437 WARN("%s <<< %08x\n", debugstr_w(prop->name), hres);
3438 IDispatchEx_Release(iface);
3439 }else {
3440 FIXME("No IDispatchEx\n");
3442 IDispatch_Release(disp);
3443 break;
3445 case GLOBAL_ELEMENTVAR:
3446 switch(flags) {
3447 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
3448 case DISPATCH_PROPERTYGET: {
3449 IHTMLElement *elem;
3451 hres = IHTMLDocument3_getElementById(&This->base.inner_window->doc->basedoc.IHTMLDocument3_iface,
3452 prop->name, &elem);
3453 if(FAILED(hres))
3454 return hres;
3456 if(!elem)
3457 return DISP_E_MEMBERNOTFOUND;
3459 V_VT(res) = VT_DISPATCH;
3460 V_DISPATCH(res) = (IDispatch*)elem;
3461 return S_OK;
3463 case DISPATCH_PROPERTYPUT: {
3464 DISPID dispex_id;
3466 hres = dispex_get_dynid(&This->event_target.dispex, prop->name, &dispex_id);
3467 if(FAILED(hres))
3468 return hres;
3470 prop->type = GLOBAL_DISPEXVAR;
3471 prop->id = dispex_id;
3472 return IDispatchEx_InvokeEx(&This->event_target.dispex.IDispatchEx_iface, dispex_id, 0, flags, params, res, ei, caller);
3474 default:
3475 FIXME("Not supported flags: %x\n", flags);
3476 return E_NOTIMPL;
3478 case GLOBAL_FRAMEVAR:
3479 if(!This->base.outer_window)
3480 return E_UNEXPECTED;
3482 switch(flags) {
3483 case DISPATCH_PROPERTYGET: {
3484 HTMLOuterWindow *frame;
3486 hres = get_frame_by_name(This->base.outer_window, prop->name, FALSE, &frame);
3487 if(FAILED(hres))
3488 return hres;
3490 if(!frame)
3491 return DISP_E_MEMBERNOTFOUND;
3493 V_VT(res) = VT_DISPATCH;
3494 V_DISPATCH(res) = (IDispatch*)&frame->base.inner_window->base.IHTMLWindow2_iface;
3495 IDispatch_AddRef(V_DISPATCH(res));
3496 return S_OK;
3498 default:
3499 FIXME("Not supported flags: %x\n", flags);
3500 return E_NOTIMPL;
3502 case GLOBAL_DISPEXVAR:
3503 return IDispatchEx_InvokeEx(&This->event_target.dispex.IDispatchEx_iface, prop->id, 0, flags, params, res, ei, caller);
3504 default:
3505 ERR("invalid type %d\n", prop->type);
3506 hres = DISP_E_MEMBERNOTFOUND;
3509 return hres;
3512 static compat_mode_t HTMLWindow_get_compat_mode(DispatchEx *dispex)
3514 HTMLInnerWindow *This = impl_from_DispatchEx(dispex);
3515 return lock_document_mode(This->doc);
3518 static nsISupports *HTMLWindow_get_gecko_target(DispatchEx *dispex)
3520 HTMLInnerWindow *This = impl_from_DispatchEx(dispex);
3521 return (nsISupports*)This->base.outer_window->nswindow;
3524 static void HTMLWindow_bind_event(DispatchEx *dispex, eventid_t eid)
3526 HTMLInnerWindow *This = impl_from_DispatchEx(dispex);
3527 ensure_doc_nsevent_handler(This->doc, NULL, eid);
3530 static void HTMLWindow_init_dispex_info(dispex_data_t *info, compat_mode_t compat_mode)
3532 if(compat_mode >= COMPAT_MODE_IE9)
3533 dispex_info_add_interface(info, IHTMLWindow7_tid, NULL);
3534 dispex_info_add_interface(info, IHTMLWindow5_tid, NULL);
3535 EventTarget_init_dispex_info(info, compat_mode);
3538 static IHTMLEventObj *HTMLWindow_set_current_event(DispatchEx *dispex, IHTMLEventObj *event)
3540 HTMLInnerWindow *This = impl_from_DispatchEx(dispex);
3541 return default_set_current_event(This, event);
3544 static const event_target_vtbl_t HTMLWindow_event_target_vtbl = {
3546 NULL,
3547 NULL,
3548 HTMLWindow_invoke,
3549 HTMLWindow_get_compat_mode,
3550 NULL
3552 HTMLWindow_get_gecko_target,
3553 HTMLWindow_bind_event,
3554 NULL,
3555 NULL,
3556 NULL,
3557 HTMLWindow_set_current_event
3560 static const tid_t HTMLWindow_iface_tids[] = {
3561 IHTMLWindow2_tid,
3562 IHTMLWindow3_tid,
3563 IHTMLWindow4_tid,
3564 IHTMLWindow6_tid,
3568 static dispex_static_data_t HTMLWindow_dispex = {
3569 &HTMLWindow_event_target_vtbl.dispex_vtbl,
3570 DispHTMLWindow2_tid,
3571 HTMLWindow_iface_tids,
3572 HTMLWindow_init_dispex_info
3575 static void *alloc_window(size_t size)
3577 HTMLWindow *window;
3579 window = heap_alloc_zero(size);
3580 if(!window)
3581 return NULL;
3583 window->IHTMLWindow2_iface.lpVtbl = &HTMLWindow2Vtbl;
3584 window->IHTMLWindow3_iface.lpVtbl = &HTMLWindow3Vtbl;
3585 window->IHTMLWindow4_iface.lpVtbl = &HTMLWindow4Vtbl;
3586 window->IHTMLWindow5_iface.lpVtbl = &HTMLWindow5Vtbl;
3587 window->IHTMLWindow6_iface.lpVtbl = &HTMLWindow6Vtbl;
3588 window->IHTMLWindow7_iface.lpVtbl = &HTMLWindow7Vtbl;
3589 window->IHTMLPrivateWindow_iface.lpVtbl = &HTMLPrivateWindowVtbl;
3590 window->IDispatchEx_iface.lpVtbl = &WindowDispExVtbl;
3591 window->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
3592 window->ITravelLogClient_iface.lpVtbl = &TravelLogClientVtbl;
3593 window->IObjectIdentity_iface.lpVtbl = &ObjectIdentityVtbl;
3594 window->IProvideMultipleClassInfo_iface.lpVtbl = &ProvideMultipleClassInfoVtbl;
3595 window->ref = 1;
3597 return window;
3600 static HRESULT create_inner_window(HTMLOuterWindow *outer_window, IMoniker *mon, HTMLInnerWindow **ret)
3602 HTMLInnerWindow *window;
3604 window = alloc_window(sizeof(HTMLInnerWindow));
3605 if(!window)
3606 return E_OUTOFMEMORY;
3608 list_init(&window->children);
3609 list_init(&window->script_hosts);
3610 list_init(&window->bindings);
3611 list_init(&window->script_queue);
3613 window->base.outer_window = outer_window;
3614 window->base.inner_window = window;
3616 EventTarget_Init(&window->event_target, (IUnknown*)&window->base.IHTMLWindow2_iface,
3617 &HTMLWindow_dispex, COMPAT_MODE_NONE);
3619 window->task_magic = get_task_target_magic();
3621 if(mon) {
3622 IMoniker_AddRef(mon);
3623 window->mon = mon;
3626 *ret = window;
3627 return S_OK;
3630 HRESULT create_outer_window(GeckoBrowser *browser, mozIDOMWindowProxy *mozwindow,
3631 HTMLOuterWindow *parent, HTMLOuterWindow **ret)
3633 HTMLOuterWindow *window;
3634 nsresult nsres;
3635 HRESULT hres;
3637 window = alloc_window(sizeof(HTMLOuterWindow));
3638 if(!window)
3639 return E_OUTOFMEMORY;
3641 window->base.outer_window = window;
3642 window->base.inner_window = NULL;
3643 window->browser = browser;
3644 list_add_head(&browser->outer_windows, &window->browser_entry);
3646 mozIDOMWindowProxy_AddRef(mozwindow);
3647 window->window_proxy = mozwindow;
3648 nsres = mozIDOMWindowProxy_QueryInterface(mozwindow, &IID_nsIDOMWindow, (void**)&window->nswindow);
3649 assert(nsres == NS_OK);
3651 window->readystate = READYSTATE_UNINITIALIZED;
3652 window->task_magic = get_task_target_magic();
3654 wine_rb_put(&window_map, window->window_proxy, &window->entry);
3656 hres = create_pending_window(window, NULL);
3657 if(SUCCEEDED(hres))
3658 hres = update_window_doc(window->pending_window);
3659 if(FAILED(hres)) {
3660 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
3661 return hres;
3664 if(parent) {
3665 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
3667 window->parent = parent;
3668 list_add_tail(&parent->base.inner_window->children, &window->sibling_entry);
3671 TRACE("%p inner_window %p\n", window, window->base.inner_window);
3673 *ret = window;
3674 return S_OK;
3677 HRESULT create_pending_window(HTMLOuterWindow *outer_window, nsChannelBSC *channelbsc)
3679 HTMLInnerWindow *pending_window;
3680 HRESULT hres;
3682 hres = create_inner_window(outer_window, outer_window->mon /* FIXME */, &pending_window);
3683 if(FAILED(hres))
3684 return hres;
3686 if(channelbsc) {
3687 IBindStatusCallback_AddRef(&channelbsc->bsc.IBindStatusCallback_iface);
3688 pending_window->bscallback = channelbsc;
3691 if(outer_window->pending_window) {
3692 abort_window_bindings(outer_window->pending_window);
3693 outer_window->pending_window->base.outer_window = NULL;
3694 IHTMLWindow2_Release(&outer_window->pending_window->base.IHTMLWindow2_iface);
3697 outer_window->pending_window = pending_window;
3698 return S_OK;
3701 HRESULT update_window_doc(HTMLInnerWindow *window)
3703 HTMLOuterWindow *outer_window = window->base.outer_window;
3704 compat_mode_t parent_mode = COMPAT_MODE_QUIRKS;
3705 nsIDOMHTMLDocument *nshtmldoc;
3706 nsIDOMDocument *nsdoc;
3707 nsresult nsres;
3708 HRESULT hres;
3710 assert(!window->doc);
3712 if(!outer_window)
3713 return E_UNEXPECTED;
3715 nsres = nsIDOMWindow_GetDocument(outer_window->nswindow, &nsdoc);
3716 if(NS_FAILED(nsres) || !nsdoc) {
3717 ERR("GetDocument failed: %08x\n", nsres);
3718 return E_FAIL;
3721 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
3722 nsIDOMDocument_Release(nsdoc);
3723 if(NS_FAILED(nsres)) {
3724 ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres);
3725 return E_FAIL;
3728 if(outer_window->parent)
3729 parent_mode = outer_window->parent->base.inner_window->doc->document_mode;
3731 hres = create_document_node(nshtmldoc, outer_window->browser, window, parent_mode, &window->doc);
3732 nsIDOMHTMLDocument_Release(nshtmldoc);
3733 if(FAILED(hres))
3734 return hres;
3736 if(window != outer_window->pending_window) {
3737 ERR("not current pending window\n");
3738 return S_OK;
3741 if(outer_window->base.inner_window)
3742 detach_inner_window(outer_window->base.inner_window);
3743 outer_window->base.inner_window = window;
3744 outer_window->pending_window = NULL;
3746 if(is_main_content_window(outer_window) || !outer_window->browser->content_window) {
3747 HTMLDocumentObj *doc_obj = outer_window->browser->doc;
3748 if(doc_obj->basedoc.doc_node)
3749 htmldoc_release(&doc_obj->basedoc.doc_node->basedoc);
3750 doc_obj->basedoc.doc_node = window->doc;
3751 htmldoc_addref(&window->doc->basedoc);
3754 return hres;