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);
300 hres = IMoniker_GetDisplayName(pimkName, pibc, NULL, &url);
302 WARN("GetDiaplayName failed: %08lx\n", hres);
306 TRACE("got url: %s\n", debugstr_w(url));
308 if(This->nscontainer && !This->nscontainer->stream) {
310 * This is a workaround for older Gecko that doesn't support nsIWebBrowserStream.
311 * It uses Gecko's LoadURI instead of IMoniker's BindToStorage. Should we improve
312 * it (to do so we'd have to use not frozen interfaces)?
314 nsres = nsIWebNavigation_LoadURI(This->nscontainer->navigation, url,
315 LOAD_FLAGS_NONE, NULL, NULL, NULL);
316 if(NS_SUCCEEDED(nsres)) {
320 WARN("LoadURI failed: %08lx\n", nsres);
324 /* FIXME: Use grfMode */
327 FIXME("not supported fFullyAvailable\n");
329 FIXME("not supported pibc\n");
331 if(This->status_callback && This->status_callback->binding)
332 IBinding_Abort(This->status_callback->binding);
334 callback = This->status_callback = BindStatusCallback_Create(This, url);
336 CreateAsyncBindCtx(0, STATUSCLB(callback), NULL, &pbind);
338 hres = IMoniker_BindToStorage(pimkName, pbind, NULL, &IID_IStream, (void**)&str);
339 IBindCtx_Release(pbind);
341 IStream_Release(str);
343 WARN("BindToStorage failed: %08lx\n", hres);
350 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName,
351 LPBC pbc, BOOL fRemember)
353 HTMLDocument *This = PERSISTMON_THIS(iface);
354 FIXME("(%p)->(%p %p %x)\n", This, pimkName, pbc, fRemember);
358 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
360 HTMLDocument *This = PERSISTMON_THIS(iface);
361 FIXME("(%p)->(%p %p)\n", This, pimkName, pibc);
365 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **ppimkName)
367 HTMLDocument *This = PERSISTMON_THIS(iface);
368 FIXME("(%p)->(%p)\n", This, ppimkName);
372 static const IPersistMonikerVtbl PersistMonikerVtbl = {
373 PersistMoniker_QueryInterface,
374 PersistMoniker_AddRef,
375 PersistMoniker_Release,
376 PersistMoniker_GetClassID,
377 PersistMoniker_IsDirty,
380 PersistMoniker_SaveCompleted,
381 PersistMoniker_GetCurMoniker
384 /**********************************************************
385 * IMonikerProp implementation
388 #define MONPROP_THIS(iface) DEFINE_THIS(HTMLDocument, MonikerProp, iface)
390 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppvObject)
392 HTMLDocument *This = MONPROP_THIS(iface);
393 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
396 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
398 HTMLDocument *This = MONPROP_THIS(iface);
399 return IHTMLDocument2_AddRef(HTMLDOC(This));
402 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
404 HTMLDocument *This = MONPROP_THIS(iface);
405 return IHTMLDocument_Release(HTMLDOC(This));
408 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
410 HTMLDocument *This = MONPROP_THIS(iface);
411 FIXME("(%p)->(%d %s)\n", This, mkp, debugstr_w(val));
415 static const IMonikerPropVtbl MonikerPropVtbl = {
416 MonikerProp_QueryInterface,
419 MonikerProp_PutProperty
422 /**********************************************************
423 * IPersistFile implementation
426 #define PERSISTFILE_THIS(iface) DEFINE_THIS(HTMLDocument, PersistFile, iface)
428 static HRESULT WINAPI PersistFile_QueryInterface(IPersistFile *iface, REFIID riid, void **ppvObject)
430 HTMLDocument *This = PERSISTFILE_THIS(iface);
431 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
434 static ULONG WINAPI PersistFile_AddRef(IPersistFile *iface)
436 HTMLDocument *This = PERSISTFILE_THIS(iface);
437 return IHTMLDocument2_AddRef(HTMLDOC(This));
440 static ULONG WINAPI PersistFile_Release(IPersistFile *iface)
442 HTMLDocument *This = PERSISTFILE_THIS(iface);
443 return IHTMLDocument2_Release(HTMLDOC(This));
446 static HRESULT WINAPI PersistFile_GetClassID(IPersistFile *iface, CLSID *pClassID)
448 HTMLDocument *This = PERSISTFILE_THIS(iface);
450 TRACE("(%p)->(%p)\n", This, pClassID);
455 memcpy(pClassID, &CLSID_HTMLDocument, sizeof(CLSID));
459 static HRESULT WINAPI PersistFile_IsDirty(IPersistFile *iface)
461 HTMLDocument *This = PERSISTFILE_THIS(iface);
462 FIXME("(%p)\n", This);
466 static HRESULT WINAPI PersistFile_Load(IPersistFile *iface, LPCOLESTR pszFileName, DWORD dwMode)
468 HTMLDocument *This = PERSISTFILE_THIS(iface);
469 FIXME("(%p)->(%s %08lx)\n", This, debugstr_w(pszFileName), dwMode);
473 static HRESULT WINAPI PersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileName, BOOL fRemember)
475 HTMLDocument *This = PERSISTFILE_THIS(iface);
476 FIXME("(%p)->(%s %x)\n", This, debugstr_w(pszFileName), fRemember);
480 static HRESULT WINAPI PersistFile_SaveCompleted(IPersistFile *iface, LPCOLESTR pszFileName)
482 HTMLDocument *This = PERSISTFILE_THIS(iface);
483 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFileName));
487 static HRESULT WINAPI PersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *pszFileName)
489 HTMLDocument *This = PERSISTFILE_THIS(iface);
490 FIXME("(%p)->(%p)\n", This, pszFileName);
494 static const IPersistFileVtbl PersistFileVtbl = {
495 PersistFile_QueryInterface,
498 PersistFile_GetClassID,
502 PersistFile_SaveCompleted,
503 PersistFile_GetCurFile
506 void HTMLDocument_Persist_Init(HTMLDocument *This)
508 This->lpPersistMonikerVtbl = &PersistMonikerVtbl;
509 This->lpPersistFileVtbl = &PersistFileVtbl;
510 This->lpMonikerPropVtbl = &MonikerPropVtbl;
512 This->status_callback = NULL;