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 #define NO_SHLWAPI_REG
38 #include "wine/debug.h"
40 #include "mshtml_private.h"
41 #include "htmlscript.h"
42 #include "htmlevent.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
48 /* Undocumented notification, see tests */
49 #define CMDID_EXPLORER_UPDATEHISTORY 38
51 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
58 } download_proc_task_t;
60 static BOOL use_gecko_script(HTMLOuterWindow *window)
65 hres = IInternetSecurityManager_MapUrlToZone(window->secmgr, window->url, &zone, 0);
67 WARN("Could not map %s to zone: %08x\n", debugstr_w(window->url), hres);
71 TRACE("zone %d\n", zone);
72 return zone == URLZONE_UNTRUSTED;
75 static void notify_travellog_update(HTMLDocumentObj *doc)
77 IOleCommandTarget *cmdtrg;
80 if(!doc->is_webbrowser)
83 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
90 IOleCommandTarget_Exec(cmdtrg, &CGID_Explorer, CMDID_EXPLORER_UPDATEHISTORY, 0, &vin, NULL);
91 IOleCommandTarget_Release(cmdtrg);
95 void set_current_uri(HTMLOuterWindow *window, IUri *uri)
98 IUri_Release(window->uri);
102 if(window->uri_nofrag) {
103 IUri_Release(window->uri_nofrag);
104 window->uri_nofrag = NULL;
107 SysFreeString(window->url);
116 window->uri_nofrag = get_uri_nofrag(uri);
117 if(!window->uri_nofrag) {
118 FIXME("get_uri_nofrag failed\n");
120 window->uri_nofrag = uri;
123 IUri_GetDisplayUri(uri, &window->url);
126 void set_current_mon(HTMLOuterWindow *This, IMoniker *mon, DWORD flags)
128 IUriContainer *uri_container;
133 if(This->doc_obj && !(flags & (BINDING_REPLACE|BINDING_REFRESH)))
134 notify_travellog_update(This->doc_obj);
135 IMoniker_Release(This->mon);
139 This->load_flags = flags;
143 IMoniker_AddRef(mon);
146 hres = IMoniker_QueryInterface(mon, &IID_IUriContainer, (void**)&uri_container);
147 if(SUCCEEDED(hres)) {
148 hres = IUriContainer_GetIUri(uri_container, &uri);
149 IUriContainer_Release(uri_container);
151 WARN("GetIUri failed: %08x\n", hres);
159 hres = IMoniker_GetDisplayName(mon, NULL, NULL, &url);
160 if(SUCCEEDED(hres)) {
161 hres = CreateUri(url, 0, 0, &uri);
163 WARN("CrateUri failed: %08x\n", hres);
164 set_current_uri(This, NULL);
165 This->url = SysAllocString(url);
171 WARN("GetDisplayName failed: %08x\n", hres);
175 set_current_uri(This, uri);
178 set_script_mode(This, use_gecko_script(This) ? SCRIPTMODE_GECKO : SCRIPTMODE_ACTIVESCRIPT);
181 HRESULT create_relative_uri(HTMLOuterWindow *window, const WCHAR *rel_uri, IUri **uri)
184 ? CoInternetCombineUrlEx(window->uri, rel_uri, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO, uri, 0)
185 : CreateUri(rel_uri, 0, 0, uri);
188 void set_download_state(HTMLDocumentObj *doc, int state)
191 IOleCommandTarget *olecmd;
194 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
195 if(SUCCEEDED(hres)) {
201 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETDOWNLOADSTATE,
202 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
203 IOleCommandTarget_Release(olecmd);
207 doc->download_state = state;
210 static void set_progress_proc(task_t *_task)
212 docobj_task_t *task = (docobj_task_t*)_task;
213 IOleCommandTarget *olecmd = NULL;
214 HTMLDocumentObj *doc = task->doc;
217 TRACE("(%p)\n", doc);
220 IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
223 VARIANT progress_max, progress;
225 V_VT(&progress_max) = VT_I4;
226 V_I4(&progress_max) = 0; /* FIXME */
227 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSMAX, OLECMDEXECOPT_DONTPROMPTUSER,
228 &progress_max, NULL);
230 V_VT(&progress) = VT_I4;
231 V_I4(&progress) = 0; /* FIXME */
232 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSPOS, OLECMDEXECOPT_DONTPROMPTUSER,
234 IOleCommandTarget_Release(olecmd);
237 if(doc->usermode == EDITMODE && doc->hostui) {
238 DOCHOSTUIINFO hostinfo;
240 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
241 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
242 hres = IDocHostUIHandler_GetHostInfo(doc->hostui, &hostinfo);
244 /* FIXME: use hostinfo */
245 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
246 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
247 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
251 static void set_downloading_proc(task_t *_task)
253 download_proc_task_t *task = (download_proc_task_t*)_task;
254 HTMLDocumentObj *doc = task->doc;
257 TRACE("(%p)\n", doc);
259 set_statustext(doc, IDS_STATUS_DOWNLOADINGFROM, task->url);
261 if(task->set_download)
262 set_download_state(doc, 1);
268 IAdviseSink_OnViewChange(doc->view_sink, DVASPECT_CONTENT, -1);
271 IDropTarget *drop_target = NULL;
273 hres = IDocHostUIHandler_GetDropTarget(doc->hostui, NULL /* FIXME */, &drop_target);
274 if(SUCCEEDED(hres) && drop_target) {
275 FIXME("Use IDropTarget\n");
276 IDropTarget_Release(drop_target);
281 static void set_downloading_task_destr(task_t *_task)
283 download_proc_task_t *task = (download_proc_task_t*)_task;
285 CoTaskMemFree(task->url);
289 void prepare_for_binding(HTMLDocument *This, IMoniker *mon, DWORD flags)
293 if(This->doc_obj->client) {
294 VARIANT silent, offline;
296 hres = get_client_disp_property(This->doc_obj->client, DISPID_AMBIENT_SILENT, &silent);
297 if(SUCCEEDED(hres)) {
298 if(V_VT(&silent) != VT_BOOL)
299 WARN("silent = %s\n", debugstr_variant(&silent));
300 else if(V_BOOL(&silent))
301 FIXME("silent == true\n");
304 hres = get_client_disp_property(This->doc_obj->client,
305 DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
306 if(SUCCEEDED(hres)) {
307 if(V_VT(&offline) != VT_BOOL)
308 WARN("offline = %s\n", debugstr_variant(&offline));
309 else if(V_BOOL(&offline))
310 FIXME("offline == true\n");
314 if(This->window->mon) {
315 update_doc(This, UPDATE_TITLE|UPDATE_UI);
317 update_doc(This, UPDATE_TITLE);
318 set_current_mon(This->window, mon, flags);
321 if(This->doc_obj->client) {
322 IOleCommandTarget *cmdtrg = NULL;
324 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget,
326 if(SUCCEEDED(hres)) {
329 if(flags & BINDING_NAVIGATED) {
330 V_VT(&var) = VT_UNKNOWN;
331 V_UNKNOWN(&var) = (IUnknown*)&This->window->base.IHTMLWindow2_iface;
332 V_VT(&out) = VT_EMPTY;
333 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 63, 0, &var, &out);
336 }else if(!(flags & BINDING_FROMHIST)) {
339 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
342 IOleCommandTarget_Release(cmdtrg);
347 HRESULT set_moniker(HTMLDocument *This, IMoniker *mon, IBindCtx *pibc, nsChannelBSC *async_bsc, BOOL set_download)
349 download_proc_task_t *download_task;
350 nsChannelBSC *bscallback;
355 hres = IMoniker_GetDisplayName(mon, pibc, NULL, &url);
357 WARN("GetDiaplayName failed: %08x\n", hres);
361 TRACE("got url: %s\n", debugstr_w(url));
363 set_ready_state(This->window, READYSTATE_LOADING);
365 hres = create_doc_uri(This->window, url, &nsuri);
366 if(SUCCEEDED(hres)) {
368 bscallback = async_bsc;
370 hres = create_channelbsc(mon, NULL, NULL, 0, TRUE, &bscallback);
373 if(SUCCEEDED(hres)) {
374 remove_target_tasks(This->task_magic);
375 abort_window_bindings(This->window->base.inner_window);
377 hres = load_nsuri(This->window, nsuri, bscallback, 0/*LOAD_INITIAL_DOCUMENT_URI*/);
378 nsISupports_Release((nsISupports*)nsuri); /* FIXME */
380 hres = create_pending_window(This->window, bscallback);
381 if(bscallback != async_bsc)
382 IBindStatusCallback_Release(&bscallback->bsc.IBindStatusCallback_iface);
390 HTMLDocument_LockContainer(This->doc_obj, TRUE);
392 if(This->doc_obj->frame) {
395 task = heap_alloc(sizeof(docobj_task_t));
396 task->doc = This->doc_obj;
397 hres = push_task(&task->header, set_progress_proc, NULL, This->doc_obj->basedoc.task_magic);
404 download_task = heap_alloc(sizeof(download_proc_task_t));
405 download_task->doc = This->doc_obj;
406 download_task->set_download = set_download;
407 download_task->url = url;
408 return push_task(&download_task->header, set_downloading_proc, set_downloading_task_destr, This->doc_obj->basedoc.task_magic);
411 void set_ready_state(HTMLOuterWindow *window, READYSTATE readystate)
413 window->readystate = readystate;
415 if(window->doc_obj && window->doc_obj->basedoc.window == window)
416 call_property_onchanged(&window->doc_obj->basedoc.cp_propnotif, DISPID_READYSTATE);
418 fire_event(window->base.inner_window->doc, EVENTID_READYSTATECHANGE, FALSE,
419 window->base.inner_window->doc->node.nsnode, NULL, NULL);
421 if(window->frame_element)
422 fire_event(window->frame_element->element.node.doc, EVENTID_READYSTATECHANGE,
423 TRUE, window->frame_element->element.node.nsnode, NULL, NULL);
426 static HRESULT get_doc_string(HTMLDocumentNode *This, char **str)
435 WARN("NULL nsdoc\n");
439 nsres = nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
440 if(NS_FAILED(nsres)) {
441 ERR("Could not get nsIDOMNode failed: %08x\n", nsres);
445 nsAString_Init(&nsstr, NULL);
446 hres = nsnode_to_nsstring(nsnode, &nsstr);
447 nsIDOMNode_Release(nsnode);
449 nsAString_Finish(&nsstr);
453 nsAString_GetData(&nsstr, &strw);
454 TRACE("%s\n", debugstr_w(strw));
456 *str = heap_strdupWtoA(strw);
458 nsAString_Finish(&nsstr);
461 return E_OUTOFMEMORY;
466 /**********************************************************
467 * IPersistMoniker implementation
470 static inline HTMLDocument *impl_from_IPersistMoniker(IPersistMoniker *iface)
472 return CONTAINING_RECORD(iface, HTMLDocument, IPersistMoniker_iface);
475 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid, void **ppv)
477 HTMLDocument *This = impl_from_IPersistMoniker(iface);
478 return htmldoc_query_interface(This, riid, ppv);
481 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
483 HTMLDocument *This = impl_from_IPersistMoniker(iface);
484 return htmldoc_addref(This);
487 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
489 HTMLDocument *This = impl_from_IPersistMoniker(iface);
490 return htmldoc_release(This);
493 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
495 HTMLDocument *This = impl_from_IPersistMoniker(iface);
496 return IPersistFile_GetClassID(&This->IPersistFile_iface, pClassID);
499 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
501 HTMLDocument *This = impl_from_IPersistMoniker(iface);
503 TRACE("(%p)\n", This);
505 return IPersistStreamInit_IsDirty(&This->IPersistStreamInit_iface);
508 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
509 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
511 HTMLDocument *This = impl_from_IPersistMoniker(iface);
514 TRACE("(%p)->(%x %p %p %08x)\n", This, fFullyAvailable, pimkName, pibc, grfMode);
517 IUnknown *unk = NULL;
521 * "__PrecreatedObject"
522 * "BIND_CONTEXT_PARAM"
523 * "__HTMLLOADOPTIONS"
526 * "_ITransData_Object_"
530 hres = IBindCtx_GetObjectParam(pibc, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM, &unk);
531 if(SUCCEEDED(hres) && unk) {
532 IOleClientSite *client = NULL;
534 hres = IUnknown_QueryInterface(unk, &IID_IOleClientSite, (void**)&client);
535 if(SUCCEEDED(hres)) {
536 TRACE("Got client site %p\n", client);
537 IOleObject_SetClientSite(&This->IOleObject_iface, client);
538 IOleClientSite_Release(client);
541 IUnknown_Release(unk);
545 prepare_for_binding(This, pimkName, FALSE);
546 call_docview_84(This->doc_obj);
547 hres = set_moniker(This, pimkName, pibc, NULL, TRUE);
551 return start_binding(This->window->pending_window, (BSCallback*)This->window->pending_window->bscallback, pibc);
554 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName,
555 LPBC pbc, BOOL fRemember)
557 HTMLDocument *This = impl_from_IPersistMoniker(iface);
558 FIXME("(%p)->(%p %p %x)\n", This, pimkName, pbc, fRemember);
562 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
564 HTMLDocument *This = impl_from_IPersistMoniker(iface);
565 FIXME("(%p)->(%p %p)\n", This, pimkName, pibc);
569 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **ppimkName)
571 HTMLDocument *This = impl_from_IPersistMoniker(iface);
573 TRACE("(%p)->(%p)\n", This, ppimkName);
575 if(!This->window || !This->window->mon)
578 IMoniker_AddRef(This->window->mon);
579 *ppimkName = This->window->mon;
583 static const IPersistMonikerVtbl PersistMonikerVtbl = {
584 PersistMoniker_QueryInterface,
585 PersistMoniker_AddRef,
586 PersistMoniker_Release,
587 PersistMoniker_GetClassID,
588 PersistMoniker_IsDirty,
591 PersistMoniker_SaveCompleted,
592 PersistMoniker_GetCurMoniker
595 /**********************************************************
596 * IMonikerProp implementation
599 static inline HTMLDocument *impl_from_IMonikerProp(IMonikerProp *iface)
601 return CONTAINING_RECORD(iface, HTMLDocument, IMonikerProp_iface);
604 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppv)
606 HTMLDocument *This = impl_from_IMonikerProp(iface);
607 return htmldoc_query_interface(This, riid, ppv);
610 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
612 HTMLDocument *This = impl_from_IMonikerProp(iface);
613 return htmldoc_addref(This);
616 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
618 HTMLDocument *This = impl_from_IMonikerProp(iface);
619 return htmldoc_release(This);
622 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
624 HTMLDocument *This = impl_from_IMonikerProp(iface);
626 TRACE("(%p)->(%d %s)\n", This, mkp, debugstr_w(val));
630 heap_free(This->doc_obj->mime);
631 This->doc_obj->mime = heap_strdupW(val);
638 FIXME("mkp %d\n", mkp);
645 static const IMonikerPropVtbl MonikerPropVtbl = {
646 MonikerProp_QueryInterface,
649 MonikerProp_PutProperty
652 /**********************************************************
653 * IPersistFile implementation
656 static inline HTMLDocument *impl_from_IPersistFile(IPersistFile *iface)
658 return CONTAINING_RECORD(iface, HTMLDocument, IPersistFile_iface);
661 static HRESULT WINAPI PersistFile_QueryInterface(IPersistFile *iface, REFIID riid, void **ppv)
663 HTMLDocument *This = impl_from_IPersistFile(iface);
664 return htmldoc_query_interface(This, riid, ppv);
667 static ULONG WINAPI PersistFile_AddRef(IPersistFile *iface)
669 HTMLDocument *This = impl_from_IPersistFile(iface);
670 return htmldoc_addref(This);
673 static ULONG WINAPI PersistFile_Release(IPersistFile *iface)
675 HTMLDocument *This = impl_from_IPersistFile(iface);
676 return htmldoc_release(This);
679 static HRESULT WINAPI PersistFile_GetClassID(IPersistFile *iface, CLSID *pClassID)
681 HTMLDocument *This = impl_from_IPersistFile(iface);
683 TRACE("(%p)->(%p)\n", This, pClassID);
688 *pClassID = CLSID_HTMLDocument;
692 static HRESULT WINAPI PersistFile_IsDirty(IPersistFile *iface)
694 HTMLDocument *This = impl_from_IPersistFile(iface);
696 TRACE("(%p)\n", This);
698 return IPersistStreamInit_IsDirty(&This->IPersistStreamInit_iface);
701 static HRESULT WINAPI PersistFile_Load(IPersistFile *iface, LPCOLESTR pszFileName, DWORD dwMode)
703 HTMLDocument *This = impl_from_IPersistFile(iface);
704 FIXME("(%p)->(%s %08x)\n", This, debugstr_w(pszFileName), dwMode);
708 static HRESULT WINAPI PersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileName, BOOL fRemember)
710 HTMLDocument *This = impl_from_IPersistFile(iface);
716 TRACE("(%p)->(%s %x)\n", This, debugstr_w(pszFileName), fRemember);
718 file = CreateFileW(pszFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
719 FILE_ATTRIBUTE_NORMAL, NULL);
720 if(file == INVALID_HANDLE_VALUE) {
721 WARN("Could not create file: %u\n", GetLastError());
725 hres = get_doc_string(This->doc_node, &str);
727 WriteFile(file, str, strlen(str), &written, NULL);
733 static HRESULT WINAPI PersistFile_SaveCompleted(IPersistFile *iface, LPCOLESTR pszFileName)
735 HTMLDocument *This = impl_from_IPersistFile(iface);
736 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFileName));
740 static HRESULT WINAPI PersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *pszFileName)
742 HTMLDocument *This = impl_from_IPersistFile(iface);
743 FIXME("(%p)->(%p)\n", This, pszFileName);
747 static const IPersistFileVtbl PersistFileVtbl = {
748 PersistFile_QueryInterface,
751 PersistFile_GetClassID,
755 PersistFile_SaveCompleted,
756 PersistFile_GetCurFile
759 static inline HTMLDocument *impl_from_IPersistStreamInit(IPersistStreamInit *iface)
761 return CONTAINING_RECORD(iface, HTMLDocument, IPersistStreamInit_iface);
764 static HRESULT WINAPI PersistStreamInit_QueryInterface(IPersistStreamInit *iface,
765 REFIID riid, void **ppv)
767 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
768 return htmldoc_query_interface(This, riid, ppv);
771 static ULONG WINAPI PersistStreamInit_AddRef(IPersistStreamInit *iface)
773 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
774 return htmldoc_addref(This);
777 static ULONG WINAPI PersistStreamInit_Release(IPersistStreamInit *iface)
779 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
780 return htmldoc_release(This);
783 static HRESULT WINAPI PersistStreamInit_GetClassID(IPersistStreamInit *iface, CLSID *pClassID)
785 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
786 return IPersistFile_GetClassID(&This->IPersistFile_iface, pClassID);
789 static HRESULT WINAPI PersistStreamInit_IsDirty(IPersistStreamInit *iface)
791 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
793 TRACE("(%p)\n", This);
795 if(This->doc_obj->usermode == EDITMODE)
796 return editor_is_dirty(This);
801 static HRESULT WINAPI PersistStreamInit_Load(IPersistStreamInit *iface, LPSTREAM pStm)
803 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
807 TRACE("(%p)->(%p)\n", This, pStm);
809 hres = CreateURLMoniker(NULL, about_blankW, &mon);
811 WARN("CreateURLMoniker failed: %08x\n", hres);
815 prepare_for_binding(This, mon, FALSE);
816 hres = set_moniker(This, mon, NULL, NULL, TRUE);
817 IMoniker_Release(mon);
821 return channelbsc_load_stream(This->window->pending_window, pStm);
824 static HRESULT WINAPI PersistStreamInit_Save(IPersistStreamInit *iface, LPSTREAM pStm,
827 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
832 TRACE("(%p)->(%p %x)\n", This, pStm, fClearDirty);
834 hres = get_doc_string(This->doc_node, &str);
838 hres = IStream_Write(pStm, str, strlen(str), &written);
840 FIXME("Write failed: %08x\n", hres);
845 set_dirty(This, VARIANT_FALSE);
850 static HRESULT WINAPI PersistStreamInit_GetSizeMax(IPersistStreamInit *iface,
851 ULARGE_INTEGER *pcbSize)
853 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
854 FIXME("(%p)->(%p)\n", This, pcbSize);
858 static HRESULT WINAPI PersistStreamInit_InitNew(IPersistStreamInit *iface)
860 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
864 TRACE("(%p)\n", This);
866 hres = CreateURLMoniker(NULL, about_blankW, &mon);
868 WARN("CreateURLMoniker failed: %08x\n", hres);
872 prepare_for_binding(This, mon, FALSE);
873 hres = set_moniker(This, mon, NULL, NULL, FALSE);
874 IMoniker_Release(mon);
878 return channelbsc_load_stream(This->window->pending_window, NULL);
881 static const IPersistStreamInitVtbl PersistStreamInitVtbl = {
882 PersistStreamInit_QueryInterface,
883 PersistStreamInit_AddRef,
884 PersistStreamInit_Release,
885 PersistStreamInit_GetClassID,
886 PersistStreamInit_IsDirty,
887 PersistStreamInit_Load,
888 PersistStreamInit_Save,
889 PersistStreamInit_GetSizeMax,
890 PersistStreamInit_InitNew
893 /**********************************************************
894 * IPersistHistory implementation
897 static inline HTMLDocument *impl_from_IPersistHistory(IPersistHistory *iface)
899 return CONTAINING_RECORD(iface, HTMLDocument, IPersistHistory_iface);
902 static HRESULT WINAPI PersistHistory_QueryInterface(IPersistHistory *iface, REFIID riid, void **ppv)
904 HTMLDocument *This = impl_from_IPersistHistory(iface);
905 return htmldoc_query_interface(This, riid, ppv);
908 static ULONG WINAPI PersistHistory_AddRef(IPersistHistory *iface)
910 HTMLDocument *This = impl_from_IPersistHistory(iface);
911 return htmldoc_addref(This);
914 static ULONG WINAPI PersistHistory_Release(IPersistHistory *iface)
916 HTMLDocument *This = impl_from_IPersistHistory(iface);
917 return htmldoc_release(This);
920 static HRESULT WINAPI PersistHistory_GetClassID(IPersistHistory *iface, CLSID *pClassID)
922 HTMLDocument *This = impl_from_IPersistHistory(iface);
923 return IPersistFile_GetClassID(&This->IPersistFile_iface, pClassID);
926 static HRESULT WINAPI PersistHistory_LoadHistory(IPersistHistory *iface, IStream *pStream, IBindCtx *pbc)
928 HTMLDocument *This = impl_from_IPersistHistory(iface);
934 TRACE("(%p)->(%p %p)\n", This, pStream, pbc);
937 FIXME("No current window\n");
942 FIXME("pbc not supported\n");
944 if(This->doc_obj->client) {
945 IOleCommandTarget *cmdtrg = NULL;
947 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget,
949 if(SUCCEEDED(hres)) {
950 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 138, 0, NULL, NULL);
951 IOleCommandTarget_Release(cmdtrg);
955 hres = IStream_Read(pStream, &str_len, sizeof(str_len), &read);
958 if(read != sizeof(str_len))
961 uri_str = heap_alloc((str_len+1)*sizeof(WCHAR));
963 return E_OUTOFMEMORY;
965 hres = IStream_Read(pStream, uri_str, str_len*sizeof(WCHAR), &read);
966 if(SUCCEEDED(hres) && read != str_len*sizeof(WCHAR))
968 if(SUCCEEDED(hres)) {
969 uri_str[str_len] = 0;
970 hres = CreateUri(uri_str, 0, 0, &uri);
976 hres = load_uri(This->window, uri, BINDING_FROMHIST);
981 static HRESULT WINAPI PersistHistory_SaveHistory(IPersistHistory *iface, IStream *pStream)
983 HTMLDocument *This = impl_from_IPersistHistory(iface);
988 TRACE("(%p)->(%p)\n", This, pStream);
990 if(!This->window || !This->window->uri) {
991 FIXME("No current URI\n");
995 /* NOTE: The format we store is *not* compatible with native MSHTML. We currently
996 * store only URI of the page (as a length followed by a string) */
997 hres = IUri_GetDisplayUri(This->window->uri, &display_uri);
1001 len = SysStringLen(display_uri);
1002 hres = IStream_Write(pStream, &len, sizeof(len), &written);
1004 hres = IStream_Write(pStream, display_uri, len*sizeof(WCHAR), &written);
1005 SysFreeString(display_uri);
1009 static HRESULT WINAPI PersistHistory_SetPositionCookie(IPersistHistory *iface, DWORD dwPositioncookie)
1011 HTMLDocument *This = impl_from_IPersistHistory(iface);
1012 FIXME("(%p)->(%x)\n", This, dwPositioncookie);
1016 static HRESULT WINAPI PersistHistory_GetPositionCookie(IPersistHistory *iface, DWORD *pdwPositioncookie)
1018 HTMLDocument *This = impl_from_IPersistHistory(iface);
1019 FIXME("(%p)->(%p)\n", This, pdwPositioncookie);
1023 static const IPersistHistoryVtbl PersistHistoryVtbl = {
1024 PersistHistory_QueryInterface,
1025 PersistHistory_AddRef,
1026 PersistHistory_Release,
1027 PersistHistory_GetClassID,
1028 PersistHistory_LoadHistory,
1029 PersistHistory_SaveHistory,
1030 PersistHistory_SetPositionCookie,
1031 PersistHistory_GetPositionCookie
1034 void HTMLDocument_Persist_Init(HTMLDocument *This)
1036 This->IPersistMoniker_iface.lpVtbl = &PersistMonikerVtbl;
1037 This->IPersistFile_iface.lpVtbl = &PersistFileVtbl;
1038 This->IMonikerProp_iface.lpVtbl = &MonikerPropVtbl;
1039 This->IPersistStreamInit_iface.lpVtbl = &PersistStreamInitVtbl;
1040 This->IPersistHistory_iface.lpVtbl = &PersistHistoryVtbl;