mshtml: Added IHTMLDocument2::get_domain implementation.
[wine/multimedia.git] / dlls / mshtml / htmldoc.c
blob3cbfe8d694adaef2caa13cf83a6fae561ce1d078
1 /*
2 * Copyright 2005-2009 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 "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "wininet.h"
30 #include "ole2.h"
31 #include "perhist.h"
32 #include "mshtmdid.h"
34 #include "wine/debug.h"
36 #include "mshtml_private.h"
37 #include "htmlevent.h"
38 #include "pluginhost.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
42 static inline HTMLDocument *impl_from_IHTMLDocument2(IHTMLDocument2 *iface)
44 return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument2_iface);
47 static HRESULT WINAPI HTMLDocument_QueryInterface(IHTMLDocument2 *iface, REFIID riid, void **ppv)
49 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
51 return htmldoc_query_interface(This, riid, ppv);
54 static ULONG WINAPI HTMLDocument_AddRef(IHTMLDocument2 *iface)
56 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
58 return htmldoc_addref(This);
61 static ULONG WINAPI HTMLDocument_Release(IHTMLDocument2 *iface)
63 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
65 return htmldoc_release(This);
68 static HRESULT WINAPI HTMLDocument_GetTypeInfoCount(IHTMLDocument2 *iface, UINT *pctinfo)
70 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
72 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
75 static HRESULT WINAPI HTMLDocument_GetTypeInfo(IHTMLDocument2 *iface, UINT iTInfo,
76 LCID lcid, ITypeInfo **ppTInfo)
78 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
80 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
83 static HRESULT WINAPI HTMLDocument_GetIDsOfNames(IHTMLDocument2 *iface, REFIID riid,
84 LPOLESTR *rgszNames, UINT cNames,
85 LCID lcid, DISPID *rgDispId)
87 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
89 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
90 rgDispId);
93 static HRESULT WINAPI HTMLDocument_Invoke(IHTMLDocument2 *iface, DISPID dispIdMember,
94 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
95 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
97 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
99 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
100 pDispParams, pVarResult, pExcepInfo, puArgErr);
103 static HRESULT WINAPI HTMLDocument_get_Script(IHTMLDocument2 *iface, IDispatch **p)
105 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
107 TRACE("(%p)->(%p)\n", This, p);
109 *p = (IDispatch*)&This->window->IHTMLWindow2_iface;
110 IDispatch_AddRef(*p);
111 return S_OK;
114 static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
116 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
117 nsIDOMElement *nselem = NULL;
118 HTMLDOMNode *node;
119 nsresult nsres;
120 HRESULT hres;
122 TRACE("(%p)->(%p)\n", This, p);
124 if(!This->doc_node->nsdoc) {
125 WARN("NULL nsdoc\n");
126 return E_UNEXPECTED;
129 nsres = nsIDOMHTMLDocument_GetDocumentElement(This->doc_node->nsdoc, &nselem);
130 if(NS_FAILED(nsres)) {
131 ERR("GetDocumentElement failed: %08x\n", nsres);
132 return E_FAIL;
135 if(!nselem) {
136 *p = NULL;
137 return S_OK;
140 hres = get_node(This->doc_node, (nsIDOMNode*)nselem, TRUE, &node);
141 if(SUCCEEDED(hres))
142 *p = create_all_collection(node, TRUE);
143 nsIDOMElement_Release(nselem);
144 return hres;
147 static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
149 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
150 nsIDOMHTMLElement *nsbody = NULL;
151 HTMLDOMNode *node;
152 HRESULT hres;
154 TRACE("(%p)->(%p)\n", This, p);
156 if(This->doc_node->nsdoc) {
157 nsresult nsres;
159 nsres = nsIDOMHTMLDocument_GetBody(This->doc_node->nsdoc, &nsbody);
160 if(NS_FAILED(nsres)) {
161 TRACE("Could not get body: %08x\n", nsres);
162 return E_UNEXPECTED;
166 if(!nsbody) {
167 *p = NULL;
168 return S_OK;
171 hres = get_node(This->doc_node, (nsIDOMNode*)nsbody, TRUE, &node);
172 nsIDOMHTMLElement_Release(nsbody);
173 if(FAILED(hres))
174 return hres;
176 return IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
179 static HRESULT WINAPI HTMLDocument_get_activeElement(IHTMLDocument2 *iface, IHTMLElement **p)
181 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
182 FIXME("(%p)->(%p)\n", This, p);
183 return E_NOTIMPL;
186 static HRESULT WINAPI HTMLDocument_get_images(IHTMLDocument2 *iface, IHTMLElementCollection **p)
188 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
189 nsIDOMHTMLCollection *nscoll = NULL;
190 nsresult nsres;
192 TRACE("(%p)->(%p)\n", This, p);
194 if(!p)
195 return E_INVALIDARG;
197 *p = NULL;
199 if(!This->doc_node->nsdoc) {
200 WARN("NULL nsdoc\n");
201 return E_UNEXPECTED;
204 nsres = nsIDOMHTMLDocument_GetImages(This->doc_node->nsdoc, &nscoll);
205 if(NS_FAILED(nsres)) {
206 ERR("GetImages failed: %08x\n", nsres);
207 return E_FAIL;
210 if(nscoll) {
211 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)&This->IHTMLDocument2_iface, nscoll);
212 nsIDOMElement_Release(nscoll);
215 return S_OK;
218 static HRESULT WINAPI HTMLDocument_get_applets(IHTMLDocument2 *iface, IHTMLElementCollection **p)
220 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
221 nsIDOMHTMLCollection *nscoll = NULL;
222 nsresult nsres;
224 TRACE("(%p)->(%p)\n", This, p);
226 if(!p)
227 return E_INVALIDARG;
229 *p = NULL;
231 if(!This->doc_node->nsdoc) {
232 WARN("NULL nsdoc\n");
233 return E_UNEXPECTED;
236 nsres = nsIDOMHTMLDocument_GetApplets(This->doc_node->nsdoc, &nscoll);
237 if(NS_FAILED(nsres)) {
238 ERR("GetApplets failed: %08x\n", nsres);
239 return E_FAIL;
242 if(nscoll) {
243 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)&This->IHTMLDocument2_iface, nscoll);
244 nsIDOMElement_Release(nscoll);
247 return S_OK;
250 static HRESULT WINAPI HTMLDocument_get_links(IHTMLDocument2 *iface, IHTMLElementCollection **p)
252 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
253 nsIDOMHTMLCollection *nscoll = NULL;
254 nsresult nsres;
256 TRACE("(%p)->(%p)\n", This, p);
258 if(!p)
259 return E_INVALIDARG;
261 *p = NULL;
263 if(!This->doc_node->nsdoc) {
264 WARN("NULL nsdoc\n");
265 return E_UNEXPECTED;
268 nsres = nsIDOMHTMLDocument_GetLinks(This->doc_node->nsdoc, &nscoll);
269 if(NS_FAILED(nsres)) {
270 ERR("GetLinks failed: %08x\n", nsres);
271 return E_FAIL;
274 if(nscoll) {
275 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)&This->IHTMLDocument2_iface, nscoll);
276 nsIDOMElement_Release(nscoll);
279 return S_OK;
282 static HRESULT WINAPI HTMLDocument_get_forms(IHTMLDocument2 *iface, IHTMLElementCollection **p)
284 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
285 nsIDOMHTMLCollection *nscoll = NULL;
286 nsresult nsres;
288 TRACE("(%p)->(%p)\n", This, p);
290 if(!p)
291 return E_INVALIDARG;
293 *p = NULL;
295 if(!This->doc_node->nsdoc) {
296 WARN("NULL nsdoc\n");
297 return E_UNEXPECTED;
300 nsres = nsIDOMHTMLDocument_GetForms(This->doc_node->nsdoc, &nscoll);
301 if(NS_FAILED(nsres)) {
302 ERR("GetForms failed: %08x\n", nsres);
303 return E_FAIL;
306 if(nscoll) {
307 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)&This->IHTMLDocument2_iface, nscoll);
308 nsIDOMElement_Release(nscoll);
311 return S_OK;
314 static HRESULT WINAPI HTMLDocument_get_anchors(IHTMLDocument2 *iface, IHTMLElementCollection **p)
316 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
317 nsIDOMHTMLCollection *nscoll = NULL;
318 nsresult nsres;
320 TRACE("(%p)->(%p)\n", This, p);
322 if(!p)
323 return E_INVALIDARG;
325 *p = NULL;
327 if(!This->doc_node->nsdoc) {
328 WARN("NULL nsdoc\n");
329 return E_UNEXPECTED;
332 nsres = nsIDOMHTMLDocument_GetAnchors(This->doc_node->nsdoc, &nscoll);
333 if(NS_FAILED(nsres)) {
334 ERR("GetAnchors failed: %08x\n", nsres);
335 return E_FAIL;
338 if(nscoll) {
339 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)&This->IHTMLDocument2_iface, nscoll);
340 nsIDOMElement_Release(nscoll);
343 return S_OK;
346 static HRESULT WINAPI HTMLDocument_put_title(IHTMLDocument2 *iface, BSTR v)
348 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
349 nsAString nsstr;
350 nsresult nsres;
352 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
354 if(!This->doc_node->nsdoc) {
355 WARN("NULL nsdoc\n");
356 return E_UNEXPECTED;
359 nsAString_InitDepend(&nsstr, v);
360 nsres = nsIDOMHTMLDocument_SetTitle(This->doc_node->nsdoc, &nsstr);
361 nsAString_Finish(&nsstr);
362 if(NS_FAILED(nsres))
363 ERR("SetTitle failed: %08x\n", nsres);
365 return S_OK;
368 static HRESULT WINAPI HTMLDocument_get_title(IHTMLDocument2 *iface, BSTR *p)
370 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
371 const PRUnichar *ret;
372 nsAString nsstr;
373 nsresult nsres;
375 TRACE("(%p)->(%p)\n", This, p);
377 if(!This->doc_node->nsdoc) {
378 WARN("NULL nsdoc\n");
379 return E_UNEXPECTED;
383 nsAString_Init(&nsstr, NULL);
384 nsres = nsIDOMHTMLDocument_GetTitle(This->doc_node->nsdoc, &nsstr);
385 if (NS_SUCCEEDED(nsres)) {
386 nsAString_GetData(&nsstr, &ret);
387 *p = SysAllocString(ret);
389 nsAString_Finish(&nsstr);
391 if(NS_FAILED(nsres)) {
392 ERR("GetTitle failed: %08x\n", nsres);
393 return E_FAIL;
396 return S_OK;
399 static HRESULT WINAPI HTMLDocument_get_scripts(IHTMLDocument2 *iface, IHTMLElementCollection **p)
401 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
402 FIXME("(%p)->(%p)\n", This, p);
403 return E_NOTIMPL;
406 static HRESULT WINAPI HTMLDocument_put_designMode(IHTMLDocument2 *iface, BSTR v)
408 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
409 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
410 return E_NOTIMPL;
413 static HRESULT WINAPI HTMLDocument_get_designMode(IHTMLDocument2 *iface, BSTR *p)
415 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
416 static WCHAR szOff[] = {'O','f','f',0};
417 FIXME("(%p)->(%p) always returning Off\n", This, p);
419 if(!p)
420 return E_INVALIDARG;
422 *p = SysAllocString(szOff);
424 return S_OK;
427 static HRESULT WINAPI HTMLDocument_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
429 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
430 nsISelection *nsselection;
431 nsresult nsres;
433 TRACE("(%p)->(%p)\n", This, p);
435 nsres = nsIDOMWindow_GetSelection(This->window->nswindow, &nsselection);
436 if(NS_FAILED(nsres)) {
437 ERR("GetSelection failed: %08x\n", nsres);
438 return E_FAIL;
441 return HTMLSelectionObject_Create(This->doc_node, nsselection, p);
444 static HRESULT WINAPI HTMLDocument_get_readyState(IHTMLDocument2 *iface, BSTR *p)
446 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
448 static const WCHAR wszUninitialized[] = {'u','n','i','n','i','t','i','a','l','i','z','e','d',0};
449 static const WCHAR wszLoading[] = {'l','o','a','d','i','n','g',0};
450 static const WCHAR wszLoaded[] = {'l','o','a','d','e','d',0};
451 static const WCHAR wszInteractive[] = {'i','n','t','e','r','a','c','t','i','v','e',0};
452 static const WCHAR wszComplete[] = {'c','o','m','p','l','e','t','e',0};
454 static const LPCWSTR readystate_str[] = {
455 wszUninitialized,
456 wszLoading,
457 wszLoaded,
458 wszInteractive,
459 wszComplete
462 TRACE("(%p)->(%p)\n", iface, p);
464 if(!p)
465 return E_POINTER;
467 *p = SysAllocString(readystate_str[This->window->readystate]);
468 return S_OK;
471 static HRESULT WINAPI HTMLDocument_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
473 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
475 TRACE("(%p)->(%p)\n", This, p);
477 return IHTMLWindow2_get_frames(&This->window->IHTMLWindow2_iface, p);
480 static HRESULT WINAPI HTMLDocument_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
482 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
483 FIXME("(%p)->(%p)\n", This, p);
484 return E_NOTIMPL;
487 static HRESULT WINAPI HTMLDocument_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
489 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
490 FIXME("(%p)->(%p)\n", This, p);
491 return E_NOTIMPL;
494 static HRESULT WINAPI HTMLDocument_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
496 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
497 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
498 return E_NOTIMPL;
501 static HRESULT WINAPI HTMLDocument_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
503 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
504 FIXME("(%p)->(%p)\n", This, p);
505 return E_NOTIMPL;
508 static HRESULT WINAPI HTMLDocument_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
510 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
511 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
512 return E_NOTIMPL;
515 static HRESULT WINAPI HTMLDocument_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
517 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
518 FIXME("(%p)->(%p)\n", This, p);
519 return E_NOTIMPL;
522 static HRESULT WINAPI HTMLDocument_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
524 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
525 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
526 return E_NOTIMPL;
529 static HRESULT WINAPI HTMLDocument_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
531 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
532 FIXME("(%p)->(%p)\n", This, p);
533 return E_NOTIMPL;
536 static HRESULT WINAPI HTMLDocument_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
538 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
539 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
540 return E_NOTIMPL;
543 static HRESULT WINAPI HTMLDocument_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
545 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
546 FIXME("(%p)->(%p)\n", This, p);
547 return E_NOTIMPL;
550 static HRESULT WINAPI HTMLDocument_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
552 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
553 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
554 return E_NOTIMPL;
557 static HRESULT WINAPI HTMLDocument_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
559 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
560 FIXME("(%p)->(%p)\n", This, p);
561 return E_NOTIMPL;
564 static HRESULT WINAPI HTMLDocument_get_referrer(IHTMLDocument2 *iface, BSTR *p)
566 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
568 FIXME("(%p)->(%p)\n", This, p);
570 *p = NULL;
571 return S_OK;
574 static HRESULT WINAPI HTMLDocument_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
576 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
578 TRACE("(%p)->(%p)\n", This, p);
580 if(!This->doc_node->nsdoc) {
581 WARN("NULL nsdoc\n");
582 return E_UNEXPECTED;
585 return IHTMLWindow2_get_location(&This->window->IHTMLWindow2_iface, p);
588 static HRESULT WINAPI HTMLDocument_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
590 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
591 FIXME("(%p)->(%p)\n", This, p);
592 return E_NOTIMPL;
595 static HRESULT WINAPI HTMLDocument_put_URL(IHTMLDocument2 *iface, BSTR v)
597 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
598 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
599 return E_NOTIMPL;
602 static HRESULT WINAPI HTMLDocument_get_URL(IHTMLDocument2 *iface, BSTR *p)
604 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
606 static const WCHAR about_blank_url[] =
607 {'a','b','o','u','t',':','b','l','a','n','k',0};
609 TRACE("(%p)->(%p)\n", iface, p);
611 *p = SysAllocString(This->window->url ? This->window->url : about_blank_url);
612 return *p ? S_OK : E_OUTOFMEMORY;
615 static HRESULT WINAPI HTMLDocument_put_domain(IHTMLDocument2 *iface, BSTR v)
617 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
618 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
619 return E_NOTIMPL;
622 static HRESULT WINAPI HTMLDocument_get_domain(IHTMLDocument2 *iface, BSTR *p)
624 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
625 HRESULT hres;
627 TRACE("(%p)->(%p)\n", This, p);
629 if(!This->window || !This->window->uri) {
630 FIXME("No current URI\n");
631 return E_FAIL;
634 hres = IUri_GetHost(This->window->uri, p);
635 return FAILED(hres) ? hres : S_OK;
638 static HRESULT WINAPI HTMLDocument_put_cookie(IHTMLDocument2 *iface, BSTR v)
640 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
641 BOOL bret;
643 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
645 bret = InternetSetCookieExW(This->window->url, NULL, v, 0, 0);
646 if(!bret) {
647 FIXME("InternetSetCookieExW failed: %u\n", GetLastError());
648 return HRESULT_FROM_WIN32(GetLastError());
651 return S_OK;
654 static HRESULT WINAPI HTMLDocument_get_cookie(IHTMLDocument2 *iface, BSTR *p)
656 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
657 DWORD size;
658 BOOL bret;
660 TRACE("(%p)->(%p)\n", This, p);
662 size = 0;
663 bret = InternetGetCookieExW(This->window->url, NULL, NULL, &size, 0, NULL);
664 if(!bret) {
665 switch(GetLastError()) {
666 case ERROR_INSUFFICIENT_BUFFER:
667 break;
668 case ERROR_NO_MORE_ITEMS:
669 *p = NULL;
670 return S_OK;
671 default:
672 FIXME("InternetGetCookieExW failed: %u\n", GetLastError());
673 return HRESULT_FROM_WIN32(GetLastError());
677 if(!size) {
678 *p = NULL;
679 return S_OK;
682 *p = SysAllocStringLen(NULL, size-1);
683 if(!*p)
684 return E_OUTOFMEMORY;
686 bret = InternetGetCookieExW(This->window->url, NULL, *p, &size, 0, NULL);
687 if(!bret) {
688 ERR("InternetGetCookieExW failed: %u\n", GetLastError());
689 return E_FAIL;
692 return S_OK;
695 static HRESULT WINAPI HTMLDocument_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
697 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
698 FIXME("(%p)->(%x)\n", This, v);
699 return E_NOTIMPL;
702 static HRESULT WINAPI HTMLDocument_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
704 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
705 FIXME("(%p)->(%p)\n", This, p);
706 return E_NOTIMPL;
709 static HRESULT WINAPI HTMLDocument_put_charset(IHTMLDocument2 *iface, BSTR v)
711 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
712 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
713 return E_NOTIMPL;
716 static HRESULT WINAPI HTMLDocument_get_charset(IHTMLDocument2 *iface, BSTR *p)
718 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
719 FIXME("(%p)->(%p)\n", This, p);
720 return E_NOTIMPL;
723 static HRESULT WINAPI HTMLDocument_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
725 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
726 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
727 return E_NOTIMPL;
730 static HRESULT WINAPI HTMLDocument_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
732 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
733 FIXME("(%p)->(%p)\n", This, p);
734 return E_NOTIMPL;
737 static HRESULT WINAPI HTMLDocument_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
739 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
740 FIXME("(%p)->(%p)\n", This, p);
741 return E_NOTIMPL;
744 static HRESULT WINAPI HTMLDocument_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
746 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
747 FIXME("(%p)->(%p)\n", This, p);
748 return E_NOTIMPL;
751 static HRESULT WINAPI HTMLDocument_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
753 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
754 FIXME("(%p)->(%p)\n", This, p);
755 return E_NOTIMPL;
758 static HRESULT WINAPI HTMLDocument_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
760 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
761 FIXME("(%p)->(%p)\n", This, p);
762 return E_NOTIMPL;
765 static HRESULT WINAPI HTMLDocument_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
767 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
768 FIXME("(%p)->(%p)\n", This, p);
769 return E_NOTIMPL;
772 static HRESULT WINAPI HTMLDocument_get_security(IHTMLDocument2 *iface, BSTR *p)
774 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
775 FIXME("(%p)->(%p)\n", This, p);
776 return E_NOTIMPL;
779 static HRESULT WINAPI HTMLDocument_get_protocol(IHTMLDocument2 *iface, BSTR *p)
781 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
782 FIXME("(%p)->(%p)\n", This, p);
783 return E_NOTIMPL;
786 static HRESULT WINAPI HTMLDocument_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
788 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
789 FIXME("(%p)->(%p)\n", This, p);
790 return E_NOTIMPL;
793 static HRESULT document_write(HTMLDocument *This, SAFEARRAY *psarray, BOOL ln)
795 nsAString nsstr;
796 VARIANT *var;
797 ULONG i, argc;
798 nsresult nsres;
799 HRESULT hres;
801 if(!This->doc_node->nsdoc) {
802 WARN("NULL nsdoc\n");
803 return E_UNEXPECTED;
806 if (!psarray)
807 return S_OK;
809 if(psarray->cDims != 1) {
810 FIXME("cDims=%d\n", psarray->cDims);
811 return E_INVALIDARG;
814 hres = SafeArrayAccessData(psarray, (void**)&var);
815 if(FAILED(hres)) {
816 WARN("SafeArrayAccessData failed: %08x\n", hres);
817 return hres;
820 nsAString_Init(&nsstr, NULL);
822 argc = psarray->rgsabound[0].cElements;
823 for(i=0; i < argc; i++) {
824 if(V_VT(var+i) == VT_BSTR) {
825 nsAString_SetData(&nsstr, V_BSTR(var+i));
826 if(!ln || i != argc-1)
827 nsres = nsIDOMHTMLDocument_Write(This->doc_node->nsdoc, &nsstr, NULL /* FIXME! */);
828 else
829 nsres = nsIDOMHTMLDocument_Writeln(This->doc_node->nsdoc, &nsstr, NULL /* FIXME! */);
830 if(NS_FAILED(nsres))
831 ERR("Write failed: %08x\n", nsres);
832 }else {
833 FIXME("unsupported arg[%d] = %s\n", i, debugstr_variant(var+i));
837 nsAString_Finish(&nsstr);
838 SafeArrayUnaccessData(psarray);
840 return S_OK;
843 static HRESULT WINAPI HTMLDocument_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
845 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
847 TRACE("(%p)->(%p)\n", iface, psarray);
849 return document_write(This, psarray, FALSE);
852 static HRESULT WINAPI HTMLDocument_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
854 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
856 TRACE("(%p)->(%p)\n", This, psarray);
858 return document_write(This, psarray, TRUE);
861 static HRESULT WINAPI HTMLDocument_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
862 VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
864 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
865 nsISupports *tmp;
866 nsresult nsres;
868 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
870 TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_w(url), debugstr_variant(&name),
871 debugstr_variant(&features), debugstr_variant(&replace), pomWindowResult);
873 if(!This->doc_node->nsdoc) {
874 ERR("!nsdoc\n");
875 return E_NOTIMPL;
878 if(!url || strcmpW(url, text_htmlW) || V_VT(&name) != VT_ERROR
879 || V_VT(&features) != VT_ERROR || V_VT(&replace) != VT_ERROR)
880 FIXME("unsupported args\n");
882 nsres = nsIDOMHTMLDocument_Open(This->doc_node->nsdoc, NULL, NULL, NULL, NULL, 0, &tmp);
883 if(NS_FAILED(nsres)) {
884 ERR("Open failed: %08x\n", nsres);
885 return E_FAIL;
888 if(tmp)
889 nsISupports_Release(tmp);
891 *pomWindowResult = (IDispatch*)&This->window->IHTMLWindow2_iface;
892 IHTMLWindow2_AddRef(&This->window->IHTMLWindow2_iface);
893 return S_OK;
896 static HRESULT WINAPI HTMLDocument_close(IHTMLDocument2 *iface)
898 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
899 nsresult nsres;
901 TRACE("(%p)\n", This);
903 if(!This->doc_node->nsdoc) {
904 ERR("!nsdoc\n");
905 return E_NOTIMPL;
908 nsres = nsIDOMHTMLDocument_Close(This->doc_node->nsdoc);
909 if(NS_FAILED(nsres)) {
910 ERR("Close failed: %08x\n", nsres);
911 return E_FAIL;
914 return S_OK;
917 static HRESULT WINAPI HTMLDocument_clear(IHTMLDocument2 *iface)
919 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
920 nsresult nsres;
922 TRACE("(%p)\n", This);
924 nsres = nsIDOMHTMLDocument_Clear(This->doc_node->nsdoc);
925 if(NS_FAILED(nsres)) {
926 ERR("Clear failed: %08x\n", nsres);
927 return E_FAIL;
930 return S_OK;
933 static HRESULT WINAPI HTMLDocument_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
934 VARIANT_BOOL *pfRet)
936 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
937 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
938 return E_NOTIMPL;
941 static HRESULT WINAPI HTMLDocument_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
942 VARIANT_BOOL *pfRet)
944 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
945 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
946 return E_NOTIMPL;
949 static HRESULT WINAPI HTMLDocument_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
950 VARIANT_BOOL *pfRet)
952 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
953 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
954 return E_NOTIMPL;
957 static HRESULT WINAPI HTMLDocument_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
958 VARIANT_BOOL *pfRet)
960 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
961 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
962 return E_NOTIMPL;
965 static HRESULT WINAPI HTMLDocument_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
966 BSTR *pfRet)
968 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
969 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
970 return E_NOTIMPL;
973 static HRESULT WINAPI HTMLDocument_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
974 VARIANT *pfRet)
976 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
977 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
978 return E_NOTIMPL;
981 static HRESULT WINAPI HTMLDocument_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
982 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
984 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
985 FIXME("(%p)->(%s %x %s %p)\n", This, debugstr_w(cmdID), showUI, debugstr_variant(&value), pfRet);
986 return E_NOTIMPL;
989 static HRESULT WINAPI HTMLDocument_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
990 VARIANT_BOOL *pfRet)
992 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
993 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
994 return E_NOTIMPL;
997 static HRESULT WINAPI HTMLDocument_createElement(IHTMLDocument2 *iface, BSTR eTag,
998 IHTMLElement **newElem)
1000 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1001 nsIDOMHTMLElement *nselem;
1002 HTMLElement *elem;
1003 HRESULT hres;
1005 TRACE("(%p)->(%s %p)\n", This, debugstr_w(eTag), newElem);
1007 hres = create_nselem(This->doc_node, eTag, &nselem);
1008 if(FAILED(hres))
1009 return hres;
1011 hres = HTMLElement_Create(This->doc_node, (nsIDOMNode*)nselem, TRUE, &elem);
1012 nsIDOMHTMLElement_Release(nselem);
1013 if(FAILED(hres))
1014 return hres;
1016 *newElem = &elem->IHTMLElement_iface;
1017 IHTMLElement_AddRef(&elem->IHTMLElement_iface);
1018 return S_OK;
1021 static HRESULT WINAPI HTMLDocument_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
1023 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1024 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1025 return E_NOTIMPL;
1028 static HRESULT WINAPI HTMLDocument_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
1030 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1031 FIXME("(%p)->(%p)\n", This, p);
1032 return E_NOTIMPL;
1035 static HRESULT WINAPI HTMLDocument_put_onclick(IHTMLDocument2 *iface, VARIANT v)
1037 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1039 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1041 return set_doc_event(This, EVENTID_CLICK, &v);
1044 static HRESULT WINAPI HTMLDocument_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
1046 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1048 TRACE("(%p)->(%p)\n", This, p);
1050 return get_doc_event(This, EVENTID_CLICK, p);
1053 static HRESULT WINAPI HTMLDocument_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
1055 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1056 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1057 return E_NOTIMPL;
1060 static HRESULT WINAPI HTMLDocument_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
1062 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1063 FIXME("(%p)->(%p)\n", This, p);
1064 return E_NOTIMPL;
1067 static HRESULT WINAPI HTMLDocument_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
1069 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1071 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1073 return set_doc_event(This, EVENTID_KEYUP, &v);
1076 static HRESULT WINAPI HTMLDocument_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
1078 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1080 TRACE("(%p)->(%p)\n", This, p);
1082 return get_doc_event(This, EVENTID_KEYUP, p);
1085 static HRESULT WINAPI HTMLDocument_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
1087 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1089 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1091 return set_doc_event(This, EVENTID_KEYDOWN, &v);
1094 static HRESULT WINAPI HTMLDocument_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
1096 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1098 TRACE("(%p)->(%p)\n", This, p);
1100 return get_doc_event(This, EVENTID_KEYDOWN, p);
1103 static HRESULT WINAPI HTMLDocument_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
1105 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1106 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1107 return E_NOTIMPL;
1110 static HRESULT WINAPI HTMLDocument_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
1112 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1113 FIXME("(%p)->(%p)\n", This, p);
1114 return E_NOTIMPL;
1117 static HRESULT WINAPI HTMLDocument_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
1119 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1121 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1123 return set_doc_event(This, EVENTID_MOUSEUP, &v);
1126 static HRESULT WINAPI HTMLDocument_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
1128 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1130 TRACE("(%p)->(%p)\n", This, p);
1132 return get_doc_event(This, EVENTID_MOUSEUP, p);
1135 static HRESULT WINAPI HTMLDocument_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
1137 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1139 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1141 return set_doc_event(This, EVENTID_MOUSEDOWN, &v);
1144 static HRESULT WINAPI HTMLDocument_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
1146 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1148 TRACE("(%p)->(%p)\n", This, p);
1150 return get_doc_event(This, EVENTID_MOUSEDOWN, p);
1153 static HRESULT WINAPI HTMLDocument_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
1155 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1157 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1159 return set_doc_event(This, EVENTID_MOUSEMOVE, &v);
1162 static HRESULT WINAPI HTMLDocument_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
1164 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1166 TRACE("(%p)->(%p)\n", This, p);
1168 return get_doc_event(This, EVENTID_MOUSEMOVE, p);
1171 static HRESULT WINAPI HTMLDocument_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
1173 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1175 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1177 return set_doc_event(This, EVENTID_MOUSEOUT, &v);
1180 static HRESULT WINAPI HTMLDocument_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
1182 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1184 TRACE("(%p)->(%p)\n", This, p);
1186 return get_doc_event(This, EVENTID_MOUSEOUT, p);
1189 static HRESULT WINAPI HTMLDocument_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
1191 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1193 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1195 return set_doc_event(This, EVENTID_MOUSEOVER, &v);
1198 static HRESULT WINAPI HTMLDocument_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
1200 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1202 TRACE("(%p)->(%p)\n", This, p);
1204 return get_doc_event(This, EVENTID_MOUSEOVER, p);
1207 static HRESULT WINAPI HTMLDocument_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
1209 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1211 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1213 return set_doc_event(This, EVENTID_READYSTATECHANGE, &v);
1216 static HRESULT WINAPI HTMLDocument_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
1218 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1220 TRACE("(%p)->(%p)\n", This, p);
1222 return get_doc_event(This, EVENTID_READYSTATECHANGE, p);
1225 static HRESULT WINAPI HTMLDocument_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
1227 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1228 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1229 return E_NOTIMPL;
1232 static HRESULT WINAPI HTMLDocument_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
1234 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1235 FIXME("(%p)->(%p)\n", This, p);
1236 return E_NOTIMPL;
1239 static HRESULT WINAPI HTMLDocument_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
1241 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1242 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1243 return E_NOTIMPL;
1246 static HRESULT WINAPI HTMLDocument_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
1248 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1249 FIXME("(%p)->(%p)\n", This, p);
1250 return E_NOTIMPL;
1253 static HRESULT WINAPI HTMLDocument_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
1255 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1256 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1257 return E_NOTIMPL;
1260 static HRESULT WINAPI HTMLDocument_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
1262 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1263 FIXME("(%p)->(%p)\n", This, p);
1264 return E_NOTIMPL;
1267 static HRESULT WINAPI HTMLDocument_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
1269 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1271 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1273 return set_doc_event(This, EVENTID_DRAGSTART, &v);
1276 static HRESULT WINAPI HTMLDocument_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
1278 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1280 TRACE("(%p)->(%p)\n", This, p);
1282 return get_doc_event(This, EVENTID_DRAGSTART, p);
1285 static HRESULT WINAPI HTMLDocument_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
1287 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1289 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1291 return set_doc_event(This, EVENTID_SELECTSTART, &v);
1294 static HRESULT WINAPI HTMLDocument_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
1296 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1298 TRACE("(%p)->(%p)\n", This, p);
1300 return get_doc_event(This, EVENTID_SELECTSTART, p);
1303 static HRESULT WINAPI HTMLDocument_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
1304 IHTMLElement **elementHit)
1306 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1307 nsIDOMElement *nselem;
1308 HTMLDOMNode *node;
1309 nsresult nsres;
1310 HRESULT hres;
1312 TRACE("(%p)->(%d %d %p)\n", This, x, y, elementHit);
1314 nsres = nsIDOMHTMLDocument_ElementFromPoint(This->doc_node->nsdoc, x, y, &nselem);
1315 if(NS_FAILED(nsres)) {
1316 ERR("ElementFromPoint failed: %08x\n", nsres);
1317 return E_FAIL;
1320 if(!nselem) {
1321 *elementHit = NULL;
1322 return S_OK;
1325 hres = get_node(This->doc_node, (nsIDOMNode*)nselem, TRUE, &node);
1326 nsIDOMElement_Release(nselem);
1327 if(FAILED(hres))
1328 return hres;
1330 return IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)elementHit);
1333 static HRESULT WINAPI HTMLDocument_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
1335 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1337 TRACE("(%p)->(%p)\n", This, p);
1339 *p = &This->window->IHTMLWindow2_iface;
1340 IHTMLWindow2_AddRef(*p);
1341 return S_OK;
1344 static HRESULT WINAPI HTMLDocument_get_styleSheets(IHTMLDocument2 *iface,
1345 IHTMLStyleSheetsCollection **p)
1347 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1348 nsIDOMStyleSheetList *nsstylelist;
1349 nsresult nsres;
1351 TRACE("(%p)->(%p)\n", This, p);
1353 *p = NULL;
1355 if(!This->doc_node->nsdoc) {
1356 WARN("NULL nsdoc\n");
1357 return E_UNEXPECTED;
1360 nsres = nsIDOMHTMLDocument_GetStyleSheets(This->doc_node->nsdoc, &nsstylelist);
1361 if(NS_FAILED(nsres)) {
1362 ERR("GetStyleSheets failed: %08x\n", nsres);
1363 return E_FAIL;
1366 *p = HTMLStyleSheetsCollection_Create(nsstylelist);
1367 nsIDOMStyleSheetList_Release(nsstylelist);
1369 return S_OK;
1372 static HRESULT WINAPI HTMLDocument_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
1374 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1375 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1376 return E_NOTIMPL;
1379 static HRESULT WINAPI HTMLDocument_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
1381 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1382 FIXME("(%p)->(%p)\n", This, p);
1383 return E_NOTIMPL;
1386 static HRESULT WINAPI HTMLDocument_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1388 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1389 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1390 return E_NOTIMPL;
1393 static HRESULT WINAPI HTMLDocument_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1395 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1396 FIXME("(%p)->(%p)\n", This, p);
1397 return E_NOTIMPL;
1400 static HRESULT WINAPI HTMLDocument_toString(IHTMLDocument2 *iface, BSTR *String)
1402 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1403 FIXME("(%p)->(%p)\n", This, String);
1404 return E_NOTIMPL;
1407 static HRESULT WINAPI HTMLDocument_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1408 LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1410 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1412 FIXME("(%p)->(%s %d %p) semi-stub\n", This, debugstr_w(bstrHref), lIndex, ppnewStyleSheet);
1414 *ppnewStyleSheet = HTMLStyleSheet_Create(NULL);
1415 return S_OK;
1418 static const IHTMLDocument2Vtbl HTMLDocumentVtbl = {
1419 HTMLDocument_QueryInterface,
1420 HTMLDocument_AddRef,
1421 HTMLDocument_Release,
1422 HTMLDocument_GetTypeInfoCount,
1423 HTMLDocument_GetTypeInfo,
1424 HTMLDocument_GetIDsOfNames,
1425 HTMLDocument_Invoke,
1426 HTMLDocument_get_Script,
1427 HTMLDocument_get_all,
1428 HTMLDocument_get_body,
1429 HTMLDocument_get_activeElement,
1430 HTMLDocument_get_images,
1431 HTMLDocument_get_applets,
1432 HTMLDocument_get_links,
1433 HTMLDocument_get_forms,
1434 HTMLDocument_get_anchors,
1435 HTMLDocument_put_title,
1436 HTMLDocument_get_title,
1437 HTMLDocument_get_scripts,
1438 HTMLDocument_put_designMode,
1439 HTMLDocument_get_designMode,
1440 HTMLDocument_get_selection,
1441 HTMLDocument_get_readyState,
1442 HTMLDocument_get_frames,
1443 HTMLDocument_get_embeds,
1444 HTMLDocument_get_plugins,
1445 HTMLDocument_put_alinkColor,
1446 HTMLDocument_get_alinkColor,
1447 HTMLDocument_put_bgColor,
1448 HTMLDocument_get_bgColor,
1449 HTMLDocument_put_fgColor,
1450 HTMLDocument_get_fgColor,
1451 HTMLDocument_put_linkColor,
1452 HTMLDocument_get_linkColor,
1453 HTMLDocument_put_vlinkColor,
1454 HTMLDocument_get_vlinkColor,
1455 HTMLDocument_get_referrer,
1456 HTMLDocument_get_location,
1457 HTMLDocument_get_lastModified,
1458 HTMLDocument_put_URL,
1459 HTMLDocument_get_URL,
1460 HTMLDocument_put_domain,
1461 HTMLDocument_get_domain,
1462 HTMLDocument_put_cookie,
1463 HTMLDocument_get_cookie,
1464 HTMLDocument_put_expando,
1465 HTMLDocument_get_expando,
1466 HTMLDocument_put_charset,
1467 HTMLDocument_get_charset,
1468 HTMLDocument_put_defaultCharset,
1469 HTMLDocument_get_defaultCharset,
1470 HTMLDocument_get_mimeType,
1471 HTMLDocument_get_fileSize,
1472 HTMLDocument_get_fileCreatedDate,
1473 HTMLDocument_get_fileModifiedDate,
1474 HTMLDocument_get_fileUpdatedDate,
1475 HTMLDocument_get_security,
1476 HTMLDocument_get_protocol,
1477 HTMLDocument_get_nameProp,
1478 HTMLDocument_write,
1479 HTMLDocument_writeln,
1480 HTMLDocument_open,
1481 HTMLDocument_close,
1482 HTMLDocument_clear,
1483 HTMLDocument_queryCommandSupported,
1484 HTMLDocument_queryCommandEnabled,
1485 HTMLDocument_queryCommandState,
1486 HTMLDocument_queryCommandIndeterm,
1487 HTMLDocument_queryCommandText,
1488 HTMLDocument_queryCommandValue,
1489 HTMLDocument_execCommand,
1490 HTMLDocument_execCommandShowHelp,
1491 HTMLDocument_createElement,
1492 HTMLDocument_put_onhelp,
1493 HTMLDocument_get_onhelp,
1494 HTMLDocument_put_onclick,
1495 HTMLDocument_get_onclick,
1496 HTMLDocument_put_ondblclick,
1497 HTMLDocument_get_ondblclick,
1498 HTMLDocument_put_onkeyup,
1499 HTMLDocument_get_onkeyup,
1500 HTMLDocument_put_onkeydown,
1501 HTMLDocument_get_onkeydown,
1502 HTMLDocument_put_onkeypress,
1503 HTMLDocument_get_onkeypress,
1504 HTMLDocument_put_onmouseup,
1505 HTMLDocument_get_onmouseup,
1506 HTMLDocument_put_onmousedown,
1507 HTMLDocument_get_onmousedown,
1508 HTMLDocument_put_onmousemove,
1509 HTMLDocument_get_onmousemove,
1510 HTMLDocument_put_onmouseout,
1511 HTMLDocument_get_onmouseout,
1512 HTMLDocument_put_onmouseover,
1513 HTMLDocument_get_onmouseover,
1514 HTMLDocument_put_onreadystatechange,
1515 HTMLDocument_get_onreadystatechange,
1516 HTMLDocument_put_onafterupdate,
1517 HTMLDocument_get_onafterupdate,
1518 HTMLDocument_put_onrowexit,
1519 HTMLDocument_get_onrowexit,
1520 HTMLDocument_put_onrowenter,
1521 HTMLDocument_get_onrowenter,
1522 HTMLDocument_put_ondragstart,
1523 HTMLDocument_get_ondragstart,
1524 HTMLDocument_put_onselectstart,
1525 HTMLDocument_get_onselectstart,
1526 HTMLDocument_elementFromPoint,
1527 HTMLDocument_get_parentWindow,
1528 HTMLDocument_get_styleSheets,
1529 HTMLDocument_put_onbeforeupdate,
1530 HTMLDocument_get_onbeforeupdate,
1531 HTMLDocument_put_onerrorupdate,
1532 HTMLDocument_get_onerrorupdate,
1533 HTMLDocument_toString,
1534 HTMLDocument_createStyleSheet
1537 static void HTMLDocument_on_advise(IUnknown *iface, cp_static_data_t *cp)
1539 HTMLDocument *This = impl_from_IHTMLDocument2((IHTMLDocument2*)iface);
1541 if(This->window)
1542 update_cp_events(This->window, &This->doc_node->node.event_target, cp, This->doc_node->node.nsnode);
1545 static inline HTMLDocument *impl_from_ISupportErrorInfo(ISupportErrorInfo *iface)
1547 return CONTAINING_RECORD(iface, HTMLDocument, ISupportErrorInfo_iface);
1550 static HRESULT WINAPI SupportErrorInfo_QueryInterface(ISupportErrorInfo *iface, REFIID riid, void **ppv)
1552 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1553 return htmldoc_query_interface(This, riid, ppv);
1556 static ULONG WINAPI SupportErrorInfo_AddRef(ISupportErrorInfo *iface)
1558 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1559 return htmldoc_addref(This);
1562 static ULONG WINAPI SupportErrorInfo_Release(ISupportErrorInfo *iface)
1564 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1565 return htmldoc_release(This);
1568 static HRESULT WINAPI SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo *iface, REFIID riid)
1570 FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
1571 return S_FALSE;
1574 static const ISupportErrorInfoVtbl SupportErrorInfoVtbl = {
1575 SupportErrorInfo_QueryInterface,
1576 SupportErrorInfo_AddRef,
1577 SupportErrorInfo_Release,
1578 SupportErrorInfo_InterfaceSupportsErrorInfo
1581 static inline HTMLDocument *impl_from_IDispatchEx(IDispatchEx *iface)
1583 return CONTAINING_RECORD(iface, HTMLDocument, IDispatchEx_iface);
1586 static HRESULT dispid_from_elem_name(HTMLDocumentNode *This, BSTR name, DISPID *dispid)
1588 nsIDOMNodeList *node_list;
1589 nsAString name_str;
1590 PRUint32 len;
1591 unsigned i;
1592 nsresult nsres;
1594 if(!This->nsdoc)
1595 return DISP_E_UNKNOWNNAME;
1597 nsAString_InitDepend(&name_str, name);
1598 nsres = nsIDOMHTMLDocument_GetElementsByName(This->nsdoc, &name_str, &node_list);
1599 nsAString_Finish(&name_str);
1600 if(NS_FAILED(nsres))
1601 return E_FAIL;
1603 nsres = nsIDOMNodeList_GetLength(node_list, &len);
1604 nsIDOMNodeList_Release(node_list);
1605 if(NS_FAILED(nsres))
1606 return E_FAIL;
1608 if(!len)
1609 return DISP_E_UNKNOWNNAME;
1611 for(i=0; i < This->elem_vars_cnt; i++) {
1612 if(!strcmpW(name, This->elem_vars[i])) {
1613 *dispid = MSHTML_DISPID_CUSTOM_MIN+i;
1614 return S_OK;
1618 if(This->elem_vars_cnt == This->elem_vars_size) {
1619 WCHAR **new_vars;
1621 if(This->elem_vars_size) {
1622 new_vars = heap_realloc(This->elem_vars, This->elem_vars_size*2*sizeof(WCHAR*));
1623 if(!new_vars)
1624 return E_OUTOFMEMORY;
1625 This->elem_vars_size *= 2;
1626 }else {
1627 new_vars = heap_alloc(16*sizeof(WCHAR*));
1628 if(!new_vars)
1629 return E_OUTOFMEMORY;
1630 This->elem_vars_size = 16;
1633 This->elem_vars = new_vars;
1636 This->elem_vars[This->elem_vars_cnt] = heap_strdupW(name);
1637 if(!This->elem_vars[This->elem_vars_cnt])
1638 return E_OUTOFMEMORY;
1640 *dispid = MSHTML_DISPID_CUSTOM_MIN+This->elem_vars_cnt++;
1641 return S_OK;
1644 static HRESULT WINAPI DocDispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1646 HTMLDocument *This = impl_from_IDispatchEx(iface);
1648 return htmldoc_query_interface(This, riid, ppv);
1651 static ULONG WINAPI DocDispatchEx_AddRef(IDispatchEx *iface)
1653 HTMLDocument *This = impl_from_IDispatchEx(iface);
1655 return htmldoc_addref(This);
1658 static ULONG WINAPI DocDispatchEx_Release(IDispatchEx *iface)
1660 HTMLDocument *This = impl_from_IDispatchEx(iface);
1662 return htmldoc_release(This);
1665 static HRESULT WINAPI DocDispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1667 HTMLDocument *This = impl_from_IDispatchEx(iface);
1669 return IDispatchEx_GetTypeInfoCount(This->dispex, pctinfo);
1672 static HRESULT WINAPI DocDispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1673 LCID lcid, ITypeInfo **ppTInfo)
1675 HTMLDocument *This = impl_from_IDispatchEx(iface);
1677 return IDispatchEx_GetTypeInfo(This->dispex, iTInfo, lcid, ppTInfo);
1680 static HRESULT WINAPI DocDispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1681 LPOLESTR *rgszNames, UINT cNames,
1682 LCID lcid, DISPID *rgDispId)
1684 HTMLDocument *This = impl_from_IDispatchEx(iface);
1686 return IDispatchEx_GetIDsOfNames(This->dispex, riid, rgszNames, cNames, lcid, rgDispId);
1689 static HRESULT WINAPI DocDispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1690 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1691 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1693 HTMLDocument *This = impl_from_IDispatchEx(iface);
1695 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1696 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1698 switch(dispIdMember) {
1699 case DISPID_READYSTATE:
1700 TRACE("DISPID_READYSTATE\n");
1702 if(!(wFlags & DISPATCH_PROPERTYGET))
1703 return E_INVALIDARG;
1705 V_VT(pVarResult) = VT_I4;
1706 V_I4(pVarResult) = This->window->readystate;
1707 return S_OK;
1710 return IDispatchEx_Invoke(This->dispex, dispIdMember, riid, lcid, wFlags, pDispParams,
1711 pVarResult, pExcepInfo, puArgErr);
1714 static HRESULT WINAPI DocDispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1716 HTMLDocument *This = impl_from_IDispatchEx(iface);
1717 HRESULT hres;
1719 hres = IDispatchEx_GetDispID(This->dispex, bstrName, grfdex, pid);
1720 if(hres != DISP_E_UNKNOWNNAME)
1721 return hres;
1723 return dispid_from_elem_name(This->doc_node, bstrName, pid);
1726 static HRESULT WINAPI DocDispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1727 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1729 HTMLDocument *This = impl_from_IDispatchEx(iface);
1731 if(This->window && id == DISPID_IHTMLDOCUMENT2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT))
1732 return IDispatchEx_InvokeEx(&This->window->IDispatchEx_iface, DISPID_IHTMLWINDOW2_LOCATION,
1733 lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1736 return IDispatchEx_InvokeEx(This->dispex, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1739 static HRESULT WINAPI DocDispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1741 HTMLDocument *This = impl_from_IDispatchEx(iface);
1743 return IDispatchEx_DeleteMemberByName(This->dispex, bstrName, grfdex);
1746 static HRESULT WINAPI DocDispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1748 HTMLDocument *This = impl_from_IDispatchEx(iface);
1750 return IDispatchEx_DeleteMemberByDispID(This->dispex, id);
1753 static HRESULT WINAPI DocDispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
1755 HTMLDocument *This = impl_from_IDispatchEx(iface);
1757 return IDispatchEx_GetMemberProperties(This->dispex, id, grfdexFetch, pgrfdex);
1760 static HRESULT WINAPI DocDispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
1762 HTMLDocument *This = impl_from_IDispatchEx(iface);
1764 return IDispatchEx_GetMemberName(This->dispex, id, pbstrName);
1767 static HRESULT WINAPI DocDispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
1769 HTMLDocument *This = impl_from_IDispatchEx(iface);
1771 return IDispatchEx_GetNextDispID(This->dispex, grfdex, id, pid);
1774 static HRESULT WINAPI DocDispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
1776 HTMLDocument *This = impl_from_IDispatchEx(iface);
1778 return IDispatchEx_GetNameSpaceParent(This->dispex, ppunk);
1781 static const IDispatchExVtbl DocDispatchExVtbl = {
1782 DocDispatchEx_QueryInterface,
1783 DocDispatchEx_AddRef,
1784 DocDispatchEx_Release,
1785 DocDispatchEx_GetTypeInfoCount,
1786 DocDispatchEx_GetTypeInfo,
1787 DocDispatchEx_GetIDsOfNames,
1788 DocDispatchEx_Invoke,
1789 DocDispatchEx_GetDispID,
1790 DocDispatchEx_InvokeEx,
1791 DocDispatchEx_DeleteMemberByName,
1792 DocDispatchEx_DeleteMemberByDispID,
1793 DocDispatchEx_GetMemberProperties,
1794 DocDispatchEx_GetMemberName,
1795 DocDispatchEx_GetNextDispID,
1796 DocDispatchEx_GetNameSpaceParent
1799 static inline HTMLDocument *impl_from_IProvideClassInfo(IProvideClassInfo *iface)
1801 return CONTAINING_RECORD(iface, HTMLDocument, IProvideClassInfo_iface);
1804 static HRESULT WINAPI ProvideClassInfo_QueryInterface(IProvideClassInfo *iface,
1805 REFIID riid, void **ppv)
1807 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1808 return htmldoc_query_interface(This, riid, ppv);
1811 static ULONG WINAPI ProvideClassInfo_AddRef(IProvideClassInfo *iface)
1813 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1814 return htmldoc_addref(This);
1817 static ULONG WINAPI ProvideClassInfo_Release(IProvideClassInfo *iface)
1819 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1820 return htmldoc_release(This);
1823 static HRESULT WINAPI ProvideClassInfo_GetClassInfo(IProvideClassInfo* iface,
1824 ITypeInfo **ppTI)
1826 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1827 TRACE("(%p)->(%p)\n", This, ppTI);
1828 return get_htmldoc_classinfo(ppTI);
1831 static const IProvideClassInfoVtbl ProvideClassInfoVtbl = {
1832 ProvideClassInfo_QueryInterface,
1833 ProvideClassInfo_AddRef,
1834 ProvideClassInfo_Release,
1835 ProvideClassInfo_GetClassInfo
1838 static BOOL htmldoc_qi(HTMLDocument *This, REFIID riid, void **ppv)
1840 *ppv = NULL;
1842 if(IsEqualGUID(&IID_IUnknown, riid)) {
1843 TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppv);
1844 *ppv = &This->IHTMLDocument2_iface;
1845 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1846 TRACE("(%p)->(IID_IDispatch, %p)\n", This, ppv);
1847 *ppv = &This->IDispatchEx_iface;
1848 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1849 TRACE("(%p)->(IID_IDispatchEx, %p)\n", This, ppv);
1850 *ppv = &This->IDispatchEx_iface;
1851 }else if(IsEqualGUID(&IID_IHTMLDocument, riid)) {
1852 TRACE("(%p)->(IID_IHTMLDocument, %p)\n", This, ppv);
1853 *ppv = &This->IHTMLDocument2_iface;
1854 }else if(IsEqualGUID(&IID_IHTMLDocument2, riid)) {
1855 TRACE("(%p)->(IID_IHTMLDocument2, %p)\n", This, ppv);
1856 *ppv = &This->IHTMLDocument2_iface;
1857 }else if(IsEqualGUID(&IID_IHTMLDocument3, riid)) {
1858 TRACE("(%p)->(IID_IHTMLDocument3, %p)\n", This, ppv);
1859 *ppv = &This->IHTMLDocument3_iface;
1860 }else if(IsEqualGUID(&IID_IHTMLDocument4, riid)) {
1861 TRACE("(%p)->(IID_IHTMLDocument4, %p)\n", This, ppv);
1862 *ppv = &This->IHTMLDocument4_iface;
1863 }else if(IsEqualGUID(&IID_IHTMLDocument5, riid)) {
1864 TRACE("(%p)->(IID_IHTMLDocument5, %p)\n", This, ppv);
1865 *ppv = &This->IHTMLDocument5_iface;
1866 }else if(IsEqualGUID(&IID_IHTMLDocument6, riid)) {
1867 TRACE("(%p)->(IID_IHTMLDocument6, %p)\n", This, ppv);
1868 *ppv = &This->IHTMLDocument6_iface;
1869 }else if(IsEqualGUID(&IID_IPersist, riid)) {
1870 TRACE("(%p)->(IID_IPersist, %p)\n", This, ppv);
1871 *ppv = &This->IPersistFile_iface;
1872 }else if(IsEqualGUID(&IID_IPersistMoniker, riid)) {
1873 TRACE("(%p)->(IID_IPersistMoniker, %p)\n", This, ppv);
1874 *ppv = &This->IPersistMoniker_iface;
1875 }else if(IsEqualGUID(&IID_IPersistFile, riid)) {
1876 TRACE("(%p)->(IID_IPersistFile, %p)\n", This, ppv);
1877 *ppv = &This->IPersistFile_iface;
1878 }else if(IsEqualGUID(&IID_IMonikerProp, riid)) {
1879 TRACE("(%p)->(IID_IMonikerProp, %p)\n", This, ppv);
1880 *ppv = &This->IMonikerProp_iface;
1881 }else if(IsEqualGUID(&IID_IOleObject, riid)) {
1882 TRACE("(%p)->(IID_IOleObject, %p)\n", This, ppv);
1883 *ppv = &This->IOleObject_iface;
1884 }else if(IsEqualGUID(&IID_IOleDocument, riid)) {
1885 TRACE("(%p)->(IID_IOleDocument, %p)\n", This, ppv);
1886 *ppv = &This->IOleDocument_iface;
1887 }else if(IsEqualGUID(&IID_IOleDocumentView, riid)) {
1888 TRACE("(%p)->(IID_IOleDocumentView, %p)\n", This, ppv);
1889 *ppv = &This->IOleDocumentView_iface;
1890 }else if(IsEqualGUID(&IID_IOleInPlaceActiveObject, riid)) {
1891 TRACE("(%p)->(IID_IOleInPlaceActiveObject, %p)\n", This, ppv);
1892 *ppv = &This->IOleInPlaceActiveObject_iface;
1893 }else if(IsEqualGUID(&IID_IViewObject, riid)) {
1894 TRACE("(%p)->(IID_IViewObject, %p)\n", This, ppv);
1895 *ppv = &This->IViewObjectEx_iface;
1896 }else if(IsEqualGUID(&IID_IViewObject2, riid)) {
1897 TRACE("(%p)->(IID_IViewObject2, %p)\n", This, ppv);
1898 *ppv = &This->IViewObjectEx_iface;
1899 }else if(IsEqualGUID(&IID_IViewObjectEx, riid)) {
1900 TRACE("(%p)->(IID_IViewObjectEx, %p)\n", This, ppv);
1901 *ppv = &This->IViewObjectEx_iface;
1902 }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
1903 TRACE("(%p)->(IID_IOleWindow, %p)\n", This, ppv);
1904 *ppv = &This->IOleInPlaceActiveObject_iface;
1905 }else if(IsEqualGUID(&IID_IOleInPlaceObject, riid)) {
1906 TRACE("(%p)->(IID_IOleInPlaceObject, %p)\n", This, ppv);
1907 *ppv = &This->IOleInPlaceObjectWindowless_iface;
1908 }else if(IsEqualGUID(&IID_IOleInPlaceObjectWindowless, riid)) {
1909 TRACE("(%p)->(IID_IOleInPlaceObjectWindowless, %p)\n", This, ppv);
1910 *ppv = &This->IOleInPlaceObjectWindowless_iface;
1911 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
1912 TRACE("(%p)->(IID_IServiceProvider, %p)\n", This, ppv);
1913 *ppv = &This->IServiceProvider_iface;
1914 }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
1915 TRACE("(%p)->(IID_IOleCommandTarget, %p)\n", This, ppv);
1916 *ppv = &This->IOleCommandTarget_iface;
1917 }else if(IsEqualGUID(&IID_IOleControl, riid)) {
1918 TRACE("(%p)->(IID_IOleControl, %p)\n", This, ppv);
1919 *ppv = &This->IOleControl_iface;
1920 }else if(IsEqualGUID(&IID_IHlinkTarget, riid)) {
1921 TRACE("(%p)->(IID_IHlinkTarget, %p)\n", This, ppv);
1922 *ppv = &This->IHlinkTarget_iface;
1923 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1924 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1925 *ppv = &This->cp_container.IConnectionPointContainer_iface;
1926 }else if(IsEqualGUID(&IID_IPersistStreamInit, riid)) {
1927 TRACE("(%p)->(IID_IPersistStreamInit %p)\n", This, ppv);
1928 *ppv = &This->IPersistStreamInit_iface;
1929 }else if(IsEqualGUID(&DIID_DispHTMLDocument, riid)) {
1930 TRACE("(%p)->(DIID_DispHTMLDocument %p)\n", This, ppv);
1931 *ppv = &This->IHTMLDocument2_iface;
1932 }else if(IsEqualGUID(&IID_ISupportErrorInfo, riid)) {
1933 TRACE("(%p)->(IID_ISupportErrorInfo %p)\n", This, ppv);
1934 *ppv = &This->ISupportErrorInfo_iface;
1935 }else if(IsEqualGUID(&IID_IPersistHistory, riid)) {
1936 TRACE("(%p)->(IID_IPersistHistory %p)\n", This, ppv);
1937 *ppv = &This->IPersistHistory_iface;
1938 }else if(IsEqualGUID(&CLSID_CMarkup, riid)) {
1939 FIXME("(%p)->(CLSID_CMarkup %p)\n", This, ppv);
1940 *ppv = NULL;
1941 }else if(IsEqualGUID(&IID_IRunnableObject, riid)) {
1942 TRACE("(%p)->(IID_IRunnableObject %p) returning NULL\n", This, ppv);
1943 *ppv = NULL;
1944 }else if(IsEqualGUID(&IID_IPersistPropertyBag, riid)) {
1945 TRACE("(%p)->(IID_IPersistPropertyBag %p) returning NULL\n", This, ppv);
1946 *ppv = NULL;
1947 }else if(IsEqualGUID(&IID_IMarshal, riid)) {
1948 TRACE("(%p)->(IID_IMarshal %p) returning NULL\n", This, ppv);
1949 *ppv = NULL;
1950 }else if(IsEqualGUID(&IID_IExternalConnection, riid)) {
1951 TRACE("(%p)->(IID_IExternalConnection %p) returning NULL\n", This, ppv);
1952 *ppv = NULL;
1953 }else if(IsEqualGUID(&IID_IStdMarshalInfo, riid)) {
1954 TRACE("(%p)->(IID_IStdMarshalInfo %p) returning NULL\n", This, ppv);
1955 *ppv = NULL;
1956 }else if(IsEqualGUID(&IID_IObjectWithSite, riid)) {
1957 TRACE("(%p)->(IID_IObjectWithSite %p)\n", This, ppv);
1958 *ppv = &This->IObjectWithSite_iface;
1959 }else if(IsEqualGUID(&IID_IOleContainer, riid)) {
1960 TRACE("(%p)->(IID_IOleContainer %p)\n", This, ppv);
1961 *ppv = &This->IOleContainer_iface;
1962 }else if(IsEqualGUID(&IID_IObjectSafety, riid)) {
1963 TRACE("(%p)->(IID_IObjectSafety %p)\n", This, ppv);
1964 *ppv = &This->IObjectSafety_iface;
1965 }else if(IsEqualGUID(&IID_IProvideClassInfo, riid)) {
1966 TRACE("(%p)->(IID_IProvideClassInfo, %p)\n", This, ppv);
1967 *ppv = &This->IProvideClassInfo_iface;
1968 }else {
1969 return FALSE;
1972 if(*ppv)
1973 IUnknown_AddRef((IUnknown*)*ppv);
1974 return TRUE;
1977 static cp_static_data_t HTMLDocumentEvents_data = { HTMLDocumentEvents_tid, HTMLDocument_on_advise };
1979 static void init_doc(HTMLDocument *doc, IUnknown *unk_impl, IDispatchEx *dispex)
1981 doc->IHTMLDocument2_iface.lpVtbl = &HTMLDocumentVtbl;
1982 doc->IDispatchEx_iface.lpVtbl = &DocDispatchExVtbl;
1983 doc->ISupportErrorInfo_iface.lpVtbl = &SupportErrorInfoVtbl;
1984 doc->IProvideClassInfo_iface.lpVtbl = &ProvideClassInfoVtbl;
1986 doc->unk_impl = unk_impl;
1987 doc->dispex = dispex;
1988 doc->task_magic = get_task_target_magic();
1990 HTMLDocument_HTMLDocument3_Init(doc);
1991 HTMLDocument_HTMLDocument5_Init(doc);
1992 HTMLDocument_Persist_Init(doc);
1993 HTMLDocument_OleCmd_Init(doc);
1994 HTMLDocument_OleObj_Init(doc);
1995 HTMLDocument_View_Init(doc);
1996 HTMLDocument_Window_Init(doc);
1997 HTMLDocument_Service_Init(doc);
1998 HTMLDocument_Hlink_Init(doc);
2000 ConnectionPointContainer_Init(&doc->cp_container, (IUnknown*)&doc->IHTMLDocument2_iface);
2001 ConnectionPoint_Init(&doc->cp_dispatch, &doc->cp_container, &IID_IDispatch, &HTMLDocumentEvents_data);
2002 ConnectionPoint_Init(&doc->cp_propnotif, &doc->cp_container, &IID_IPropertyNotifySink, NULL);
2003 ConnectionPoint_Init(&doc->cp_htmldocevents, &doc->cp_container, &DIID_HTMLDocumentEvents, &HTMLDocumentEvents_data);
2004 ConnectionPoint_Init(&doc->cp_htmldocevents2, &doc->cp_container, &DIID_HTMLDocumentEvents2, NULL);
2007 static void destroy_htmldoc(HTMLDocument *This)
2009 remove_target_tasks(This->task_magic);
2011 ConnectionPointContainer_Destroy(&This->cp_container);
2014 static inline HTMLDocumentNode *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
2016 return CONTAINING_RECORD(iface, HTMLDocumentNode, node);
2019 static HRESULT HTMLDocumentNode_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
2021 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2023 if(htmldoc_qi(&This->basedoc, riid, ppv))
2024 return *ppv ? S_OK : E_NOINTERFACE;
2026 if(IsEqualGUID(&IID_IInternetHostSecurityManager, riid)) {
2027 TRACE("(%p)->(IID_IInternetHostSecurityManager %p)\n", This, ppv);
2028 *ppv = &This->IInternetHostSecurityManager_iface;
2029 }else {
2030 return HTMLDOMNode_QI(&This->node, riid, ppv);
2033 IUnknown_AddRef((IUnknown*)*ppv);
2034 return S_OK;
2037 static void HTMLDocumentNode_destructor(HTMLDOMNode *iface)
2039 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2040 unsigned i;
2042 for(i=0; i < This->elem_vars_cnt; i++)
2043 heap_free(This->elem_vars[i]);
2044 heap_free(This->elem_vars);
2046 detach_events(This);
2047 if(This->body_event_target)
2048 release_event_target(This->body_event_target);
2049 if(This->nsevent_listener)
2050 release_nsevents(This);
2051 if(This->catmgr)
2052 ICatInformation_Release(This->catmgr);
2054 detach_selection(This);
2055 detach_ranges(This);
2056 release_nodes(This);
2058 while(!list_empty(&This->plugin_hosts))
2059 detach_plugin_host(LIST_ENTRY(list_head(&This->plugin_hosts), PluginHost, entry));
2061 if(This->nsdoc) {
2062 release_document_mutation(This);
2063 nsIDOMHTMLDocument_Release(This->nsdoc);
2066 heap_free(This->event_vector);
2067 destroy_htmldoc(&This->basedoc);
2070 static HRESULT HTMLDocumentNode_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
2072 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2073 FIXME("%p\n", This);
2074 return E_NOTIMPL;
2077 static const NodeImplVtbl HTMLDocumentNodeImplVtbl = {
2078 HTMLDocumentNode_QI,
2079 HTMLDocumentNode_destructor,
2080 HTMLDocumentNode_clone
2083 static HRESULT HTMLDocumentFragment_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
2085 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2086 HTMLDocumentNode *new_node;
2087 HRESULT hres;
2089 hres = create_document_fragment(nsnode, This->node.doc, &new_node);
2090 if(FAILED(hres))
2091 return hres;
2093 *ret = &new_node->node;
2094 return S_OK;
2097 static inline HTMLDocumentNode *impl_from_DispatchEx(DispatchEx *iface)
2099 return CONTAINING_RECORD(iface, HTMLDocumentNode, node.dispex);
2102 static HRESULT HTMLDocumentNode_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2103 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2105 HTMLDocumentNode *This = impl_from_DispatchEx(dispex);
2106 nsIDOMNodeList *node_list;
2107 nsAString name_str;
2108 nsIDOMNode *nsnode;
2109 HTMLDOMNode *node;
2110 unsigned i;
2111 nsresult nsres;
2112 HRESULT hres;
2114 if(flags != DISPATCH_PROPERTYGET) {
2115 FIXME("unsupported flags %x\n", flags);
2116 return E_NOTIMPL;
2119 i = id - MSHTML_DISPID_CUSTOM_MIN;
2121 if(!This->nsdoc || i >= This->elem_vars_cnt)
2122 return DISP_E_UNKNOWNNAME;
2124 nsAString_InitDepend(&name_str, This->elem_vars[i]);
2125 nsres = nsIDOMHTMLDocument_GetElementsByName(This->nsdoc, &name_str, &node_list);
2126 nsAString_Finish(&name_str);
2127 if(NS_FAILED(nsres))
2128 return E_FAIL;
2130 nsres = nsIDOMNodeList_Item(node_list, 0, &nsnode);
2131 nsIDOMNodeList_Release(node_list);
2132 if(NS_FAILED(nsres) || !nsnode)
2133 return DISP_E_UNKNOWNNAME;
2135 hres = get_node(This, nsnode, TRUE, &node);
2136 if(FAILED(hres))
2137 return hres;
2139 IHTMLDOMNode_AddRef(&node->IHTMLDOMNode_iface);
2140 V_VT(res) = VT_DISPATCH;
2141 V_DISPATCH(res) = (IDispatch*)&node->IHTMLDOMNode_iface;
2142 return S_OK;
2146 static const dispex_static_data_vtbl_t HTMLDocumentNode_dispex_vtbl = {
2147 NULL,
2148 NULL,
2149 HTMLDocumentNode_invoke,
2150 NULL
2153 static const NodeImplVtbl HTMLDocumentFragmentImplVtbl = {
2154 HTMLDocumentNode_QI,
2155 HTMLDocumentNode_destructor,
2156 HTMLDocumentFragment_clone
2159 static const tid_t HTMLDocumentNode_iface_tids[] = {
2160 IHTMLDOMNode_tid,
2161 IHTMLDOMNode2_tid,
2162 IHTMLDocument2_tid,
2163 IHTMLDocument3_tid,
2164 IHTMLDocument4_tid,
2165 IHTMLDocument5_tid,
2169 static dispex_static_data_t HTMLDocumentNode_dispex = {
2170 &HTMLDocumentNode_dispex_vtbl,
2171 DispHTMLDocument_tid,
2172 NULL,
2173 HTMLDocumentNode_iface_tids
2176 static HTMLDocumentNode *alloc_doc_node(HTMLDocumentObj *doc_obj, HTMLWindow *window)
2178 HTMLDocumentNode *doc;
2180 doc = heap_alloc_zero(sizeof(HTMLDocumentNode));
2181 if(!doc)
2182 return NULL;
2184 doc->ref = 1;
2185 doc->basedoc.doc_node = doc;
2186 doc->basedoc.doc_obj = doc_obj;
2187 doc->basedoc.window = window;
2189 init_dispex(&doc->node.dispex, (IUnknown*)&doc->node.IHTMLDOMNode_iface,
2190 &HTMLDocumentNode_dispex);
2191 init_doc(&doc->basedoc, (IUnknown*)&doc->node.IHTMLDOMNode_iface,
2192 &doc->node.dispex.IDispatchEx_iface);
2193 HTMLDocumentNode_SecMgr_Init(doc);
2195 list_init(&doc->bindings);
2196 list_init(&doc->selection_list);
2197 list_init(&doc->range_list);
2198 list_init(&doc->plugin_hosts);
2200 return doc;
2203 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocumentObj *doc_obj, HTMLWindow *window, HTMLDocumentNode **ret)
2205 HTMLDocumentNode *doc;
2207 doc = alloc_doc_node(doc_obj, window);
2208 if(!doc)
2209 return E_OUTOFMEMORY;
2211 if(!doc_obj->basedoc.window || window == doc_obj->basedoc.window)
2212 doc->basedoc.cp_container.forward_container = &doc_obj->basedoc.cp_container;
2214 nsIDOMHTMLDocument_AddRef(nsdoc);
2215 doc->nsdoc = nsdoc;
2216 init_document_mutation(doc);
2217 doc_init_events(doc);
2219 HTMLDOMNode_Init(doc, &doc->node, (nsIDOMNode*)nsdoc);
2220 doc->node.vtbl = &HTMLDocumentNodeImplVtbl;
2221 doc->node.cp_container = &doc->basedoc.cp_container;
2223 *ret = doc;
2224 return S_OK;
2227 HRESULT create_document_fragment(nsIDOMNode *nsnode, HTMLDocumentNode *doc_node, HTMLDocumentNode **ret)
2229 HTMLDocumentNode *doc_frag;
2231 doc_frag = alloc_doc_node(doc_node->basedoc.doc_obj, doc_node->basedoc.window);
2232 if(!doc_frag)
2233 return E_OUTOFMEMORY;
2235 HTMLDOMNode_Init(doc_node, &doc_frag->node, nsnode);
2236 doc_frag->node.vtbl = &HTMLDocumentFragmentImplVtbl;
2237 doc_frag->node.cp_container = &doc_frag->basedoc.cp_container;
2239 htmldoc_addref(&doc_frag->basedoc);
2240 *ret = doc_frag;
2241 return S_OK;
2244 /**********************************************************
2245 * ICustomDoc implementation
2248 static inline HTMLDocumentObj *impl_from_ICustomDoc(ICustomDoc *iface)
2250 return CONTAINING_RECORD(iface, HTMLDocumentObj, ICustomDoc_iface);
2253 static HRESULT WINAPI CustomDoc_QueryInterface(ICustomDoc *iface, REFIID riid, void **ppv)
2255 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2257 if(htmldoc_qi(&This->basedoc, riid, ppv))
2258 return *ppv ? S_OK : E_NOINTERFACE;
2260 if(IsEqualGUID(&IID_ICustomDoc, riid)) {
2261 TRACE("(%p)->(IID_ICustomDoc %p)\n", This, ppv);
2262 *ppv = &This->ICustomDoc_iface;
2263 }else if(IsEqualGUID(&IID_ITargetContainer, riid)) {
2264 TRACE("(%p)->(IID_ITargetContainer %p)\n", This, ppv);
2265 *ppv = &This->ITargetContainer_iface;
2266 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2267 return *ppv ? S_OK : E_NOINTERFACE;
2268 }else {
2269 FIXME("Unimplemented interface %s\n", debugstr_guid(riid));
2270 *ppv = NULL;
2271 return E_NOINTERFACE;
2274 IUnknown_AddRef((IUnknown*)*ppv);
2275 return S_OK;
2278 static ULONG WINAPI CustomDoc_AddRef(ICustomDoc *iface)
2280 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2281 ULONG ref = InterlockedIncrement(&This->ref);
2283 TRACE("(%p) ref = %u\n", This, ref);
2285 return ref;
2288 static ULONG WINAPI CustomDoc_Release(ICustomDoc *iface)
2290 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2291 ULONG ref = InterlockedDecrement(&This->ref);
2293 TRACE("(%p) ref = %u\n", This, ref);
2295 if(!ref) {
2296 if(This->basedoc.doc_node) {
2297 This->basedoc.doc_node->basedoc.doc_obj = NULL;
2298 htmldoc_release(&This->basedoc.doc_node->basedoc);
2300 if(This->basedoc.window) {
2301 This->basedoc.window->doc_obj = NULL;
2302 IHTMLWindow2_Release(&This->basedoc.window->IHTMLWindow2_iface);
2304 if(This->basedoc.advise_holder)
2305 IOleAdviseHolder_Release(This->basedoc.advise_holder);
2307 if(This->view_sink)
2308 IAdviseSink_Release(This->view_sink);
2309 if(This->client)
2310 IOleObject_SetClientSite(&This->basedoc.IOleObject_iface, NULL);
2311 if(This->hostui)
2312 ICustomDoc_SetUIHandler(&This->ICustomDoc_iface, NULL);
2313 if(This->in_place_active)
2314 IOleInPlaceObjectWindowless_InPlaceDeactivate(&This->basedoc.IOleInPlaceObjectWindowless_iface);
2315 if(This->ipsite)
2316 IOleDocumentView_SetInPlaceSite(&This->basedoc.IOleDocumentView_iface, NULL);
2317 if(This->undomgr)
2318 IOleUndoManager_Release(This->undomgr);
2319 if(This->tooltips_hwnd)
2320 DestroyWindow(This->tooltips_hwnd);
2322 if(This->hwnd)
2323 DestroyWindow(This->hwnd);
2324 heap_free(This->mime);
2326 destroy_htmldoc(&This->basedoc);
2327 release_dispex(&This->dispex);
2329 if(This->nscontainer)
2330 NSContainer_Release(This->nscontainer);
2331 heap_free(This);
2334 return ref;
2337 static HRESULT WINAPI CustomDoc_SetUIHandler(ICustomDoc *iface, IDocHostUIHandler *pUIHandler)
2339 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2340 IOleCommandTarget *cmdtrg;
2341 HRESULT hres;
2343 TRACE("(%p)->(%p)\n", This, pUIHandler);
2345 if(This->custom_hostui && This->hostui == pUIHandler)
2346 return S_OK;
2348 This->custom_hostui = TRUE;
2350 if(This->hostui)
2351 IDocHostUIHandler_Release(This->hostui);
2352 if(pUIHandler)
2353 IDocHostUIHandler_AddRef(pUIHandler);
2354 This->hostui = pUIHandler;
2355 if(!pUIHandler)
2356 return S_OK;
2358 hres = IDocHostUIHandler_QueryInterface(pUIHandler, &IID_IOleCommandTarget, (void**)&cmdtrg);
2359 if(SUCCEEDED(hres)) {
2360 FIXME("custom UI handler supports IOleCommandTarget\n");
2361 IOleCommandTarget_Release(cmdtrg);
2364 return S_OK;
2367 static const ICustomDocVtbl CustomDocVtbl = {
2368 CustomDoc_QueryInterface,
2369 CustomDoc_AddRef,
2370 CustomDoc_Release,
2371 CustomDoc_SetUIHandler
2374 static const tid_t HTMLDocumentObj_iface_tids[] = {
2375 IHTMLDocument2_tid,
2376 IHTMLDocument3_tid,
2377 IHTMLDocument4_tid,
2378 IHTMLDocument5_tid,
2381 static dispex_static_data_t HTMLDocumentObj_dispex = {
2382 NULL,
2383 DispHTMLDocument_tid,
2384 NULL,
2385 HTMLDocumentObj_iface_tids
2388 HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject)
2390 HTMLDocumentObj *doc;
2391 nsIDOMWindow *nswindow = NULL;
2392 nsresult nsres;
2393 HRESULT hres;
2395 TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppvObject);
2397 doc = heap_alloc_zero(sizeof(HTMLDocumentObj));
2398 if(!doc)
2399 return E_OUTOFMEMORY;
2401 init_dispex(&doc->dispex, (IUnknown*)&doc->ICustomDoc_iface, &HTMLDocumentObj_dispex);
2402 init_doc(&doc->basedoc, (IUnknown*)&doc->ICustomDoc_iface, &doc->dispex.IDispatchEx_iface);
2403 TargetContainer_Init(doc);
2405 doc->ICustomDoc_iface.lpVtbl = &CustomDocVtbl;
2406 doc->ref = 1;
2407 doc->basedoc.doc_obj = doc;
2409 doc->usermode = UNKNOWN_USERMODE;
2411 hres = create_nscontainer(doc, NULL, &doc->nscontainer);
2412 if(FAILED(hres)) {
2413 ERR("Failed to init Gecko, returning CLASS_E_CLASSNOTAVAILABLE\n");
2414 htmldoc_release(&doc->basedoc);
2415 return hres;
2418 hres = htmldoc_query_interface(&doc->basedoc, riid, ppvObject);
2419 htmldoc_release(&doc->basedoc);
2420 if(FAILED(hres))
2421 return hres;
2424 nsres = nsIWebBrowser_GetContentDOMWindow(doc->nscontainer->webbrowser, &nswindow);
2425 if(NS_FAILED(nsres))
2426 ERR("GetContentDOMWindow failed: %08x\n", nsres);
2428 hres = HTMLWindow_Create(doc, nswindow, NULL /* FIXME */, &doc->basedoc.window);
2429 if(nswindow)
2430 nsIDOMWindow_Release(nswindow);
2431 if(FAILED(hres)) {
2432 htmldoc_release(&doc->basedoc);
2433 return hres;
2436 if(!doc->basedoc.doc_node && doc->basedoc.window->doc) {
2437 doc->basedoc.doc_node = doc->basedoc.window->doc;
2438 htmldoc_addref(&doc->basedoc.doc_node->basedoc);
2441 get_thread_hwnd();
2443 return S_OK;