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
34 #include "wine/debug.h"
36 #include "mshtml_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
40 struct BindStatusCallback {
41 const IBindStatusCallbackVtbl *lpBindStatusCallbackVtbl;
51 #define STATUSCLB_THIS(iface) DEFINE_THIS(BindStatusCallback, BindStatusCallback, iface)
53 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
54 REFIID riid, void **ppv)
56 BindStatusCallback *This = STATUSCLB_THIS(iface);
59 if(IsEqualGUID(&IID_IUnknown, riid)) {
60 TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppv);
61 *ppv = STATUSCLB(This);
62 }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) {
63 TRACE("(%p)->(IID_IBindStatusCallback, %p)\n", This, ppv);
64 *ppv = STATUSCLB(This);
68 IBindStatusCallback_AddRef(STATUSCLB(This));
72 TRACE("Unsupported riid = %s\n", debugstr_guid(riid));
76 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
78 BindStatusCallback *This = STATUSCLB_THIS(iface);
79 LONG ref = InterlockedIncrement(&This->ref);
81 TRACE("(%p) ref = %ld\n", This, ref);
86 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
88 BindStatusCallback *This = STATUSCLB_THIS(iface);
89 LONG ref = InterlockedDecrement(&This->ref);
91 TRACE("(%p) ref = %ld\n", This, ref);
94 if(This->doc->status_callback == This)
95 This->doc->status_callback = NULL;
96 IHTMLDocument2_Release(HTMLDOC(This->doc));
98 IStream_Release(This->stream);
99 CoTaskMemFree(This->url);
100 HeapFree(GetProcessHeap(), 0, This);
106 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
107 DWORD dwReserved, IBinding *pbind)
109 BindStatusCallback *This = STATUSCLB_THIS(iface);
111 TRACE("(%p)->(%ld %p)\n", This, dwReserved, pbind);
113 This->binding = pbind;
114 IBinding_AddRef(pbind);
116 if(This->doc->nscontainer && This->doc->nscontainer->stream) {
117 nsACString *strTextHtml;
119 nsIURI *uri = get_nsIURI(This->url);
121 strTextHtml = nsACString_Create();
122 /* FIXME: Set it correctly */
123 nsACString_SetData(strTextHtml, "text/html");
125 nsres = nsIWebBrowserStream_OpenStream(This->doc->nscontainer->stream, uri, strTextHtml);
127 ERR("OpenStream failed: %08lx\n", nsres);
135 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface, LONG *pnPriority)
137 BindStatusCallback *This = STATUSCLB_THIS(iface);
138 FIXME("(%p)->(%p)\n", This, pnPriority);
142 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface, DWORD reserved)
144 BindStatusCallback *This = STATUSCLB_THIS(iface);
145 FIXME("(%p)->(%ld)\n", This, reserved);
149 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
150 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
152 BindStatusCallback *This = STATUSCLB_THIS(iface);
153 TRACE("%p)->(%lu %lu %lu %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
154 debugstr_w(szStatusText));
158 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
159 HRESULT hresult, LPCWSTR szError)
161 BindStatusCallback *This = STATUSCLB_THIS(iface);
163 TRACE("(%p)->(%08lx %s)\n", This, hresult, debugstr_w(szError));
165 if(This->doc->nscontainer && This->doc->nscontainer->stream)
166 nsIWebBrowserStream_CloseStream(This->doc->nscontainer->stream);
168 IBinding_Release(This->binding);
169 This->binding = NULL;
173 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
174 DWORD *grfBINDF, BINDINFO *pbindinfo)
176 BindStatusCallback *This = STATUSCLB_THIS(iface);
179 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
181 *grfBINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
182 size = pbindinfo->cbSize;
183 memset(pbindinfo, 0, size);
184 pbindinfo->cbSize = size;
189 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
190 DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
192 BindStatusCallback *This = STATUSCLB_THIS(iface);
194 TRACE("(%p)->(%08lx %ld %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
197 This->stream = pstgmed->u.pstm;
198 IStream_AddRef(This->stream);
201 if(This->doc->nscontainer && This->doc->nscontainer->stream) {
208 hres = IStream_Read(This->stream, buf, size, &size);
209 nsIWebBrowserStream_AppendToStream(This->doc->nscontainer->stream, buf, size);
210 }while(hres == S_OK);
216 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
217 REFIID riid, IUnknown *punk)
219 BindStatusCallback *This = STATUSCLB_THIS(iface);
220 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
224 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
225 BindStatusCallback_QueryInterface,
226 BindStatusCallback_AddRef,
227 BindStatusCallback_Release,
228 BindStatusCallback_OnStartBinding,
229 BindStatusCallback_GetPriority,
230 BindStatusCallback_OnLowResource,
231 BindStatusCallback_OnProgress,
232 BindStatusCallback_OnStopBinding,
233 BindStatusCallback_GetBindInfo,
234 BindStatusCallback_OnDataAvailable,
235 BindStatusCallback_OnObjectAvailable
238 static BindStatusCallback *BindStatusCallback_Create(HTMLDocument *doc, LPOLESTR url)
240 BindStatusCallback *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(BindStatusCallback));
241 ret->lpBindStatusCallbackVtbl = &BindStatusCallbackVtbl;
246 IHTMLDocument2_AddRef(HTMLDOC(doc));
250 /**********************************************************
251 * IPersistMoniker implementation
254 #define PERSISTMON_THIS(iface) DEFINE_THIS(HTMLDocument, PersistMoniker, iface)
256 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid,
259 HTMLDocument *This = PERSISTMON_THIS(iface);
260 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
263 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
265 HTMLDocument *This = PERSISTMON_THIS(iface);
266 return IHTMLDocument2_AddRef(HTMLDOC(This));
269 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
271 HTMLDocument *This = PERSISTMON_THIS(iface);
272 return IHTMLDocument2_Release(HTMLDOC(This));
275 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
277 HTMLDocument *This = PERSISTMON_THIS(iface);
278 return IPersist_GetClassID(PERSIST(This), pClassID);
281 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
283 HTMLDocument *This = PERSISTMON_THIS(iface);
284 FIXME("(%p)\n", This);
288 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
289 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
291 HTMLDocument *This = PERSISTMON_THIS(iface);
293 BindStatusCallback *callback;
299 TRACE("(%p)->(%x %p %p %08lx)\n", This, fFullyAvailable, pimkName, pibc, grfMode);
302 IUnknown *unk = NULL;
304 static WCHAR wszClientSiteParam[] = {'{','d','4','d','b','6','8','5','0','-',
305 '5','3','8','5','-','1','1','d','0','-','8','9','e','9','-','0','0','a',
306 '0','c','9','0','a','9','0','a','c','}',0};
310 * "__PrecreatedObject"
311 * "BIND_CONTEXT_PARAM"
312 * "__HTMLLOADOPTIONS"
316 * "_ITransData_Object_"
320 IBindCtx_GetObjectParam(pibc, wszClientSiteParam, &unk);
322 IOleClientSite *client = NULL;
324 hres = IUnknown_QueryInterface(unk, &IID_IOleClientSite, (void**)&client);
325 if(SUCCEEDED(hres)) {
326 TRACE("Got client site %p\n", client);
327 IOleObject_SetClientSite(OLEOBJ(This), client);
328 IOleClientSite_Release(client);
331 IUnknown_Release(unk);
335 HTMLDocument_LockContainer(This, TRUE);
337 hres = IMoniker_GetDisplayName(pimkName, pibc, NULL, &url);
339 WARN("GetDiaplayName failed: %08lx\n", hres);
343 TRACE("got url: %s\n", debugstr_w(url));
346 IOleCommandTarget *cmdtrg = NULL;
348 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget,
350 if(SUCCEEDED(hres)) {
355 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
359 if(This->nscontainer && !This->nscontainer->stream) {
361 * This is a workaround for older Gecko that doesn't support nsIWebBrowserStream.
362 * It uses Gecko's LoadURI instead of IMoniker's BindToStorage. Should we improve
363 * it (to do so we'd have to use not frozen interfaces)?
365 nsres = nsIWebNavigation_LoadURI(This->nscontainer->navigation, url,
366 LOAD_FLAGS_NONE, NULL, NULL, NULL);
367 if(NS_SUCCEEDED(nsres)) {
371 WARN("LoadURI failed: %08lx\n", nsres);
375 /* FIXME: Use grfMode */
378 FIXME("not supported fFullyAvailable\n");
380 if(This->status_callback && This->status_callback->binding)
381 IBinding_Abort(This->status_callback->binding);
383 callback = This->status_callback = BindStatusCallback_Create(This, url);
387 RegisterBindStatusCallback(pbind, STATUSCLB(callback), NULL, 0);
389 CreateAsyncBindCtx(0, STATUSCLB(callback), NULL, &pbind);
392 hres = IMoniker_BindToStorage(pimkName, pbind, NULL, &IID_IStream, (void**)&str);
395 IBindCtx_Release(pbind);
397 IStream_Release(str);
399 WARN("BindToStorage failed: %08lx\n", hres);
406 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName,
407 LPBC pbc, BOOL fRemember)
409 HTMLDocument *This = PERSISTMON_THIS(iface);
410 FIXME("(%p)->(%p %p %x)\n", This, pimkName, pbc, fRemember);
414 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
416 HTMLDocument *This = PERSISTMON_THIS(iface);
417 FIXME("(%p)->(%p %p)\n", This, pimkName, pibc);
421 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **ppimkName)
423 HTMLDocument *This = PERSISTMON_THIS(iface);
424 FIXME("(%p)->(%p)\n", This, ppimkName);
428 static const IPersistMonikerVtbl PersistMonikerVtbl = {
429 PersistMoniker_QueryInterface,
430 PersistMoniker_AddRef,
431 PersistMoniker_Release,
432 PersistMoniker_GetClassID,
433 PersistMoniker_IsDirty,
436 PersistMoniker_SaveCompleted,
437 PersistMoniker_GetCurMoniker
440 /**********************************************************
441 * IMonikerProp implementation
444 #define MONPROP_THIS(iface) DEFINE_THIS(HTMLDocument, MonikerProp, iface)
446 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppvObject)
448 HTMLDocument *This = MONPROP_THIS(iface);
449 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
452 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
454 HTMLDocument *This = MONPROP_THIS(iface);
455 return IHTMLDocument2_AddRef(HTMLDOC(This));
458 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
460 HTMLDocument *This = MONPROP_THIS(iface);
461 return IHTMLDocument_Release(HTMLDOC(This));
464 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
466 HTMLDocument *This = MONPROP_THIS(iface);
467 FIXME("(%p)->(%d %s)\n", This, mkp, debugstr_w(val));
471 static const IMonikerPropVtbl MonikerPropVtbl = {
472 MonikerProp_QueryInterface,
475 MonikerProp_PutProperty
478 /**********************************************************
479 * IPersistFile implementation
482 #define PERSISTFILE_THIS(iface) DEFINE_THIS(HTMLDocument, PersistFile, iface)
484 static HRESULT WINAPI PersistFile_QueryInterface(IPersistFile *iface, REFIID riid, void **ppvObject)
486 HTMLDocument *This = PERSISTFILE_THIS(iface);
487 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
490 static ULONG WINAPI PersistFile_AddRef(IPersistFile *iface)
492 HTMLDocument *This = PERSISTFILE_THIS(iface);
493 return IHTMLDocument2_AddRef(HTMLDOC(This));
496 static ULONG WINAPI PersistFile_Release(IPersistFile *iface)
498 HTMLDocument *This = PERSISTFILE_THIS(iface);
499 return IHTMLDocument2_Release(HTMLDOC(This));
502 static HRESULT WINAPI PersistFile_GetClassID(IPersistFile *iface, CLSID *pClassID)
504 HTMLDocument *This = PERSISTFILE_THIS(iface);
506 TRACE("(%p)->(%p)\n", This, pClassID);
511 memcpy(pClassID, &CLSID_HTMLDocument, sizeof(CLSID));
515 static HRESULT WINAPI PersistFile_IsDirty(IPersistFile *iface)
517 HTMLDocument *This = PERSISTFILE_THIS(iface);
518 FIXME("(%p)\n", This);
522 static HRESULT WINAPI PersistFile_Load(IPersistFile *iface, LPCOLESTR pszFileName, DWORD dwMode)
524 HTMLDocument *This = PERSISTFILE_THIS(iface);
525 FIXME("(%p)->(%s %08lx)\n", This, debugstr_w(pszFileName), dwMode);
529 static HRESULT WINAPI PersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileName, BOOL fRemember)
531 HTMLDocument *This = PERSISTFILE_THIS(iface);
532 FIXME("(%p)->(%s %x)\n", This, debugstr_w(pszFileName), fRemember);
536 static HRESULT WINAPI PersistFile_SaveCompleted(IPersistFile *iface, LPCOLESTR pszFileName)
538 HTMLDocument *This = PERSISTFILE_THIS(iface);
539 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFileName));
543 static HRESULT WINAPI PersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *pszFileName)
545 HTMLDocument *This = PERSISTFILE_THIS(iface);
546 FIXME("(%p)->(%p)\n", This, pszFileName);
550 static const IPersistFileVtbl PersistFileVtbl = {
551 PersistFile_QueryInterface,
554 PersistFile_GetClassID,
558 PersistFile_SaveCompleted,
559 PersistFile_GetCurFile
562 void HTMLDocument_Persist_Init(HTMLDocument *This)
564 This->lpPersistMonikerVtbl = &PersistMonikerVtbl;
565 This->lpPersistFileVtbl = &PersistFileVtbl;
566 This->lpMonikerPropVtbl = &MonikerPropVtbl;
568 This->status_callback = NULL;