ntdll: Reimplement DbgPrint* using DBG_PRINTEXCEPTION_C.
[wine.git] / dlls / mshtml / htmlwindow.c
bloba49cd4bd59defb721d76ff3fcfc50a532dc0875a
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->session_storage)
298 IHTMLStorage_Release(This->session_storage);
299 if(This->local_storage)
300 IHTMLStorage_Release(This->local_storage);
302 if(This->mon)
303 IMoniker_Release(This->mon);
305 heap_free(This);
308 static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
310 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
311 LONG ref = InterlockedDecrement(&This->ref);
313 TRACE("(%p) ref=%d\n", This, ref);
315 if(!ref) {
316 if(is_outer_window(This))
317 release_outer_window(This->outer_window);
318 else
319 release_inner_window(This->inner_window);
322 return ref;
325 static HRESULT WINAPI HTMLWindow2_GetTypeInfoCount(IHTMLWindow2 *iface, UINT *pctinfo)
327 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
329 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
332 static HRESULT WINAPI HTMLWindow2_GetTypeInfo(IHTMLWindow2 *iface, UINT iTInfo,
333 LCID lcid, ITypeInfo **ppTInfo)
335 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
337 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
340 static HRESULT WINAPI HTMLWindow2_GetIDsOfNames(IHTMLWindow2 *iface, REFIID riid,
341 LPOLESTR *rgszNames, UINT cNames,
342 LCID lcid, DISPID *rgDispId)
344 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
346 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
347 rgDispId);
350 static HRESULT WINAPI HTMLWindow2_Invoke(IHTMLWindow2 *iface, DISPID dispIdMember,
351 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
352 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
354 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
356 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
357 pDispParams, pVarResult, pExcepInfo, puArgErr);
360 static HRESULT get_frame_by_index(HTMLOuterWindow *This, UINT32 index, HTMLOuterWindow **ret)
362 nsIDOMWindowCollection *nsframes;
363 mozIDOMWindowProxy *mozwindow;
364 UINT32 length;
365 nsresult nsres;
367 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsframes);
368 if(NS_FAILED(nsres)) {
369 FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
370 return E_FAIL;
373 nsres = nsIDOMWindowCollection_GetLength(nsframes, &length);
374 assert(nsres == NS_OK);
376 if(index >= length) {
377 nsIDOMWindowCollection_Release(nsframes);
378 return DISP_E_MEMBERNOTFOUND;
381 nsres = nsIDOMWindowCollection_Item(nsframes, index, &mozwindow);
382 nsIDOMWindowCollection_Release(nsframes);
383 if(NS_FAILED(nsres)) {
384 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
385 return E_FAIL;
388 *ret = mozwindow_to_window(mozwindow);
390 mozIDOMWindowProxy_Release(mozwindow);
391 return S_OK;
394 HRESULT get_frame_by_name(HTMLOuterWindow *This, const WCHAR *name, BOOL deep, HTMLOuterWindow **ret)
396 nsIDOMWindowCollection *nsframes;
397 HTMLOuterWindow *window = NULL;
398 mozIDOMWindowProxy *mozwindow;
399 nsAString name_str;
400 UINT32 length, i;
401 nsresult nsres;
402 HRESULT hres = S_OK;
404 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsframes);
405 if(NS_FAILED(nsres)) {
406 FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
407 return E_FAIL;
410 if(!nsframes) {
411 WARN("nsIDOMWindow_GetFrames returned NULL nsframes: %p\n", This->nswindow);
412 return DISP_E_MEMBERNOTFOUND;
415 nsAString_InitDepend(&name_str, name);
416 nsres = nsIDOMWindowCollection_NamedItem(nsframes, &name_str, &mozwindow);
417 nsAString_Finish(&name_str);
418 if(NS_FAILED(nsres)) {
419 nsIDOMWindowCollection_Release(nsframes);
420 return E_FAIL;
423 if(mozwindow) {
424 *ret = mozwindow_to_window(mozwindow);
425 return S_OK;
428 nsres = nsIDOMWindowCollection_GetLength(nsframes, &length);
429 assert(nsres == NS_OK);
431 for(i = 0; i < length && !window; ++i) {
432 HTMLOuterWindow *window_iter;
433 BSTR id;
435 nsres = nsIDOMWindowCollection_Item(nsframes, i, &mozwindow);
436 if(NS_FAILED(nsres)) {
437 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
438 hres = E_FAIL;
439 break;
442 window_iter = mozwindow_to_window(mozwindow);
444 mozIDOMWindowProxy_Release(mozwindow);
446 if(!window_iter) {
447 WARN("nsIDOMWindow without HTMLOuterWindow: %p\n", mozwindow);
448 continue;
451 hres = IHTMLElement_get_id(&window_iter->frame_element->element.IHTMLElement_iface, &id);
452 if(FAILED(hres)) {
453 FIXME("IHTMLElement_get_id failed: 0x%08x\n", hres);
454 break;
457 if(id && !wcsicmp(id, name))
458 window = window_iter;
460 SysFreeString(id);
462 if(!window && deep)
463 get_frame_by_name(window_iter, name, TRUE, &window);
466 nsIDOMWindowCollection_Release(nsframes);
467 if(FAILED(hres))
468 return hres;
470 *ret = window;
471 return S_OK;
474 static HRESULT WINAPI HTMLWindow2_item(IHTMLWindow2 *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
476 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
477 HTMLOuterWindow *window = NULL;
478 HRESULT hres;
480 TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
482 switch(V_VT(pvarIndex)) {
483 case VT_I4: {
484 int index = V_I4(pvarIndex);
485 TRACE("Getting index %d\n", index);
486 if(index < 0)
487 return DISP_E_MEMBERNOTFOUND;
488 hres = get_frame_by_index(This->outer_window, index, &window);
489 break;
491 case VT_UINT: {
492 unsigned int index = V_UINT(pvarIndex);
493 TRACE("Getting index %u\n", index);
494 hres = get_frame_by_index(This->outer_window, index, &window);
495 break;
497 case VT_BSTR: {
498 BSTR str = V_BSTR(pvarIndex);
499 TRACE("Getting name %s\n", wine_dbgstr_w(str));
500 hres = get_frame_by_name(This->outer_window, str, FALSE, &window);
501 break;
503 default:
504 WARN("Invalid index %s\n", debugstr_variant(pvarIndex));
505 return E_INVALIDARG;
508 if(FAILED(hres))
509 return hres;
510 if(!window)
511 return DISP_E_MEMBERNOTFOUND;
513 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
514 V_VT(pvarResult) = VT_DISPATCH;
515 V_DISPATCH(pvarResult) = (IDispatch*)window;
516 return S_OK;
519 static HRESULT WINAPI HTMLWindow2_get_length(IHTMLWindow2 *iface, LONG *p)
521 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
522 nsIDOMWindowCollection *nscollection;
523 UINT32 length;
524 nsresult nsres;
526 TRACE("(%p)->(%p)\n", This, p);
528 nsres = nsIDOMWindow_GetFrames(This->outer_window->nswindow, &nscollection);
529 if(NS_FAILED(nsres)) {
530 ERR("GetFrames failed: %08x\n", nsres);
531 return E_FAIL;
534 nsres = nsIDOMWindowCollection_GetLength(nscollection, &length);
535 nsIDOMWindowCollection_Release(nscollection);
536 if(NS_FAILED(nsres)) {
537 ERR("GetLength failed: %08x\n", nsres);
538 return E_FAIL;
541 *p = length;
542 return S_OK;
545 static HRESULT WINAPI HTMLWindow2_get_frames(IHTMLWindow2 *iface, IHTMLFramesCollection2 **p)
547 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
548 FIXME("(%p)->(%p): semi-stub\n", This, p);
550 /* FIXME: Should return a separate Window object */
551 *p = (IHTMLFramesCollection2*)&This->IHTMLWindow2_iface;
552 IHTMLWindow2_AddRef(iface);
553 return S_OK;
556 static HRESULT WINAPI HTMLWindow2_put_defaultStatus(IHTMLWindow2 *iface, BSTR v)
558 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
559 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
560 return E_NOTIMPL;
563 static HRESULT WINAPI HTMLWindow2_get_defaultStatus(IHTMLWindow2 *iface, BSTR *p)
565 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
566 FIXME("(%p)->(%p)\n", This, p);
567 return E_NOTIMPL;
570 static HRESULT WINAPI HTMLWindow2_put_status(IHTMLWindow2 *iface, BSTR v)
572 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
574 WARN("(%p)->(%s)\n", This, debugstr_w(v));
577 * FIXME: Since IE7, setting status is blocked, but still possible in certain circumstances.
578 * Ignoring the call should be enough for us.
580 return S_OK;
583 static HRESULT WINAPI HTMLWindow2_get_status(IHTMLWindow2 *iface, BSTR *p)
585 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
587 TRACE("(%p)->(%p)\n", This, p);
589 /* See put_status */
590 *p = NULL;
591 return S_OK;
594 static HRESULT WINAPI HTMLWindow2_setTimeout(IHTMLWindow2 *iface, BSTR expression,
595 LONG msec, VARIANT *language, LONG *timerID)
597 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
598 VARIANT expr_var;
600 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
602 V_VT(&expr_var) = VT_BSTR;
603 V_BSTR(&expr_var) = expression;
605 return IHTMLWindow3_setTimeout(&This->IHTMLWindow3_iface, &expr_var, msec, language, timerID);
608 static HRESULT WINAPI HTMLWindow2_clearTimeout(IHTMLWindow2 *iface, LONG timerID)
610 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
612 TRACE("(%p)->(%d)\n", This, timerID);
614 return clear_task_timer(This->inner_window, timerID);
617 #define MAX_MESSAGE_LEN 2000
619 static HRESULT WINAPI HTMLWindow2_alert(IHTMLWindow2 *iface, BSTR message)
621 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
622 WCHAR title[100], *msg = message;
623 DWORD len;
625 TRACE("(%p)->(%s)\n", This, debugstr_w(message));
627 if(!This->outer_window || !This->outer_window->browser)
628 return E_UNEXPECTED;
630 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, title, ARRAY_SIZE(title))) {
631 WARN("Could not load message box title: %d\n", GetLastError());
632 return S_OK;
635 len = SysStringLen(message);
636 if(len > MAX_MESSAGE_LEN) {
637 msg = heap_alloc((MAX_MESSAGE_LEN+1)*sizeof(WCHAR));
638 if(!msg)
639 return E_OUTOFMEMORY;
640 memcpy(msg, message, MAX_MESSAGE_LEN*sizeof(WCHAR));
641 msg[MAX_MESSAGE_LEN] = 0;
644 MessageBoxW(This->outer_window->browser->doc->hwnd, msg, title, MB_ICONWARNING);
645 if(msg != message)
646 heap_free(msg);
647 return S_OK;
650 static HRESULT WINAPI HTMLWindow2_confirm(IHTMLWindow2 *iface, BSTR message,
651 VARIANT_BOOL *confirmed)
653 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
654 WCHAR wszTitle[100];
656 TRACE("(%p)->(%s %p)\n", This, debugstr_w(message), confirmed);
658 if(!confirmed)
659 return E_INVALIDARG;
660 if(!This->outer_window || !This->outer_window->browser)
661 return E_UNEXPECTED;
663 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle, ARRAY_SIZE(wszTitle))) {
664 WARN("Could not load message box title: %d\n", GetLastError());
665 *confirmed = VARIANT_TRUE;
666 return S_OK;
669 if(MessageBoxW(This->outer_window->browser->doc->hwnd, message, wszTitle,
670 MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
671 *confirmed = VARIANT_TRUE;
672 else *confirmed = VARIANT_FALSE;
674 return S_OK;
677 typedef struct
679 BSTR message;
680 BSTR dststr;
681 VARIANT *textdata;
682 }prompt_arg;
684 static INT_PTR CALLBACK prompt_dlgproc(HWND hwnd, UINT msg,
685 WPARAM wparam, LPARAM lparam)
687 switch(msg)
689 case WM_INITDIALOG:
691 prompt_arg *arg = (prompt_arg*)lparam;
692 WCHAR wszTitle[100];
694 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle, ARRAY_SIZE(wszTitle))) {
695 WARN("Could not load message box title: %d\n", GetLastError());
696 EndDialog(hwnd, wparam);
697 return FALSE;
700 SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
701 SetWindowTextW(hwnd, wszTitle);
702 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_PROMPT), arg->message);
703 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_EDIT), arg->dststr);
704 return FALSE;
706 case WM_COMMAND:
707 switch(wparam)
709 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
710 EndDialog(hwnd, wparam);
711 return TRUE;
712 case MAKEWPARAM(IDOK, BN_CLICKED):
714 prompt_arg *arg =
715 (prompt_arg*)GetWindowLongPtrW(hwnd, DWLP_USER);
716 HWND hwndPrompt = GetDlgItem(hwnd, ID_PROMPT_EDIT);
717 INT len = GetWindowTextLengthW(hwndPrompt);
719 if(!arg->textdata)
721 EndDialog(hwnd, wparam);
722 return TRUE;
725 V_VT(arg->textdata) = VT_BSTR;
726 if(!len && !arg->dststr)
727 V_BSTR(arg->textdata) = NULL;
728 else
730 V_BSTR(arg->textdata) = SysAllocStringLen(NULL, len);
731 GetWindowTextW(hwndPrompt, V_BSTR(arg->textdata), len+1);
733 EndDialog(hwnd, wparam);
734 return TRUE;
737 return FALSE;
738 case WM_CLOSE:
739 EndDialog(hwnd, IDCANCEL);
740 return TRUE;
741 default:
742 return FALSE;
746 static HRESULT WINAPI HTMLWindow2_prompt(IHTMLWindow2 *iface, BSTR message,
747 BSTR dststr, VARIANT *textdata)
749 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
750 prompt_arg arg;
752 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(message), debugstr_w(dststr), textdata);
754 if(!This->outer_window || !This->outer_window->browser)
755 return E_UNEXPECTED;
757 if(textdata) V_VT(textdata) = VT_NULL;
759 arg.message = message;
760 arg.dststr = dststr;
761 arg.textdata = textdata;
763 DialogBoxParamW(hInst, MAKEINTRESOURCEW(ID_PROMPT_DIALOG),
764 This->outer_window->browser->doc->hwnd, prompt_dlgproc, (LPARAM)&arg);
765 return S_OK;
768 static HRESULT WINAPI HTMLWindow2_get_Image(IHTMLWindow2 *iface, IHTMLImageElementFactory **p)
770 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
771 HTMLInnerWindow *window = This->inner_window;
773 TRACE("(%p)->(%p)\n", This, p);
775 if(!window->image_factory) {
776 HRESULT hres;
778 hres = HTMLImageElementFactory_Create(window, &window->image_factory);
779 if(FAILED(hres))
780 return hres;
783 *p = &window->image_factory->IHTMLImageElementFactory_iface;
784 IHTMLImageElementFactory_AddRef(*p);
786 return S_OK;
789 static HRESULT WINAPI HTMLWindow2_get_location(IHTMLWindow2 *iface, IHTMLLocation **p)
791 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
792 HTMLLocation *location;
793 HRESULT hres;
795 TRACE("(%p)->(%p)\n", This, p);
797 hres = get_location(This->inner_window, &location);
798 if(FAILED(hres))
799 return hres;
801 *p = &location->IHTMLLocation_iface;
802 return S_OK;
805 static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p)
807 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
808 HTMLInnerWindow *window = This->inner_window;
810 TRACE("(%p)->(%p)\n", This, p);
812 if(!window->history) {
813 HRESULT hres;
815 hres = create_history(window, &window->history);
816 if(FAILED(hres))
817 return hres;
820 IOmHistory_AddRef(&window->history->IOmHistory_iface);
821 *p = &window->history->IOmHistory_iface;
822 return S_OK;
825 static BOOL notify_webbrowser_close(HTMLOuterWindow *window, HTMLDocumentObj *doc)
827 IConnectionPointContainer *cp_container;
828 VARIANT_BOOL cancel = VARIANT_FALSE;
829 IEnumConnections *enum_conn;
830 VARIANT args[2];
831 DISPPARAMS dp = {args, NULL, 2, 0};
832 CONNECTDATA conn_data;
833 IConnectionPoint *cp;
834 IDispatch *disp;
835 ULONG fetched;
836 HRESULT hres;
838 if(!doc->webbrowser)
839 return TRUE;
841 hres = IUnknown_QueryInterface(doc->webbrowser, &IID_IConnectionPointContainer, (void**)&cp_container);
842 if(FAILED(hres))
843 return TRUE;
845 hres = IConnectionPointContainer_FindConnectionPoint(cp_container, &DIID_DWebBrowserEvents2, &cp);
846 IConnectionPointContainer_Release(cp_container);
847 if(FAILED(hres))
848 return TRUE;
850 hres = IConnectionPoint_EnumConnections(cp, &enum_conn);
851 IConnectionPoint_Release(cp);
852 if(FAILED(hres))
853 return TRUE;
855 while(!cancel) {
856 conn_data.pUnk = NULL;
857 conn_data.dwCookie = 0;
858 fetched = 0;
859 hres = IEnumConnections_Next(enum_conn, 1, &conn_data, &fetched);
860 if(hres != S_OK)
861 break;
863 hres = IUnknown_QueryInterface(conn_data.pUnk, &IID_IDispatch, (void**)&disp);
864 IUnknown_Release(conn_data.pUnk);
865 if(FAILED(hres))
866 continue;
868 V_VT(args) = VT_BYREF|VT_BOOL;
869 V_BOOLREF(args) = &cancel;
870 V_VT(args+1) = VT_BOOL;
871 V_BOOL(args+1) = variant_bool(window->parent != NULL);
872 hres = IDispatch_Invoke(disp, DISPID_WINDOWCLOSING, &IID_NULL, 0, DISPATCH_METHOD, &dp, NULL, NULL, NULL);
873 IDispatch_Release(disp);
874 if(FAILED(hres))
875 cancel = VARIANT_FALSE;
878 IEnumConnections_Release(enum_conn);
879 return !cancel;
882 static HRESULT WINAPI HTMLWindow2_close(IHTMLWindow2 *iface)
884 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
885 HTMLOuterWindow *window = This->outer_window;
887 TRACE("(%p)\n", This);
889 if(!window || !window->browser) {
890 FIXME("No document object\n");
891 return E_FAIL;
894 if(!notify_webbrowser_close(window, window->browser->doc))
895 return S_OK;
897 FIXME("default action not implemented\n");
898 return E_NOTIMPL;
901 static HRESULT WINAPI HTMLWindow2_put_opener(IHTMLWindow2 *iface, VARIANT v)
903 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
904 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
905 return E_NOTIMPL;
908 static HRESULT WINAPI HTMLWindow2_get_opener(IHTMLWindow2 *iface, VARIANT *p)
910 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
912 FIXME("(%p)->(%p) returning empty\n", This, p);
914 V_VT(p) = VT_EMPTY;
915 return S_OK;
918 static HRESULT WINAPI HTMLWindow2_get_navigator(IHTMLWindow2 *iface, IOmNavigator **p)
920 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
922 TRACE("(%p)->(%p)\n", This, p);
924 *p = OmNavigator_Create();
925 return *p ? S_OK : E_OUTOFMEMORY;
928 static HRESULT WINAPI HTMLWindow2_put_name(IHTMLWindow2 *iface, BSTR v)
930 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
931 nsAString name_str;
932 nsresult nsres;
934 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
936 nsAString_InitDepend(&name_str, v);
937 nsres = nsIDOMWindow_SetName(This->outer_window->nswindow, &name_str);
938 nsAString_Finish(&name_str);
939 if(NS_FAILED(nsres))
940 ERR("SetName failed: %08x\n", nsres);
942 return S_OK;
945 static HRESULT WINAPI HTMLWindow2_get_name(IHTMLWindow2 *iface, BSTR *p)
947 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
948 nsAString name_str;
949 nsresult nsres;
951 TRACE("(%p)->(%p)\n", This, p);
953 nsAString_Init(&name_str, NULL);
954 nsres = nsIDOMWindow_GetName(This->outer_window->nswindow, &name_str);
955 return return_nsstr(nsres, &name_str, p);
958 static HRESULT WINAPI HTMLWindow2_get_parent(IHTMLWindow2 *iface, IHTMLWindow2 **p)
960 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
961 HTMLOuterWindow *window = This->outer_window;
963 TRACE("(%p)->(%p)\n", This, p);
965 if(!window->parent)
966 return IHTMLWindow2_get_self(&This->IHTMLWindow2_iface, p);
968 *p = &window->parent->base.IHTMLWindow2_iface;
969 IHTMLWindow2_AddRef(*p);
970 return S_OK;
973 static HRESULT WINAPI HTMLWindow2_open(IHTMLWindow2 *iface, BSTR url, BSTR name,
974 BSTR features, VARIANT_BOOL replace, IHTMLWindow2 **pomWindowResult)
976 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
977 HTMLOuterWindow *window = This->outer_window;
978 IUri *uri;
979 HRESULT hres;
981 static const WCHAR _selfW[] = {'_','s','e','l','f',0};
983 TRACE("(%p)->(%s %s %s %x %p)\n", This, debugstr_w(url), debugstr_w(name),
984 debugstr_w(features), replace, pomWindowResult);
985 if(features)
986 FIXME("unsupported features argument %s\n", debugstr_w(features));
987 if(replace)
988 FIXME("unsupported relace argument\n");
990 if(!window || !window->browser || !window->uri_nofrag)
991 return E_UNEXPECTED;
993 if(name && *name == '_') {
994 if(!wcscmp(name, _selfW)) {
995 if((features && *features) || replace)
996 FIXME("Unsupported arguments for _self target\n");
998 hres = IHTMLWindow2_navigate(&This->IHTMLWindow2_iface, url);
999 if(FAILED(hres))
1000 return hres;
1002 if(pomWindowResult) {
1003 FIXME("Returning this window for _self target\n");
1004 *pomWindowResult = &This->IHTMLWindow2_iface;
1005 IHTMLWindow2_AddRef(*pomWindowResult);
1008 return S_OK;
1011 FIXME("Unsupported name %s\n", debugstr_w(name));
1012 return E_NOTIMPL;
1015 hres = create_relative_uri(window, url, &uri);
1016 if(FAILED(hres))
1017 return hres;
1019 hres = navigate_new_window(window, uri, name, NULL, pomWindowResult);
1020 IUri_Release(uri);
1021 return hres;
1024 static HRESULT WINAPI HTMLWindow2_get_self(IHTMLWindow2 *iface, IHTMLWindow2 **p)
1026 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1028 TRACE("(%p)->(%p)\n", This, p);
1030 /* FIXME: We should return kind of proxy window here. */
1031 IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1032 *p = &This->IHTMLWindow2_iface;
1033 return S_OK;
1036 static HRESULT WINAPI HTMLWindow2_get_top(IHTMLWindow2 *iface, IHTMLWindow2 **p)
1038 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1039 HTMLOuterWindow *top;
1041 TRACE("(%p)->(%p)\n", This, p);
1043 get_top_window(This->outer_window, &top);
1044 *p = &top->base.IHTMLWindow2_iface;
1045 IHTMLWindow2_AddRef(*p);
1047 return S_OK;
1050 static HRESULT WINAPI HTMLWindow2_get_window(IHTMLWindow2 *iface, IHTMLWindow2 **p)
1052 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1054 TRACE("(%p)->(%p)\n", This, p);
1056 /* FIXME: We should return kind of proxy window here. */
1057 IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1058 *p = &This->IHTMLWindow2_iface;
1059 return S_OK;
1062 static HRESULT WINAPI HTMLWindow2_navigate(IHTMLWindow2 *iface, BSTR url)
1064 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1066 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
1068 return navigate_url(This->outer_window, url, This->outer_window->uri, BINDING_NAVIGATED);
1071 static HRESULT WINAPI HTMLWindow2_put_onfocus(IHTMLWindow2 *iface, VARIANT v)
1073 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1075 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1077 return set_window_event(This, EVENTID_FOCUS, &v);
1080 static HRESULT WINAPI HTMLWindow2_get_onfocus(IHTMLWindow2 *iface, VARIANT *p)
1082 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1084 TRACE("(%p)->(%p)\n", This, p);
1086 return get_window_event(This, EVENTID_FOCUS, p);
1089 static HRESULT WINAPI HTMLWindow2_put_onblur(IHTMLWindow2 *iface, VARIANT v)
1091 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1093 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1095 return set_window_event(This, EVENTID_BLUR, &v);
1098 static HRESULT WINAPI HTMLWindow2_get_onblur(IHTMLWindow2 *iface, VARIANT *p)
1100 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1102 TRACE("(%p)->(%p)\n", This, p);
1104 return get_window_event(This, EVENTID_BLUR, p);
1107 static HRESULT WINAPI HTMLWindow2_put_onload(IHTMLWindow2 *iface, VARIANT v)
1109 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1111 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1113 return set_window_event(This, EVENTID_LOAD, &v);
1116 static HRESULT WINAPI HTMLWindow2_get_onload(IHTMLWindow2 *iface, VARIANT *p)
1118 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1120 TRACE("(%p)->(%p)\n", This, p);
1122 return get_window_event(This, EVENTID_LOAD, p);
1125 static HRESULT WINAPI HTMLWindow2_put_onbeforeunload(IHTMLWindow2 *iface, VARIANT v)
1127 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1129 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1131 return set_window_event(This, EVENTID_BEFOREUNLOAD, &v);
1134 static HRESULT WINAPI HTMLWindow2_get_onbeforeunload(IHTMLWindow2 *iface, VARIANT *p)
1136 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1138 TRACE("(%p)->(%p)\n", This, p);
1140 return get_window_event(This, EVENTID_BEFOREUNLOAD, p);
1143 static HRESULT WINAPI HTMLWindow2_put_onunload(IHTMLWindow2 *iface, VARIANT v)
1145 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1147 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1149 return set_window_event(This, EVENTID_UNLOAD, &v);
1152 static HRESULT WINAPI HTMLWindow2_get_onunload(IHTMLWindow2 *iface, VARIANT *p)
1154 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1156 TRACE("(%p)->(%p)\n", This, p);
1158 return get_window_event(This, EVENTID_UNLOAD, p);
1161 static HRESULT WINAPI HTMLWindow2_put_onhelp(IHTMLWindow2 *iface, VARIANT v)
1163 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1165 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1167 return set_window_event(This, EVENTID_HELP, &v);
1170 static HRESULT WINAPI HTMLWindow2_get_onhelp(IHTMLWindow2 *iface, VARIANT *p)
1172 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1174 TRACE("(%p)->(%p)\n", This, p);
1176 return get_window_event(This, EVENTID_HELP, p);
1179 static HRESULT WINAPI HTMLWindow2_put_onerror(IHTMLWindow2 *iface, VARIANT v)
1181 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1183 FIXME("(%p)->(%s) semi-stub\n", This, debugstr_variant(&v));
1185 return set_window_event(This, EVENTID_ERROR, &v);
1188 static HRESULT WINAPI HTMLWindow2_get_onerror(IHTMLWindow2 *iface, VARIANT *p)
1190 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1192 TRACE("(%p)->(%p)\n", This, p);
1194 return get_window_event(This, EVENTID_ERROR, p);
1197 static HRESULT WINAPI HTMLWindow2_put_onresize(IHTMLWindow2 *iface, VARIANT v)
1199 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1201 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1203 return set_window_event(This, EVENTID_RESIZE, &v);
1206 static HRESULT WINAPI HTMLWindow2_get_onresize(IHTMLWindow2 *iface, VARIANT *p)
1208 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1210 TRACE("(%p)->(%p)\n", This, p);
1212 return get_window_event(This, EVENTID_RESIZE, p);
1215 static HRESULT WINAPI HTMLWindow2_put_onscroll(IHTMLWindow2 *iface, VARIANT v)
1217 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1219 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1221 return set_window_event(This, EVENTID_SCROLL, &v);
1224 static HRESULT WINAPI HTMLWindow2_get_onscroll(IHTMLWindow2 *iface, VARIANT *p)
1226 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1228 TRACE("(%p)->(%p)\n", This, p);
1230 return get_window_event(This, EVENTID_SCROLL, p);
1233 static HRESULT WINAPI HTMLWindow2_get_document(IHTMLWindow2 *iface, IHTMLDocument2 **p)
1235 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1237 TRACE("(%p)->(%p)\n", This, p);
1239 if(This->inner_window->doc) {
1240 /* FIXME: We should return a wrapper object here */
1241 *p = &This->inner_window->doc->basedoc.IHTMLDocument2_iface;
1242 IHTMLDocument2_AddRef(*p);
1243 }else {
1244 *p = NULL;
1247 return S_OK;
1250 IHTMLEventObj *default_set_current_event(HTMLInnerWindow *window, IHTMLEventObj *event_obj)
1252 IHTMLEventObj *prev_event = NULL;
1254 if(window) {
1255 if(event_obj)
1256 IHTMLEventObj_AddRef(event_obj);
1257 prev_event = window->event;
1258 window->event = event_obj;
1261 return prev_event;
1264 static HRESULT WINAPI HTMLWindow2_get_event(IHTMLWindow2 *iface, IHTMLEventObj **p)
1266 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1267 HTMLInnerWindow *window = This->inner_window;
1269 TRACE("(%p)->(%p)\n", This, p);
1271 if(window->event)
1272 IHTMLEventObj_AddRef(window->event);
1273 *p = window->event;
1274 return S_OK;
1277 static HRESULT WINAPI HTMLWindow2_get__newEnum(IHTMLWindow2 *iface, IUnknown **p)
1279 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1280 FIXME("(%p)->(%p)\n", This, p);
1281 return E_NOTIMPL;
1284 static HRESULT WINAPI HTMLWindow2_showModalDialog(IHTMLWindow2 *iface, BSTR dialog,
1285 VARIANT *varArgIn, VARIANT *varOptions, VARIANT *varArgOut)
1287 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1288 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(dialog), varArgIn, varOptions, varArgOut);
1289 return E_NOTIMPL;
1292 static HRESULT WINAPI HTMLWindow2_showHelp(IHTMLWindow2 *iface, BSTR helpURL, VARIANT helpArg,
1293 BSTR features)
1295 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1296 FIXME("(%p)->(%s %s %s)\n", This, debugstr_w(helpURL), debugstr_variant(&helpArg), debugstr_w(features));
1297 return E_NOTIMPL;
1300 static HRESULT WINAPI HTMLWindow2_get_screen(IHTMLWindow2 *iface, IHTMLScreen **p)
1302 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1303 HTMLInnerWindow *window = This->inner_window;
1305 TRACE("(%p)->(%p)\n", This, p);
1307 if(!window->screen) {
1308 HRESULT hres;
1310 hres = HTMLScreen_Create(&window->screen);
1311 if(FAILED(hres))
1312 return hres;
1315 *p = window->screen;
1316 IHTMLScreen_AddRef(window->screen);
1317 return S_OK;
1320 static HRESULT WINAPI HTMLWindow2_get_Option(IHTMLWindow2 *iface, IHTMLOptionElementFactory **p)
1322 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1323 HTMLInnerWindow *window = This->inner_window;
1325 TRACE("(%p)->(%p)\n", This, p);
1327 if(!window->option_factory) {
1328 HRESULT hres;
1330 hres = HTMLOptionElementFactory_Create(window, &window->option_factory);
1331 if(FAILED(hres))
1332 return hres;
1335 *p = &window->option_factory->IHTMLOptionElementFactory_iface;
1336 IHTMLOptionElementFactory_AddRef(*p);
1338 return S_OK;
1341 static HRESULT WINAPI HTMLWindow2_focus(IHTMLWindow2 *iface)
1343 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1345 TRACE("(%p)->()\n", This);
1347 if(!This->outer_window || !This->outer_window->browser)
1348 return E_UNEXPECTED;
1350 SetFocus(This->outer_window->browser->doc->hwnd);
1351 return S_OK;
1354 static HRESULT WINAPI HTMLWindow2_get_closed(IHTMLWindow2 *iface, VARIANT_BOOL *p)
1356 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1357 FIXME("(%p)->(%p)\n", This, p);
1358 return E_NOTIMPL;
1361 static HRESULT WINAPI HTMLWindow2_blur(IHTMLWindow2 *iface)
1363 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1364 FIXME("(%p)->()\n", This);
1365 return E_NOTIMPL;
1368 static HRESULT WINAPI HTMLWindow2_scroll(IHTMLWindow2 *iface, LONG x, LONG y)
1370 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1371 nsresult nsres;
1373 TRACE("(%p)->(%d %d)\n", This, x, y);
1375 nsres = nsIDOMWindow_Scroll(This->outer_window->nswindow, x, y);
1376 if(NS_FAILED(nsres)) {
1377 ERR("ScrollBy failed: %08x\n", nsres);
1378 return E_FAIL;
1381 return S_OK;
1384 static HRESULT WINAPI HTMLWindow2_get_clientInformation(IHTMLWindow2 *iface, IOmNavigator **p)
1386 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1388 TRACE("(%p)->(%p)\n", This, p);
1390 return IHTMLWindow2_get_navigator(&This->IHTMLWindow2_iface, p);
1393 static HRESULT WINAPI HTMLWindow2_setInterval(IHTMLWindow2 *iface, BSTR expression,
1394 LONG msec, VARIANT *language, LONG *timerID)
1396 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1397 VARIANT expr;
1399 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
1401 V_VT(&expr) = VT_BSTR;
1402 V_BSTR(&expr) = expression;
1403 return IHTMLWindow3_setInterval(&This->IHTMLWindow3_iface, &expr, msec, language, timerID);
1406 static HRESULT WINAPI HTMLWindow2_clearInterval(IHTMLWindow2 *iface, LONG timerID)
1408 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1410 TRACE("(%p)->(%d)\n", This, timerID);
1412 return clear_task_timer(This->inner_window, timerID);
1415 static HRESULT WINAPI HTMLWindow2_put_offscreenBuffering(IHTMLWindow2 *iface, VARIANT v)
1417 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1418 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1419 return E_NOTIMPL;
1422 static HRESULT WINAPI HTMLWindow2_get_offscreenBuffering(IHTMLWindow2 *iface, VARIANT *p)
1424 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1425 FIXME("(%p)->(%p)\n", This, p);
1426 return E_NOTIMPL;
1429 static HRESULT WINAPI HTMLWindow2_execScript(IHTMLWindow2 *iface, BSTR scode, BSTR language,
1430 VARIANT *pvarRet)
1432 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1434 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(scode), debugstr_w(language), pvarRet);
1436 return exec_script(This->inner_window, scode, language, pvarRet);
1439 static HRESULT WINAPI HTMLWindow2_toString(IHTMLWindow2 *iface, BSTR *String)
1441 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1443 static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
1445 TRACE("(%p)->(%p)\n", This, String);
1447 if(!String)
1448 return E_INVALIDARG;
1450 *String = SysAllocString(objectW);
1451 return *String ? S_OK : E_OUTOFMEMORY;
1454 static HRESULT WINAPI HTMLWindow2_scrollBy(IHTMLWindow2 *iface, LONG x, LONG y)
1456 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1457 nsresult nsres;
1459 TRACE("(%p)->(%d %d)\n", This, x, y);
1461 nsres = nsIDOMWindow_ScrollBy(This->outer_window->nswindow, x, y);
1462 if(NS_FAILED(nsres))
1463 ERR("ScrollBy failed: %08x\n", nsres);
1465 return S_OK;
1468 static HRESULT WINAPI HTMLWindow2_scrollTo(IHTMLWindow2 *iface, LONG x, LONG y)
1470 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1471 nsresult nsres;
1473 TRACE("(%p)->(%d %d)\n", This, x, y);
1475 nsres = nsIDOMWindow_ScrollTo(This->outer_window->nswindow, x, y);
1476 if(NS_FAILED(nsres))
1477 ERR("ScrollTo failed: %08x\n", nsres);
1479 return S_OK;
1482 static HRESULT WINAPI HTMLWindow2_moveTo(IHTMLWindow2 *iface, LONG x, LONG y)
1484 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1485 FIXME("(%p)->(%d %d)\n", This, x, y);
1486 return E_NOTIMPL;
1489 static HRESULT WINAPI HTMLWindow2_moveBy(IHTMLWindow2 *iface, LONG x, LONG y)
1491 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1492 FIXME("(%p)->(%d %d)\n", This, x, y);
1493 return S_FALSE;
1496 static HRESULT WINAPI HTMLWindow2_resizeTo(IHTMLWindow2 *iface, LONG x, LONG y)
1498 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1499 FIXME("(%p)->(%d %d)\n", This, x, y);
1500 return E_NOTIMPL;
1503 static HRESULT WINAPI HTMLWindow2_resizeBy(IHTMLWindow2 *iface, LONG x, LONG y)
1505 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1506 FIXME("(%p)->(%d %d)\n", This, x, y);
1507 return S_FALSE;
1510 static HRESULT WINAPI HTMLWindow2_get_external(IHTMLWindow2 *iface, IDispatch **p)
1512 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1514 TRACE("(%p)->(%p)\n", This, p);
1516 if(!This->outer_window || !This->outer_window->browser)
1517 return E_UNEXPECTED;
1519 *p = NULL;
1521 if(!This->outer_window->browser->doc->hostui)
1522 return S_OK;
1524 return IDocHostUIHandler_GetExternal(This->outer_window->browser->doc->hostui, p);
1527 static const IHTMLWindow2Vtbl HTMLWindow2Vtbl = {
1528 HTMLWindow2_QueryInterface,
1529 HTMLWindow2_AddRef,
1530 HTMLWindow2_Release,
1531 HTMLWindow2_GetTypeInfoCount,
1532 HTMLWindow2_GetTypeInfo,
1533 HTMLWindow2_GetIDsOfNames,
1534 HTMLWindow2_Invoke,
1535 HTMLWindow2_item,
1536 HTMLWindow2_get_length,
1537 HTMLWindow2_get_frames,
1538 HTMLWindow2_put_defaultStatus,
1539 HTMLWindow2_get_defaultStatus,
1540 HTMLWindow2_put_status,
1541 HTMLWindow2_get_status,
1542 HTMLWindow2_setTimeout,
1543 HTMLWindow2_clearTimeout,
1544 HTMLWindow2_alert,
1545 HTMLWindow2_confirm,
1546 HTMLWindow2_prompt,
1547 HTMLWindow2_get_Image,
1548 HTMLWindow2_get_location,
1549 HTMLWindow2_get_history,
1550 HTMLWindow2_close,
1551 HTMLWindow2_put_opener,
1552 HTMLWindow2_get_opener,
1553 HTMLWindow2_get_navigator,
1554 HTMLWindow2_put_name,
1555 HTMLWindow2_get_name,
1556 HTMLWindow2_get_parent,
1557 HTMLWindow2_open,
1558 HTMLWindow2_get_self,
1559 HTMLWindow2_get_top,
1560 HTMLWindow2_get_window,
1561 HTMLWindow2_navigate,
1562 HTMLWindow2_put_onfocus,
1563 HTMLWindow2_get_onfocus,
1564 HTMLWindow2_put_onblur,
1565 HTMLWindow2_get_onblur,
1566 HTMLWindow2_put_onload,
1567 HTMLWindow2_get_onload,
1568 HTMLWindow2_put_onbeforeunload,
1569 HTMLWindow2_get_onbeforeunload,
1570 HTMLWindow2_put_onunload,
1571 HTMLWindow2_get_onunload,
1572 HTMLWindow2_put_onhelp,
1573 HTMLWindow2_get_onhelp,
1574 HTMLWindow2_put_onerror,
1575 HTMLWindow2_get_onerror,
1576 HTMLWindow2_put_onresize,
1577 HTMLWindow2_get_onresize,
1578 HTMLWindow2_put_onscroll,
1579 HTMLWindow2_get_onscroll,
1580 HTMLWindow2_get_document,
1581 HTMLWindow2_get_event,
1582 HTMLWindow2_get__newEnum,
1583 HTMLWindow2_showModalDialog,
1584 HTMLWindow2_showHelp,
1585 HTMLWindow2_get_screen,
1586 HTMLWindow2_get_Option,
1587 HTMLWindow2_focus,
1588 HTMLWindow2_get_closed,
1589 HTMLWindow2_blur,
1590 HTMLWindow2_scroll,
1591 HTMLWindow2_get_clientInformation,
1592 HTMLWindow2_setInterval,
1593 HTMLWindow2_clearInterval,
1594 HTMLWindow2_put_offscreenBuffering,
1595 HTMLWindow2_get_offscreenBuffering,
1596 HTMLWindow2_execScript,
1597 HTMLWindow2_toString,
1598 HTMLWindow2_scrollBy,
1599 HTMLWindow2_scrollTo,
1600 HTMLWindow2_moveTo,
1601 HTMLWindow2_moveBy,
1602 HTMLWindow2_resizeTo,
1603 HTMLWindow2_resizeBy,
1604 HTMLWindow2_get_external
1607 static inline HTMLWindow *impl_from_IHTMLWindow3(IHTMLWindow3 *iface)
1609 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow3_iface);
1612 static HRESULT WINAPI HTMLWindow3_QueryInterface(IHTMLWindow3 *iface, REFIID riid, void **ppv)
1614 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1616 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1619 static ULONG WINAPI HTMLWindow3_AddRef(IHTMLWindow3 *iface)
1621 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1623 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1626 static ULONG WINAPI HTMLWindow3_Release(IHTMLWindow3 *iface)
1628 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1630 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1633 static HRESULT WINAPI HTMLWindow3_GetTypeInfoCount(IHTMLWindow3 *iface, UINT *pctinfo)
1635 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1637 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1640 static HRESULT WINAPI HTMLWindow3_GetTypeInfo(IHTMLWindow3 *iface, UINT iTInfo,
1641 LCID lcid, ITypeInfo **ppTInfo)
1643 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1645 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1648 static HRESULT WINAPI HTMLWindow3_GetIDsOfNames(IHTMLWindow3 *iface, REFIID riid,
1649 LPOLESTR *rgszNames, UINT cNames,
1650 LCID lcid, DISPID *rgDispId)
1652 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1654 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1655 rgDispId);
1658 static HRESULT WINAPI HTMLWindow3_Invoke(IHTMLWindow3 *iface, DISPID dispIdMember,
1659 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1660 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1662 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1664 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1665 pDispParams, pVarResult, pExcepInfo, puArgErr);
1668 static HRESULT WINAPI HTMLWindow3_get_screenLeft(IHTMLWindow3 *iface, LONG *p)
1670 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1671 nsresult nsres;
1673 TRACE("(%p)->(%p)\n", This, p);
1675 nsres = nsIDOMWindow_GetScreenX(This->outer_window->nswindow, p);
1676 if(NS_FAILED(nsres)) {
1677 ERR("GetScreenX failed: %08x\n", nsres);
1678 return E_FAIL;
1681 return S_OK;
1684 static HRESULT WINAPI HTMLWindow3_get_screenTop(IHTMLWindow3 *iface, LONG *p)
1686 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1687 nsresult nsres;
1689 TRACE("(%p)->(%p)\n", This, p);
1691 nsres = nsIDOMWindow_GetScreenY(This->outer_window->nswindow, p);
1692 if(NS_FAILED(nsres)) {
1693 ERR("GetScreenY failed: %08x\n", nsres);
1694 return E_FAIL;
1697 return S_OK;
1700 static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp, VARIANT_BOOL *pfResult)
1702 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1703 HTMLInnerWindow *window = This->inner_window;
1705 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
1707 if(!window->doc) {
1708 FIXME("No document\n");
1709 return E_FAIL;
1712 return attach_event(&window->event_target, event, pDisp, pfResult);
1715 static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
1717 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1718 HTMLInnerWindow *window = This->inner_window;
1720 TRACE("(%p)->()\n", This);
1722 if(!window->doc) {
1723 FIXME("No document\n");
1724 return E_FAIL;
1727 return detach_event(&window->event_target, event, pDisp);
1730 static HRESULT window_set_timer(HTMLInnerWindow *This, VARIANT *expr, LONG msec, VARIANT *language,
1731 BOOL interval, LONG *timer_id)
1733 IDispatch *disp = NULL;
1734 HRESULT hres;
1736 switch(V_VT(expr)) {
1737 case VT_DISPATCH:
1738 disp = V_DISPATCH(expr);
1739 IDispatch_AddRef(disp);
1740 break;
1742 case VT_BSTR:
1743 disp = script_parse_event(This->base.inner_window, V_BSTR(expr));
1744 break;
1746 default:
1747 FIXME("unimplemented expr %s\n", debugstr_variant(expr));
1748 return E_NOTIMPL;
1751 if(!disp)
1752 return E_FAIL;
1754 hres = set_task_timer(This, msec, interval, disp, timer_id);
1755 IDispatch_Release(disp);
1757 return hres;
1760 static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1761 VARIANT *language, LONG *timerID)
1763 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1765 TRACE("(%p)->(%s %d %s %p)\n", This, debugstr_variant(expression), msec, debugstr_variant(language), timerID);
1767 return window_set_timer(This->inner_window, expression, msec, language, FALSE, timerID);
1770 static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1771 VARIANT *language, LONG *timerID)
1773 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1775 TRACE("(%p)->(%p %d %p %p)\n", This, expression, msec, language, timerID);
1777 return window_set_timer(This->inner_window, expression, msec, language, TRUE, timerID);
1780 static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)
1782 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1783 FIXME("(%p)\n", This);
1784 return E_NOTIMPL;
1787 static HRESULT WINAPI HTMLWindow3_put_onbeforeprint(IHTMLWindow3 *iface, VARIANT v)
1789 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1790 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1791 return E_NOTIMPL;
1794 static HRESULT WINAPI HTMLWindow3_get_onbeforeprint(IHTMLWindow3 *iface, VARIANT *p)
1796 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1797 FIXME("(%p)->(%p)\n", This, p);
1798 return E_NOTIMPL;
1801 static HRESULT WINAPI HTMLWindow3_put_onafterprint(IHTMLWindow3 *iface, VARIANT v)
1803 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1804 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1805 return E_NOTIMPL;
1808 static HRESULT WINAPI HTMLWindow3_get_onafterprint(IHTMLWindow3 *iface, VARIANT *p)
1810 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1811 FIXME("(%p)->(%p)\n", This, p);
1812 return E_NOTIMPL;
1815 static HRESULT WINAPI HTMLWindow3_get_clipboardData(IHTMLWindow3 *iface, IHTMLDataTransfer **p)
1817 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1818 FIXME("(%p)->(%p)\n", This, p);
1819 return E_NOTIMPL;
1822 static HRESULT WINAPI HTMLWindow3_showModelessDialog(IHTMLWindow3 *iface, BSTR url,
1823 VARIANT *varArgIn, VARIANT *options, IHTMLWindow2 **pDialog)
1825 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1826 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(url), varArgIn, options, pDialog);
1827 return E_NOTIMPL;
1830 static const IHTMLWindow3Vtbl HTMLWindow3Vtbl = {
1831 HTMLWindow3_QueryInterface,
1832 HTMLWindow3_AddRef,
1833 HTMLWindow3_Release,
1834 HTMLWindow3_GetTypeInfoCount,
1835 HTMLWindow3_GetTypeInfo,
1836 HTMLWindow3_GetIDsOfNames,
1837 HTMLWindow3_Invoke,
1838 HTMLWindow3_get_screenLeft,
1839 HTMLWindow3_get_screenTop,
1840 HTMLWindow3_attachEvent,
1841 HTMLWindow3_detachEvent,
1842 HTMLWindow3_setTimeout,
1843 HTMLWindow3_setInterval,
1844 HTMLWindow3_print,
1845 HTMLWindow3_put_onbeforeprint,
1846 HTMLWindow3_get_onbeforeprint,
1847 HTMLWindow3_put_onafterprint,
1848 HTMLWindow3_get_onafterprint,
1849 HTMLWindow3_get_clipboardData,
1850 HTMLWindow3_showModelessDialog
1853 static inline HTMLWindow *impl_from_IHTMLWindow4(IHTMLWindow4 *iface)
1855 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow4_iface);
1858 static HRESULT WINAPI HTMLWindow4_QueryInterface(IHTMLWindow4 *iface, REFIID riid, void **ppv)
1860 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1862 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1865 static ULONG WINAPI HTMLWindow4_AddRef(IHTMLWindow4 *iface)
1867 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1869 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1872 static ULONG WINAPI HTMLWindow4_Release(IHTMLWindow4 *iface)
1874 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1876 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1879 static HRESULT WINAPI HTMLWindow4_GetTypeInfoCount(IHTMLWindow4 *iface, UINT *pctinfo)
1881 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1883 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1886 static HRESULT WINAPI HTMLWindow4_GetTypeInfo(IHTMLWindow4 *iface, UINT iTInfo,
1887 LCID lcid, ITypeInfo **ppTInfo)
1889 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1891 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1894 static HRESULT WINAPI HTMLWindow4_GetIDsOfNames(IHTMLWindow4 *iface, REFIID riid,
1895 LPOLESTR *rgszNames, UINT cNames,
1896 LCID lcid, DISPID *rgDispId)
1898 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1900 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1901 rgDispId);
1904 static HRESULT WINAPI HTMLWindow4_Invoke(IHTMLWindow4 *iface, DISPID dispIdMember,
1905 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1906 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1908 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1910 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1911 pDispParams, pVarResult, pExcepInfo, puArgErr);
1914 static HRESULT WINAPI HTMLWindow4_createPopup(IHTMLWindow4 *iface, VARIANT *varArgIn,
1915 IDispatch **ppPopup)
1917 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1918 FIXME("(%p)->(%p %p)\n", This, varArgIn, ppPopup);
1919 return E_NOTIMPL;
1922 static HRESULT WINAPI HTMLWindow4_get_frameElement(IHTMLWindow4 *iface, IHTMLFrameBase **p)
1924 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1925 TRACE("(%p)->(%p)\n", This, p);
1927 if(This->outer_window->frame_element) {
1928 *p = &This->outer_window->frame_element->IHTMLFrameBase_iface;
1929 IHTMLFrameBase_AddRef(*p);
1930 }else
1931 *p = NULL;
1933 return S_OK;
1936 static const IHTMLWindow4Vtbl HTMLWindow4Vtbl = {
1937 HTMLWindow4_QueryInterface,
1938 HTMLWindow4_AddRef,
1939 HTMLWindow4_Release,
1940 HTMLWindow4_GetTypeInfoCount,
1941 HTMLWindow4_GetTypeInfo,
1942 HTMLWindow4_GetIDsOfNames,
1943 HTMLWindow4_Invoke,
1944 HTMLWindow4_createPopup,
1945 HTMLWindow4_get_frameElement
1948 static inline HTMLWindow *impl_from_IHTMLWindow5(IHTMLWindow5 *iface)
1950 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow5_iface);
1953 static HRESULT WINAPI HTMLWindow5_QueryInterface(IHTMLWindow5 *iface, REFIID riid, void **ppv)
1955 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1957 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1960 static ULONG WINAPI HTMLWindow5_AddRef(IHTMLWindow5 *iface)
1962 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1964 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1967 static ULONG WINAPI HTMLWindow5_Release(IHTMLWindow5 *iface)
1969 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1971 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1974 static HRESULT WINAPI HTMLWindow5_GetTypeInfoCount(IHTMLWindow5 *iface, UINT *pctinfo)
1976 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1978 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1981 static HRESULT WINAPI HTMLWindow5_GetTypeInfo(IHTMLWindow5 *iface, UINT iTInfo,
1982 LCID lcid, ITypeInfo **ppTInfo)
1984 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1986 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1989 static HRESULT WINAPI HTMLWindow5_GetIDsOfNames(IHTMLWindow5 *iface, REFIID riid,
1990 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1992 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1994 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1995 rgDispId);
1998 static HRESULT WINAPI HTMLWindow5_Invoke(IHTMLWindow5 *iface, DISPID dispIdMember,
1999 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2000 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2002 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
2004 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
2005 pDispParams, pVarResult, pExcepInfo, puArgErr);
2008 static HRESULT WINAPI HTMLWindow5_put_XMLHttpRequest(IHTMLWindow5 *iface, VARIANT v)
2010 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
2011 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
2012 return E_NOTIMPL;
2015 static HRESULT WINAPI HTMLWindow5_get_XMLHttpRequest(IHTMLWindow5 *iface, VARIANT *p)
2017 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
2018 HTMLInnerWindow *window = This->inner_window;
2020 TRACE("(%p)->(%p)\n", This, p);
2022 if(!window->xhr_factory) {
2023 HRESULT hres;
2025 hres = HTMLXMLHttpRequestFactory_Create(window, &window->xhr_factory);
2026 if(FAILED(hres)) {
2027 return hres;
2031 V_VT(p) = VT_DISPATCH;
2032 V_DISPATCH(p) = (IDispatch*)&window->xhr_factory->IHTMLXMLHttpRequestFactory_iface;
2033 IDispatch_AddRef(V_DISPATCH(p));
2035 return S_OK;
2038 static const IHTMLWindow5Vtbl HTMLWindow5Vtbl = {
2039 HTMLWindow5_QueryInterface,
2040 HTMLWindow5_AddRef,
2041 HTMLWindow5_Release,
2042 HTMLWindow5_GetTypeInfoCount,
2043 HTMLWindow5_GetTypeInfo,
2044 HTMLWindow5_GetIDsOfNames,
2045 HTMLWindow5_Invoke,
2046 HTMLWindow5_put_XMLHttpRequest,
2047 HTMLWindow5_get_XMLHttpRequest
2050 static inline HTMLWindow *impl_from_IHTMLWindow6(IHTMLWindow6 *iface)
2052 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow6_iface);
2055 static HRESULT WINAPI HTMLWindow6_QueryInterface(IHTMLWindow6 *iface, REFIID riid, void **ppv)
2057 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2059 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2062 static ULONG WINAPI HTMLWindow6_AddRef(IHTMLWindow6 *iface)
2064 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2066 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2069 static ULONG WINAPI HTMLWindow6_Release(IHTMLWindow6 *iface)
2071 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2073 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2076 static HRESULT WINAPI HTMLWindow6_GetTypeInfoCount(IHTMLWindow6 *iface, UINT *pctinfo)
2078 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2080 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
2083 static HRESULT WINAPI HTMLWindow6_GetTypeInfo(IHTMLWindow6 *iface, UINT iTInfo,
2084 LCID lcid, ITypeInfo **ppTInfo)
2086 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2088 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2091 static HRESULT WINAPI HTMLWindow6_GetIDsOfNames(IHTMLWindow6 *iface, REFIID riid,
2092 LPOLESTR *rgszNames, UINT cNames,
2093 LCID lcid, DISPID *rgDispId)
2095 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2097 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
2098 rgDispId);
2101 static HRESULT WINAPI HTMLWindow6_Invoke(IHTMLWindow6 *iface, DISPID dispIdMember,
2102 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2103 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2105 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2107 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
2108 pDispParams, pVarResult, pExcepInfo, puArgErr);
2111 static HRESULT WINAPI HTMLWindow6_put_XDomainRequest(IHTMLWindow6 *iface, VARIANT v)
2113 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2114 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
2115 return E_NOTIMPL;
2118 static HRESULT WINAPI HTMLWindow6_get_XDomainRequest(IHTMLWindow6 *iface, VARIANT *p)
2120 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2121 FIXME("(%p)->(%p)\n", This, p);
2122 return E_NOTIMPL;
2125 static HRESULT WINAPI HTMLWindow6_get_sessionStorage(IHTMLWindow6 *iface, IHTMLStorage **p)
2127 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2129 TRACE("(%p)->(%p)\n", This, p);
2131 if(!This->inner_window->session_storage) {
2132 HRESULT hres;
2134 hres = create_storage(&This->inner_window->session_storage);
2135 if(FAILED(hres))
2136 return hres;
2139 IHTMLStorage_AddRef(This->inner_window->session_storage);
2140 *p = This->inner_window->session_storage;
2141 return S_OK;
2144 static HRESULT WINAPI HTMLWindow6_get_localStorage(IHTMLWindow6 *iface, IHTMLStorage **p)
2146 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2148 TRACE("(%p)->(%p)\n", This, p);
2150 if(!This->inner_window->local_storage) {
2151 HRESULT hres;
2153 hres = create_storage(&This->inner_window->local_storage);
2154 if(FAILED(hres))
2155 return hres;
2158 IHTMLStorage_AddRef(This->inner_window->local_storage);
2159 *p = This->inner_window->local_storage;
2160 return S_OK;
2163 static HRESULT WINAPI HTMLWindow6_put_onhashchange(IHTMLWindow6 *iface, VARIANT v)
2165 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2166 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
2167 return E_NOTIMPL;
2170 static HRESULT WINAPI HTMLWindow6_get_onhashchange(IHTMLWindow6 *iface, VARIANT *p)
2172 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2173 FIXME("(%p)->(%p)\n", This, p);
2174 return E_NOTIMPL;
2177 static HRESULT WINAPI HTMLWindow6_get_maxConnectionsPerServer(IHTMLWindow6 *iface, LONG *p)
2179 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2180 FIXME("(%p)->(%p)\n", This, p);
2181 return E_NOTIMPL;
2184 static HRESULT WINAPI HTMLWindow6_postMessage(IHTMLWindow6 *iface, BSTR msg, VARIANT targetOrigin)
2186 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2187 DOMEvent *event;
2188 HRESULT hres;
2190 FIXME("(%p)->(%s %s) semi-stub\n", This, debugstr_w(msg), debugstr_variant(&targetOrigin));
2192 if(!This->inner_window->doc) {
2193 FIXME("No document\n");
2194 return E_FAIL;
2197 hres = create_document_event(This->inner_window->doc, EVENTID_MESSAGE, &event);
2198 if(FAILED(hres))
2199 return hres;
2201 dispatch_event(&This->inner_window->event_target, event);
2202 IDOMEvent_Release(&event->IDOMEvent_iface);
2203 return S_OK;
2206 static HRESULT WINAPI HTMLWindow6_toStaticHTML(IHTMLWindow6 *iface, BSTR bstrHTML, BSTR *pbstrStaticHTML)
2208 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2209 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrHTML), pbstrStaticHTML);
2210 return E_NOTIMPL;
2213 static HRESULT WINAPI HTMLWindow6_put_onmessage(IHTMLWindow6 *iface, VARIANT v)
2215 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2217 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
2219 return set_window_event(This, EVENTID_MESSAGE, &v);
2222 static HRESULT WINAPI HTMLWindow6_get_onmessage(IHTMLWindow6 *iface, VARIANT *p)
2224 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2226 TRACE("(%p)->(%p)\n", This, p);
2228 return get_window_event(This, EVENTID_MESSAGE, p);
2231 static HRESULT WINAPI HTMLWindow6_msWriteProfilerMark(IHTMLWindow6 *iface, BSTR bstrProfilerMark)
2233 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2234 FIXME("(%p)->(%s)\n", This, debugstr_w(bstrProfilerMark));
2235 return E_NOTIMPL;
2238 static const IHTMLWindow6Vtbl HTMLWindow6Vtbl = {
2239 HTMLWindow6_QueryInterface,
2240 HTMLWindow6_AddRef,
2241 HTMLWindow6_Release,
2242 HTMLWindow6_GetTypeInfoCount,
2243 HTMLWindow6_GetTypeInfo,
2244 HTMLWindow6_GetIDsOfNames,
2245 HTMLWindow6_Invoke,
2246 HTMLWindow6_put_XDomainRequest,
2247 HTMLWindow6_get_XDomainRequest,
2248 HTMLWindow6_get_sessionStorage,
2249 HTMLWindow6_get_localStorage,
2250 HTMLWindow6_put_onhashchange,
2251 HTMLWindow6_get_onhashchange,
2252 HTMLWindow6_get_maxConnectionsPerServer,
2253 HTMLWindow6_postMessage,
2254 HTMLWindow6_toStaticHTML,
2255 HTMLWindow6_put_onmessage,
2256 HTMLWindow6_get_onmessage,
2257 HTMLWindow6_msWriteProfilerMark
2260 static inline HTMLWindow *impl_from_IHTMLWindow7(IHTMLWindow7 *iface)
2262 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow7_iface);
2265 static HRESULT WINAPI HTMLWindow7_QueryInterface(IHTMLWindow7 *iface, REFIID riid, void **ppv)
2267 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2269 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2272 static ULONG WINAPI HTMLWindow7_AddRef(IHTMLWindow7 *iface)
2274 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2275 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2278 static ULONG WINAPI HTMLWindow7_Release(IHTMLWindow7 *iface)
2280 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2281 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2284 static HRESULT WINAPI HTMLWindow7_GetTypeInfoCount(IHTMLWindow7 *iface, UINT *pctinfo)
2286 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2287 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
2290 static HRESULT WINAPI HTMLWindow7_GetTypeInfo(IHTMLWindow7 *iface, UINT iTInfo,
2291 LCID lcid, ITypeInfo **ppTInfo)
2293 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2294 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2297 static HRESULT WINAPI HTMLWindow7_GetIDsOfNames(IHTMLWindow7 *iface, REFIID riid,
2298 LPOLESTR *rgszNames, UINT cNames,
2299 LCID lcid, DISPID *rgDispId)
2301 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2302 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
2303 rgDispId);
2306 static HRESULT WINAPI HTMLWindow7_Invoke(IHTMLWindow7 *iface, DISPID dispIdMember,
2307 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2308 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2310 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2311 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
2312 pDispParams, pVarResult, pExcepInfo, puArgErr);
2315 static HRESULT WINAPI HTMLWindow7_getSelection(IHTMLWindow7 *iface, IHTMLSelection **p)
2317 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2318 FIXME("(%p)->(%p)\n", This, p);
2319 return E_NOTIMPL;
2322 static HRESULT WINAPI HTMLWindow7_getComputedStyle(IHTMLWindow7 *iface, IHTMLDOMNode *node,
2323 BSTR pseudo_elt, IHTMLCSSStyleDeclaration **p)
2325 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2326 nsIDOMCSSStyleDeclaration *nsstyle;
2327 nsAString pseudo_elt_str;
2328 HTMLElement *element;
2329 IHTMLElement *elem;
2330 nsresult nsres;
2331 HRESULT hres;
2333 TRACE("(%p)->(%p %s %p)\n", This, node, debugstr_w(pseudo_elt), p);
2335 if(!This->outer_window || !This->inner_window)
2336 return E_UNEXPECTED;
2338 hres = IHTMLDOMNode_QueryInterface(node, &IID_IHTMLElement, (void**)&elem);
2339 if(FAILED(hres))
2340 return hres;
2342 element = unsafe_impl_from_IHTMLElement(elem);
2343 if(!element) {
2344 WARN("Not our element\n");
2345 IHTMLElement_Release(elem);
2346 return E_INVALIDARG;
2349 nsAString_Init(&pseudo_elt_str, NULL);
2350 nsres = nsIDOMWindow_GetComputedStyle(This->outer_window->nswindow, element->dom_element,
2351 &pseudo_elt_str, &nsstyle);
2352 IHTMLElement_Release(elem);
2353 nsAString_Finish(&pseudo_elt_str);
2354 if(NS_FAILED(nsres)) {
2355 FIXME("GetComputedStyle failed: %08x\n", nsres);
2356 return E_FAIL;
2359 hres = create_computed_style(nsstyle, dispex_compat_mode(&This->inner_window->event_target.dispex), p);
2360 nsIDOMCSSStyleDeclaration_Release(nsstyle);
2361 return hres;
2364 static HRESULT WINAPI HTMLWindow7_get_styleMedia(IHTMLWindow7 *iface, IHTMLStyleMedia **p)
2366 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2367 FIXME("(%p)->(%p)\n", This, p);
2368 return E_NOTIMPL;
2371 static HRESULT WINAPI HTMLWindow7_put_performance(IHTMLWindow7 *iface, VARIANT v)
2373 HTMLInnerWindow *This = impl_from_IHTMLWindow7(iface)->inner_window;
2375 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
2377 if(!This->performance_initialized) {
2378 V_VT(&This->performance) = VT_EMPTY;
2379 This->performance_initialized = TRUE;
2382 return VariantCopy(&This->performance, &v);
2385 static HRESULT WINAPI HTMLWindow7_get_performance(IHTMLWindow7 *iface, VARIANT *p)
2387 HTMLInnerWindow *This = impl_from_IHTMLWindow7(iface)->inner_window;
2388 HRESULT hres;
2390 TRACE("(%p)->(%p)\n", This, p);
2392 if(!This->performance_initialized) {
2393 IHTMLPerformance *performance;
2395 hres = create_performance(&performance);
2396 if(FAILED(hres))
2397 return hres;
2399 V_VT(&This->performance) = VT_DISPATCH;
2400 V_DISPATCH(&This->performance) = (IDispatch*)performance;
2401 This->performance_initialized = TRUE;
2404 V_VT(p) = VT_NULL;
2405 return VariantCopy(p, &This->performance);
2408 static HRESULT WINAPI HTMLWindow7_get_innerWidth(IHTMLWindow7 *iface, LONG *p)
2410 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2411 INT32 ret;
2412 nsresult nsres;
2414 TRACE("(%p)->(%p)\n", This, p);
2416 nsres = nsIDOMWindow_GetInnerWidth(This->outer_window->nswindow, &ret);
2417 if(NS_FAILED(nsres)) {
2418 ERR("GetInnerWidth failed: %08x\n", nsres);
2419 return E_FAIL;
2422 *p = ret;
2423 return S_OK;
2426 static HRESULT WINAPI HTMLWindow7_get_innerHeight(IHTMLWindow7 *iface, LONG *p)
2428 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2429 INT32 ret;
2430 nsresult nsres;
2432 TRACE("(%p)->(%p)\n", This, p);
2434 nsres = nsIDOMWindow_GetInnerHeight(This->outer_window->nswindow, &ret);
2435 if(NS_FAILED(nsres)) {
2436 ERR("GetInnerWidth failed: %08x\n", nsres);
2437 return E_FAIL;
2440 *p = ret;
2441 return S_OK;
2444 static HRESULT WINAPI HTMLWindow7_get_pageXOffset(IHTMLWindow7 *iface, LONG *p)
2446 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2447 nsresult nsres;
2448 INT32 ret;
2450 TRACE("(%p)->(%p)\n", This, p);
2452 nsres = nsIDOMWindow_GetPageXOffset(This->outer_window->nswindow, &ret);
2453 if(NS_FAILED(nsres)) {
2454 ERR("GetPageXOffset failed: %08x\n", nsres);
2455 return E_FAIL;
2458 *p = ret;
2459 return S_OK;
2462 static HRESULT WINAPI HTMLWindow7_get_pageYOffset(IHTMLWindow7 *iface, LONG *p)
2464 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2465 nsresult nsres;
2466 INT32 ret;
2468 TRACE("(%p)->(%p)\n", This, p);
2470 nsres = nsIDOMWindow_GetPageYOffset(This->outer_window->nswindow, &ret);
2471 if(NS_FAILED(nsres)) {
2472 ERR("GetPageYOffset failed: %08x\n", nsres);
2473 return E_FAIL;
2476 *p = ret;
2477 return S_OK;
2480 static HRESULT WINAPI HTMLWindow7_get_screenX(IHTMLWindow7 *iface, LONG *p)
2482 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2483 FIXME("(%p)->(%p)\n", This, p);
2484 return E_NOTIMPL;
2487 static HRESULT WINAPI HTMLWindow7_get_screenY(IHTMLWindow7 *iface, LONG *p)
2489 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2490 FIXME("(%p)->(%p)\n", This, p);
2491 return E_NOTIMPL;
2494 static HRESULT WINAPI HTMLWindow7_get_outerWidth(IHTMLWindow7 *iface, LONG *p)
2496 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2497 FIXME("(%p)->(%p)\n", This, p);
2498 return E_NOTIMPL;
2501 static HRESULT WINAPI HTMLWindow7_get_outerHeight(IHTMLWindow7 *iface, LONG *p)
2503 HTMLWindow *This = impl_from_IHTMLWindow7(iface);
2504 FIXME("(%p)->(%p)\n", This, p);
2505 return E_NOTIMPL;
2508 #define HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(name, event_id) \
2509 static HRESULT WINAPI HTMLWindow7_put_on##name(IHTMLWindow7 *iface, VARIANT v) \
2511 HTMLWindow *This = impl_from_IHTMLWindow7(iface); \
2512 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v)); \
2513 return set_window_event(This, event_id, &v); \
2515 static HRESULT WINAPI HTMLWindow7_get_on##name(IHTMLWindow7 *iface, VARIANT *p) \
2517 HTMLWindow *This = impl_from_IHTMLWindow7(iface); \
2518 TRACE("(%p)->(%p)\n", This, p); \
2519 return get_window_event(This, event_id, p); \
2522 #define HTMLWINDOW7_ONEVENT_PROPERTY_STUB(name) \
2523 static HRESULT WINAPI HTMLWindow7_put_on##name(IHTMLWindow7 *iface, VARIANT v) \
2525 HTMLWindow *This = impl_from_IHTMLWindow7(iface); \
2526 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v)); \
2527 return E_NOTIMPL; \
2529 static HRESULT WINAPI HTMLWindow7_get_on##name(IHTMLWindow7 *iface, VARIANT *p) \
2531 HTMLWindow *This = impl_from_IHTMLWindow7(iface); \
2532 FIXME("(%p)->(%p)\n", This, p); \
2533 return E_NOTIMPL; \
2536 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(abort, EVENTID_ABORT)
2537 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(canplay)
2538 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(canplaythrough)
2539 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(change)
2540 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(click)
2541 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(contextmenu, EVENTID_CONTEXTMENU)
2542 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(dblclick, EVENTID_DBLCLICK)
2543 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(drag, EVENTID_DRAG)
2544 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(dragend)
2545 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(dragenter)
2546 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(dragleave)
2547 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(dragover)
2548 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(dragstart, EVENTID_DRAGSTART)
2549 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(drop)
2550 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(durationchange)
2551 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(focusin, EVENTID_FOCUSIN)
2552 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(focusout, EVENTID_FOCUSOUT)
2553 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(input, EVENTID_INPUT)
2554 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(emptied)
2555 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(ended)
2556 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(keydown, EVENTID_KEYDOWN)
2557 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(keypress, EVENTID_KEYPRESS)
2558 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(keyup)
2559 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(loadeddata)
2560 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(loadedmetadata)
2561 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(loadstart)
2562 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(mousedown, EVENTID_MOUSEDOWN)
2563 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(mouseenter)
2564 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(mouseleave)
2565 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(mousemove, EVENTID_MOUSEMOVE)
2566 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(mouseout, EVENTID_MOUSEOUT)
2567 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(mouseover, EVENTID_MOUSEOVER)
2568 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(mouseup, EVENTID_MOUSEUP)
2569 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(mousewheel, EVENTID_MOUSEWHEEL)
2570 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(offline)
2571 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(online)
2572 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(progress)
2573 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(ratechange)
2574 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(readystatechange, EVENTID_READYSTATECHANGE)
2575 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(reset)
2576 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(seeked)
2577 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(seeking)
2578 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(select)
2579 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(stalled)
2580 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(storage)
2581 HTMLWINDOW7_ONEVENT_PROPERTY_IMPL(submit, EVENTID_SUBMIT)
2582 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(suspend)
2583 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(timeupdate)
2584 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(pause)
2585 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(play)
2586 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(playing)
2587 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(volumechange)
2588 HTMLWINDOW7_ONEVENT_PROPERTY_STUB(waiting)
2590 static const IHTMLWindow7Vtbl HTMLWindow7Vtbl = {
2591 HTMLWindow7_QueryInterface,
2592 HTMLWindow7_AddRef,
2593 HTMLWindow7_Release,
2594 HTMLWindow7_GetTypeInfoCount,
2595 HTMLWindow7_GetTypeInfo,
2596 HTMLWindow7_GetIDsOfNames,
2597 HTMLWindow7_Invoke,
2598 HTMLWindow7_getSelection,
2599 HTMLWindow7_getComputedStyle,
2600 HTMLWindow7_get_styleMedia,
2601 HTMLWindow7_put_performance,
2602 HTMLWindow7_get_performance,
2603 HTMLWindow7_get_innerWidth,
2604 HTMLWindow7_get_innerHeight,
2605 HTMLWindow7_get_pageXOffset,
2606 HTMLWindow7_get_pageYOffset,
2607 HTMLWindow7_get_screenX,
2608 HTMLWindow7_get_screenY,
2609 HTMLWindow7_get_outerWidth,
2610 HTMLWindow7_get_outerHeight,
2611 HTMLWindow7_put_onabort,
2612 HTMLWindow7_get_onabort,
2613 HTMLWindow7_put_oncanplay,
2614 HTMLWindow7_get_oncanplay,
2615 HTMLWindow7_put_oncanplaythrough,
2616 HTMLWindow7_get_oncanplaythrough,
2617 HTMLWindow7_put_onchange,
2618 HTMLWindow7_get_onchange,
2619 HTMLWindow7_put_onclick,
2620 HTMLWindow7_get_onclick,
2621 HTMLWindow7_put_oncontextmenu,
2622 HTMLWindow7_get_oncontextmenu,
2623 HTMLWindow7_put_ondblclick,
2624 HTMLWindow7_get_ondblclick,
2625 HTMLWindow7_put_ondrag,
2626 HTMLWindow7_get_ondrag,
2627 HTMLWindow7_put_ondragend,
2628 HTMLWindow7_get_ondragend,
2629 HTMLWindow7_put_ondragenter,
2630 HTMLWindow7_get_ondragenter,
2631 HTMLWindow7_put_ondragleave,
2632 HTMLWindow7_get_ondragleave,
2633 HTMLWindow7_put_ondragover,
2634 HTMLWindow7_get_ondragover,
2635 HTMLWindow7_put_ondragstart,
2636 HTMLWindow7_get_ondragstart,
2637 HTMLWindow7_put_ondrop,
2638 HTMLWindow7_get_ondrop,
2639 HTMLWindow7_put_ondurationchange,
2640 HTMLWindow7_get_ondurationchange,
2641 HTMLWindow7_put_onfocusin,
2642 HTMLWindow7_get_onfocusin,
2643 HTMLWindow7_put_onfocusout,
2644 HTMLWindow7_get_onfocusout,
2645 HTMLWindow7_put_oninput,
2646 HTMLWindow7_get_oninput,
2647 HTMLWindow7_put_onemptied,
2648 HTMLWindow7_get_onemptied,
2649 HTMLWindow7_put_onended,
2650 HTMLWindow7_get_onended,
2651 HTMLWindow7_put_onkeydown,
2652 HTMLWindow7_get_onkeydown,
2653 HTMLWindow7_put_onkeypress,
2654 HTMLWindow7_get_onkeypress,
2655 HTMLWindow7_put_onkeyup,
2656 HTMLWindow7_get_onkeyup,
2657 HTMLWindow7_put_onloadeddata,
2658 HTMLWindow7_get_onloadeddata,
2659 HTMLWindow7_put_onloadedmetadata,
2660 HTMLWindow7_get_onloadedmetadata,
2661 HTMLWindow7_put_onloadstart,
2662 HTMLWindow7_get_onloadstart,
2663 HTMLWindow7_put_onmousedown,
2664 HTMLWindow7_get_onmousedown,
2665 HTMLWindow7_put_onmouseenter,
2666 HTMLWindow7_get_onmouseenter,
2667 HTMLWindow7_put_onmouseleave,
2668 HTMLWindow7_get_onmouseleave,
2669 HTMLWindow7_put_onmousemove,
2670 HTMLWindow7_get_onmousemove,
2671 HTMLWindow7_put_onmouseout,
2672 HTMLWindow7_get_onmouseout,
2673 HTMLWindow7_put_onmouseover,
2674 HTMLWindow7_get_onmouseover,
2675 HTMLWindow7_put_onmouseup,
2676 HTMLWindow7_get_onmouseup,
2677 HTMLWindow7_put_onmousewheel,
2678 HTMLWindow7_get_onmousewheel,
2679 HTMLWindow7_put_onoffline,
2680 HTMLWindow7_get_onoffline,
2681 HTMLWindow7_put_ononline,
2682 HTMLWindow7_get_ononline,
2683 HTMLWindow7_put_onprogress,
2684 HTMLWindow7_get_onprogress,
2685 HTMLWindow7_put_onratechange,
2686 HTMLWindow7_get_onratechange,
2687 HTMLWindow7_put_onreadystatechange,
2688 HTMLWindow7_get_onreadystatechange,
2689 HTMLWindow7_put_onreset,
2690 HTMLWindow7_get_onreset,
2691 HTMLWindow7_put_onseeked,
2692 HTMLWindow7_get_onseeked,
2693 HTMLWindow7_put_onseeking,
2694 HTMLWindow7_get_onseeking,
2695 HTMLWindow7_put_onselect,
2696 HTMLWindow7_get_onselect,
2697 HTMLWindow7_put_onstalled,
2698 HTMLWindow7_get_onstalled,
2699 HTMLWindow7_put_onstorage,
2700 HTMLWindow7_get_onstorage,
2701 HTMLWindow7_put_onsubmit,
2702 HTMLWindow7_get_onsubmit,
2703 HTMLWindow7_put_onsuspend,
2704 HTMLWindow7_get_onsuspend,
2705 HTMLWindow7_put_ontimeupdate,
2706 HTMLWindow7_get_ontimeupdate,
2707 HTMLWindow7_put_onpause,
2708 HTMLWindow7_get_onpause,
2709 HTMLWindow7_put_onplay,
2710 HTMLWindow7_get_onplay,
2711 HTMLWindow7_put_onplaying,
2712 HTMLWindow7_get_onplaying,
2713 HTMLWindow7_put_onvolumechange,
2714 HTMLWindow7_get_onvolumechange,
2715 HTMLWindow7_put_onwaiting,
2716 HTMLWindow7_get_onwaiting
2719 static inline HTMLWindow *impl_from_IHTMLPrivateWindow(IHTMLPrivateWindow *iface)
2721 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLPrivateWindow_iface);
2724 static HRESULT WINAPI HTMLPrivateWindow_QueryInterface(IHTMLPrivateWindow *iface, REFIID riid, void **ppv)
2726 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2728 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2731 static ULONG WINAPI HTMLPrivateWindow_AddRef(IHTMLPrivateWindow *iface)
2733 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2735 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2738 static ULONG WINAPI HTMLPrivateWindow_Release(IHTMLPrivateWindow *iface)
2740 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2742 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2745 static HRESULT WINAPI HTMLPrivateWindow_SuperNavigate(IHTMLPrivateWindow *iface, BSTR url, BSTR arg2, BSTR arg3,
2746 BSTR arg4, VARIANT *post_data_var, VARIANT *headers_var, ULONG flags)
2748 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2749 HTMLOuterWindow *window = This->outer_window;
2750 OLECHAR *translated_url = NULL;
2751 DWORD post_data_size = 0;
2752 BYTE *post_data = NULL;
2753 WCHAR *headers = NULL;
2754 IUri *uri;
2755 HRESULT hres;
2757 TRACE("(%p)->(%s %s %s %s %s %s %x)\n", This, debugstr_w(url), debugstr_w(arg2), debugstr_w(arg3), debugstr_w(arg4),
2758 debugstr_variant(post_data_var), debugstr_variant(headers_var), flags);
2760 if(!window || !window->browser)
2761 return E_UNEXPECTED;
2763 if(window->browser->doc->hostui) {
2764 hres = IDocHostUIHandler_TranslateUrl(window->browser->doc->hostui, 0, url, &translated_url);
2765 if(hres != S_OK)
2766 translated_url = NULL;
2769 hres = create_uri(translated_url ? translated_url : url, 0, &uri);
2770 CoTaskMemFree(translated_url);
2771 if(FAILED(hres))
2772 return hres;
2774 if(post_data_var) {
2775 if(V_VT(post_data_var) == (VT_ARRAY|VT_UI1)) {
2776 SafeArrayAccessData(V_ARRAY(post_data_var), (void**)&post_data);
2777 post_data_size = V_ARRAY(post_data_var)->rgsabound[0].cElements;
2781 if(headers_var && V_VT(headers_var) != VT_EMPTY && V_VT(headers_var) != VT_ERROR) {
2782 if(V_VT(headers_var) != VT_BSTR)
2783 return E_INVALIDARG;
2785 headers = V_BSTR(headers_var);
2788 hres = super_navigate(window, uri, BINDING_NAVIGATED|BINDING_NOFRAG, headers, post_data, post_data_size);
2789 IUri_Release(uri);
2790 if(post_data)
2791 SafeArrayUnaccessData(V_ARRAY(post_data_var));
2793 return hres;
2796 static HRESULT WINAPI HTMLPrivateWindow_GetPendingUrl(IHTMLPrivateWindow *iface, BSTR *url)
2798 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2799 FIXME("(%p)->(%p)\n", This, url);
2800 return E_NOTIMPL;
2803 static HRESULT WINAPI HTMLPrivateWindow_SetPICSTarget(IHTMLPrivateWindow *iface, IOleCommandTarget *cmdtrg)
2805 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2806 FIXME("(%p)->(%p)\n", This, cmdtrg);
2807 return E_NOTIMPL;
2810 static HRESULT WINAPI HTMLPrivateWindow_PICSComplete(IHTMLPrivateWindow *iface, int arg)
2812 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2813 FIXME("(%p)->(%x)\n", This, arg);
2814 return E_NOTIMPL;
2817 static HRESULT WINAPI HTMLPrivateWindow_FindWindowByName(IHTMLPrivateWindow *iface, LPCWSTR name, IHTMLWindow2 **ret)
2819 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2820 FIXME("(%p)->(%s %p)\n", This, debugstr_w(name), ret);
2821 return E_NOTIMPL;
2824 static HRESULT WINAPI HTMLPrivateWindow_GetAddressBarUrl(IHTMLPrivateWindow *iface, BSTR *url)
2826 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2827 TRACE("(%p)->(%p)\n", This, url);
2829 if(!url)
2830 return E_INVALIDARG;
2832 *url = SysAllocString(This->outer_window->url);
2833 return S_OK;
2836 static const IHTMLPrivateWindowVtbl HTMLPrivateWindowVtbl = {
2837 HTMLPrivateWindow_QueryInterface,
2838 HTMLPrivateWindow_AddRef,
2839 HTMLPrivateWindow_Release,
2840 HTMLPrivateWindow_SuperNavigate,
2841 HTMLPrivateWindow_GetPendingUrl,
2842 HTMLPrivateWindow_SetPICSTarget,
2843 HTMLPrivateWindow_PICSComplete,
2844 HTMLPrivateWindow_FindWindowByName,
2845 HTMLPrivateWindow_GetAddressBarUrl
2848 static inline HTMLWindow *impl_from_ITravelLogClient(ITravelLogClient *iface)
2850 return CONTAINING_RECORD(iface, HTMLWindow, ITravelLogClient_iface);
2853 static HRESULT WINAPI TravelLogClient_QueryInterface(ITravelLogClient *iface, REFIID riid, void **ppv)
2855 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2857 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2860 static ULONG WINAPI TravelLogClient_AddRef(ITravelLogClient *iface)
2862 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2864 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2867 static ULONG WINAPI TravelLogClient_Release(ITravelLogClient *iface)
2869 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2871 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2874 static HRESULT WINAPI TravelLogClient_FindWindowByIndex(ITravelLogClient *iface, DWORD dwID, IUnknown **ppunk)
2876 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2878 FIXME("(%p)->(%d %p) semi-stub\n", This, dwID, ppunk);
2880 *ppunk = NULL;
2881 return E_FAIL;
2884 static HRESULT WINAPI TravelLogClient_GetWindowData(ITravelLogClient *iface, IStream *pStream, LPWINDOWDATA pWinData)
2886 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2887 FIXME("(%p)->(%p %p)\n", This, pStream, pWinData);
2888 return E_NOTIMPL;
2891 static HRESULT WINAPI TravelLogClient_LoadHistoryPosition(ITravelLogClient *iface, LPWSTR pszUrlLocation, DWORD dwPosition)
2893 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2894 FIXME("(%p)->(%s %d)\n", This, debugstr_w(pszUrlLocation), dwPosition);
2895 return E_NOTIMPL;
2898 static const ITravelLogClientVtbl TravelLogClientVtbl = {
2899 TravelLogClient_QueryInterface,
2900 TravelLogClient_AddRef,
2901 TravelLogClient_Release,
2902 TravelLogClient_FindWindowByIndex,
2903 TravelLogClient_GetWindowData,
2904 TravelLogClient_LoadHistoryPosition
2907 static inline HTMLWindow *impl_from_IObjectIdentity(IObjectIdentity *iface)
2909 return CONTAINING_RECORD(iface, HTMLWindow, IObjectIdentity_iface);
2912 static HRESULT WINAPI ObjectIdentity_QueryInterface(IObjectIdentity *iface, REFIID riid, void **ppv)
2914 HTMLWindow *This = impl_from_IObjectIdentity(iface);
2916 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2919 static ULONG WINAPI ObjectIdentity_AddRef(IObjectIdentity *iface)
2921 HTMLWindow *This = impl_from_IObjectIdentity(iface);
2923 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2926 static ULONG WINAPI ObjectIdentity_Release(IObjectIdentity *iface)
2928 HTMLWindow *This = impl_from_IObjectIdentity(iface);
2930 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2933 static HRESULT WINAPI ObjectIdentity_IsEqualObject(IObjectIdentity *iface, IUnknown *unk)
2935 HTMLWindow *This = impl_from_IObjectIdentity(iface);
2936 IServiceProvider *sp;
2937 HRESULT hres;
2939 TRACE("(%p)->(%p)\n", This, unk);
2941 hres = IUnknown_QueryInterface(unk, &IID_IServiceProvider, (void**)&sp);
2942 if(hres != S_OK)
2943 return hres;
2945 hres = &This->inner_window->base.IServiceProvider_iface==sp ||
2946 &This->outer_window->base.IServiceProvider_iface==sp ? S_OK : S_FALSE;
2947 IServiceProvider_Release(sp);
2948 return hres;
2951 static const IObjectIdentityVtbl ObjectIdentityVtbl = {
2952 ObjectIdentity_QueryInterface,
2953 ObjectIdentity_AddRef,
2954 ObjectIdentity_Release,
2955 ObjectIdentity_IsEqualObject
2958 static inline HTMLWindow *impl_from_IProvideMultipleClassInfo(IProvideMultipleClassInfo *iface)
2960 return CONTAINING_RECORD(iface, HTMLWindow, IProvideMultipleClassInfo_iface);
2963 static HRESULT WINAPI ProvideClassInfo_QueryInterface(IProvideMultipleClassInfo *iface,
2964 REFIID riid, void **ppv)
2966 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
2967 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2970 static ULONG WINAPI ProvideClassInfo_AddRef(IProvideMultipleClassInfo *iface)
2972 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
2973 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2976 static ULONG WINAPI ProvideClassInfo_Release(IProvideMultipleClassInfo *iface)
2978 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
2979 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2982 static HRESULT WINAPI ProvideClassInfo_GetClassInfo(IProvideMultipleClassInfo *iface, ITypeInfo **ppTI)
2984 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
2985 TRACE("(%p)->(%p)\n", This, ppTI);
2986 return get_class_typeinfo(&CLSID_HTMLWindow2, ppTI);
2989 static HRESULT WINAPI ProvideClassInfo2_GetGUID(IProvideMultipleClassInfo *iface, DWORD dwGuidKind, GUID *pGUID)
2991 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
2992 FIXME("(%p)->(%u %p)\n", This, dwGuidKind, pGUID);
2993 return E_NOTIMPL;
2996 static HRESULT WINAPI ProvideMultipleClassInfo_GetMultiTypeInfoCount(IProvideMultipleClassInfo *iface, ULONG *pcti)
2998 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
2999 FIXME("(%p)->(%p)\n", This, pcti);
3000 *pcti = 1;
3001 return S_OK;
3004 static HRESULT WINAPI ProvideMultipleClassInfo_GetInfoOfIndex(IProvideMultipleClassInfo *iface, ULONG iti,
3005 DWORD dwFlags, ITypeInfo **pptiCoClass, DWORD *pdwTIFlags, ULONG *pcdispidReserved, IID *piidPrimary, IID *piidSource)
3007 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
3008 FIXME("(%p)->(%u %x %p %p %p %p %p)\n", This, iti, dwFlags, pptiCoClass, pdwTIFlags, pcdispidReserved, piidPrimary, piidSource);
3009 return E_NOTIMPL;
3012 static const IProvideMultipleClassInfoVtbl ProvideMultipleClassInfoVtbl = {
3013 ProvideClassInfo_QueryInterface,
3014 ProvideClassInfo_AddRef,
3015 ProvideClassInfo_Release,
3016 ProvideClassInfo_GetClassInfo,
3017 ProvideClassInfo2_GetGUID,
3018 ProvideMultipleClassInfo_GetMultiTypeInfoCount,
3019 ProvideMultipleClassInfo_GetInfoOfIndex
3022 static inline HTMLWindow *impl_from_IDispatchEx(IDispatchEx *iface)
3024 return CONTAINING_RECORD(iface, HTMLWindow, IDispatchEx_iface);
3027 static HRESULT WINAPI WindowDispEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
3029 HTMLWindow *This = impl_from_IDispatchEx(iface);
3031 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
3034 static ULONG WINAPI WindowDispEx_AddRef(IDispatchEx *iface)
3036 HTMLWindow *This = impl_from_IDispatchEx(iface);
3038 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
3041 static ULONG WINAPI WindowDispEx_Release(IDispatchEx *iface)
3043 HTMLWindow *This = impl_from_IDispatchEx(iface);
3045 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
3048 static HRESULT WINAPI WindowDispEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
3050 HTMLWindow *This = impl_from_IDispatchEx(iface);
3052 TRACE("(%p)->(%p)\n", This, pctinfo);
3054 return IDispatchEx_GetTypeInfoCount(&This->inner_window->event_target.dispex.IDispatchEx_iface, pctinfo);
3057 static HRESULT WINAPI WindowDispEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
3058 LCID lcid, ITypeInfo **ppTInfo)
3060 HTMLWindow *This = impl_from_IDispatchEx(iface);
3062 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
3064 return IDispatchEx_GetTypeInfo(&This->inner_window->event_target.dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
3067 static HRESULT WINAPI WindowDispEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
3068 LPOLESTR *rgszNames, UINT cNames,
3069 LCID lcid, DISPID *rgDispId)
3071 HTMLWindow *This = impl_from_IDispatchEx(iface);
3072 UINT i;
3073 HRESULT hres;
3075 WARN("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
3077 for(i=0; i < cNames; i++) {
3078 /* We shouldn't use script's IDispatchEx here, so we shouldn't use GetDispID */
3079 hres = IDispatchEx_GetDispID(&This->IDispatchEx_iface, rgszNames[i], 0, rgDispId+i);
3080 if(FAILED(hres))
3081 return hres;
3084 return S_OK;
3087 static HRESULT WINAPI WindowDispEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
3088 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
3089 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
3091 HTMLWindow *This = impl_from_IDispatchEx(iface);
3093 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
3094 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
3096 /* FIXME: Use script dispatch */
3098 return IDispatchEx_Invoke(&This->inner_window->event_target.dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
3099 pDispParams, pVarResult, pExcepInfo, puArgErr);
3102 static global_prop_t *alloc_global_prop(HTMLInnerWindow *This, global_prop_type_t type, BSTR name)
3104 if(This->global_prop_cnt == This->global_prop_size) {
3105 global_prop_t *new_props;
3106 DWORD new_size;
3108 if(This->global_props) {
3109 new_size = This->global_prop_size*2;
3110 new_props = heap_realloc(This->global_props, new_size*sizeof(global_prop_t));
3111 }else {
3112 new_size = 16;
3113 new_props = heap_alloc(new_size*sizeof(global_prop_t));
3115 if(!new_props)
3116 return NULL;
3117 This->global_props = new_props;
3118 This->global_prop_size = new_size;
3121 This->global_props[This->global_prop_cnt].name = heap_strdupW(name);
3122 if(!This->global_props[This->global_prop_cnt].name)
3123 return NULL;
3125 This->global_props[This->global_prop_cnt].type = type;
3126 return This->global_props + This->global_prop_cnt++;
3129 static inline DWORD prop_to_dispid(HTMLInnerWindow *This, global_prop_t *prop)
3131 return MSHTML_DISPID_CUSTOM_MIN + (prop-This->global_props);
3134 HRESULT search_window_props(HTMLInnerWindow *This, BSTR bstrName, DWORD grfdex, DISPID *pid)
3136 DWORD i;
3137 ScriptHost *script_host;
3138 DISPID id;
3140 for(i=0; i < This->global_prop_cnt; i++) {
3141 /* FIXME: case sensitivity */
3142 if(!wcscmp(This->global_props[i].name, bstrName)) {
3143 *pid = MSHTML_DISPID_CUSTOM_MIN+i;
3144 return S_OK;
3148 if(find_global_prop(This->base.inner_window, bstrName, grfdex, &script_host, &id)) {
3149 global_prop_t *prop;
3151 prop = alloc_global_prop(This, GLOBAL_SCRIPTVAR, bstrName);
3152 if(!prop)
3153 return E_OUTOFMEMORY;
3155 prop->script_host = script_host;
3156 prop->id = id;
3158 *pid = prop_to_dispid(This, prop);
3159 return S_OK;
3162 return DISP_E_UNKNOWNNAME;
3165 static HRESULT WINAPI WindowDispEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
3167 HTMLWindow *This = impl_from_IDispatchEx(iface);
3168 HTMLInnerWindow *window = This->inner_window;
3169 HRESULT hres;
3171 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
3173 hres = search_window_props(window, bstrName, grfdex, pid);
3174 if(hres != DISP_E_UNKNOWNNAME)
3175 return hres;
3177 hres = IDispatchEx_GetDispID(&window->base.inner_window->event_target.dispex.IDispatchEx_iface, bstrName, grfdex, pid);
3178 if(hres != DISP_E_UNKNOWNNAME)
3179 return hres;
3181 if(This->outer_window) {
3182 HTMLOuterWindow *frame;
3184 hres = get_frame_by_name(This->outer_window, bstrName, FALSE, &frame);
3185 if(SUCCEEDED(hres) && frame) {
3186 global_prop_t *prop;
3188 IHTMLWindow2_Release(&frame->base.IHTMLWindow2_iface);
3190 prop = alloc_global_prop(window, GLOBAL_FRAMEVAR, bstrName);
3191 if(!prop)
3192 return E_OUTOFMEMORY;
3194 *pid = prop_to_dispid(window, prop);
3195 return S_OK;
3199 if(window->doc) {
3200 global_prop_t *prop;
3201 IHTMLElement *elem;
3203 hres = IHTMLDocument3_getElementById(&window->base.inner_window->doc->basedoc.IHTMLDocument3_iface,
3204 bstrName, &elem);
3205 if(SUCCEEDED(hres) && elem) {
3206 IHTMLElement_Release(elem);
3208 prop = alloc_global_prop(window, GLOBAL_ELEMENTVAR, bstrName);
3209 if(!prop)
3210 return E_OUTOFMEMORY;
3212 *pid = prop_to_dispid(window, prop);
3213 return S_OK;
3217 return DISP_E_UNKNOWNNAME;
3220 static HRESULT WINAPI WindowDispEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
3221 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
3223 HTMLWindow *This = impl_from_IDispatchEx(iface);
3224 HTMLInnerWindow *window = This->inner_window;
3226 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
3228 switch(id) {
3229 case DISPID_IHTMLWINDOW2_LOCATION: {
3230 HTMLLocation *location;
3231 HRESULT hres;
3233 if(!(wFlags & DISPATCH_PROPERTYPUT))
3234 break;
3236 TRACE("forwarding to location.href\n");
3238 hres = get_location(window, &location);
3239 if(FAILED(hres))
3240 return hres;
3242 hres = IDispatchEx_InvokeEx(&location->dispex.IDispatchEx_iface, DISPID_VALUE, lcid,
3243 wFlags, pdp, pvarRes, pei, pspCaller);
3244 IHTMLLocation_Release(&location->IHTMLLocation_iface);
3245 return hres;
3247 case DISPID_IHTMLWINDOW2_SETTIMEOUT:
3248 case DISPID_IHTMLWINDOW3_SETTIMEOUT: {
3249 VARIANT args[2];
3250 DISPPARAMS dp = {args, NULL, 2, 0};
3253 * setTimeout calls should use default value 0 for the second argument if only one is provided,
3254 * but IDL file does not reflect that. We fixup arguments here instead.
3256 if(!(wFlags & DISPATCH_METHOD) || pdp->cArgs != 1 || pdp->cNamedArgs)
3257 break;
3259 TRACE("Fixing args\n");
3261 V_VT(args) = VT_I4;
3262 V_I4(args) = 0;
3263 args[1] = *pdp->rgvarg;
3264 return IDispatchEx_InvokeEx(&window->event_target.dispex.IDispatchEx_iface, id, lcid,
3265 wFlags, &dp, pvarRes, pei, pspCaller);
3269 return IDispatchEx_InvokeEx(&window->event_target.dispex.IDispatchEx_iface, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
3272 static HRESULT WINAPI WindowDispEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
3274 HTMLWindow *This = impl_from_IDispatchEx(iface);
3276 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
3278 return IDispatchEx_DeleteMemberByName(&This->inner_window->event_target.dispex.IDispatchEx_iface, bstrName, grfdex);
3281 static HRESULT WINAPI WindowDispEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
3283 HTMLWindow *This = impl_from_IDispatchEx(iface);
3285 TRACE("(%p)->(%x)\n", This, id);
3287 return IDispatchEx_DeleteMemberByDispID(&This->inner_window->event_target.dispex.IDispatchEx_iface, id);
3290 static HRESULT WINAPI WindowDispEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
3292 HTMLWindow *This = impl_from_IDispatchEx(iface);
3294 TRACE("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
3296 return IDispatchEx_GetMemberProperties(&This->inner_window->event_target.dispex.IDispatchEx_iface, id, grfdexFetch,
3297 pgrfdex);
3300 static HRESULT WINAPI WindowDispEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
3302 HTMLWindow *This = impl_from_IDispatchEx(iface);
3304 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
3306 return IDispatchEx_GetMemberName(&This->inner_window->event_target.dispex.IDispatchEx_iface, id, pbstrName);
3309 static HRESULT WINAPI WindowDispEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
3311 HTMLWindow *This = impl_from_IDispatchEx(iface);
3313 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
3315 return IDispatchEx_GetNextDispID(&This->inner_window->event_target.dispex.IDispatchEx_iface, grfdex, id, pid);
3318 static HRESULT WINAPI WindowDispEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
3320 HTMLWindow *This = impl_from_IDispatchEx(iface);
3322 TRACE("(%p)->(%p)\n", This, ppunk);
3324 *ppunk = NULL;
3325 return S_OK;
3328 static const IDispatchExVtbl WindowDispExVtbl = {
3329 WindowDispEx_QueryInterface,
3330 WindowDispEx_AddRef,
3331 WindowDispEx_Release,
3332 WindowDispEx_GetTypeInfoCount,
3333 WindowDispEx_GetTypeInfo,
3334 WindowDispEx_GetIDsOfNames,
3335 WindowDispEx_Invoke,
3336 WindowDispEx_GetDispID,
3337 WindowDispEx_InvokeEx,
3338 WindowDispEx_DeleteMemberByName,
3339 WindowDispEx_DeleteMemberByDispID,
3340 WindowDispEx_GetMemberProperties,
3341 WindowDispEx_GetMemberName,
3342 WindowDispEx_GetNextDispID,
3343 WindowDispEx_GetNameSpaceParent
3346 static inline HTMLWindow *impl_from_IServiceProvider(IServiceProvider *iface)
3348 return CONTAINING_RECORD(iface, HTMLWindow, IServiceProvider_iface);
3351 static HRESULT WINAPI HTMLWindowSP_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
3353 HTMLWindow *This = impl_from_IServiceProvider(iface);
3354 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
3357 static ULONG WINAPI HTMLWindowSP_AddRef(IServiceProvider *iface)
3359 HTMLWindow *This = impl_from_IServiceProvider(iface);
3360 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
3363 static ULONG WINAPI HTMLWindowSP_Release(IServiceProvider *iface)
3365 HTMLWindow *This = impl_from_IServiceProvider(iface);
3366 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
3369 static HRESULT WINAPI HTMLWindowSP_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
3371 HTMLWindow *This = impl_from_IServiceProvider(iface);
3373 if(IsEqualGUID(guidService, &IID_IHTMLWindow2)) {
3374 TRACE("IID_IHTMLWindow2\n");
3375 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
3378 TRACE("(%p)->(%s %s %p)\n", This, debugstr_mshtml_guid(guidService), debugstr_mshtml_guid(riid), ppv);
3380 if(!This->outer_window || !This->outer_window->browser)
3381 return E_NOINTERFACE;
3383 return IServiceProvider_QueryService(&This->outer_window->browser->doc->basedoc.IServiceProvider_iface,
3384 guidService, riid, ppv);
3387 static const IServiceProviderVtbl ServiceProviderVtbl = {
3388 HTMLWindowSP_QueryInterface,
3389 HTMLWindowSP_AddRef,
3390 HTMLWindowSP_Release,
3391 HTMLWindowSP_QueryService
3394 static inline HTMLInnerWindow *impl_from_DispatchEx(DispatchEx *iface)
3396 return CONTAINING_RECORD(iface, HTMLInnerWindow, event_target.dispex);
3399 static HRESULT HTMLWindow_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
3400 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
3402 HTMLInnerWindow *This = impl_from_DispatchEx(dispex);
3403 global_prop_t *prop;
3404 DWORD idx;
3405 HRESULT hres;
3407 idx = id - MSHTML_DISPID_CUSTOM_MIN;
3408 if(idx >= This->global_prop_cnt)
3409 return DISP_E_MEMBERNOTFOUND;
3411 prop = This->global_props+idx;
3413 switch(prop->type) {
3414 case GLOBAL_SCRIPTVAR: {
3415 IDispatchEx *iface;
3416 IDispatch *disp;
3418 disp = get_script_disp(prop->script_host);
3419 if(!disp)
3420 return E_UNEXPECTED;
3422 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&iface);
3423 if(SUCCEEDED(hres)) {
3424 TRACE("%s >>>\n", debugstr_w(prop->name));
3425 hres = IDispatchEx_InvokeEx(iface, prop->id, lcid, flags, params, res, ei, caller);
3426 if(hres == S_OK)
3427 TRACE("%s <<<\n", debugstr_w(prop->name));
3428 else
3429 WARN("%s <<< %08x\n", debugstr_w(prop->name), hres);
3430 IDispatchEx_Release(iface);
3431 }else {
3432 FIXME("No IDispatchEx\n");
3434 IDispatch_Release(disp);
3435 break;
3437 case GLOBAL_ELEMENTVAR:
3438 switch(flags) {
3439 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
3440 case DISPATCH_PROPERTYGET: {
3441 IHTMLElement *elem;
3443 hres = IHTMLDocument3_getElementById(&This->base.inner_window->doc->basedoc.IHTMLDocument3_iface,
3444 prop->name, &elem);
3445 if(FAILED(hres))
3446 return hres;
3448 if(!elem)
3449 return DISP_E_MEMBERNOTFOUND;
3451 V_VT(res) = VT_DISPATCH;
3452 V_DISPATCH(res) = (IDispatch*)elem;
3453 return S_OK;
3455 case DISPATCH_PROPERTYPUT: {
3456 DISPID dispex_id;
3458 hres = dispex_get_dynid(&This->event_target.dispex, prop->name, &dispex_id);
3459 if(FAILED(hres))
3460 return hres;
3462 prop->type = GLOBAL_DISPEXVAR;
3463 prop->id = dispex_id;
3464 return IDispatchEx_InvokeEx(&This->event_target.dispex.IDispatchEx_iface, dispex_id, 0, flags, params, res, ei, caller);
3466 default:
3467 FIXME("Not supported flags: %x\n", flags);
3468 return E_NOTIMPL;
3470 case GLOBAL_FRAMEVAR:
3471 if(!This->base.outer_window)
3472 return E_UNEXPECTED;
3474 switch(flags) {
3475 case DISPATCH_PROPERTYGET: {
3476 HTMLOuterWindow *frame;
3478 hres = get_frame_by_name(This->base.outer_window, prop->name, FALSE, &frame);
3479 if(FAILED(hres))
3480 return hres;
3482 if(!frame)
3483 return DISP_E_MEMBERNOTFOUND;
3485 V_VT(res) = VT_DISPATCH;
3486 V_DISPATCH(res) = (IDispatch*)&frame->base.inner_window->base.IHTMLWindow2_iface;
3487 IDispatch_AddRef(V_DISPATCH(res));
3488 return S_OK;
3490 default:
3491 FIXME("Not supported flags: %x\n", flags);
3492 return E_NOTIMPL;
3494 case GLOBAL_DISPEXVAR:
3495 return IDispatchEx_InvokeEx(&This->event_target.dispex.IDispatchEx_iface, prop->id, 0, flags, params, res, ei, caller);
3496 default:
3497 ERR("invalid type %d\n", prop->type);
3498 hres = DISP_E_MEMBERNOTFOUND;
3501 return hres;
3504 static compat_mode_t HTMLWindow_get_compat_mode(DispatchEx *dispex)
3506 HTMLInnerWindow *This = impl_from_DispatchEx(dispex);
3507 return lock_document_mode(This->doc);
3510 static nsISupports *HTMLWindow_get_gecko_target(DispatchEx *dispex)
3512 HTMLInnerWindow *This = impl_from_DispatchEx(dispex);
3513 return (nsISupports*)This->base.outer_window->nswindow;
3516 static void HTMLWindow_bind_event(DispatchEx *dispex, eventid_t eid)
3518 HTMLInnerWindow *This = impl_from_DispatchEx(dispex);
3519 ensure_doc_nsevent_handler(This->doc, NULL, eid);
3522 static void HTMLWindow_init_dispex_info(dispex_data_t *info, compat_mode_t compat_mode)
3524 if(compat_mode >= COMPAT_MODE_IE9)
3525 dispex_info_add_interface(info, IHTMLWindow7_tid, NULL);
3526 dispex_info_add_interface(info, IHTMLWindow5_tid, NULL);
3527 EventTarget_init_dispex_info(info, compat_mode);
3530 static IHTMLEventObj *HTMLWindow_set_current_event(DispatchEx *dispex, IHTMLEventObj *event)
3532 HTMLInnerWindow *This = impl_from_DispatchEx(dispex);
3533 return default_set_current_event(This, event);
3536 static const event_target_vtbl_t HTMLWindow_event_target_vtbl = {
3538 NULL,
3539 NULL,
3540 HTMLWindow_invoke,
3541 HTMLWindow_get_compat_mode,
3542 NULL
3544 HTMLWindow_get_gecko_target,
3545 HTMLWindow_bind_event,
3546 NULL,
3547 NULL,
3548 NULL,
3549 HTMLWindow_set_current_event
3552 static const tid_t HTMLWindow_iface_tids[] = {
3553 IHTMLWindow2_tid,
3554 IHTMLWindow3_tid,
3555 IHTMLWindow4_tid,
3556 IHTMLWindow6_tid,
3560 static dispex_static_data_t HTMLWindow_dispex = {
3561 &HTMLWindow_event_target_vtbl.dispex_vtbl,
3562 DispHTMLWindow2_tid,
3563 HTMLWindow_iface_tids,
3564 HTMLWindow_init_dispex_info
3567 static void *alloc_window(size_t size)
3569 HTMLWindow *window;
3571 window = heap_alloc_zero(size);
3572 if(!window)
3573 return NULL;
3575 window->IHTMLWindow2_iface.lpVtbl = &HTMLWindow2Vtbl;
3576 window->IHTMLWindow3_iface.lpVtbl = &HTMLWindow3Vtbl;
3577 window->IHTMLWindow4_iface.lpVtbl = &HTMLWindow4Vtbl;
3578 window->IHTMLWindow5_iface.lpVtbl = &HTMLWindow5Vtbl;
3579 window->IHTMLWindow6_iface.lpVtbl = &HTMLWindow6Vtbl;
3580 window->IHTMLWindow7_iface.lpVtbl = &HTMLWindow7Vtbl;
3581 window->IHTMLPrivateWindow_iface.lpVtbl = &HTMLPrivateWindowVtbl;
3582 window->IDispatchEx_iface.lpVtbl = &WindowDispExVtbl;
3583 window->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
3584 window->ITravelLogClient_iface.lpVtbl = &TravelLogClientVtbl;
3585 window->IObjectIdentity_iface.lpVtbl = &ObjectIdentityVtbl;
3586 window->IProvideMultipleClassInfo_iface.lpVtbl = &ProvideMultipleClassInfoVtbl;
3587 window->ref = 1;
3589 return window;
3592 static HRESULT create_inner_window(HTMLOuterWindow *outer_window, IMoniker *mon, HTMLInnerWindow **ret)
3594 HTMLInnerWindow *window;
3596 window = alloc_window(sizeof(HTMLInnerWindow));
3597 if(!window)
3598 return E_OUTOFMEMORY;
3600 list_init(&window->children);
3601 list_init(&window->script_hosts);
3602 list_init(&window->bindings);
3603 list_init(&window->script_queue);
3605 window->base.outer_window = outer_window;
3606 window->base.inner_window = window;
3608 EventTarget_Init(&window->event_target, (IUnknown*)&window->base.IHTMLWindow2_iface,
3609 &HTMLWindow_dispex, COMPAT_MODE_NONE);
3611 window->task_magic = get_task_target_magic();
3613 if(mon) {
3614 IMoniker_AddRef(mon);
3615 window->mon = mon;
3618 *ret = window;
3619 return S_OK;
3622 HRESULT create_outer_window(GeckoBrowser *browser, mozIDOMWindowProxy *mozwindow,
3623 HTMLOuterWindow *parent, HTMLOuterWindow **ret)
3625 HTMLOuterWindow *window;
3626 nsresult nsres;
3627 HRESULT hres;
3629 window = alloc_window(sizeof(HTMLOuterWindow));
3630 if(!window)
3631 return E_OUTOFMEMORY;
3633 window->base.outer_window = window;
3634 window->base.inner_window = NULL;
3635 window->browser = browser;
3636 list_add_head(&browser->outer_windows, &window->browser_entry);
3638 mozIDOMWindowProxy_AddRef(mozwindow);
3639 window->window_proxy = mozwindow;
3640 nsres = mozIDOMWindowProxy_QueryInterface(mozwindow, &IID_nsIDOMWindow, (void**)&window->nswindow);
3641 assert(nsres == NS_OK);
3643 window->readystate = READYSTATE_UNINITIALIZED;
3644 window->task_magic = get_task_target_magic();
3646 wine_rb_put(&window_map, window->window_proxy, &window->entry);
3648 hres = create_pending_window(window, NULL);
3649 if(SUCCEEDED(hres))
3650 hres = update_window_doc(window->pending_window);
3651 if(FAILED(hres)) {
3652 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
3653 return hres;
3656 if(parent) {
3657 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
3659 window->parent = parent;
3660 list_add_tail(&parent->base.inner_window->children, &window->sibling_entry);
3663 TRACE("%p inner_window %p\n", window, window->base.inner_window);
3665 *ret = window;
3666 return S_OK;
3669 HRESULT create_pending_window(HTMLOuterWindow *outer_window, nsChannelBSC *channelbsc)
3671 HTMLInnerWindow *pending_window;
3672 HRESULT hres;
3674 hres = create_inner_window(outer_window, outer_window->mon /* FIXME */, &pending_window);
3675 if(FAILED(hres))
3676 return hres;
3678 if(channelbsc) {
3679 IBindStatusCallback_AddRef(&channelbsc->bsc.IBindStatusCallback_iface);
3680 pending_window->bscallback = channelbsc;
3683 if(outer_window->pending_window) {
3684 abort_window_bindings(outer_window->pending_window);
3685 outer_window->pending_window->base.outer_window = NULL;
3686 IHTMLWindow2_Release(&outer_window->pending_window->base.IHTMLWindow2_iface);
3689 outer_window->pending_window = pending_window;
3690 return S_OK;
3693 HRESULT update_window_doc(HTMLInnerWindow *window)
3695 HTMLOuterWindow *outer_window = window->base.outer_window;
3696 compat_mode_t parent_mode = COMPAT_MODE_QUIRKS;
3697 nsIDOMHTMLDocument *nshtmldoc;
3698 nsIDOMDocument *nsdoc;
3699 nsresult nsres;
3700 HRESULT hres;
3702 assert(!window->doc);
3704 if(!outer_window)
3705 return E_UNEXPECTED;
3707 nsres = nsIDOMWindow_GetDocument(outer_window->nswindow, &nsdoc);
3708 if(NS_FAILED(nsres) || !nsdoc) {
3709 ERR("GetDocument failed: %08x\n", nsres);
3710 return E_FAIL;
3713 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
3714 nsIDOMDocument_Release(nsdoc);
3715 if(NS_FAILED(nsres)) {
3716 ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres);
3717 return E_FAIL;
3720 if(outer_window->parent)
3721 parent_mode = outer_window->parent->base.inner_window->doc->document_mode;
3723 hres = create_document_node(nshtmldoc, outer_window->browser, window, parent_mode, &window->doc);
3724 nsIDOMHTMLDocument_Release(nshtmldoc);
3725 if(FAILED(hres))
3726 return hres;
3728 if(window != outer_window->pending_window) {
3729 ERR("not current pending window\n");
3730 return S_OK;
3733 if(outer_window->base.inner_window)
3734 detach_inner_window(outer_window->base.inner_window);
3735 outer_window->base.inner_window = window;
3736 outer_window->pending_window = NULL;
3738 if(is_main_content_window(outer_window) || !outer_window->browser->content_window) {
3739 HTMLDocumentObj *doc_obj = outer_window->browser->doc;
3740 if(doc_obj->basedoc.doc_node)
3741 htmldoc_release(&doc_obj->basedoc.doc_node->basedoc);
3742 doc_obj->basedoc.doc_node = window->doc;
3743 htmldoc_addref(&window->doc->basedoc);
3746 return hres;