2 * Copyright 2005 Jacek Caban
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
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
35 #include "wine/debug.h"
36 #include "wine/unicode.h"
38 #include "mshtml_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
42 static HRESULT
get_doc_string(HTMLDocument
*This
, char **str
, DWORD
*len
)
44 nsIDOMDocument
*nsdoc
;
50 if(!This
->nscontainer
) {
51 WARN("no nscontainer, returning NULL\n");
55 nsres
= nsIWebNavigation_GetDocument(This
->nscontainer
->navigation
, &nsdoc
);
56 if(NS_FAILED(nsres
)) {
57 ERR("GetDocument failed: %08x\n", nsres
);
61 nsres
= nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMNode
, (void**)&nsnode
);
62 nsIDOMDocument_Release(nsdoc
);
63 if(NS_FAILED(nsres
)) {
64 ERR("Could not get nsIDOMNode failed: %08x\n", nsres
);
68 nsAString_Init(&nsstr
, NULL
);
69 nsnode_to_nsstring(nsnode
, &nsstr
);
70 nsIDOMNode_Release(nsnode
);
72 nsAString_GetData(&nsstr
, &strw
, NULL
);
73 TRACE("%s\n", debugstr_w(strw
));
75 *len
= WideCharToMultiByte(CP_ACP
, 0, strw
, -1, NULL
, 0, NULL
, NULL
);
76 *str
= mshtml_alloc(*len
);
77 WideCharToMultiByte(CP_ACP
, 0, strw
, -1, *str
, *len
, NULL
, NULL
);
79 nsAString_Finish(&nsstr
);
84 /**********************************************************
85 * IPersistMoniker implementation
88 #define PERSISTMON_THIS(iface) DEFINE_THIS(HTMLDocument, PersistMoniker, iface)
90 static HRESULT WINAPI
PersistMoniker_QueryInterface(IPersistMoniker
*iface
, REFIID riid
,
93 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
94 return IHTMLDocument2_QueryInterface(HTMLDOC(This
), riid
, ppvObject
);
97 static ULONG WINAPI
PersistMoniker_AddRef(IPersistMoniker
*iface
)
99 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
100 return IHTMLDocument2_AddRef(HTMLDOC(This
));
103 static ULONG WINAPI
PersistMoniker_Release(IPersistMoniker
*iface
)
105 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
106 return IHTMLDocument2_Release(HTMLDOC(This
));
109 static HRESULT WINAPI
PersistMoniker_GetClassID(IPersistMoniker
*iface
, CLSID
*pClassID
)
111 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
112 return IPersist_GetClassID(PERSIST(This
), pClassID
);
115 static HRESULT WINAPI
PersistMoniker_IsDirty(IPersistMoniker
*iface
)
117 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
118 FIXME("(%p)\n", This
);
122 static nsIInputStream
*get_post_data_stream(IBindCtx
*bctx
)
124 nsIInputStream
*ret
= NULL
;
125 IBindStatusCallback
*callback
;
126 IHttpNegotiate
*http_negotiate
;
129 DWORD post_len
= 0, headers_len
= 0;
130 LPWSTR headers
= NULL
;
131 WCHAR emptystr
[] = {0};
135 static WCHAR _BSCB_Holder_
[] =
136 {'_','B','S','C','B','_','H','o','l','d','e','r','_',0};
139 /* FIXME: This should be done in URLMoniker */
143 hres
= IBindCtx_GetObjectParam(bctx
, _BSCB_Holder_
, (IUnknown
**)&callback
);
147 hres
= IBindStatusCallback_QueryInterface(callback
, &IID_IHttpNegotiate
,
148 (void**)&http_negotiate
);
149 if(SUCCEEDED(hres
)) {
150 hres
= IHttpNegotiate_BeginningTransaction(http_negotiate
, emptystr
,
151 emptystr
, 0, &headers
);
152 IHttpNegotiate_Release(http_negotiate
);
154 if(SUCCEEDED(hres
) && headers
)
155 headers_len
= WideCharToMultiByte(CP_ACP
, 0, headers
, -1, NULL
, 0, NULL
, NULL
);
158 memset(&bindinfo
, 0, sizeof(bindinfo
));
159 bindinfo
.cbSize
= sizeof(bindinfo
);
161 hres
= IBindStatusCallback_GetBindInfo(callback
, &bindf
, &bindinfo
);
163 if(SUCCEEDED(hres
) && bindinfo
.dwBindVerb
== BINDVERB_POST
)
164 post_len
= bindinfo
.cbstgmedData
;
166 if(headers_len
|| post_len
) {
167 int len
= headers_len
? headers_len
-1 : 0;
169 static const char content_length
[] = "Content-Length: %u\r\n\r\n";
171 data
= mshtml_alloc(headers_len
+post_len
+sizeof(content_length
)+8);
174 WideCharToMultiByte(CP_ACP
, 0, headers
, -1, data
, -1, NULL
, NULL
);
175 CoTaskMemFree(headers
);
179 sprintf(data
+len
, content_length
, post_len
);
182 memcpy(data
+len
, bindinfo
.stgmedData
.u
.hGlobal
, post_len
);
185 TRACE("data = %s\n", debugstr_an(data
, len
+post_len
));
187 ret
= create_nsstream(data
, len
+post_len
);
190 ReleaseBindInfo(&bindinfo
);
191 IBindStatusCallback_Release(callback
);
196 static HRESULT WINAPI
PersistMoniker_Load(IPersistMoniker
*iface
, BOOL fFullyAvailable
,
197 IMoniker
*pimkName
, LPBC pibc
, DWORD grfMode
)
199 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
200 BSCallback
*bscallback
;
206 TRACE("(%p)->(%x %p %p %08x)\n", This
, fFullyAvailable
, pimkName
, pibc
, grfMode
);
209 IUnknown
*unk
= NULL
;
213 * "__PrecreatedObject"
214 * "BIND_CONTEXT_PARAM"
215 * "__HTMLLOADOPTIONS"
219 * "_ITransData_Object_"
223 IBindCtx_GetObjectParam(pibc
, (LPOLESTR
)SZ_HTML_CLIENTSITE_OBJECTPARAM
, &unk
);
225 IOleClientSite
*client
= NULL
;
227 hres
= IUnknown_QueryInterface(unk
, &IID_IOleClientSite
, (void**)&client
);
228 if(SUCCEEDED(hres
)) {
229 TRACE("Got client site %p\n", client
);
230 IOleObject_SetClientSite(OLEOBJ(This
), client
);
231 IOleClientSite_Release(client
);
234 IUnknown_Release(unk
);
238 This
->readystate
= READYSTATE_LOADING
;
239 call_property_onchanged(This
->cp_propnotif
, DISPID_READYSTATE
);
241 HTMLDocument_LockContainer(This
, TRUE
);
243 hres
= IMoniker_GetDisplayName(pimkName
, pibc
, NULL
, &url
);
245 WARN("GetDiaplayName failed: %08x\n", hres
);
249 TRACE("got url: %s\n", debugstr_w(url
));
252 IOleCommandTarget
*cmdtrg
= NULL
;
254 hres
= IOleClientSite_QueryInterface(This
->client
, &IID_IOleCommandTarget
,
256 if(SUCCEEDED(hres
)) {
261 IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 37, 0, &var
, NULL
);
263 IOleCommandTarget_Release(cmdtrg
);
268 VARIANT silent
, offline
;
270 hres
= get_client_disp_property(This
->client
, DISPID_AMBIENT_SILENT
, &silent
);
271 if(SUCCEEDED(hres
)) {
272 if(V_VT(&silent
) != VT_BOOL
)
273 WARN("V_VT(silent) = %d\n", V_VT(&silent
));
274 else if(V_BOOL(&silent
))
275 FIXME("silent == true\n");
278 hres
= get_client_disp_property(This
->client
,
279 DISPID_AMBIENT_OFFLINEIFNOTCONNECTED
, &offline
);
280 if(SUCCEEDED(hres
)) {
281 if(V_VT(&silent
) != VT_BOOL
)
282 WARN("V_VT(offline) = %d\n", V_VT(&silent
));
283 else if(V_BOOL(&silent
))
284 FIXME("offline == true\n");
288 bscallback
= create_bscallback(pimkName
);
291 task
= mshtml_alloc(sizeof(task_t
));
294 task
->task_id
= TASK_SETPROGRESS
;
300 task
= mshtml_alloc(sizeof(task_t
));
303 task
->task_id
= TASK_SETDOWNLOADSTATE
;
308 if(This
->nscontainer
) {
309 nsIInputStream
*post_data_stream
= get_post_data_stream(pibc
);
311 This
->nscontainer
->bscallback
= bscallback
;
312 nsres
= nsIWebNavigation_LoadURI(This
->nscontainer
->navigation
, url
,
313 LOAD_FLAGS_NONE
, NULL
, post_data_stream
, NULL
);
314 This
->nscontainer
->bscallback
= NULL
;
317 nsIInputStream_Release(post_data_stream
);
319 if(NS_SUCCEEDED(nsres
)) {
320 /* FIXME: don't return here (URL Moniker needs to be good enough) */
322 IBindStatusCallback_Release(STATUSCLB(bscallback
));
325 }else if(nsres
!= WINE_NS_LOAD_FROM_MONIKER
) {
326 WARN("LoadURI failed: %08x\n", nsres
);
330 set_document_bscallback(This
, bscallback
);
331 hres
= start_binding(bscallback
);
333 IBindStatusCallback_Release(STATUSCLB(bscallback
));
339 static HRESULT WINAPI
PersistMoniker_Save(IPersistMoniker
*iface
, IMoniker
*pimkName
,
340 LPBC pbc
, BOOL fRemember
)
342 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
343 FIXME("(%p)->(%p %p %x)\n", This
, pimkName
, pbc
, fRemember
);
347 static HRESULT WINAPI
PersistMoniker_SaveCompleted(IPersistMoniker
*iface
, IMoniker
*pimkName
, LPBC pibc
)
349 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
350 FIXME("(%p)->(%p %p)\n", This
, pimkName
, pibc
);
354 static HRESULT WINAPI
PersistMoniker_GetCurMoniker(IPersistMoniker
*iface
, IMoniker
**ppimkName
)
356 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
357 FIXME("(%p)->(%p)\n", This
, ppimkName
);
361 static const IPersistMonikerVtbl PersistMonikerVtbl
= {
362 PersistMoniker_QueryInterface
,
363 PersistMoniker_AddRef
,
364 PersistMoniker_Release
,
365 PersistMoniker_GetClassID
,
366 PersistMoniker_IsDirty
,
369 PersistMoniker_SaveCompleted
,
370 PersistMoniker_GetCurMoniker
373 /**********************************************************
374 * IMonikerProp implementation
377 #define MONPROP_THIS(iface) DEFINE_THIS(HTMLDocument, MonikerProp, iface)
379 static HRESULT WINAPI
MonikerProp_QueryInterface(IMonikerProp
*iface
, REFIID riid
, void **ppvObject
)
381 HTMLDocument
*This
= MONPROP_THIS(iface
);
382 return IHTMLDocument2_QueryInterface(HTMLDOC(This
), riid
, ppvObject
);
385 static ULONG WINAPI
MonikerProp_AddRef(IMonikerProp
*iface
)
387 HTMLDocument
*This
= MONPROP_THIS(iface
);
388 return IHTMLDocument2_AddRef(HTMLDOC(This
));
391 static ULONG WINAPI
MonikerProp_Release(IMonikerProp
*iface
)
393 HTMLDocument
*This
= MONPROP_THIS(iface
);
394 return IHTMLDocument_Release(HTMLDOC(This
));
397 static HRESULT WINAPI
MonikerProp_PutProperty(IMonikerProp
*iface
, MONIKERPROPERTY mkp
, LPCWSTR val
)
399 HTMLDocument
*This
= MONPROP_THIS(iface
);
400 FIXME("(%p)->(%d %s)\n", This
, mkp
, debugstr_w(val
));
404 static const IMonikerPropVtbl MonikerPropVtbl
= {
405 MonikerProp_QueryInterface
,
408 MonikerProp_PutProperty
411 /**********************************************************
412 * IPersistFile implementation
415 #define PERSISTFILE_THIS(iface) DEFINE_THIS(HTMLDocument, PersistFile, iface)
417 static HRESULT WINAPI
PersistFile_QueryInterface(IPersistFile
*iface
, REFIID riid
, void **ppvObject
)
419 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
420 return IHTMLDocument2_QueryInterface(HTMLDOC(This
), riid
, ppvObject
);
423 static ULONG WINAPI
PersistFile_AddRef(IPersistFile
*iface
)
425 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
426 return IHTMLDocument2_AddRef(HTMLDOC(This
));
429 static ULONG WINAPI
PersistFile_Release(IPersistFile
*iface
)
431 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
432 return IHTMLDocument2_Release(HTMLDOC(This
));
435 static HRESULT WINAPI
PersistFile_GetClassID(IPersistFile
*iface
, CLSID
*pClassID
)
437 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
439 TRACE("(%p)->(%p)\n", This
, pClassID
);
444 memcpy(pClassID
, &CLSID_HTMLDocument
, sizeof(CLSID
));
448 static HRESULT WINAPI
PersistFile_IsDirty(IPersistFile
*iface
)
450 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
451 FIXME("(%p)\n", This
);
455 static HRESULT WINAPI
PersistFile_Load(IPersistFile
*iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
457 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
458 FIXME("(%p)->(%s %08x)\n", This
, debugstr_w(pszFileName
), dwMode
);
462 static HRESULT WINAPI
PersistFile_Save(IPersistFile
*iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
464 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
466 DWORD len
, written
=0;
470 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(pszFileName
), fRemember
);
472 file
= CreateFileW(pszFileName
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
473 FILE_ATTRIBUTE_NORMAL
, NULL
);
474 if(file
== INVALID_HANDLE_VALUE
) {
475 WARN("Could not create file: %u\n", GetLastError());
479 hres
= get_doc_string(This
, &str
, &len
);
483 WriteFile(file
, str
, len
, &written
, NULL
);
488 static HRESULT WINAPI
PersistFile_SaveCompleted(IPersistFile
*iface
, LPCOLESTR pszFileName
)
490 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
491 FIXME("(%p)->(%s)\n", This
, debugstr_w(pszFileName
));
495 static HRESULT WINAPI
PersistFile_GetCurFile(IPersistFile
*iface
, LPOLESTR
*pszFileName
)
497 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
498 FIXME("(%p)->(%p)\n", This
, pszFileName
);
502 static const IPersistFileVtbl PersistFileVtbl
= {
503 PersistFile_QueryInterface
,
506 PersistFile_GetClassID
,
510 PersistFile_SaveCompleted
,
511 PersistFile_GetCurFile
514 #define PERSTRINIT_THIS(iface) DEFINE_THIS(HTMLDocument, PersistStreamInit, iface)
516 static HRESULT WINAPI
PersistStreamInit_QueryInterface(IPersistStreamInit
*iface
,
517 REFIID riid
, void **ppv
)
519 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
520 return IHTMLDocument2_QueryInterface(HTMLDOC(This
), riid
, ppv
);
523 static ULONG WINAPI
PersistStreamInit_AddRef(IPersistStreamInit
*iface
)
525 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
526 return IHTMLDocument2_AddRef(HTMLDOC(This
));
529 static ULONG WINAPI
PersistStreamInit_Release(IPersistStreamInit
*iface
)
531 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
532 return IHTMLDocument2_AddRef(HTMLDOC(This
));
535 static HRESULT WINAPI
PersistStreamInit_GetClassID(IPersistStreamInit
*iface
, CLSID
*pClassID
)
537 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
538 return IPersist_GetClassID(PERSIST(This
), pClassID
);
541 static HRESULT WINAPI
PersistStreamInit_IsDirty(IPersistStreamInit
*iface
)
543 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
544 FIXME("(%p)\n", This
);
548 static HRESULT WINAPI
PersistStreamInit_Load(IPersistStreamInit
*iface
, LPSTREAM pStm
)
550 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
551 FIXME("(%p)->(%p)\n", This
, pStm
);
555 static HRESULT WINAPI
PersistStreamInit_Save(IPersistStreamInit
*iface
, LPSTREAM pStm
,
558 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
560 DWORD len
, written
=0;
563 WARN("(%p)->(%p %x) needs more work\n", This
, pStm
, fClearDirty
);
565 hres
= get_doc_string(This
, &str
, &len
);
570 hres
= IStream_Write(pStm
, str
, len
, &written
);
572 FIXME("Write failed: %08x\n", hres
);
578 static HRESULT WINAPI
PersistStreamInit_GetSizeMax(IPersistStreamInit
*iface
,
579 ULARGE_INTEGER
*pcbSize
)
581 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
582 FIXME("(%p)->(%p)\n", This
, pcbSize
);
586 static HRESULT WINAPI
PersistStreamInit_InitNew(IPersistStreamInit
*iface
)
588 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
589 FIXME("(%p)\n", This
);
593 #undef PERSTRINIT_THIS
595 static const IPersistStreamInitVtbl PersistStreamInitVtbl
= {
596 PersistStreamInit_QueryInterface
,
597 PersistStreamInit_AddRef
,
598 PersistStreamInit_Release
,
599 PersistStreamInit_GetClassID
,
600 PersistStreamInit_IsDirty
,
601 PersistStreamInit_Load
,
602 PersistStreamInit_Save
,
603 PersistStreamInit_GetSizeMax
,
604 PersistStreamInit_InitNew
607 void HTMLDocument_Persist_Init(HTMLDocument
*This
)
609 This
->lpPersistMonikerVtbl
= &PersistMonikerVtbl
;
610 This
->lpPersistFileVtbl
= &PersistFileVtbl
;
611 This
->lpMonikerPropVtbl
= &MonikerPropVtbl
;
612 This
->lpPersistStreamInitVtbl
= &PersistStreamInitVtbl
;
614 This
->bscallback
= NULL
;