gdi32: Allocate smaller buffer in delete_external_font_keys helper.
[wine.git] / dlls / mshtml / htmlwindow.c
blobb68579b0f8b99662cdc0ce6de7fa5bed1b7ac500
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 "pluginhost.h"
42 #include "binding.h"
43 #include "resource.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
47 static int window_map_compare(const void *key, const struct wine_rb_entry *entry)
49 HTMLOuterWindow *window = WINE_RB_ENTRY_VALUE(entry, HTMLOuterWindow, entry);
51 if(window->window_proxy == key)
52 return 0;
53 return (void*)window->window_proxy > key ? -1 : 1;
56 static struct wine_rb_tree window_map = { window_map_compare };
58 HTMLOuterWindow *mozwindow_to_window(const mozIDOMWindowProxy *mozwindow)
60 struct wine_rb_entry *entry = wine_rb_get(&window_map, mozwindow);
61 return entry ? WINE_RB_ENTRY_VALUE(entry, HTMLOuterWindow, entry) : NULL;
64 static inline BOOL is_outer_window(HTMLWindow *window)
66 return &window->outer_window->base == window;
69 static void release_children(HTMLOuterWindow *This)
71 HTMLOuterWindow *child;
73 while(!list_empty(&This->children)) {
74 child = LIST_ENTRY(list_tail(&This->children), HTMLOuterWindow, sibling_entry);
76 list_remove(&child->sibling_entry);
77 child->parent = NULL;
78 IHTMLWindow2_Release(&child->base.IHTMLWindow2_iface);
82 static HRESULT get_location(HTMLInnerWindow *This, HTMLLocation **ret)
84 if(This->location) {
85 IHTMLLocation_AddRef(&This->location->IHTMLLocation_iface);
86 }else {
87 HRESULT hres;
89 hres = HTMLLocation_Create(This, &This->location);
90 if(FAILED(hres))
91 return hres;
94 *ret = This->location;
95 return S_OK;
98 void get_top_window(HTMLOuterWindow *window, HTMLOuterWindow **ret)
100 HTMLOuterWindow *iter;
102 for(iter = window; iter->parent; iter = iter->parent);
103 *ret = iter;
106 static inline HRESULT set_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
108 if(!window->inner_window->doc) {
109 FIXME("No document\n");
110 return E_FAIL;
113 return set_event_handler(&window->inner_window->event_target, eid, var);
116 static inline HRESULT get_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var)
118 if(!window->inner_window->doc) {
119 FIXME("No document\n");
120 return E_FAIL;
123 return get_event_handler(&window->inner_window->event_target, eid, var);
126 static void detach_inner_window(HTMLInnerWindow *window)
128 HTMLOuterWindow *outer_window = window->base.outer_window;
130 if(outer_window && outer_window->doc_obj && outer_window == outer_window->doc_obj->basedoc.window)
131 window->doc->basedoc.cp_container.forward_container = NULL;
133 if(window->doc) {
134 detach_events(window->doc);
135 while(!list_empty(&window->doc->plugin_hosts))
136 detach_plugin_host(LIST_ENTRY(list_head(&window->doc->plugin_hosts), PluginHost, entry));
139 abort_window_bindings(window);
140 remove_target_tasks(window->task_magic);
141 release_script_hosts(window);
142 window->base.outer_window = NULL;
144 if(outer_window && outer_window->base.inner_window == window) {
145 outer_window->base.inner_window = NULL;
146 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
150 static inline HTMLWindow *impl_from_IHTMLWindow2(IHTMLWindow2 *iface)
152 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow2_iface);
155 static HRESULT WINAPI HTMLWindow2_QueryInterface(IHTMLWindow2 *iface, REFIID riid, void **ppv)
157 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
159 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
161 if(IsEqualGUID(&IID_IUnknown, riid)) {
162 *ppv = &This->IHTMLWindow2_iface;
163 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
164 *ppv = &This->IHTMLWindow2_iface;
165 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
166 *ppv = &This->IDispatchEx_iface;
167 }else if(IsEqualGUID(&IID_IHTMLFramesCollection2, riid)) {
168 *ppv = &This->IHTMLWindow2_iface;
169 }else if(IsEqualGUID(&IID_IHTMLWindow2, riid)) {
170 *ppv = &This->IHTMLWindow2_iface;
171 }else if(IsEqualGUID(&IID_IHTMLWindow3, riid)) {
172 *ppv = &This->IHTMLWindow3_iface;
173 }else if(IsEqualGUID(&IID_IHTMLWindow4, riid)) {
174 *ppv = &This->IHTMLWindow4_iface;
175 }else if(IsEqualGUID(&IID_IHTMLWindow5, riid)) {
176 *ppv = &This->IHTMLWindow5_iface;
177 }else if(IsEqualGUID(&IID_IHTMLWindow6, riid)) {
178 *ppv = &This->IHTMLWindow6_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 *ppv = NULL;
202 WARN("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
203 return E_NOINTERFACE;
206 IUnknown_AddRef((IUnknown*)*ppv);
207 return S_OK;
210 static ULONG WINAPI HTMLWindow2_AddRef(IHTMLWindow2 *iface)
212 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
213 LONG ref = InterlockedIncrement(&This->ref);
215 TRACE("(%p) ref=%d\n", This, ref);
217 return ref;
220 static void release_outer_window(HTMLOuterWindow *This)
222 if(This->pending_window) {
223 abort_window_bindings(This->pending_window);
224 This->pending_window->base.outer_window = NULL;
225 IHTMLWindow2_Release(&This->pending_window->base.IHTMLWindow2_iface);
228 remove_target_tasks(This->task_magic);
229 set_current_mon(This, NULL, 0);
230 set_current_uri(This, NULL);
231 if(This->base.inner_window)
232 detach_inner_window(This->base.inner_window);
233 release_children(This);
235 if(This->secmgr)
236 IInternetSecurityManager_Release(This->secmgr);
238 if(This->frame_element)
239 This->frame_element->content_window = NULL;
241 This->window_ref->window = NULL;
242 windowref_release(This->window_ref);
244 if(This->nswindow)
245 nsIDOMWindow_Release(This->nswindow);
246 if(This->window_proxy)
247 mozIDOMWindowProxy_Release(This->window_proxy);
249 wine_rb_remove(&window_map, &This->entry);
250 heap_free(This);
253 static void release_inner_window(HTMLInnerWindow *This)
255 unsigned i;
257 TRACE("%p\n", This);
259 detach_inner_window(This);
261 if(This->doc) {
262 This->doc->window = NULL;
263 htmldoc_release(&This->doc->basedoc);
266 release_event_target(&This->event_target);
267 release_dispex(&This->event_target.dispex);
269 for(i=0; i < This->global_prop_cnt; i++)
270 heap_free(This->global_props[i].name);
271 heap_free(This->global_props);
273 if(This->location) {
274 This->location->window = NULL;
275 IHTMLLocation_Release(&This->location->IHTMLLocation_iface);
278 if(This->image_factory) {
279 This->image_factory->window = NULL;
280 IHTMLImageElementFactory_Release(&This->image_factory->IHTMLImageElementFactory_iface);
283 if(This->option_factory) {
284 This->option_factory->window = NULL;
285 IHTMLOptionElementFactory_Release(&This->option_factory->IHTMLOptionElementFactory_iface);
288 if(This->xhr_factory) {
289 This->xhr_factory->window = NULL;
290 IHTMLXMLHttpRequestFactory_Release(&This->xhr_factory->IHTMLXMLHttpRequestFactory_iface);
293 if(This->screen)
294 IHTMLScreen_Release(This->screen);
296 if(This->history) {
297 This->history->window = NULL;
298 IOmHistory_Release(&This->history->IOmHistory_iface);
301 if(This->session_storage)
302 IHTMLStorage_Release(This->session_storage);
304 if(This->mon)
305 IMoniker_Release(This->mon);
307 heap_free(This);
310 static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
312 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
313 LONG ref = InterlockedDecrement(&This->ref);
315 TRACE("(%p) ref=%d\n", This, ref);
317 if(!ref) {
318 if(is_outer_window(This))
319 release_outer_window(This->outer_window);
320 else
321 release_inner_window(This->inner_window);
324 return ref;
327 static HRESULT WINAPI HTMLWindow2_GetTypeInfoCount(IHTMLWindow2 *iface, UINT *pctinfo)
329 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
331 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
334 static HRESULT WINAPI HTMLWindow2_GetTypeInfo(IHTMLWindow2 *iface, UINT iTInfo,
335 LCID lcid, ITypeInfo **ppTInfo)
337 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
339 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
342 static HRESULT WINAPI HTMLWindow2_GetIDsOfNames(IHTMLWindow2 *iface, REFIID riid,
343 LPOLESTR *rgszNames, UINT cNames,
344 LCID lcid, DISPID *rgDispId)
346 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
348 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
349 rgDispId);
352 static HRESULT WINAPI HTMLWindow2_Invoke(IHTMLWindow2 *iface, DISPID dispIdMember,
353 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
354 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
356 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
358 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
359 pDispParams, pVarResult, pExcepInfo, puArgErr);
362 static HRESULT get_frame_by_index(HTMLOuterWindow *This, UINT32 index, HTMLOuterWindow **ret)
364 nsIDOMWindowCollection *nsframes;
365 mozIDOMWindowProxy *mozwindow;
366 UINT32 length;
367 nsresult nsres;
369 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsframes);
370 if(NS_FAILED(nsres)) {
371 FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
372 return E_FAIL;
375 nsres = nsIDOMWindowCollection_GetLength(nsframes, &length);
376 assert(nsres == NS_OK);
378 if(index >= length) {
379 nsIDOMWindowCollection_Release(nsframes);
380 return DISP_E_MEMBERNOTFOUND;
383 nsres = nsIDOMWindowCollection_Item(nsframes, index, &mozwindow);
384 nsIDOMWindowCollection_Release(nsframes);
385 if(NS_FAILED(nsres)) {
386 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
387 return E_FAIL;
390 *ret = mozwindow_to_window(mozwindow);
392 mozIDOMWindowProxy_Release(mozwindow);
393 return S_OK;
396 HRESULT get_frame_by_name(HTMLOuterWindow *This, const WCHAR *name, BOOL deep, HTMLOuterWindow **ret)
398 nsIDOMWindowCollection *nsframes;
399 HTMLOuterWindow *window = NULL;
400 mozIDOMWindowProxy *mozwindow;
401 nsAString name_str;
402 UINT32 length, i;
403 nsresult nsres;
404 HRESULT hres = S_OK;
406 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsframes);
407 if(NS_FAILED(nsres)) {
408 FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
409 return E_FAIL;
412 if(!nsframes) {
413 WARN("nsIDOMWindow_GetFrames returned NULL nsframes: %p\n", This->nswindow);
414 return DISP_E_MEMBERNOTFOUND;
417 nsAString_InitDepend(&name_str, name);
418 nsres = nsIDOMWindowCollection_NamedItem(nsframes, &name_str, &mozwindow);
419 nsAString_Finish(&name_str);
420 if(NS_FAILED(nsres)) {
421 nsIDOMWindowCollection_Release(nsframes);
422 return E_FAIL;
425 if(mozwindow) {
426 *ret = mozwindow_to_window(mozwindow);
427 return S_OK;
430 nsres = nsIDOMWindowCollection_GetLength(nsframes, &length);
431 assert(nsres == NS_OK);
433 for(i = 0; i < length && !window; ++i) {
434 HTMLOuterWindow *window_iter;
435 BSTR id;
437 nsres = nsIDOMWindowCollection_Item(nsframes, i, &mozwindow);
438 if(NS_FAILED(nsres)) {
439 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
440 hres = E_FAIL;
441 break;
444 window_iter = mozwindow_to_window(mozwindow);
446 mozIDOMWindowProxy_Release(mozwindow);
448 if(!window_iter) {
449 WARN("nsIDOMWindow without HTMLOuterWindow: %p\n", mozwindow);
450 continue;
453 hres = IHTMLElement_get_id(&window_iter->frame_element->element.IHTMLElement_iface, &id);
454 if(FAILED(hres)) {
455 FIXME("IHTMLElement_get_id failed: 0x%08x\n", hres);
456 break;
459 if(id && !strcmpiW(id, name))
460 window = window_iter;
462 SysFreeString(id);
464 if(!window && deep)
465 get_frame_by_name(window_iter, name, TRUE, &window);
468 nsIDOMWindowCollection_Release(nsframes);
469 if(FAILED(hres))
470 return hres;
472 *ret = window;
473 return S_OK;
476 static HRESULT WINAPI HTMLWindow2_item(IHTMLWindow2 *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
478 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
479 HTMLOuterWindow *window = NULL;
480 HRESULT hres;
482 TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
484 switch(V_VT(pvarIndex)) {
485 case VT_I4: {
486 int index = V_I4(pvarIndex);
487 TRACE("Getting index %d\n", index);
488 if(index < 0)
489 return DISP_E_MEMBERNOTFOUND;
490 hres = get_frame_by_index(This->outer_window, index, &window);
491 break;
493 case VT_UINT: {
494 unsigned int index = V_UINT(pvarIndex);
495 TRACE("Getting index %u\n", index);
496 hres = get_frame_by_index(This->outer_window, index, &window);
497 break;
499 case VT_BSTR: {
500 BSTR str = V_BSTR(pvarIndex);
501 TRACE("Getting name %s\n", wine_dbgstr_w(str));
502 hres = get_frame_by_name(This->outer_window, str, FALSE, &window);
503 break;
505 default:
506 WARN("Invalid index %s\n", debugstr_variant(pvarIndex));
507 return E_INVALIDARG;
510 if(FAILED(hres))
511 return hres;
512 if(!window)
513 return DISP_E_MEMBERNOTFOUND;
515 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
516 V_VT(pvarResult) = VT_DISPATCH;
517 V_DISPATCH(pvarResult) = (IDispatch*)window;
518 return S_OK;
521 static HRESULT WINAPI HTMLWindow2_get_length(IHTMLWindow2 *iface, LONG *p)
523 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
524 nsIDOMWindowCollection *nscollection;
525 UINT32 length;
526 nsresult nsres;
528 TRACE("(%p)->(%p)\n", This, p);
530 nsres = nsIDOMWindow_GetFrames(This->outer_window->nswindow, &nscollection);
531 if(NS_FAILED(nsres)) {
532 ERR("GetFrames failed: %08x\n", nsres);
533 return E_FAIL;
536 nsres = nsIDOMWindowCollection_GetLength(nscollection, &length);
537 nsIDOMWindowCollection_Release(nscollection);
538 if(NS_FAILED(nsres)) {
539 ERR("GetLength failed: %08x\n", nsres);
540 return E_FAIL;
543 *p = length;
544 return S_OK;
547 static HRESULT WINAPI HTMLWindow2_get_frames(IHTMLWindow2 *iface, IHTMLFramesCollection2 **p)
549 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
550 FIXME("(%p)->(%p): semi-stub\n", This, p);
552 /* FIXME: Should return a separate Window object */
553 *p = (IHTMLFramesCollection2*)&This->IHTMLWindow2_iface;
554 IHTMLWindow2_AddRef(iface);
555 return S_OK;
558 static HRESULT WINAPI HTMLWindow2_put_defaultStatus(IHTMLWindow2 *iface, BSTR v)
560 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
561 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
562 return E_NOTIMPL;
565 static HRESULT WINAPI HTMLWindow2_get_defaultStatus(IHTMLWindow2 *iface, BSTR *p)
567 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
568 FIXME("(%p)->(%p)\n", This, p);
569 return E_NOTIMPL;
572 static HRESULT WINAPI HTMLWindow2_put_status(IHTMLWindow2 *iface, BSTR v)
574 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
576 WARN("(%p)->(%s)\n", This, debugstr_w(v));
579 * FIXME: Since IE7, setting status is blocked, but still possible in certain circumstances.
580 * Ignoring the call should be enough for us.
582 return S_OK;
585 static HRESULT WINAPI HTMLWindow2_get_status(IHTMLWindow2 *iface, BSTR *p)
587 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
589 TRACE("(%p)->(%p)\n", This, p);
591 /* See put_status */
592 *p = NULL;
593 return S_OK;
596 static HRESULT WINAPI HTMLWindow2_setTimeout(IHTMLWindow2 *iface, BSTR expression,
597 LONG msec, VARIANT *language, LONG *timerID)
599 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
600 VARIANT expr_var;
602 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
604 V_VT(&expr_var) = VT_BSTR;
605 V_BSTR(&expr_var) = expression;
607 return IHTMLWindow3_setTimeout(&This->IHTMLWindow3_iface, &expr_var, msec, language, timerID);
610 static HRESULT WINAPI HTMLWindow2_clearTimeout(IHTMLWindow2 *iface, LONG timerID)
612 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
614 TRACE("(%p)->(%d)\n", This, timerID);
616 return clear_task_timer(This->inner_window, timerID);
619 #define MAX_MESSAGE_LEN 2000
621 static HRESULT WINAPI HTMLWindow2_alert(IHTMLWindow2 *iface, BSTR message)
623 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
624 WCHAR title[100], *msg = message;
625 DWORD len;
627 TRACE("(%p)->(%s)\n", This, debugstr_w(message));
629 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, title,
630 sizeof(title)/sizeof(WCHAR))) {
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->doc_obj->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) return E_INVALIDARG;
660 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
661 sizeof(wszTitle)/sizeof(WCHAR))) {
662 WARN("Could not load message box title: %d\n", GetLastError());
663 *confirmed = VARIANT_TRUE;
664 return S_OK;
667 if(MessageBoxW(This->outer_window->doc_obj->hwnd, message, wszTitle,
668 MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
669 *confirmed = VARIANT_TRUE;
670 else *confirmed = VARIANT_FALSE;
672 return S_OK;
675 typedef struct
677 BSTR message;
678 BSTR dststr;
679 VARIANT *textdata;
680 }prompt_arg;
682 static INT_PTR CALLBACK prompt_dlgproc(HWND hwnd, UINT msg,
683 WPARAM wparam, LPARAM lparam)
685 switch(msg)
687 case WM_INITDIALOG:
689 prompt_arg *arg = (prompt_arg*)lparam;
690 WCHAR wszTitle[100];
692 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
693 sizeof(wszTitle)/sizeof(WCHAR))) {
694 WARN("Could not load message box title: %d\n", GetLastError());
695 EndDialog(hwnd, wparam);
696 return FALSE;
699 SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
700 SetWindowTextW(hwnd, wszTitle);
701 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_PROMPT), arg->message);
702 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_EDIT), arg->dststr);
703 return FALSE;
705 case WM_COMMAND:
706 switch(wparam)
708 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
709 EndDialog(hwnd, wparam);
710 return TRUE;
711 case MAKEWPARAM(IDOK, BN_CLICKED):
713 prompt_arg *arg =
714 (prompt_arg*)GetWindowLongPtrW(hwnd, DWLP_USER);
715 HWND hwndPrompt = GetDlgItem(hwnd, ID_PROMPT_EDIT);
716 INT len = GetWindowTextLengthW(hwndPrompt);
718 if(!arg->textdata)
720 EndDialog(hwnd, wparam);
721 return TRUE;
724 V_VT(arg->textdata) = VT_BSTR;
725 if(!len && !arg->dststr)
726 V_BSTR(arg->textdata) = NULL;
727 else
729 V_BSTR(arg->textdata) = SysAllocStringLen(NULL, len);
730 GetWindowTextW(hwndPrompt, V_BSTR(arg->textdata), len+1);
732 EndDialog(hwnd, wparam);
733 return TRUE;
736 return FALSE;
737 case WM_CLOSE:
738 EndDialog(hwnd, IDCANCEL);
739 return TRUE;
740 default:
741 return FALSE;
745 static HRESULT WINAPI HTMLWindow2_prompt(IHTMLWindow2 *iface, BSTR message,
746 BSTR dststr, VARIANT *textdata)
748 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
749 prompt_arg arg;
751 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(message), debugstr_w(dststr), textdata);
753 if(textdata) V_VT(textdata) = VT_NULL;
755 arg.message = message;
756 arg.dststr = dststr;
757 arg.textdata = textdata;
759 DialogBoxParamW(hInst, MAKEINTRESOURCEW(ID_PROMPT_DIALOG),
760 This->outer_window->doc_obj->hwnd, prompt_dlgproc, (LPARAM)&arg);
761 return S_OK;
764 static HRESULT WINAPI HTMLWindow2_get_Image(IHTMLWindow2 *iface, IHTMLImageElementFactory **p)
766 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
767 HTMLInnerWindow *window = This->inner_window;
769 TRACE("(%p)->(%p)\n", This, p);
771 if(!window->image_factory) {
772 HRESULT hres;
774 hres = HTMLImageElementFactory_Create(window, &window->image_factory);
775 if(FAILED(hres))
776 return hres;
779 *p = &window->image_factory->IHTMLImageElementFactory_iface;
780 IHTMLImageElementFactory_AddRef(*p);
782 return S_OK;
785 static HRESULT WINAPI HTMLWindow2_get_location(IHTMLWindow2 *iface, IHTMLLocation **p)
787 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
788 HTMLLocation *location;
789 HRESULT hres;
791 TRACE("(%p)->(%p)\n", This, p);
793 hres = get_location(This->inner_window, &location);
794 if(FAILED(hres))
795 return hres;
797 *p = &location->IHTMLLocation_iface;
798 return S_OK;
801 static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p)
803 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
804 HTMLInnerWindow *window = This->inner_window;
806 TRACE("(%p)->(%p)\n", This, p);
808 if(!window->history) {
809 HRESULT hres;
811 hres = create_history(window, &window->history);
812 if(FAILED(hres))
813 return hres;
816 IOmHistory_AddRef(&window->history->IOmHistory_iface);
817 *p = &window->history->IOmHistory_iface;
818 return S_OK;
821 static BOOL notify_webbrowser_close(HTMLOuterWindow *window, HTMLDocumentObj *doc)
823 IConnectionPointContainer *cp_container;
824 VARIANT_BOOL cancel = VARIANT_FALSE;
825 IEnumConnections *enum_conn;
826 VARIANT args[2];
827 DISPPARAMS dp = {args, NULL, 2, 0};
828 CONNECTDATA conn_data;
829 IConnectionPoint *cp;
830 IDispatch *disp;
831 ULONG fetched;
832 HRESULT hres;
834 if(!doc->webbrowser)
835 return TRUE;
837 hres = IUnknown_QueryInterface(doc->webbrowser, &IID_IConnectionPointContainer, (void**)&cp_container);
838 if(FAILED(hres))
839 return TRUE;
841 hres = IConnectionPointContainer_FindConnectionPoint(cp_container, &DIID_DWebBrowserEvents2, &cp);
842 IConnectionPointContainer_Release(cp_container);
843 if(FAILED(hres))
844 return TRUE;
846 hres = IConnectionPoint_EnumConnections(cp, &enum_conn);
847 IConnectionPoint_Release(cp);
848 if(FAILED(hres))
849 return TRUE;
851 while(!cancel) {
852 conn_data.pUnk = NULL;
853 conn_data.dwCookie = 0;
854 fetched = 0;
855 hres = IEnumConnections_Next(enum_conn, 1, &conn_data, &fetched);
856 if(hres != S_OK)
857 break;
859 hres = IUnknown_QueryInterface(conn_data.pUnk, &IID_IDispatch, (void**)&disp);
860 IUnknown_Release(conn_data.pUnk);
861 if(FAILED(hres))
862 continue;
864 V_VT(args) = VT_BYREF|VT_BOOL;
865 V_BOOLREF(args) = &cancel;
866 V_VT(args+1) = VT_BOOL;
867 V_BOOL(args+1) = window->parent ? VARIANT_TRUE : VARIANT_FALSE;
868 hres = IDispatch_Invoke(disp, DISPID_WINDOWCLOSING, &IID_NULL, 0, DISPATCH_METHOD, &dp, NULL, NULL, NULL);
869 IDispatch_Release(disp);
870 if(FAILED(hres))
871 cancel = VARIANT_FALSE;
874 IEnumConnections_Release(enum_conn);
875 return !cancel;
878 static HRESULT WINAPI HTMLWindow2_close(IHTMLWindow2 *iface)
880 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
881 HTMLOuterWindow *window = This->outer_window;
883 TRACE("(%p)\n", This);
885 if(!window->doc_obj) {
886 FIXME("No document object\n");
887 return E_FAIL;
890 if(!notify_webbrowser_close(window, window->doc_obj))
891 return S_OK;
893 FIXME("default action not implemented\n");
894 return E_NOTIMPL;
897 static HRESULT WINAPI HTMLWindow2_put_opener(IHTMLWindow2 *iface, VARIANT v)
899 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
900 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
901 return E_NOTIMPL;
904 static HRESULT WINAPI HTMLWindow2_get_opener(IHTMLWindow2 *iface, VARIANT *p)
906 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
908 FIXME("(%p)->(%p) returning empty\n", This, p);
910 V_VT(p) = VT_EMPTY;
911 return S_OK;
914 static HRESULT WINAPI HTMLWindow2_get_navigator(IHTMLWindow2 *iface, IOmNavigator **p)
916 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
918 TRACE("(%p)->(%p)\n", This, p);
920 *p = OmNavigator_Create();
921 return *p ? S_OK : E_OUTOFMEMORY;
924 static HRESULT WINAPI HTMLWindow2_put_name(IHTMLWindow2 *iface, BSTR v)
926 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
927 nsAString name_str;
928 nsresult nsres;
930 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
932 nsAString_InitDepend(&name_str, v);
933 nsres = nsIDOMWindow_SetName(This->outer_window->nswindow, &name_str);
934 nsAString_Finish(&name_str);
935 if(NS_FAILED(nsres))
936 ERR("SetName failed: %08x\n", nsres);
938 return S_OK;
941 static HRESULT WINAPI HTMLWindow2_get_name(IHTMLWindow2 *iface, BSTR *p)
943 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
944 nsAString name_str;
945 nsresult nsres;
947 TRACE("(%p)->(%p)\n", This, p);
949 nsAString_Init(&name_str, NULL);
950 nsres = nsIDOMWindow_GetName(This->outer_window->nswindow, &name_str);
951 return return_nsstr(nsres, &name_str, p);
954 static HRESULT WINAPI HTMLWindow2_get_parent(IHTMLWindow2 *iface, IHTMLWindow2 **p)
956 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
957 HTMLOuterWindow *window = This->outer_window;
959 TRACE("(%p)->(%p)\n", This, p);
961 if(!window->parent)
962 return IHTMLWindow2_get_self(&This->IHTMLWindow2_iface, p);
964 *p = &window->parent->base.IHTMLWindow2_iface;
965 IHTMLWindow2_AddRef(*p);
966 return S_OK;
969 static HRESULT WINAPI HTMLWindow2_open(IHTMLWindow2 *iface, BSTR url, BSTR name,
970 BSTR features, VARIANT_BOOL replace, IHTMLWindow2 **pomWindowResult)
972 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
973 HTMLOuterWindow *window = This->outer_window;
974 INewWindowManager *new_window_mgr;
975 BSTR uri_str;
976 IUri *uri;
977 HRESULT hres;
979 static const WCHAR _selfW[] = {'_','s','e','l','f',0};
981 TRACE("(%p)->(%s %s %s %x %p)\n", This, debugstr_w(url), debugstr_w(name),
982 debugstr_w(features), replace, pomWindowResult);
984 if(!window->doc_obj || !window->uri_nofrag)
985 return E_UNEXPECTED;
987 if(name && *name == '_') {
988 if(!strcmpW(name, _selfW)) {
989 if((features && *features) || replace)
990 FIXME("Unsupported arguments for _self target\n");
992 hres = IHTMLWindow2_navigate(&This->IHTMLWindow2_iface, url);
993 if(FAILED(hres))
994 return hres;
996 if(pomWindowResult) {
997 FIXME("Returning this window for _self target\n");
998 *pomWindowResult = &This->IHTMLWindow2_iface;
999 IHTMLWindow2_AddRef(*pomWindowResult);
1002 return S_OK;
1005 FIXME("Unsupported name %s\n", debugstr_w(name));
1006 return E_NOTIMPL;
1009 hres = do_query_service((IUnknown*)window->doc_obj->client, &SID_SNewWindowManager, &IID_INewWindowManager,
1010 (void**)&new_window_mgr);
1011 if(FAILED(hres)) {
1012 FIXME("No INewWindowManager\n");
1013 return E_NOTIMPL;
1016 hres = IUri_GetDisplayUri(window->uri_nofrag, &uri_str);
1017 if(SUCCEEDED(hres)) {
1018 hres = INewWindowManager_EvaluateNewWindow(new_window_mgr, url, name, uri_str,
1019 features, !!replace, window->doc_obj->has_popup ? 0 : NWMF_FIRST, 0);
1020 window->doc_obj->has_popup = TRUE;
1021 SysFreeString(uri_str);
1023 INewWindowManager_Release(new_window_mgr);
1024 if(FAILED(hres)) {
1025 *pomWindowResult = NULL;
1026 return S_OK;
1029 hres = create_relative_uri(window, url, &uri);
1030 if(FAILED(hres))
1031 return hres;
1033 hres = navigate_new_window(window, uri, name, NULL, pomWindowResult);
1034 IUri_Release(uri);
1035 return hres;
1038 static HRESULT WINAPI HTMLWindow2_get_self(IHTMLWindow2 *iface, IHTMLWindow2 **p)
1040 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1042 TRACE("(%p)->(%p)\n", This, p);
1044 /* FIXME: We should return kind of proxy window here. */
1045 IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1046 *p = &This->IHTMLWindow2_iface;
1047 return S_OK;
1050 static HRESULT WINAPI HTMLWindow2_get_top(IHTMLWindow2 *iface, IHTMLWindow2 **p)
1052 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1053 HTMLOuterWindow *top;
1055 TRACE("(%p)->(%p)\n", This, p);
1057 get_top_window(This->outer_window, &top);
1058 *p = &top->base.IHTMLWindow2_iface;
1059 IHTMLWindow2_AddRef(*p);
1061 return S_OK;
1064 static HRESULT WINAPI HTMLWindow2_get_window(IHTMLWindow2 *iface, IHTMLWindow2 **p)
1066 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1068 TRACE("(%p)->(%p)\n", This, p);
1070 /* FIXME: We should return kind of proxy window here. */
1071 IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1072 *p = &This->IHTMLWindow2_iface;
1073 return S_OK;
1076 static HRESULT WINAPI HTMLWindow2_navigate(IHTMLWindow2 *iface, BSTR url)
1078 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1080 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
1082 return navigate_url(This->outer_window, url, This->outer_window->uri, BINDING_NAVIGATED);
1085 static HRESULT WINAPI HTMLWindow2_put_onfocus(IHTMLWindow2 *iface, VARIANT v)
1087 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1089 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1091 return set_window_event(This, EVENTID_FOCUS, &v);
1094 static HRESULT WINAPI HTMLWindow2_get_onfocus(IHTMLWindow2 *iface, VARIANT *p)
1096 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1098 TRACE("(%p)->(%p)\n", This, p);
1100 return get_window_event(This, EVENTID_FOCUS, p);
1103 static HRESULT WINAPI HTMLWindow2_put_onblur(IHTMLWindow2 *iface, VARIANT v)
1105 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1107 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1109 return set_window_event(This, EVENTID_BLUR, &v);
1112 static HRESULT WINAPI HTMLWindow2_get_onblur(IHTMLWindow2 *iface, VARIANT *p)
1114 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1116 TRACE("(%p)->(%p)\n", This, p);
1118 return get_window_event(This, EVENTID_BLUR, p);
1121 static HRESULT WINAPI HTMLWindow2_put_onload(IHTMLWindow2 *iface, VARIANT v)
1123 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1125 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1127 return set_window_event(This, EVENTID_LOAD, &v);
1130 static HRESULT WINAPI HTMLWindow2_get_onload(IHTMLWindow2 *iface, VARIANT *p)
1132 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1134 TRACE("(%p)->(%p)\n", This, p);
1136 return get_window_event(This, EVENTID_LOAD, p);
1139 static HRESULT WINAPI HTMLWindow2_put_onbeforeunload(IHTMLWindow2 *iface, VARIANT v)
1141 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1143 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1145 return set_window_event(This, EVENTID_BEFOREUNLOAD, &v);
1148 static HRESULT WINAPI HTMLWindow2_get_onbeforeunload(IHTMLWindow2 *iface, VARIANT *p)
1150 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1152 TRACE("(%p)->(%p)\n", This, p);
1154 return get_window_event(This, EVENTID_BEFOREUNLOAD, p);
1157 static HRESULT WINAPI HTMLWindow2_put_onunload(IHTMLWindow2 *iface, VARIANT v)
1159 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1161 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1163 return set_window_event(This, EVENTID_UNLOAD, &v);
1166 static HRESULT WINAPI HTMLWindow2_get_onunload(IHTMLWindow2 *iface, VARIANT *p)
1168 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1170 TRACE("(%p)->(%p)\n", This, p);
1172 return get_window_event(This, EVENTID_UNLOAD, p);
1175 static HRESULT WINAPI HTMLWindow2_put_onhelp(IHTMLWindow2 *iface, VARIANT v)
1177 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1179 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1181 return set_window_event(This, EVENTID_HELP, &v);
1184 static HRESULT WINAPI HTMLWindow2_get_onhelp(IHTMLWindow2 *iface, VARIANT *p)
1186 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1188 TRACE("(%p)->(%p)\n", This, p);
1190 return get_window_event(This, EVENTID_HELP, p);
1193 static HRESULT WINAPI HTMLWindow2_put_onerror(IHTMLWindow2 *iface, VARIANT v)
1195 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1197 FIXME("(%p)->(%s) semi-stub\n", This, debugstr_variant(&v));
1199 return set_window_event(This, EVENTID_ERROR, &v);
1202 static HRESULT WINAPI HTMLWindow2_get_onerror(IHTMLWindow2 *iface, VARIANT *p)
1204 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1206 TRACE("(%p)->(%p)\n", This, p);
1208 return get_window_event(This, EVENTID_ERROR, p);
1211 static HRESULT WINAPI HTMLWindow2_put_onresize(IHTMLWindow2 *iface, VARIANT v)
1213 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1215 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1217 return set_window_event(This, EVENTID_RESIZE, &v);
1220 static HRESULT WINAPI HTMLWindow2_get_onresize(IHTMLWindow2 *iface, VARIANT *p)
1222 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1224 TRACE("(%p)->(%p)\n", This, p);
1226 return get_window_event(This, EVENTID_RESIZE, p);
1229 static HRESULT WINAPI HTMLWindow2_put_onscroll(IHTMLWindow2 *iface, VARIANT v)
1231 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1233 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1235 return set_window_event(This, EVENTID_SCROLL, &v);
1238 static HRESULT WINAPI HTMLWindow2_get_onscroll(IHTMLWindow2 *iface, VARIANT *p)
1240 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1242 TRACE("(%p)->(%p)\n", This, p);
1244 return get_window_event(This, EVENTID_SCROLL, p);
1247 static HRESULT WINAPI HTMLWindow2_get_document(IHTMLWindow2 *iface, IHTMLDocument2 **p)
1249 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1251 TRACE("(%p)->(%p)\n", This, p);
1253 if(This->inner_window->doc) {
1254 /* FIXME: We should return a wrapper object here */
1255 *p = &This->inner_window->doc->basedoc.IHTMLDocument2_iface;
1256 IHTMLDocument2_AddRef(*p);
1257 }else {
1258 *p = NULL;
1261 return S_OK;
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->doc_obj)
1348 SetFocus(This->outer_window->doc_obj->hwnd);
1349 return S_OK;
1352 static HRESULT WINAPI HTMLWindow2_get_closed(IHTMLWindow2 *iface, VARIANT_BOOL *p)
1354 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1355 FIXME("(%p)->(%p)\n", This, p);
1356 return E_NOTIMPL;
1359 static HRESULT WINAPI HTMLWindow2_blur(IHTMLWindow2 *iface)
1361 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1362 FIXME("(%p)->()\n", This);
1363 return E_NOTIMPL;
1366 static HRESULT WINAPI HTMLWindow2_scroll(IHTMLWindow2 *iface, LONG x, LONG y)
1368 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1369 nsresult nsres;
1371 TRACE("(%p)->(%d %d)\n", This, x, y);
1373 nsres = nsIDOMWindow_Scroll(This->outer_window->nswindow, x, y);
1374 if(NS_FAILED(nsres)) {
1375 ERR("ScrollBy failed: %08x\n", nsres);
1376 return E_FAIL;
1379 return S_OK;
1382 static HRESULT WINAPI HTMLWindow2_get_clientInformation(IHTMLWindow2 *iface, IOmNavigator **p)
1384 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1386 TRACE("(%p)->(%p)\n", This, p);
1388 return IHTMLWindow2_get_navigator(&This->IHTMLWindow2_iface, p);
1391 static HRESULT WINAPI HTMLWindow2_setInterval(IHTMLWindow2 *iface, BSTR expression,
1392 LONG msec, VARIANT *language, LONG *timerID)
1394 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1395 VARIANT expr;
1397 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
1399 V_VT(&expr) = VT_BSTR;
1400 V_BSTR(&expr) = expression;
1401 return IHTMLWindow3_setInterval(&This->IHTMLWindow3_iface, &expr, msec, language, timerID);
1404 static HRESULT WINAPI HTMLWindow2_clearInterval(IHTMLWindow2 *iface, LONG timerID)
1406 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1408 TRACE("(%p)->(%d)\n", This, timerID);
1410 return clear_task_timer(This->inner_window, timerID);
1413 static HRESULT WINAPI HTMLWindow2_put_offscreenBuffering(IHTMLWindow2 *iface, VARIANT v)
1415 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1416 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1417 return E_NOTIMPL;
1420 static HRESULT WINAPI HTMLWindow2_get_offscreenBuffering(IHTMLWindow2 *iface, VARIANT *p)
1422 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1423 FIXME("(%p)->(%p)\n", This, p);
1424 return E_NOTIMPL;
1427 static HRESULT WINAPI HTMLWindow2_execScript(IHTMLWindow2 *iface, BSTR scode, BSTR language,
1428 VARIANT *pvarRet)
1430 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1432 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(scode), debugstr_w(language), pvarRet);
1434 return exec_script(This->inner_window, scode, language, pvarRet);
1437 static HRESULT WINAPI HTMLWindow2_toString(IHTMLWindow2 *iface, BSTR *String)
1439 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1441 static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
1443 TRACE("(%p)->(%p)\n", This, String);
1445 if(!String)
1446 return E_INVALIDARG;
1448 *String = SysAllocString(objectW);
1449 return *String ? S_OK : E_OUTOFMEMORY;
1452 static HRESULT WINAPI HTMLWindow2_scrollBy(IHTMLWindow2 *iface, LONG x, LONG y)
1454 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1455 nsresult nsres;
1457 TRACE("(%p)->(%d %d)\n", This, x, y);
1459 nsres = nsIDOMWindow_ScrollBy(This->outer_window->nswindow, x, y);
1460 if(NS_FAILED(nsres))
1461 ERR("ScrollBy failed: %08x\n", nsres);
1463 return S_OK;
1466 static HRESULT WINAPI HTMLWindow2_scrollTo(IHTMLWindow2 *iface, LONG x, LONG y)
1468 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1469 nsresult nsres;
1471 TRACE("(%p)->(%d %d)\n", This, x, y);
1473 nsres = nsIDOMWindow_ScrollTo(This->outer_window->nswindow, x, y);
1474 if(NS_FAILED(nsres))
1475 ERR("ScrollTo failed: %08x\n", nsres);
1477 return S_OK;
1480 static HRESULT WINAPI HTMLWindow2_moveTo(IHTMLWindow2 *iface, LONG x, LONG y)
1482 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1483 FIXME("(%p)->(%d %d)\n", This, x, y);
1484 return E_NOTIMPL;
1487 static HRESULT WINAPI HTMLWindow2_moveBy(IHTMLWindow2 *iface, LONG x, LONG y)
1489 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1490 FIXME("(%p)->(%d %d)\n", This, x, y);
1491 return S_FALSE;
1494 static HRESULT WINAPI HTMLWindow2_resizeTo(IHTMLWindow2 *iface, LONG x, LONG y)
1496 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1497 FIXME("(%p)->(%d %d)\n", This, x, y);
1498 return E_NOTIMPL;
1501 static HRESULT WINAPI HTMLWindow2_resizeBy(IHTMLWindow2 *iface, LONG x, LONG y)
1503 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1504 FIXME("(%p)->(%d %d)\n", This, x, y);
1505 return S_FALSE;
1508 static HRESULT WINAPI HTMLWindow2_get_external(IHTMLWindow2 *iface, IDispatch **p)
1510 HTMLWindow *This = impl_from_IHTMLWindow2(iface);
1512 TRACE("(%p)->(%p)\n", This, p);
1514 *p = NULL;
1516 if(!This->outer_window->doc_obj->hostui)
1517 return S_OK;
1519 return IDocHostUIHandler_GetExternal(This->outer_window->doc_obj->hostui, p);
1522 static const IHTMLWindow2Vtbl HTMLWindow2Vtbl = {
1523 HTMLWindow2_QueryInterface,
1524 HTMLWindow2_AddRef,
1525 HTMLWindow2_Release,
1526 HTMLWindow2_GetTypeInfoCount,
1527 HTMLWindow2_GetTypeInfo,
1528 HTMLWindow2_GetIDsOfNames,
1529 HTMLWindow2_Invoke,
1530 HTMLWindow2_item,
1531 HTMLWindow2_get_length,
1532 HTMLWindow2_get_frames,
1533 HTMLWindow2_put_defaultStatus,
1534 HTMLWindow2_get_defaultStatus,
1535 HTMLWindow2_put_status,
1536 HTMLWindow2_get_status,
1537 HTMLWindow2_setTimeout,
1538 HTMLWindow2_clearTimeout,
1539 HTMLWindow2_alert,
1540 HTMLWindow2_confirm,
1541 HTMLWindow2_prompt,
1542 HTMLWindow2_get_Image,
1543 HTMLWindow2_get_location,
1544 HTMLWindow2_get_history,
1545 HTMLWindow2_close,
1546 HTMLWindow2_put_opener,
1547 HTMLWindow2_get_opener,
1548 HTMLWindow2_get_navigator,
1549 HTMLWindow2_put_name,
1550 HTMLWindow2_get_name,
1551 HTMLWindow2_get_parent,
1552 HTMLWindow2_open,
1553 HTMLWindow2_get_self,
1554 HTMLWindow2_get_top,
1555 HTMLWindow2_get_window,
1556 HTMLWindow2_navigate,
1557 HTMLWindow2_put_onfocus,
1558 HTMLWindow2_get_onfocus,
1559 HTMLWindow2_put_onblur,
1560 HTMLWindow2_get_onblur,
1561 HTMLWindow2_put_onload,
1562 HTMLWindow2_get_onload,
1563 HTMLWindow2_put_onbeforeunload,
1564 HTMLWindow2_get_onbeforeunload,
1565 HTMLWindow2_put_onunload,
1566 HTMLWindow2_get_onunload,
1567 HTMLWindow2_put_onhelp,
1568 HTMLWindow2_get_onhelp,
1569 HTMLWindow2_put_onerror,
1570 HTMLWindow2_get_onerror,
1571 HTMLWindow2_put_onresize,
1572 HTMLWindow2_get_onresize,
1573 HTMLWindow2_put_onscroll,
1574 HTMLWindow2_get_onscroll,
1575 HTMLWindow2_get_document,
1576 HTMLWindow2_get_event,
1577 HTMLWindow2_get__newEnum,
1578 HTMLWindow2_showModalDialog,
1579 HTMLWindow2_showHelp,
1580 HTMLWindow2_get_screen,
1581 HTMLWindow2_get_Option,
1582 HTMLWindow2_focus,
1583 HTMLWindow2_get_closed,
1584 HTMLWindow2_blur,
1585 HTMLWindow2_scroll,
1586 HTMLWindow2_get_clientInformation,
1587 HTMLWindow2_setInterval,
1588 HTMLWindow2_clearInterval,
1589 HTMLWindow2_put_offscreenBuffering,
1590 HTMLWindow2_get_offscreenBuffering,
1591 HTMLWindow2_execScript,
1592 HTMLWindow2_toString,
1593 HTMLWindow2_scrollBy,
1594 HTMLWindow2_scrollTo,
1595 HTMLWindow2_moveTo,
1596 HTMLWindow2_moveBy,
1597 HTMLWindow2_resizeTo,
1598 HTMLWindow2_resizeBy,
1599 HTMLWindow2_get_external
1602 static inline HTMLWindow *impl_from_IHTMLWindow3(IHTMLWindow3 *iface)
1604 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow3_iface);
1607 static HRESULT WINAPI HTMLWindow3_QueryInterface(IHTMLWindow3 *iface, REFIID riid, void **ppv)
1609 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1611 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1614 static ULONG WINAPI HTMLWindow3_AddRef(IHTMLWindow3 *iface)
1616 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1618 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1621 static ULONG WINAPI HTMLWindow3_Release(IHTMLWindow3 *iface)
1623 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1625 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1628 static HRESULT WINAPI HTMLWindow3_GetTypeInfoCount(IHTMLWindow3 *iface, UINT *pctinfo)
1630 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1632 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1635 static HRESULT WINAPI HTMLWindow3_GetTypeInfo(IHTMLWindow3 *iface, UINT iTInfo,
1636 LCID lcid, ITypeInfo **ppTInfo)
1638 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1640 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1643 static HRESULT WINAPI HTMLWindow3_GetIDsOfNames(IHTMLWindow3 *iface, REFIID riid,
1644 LPOLESTR *rgszNames, UINT cNames,
1645 LCID lcid, DISPID *rgDispId)
1647 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1649 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1650 rgDispId);
1653 static HRESULT WINAPI HTMLWindow3_Invoke(IHTMLWindow3 *iface, DISPID dispIdMember,
1654 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1655 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1657 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1659 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1660 pDispParams, pVarResult, pExcepInfo, puArgErr);
1663 static HRESULT WINAPI HTMLWindow3_get_screenLeft(IHTMLWindow3 *iface, LONG *p)
1665 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1666 nsresult nsres;
1668 TRACE("(%p)->(%p)\n", This, p);
1670 nsres = nsIDOMWindow_GetScreenX(This->outer_window->nswindow, p);
1671 if(NS_FAILED(nsres)) {
1672 ERR("GetScreenX failed: %08x\n", nsres);
1673 return E_FAIL;
1676 return S_OK;
1679 static HRESULT WINAPI HTMLWindow3_get_screenTop(IHTMLWindow3 *iface, LONG *p)
1681 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1682 nsresult nsres;
1684 TRACE("(%p)->(%p)\n", This, p);
1686 nsres = nsIDOMWindow_GetScreenY(This->outer_window->nswindow, p);
1687 if(NS_FAILED(nsres)) {
1688 ERR("GetScreenY failed: %08x\n", nsres);
1689 return E_FAIL;
1692 return S_OK;
1695 static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp, VARIANT_BOOL *pfResult)
1697 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1698 HTMLInnerWindow *window = This->inner_window;
1700 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
1702 if(!window->doc) {
1703 FIXME("No document\n");
1704 return E_FAIL;
1707 return attach_event(&window->event_target, event, pDisp, pfResult);
1710 static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
1712 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1713 HTMLInnerWindow *window = This->inner_window;
1715 TRACE("(%p)->()\n", This);
1717 if(!window->doc) {
1718 FIXME("No document\n");
1719 return E_FAIL;
1722 return detach_event(&window->event_target, event, pDisp);
1725 static HRESULT window_set_timer(HTMLInnerWindow *This, VARIANT *expr, LONG msec, VARIANT *language,
1726 BOOL interval, LONG *timer_id)
1728 IDispatch *disp = NULL;
1729 HRESULT hres;
1731 switch(V_VT(expr)) {
1732 case VT_DISPATCH:
1733 disp = V_DISPATCH(expr);
1734 IDispatch_AddRef(disp);
1735 break;
1737 case VT_BSTR:
1738 disp = script_parse_event(This->base.inner_window, V_BSTR(expr));
1739 break;
1741 default:
1742 FIXME("unimplemented expr %s\n", debugstr_variant(expr));
1743 return E_NOTIMPL;
1746 if(!disp)
1747 return E_FAIL;
1749 hres = set_task_timer(This, msec, interval, disp, timer_id);
1750 IDispatch_Release(disp);
1752 return hres;
1755 static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1756 VARIANT *language, LONG *timerID)
1758 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1760 TRACE("(%p)->(%s %d %s %p)\n", This, debugstr_variant(expression), msec, debugstr_variant(language), timerID);
1762 return window_set_timer(This->inner_window, expression, msec, language, FALSE, timerID);
1765 static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1766 VARIANT *language, LONG *timerID)
1768 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1770 TRACE("(%p)->(%p %d %p %p)\n", This, expression, msec, language, timerID);
1772 return window_set_timer(This->inner_window, expression, msec, language, TRUE, timerID);
1775 static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)
1777 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1778 FIXME("(%p)\n", This);
1779 return E_NOTIMPL;
1782 static HRESULT WINAPI HTMLWindow3_put_onbeforeprint(IHTMLWindow3 *iface, VARIANT v)
1784 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1785 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1786 return E_NOTIMPL;
1789 static HRESULT WINAPI HTMLWindow3_get_onbeforeprint(IHTMLWindow3 *iface, VARIANT *p)
1791 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1792 FIXME("(%p)->(%p)\n", This, p);
1793 return E_NOTIMPL;
1796 static HRESULT WINAPI HTMLWindow3_put_onafterprint(IHTMLWindow3 *iface, VARIANT v)
1798 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1799 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1800 return E_NOTIMPL;
1803 static HRESULT WINAPI HTMLWindow3_get_onafterprint(IHTMLWindow3 *iface, VARIANT *p)
1805 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1806 FIXME("(%p)->(%p)\n", This, p);
1807 return E_NOTIMPL;
1810 static HRESULT WINAPI HTMLWindow3_get_clipboardData(IHTMLWindow3 *iface, IHTMLDataTransfer **p)
1812 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1813 FIXME("(%p)->(%p)\n", This, p);
1814 return E_NOTIMPL;
1817 static HRESULT WINAPI HTMLWindow3_showModelessDialog(IHTMLWindow3 *iface, BSTR url,
1818 VARIANT *varArgIn, VARIANT *options, IHTMLWindow2 **pDialog)
1820 HTMLWindow *This = impl_from_IHTMLWindow3(iface);
1821 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(url), varArgIn, options, pDialog);
1822 return E_NOTIMPL;
1825 static const IHTMLWindow3Vtbl HTMLWindow3Vtbl = {
1826 HTMLWindow3_QueryInterface,
1827 HTMLWindow3_AddRef,
1828 HTMLWindow3_Release,
1829 HTMLWindow3_GetTypeInfoCount,
1830 HTMLWindow3_GetTypeInfo,
1831 HTMLWindow3_GetIDsOfNames,
1832 HTMLWindow3_Invoke,
1833 HTMLWindow3_get_screenLeft,
1834 HTMLWindow3_get_screenTop,
1835 HTMLWindow3_attachEvent,
1836 HTMLWindow3_detachEvent,
1837 HTMLWindow3_setTimeout,
1838 HTMLWindow3_setInterval,
1839 HTMLWindow3_print,
1840 HTMLWindow3_put_onbeforeprint,
1841 HTMLWindow3_get_onbeforeprint,
1842 HTMLWindow3_put_onafterprint,
1843 HTMLWindow3_get_onafterprint,
1844 HTMLWindow3_get_clipboardData,
1845 HTMLWindow3_showModelessDialog
1848 static inline HTMLWindow *impl_from_IHTMLWindow4(IHTMLWindow4 *iface)
1850 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow4_iface);
1853 static HRESULT WINAPI HTMLWindow4_QueryInterface(IHTMLWindow4 *iface, REFIID riid, void **ppv)
1855 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1857 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1860 static ULONG WINAPI HTMLWindow4_AddRef(IHTMLWindow4 *iface)
1862 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1864 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1867 static ULONG WINAPI HTMLWindow4_Release(IHTMLWindow4 *iface)
1869 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1871 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1874 static HRESULT WINAPI HTMLWindow4_GetTypeInfoCount(IHTMLWindow4 *iface, UINT *pctinfo)
1876 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1878 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1881 static HRESULT WINAPI HTMLWindow4_GetTypeInfo(IHTMLWindow4 *iface, UINT iTInfo,
1882 LCID lcid, ITypeInfo **ppTInfo)
1884 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1886 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1889 static HRESULT WINAPI HTMLWindow4_GetIDsOfNames(IHTMLWindow4 *iface, REFIID riid,
1890 LPOLESTR *rgszNames, UINT cNames,
1891 LCID lcid, DISPID *rgDispId)
1893 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1895 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1896 rgDispId);
1899 static HRESULT WINAPI HTMLWindow4_Invoke(IHTMLWindow4 *iface, DISPID dispIdMember,
1900 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1901 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1903 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1905 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
1906 pDispParams, pVarResult, pExcepInfo, puArgErr);
1909 static HRESULT WINAPI HTMLWindow4_createPopup(IHTMLWindow4 *iface, VARIANT *varArgIn,
1910 IDispatch **ppPopup)
1912 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1913 FIXME("(%p)->(%p %p)\n", This, varArgIn, ppPopup);
1914 return E_NOTIMPL;
1917 static HRESULT WINAPI HTMLWindow4_get_frameElement(IHTMLWindow4 *iface, IHTMLFrameBase **p)
1919 HTMLWindow *This = impl_from_IHTMLWindow4(iface);
1920 TRACE("(%p)->(%p)\n", This, p);
1922 if(This->outer_window->frame_element) {
1923 *p = &This->outer_window->frame_element->IHTMLFrameBase_iface;
1924 IHTMLFrameBase_AddRef(*p);
1925 }else
1926 *p = NULL;
1928 return S_OK;
1931 static const IHTMLWindow4Vtbl HTMLWindow4Vtbl = {
1932 HTMLWindow4_QueryInterface,
1933 HTMLWindow4_AddRef,
1934 HTMLWindow4_Release,
1935 HTMLWindow4_GetTypeInfoCount,
1936 HTMLWindow4_GetTypeInfo,
1937 HTMLWindow4_GetIDsOfNames,
1938 HTMLWindow4_Invoke,
1939 HTMLWindow4_createPopup,
1940 HTMLWindow4_get_frameElement
1943 static inline HTMLWindow *impl_from_IHTMLWindow5(IHTMLWindow5 *iface)
1945 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow5_iface);
1948 static HRESULT WINAPI HTMLWindow5_QueryInterface(IHTMLWindow5 *iface, REFIID riid, void **ppv)
1950 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1952 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
1955 static ULONG WINAPI HTMLWindow5_AddRef(IHTMLWindow5 *iface)
1957 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1959 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
1962 static ULONG WINAPI HTMLWindow5_Release(IHTMLWindow5 *iface)
1964 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1966 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
1969 static HRESULT WINAPI HTMLWindow5_GetTypeInfoCount(IHTMLWindow5 *iface, UINT *pctinfo)
1971 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1973 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
1976 static HRESULT WINAPI HTMLWindow5_GetTypeInfo(IHTMLWindow5 *iface, UINT iTInfo,
1977 LCID lcid, ITypeInfo **ppTInfo)
1979 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1981 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1984 static HRESULT WINAPI HTMLWindow5_GetIDsOfNames(IHTMLWindow5 *iface, REFIID riid,
1985 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1987 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1989 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
1990 rgDispId);
1993 static HRESULT WINAPI HTMLWindow5_Invoke(IHTMLWindow5 *iface, DISPID dispIdMember,
1994 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1995 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1997 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
1999 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
2000 pDispParams, pVarResult, pExcepInfo, puArgErr);
2003 static HRESULT WINAPI HTMLWindow5_put_XMLHttpRequest(IHTMLWindow5 *iface, VARIANT v)
2005 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
2006 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
2007 return E_NOTIMPL;
2010 static HRESULT WINAPI HTMLWindow5_get_XMLHttpRequest(IHTMLWindow5 *iface, VARIANT *p)
2012 HTMLWindow *This = impl_from_IHTMLWindow5(iface);
2013 HTMLInnerWindow *window = This->inner_window;
2015 TRACE("(%p)->(%p)\n", This, p);
2017 if(!window->xhr_factory) {
2018 HRESULT hres;
2020 hres = HTMLXMLHttpRequestFactory_Create(window, &window->xhr_factory);
2021 if(FAILED(hres)) {
2022 return hres;
2026 V_VT(p) = VT_DISPATCH;
2027 V_DISPATCH(p) = (IDispatch*)&window->xhr_factory->IHTMLXMLHttpRequestFactory_iface;
2028 IDispatch_AddRef(V_DISPATCH(p));
2030 return S_OK;
2033 static const IHTMLWindow5Vtbl HTMLWindow5Vtbl = {
2034 HTMLWindow5_QueryInterface,
2035 HTMLWindow5_AddRef,
2036 HTMLWindow5_Release,
2037 HTMLWindow5_GetTypeInfoCount,
2038 HTMLWindow5_GetTypeInfo,
2039 HTMLWindow5_GetIDsOfNames,
2040 HTMLWindow5_Invoke,
2041 HTMLWindow5_put_XMLHttpRequest,
2042 HTMLWindow5_get_XMLHttpRequest
2045 static inline HTMLWindow *impl_from_IHTMLWindow6(IHTMLWindow6 *iface)
2047 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLWindow6_iface);
2050 static HRESULT WINAPI HTMLWindow6_QueryInterface(IHTMLWindow6 *iface, REFIID riid, void **ppv)
2052 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2054 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2057 static ULONG WINAPI HTMLWindow6_AddRef(IHTMLWindow6 *iface)
2059 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2061 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2064 static ULONG WINAPI HTMLWindow6_Release(IHTMLWindow6 *iface)
2066 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2068 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2071 static HRESULT WINAPI HTMLWindow6_GetTypeInfoCount(IHTMLWindow6 *iface, UINT *pctinfo)
2073 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2075 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
2078 static HRESULT WINAPI HTMLWindow6_GetTypeInfo(IHTMLWindow6 *iface, UINT iTInfo,
2079 LCID lcid, ITypeInfo **ppTInfo)
2081 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2083 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2086 static HRESULT WINAPI HTMLWindow6_GetIDsOfNames(IHTMLWindow6 *iface, REFIID riid,
2087 LPOLESTR *rgszNames, UINT cNames,
2088 LCID lcid, DISPID *rgDispId)
2090 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2092 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
2093 rgDispId);
2096 static HRESULT WINAPI HTMLWindow6_Invoke(IHTMLWindow6 *iface, DISPID dispIdMember,
2097 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2098 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2100 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2102 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
2103 pDispParams, pVarResult, pExcepInfo, puArgErr);
2106 static HRESULT WINAPI HTMLWindow6_put_XDomainRequest(IHTMLWindow6 *iface, VARIANT v)
2108 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2109 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
2110 return E_NOTIMPL;
2113 static HRESULT WINAPI HTMLWindow6_get_XDomainRequest(IHTMLWindow6 *iface, VARIANT *p)
2115 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2116 FIXME("(%p)->(%p)\n", This, p);
2117 return E_NOTIMPL;
2120 static HRESULT WINAPI HTMLWindow6_get_sessionStorage(IHTMLWindow6 *iface, IHTMLStorage **p)
2122 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2124 FIXME("(%p)->(%p)\n", This, p);
2126 if(!This->inner_window->session_storage) {
2127 HRESULT hres;
2129 hres = create_storage(&This->inner_window->session_storage);
2130 if(FAILED(hres))
2131 return hres;
2134 IHTMLStorage_AddRef(This->inner_window->session_storage);
2135 *p = This->inner_window->session_storage;
2136 return S_OK;
2139 static HRESULT WINAPI HTMLWindow6_get_localStorage(IHTMLWindow6 *iface, IHTMLStorage **p)
2141 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2142 FIXME("(%p)->(%p)\n", This, p);
2143 return E_NOTIMPL;
2146 static HRESULT WINAPI HTMLWindow6_put_onhashchange(IHTMLWindow6 *iface, VARIANT v)
2148 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2149 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
2150 return E_NOTIMPL;
2153 static HRESULT WINAPI HTMLWindow6_get_onhashchange(IHTMLWindow6 *iface, VARIANT *p)
2155 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2156 FIXME("(%p)->(%p)\n", This, p);
2157 return E_NOTIMPL;
2160 static HRESULT WINAPI HTMLWindow6_get_maxConnectionsPerServer(IHTMLWindow6 *iface, LONG *p)
2162 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2163 FIXME("(%p)->(%p)\n", This, p);
2164 return E_NOTIMPL;
2167 static HRESULT WINAPI HTMLWindow6_postMessage(IHTMLWindow6 *iface, BSTR msg, VARIANT targetOrigin)
2169 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2171 FIXME("(%p)->(%s %s) semi-stub\n", This, debugstr_w(msg), debugstr_variant(&targetOrigin));
2173 if(!This->inner_window->doc) {
2174 FIXME("No document\n");
2175 return E_FAIL;
2178 fire_event(This->inner_window->doc, EVENTID_MESSAGE, TRUE, &This->inner_window->doc->node, NULL, NULL);
2179 return S_OK;
2182 static HRESULT WINAPI HTMLWindow6_toStaticHTML(IHTMLWindow6 *iface, BSTR bstrHTML, BSTR *pbstrStaticHTML)
2184 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2185 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrHTML), pbstrStaticHTML);
2186 return E_NOTIMPL;
2189 static HRESULT WINAPI HTMLWindow6_put_onmessage(IHTMLWindow6 *iface, VARIANT v)
2191 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2193 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
2195 return set_window_event(This, EVENTID_MESSAGE, &v);
2198 static HRESULT WINAPI HTMLWindow6_get_onmessage(IHTMLWindow6 *iface, VARIANT *p)
2200 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2202 TRACE("(%p)->(%p)\n", This, p);
2204 return get_window_event(This, EVENTID_MESSAGE, p);
2207 static HRESULT WINAPI HTMLWindow6_msWriteProfilerMark(IHTMLWindow6 *iface, BSTR bstrProfilerMark)
2209 HTMLWindow *This = impl_from_IHTMLWindow6(iface);
2210 FIXME("(%p)->(%s)\n", This, debugstr_w(bstrProfilerMark));
2211 return E_NOTIMPL;
2214 static const IHTMLWindow6Vtbl HTMLWindow6Vtbl = {
2215 HTMLWindow6_QueryInterface,
2216 HTMLWindow6_AddRef,
2217 HTMLWindow6_Release,
2218 HTMLWindow6_GetTypeInfoCount,
2219 HTMLWindow6_GetTypeInfo,
2220 HTMLWindow6_GetIDsOfNames,
2221 HTMLWindow6_Invoke,
2222 HTMLWindow6_put_XDomainRequest,
2223 HTMLWindow6_get_XDomainRequest,
2224 HTMLWindow6_get_sessionStorage,
2225 HTMLWindow6_get_localStorage,
2226 HTMLWindow6_put_onhashchange,
2227 HTMLWindow6_get_onhashchange,
2228 HTMLWindow6_get_maxConnectionsPerServer,
2229 HTMLWindow6_postMessage,
2230 HTMLWindow6_toStaticHTML,
2231 HTMLWindow6_put_onmessage,
2232 HTMLWindow6_get_onmessage,
2233 HTMLWindow6_msWriteProfilerMark
2236 static inline HTMLWindow *impl_from_IHTMLPrivateWindow(IHTMLPrivateWindow *iface)
2238 return CONTAINING_RECORD(iface, HTMLWindow, IHTMLPrivateWindow_iface);
2241 static HRESULT WINAPI HTMLPrivateWindow_QueryInterface(IHTMLPrivateWindow *iface, REFIID riid, void **ppv)
2243 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2245 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2248 static ULONG WINAPI HTMLPrivateWindow_AddRef(IHTMLPrivateWindow *iface)
2250 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2252 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2255 static ULONG WINAPI HTMLPrivateWindow_Release(IHTMLPrivateWindow *iface)
2257 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2259 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2262 static HRESULT WINAPI HTMLPrivateWindow_SuperNavigate(IHTMLPrivateWindow *iface, BSTR url, BSTR arg2, BSTR arg3,
2263 BSTR arg4, VARIANT *post_data_var, VARIANT *headers_var, ULONG flags)
2265 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2266 HTMLOuterWindow *window = This->outer_window;
2267 OLECHAR *translated_url = NULL;
2268 DWORD post_data_size = 0;
2269 BYTE *post_data = NULL;
2270 WCHAR *headers = NULL;
2271 IUri *uri;
2272 HRESULT hres;
2274 TRACE("(%p)->(%s %s %s %s %s %s %x)\n", This, debugstr_w(url), debugstr_w(arg2), debugstr_w(arg3), debugstr_w(arg4),
2275 debugstr_variant(post_data_var), debugstr_variant(headers_var), flags);
2277 if(window->doc_obj->hostui) {
2278 hres = IDocHostUIHandler_TranslateUrl(window->doc_obj->hostui, 0, url, &translated_url);
2279 if(hres != S_OK)
2280 translated_url = NULL;
2283 hres = create_uri(translated_url ? translated_url : url, 0, &uri);
2284 CoTaskMemFree(translated_url);
2285 if(FAILED(hres))
2286 return hres;
2288 if(post_data_var) {
2289 if(V_VT(post_data_var) == (VT_ARRAY|VT_UI1)) {
2290 SafeArrayAccessData(V_ARRAY(post_data_var), (void**)&post_data);
2291 post_data_size = V_ARRAY(post_data_var)->rgsabound[0].cElements;
2295 if(headers_var && V_VT(headers_var) != VT_EMPTY && V_VT(headers_var) != VT_ERROR) {
2296 if(V_VT(headers_var) != VT_BSTR)
2297 return E_INVALIDARG;
2299 headers = V_BSTR(headers_var);
2302 hres = super_navigate(window, uri, BINDING_NAVIGATED|BINDING_NOFRAG, headers, post_data, post_data_size);
2303 IUri_Release(uri);
2304 if(post_data)
2305 SafeArrayUnaccessData(V_ARRAY(post_data_var));
2307 return hres;
2310 static HRESULT WINAPI HTMLPrivateWindow_GetPendingUrl(IHTMLPrivateWindow *iface, BSTR *url)
2312 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2313 FIXME("(%p)->(%p)\n", This, url);
2314 return E_NOTIMPL;
2317 static HRESULT WINAPI HTMLPrivateWindow_SetPICSTarget(IHTMLPrivateWindow *iface, IOleCommandTarget *cmdtrg)
2319 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2320 FIXME("(%p)->(%p)\n", This, cmdtrg);
2321 return E_NOTIMPL;
2324 static HRESULT WINAPI HTMLPrivateWindow_PICSComplete(IHTMLPrivateWindow *iface, int arg)
2326 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2327 FIXME("(%p)->(%x)\n", This, arg);
2328 return E_NOTIMPL;
2331 static HRESULT WINAPI HTMLPrivateWindow_FindWindowByName(IHTMLPrivateWindow *iface, LPCWSTR name, IHTMLWindow2 **ret)
2333 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2334 FIXME("(%p)->(%s %p)\n", This, debugstr_w(name), ret);
2335 return E_NOTIMPL;
2338 static HRESULT WINAPI HTMLPrivateWindow_GetAddressBarUrl(IHTMLPrivateWindow *iface, BSTR *url)
2340 HTMLWindow *This = impl_from_IHTMLPrivateWindow(iface);
2341 TRACE("(%p)->(%p)\n", This, url);
2343 if(!url)
2344 return E_INVALIDARG;
2346 *url = SysAllocString(This->outer_window->url);
2347 return S_OK;
2350 static const IHTMLPrivateWindowVtbl HTMLPrivateWindowVtbl = {
2351 HTMLPrivateWindow_QueryInterface,
2352 HTMLPrivateWindow_AddRef,
2353 HTMLPrivateWindow_Release,
2354 HTMLPrivateWindow_SuperNavigate,
2355 HTMLPrivateWindow_GetPendingUrl,
2356 HTMLPrivateWindow_SetPICSTarget,
2357 HTMLPrivateWindow_PICSComplete,
2358 HTMLPrivateWindow_FindWindowByName,
2359 HTMLPrivateWindow_GetAddressBarUrl
2362 static inline HTMLWindow *impl_from_ITravelLogClient(ITravelLogClient *iface)
2364 return CONTAINING_RECORD(iface, HTMLWindow, ITravelLogClient_iface);
2367 static HRESULT WINAPI TravelLogClient_QueryInterface(ITravelLogClient *iface, REFIID riid, void **ppv)
2369 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2371 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2374 static ULONG WINAPI TravelLogClient_AddRef(ITravelLogClient *iface)
2376 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2378 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2381 static ULONG WINAPI TravelLogClient_Release(ITravelLogClient *iface)
2383 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2385 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2388 static HRESULT WINAPI TravelLogClient_FindWindowByIndex(ITravelLogClient *iface, DWORD dwID, IUnknown **ppunk)
2390 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2392 FIXME("(%p)->(%d %p) semi-stub\n", This, dwID, ppunk);
2394 *ppunk = NULL;
2395 return E_FAIL;
2398 static HRESULT WINAPI TravelLogClient_GetWindowData(ITravelLogClient *iface, IStream *pStream, LPWINDOWDATA pWinData)
2400 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2401 FIXME("(%p)->(%p %p)\n", This, pStream, pWinData);
2402 return E_NOTIMPL;
2405 static HRESULT WINAPI TravelLogClient_LoadHistoryPosition(ITravelLogClient *iface, LPWSTR pszUrlLocation, DWORD dwPosition)
2407 HTMLWindow *This = impl_from_ITravelLogClient(iface);
2408 FIXME("(%p)->(%s %d)\n", This, debugstr_w(pszUrlLocation), dwPosition);
2409 return E_NOTIMPL;
2412 static const ITravelLogClientVtbl TravelLogClientVtbl = {
2413 TravelLogClient_QueryInterface,
2414 TravelLogClient_AddRef,
2415 TravelLogClient_Release,
2416 TravelLogClient_FindWindowByIndex,
2417 TravelLogClient_GetWindowData,
2418 TravelLogClient_LoadHistoryPosition
2421 static inline HTMLWindow *impl_from_IObjectIdentity(IObjectIdentity *iface)
2423 return CONTAINING_RECORD(iface, HTMLWindow, IObjectIdentity_iface);
2426 static HRESULT WINAPI ObjectIdentity_QueryInterface(IObjectIdentity *iface, REFIID riid, void **ppv)
2428 HTMLWindow *This = impl_from_IObjectIdentity(iface);
2430 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2433 static ULONG WINAPI ObjectIdentity_AddRef(IObjectIdentity *iface)
2435 HTMLWindow *This = impl_from_IObjectIdentity(iface);
2437 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2440 static ULONG WINAPI ObjectIdentity_Release(IObjectIdentity *iface)
2442 HTMLWindow *This = impl_from_IObjectIdentity(iface);
2444 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2447 static HRESULT WINAPI ObjectIdentity_IsEqualObject(IObjectIdentity *iface, IUnknown *unk)
2449 HTMLWindow *This = impl_from_IObjectIdentity(iface);
2450 IServiceProvider *sp;
2451 HRESULT hres;
2453 TRACE("(%p)->(%p)\n", This, unk);
2455 hres = IUnknown_QueryInterface(unk, &IID_IServiceProvider, (void**)&sp);
2456 if(hres != S_OK)
2457 return hres;
2459 hres = &This->inner_window->base.IServiceProvider_iface==sp ||
2460 &This->outer_window->base.IServiceProvider_iface==sp ? S_OK : S_FALSE;
2461 IServiceProvider_Release(sp);
2462 return hres;
2465 static const IObjectIdentityVtbl ObjectIdentityVtbl = {
2466 ObjectIdentity_QueryInterface,
2467 ObjectIdentity_AddRef,
2468 ObjectIdentity_Release,
2469 ObjectIdentity_IsEqualObject
2472 static inline HTMLWindow *impl_from_IProvideMultipleClassInfo(IProvideMultipleClassInfo *iface)
2474 return CONTAINING_RECORD(iface, HTMLWindow, IProvideMultipleClassInfo_iface);
2477 static HRESULT WINAPI ProvideClassInfo_QueryInterface(IProvideMultipleClassInfo *iface,
2478 REFIID riid, void **ppv)
2480 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
2481 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2484 static ULONG WINAPI ProvideClassInfo_AddRef(IProvideMultipleClassInfo *iface)
2486 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
2487 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2490 static ULONG WINAPI ProvideClassInfo_Release(IProvideMultipleClassInfo *iface)
2492 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
2493 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2496 static HRESULT WINAPI ProvideClassInfo_GetClassInfo(IProvideMultipleClassInfo *iface, ITypeInfo **ppTI)
2498 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
2499 TRACE("(%p)->(%p)\n", This, ppTI);
2500 return get_class_typeinfo(&CLSID_HTMLWindow2, ppTI);
2503 static HRESULT WINAPI ProvideClassInfo2_GetGUID(IProvideMultipleClassInfo *iface, DWORD dwGuidKind, GUID *pGUID)
2505 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
2506 FIXME("(%p)->(%u %p)\n", This, dwGuidKind, pGUID);
2507 return E_NOTIMPL;
2510 static HRESULT WINAPI ProvideMultipleClassInfo_GetMultiTypeInfoCount(IProvideMultipleClassInfo *iface, ULONG *pcti)
2512 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
2513 FIXME("(%p)->(%p)\n", This, pcti);
2514 *pcti = 1;
2515 return S_OK;
2518 static HRESULT WINAPI ProvideMultipleClassInfo_GetInfoOfIndex(IProvideMultipleClassInfo *iface, ULONG iti,
2519 DWORD dwFlags, ITypeInfo **pptiCoClass, DWORD *pdwTIFlags, ULONG *pcdispidReserved, IID *piidPrimary, IID *piidSource)
2521 HTMLWindow *This = impl_from_IProvideMultipleClassInfo(iface);
2522 FIXME("(%p)->(%u %x %p %p %p %p %p)\n", This, iti, dwFlags, pptiCoClass, pdwTIFlags, pcdispidReserved, piidPrimary, piidSource);
2523 return E_NOTIMPL;
2526 static const IProvideMultipleClassInfoVtbl ProvideMultipleClassInfoVtbl = {
2527 ProvideClassInfo_QueryInterface,
2528 ProvideClassInfo_AddRef,
2529 ProvideClassInfo_Release,
2530 ProvideClassInfo_GetClassInfo,
2531 ProvideClassInfo2_GetGUID,
2532 ProvideMultipleClassInfo_GetMultiTypeInfoCount,
2533 ProvideMultipleClassInfo_GetInfoOfIndex
2536 static inline HTMLWindow *impl_from_IDispatchEx(IDispatchEx *iface)
2538 return CONTAINING_RECORD(iface, HTMLWindow, IDispatchEx_iface);
2541 static HRESULT WINAPI WindowDispEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
2543 HTMLWindow *This = impl_from_IDispatchEx(iface);
2545 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2548 static ULONG WINAPI WindowDispEx_AddRef(IDispatchEx *iface)
2550 HTMLWindow *This = impl_from_IDispatchEx(iface);
2552 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2555 static ULONG WINAPI WindowDispEx_Release(IDispatchEx *iface)
2557 HTMLWindow *This = impl_from_IDispatchEx(iface);
2559 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2562 static HRESULT WINAPI WindowDispEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
2564 HTMLWindow *This = impl_from_IDispatchEx(iface);
2566 TRACE("(%p)->(%p)\n", This, pctinfo);
2568 return IDispatchEx_GetTypeInfoCount(&This->inner_window->event_target.dispex.IDispatchEx_iface, pctinfo);
2571 static HRESULT WINAPI WindowDispEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
2572 LCID lcid, ITypeInfo **ppTInfo)
2574 HTMLWindow *This = impl_from_IDispatchEx(iface);
2576 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
2578 return IDispatchEx_GetTypeInfo(&This->inner_window->event_target.dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2581 static HRESULT WINAPI WindowDispEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
2582 LPOLESTR *rgszNames, UINT cNames,
2583 LCID lcid, DISPID *rgDispId)
2585 HTMLWindow *This = impl_from_IDispatchEx(iface);
2586 UINT i;
2587 HRESULT hres;
2589 WARN("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
2591 for(i=0; i < cNames; i++) {
2592 /* We shouldn't use script's IDispatchEx here, so we shouldn't use GetDispID */
2593 hres = IDispatchEx_GetDispID(&This->IDispatchEx_iface, rgszNames[i], 0, rgDispId+i);
2594 if(FAILED(hres))
2595 return hres;
2598 return S_OK;
2601 static HRESULT WINAPI WindowDispEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
2602 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2603 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2605 HTMLWindow *This = impl_from_IDispatchEx(iface);
2607 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
2608 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2610 /* FIXME: Use script dispatch */
2612 return IDispatchEx_Invoke(&This->inner_window->event_target.dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
2613 pDispParams, pVarResult, pExcepInfo, puArgErr);
2616 static global_prop_t *alloc_global_prop(HTMLInnerWindow *This, global_prop_type_t type, BSTR name)
2618 if(This->global_prop_cnt == This->global_prop_size) {
2619 global_prop_t *new_props;
2620 DWORD new_size;
2622 if(This->global_props) {
2623 new_size = This->global_prop_size*2;
2624 new_props = heap_realloc(This->global_props, new_size*sizeof(global_prop_t));
2625 }else {
2626 new_size = 16;
2627 new_props = heap_alloc(new_size*sizeof(global_prop_t));
2629 if(!new_props)
2630 return NULL;
2631 This->global_props = new_props;
2632 This->global_prop_size = new_size;
2635 This->global_props[This->global_prop_cnt].name = heap_strdupW(name);
2636 if(!This->global_props[This->global_prop_cnt].name)
2637 return NULL;
2639 This->global_props[This->global_prop_cnt].type = type;
2640 return This->global_props + This->global_prop_cnt++;
2643 static inline DWORD prop_to_dispid(HTMLInnerWindow *This, global_prop_t *prop)
2645 return MSHTML_DISPID_CUSTOM_MIN + (prop-This->global_props);
2648 HRESULT search_window_props(HTMLInnerWindow *This, BSTR bstrName, DWORD grfdex, DISPID *pid)
2650 DWORD i;
2651 ScriptHost *script_host;
2652 DISPID id;
2654 for(i=0; i < This->global_prop_cnt; i++) {
2655 /* FIXME: case sensitivity */
2656 if(!strcmpW(This->global_props[i].name, bstrName)) {
2657 *pid = MSHTML_DISPID_CUSTOM_MIN+i;
2658 return S_OK;
2662 if(find_global_prop(This->base.inner_window, bstrName, grfdex, &script_host, &id)) {
2663 global_prop_t *prop;
2665 prop = alloc_global_prop(This, GLOBAL_SCRIPTVAR, bstrName);
2666 if(!prop)
2667 return E_OUTOFMEMORY;
2669 prop->script_host = script_host;
2670 prop->id = id;
2672 *pid = prop_to_dispid(This, prop);
2673 return S_OK;
2676 return DISP_E_UNKNOWNNAME;
2679 static HRESULT WINAPI WindowDispEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
2681 HTMLWindow *This = impl_from_IDispatchEx(iface);
2682 HTMLInnerWindow *window = This->inner_window;
2683 HRESULT hres;
2685 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
2687 hres = search_window_props(window, bstrName, grfdex, pid);
2688 if(hres != DISP_E_UNKNOWNNAME)
2689 return hres;
2691 hres = IDispatchEx_GetDispID(&window->base.inner_window->event_target.dispex.IDispatchEx_iface, bstrName, grfdex, pid);
2692 if(hres != DISP_E_UNKNOWNNAME)
2693 return hres;
2695 if(This->outer_window) {
2696 HTMLOuterWindow *frame;
2698 hres = get_frame_by_name(This->outer_window, bstrName, FALSE, &frame);
2699 if(SUCCEEDED(hres) && frame) {
2700 global_prop_t *prop;
2702 IHTMLWindow2_Release(&frame->base.IHTMLWindow2_iface);
2704 prop = alloc_global_prop(window, GLOBAL_FRAMEVAR, bstrName);
2705 if(!prop)
2706 return E_OUTOFMEMORY;
2708 *pid = prop_to_dispid(window, prop);
2709 return S_OK;
2713 if(window->doc) {
2714 global_prop_t *prop;
2715 IHTMLElement *elem;
2717 hres = IHTMLDocument3_getElementById(&window->base.inner_window->doc->basedoc.IHTMLDocument3_iface,
2718 bstrName, &elem);
2719 if(SUCCEEDED(hres) && elem) {
2720 IHTMLElement_Release(elem);
2722 prop = alloc_global_prop(window, GLOBAL_ELEMENTVAR, bstrName);
2723 if(!prop)
2724 return E_OUTOFMEMORY;
2726 *pid = prop_to_dispid(window, prop);
2727 return S_OK;
2731 return DISP_E_UNKNOWNNAME;
2734 static HRESULT WINAPI WindowDispEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
2735 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
2737 HTMLWindow *This = impl_from_IDispatchEx(iface);
2738 HTMLInnerWindow *window = This->inner_window;
2740 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
2742 switch(id) {
2743 case DISPID_IHTMLWINDOW2_LOCATION: {
2744 HTMLLocation *location;
2745 HRESULT hres;
2747 if(!(wFlags & DISPATCH_PROPERTYPUT))
2748 break;
2750 TRACE("forwarding to location.href\n");
2752 hres = get_location(window, &location);
2753 if(FAILED(hres))
2754 return hres;
2756 hres = IDispatchEx_InvokeEx(&location->dispex.IDispatchEx_iface, DISPID_VALUE, lcid,
2757 wFlags, pdp, pvarRes, pei, pspCaller);
2758 IHTMLLocation_Release(&location->IHTMLLocation_iface);
2759 return hres;
2761 case DISPID_IHTMLWINDOW2_SETTIMEOUT:
2762 case DISPID_IHTMLWINDOW3_SETTIMEOUT: {
2763 VARIANT args[2];
2764 DISPPARAMS dp = {args, NULL, 2, 0};
2767 * setTimeout calls should use default value 0 for the second argument if only one is provided,
2768 * but IDL file does not reflect that. We fixup arguments here instead.
2770 if(!(wFlags & DISPATCH_METHOD) || pdp->cArgs != 1 || pdp->cNamedArgs)
2771 break;
2773 TRACE("Fixing args\n");
2775 V_VT(args) = VT_I4;
2776 V_I4(args) = 0;
2777 args[1] = *pdp->rgvarg;
2778 return IDispatchEx_InvokeEx(&window->event_target.dispex.IDispatchEx_iface, id, lcid,
2779 wFlags, &dp, pvarRes, pei, pspCaller);
2783 return IDispatchEx_InvokeEx(&window->event_target.dispex.IDispatchEx_iface, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
2786 static HRESULT WINAPI WindowDispEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
2788 HTMLWindow *This = impl_from_IDispatchEx(iface);
2790 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
2792 return IDispatchEx_DeleteMemberByName(&This->inner_window->event_target.dispex.IDispatchEx_iface, bstrName, grfdex);
2795 static HRESULT WINAPI WindowDispEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
2797 HTMLWindow *This = impl_from_IDispatchEx(iface);
2799 TRACE("(%p)->(%x)\n", This, id);
2801 return IDispatchEx_DeleteMemberByDispID(&This->inner_window->event_target.dispex.IDispatchEx_iface, id);
2804 static HRESULT WINAPI WindowDispEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
2806 HTMLWindow *This = impl_from_IDispatchEx(iface);
2808 TRACE("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
2810 return IDispatchEx_GetMemberProperties(&This->inner_window->event_target.dispex.IDispatchEx_iface, id, grfdexFetch,
2811 pgrfdex);
2814 static HRESULT WINAPI WindowDispEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
2816 HTMLWindow *This = impl_from_IDispatchEx(iface);
2818 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
2820 return IDispatchEx_GetMemberName(&This->inner_window->event_target.dispex.IDispatchEx_iface, id, pbstrName);
2823 static HRESULT WINAPI WindowDispEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
2825 HTMLWindow *This = impl_from_IDispatchEx(iface);
2827 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
2829 return IDispatchEx_GetNextDispID(&This->inner_window->event_target.dispex.IDispatchEx_iface, grfdex, id, pid);
2832 static HRESULT WINAPI WindowDispEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
2834 HTMLWindow *This = impl_from_IDispatchEx(iface);
2836 TRACE("(%p)->(%p)\n", This, ppunk);
2838 *ppunk = NULL;
2839 return S_OK;
2842 static const IDispatchExVtbl WindowDispExVtbl = {
2843 WindowDispEx_QueryInterface,
2844 WindowDispEx_AddRef,
2845 WindowDispEx_Release,
2846 WindowDispEx_GetTypeInfoCount,
2847 WindowDispEx_GetTypeInfo,
2848 WindowDispEx_GetIDsOfNames,
2849 WindowDispEx_Invoke,
2850 WindowDispEx_GetDispID,
2851 WindowDispEx_InvokeEx,
2852 WindowDispEx_DeleteMemberByName,
2853 WindowDispEx_DeleteMemberByDispID,
2854 WindowDispEx_GetMemberProperties,
2855 WindowDispEx_GetMemberName,
2856 WindowDispEx_GetNextDispID,
2857 WindowDispEx_GetNameSpaceParent
2860 static inline HTMLWindow *impl_from_IServiceProvider(IServiceProvider *iface)
2862 return CONTAINING_RECORD(iface, HTMLWindow, IServiceProvider_iface);
2865 static HRESULT WINAPI HTMLWindowSP_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
2867 HTMLWindow *This = impl_from_IServiceProvider(iface);
2868 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2871 static ULONG WINAPI HTMLWindowSP_AddRef(IServiceProvider *iface)
2873 HTMLWindow *This = impl_from_IServiceProvider(iface);
2874 return IHTMLWindow2_AddRef(&This->IHTMLWindow2_iface);
2877 static ULONG WINAPI HTMLWindowSP_Release(IServiceProvider *iface)
2879 HTMLWindow *This = impl_from_IServiceProvider(iface);
2880 return IHTMLWindow2_Release(&This->IHTMLWindow2_iface);
2883 static HRESULT WINAPI HTMLWindowSP_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv)
2885 HTMLWindow *This = impl_from_IServiceProvider(iface);
2887 if(IsEqualGUID(guidService, &IID_IHTMLWindow2)) {
2888 TRACE("IID_IHTMLWindow2\n");
2889 return IHTMLWindow2_QueryInterface(&This->IHTMLWindow2_iface, riid, ppv);
2892 TRACE("(%p)->(%s %s %p)\n", This, debugstr_mshtml_guid(guidService), debugstr_mshtml_guid(riid), ppv);
2894 if(!This->outer_window->doc_obj)
2895 return E_NOINTERFACE;
2897 return IServiceProvider_QueryService(&This->outer_window->doc_obj->basedoc.IServiceProvider_iface,
2898 guidService, riid, ppv);
2901 static const IServiceProviderVtbl ServiceProviderVtbl = {
2902 HTMLWindowSP_QueryInterface,
2903 HTMLWindowSP_AddRef,
2904 HTMLWindowSP_Release,
2905 HTMLWindowSP_QueryService
2908 static inline HTMLInnerWindow *impl_from_DispatchEx(DispatchEx *iface)
2910 return CONTAINING_RECORD(iface, HTMLInnerWindow, event_target.dispex);
2913 static HRESULT HTMLWindow_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2914 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2916 HTMLInnerWindow *This = impl_from_DispatchEx(dispex);
2917 global_prop_t *prop;
2918 DWORD idx;
2919 HRESULT hres;
2921 idx = id - MSHTML_DISPID_CUSTOM_MIN;
2922 if(idx >= This->global_prop_cnt)
2923 return DISP_E_MEMBERNOTFOUND;
2925 prop = This->global_props+idx;
2927 switch(prop->type) {
2928 case GLOBAL_SCRIPTVAR: {
2929 IDispatchEx *iface;
2930 IDispatch *disp;
2932 disp = get_script_disp(prop->script_host);
2933 if(!disp)
2934 return E_UNEXPECTED;
2936 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&iface);
2937 if(SUCCEEDED(hres)) {
2938 TRACE("%s >>>\n", debugstr_w(prop->name));
2939 hres = IDispatchEx_InvokeEx(iface, prop->id, lcid, flags, params, res, ei, caller);
2940 if(hres == S_OK)
2941 TRACE("%s <<<\n", debugstr_w(prop->name));
2942 else
2943 WARN("%s <<< %08x\n", debugstr_w(prop->name), hres);
2944 IDispatchEx_Release(iface);
2945 }else {
2946 FIXME("No IDispatchEx\n");
2948 IDispatch_Release(disp);
2949 break;
2951 case GLOBAL_ELEMENTVAR:
2952 switch(flags) {
2953 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
2954 case DISPATCH_PROPERTYGET: {
2955 IHTMLElement *elem;
2957 hres = IHTMLDocument3_getElementById(&This->base.inner_window->doc->basedoc.IHTMLDocument3_iface,
2958 prop->name, &elem);
2959 if(FAILED(hres))
2960 return hres;
2962 if(!elem)
2963 return DISP_E_MEMBERNOTFOUND;
2965 V_VT(res) = VT_DISPATCH;
2966 V_DISPATCH(res) = (IDispatch*)elem;
2967 return S_OK;
2969 case DISPATCH_PROPERTYPUT: {
2970 DISPID dispex_id;
2972 hres = dispex_get_dynid(&This->event_target.dispex, prop->name, &dispex_id);
2973 if(FAILED(hres))
2974 return hres;
2976 prop->type = GLOBAL_DISPEXVAR;
2977 prop->id = dispex_id;
2978 return IDispatchEx_InvokeEx(&This->event_target.dispex.IDispatchEx_iface, dispex_id, 0, flags, params, res, ei, caller);
2980 default:
2981 FIXME("Not supported flags: %x\n", flags);
2982 return E_NOTIMPL;
2984 case GLOBAL_FRAMEVAR:
2985 if(!This->base.outer_window)
2986 return E_UNEXPECTED;
2988 switch(flags) {
2989 case DISPATCH_PROPERTYGET: {
2990 HTMLOuterWindow *frame;
2992 hres = get_frame_by_name(This->base.outer_window, prop->name, FALSE, &frame);
2993 if(FAILED(hres))
2994 return hres;
2996 if(!frame)
2997 return DISP_E_MEMBERNOTFOUND;
2999 V_VT(res) = VT_DISPATCH;
3000 V_DISPATCH(res) = (IDispatch*)&frame->base.inner_window->base.IHTMLWindow2_iface;
3001 IDispatch_AddRef(V_DISPATCH(res));
3002 return S_OK;
3004 default:
3005 FIXME("Not supported flags: %x\n", flags);
3006 return E_NOTIMPL;
3008 case GLOBAL_DISPEXVAR:
3009 return IDispatchEx_InvokeEx(&This->event_target.dispex.IDispatchEx_iface, prop->id, 0, flags, params, res, ei, caller);
3010 default:
3011 ERR("invalid type %d\n", prop->type);
3012 hres = DISP_E_MEMBERNOTFOUND;
3015 return hres;
3018 static EventTarget *HTMLWindow_get_event_target(DispatchEx *dispex)
3020 HTMLInnerWindow *This = impl_from_DispatchEx(dispex);
3021 return &This->event_target;
3024 static void HTMLWindow_bind_event(DispatchEx *dispex, int eid)
3026 HTMLInnerWindow *This = impl_from_DispatchEx(dispex);
3027 dispex_get_vtbl(&This->doc->node.event_target.dispex)->bind_event(&This->doc->node.event_target.dispex, eid);
3030 static void HTMLWindow_init_dispex_info(dispex_data_t *info, compat_mode_t compat_mode)
3032 dispex_info_add_interface(info, IHTMLWindow5_tid);
3035 static const dispex_static_data_vtbl_t HTMLWindow_dispex_vtbl = {
3036 NULL,
3037 NULL,
3038 HTMLWindow_invoke,
3039 NULL,
3040 HTMLWindow_get_event_target,
3041 HTMLWindow_bind_event
3044 static const tid_t HTMLWindow_iface_tids[] = {
3045 IHTMLWindow2_tid,
3046 IHTMLWindow3_tid,
3047 IHTMLWindow4_tid,
3048 IHTMLWindow6_tid,
3052 static dispex_static_data_t HTMLWindow_dispex = {
3053 &HTMLWindow_dispex_vtbl,
3054 DispHTMLWindow2_tid,
3055 HTMLWindow_iface_tids,
3056 HTMLWindow_init_dispex_info
3059 static void *alloc_window(size_t size)
3061 HTMLWindow *window;
3063 window = heap_alloc_zero(size);
3064 if(!window)
3065 return NULL;
3067 window->IHTMLWindow2_iface.lpVtbl = &HTMLWindow2Vtbl;
3068 window->IHTMLWindow3_iface.lpVtbl = &HTMLWindow3Vtbl;
3069 window->IHTMLWindow4_iface.lpVtbl = &HTMLWindow4Vtbl;
3070 window->IHTMLWindow5_iface.lpVtbl = &HTMLWindow5Vtbl;
3071 window->IHTMLWindow6_iface.lpVtbl = &HTMLWindow6Vtbl;
3072 window->IHTMLPrivateWindow_iface.lpVtbl = &HTMLPrivateWindowVtbl;
3073 window->IDispatchEx_iface.lpVtbl = &WindowDispExVtbl;
3074 window->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
3075 window->ITravelLogClient_iface.lpVtbl = &TravelLogClientVtbl;
3076 window->IObjectIdentity_iface.lpVtbl = &ObjectIdentityVtbl;
3077 window->IProvideMultipleClassInfo_iface.lpVtbl = &ProvideMultipleClassInfoVtbl;
3078 window->ref = 1;
3080 return window;
3083 static HRESULT create_inner_window(HTMLOuterWindow *outer_window, IMoniker *mon, HTMLInnerWindow **ret)
3085 HTMLInnerWindow *window;
3087 window = alloc_window(sizeof(HTMLInnerWindow));
3088 if(!window)
3089 return E_OUTOFMEMORY;
3091 list_init(&window->script_hosts);
3092 list_init(&window->bindings);
3093 list_init(&window->script_queue);
3095 window->base.outer_window = outer_window;
3096 window->base.inner_window = window;
3098 init_event_target(&window->event_target);
3099 init_dispex(&window->event_target.dispex, (IUnknown*)&window->base.IHTMLWindow2_iface, &HTMLWindow_dispex);
3101 window->task_magic = get_task_target_magic();
3103 if(mon) {
3104 IMoniker_AddRef(mon);
3105 window->mon = mon;
3108 *ret = window;
3109 return S_OK;
3112 HRESULT HTMLOuterWindow_Create(HTMLDocumentObj *doc_obj, nsIDOMWindow *nswindow,
3113 HTMLOuterWindow *parent, HTMLOuterWindow **ret)
3115 HTMLOuterWindow *window;
3116 HRESULT hres;
3118 window = alloc_window(sizeof(HTMLOuterWindow));
3119 if(!window)
3120 return E_OUTOFMEMORY;
3122 window->base.outer_window = window;
3123 window->base.inner_window = NULL;
3125 window->window_ref = heap_alloc(sizeof(windowref_t));
3126 if(!window->window_ref) {
3127 heap_free(window);
3128 return E_OUTOFMEMORY;
3131 window->doc_obj = doc_obj;
3133 window->window_ref->window = window;
3134 window->window_ref->ref = 1;
3136 if(nswindow) {
3137 nsresult nsres;
3139 nsIDOMWindow_AddRef(nswindow);
3140 window->nswindow = nswindow;
3142 nsres = nsIDOMWindow_QueryInterface(nswindow, &IID_mozIDOMWindowProxy, (void**)&window->window_proxy);
3143 assert(nsres == NS_OK);
3146 window->scriptmode = parent ? parent->scriptmode : SCRIPTMODE_GECKO;
3147 window->readystate = READYSTATE_UNINITIALIZED;
3148 window->task_magic = get_task_target_magic();
3150 list_init(&window->children);
3151 wine_rb_put(&window_map, window->window_proxy, &window->entry);
3153 hres = create_pending_window(window, NULL);
3154 if(SUCCEEDED(hres))
3155 hres = update_window_doc(window->pending_window);
3156 if(FAILED(hres)) {
3157 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
3158 return hres;
3161 hres = CoInternetCreateSecurityManager(NULL, &window->secmgr, 0);
3162 if(FAILED(hres)) {
3163 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
3164 return hres;
3167 if(parent) {
3168 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
3170 window->parent = parent;
3171 list_add_tail(&parent->children, &window->sibling_entry);
3174 TRACE("%p inner_window %p\n", window, window->base.inner_window);
3176 *ret = window;
3177 return S_OK;
3180 HRESULT create_pending_window(HTMLOuterWindow *outer_window, nsChannelBSC *channelbsc)
3182 HTMLInnerWindow *pending_window;
3183 HRESULT hres;
3185 hres = create_inner_window(outer_window, outer_window->mon /* FIXME */, &pending_window);
3186 if(FAILED(hres))
3187 return hres;
3189 if(channelbsc) {
3190 IBindStatusCallback_AddRef(&channelbsc->bsc.IBindStatusCallback_iface);
3191 pending_window->bscallback = channelbsc;
3194 if(outer_window->pending_window) {
3195 abort_window_bindings(outer_window->pending_window);
3196 outer_window->pending_window->base.outer_window = NULL;
3197 IHTMLWindow2_Release(&outer_window->pending_window->base.IHTMLWindow2_iface);
3200 outer_window->pending_window = pending_window;
3201 return S_OK;
3204 HRESULT update_window_doc(HTMLInnerWindow *window)
3206 HTMLOuterWindow *outer_window = window->base.outer_window;
3207 nsIDOMHTMLDocument *nshtmldoc;
3208 nsIDOMDocument *nsdoc;
3209 nsresult nsres;
3210 HRESULT hres;
3212 assert(!window->doc);
3214 if(!outer_window) {
3215 ERR("NULL outer window\n");
3216 return E_UNEXPECTED;
3219 nsres = nsIDOMWindow_GetDocument(outer_window->nswindow, &nsdoc);
3220 if(NS_FAILED(nsres) || !nsdoc) {
3221 ERR("GetDocument failed: %08x\n", nsres);
3222 return E_FAIL;
3225 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
3226 nsIDOMDocument_Release(nsdoc);
3227 if(NS_FAILED(nsres)) {
3228 ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres);
3229 return E_FAIL;
3232 hres = create_doc_from_nsdoc(nshtmldoc, outer_window->doc_obj, window, &window->doc);
3233 nsIDOMHTMLDocument_Release(nshtmldoc);
3234 if(FAILED(hres))
3235 return hres;
3237 if(outer_window->doc_obj->usermode == EDITMODE) {
3238 nsAString mode_str;
3239 nsresult nsres;
3241 static const PRUnichar onW[] = {'o','n',0};
3243 nsAString_InitDepend(&mode_str, onW);
3244 nsres = nsIDOMHTMLDocument_SetDesignMode(window->doc->nsdoc, &mode_str);
3245 nsAString_Finish(&mode_str);
3246 if(NS_FAILED(nsres))
3247 ERR("SetDesignMode failed: %08x\n", nsres);
3250 if(window != outer_window->pending_window) {
3251 ERR("not current pending window\n");
3252 return S_OK;
3255 if(outer_window->base.inner_window)
3256 detach_inner_window(outer_window->base.inner_window);
3257 outer_window->base.inner_window = window;
3258 outer_window->pending_window = NULL;
3260 if(outer_window->doc_obj->basedoc.window == outer_window || !outer_window->doc_obj->basedoc.window) {
3261 if(outer_window->doc_obj->basedoc.doc_node)
3262 htmldoc_release(&outer_window->doc_obj->basedoc.doc_node->basedoc);
3263 outer_window->doc_obj->basedoc.doc_node = window->doc;
3264 htmldoc_addref(&window->doc->basedoc);
3267 return hres;