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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
33 #include "wine/debug.h"
35 #include "mshtml_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 struct BindStatusCallback {
40 const IBindStatusCallbackVtbl *lpBindStatusCallbackVtbl;
50 #define STATUSCLB_THIS(iface) DEFINE_THIS(BindStatusCallback, BindStatusCallback, iface)
52 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
53 REFIID riid, void **ppv)
55 BindStatusCallback *This = STATUSCLB_THIS(iface);
58 if(IsEqualGUID(&IID_IUnknown, riid)) {
59 TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppv);
60 *ppv = STATUSCLB(This);
61 }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) {
62 TRACE("(%p)->(IID_IBindStatusCallback, %p)\n", This, ppv);
63 *ppv = STATUSCLB(This);
67 IBindStatusCallback_AddRef(STATUSCLB(This));
71 TRACE("Unsupported riid = %s\n", debugstr_guid(riid));
75 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
77 BindStatusCallback *This = STATUSCLB_THIS(iface);
78 LONG ref = InterlockedIncrement(&This->ref);
80 TRACE("(%p) ref = %ld\n", This, ref);
85 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
87 BindStatusCallback *This = STATUSCLB_THIS(iface);
88 LONG ref = InterlockedDecrement(&This->ref);
90 TRACE("(%p) ref = %ld\n", This, ref);
93 if(This->doc->status_callback == This)
94 This->doc->status_callback = NULL;
95 IHTMLDocument2_Release(HTMLDOC(This->doc));
97 IStream_Release(This->stream);
98 CoTaskMemFree(This->url);
99 HeapFree(GetProcessHeap(), 0, This);
105 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
106 DWORD dwReserved, IBinding *pbind)
108 BindStatusCallback *This = STATUSCLB_THIS(iface);
110 TRACE("(%p)->(%ld %p)\n", This, dwReserved, pbind);
112 This->binding = pbind;
113 IBinding_AddRef(pbind);
115 if(This->doc->nscontainer && This->doc->nscontainer->stream) {
116 nsACString *strTextHtml;
118 nsIURI *uri = get_nsIURI(This->url);
120 strTextHtml = nsACString_Create();
121 /* FIXME: Set it correctly */
122 nsACString_SetData(strTextHtml, "text/html");
124 nsres = nsIWebBrowserStream_OpenStream(This->doc->nscontainer->stream, uri, strTextHtml);
126 ERR("OpenStream failed: %08lx\n", nsres);
134 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface, LONG *pnPriority)
136 BindStatusCallback *This = STATUSCLB_THIS(iface);
137 FIXME("(%p)->(%p)\n", This, pnPriority);
141 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface, DWORD reserved)
143 BindStatusCallback *This = STATUSCLB_THIS(iface);
144 FIXME("(%p)->(%ld)\n", This, reserved);
148 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
149 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
151 BindStatusCallback *This = STATUSCLB_THIS(iface);
152 TRACE("%p)->(%lu %lu %lu %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
153 debugstr_w(szStatusText));
157 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
158 HRESULT hresult, LPCWSTR szError)
160 BindStatusCallback *This = STATUSCLB_THIS(iface);
162 TRACE("(%p)->(%08lx %s)\n", This, hresult, debugstr_w(szError));
164 if(This->doc->nscontainer && This->doc->nscontainer->stream)
165 nsIWebBrowserStream_CloseStream(This->doc->nscontainer->stream);
167 IBinding_Release(This->binding);
168 This->binding = NULL;
172 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
173 DWORD *grfBINDF, BINDINFO *pbindinfo)
175 BindStatusCallback *This = STATUSCLB_THIS(iface);
178 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
180 *grfBINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
181 size = pbindinfo->cbSize;
182 memset(pbindinfo, 0, size);
183 pbindinfo->cbSize = size;
188 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
189 DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
191 BindStatusCallback *This = STATUSCLB_THIS(iface);
193 TRACE("(%p)->(%08lx %ld %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
196 This->stream = pstgmed->u.pstm;
197 IStream_AddRef(This->stream);
200 if(This->doc->nscontainer && This->doc->nscontainer->stream) {
207 hres = IStream_Read(This->stream, buf, size, &size);
208 nsIWebBrowserStream_AppendToStream(This->doc->nscontainer->stream, buf, size);
209 }while(hres == S_OK);
215 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
216 REFIID riid, IUnknown *punk)
218 BindStatusCallback *This = STATUSCLB_THIS(iface);
219 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
223 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
224 BindStatusCallback_QueryInterface,
225 BindStatusCallback_AddRef,
226 BindStatusCallback_Release,
227 BindStatusCallback_OnStartBinding,
228 BindStatusCallback_GetPriority,
229 BindStatusCallback_OnLowResource,
230 BindStatusCallback_OnProgress,
231 BindStatusCallback_OnStopBinding,
232 BindStatusCallback_GetBindInfo,
233 BindStatusCallback_OnDataAvailable,
234 BindStatusCallback_OnObjectAvailable
237 static BindStatusCallback *BindStatusCallback_Create(HTMLDocument *doc, LPOLESTR url)
239 BindStatusCallback *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(BindStatusCallback));
240 ret->lpBindStatusCallbackVtbl = &BindStatusCallbackVtbl;
245 IHTMLDocument2_AddRef(HTMLDOC(doc));
249 /**********************************************************
250 * IPersistMoniker implementation
253 #define PERSISTMON_THIS(iface) DEFINE_THIS(HTMLDocument, PersistMoniker, iface)
255 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid,
258 HTMLDocument *This = PERSISTMON_THIS(iface);
259 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
262 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
264 HTMLDocument *This = PERSISTMON_THIS(iface);
265 return IHTMLDocument2_AddRef(HTMLDOC(This));
268 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
270 HTMLDocument *This = PERSISTMON_THIS(iface);
271 return IHTMLDocument2_Release(HTMLDOC(This));
274 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
276 HTMLDocument *This = PERSISTMON_THIS(iface);
277 return IPersist_GetClassID(PERSIST(This), pClassID);
280 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
282 HTMLDocument *This = PERSISTMON_THIS(iface);
283 FIXME("(%p)\n", This);
287 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
288 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
290 HTMLDocument *This = PERSISTMON_THIS(iface);
292 BindStatusCallback *callback;
298 FIXME("(%p)->(%x %p %p %08lx)\n", This, fFullyAvailable, pimkName, pibc, grfMode);
301 IUnknown *unk = NULL;
303 static WCHAR wszClientSiteParam[] = {'{','d','4','d','b','6','8','5','0','-',
304 '5','3','8','5','-','1','1','d','0','-','8','9','e','9','-','0','0','a',
305 '0','c','9','0','a','9','0','a','c','}',0};
309 * "__PrecreatedObject"
310 * "BIND_CONTEXT_PARAM"
311 * "__HTMLLOADOPTIONS"
315 * "_ITransData_Object_"
319 IBindCtx_GetObjectParam(pibc, wszClientSiteParam, &unk);
321 IOleClientSite *client = NULL;
323 hres = IUnknown_QueryInterface(unk, &IID_IOleClientSite, (void**)&client);
324 if(SUCCEEDED(hres)) {
325 TRACE("Got client site %p\n", client);
326 IOleObject_SetClientSite(OLEOBJ(This), client);
327 IOleClientSite_Release(client);
330 IUnknown_Release(unk);
334 hres = IMoniker_GetDisplayName(pimkName, pibc, NULL, &url);
336 WARN("GetDiaplayName failed: %08lx\n", hres);
340 TRACE("got url: %s\n", debugstr_w(url));
342 if(This->nscontainer && !This->nscontainer->stream) {
344 * This is a workaround for older Gecko that doesn't support nsIWebBrowserStream.
345 * It uses Gecko's LoadURI instead of IMoniker's BindToStorage. Should we improve
346 * it (to do so we'd have to use not frozen interfaces)?
348 nsres = nsIWebNavigation_LoadURI(This->nscontainer->navigation, url,
349 LOAD_FLAGS_NONE, NULL, NULL, NULL);
350 if(NS_SUCCEEDED(nsres)) {
354 WARN("LoadURI failed: %08lx\n", nsres);
358 /* FIXME: Use grfMode */
361 FIXME("not supported fFullyAvailable\n");
363 if(This->status_callback && This->status_callback->binding)
364 IBinding_Abort(This->status_callback->binding);
366 callback = This->status_callback = BindStatusCallback_Create(This, url);
370 RegisterBindStatusCallback(pbind, STATUSCLB(callback), NULL, 0);
372 CreateAsyncBindCtx(0, STATUSCLB(callback), NULL, &pbind);
375 hres = IMoniker_BindToStorage(pimkName, pbind, NULL, &IID_IStream, (void**)&str);
378 IBindCtx_Release(pbind);
380 IStream_Release(str);
382 WARN("BindToStorage failed: %08lx\n", hres);
389 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName,
390 LPBC pbc, BOOL fRemember)
392 HTMLDocument *This = PERSISTMON_THIS(iface);
393 FIXME("(%p)->(%p %p %x)\n", This, pimkName, pbc, fRemember);
397 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
399 HTMLDocument *This = PERSISTMON_THIS(iface);
400 FIXME("(%p)->(%p %p)\n", This, pimkName, pibc);
404 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **ppimkName)
406 HTMLDocument *This = PERSISTMON_THIS(iface);
407 FIXME("(%p)->(%p)\n", This, ppimkName);
411 static const IPersistMonikerVtbl PersistMonikerVtbl = {
412 PersistMoniker_QueryInterface,
413 PersistMoniker_AddRef,
414 PersistMoniker_Release,
415 PersistMoniker_GetClassID,
416 PersistMoniker_IsDirty,
419 PersistMoniker_SaveCompleted,
420 PersistMoniker_GetCurMoniker
423 /**********************************************************
424 * IMonikerProp implementation
427 #define MONPROP_THIS(iface) DEFINE_THIS(HTMLDocument, MonikerProp, iface)
429 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppvObject)
431 HTMLDocument *This = MONPROP_THIS(iface);
432 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
435 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
437 HTMLDocument *This = MONPROP_THIS(iface);
438 return IHTMLDocument2_AddRef(HTMLDOC(This));
441 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
443 HTMLDocument *This = MONPROP_THIS(iface);
444 return IHTMLDocument_Release(HTMLDOC(This));
447 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
449 HTMLDocument *This = MONPROP_THIS(iface);
450 FIXME("(%p)->(%d %s)\n", This, mkp, debugstr_w(val));
454 static const IMonikerPropVtbl MonikerPropVtbl = {
455 MonikerProp_QueryInterface,
458 MonikerProp_PutProperty
461 /**********************************************************
462 * IPersistFile implementation
465 #define PERSISTFILE_THIS(iface) DEFINE_THIS(HTMLDocument, PersistFile, iface)
467 static HRESULT WINAPI PersistFile_QueryInterface(IPersistFile *iface, REFIID riid, void **ppvObject)
469 HTMLDocument *This = PERSISTFILE_THIS(iface);
470 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
473 static ULONG WINAPI PersistFile_AddRef(IPersistFile *iface)
475 HTMLDocument *This = PERSISTFILE_THIS(iface);
476 return IHTMLDocument2_AddRef(HTMLDOC(This));
479 static ULONG WINAPI PersistFile_Release(IPersistFile *iface)
481 HTMLDocument *This = PERSISTFILE_THIS(iface);
482 return IHTMLDocument2_Release(HTMLDOC(This));
485 static HRESULT WINAPI PersistFile_GetClassID(IPersistFile *iface, CLSID *pClassID)
487 HTMLDocument *This = PERSISTFILE_THIS(iface);
489 TRACE("(%p)->(%p)\n", This, pClassID);
494 memcpy(pClassID, &CLSID_HTMLDocument, sizeof(CLSID));
498 static HRESULT WINAPI PersistFile_IsDirty(IPersistFile *iface)
500 HTMLDocument *This = PERSISTFILE_THIS(iface);
501 FIXME("(%p)\n", This);
505 static HRESULT WINAPI PersistFile_Load(IPersistFile *iface, LPCOLESTR pszFileName, DWORD dwMode)
507 HTMLDocument *This = PERSISTFILE_THIS(iface);
508 FIXME("(%p)->(%s %08lx)\n", This, debugstr_w(pszFileName), dwMode);
512 static HRESULT WINAPI PersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileName, BOOL fRemember)
514 HTMLDocument *This = PERSISTFILE_THIS(iface);
515 FIXME("(%p)->(%s %x)\n", This, debugstr_w(pszFileName), fRemember);
519 static HRESULT WINAPI PersistFile_SaveCompleted(IPersistFile *iface, LPCOLESTR pszFileName)
521 HTMLDocument *This = PERSISTFILE_THIS(iface);
522 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFileName));
526 static HRESULT WINAPI PersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *pszFileName)
528 HTMLDocument *This = PERSISTFILE_THIS(iface);
529 FIXME("(%p)->(%p)\n", This, pszFileName);
533 static const IPersistFileVtbl PersistFileVtbl = {
534 PersistFile_QueryInterface,
537 PersistFile_GetClassID,
541 PersistFile_SaveCompleted,
542 PersistFile_GetCurFile
545 void HTMLDocument_Persist_Init(HTMLDocument *This)
547 This->lpPersistMonikerVtbl = &PersistMonikerVtbl;
548 This->lpPersistFileVtbl = &PersistFileVtbl;
549 This->lpMonikerPropVtbl = &MonikerPropVtbl;
551 This->status_callback = NULL;