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 /**********************************************************
43 * IPersistMoniker implementation
46 #define PERSISTMON_THIS(iface) DEFINE_THIS(HTMLDocument, PersistMoniker, iface)
48 static HRESULT WINAPI
PersistMoniker_QueryInterface(IPersistMoniker
*iface
, REFIID riid
,
51 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
52 return IHTMLDocument2_QueryInterface(HTMLDOC(This
), riid
, ppvObject
);
55 static ULONG WINAPI
PersistMoniker_AddRef(IPersistMoniker
*iface
)
57 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
58 return IHTMLDocument2_AddRef(HTMLDOC(This
));
61 static ULONG WINAPI
PersistMoniker_Release(IPersistMoniker
*iface
)
63 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
64 return IHTMLDocument2_Release(HTMLDOC(This
));
67 static HRESULT WINAPI
PersistMoniker_GetClassID(IPersistMoniker
*iface
, CLSID
*pClassID
)
69 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
70 return IPersist_GetClassID(PERSIST(This
), pClassID
);
73 static HRESULT WINAPI
PersistMoniker_IsDirty(IPersistMoniker
*iface
)
75 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
76 FIXME("(%p)\n", This
);
80 static nsIInputStream
*get_post_data_stream(IBindCtx
*bctx
)
82 nsIInputStream
*ret
= NULL
;
83 IBindStatusCallback
*callback
;
84 IHttpNegotiate
*http_negotiate
;
87 DWORD post_len
= 0, headers_len
= 0;
88 LPWSTR headers
= NULL
;
89 WCHAR emptystr
[] = {0};
93 static WCHAR _BSCB_Holder_
[] =
94 {'_','B','S','C','B','_','H','o','l','d','e','r','_',0};
97 /* FIXME: This should be done in URLMoniker */
101 hres
= IBindCtx_GetObjectParam(bctx
, _BSCB_Holder_
, (IUnknown
**)&callback
);
105 hres
= IBindStatusCallback_QueryInterface(callback
, &IID_IHttpNegotiate
,
106 (void**)&http_negotiate
);
107 if(SUCCEEDED(hres
)) {
108 hres
= IHttpNegotiate_BeginningTransaction(http_negotiate
, emptystr
,
109 emptystr
, 0, &headers
);
110 IHttpNegotiate_Release(http_negotiate
);
112 if(SUCCEEDED(hres
) && headers
)
113 headers_len
= WideCharToMultiByte(CP_ACP
, 0, headers
, -1, NULL
, 0, NULL
, NULL
);
116 memset(&bindinfo
, 0, sizeof(bindinfo
));
117 bindinfo
.cbSize
= sizeof(bindinfo
);
119 hres
= IBindStatusCallback_GetBindInfo(callback
, &bindf
, &bindinfo
);
121 if(SUCCEEDED(hres
) && bindinfo
.dwBindVerb
== BINDVERB_POST
)
122 post_len
= bindinfo
.cbstgmedData
;
124 if(headers_len
|| post_len
) {
125 int len
= headers_len
? headers_len
-1 : 0;
127 static const char content_length
[] = "Content-Length: %u\r\n\r\n";
129 data
= mshtml_alloc(headers_len
+post_len
+sizeof(content_length
)+8);
132 WideCharToMultiByte(CP_ACP
, 0, headers
, -1, data
, -1, NULL
, NULL
);
133 CoTaskMemFree(headers
);
137 sprintf(data
+len
, content_length
, post_len
);
140 memcpy(data
+len
, bindinfo
.stgmedData
.u
.hGlobal
, post_len
);
143 TRACE("data = %s\n", debugstr_an(data
, len
+post_len
));
145 ret
= create_nsstream(data
, len
+post_len
);
148 ReleaseBindInfo(&bindinfo
);
149 IBindStatusCallback_Release(callback
);
154 static HRESULT WINAPI
PersistMoniker_Load(IPersistMoniker
*iface
, BOOL fFullyAvailable
,
155 IMoniker
*pimkName
, LPBC pibc
, DWORD grfMode
)
157 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
158 BSCallback
*bscallback
;
164 TRACE("(%p)->(%x %p %p %08x)\n", This
, fFullyAvailable
, pimkName
, pibc
, grfMode
);
167 IUnknown
*unk
= NULL
;
171 * "__PrecreatedObject"
172 * "BIND_CONTEXT_PARAM"
173 * "__HTMLLOADOPTIONS"
177 * "_ITransData_Object_"
181 IBindCtx_GetObjectParam(pibc
, (LPOLESTR
)SZ_HTML_CLIENTSITE_OBJECTPARAM
, &unk
);
183 IOleClientSite
*client
= NULL
;
185 hres
= IUnknown_QueryInterface(unk
, &IID_IOleClientSite
, (void**)&client
);
186 if(SUCCEEDED(hres
)) {
187 TRACE("Got client site %p\n", client
);
188 IOleObject_SetClientSite(OLEOBJ(This
), client
);
189 IOleClientSite_Release(client
);
192 IUnknown_Release(unk
);
196 This
->readystate
= READYSTATE_LOADING
;
197 call_property_onchanged(This
->cp_propnotif
, DISPID_READYSTATE
);
199 HTMLDocument_LockContainer(This
, TRUE
);
201 hres
= IMoniker_GetDisplayName(pimkName
, pibc
, NULL
, &url
);
203 WARN("GetDiaplayName failed: %08x\n", hres
);
207 TRACE("got url: %s\n", debugstr_w(url
));
210 IOleCommandTarget
*cmdtrg
= NULL
;
212 hres
= IOleClientSite_QueryInterface(This
->client
, &IID_IOleCommandTarget
,
214 if(SUCCEEDED(hres
)) {
219 IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 37, 0, &var
, NULL
);
224 VARIANT silent
, offline
;
226 hres
= get_client_disp_property(This
->client
, DISPID_AMBIENT_SILENT
, &silent
);
227 if(SUCCEEDED(hres
)) {
228 if(V_VT(&silent
) != VT_BOOL
)
229 WARN("V_VT(silent) = %d\n", V_VT(&silent
));
230 else if(V_BOOL(&silent
))
231 FIXME("silent == true\n");
234 hres
= get_client_disp_property(This
->client
,
235 DISPID_AMBIENT_OFFLINEIFNOTCONNECTED
, &offline
);
236 if(SUCCEEDED(hres
)) {
237 if(V_VT(&silent
) != VT_BOOL
)
238 WARN("V_VT(offline) = %d\n", V_VT(&silent
));
239 else if(V_BOOL(&silent
))
240 FIXME("offline == true\n");
244 bscallback
= create_bscallback(pimkName
);
247 task
= mshtml_alloc(sizeof(task_t
));
250 task
->task_id
= TASK_SETPROGRESS
;
256 task
= mshtml_alloc(sizeof(task_t
));
259 task
->task_id
= TASK_SETDOWNLOADSTATE
;
264 if(This
->nscontainer
) {
265 nsIInputStream
*post_data_stream
= get_post_data_stream(pibc
);
267 This
->nscontainer
->bscallback
= bscallback
;
268 nsres
= nsIWebNavigation_LoadURI(This
->nscontainer
->navigation
, url
,
269 LOAD_FLAGS_NONE
, NULL
, post_data_stream
, NULL
);
270 This
->nscontainer
->bscallback
= NULL
;
273 nsIInputStream_Release(post_data_stream
);
275 if(NS_SUCCEEDED(nsres
)) {
276 /* FIXME: don't return here (URL Moniker needs to be good enough) */
278 IBindStatusCallback_Release(STATUSCLB(bscallback
));
281 }else if(nsres
!= WINE_NS_LOAD_FROM_MONIKER
) {
282 WARN("LoadURI failed: %08x\n", nsres
);
286 set_document_bscallback(This
, bscallback
);
287 hres
= start_binding(bscallback
);
289 IBindStatusCallback_Release(STATUSCLB(bscallback
));
295 static HRESULT WINAPI
PersistMoniker_Save(IPersistMoniker
*iface
, IMoniker
*pimkName
,
296 LPBC pbc
, BOOL fRemember
)
298 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
299 FIXME("(%p)->(%p %p %x)\n", This
, pimkName
, pbc
, fRemember
);
303 static HRESULT WINAPI
PersistMoniker_SaveCompleted(IPersistMoniker
*iface
, IMoniker
*pimkName
, LPBC pibc
)
305 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
306 FIXME("(%p)->(%p %p)\n", This
, pimkName
, pibc
);
310 static HRESULT WINAPI
PersistMoniker_GetCurMoniker(IPersistMoniker
*iface
, IMoniker
**ppimkName
)
312 HTMLDocument
*This
= PERSISTMON_THIS(iface
);
313 FIXME("(%p)->(%p)\n", This
, ppimkName
);
317 static const IPersistMonikerVtbl PersistMonikerVtbl
= {
318 PersistMoniker_QueryInterface
,
319 PersistMoniker_AddRef
,
320 PersistMoniker_Release
,
321 PersistMoniker_GetClassID
,
322 PersistMoniker_IsDirty
,
325 PersistMoniker_SaveCompleted
,
326 PersistMoniker_GetCurMoniker
329 /**********************************************************
330 * IMonikerProp implementation
333 #define MONPROP_THIS(iface) DEFINE_THIS(HTMLDocument, MonikerProp, iface)
335 static HRESULT WINAPI
MonikerProp_QueryInterface(IMonikerProp
*iface
, REFIID riid
, void **ppvObject
)
337 HTMLDocument
*This
= MONPROP_THIS(iface
);
338 return IHTMLDocument2_QueryInterface(HTMLDOC(This
), riid
, ppvObject
);
341 static ULONG WINAPI
MonikerProp_AddRef(IMonikerProp
*iface
)
343 HTMLDocument
*This
= MONPROP_THIS(iface
);
344 return IHTMLDocument2_AddRef(HTMLDOC(This
));
347 static ULONG WINAPI
MonikerProp_Release(IMonikerProp
*iface
)
349 HTMLDocument
*This
= MONPROP_THIS(iface
);
350 return IHTMLDocument_Release(HTMLDOC(This
));
353 static HRESULT WINAPI
MonikerProp_PutProperty(IMonikerProp
*iface
, MONIKERPROPERTY mkp
, LPCWSTR val
)
355 HTMLDocument
*This
= MONPROP_THIS(iface
);
356 FIXME("(%p)->(%d %s)\n", This
, mkp
, debugstr_w(val
));
360 static const IMonikerPropVtbl MonikerPropVtbl
= {
361 MonikerProp_QueryInterface
,
364 MonikerProp_PutProperty
367 /**********************************************************
368 * IPersistFile implementation
371 #define PERSISTFILE_THIS(iface) DEFINE_THIS(HTMLDocument, PersistFile, iface)
373 static HRESULT WINAPI
PersistFile_QueryInterface(IPersistFile
*iface
, REFIID riid
, void **ppvObject
)
375 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
376 return IHTMLDocument2_QueryInterface(HTMLDOC(This
), riid
, ppvObject
);
379 static ULONG WINAPI
PersistFile_AddRef(IPersistFile
*iface
)
381 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
382 return IHTMLDocument2_AddRef(HTMLDOC(This
));
385 static ULONG WINAPI
PersistFile_Release(IPersistFile
*iface
)
387 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
388 return IHTMLDocument2_Release(HTMLDOC(This
));
391 static HRESULT WINAPI
PersistFile_GetClassID(IPersistFile
*iface
, CLSID
*pClassID
)
393 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
395 TRACE("(%p)->(%p)\n", This
, pClassID
);
400 memcpy(pClassID
, &CLSID_HTMLDocument
, sizeof(CLSID
));
404 static HRESULT WINAPI
PersistFile_IsDirty(IPersistFile
*iface
)
406 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
407 FIXME("(%p)\n", This
);
411 static HRESULT WINAPI
PersistFile_Load(IPersistFile
*iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
413 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
414 FIXME("(%p)->(%s %08x)\n", This
, debugstr_w(pszFileName
), dwMode
);
418 static HRESULT WINAPI
PersistFile_Save(IPersistFile
*iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
420 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
421 FIXME("(%p)->(%s %x)\n", This
, debugstr_w(pszFileName
), fRemember
);
425 static HRESULT WINAPI
PersistFile_SaveCompleted(IPersistFile
*iface
, LPCOLESTR pszFileName
)
427 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
428 FIXME("(%p)->(%s)\n", This
, debugstr_w(pszFileName
));
432 static HRESULT WINAPI
PersistFile_GetCurFile(IPersistFile
*iface
, LPOLESTR
*pszFileName
)
434 HTMLDocument
*This
= PERSISTFILE_THIS(iface
);
435 FIXME("(%p)->(%p)\n", This
, pszFileName
);
439 static const IPersistFileVtbl PersistFileVtbl
= {
440 PersistFile_QueryInterface
,
443 PersistFile_GetClassID
,
447 PersistFile_SaveCompleted
,
448 PersistFile_GetCurFile
451 #define PERSTRINIT_THIS(iface) DEFINE_THIS(HTMLDocument, PersistStreamInit, iface)
453 static HRESULT WINAPI
PersistStreamInit_QueryInterface(IPersistStreamInit
*iface
,
454 REFIID riid
, void **ppv
)
456 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
457 return IHTMLDocument2_QueryInterface(HTMLDOC(This
), riid
, ppv
);
460 static ULONG WINAPI
PersistStreamInit_AddRef(IPersistStreamInit
*iface
)
462 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
463 return IHTMLDocument2_AddRef(HTMLDOC(This
));
466 static ULONG WINAPI
PersistStreamInit_Release(IPersistStreamInit
*iface
)
468 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
469 return IHTMLDocument2_AddRef(HTMLDOC(This
));
472 static HRESULT WINAPI
PersistStreamInit_GetClassID(IPersistStreamInit
*iface
, CLSID
*pClassID
)
474 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
475 return IPersist_GetClassID(PERSIST(This
), pClassID
);
478 static HRESULT WINAPI
PersistStreamInit_IsDirty(IPersistStreamInit
*iface
)
480 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
481 FIXME("(%p)\n", This
);
485 static HRESULT WINAPI
PersistStreamInit_Load(IPersistStreamInit
*iface
, LPSTREAM pStm
)
487 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
488 FIXME("(%p)->(%p)\n", This
, pStm
);
492 static HRESULT WINAPI
PersistStreamInit_Save(IPersistStreamInit
*iface
, LPSTREAM pStm
,
495 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
496 nsIDOMDocument
*nsdoc
;
501 DWORD len
, written
=0;
505 WARN("(%p)->(%p %x) needs more work\n", This
, pStm
, fClearDirty
);
507 if(!This
->nscontainer
)
510 nsres
= nsIWebNavigation_GetDocument(This
->nscontainer
->navigation
, &nsdoc
);
511 if(NS_FAILED(nsres
)) {
512 ERR("GetDocument failed: %08x\n", nsres
);
516 nsres
= nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMNode
, (void**)&nsnode
);
517 nsIDOMDocument_Release(nsdoc
);
518 if(NS_FAILED(nsres
)) {
519 ERR("Could not get nsIDOMNode failed: %08x\n", nsres
);
523 nsAString_Init(&nsstr
, NULL
);
524 nsnode_to_nsstring(nsnode
, &nsstr
);
525 nsIDOMNode_Release(nsnode
);
527 nsAString_GetData(&nsstr
, &strw
, NULL
);
529 len
= WideCharToMultiByte(CP_ACP
, 0, strw
, -1, NULL
, 0, NULL
, NULL
);
530 str
= mshtml_alloc(len
);
531 WideCharToMultiByte(CP_ACP
, 0, strw
, -1, str
, len
, NULL
, NULL
);
533 nsAString_Finish(&nsstr
);
535 ERR("%s\n", debugstr_a(str
));
537 hres
= IStream_Write(pStm
, str
, len
, &written
);
539 FIXME("Write failed: %08x\n", hres
);
546 static HRESULT WINAPI
PersistStreamInit_GetSizeMax(IPersistStreamInit
*iface
,
547 ULARGE_INTEGER
*pcbSize
)
549 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
550 FIXME("(%p)->(%p)\n", This
, pcbSize
);
554 static HRESULT WINAPI
PersistStreamInit_InitNew(IPersistStreamInit
*iface
)
556 HTMLDocument
*This
= PERSTRINIT_THIS(iface
);
557 FIXME("(%p)\n", This
);
561 #undef PERSTRINIT_THIS
563 static const IPersistStreamInitVtbl PersistStreamInitVtbl
= {
564 PersistStreamInit_QueryInterface
,
565 PersistStreamInit_AddRef
,
566 PersistStreamInit_Release
,
567 PersistStreamInit_GetClassID
,
568 PersistStreamInit_IsDirty
,
569 PersistStreamInit_Load
,
570 PersistStreamInit_Save
,
571 PersistStreamInit_GetSizeMax
,
572 PersistStreamInit_InitNew
575 void HTMLDocument_Persist_Init(HTMLDocument
*This
)
577 This
->lpPersistMonikerVtbl
= &PersistMonikerVtbl
;
578 This
->lpPersistFileVtbl
= &PersistFileVtbl
;
579 This
->lpMonikerPropVtbl
= &MonikerPropVtbl
;
580 This
->lpPersistStreamInitVtbl
= &PersistStreamInitVtbl
;
582 This
->bscallback
= NULL
;