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;
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 = create_uri(url, 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_uri(const WCHAR *uri_str, DWORD flags, IUri **uri)
183 return CreateUri(uri_str, flags | Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME, 0, uri);
186 HRESULT create_relative_uri(HTMLOuterWindow *window, const WCHAR *rel_uri, IUri **uri)
189 ? CoInternetCombineUrlEx(window->uri, rel_uri, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO, uri, 0)
190 : create_uri(rel_uri, 0, uri);
193 void set_download_state(HTMLDocumentObj *doc, int state)
196 IOleCommandTarget *olecmd;
199 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
200 if(SUCCEEDED(hres)) {
206 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETDOWNLOADSTATE,
207 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
208 IOleCommandTarget_Release(olecmd);
212 doc->download_state = state;
215 static void set_progress_proc(task_t *_task)
217 docobj_task_t *task = (docobj_task_t*)_task;
218 IOleCommandTarget *olecmd = NULL;
219 HTMLDocumentObj *doc = task->doc;
222 TRACE("(%p)\n", doc);
225 IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
228 VARIANT progress_max, progress;
230 V_VT(&progress_max) = VT_I4;
231 V_I4(&progress_max) = 0; /* FIXME */
232 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSMAX, OLECMDEXECOPT_DONTPROMPTUSER,
233 &progress_max, NULL);
235 V_VT(&progress) = VT_I4;
236 V_I4(&progress) = 0; /* FIXME */
237 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSPOS, OLECMDEXECOPT_DONTPROMPTUSER,
239 IOleCommandTarget_Release(olecmd);
242 if(doc->usermode == EDITMODE && doc->hostui) {
243 DOCHOSTUIINFO hostinfo;
245 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
246 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
247 hres = IDocHostUIHandler_GetHostInfo(doc->hostui, &hostinfo);
249 /* FIXME: use hostinfo */
250 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
251 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
252 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
256 static void set_downloading_proc(task_t *_task)
258 download_proc_task_t *task = (download_proc_task_t*)_task;
259 HTMLDocumentObj *doc = task->doc;
262 TRACE("(%p)\n", doc);
264 set_statustext(doc, IDS_STATUS_DOWNLOADINGFROM, task->url);
266 if(task->set_download)
267 set_download_state(doc, 1);
273 IAdviseSink_OnViewChange(doc->view_sink, DVASPECT_CONTENT, -1);
276 IDropTarget *drop_target = NULL;
278 hres = IDocHostUIHandler_GetDropTarget(doc->hostui, NULL /* FIXME */, &drop_target);
279 if(SUCCEEDED(hres) && drop_target) {
280 FIXME("Use IDropTarget\n");
281 IDropTarget_Release(drop_target);
286 static void set_downloading_task_destr(task_t *_task)
288 download_proc_task_t *task = (download_proc_task_t*)_task;
290 CoTaskMemFree(task->url);
294 void prepare_for_binding(HTMLDocument *This, IMoniker *mon, DWORD flags)
298 if(This->doc_obj->client) {
299 VARIANT silent, offline;
301 hres = get_client_disp_property(This->doc_obj->client, DISPID_AMBIENT_SILENT, &silent);
302 if(SUCCEEDED(hres)) {
303 if(V_VT(&silent) != VT_BOOL)
304 WARN("silent = %s\n", debugstr_variant(&silent));
305 else if(V_BOOL(&silent))
306 FIXME("silent == true\n");
309 hres = get_client_disp_property(This->doc_obj->client,
310 DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
311 if(SUCCEEDED(hres)) {
312 if(V_VT(&offline) != VT_BOOL)
313 WARN("offline = %s\n", debugstr_variant(&offline));
314 else if(V_BOOL(&offline))
315 FIXME("offline == true\n");
319 if(This->window->mon) {
320 update_doc(This, UPDATE_TITLE|UPDATE_UI);
322 update_doc(This, UPDATE_TITLE);
323 set_current_mon(This->window, mon, flags);
326 if(This->doc_obj->client) {
327 IOleCommandTarget *cmdtrg = NULL;
329 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget,
331 if(SUCCEEDED(hres)) {
334 if(flags & BINDING_NAVIGATED) {
335 V_VT(&var) = VT_UNKNOWN;
336 V_UNKNOWN(&var) = (IUnknown*)&This->window->base.IHTMLWindow2_iface;
337 V_VT(&out) = VT_EMPTY;
338 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 63, 0, &var, &out);
341 }else if(!(flags & BINDING_FROMHIST)) {
344 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
347 IOleCommandTarget_Release(cmdtrg);
352 HRESULT set_moniker(HTMLDocument *This, IMoniker *mon, IUri *nav_uri, IBindCtx *pibc, nsChannelBSC *async_bsc, BOOL set_download)
354 download_proc_task_t *download_task;
355 nsChannelBSC *bscallback;
361 hres = IMoniker_GetDisplayName(mon, pibc, NULL, &url);
363 WARN("GetDiaplayName failed: %08x\n", hres);
370 hres = create_uri(url, 0, &uri);
377 TRACE("got url: %s\n", debugstr_w(url));
379 set_ready_state(This->window, READYSTATE_LOADING);
381 hres = create_doc_uri(This->window, uri, &nsuri);
384 if(SUCCEEDED(hres)) {
386 bscallback = async_bsc;
388 hres = create_channelbsc(mon, NULL, NULL, 0, TRUE, &bscallback);
391 if(SUCCEEDED(hres)) {
392 remove_target_tasks(This->task_magic);
393 abort_window_bindings(This->window->base.inner_window);
395 hres = load_nsuri(This->window, nsuri, bscallback, LOAD_FLAGS_BYPASS_CACHE);
396 nsISupports_Release((nsISupports*)nsuri); /* FIXME */
398 hres = create_pending_window(This->window, bscallback);
399 if(bscallback != async_bsc)
400 IBindStatusCallback_Release(&bscallback->bsc.IBindStatusCallback_iface);
408 HTMLDocument_LockContainer(This->doc_obj, TRUE);
410 if(This->doc_obj->frame) {
413 task = heap_alloc(sizeof(docobj_task_t));
414 task->doc = This->doc_obj;
415 hres = push_task(&task->header, set_progress_proc, NULL, This->doc_obj->basedoc.task_magic);
422 download_task = heap_alloc(sizeof(download_proc_task_t));
423 download_task->doc = This->doc_obj;
424 download_task->set_download = set_download;
425 download_task->url = url;
426 return push_task(&download_task->header, set_downloading_proc, set_downloading_task_destr, This->doc_obj->basedoc.task_magic);
429 void set_ready_state(HTMLOuterWindow *window, READYSTATE readystate)
431 window->readystate = readystate;
433 if(window->doc_obj && window->doc_obj->basedoc.window == window)
434 call_property_onchanged(&window->doc_obj->basedoc.cp_container, DISPID_READYSTATE);
436 fire_event(window->base.inner_window->doc, EVENTID_READYSTATECHANGE, FALSE,
437 window->base.inner_window->doc->node.nsnode, NULL, NULL);
439 if(window->frame_element)
440 fire_event(window->frame_element->element.node.doc, EVENTID_READYSTATECHANGE,
441 TRUE, window->frame_element->element.node.nsnode, NULL, NULL);
444 static HRESULT get_doc_string(HTMLDocumentNode *This, char **str)
453 WARN("NULL nsdoc\n");
457 nsres = nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
458 if(NS_FAILED(nsres)) {
459 ERR("Could not get nsIDOMNode failed: %08x\n", nsres);
463 nsAString_Init(&nsstr, NULL);
464 hres = nsnode_to_nsstring(nsnode, &nsstr);
465 nsIDOMNode_Release(nsnode);
467 nsAString_Finish(&nsstr);
471 nsAString_GetData(&nsstr, &strw);
472 TRACE("%s\n", debugstr_w(strw));
474 *str = heap_strdupWtoA(strw);
476 nsAString_Finish(&nsstr);
479 return E_OUTOFMEMORY;
484 /**********************************************************
485 * IPersistMoniker implementation
488 static inline HTMLDocument *impl_from_IPersistMoniker(IPersistMoniker *iface)
490 return CONTAINING_RECORD(iface, HTMLDocument, IPersistMoniker_iface);
493 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid, void **ppv)
495 HTMLDocument *This = impl_from_IPersistMoniker(iface);
496 return htmldoc_query_interface(This, riid, ppv);
499 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
501 HTMLDocument *This = impl_from_IPersistMoniker(iface);
502 return htmldoc_addref(This);
505 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
507 HTMLDocument *This = impl_from_IPersistMoniker(iface);
508 return htmldoc_release(This);
511 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
513 HTMLDocument *This = impl_from_IPersistMoniker(iface);
514 return IPersistFile_GetClassID(&This->IPersistFile_iface, pClassID);
517 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
519 HTMLDocument *This = impl_from_IPersistMoniker(iface);
521 TRACE("(%p)\n", This);
523 return IPersistStreamInit_IsDirty(&This->IPersistStreamInit_iface);
526 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
527 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
529 HTMLDocument *This = impl_from_IPersistMoniker(iface);
532 TRACE("(%p)->(%x %p %p %08x)\n", This, fFullyAvailable, pimkName, pibc, grfMode);
535 IUnknown *unk = NULL;
539 * "__PrecreatedObject"
540 * "BIND_CONTEXT_PARAM"
541 * "__HTMLLOADOPTIONS"
544 * "_ITransData_Object_"
548 hres = IBindCtx_GetObjectParam(pibc, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM, &unk);
549 if(SUCCEEDED(hres) && unk) {
550 IOleClientSite *client = NULL;
552 hres = IUnknown_QueryInterface(unk, &IID_IOleClientSite, (void**)&client);
553 if(SUCCEEDED(hres)) {
554 TRACE("Got client site %p\n", client);
555 IOleObject_SetClientSite(&This->IOleObject_iface, client);
556 IOleClientSite_Release(client);
559 IUnknown_Release(unk);
563 prepare_for_binding(This, pimkName, FALSE);
564 call_docview_84(This->doc_obj);
565 hres = set_moniker(This, pimkName, NULL, pibc, NULL, TRUE);
569 return start_binding(This->window->pending_window, (BSCallback*)This->window->pending_window->bscallback, pibc);
572 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName,
573 LPBC pbc, BOOL fRemember)
575 HTMLDocument *This = impl_from_IPersistMoniker(iface);
576 FIXME("(%p)->(%p %p %x)\n", This, pimkName, pbc, fRemember);
580 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
582 HTMLDocument *This = impl_from_IPersistMoniker(iface);
583 FIXME("(%p)->(%p %p)\n", This, pimkName, pibc);
587 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **ppimkName)
589 HTMLDocument *This = impl_from_IPersistMoniker(iface);
591 TRACE("(%p)->(%p)\n", This, ppimkName);
593 if(!This->window || !This->window->mon)
596 IMoniker_AddRef(This->window->mon);
597 *ppimkName = This->window->mon;
601 static const IPersistMonikerVtbl PersistMonikerVtbl = {
602 PersistMoniker_QueryInterface,
603 PersistMoniker_AddRef,
604 PersistMoniker_Release,
605 PersistMoniker_GetClassID,
606 PersistMoniker_IsDirty,
609 PersistMoniker_SaveCompleted,
610 PersistMoniker_GetCurMoniker
613 /**********************************************************
614 * IMonikerProp implementation
617 static inline HTMLDocument *impl_from_IMonikerProp(IMonikerProp *iface)
619 return CONTAINING_RECORD(iface, HTMLDocument, IMonikerProp_iface);
622 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppv)
624 HTMLDocument *This = impl_from_IMonikerProp(iface);
625 return htmldoc_query_interface(This, riid, ppv);
628 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
630 HTMLDocument *This = impl_from_IMonikerProp(iface);
631 return htmldoc_addref(This);
634 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
636 HTMLDocument *This = impl_from_IMonikerProp(iface);
637 return htmldoc_release(This);
640 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
642 HTMLDocument *This = impl_from_IMonikerProp(iface);
644 TRACE("(%p)->(%d %s)\n", This, mkp, debugstr_w(val));
648 heap_free(This->doc_obj->mime);
649 This->doc_obj->mime = heap_strdupW(val);
656 FIXME("mkp %d\n", mkp);
663 static const IMonikerPropVtbl MonikerPropVtbl = {
664 MonikerProp_QueryInterface,
667 MonikerProp_PutProperty
670 /**********************************************************
671 * IPersistFile implementation
674 static inline HTMLDocument *impl_from_IPersistFile(IPersistFile *iface)
676 return CONTAINING_RECORD(iface, HTMLDocument, IPersistFile_iface);
679 static HRESULT WINAPI PersistFile_QueryInterface(IPersistFile *iface, REFIID riid, void **ppv)
681 HTMLDocument *This = impl_from_IPersistFile(iface);
682 return htmldoc_query_interface(This, riid, ppv);
685 static ULONG WINAPI PersistFile_AddRef(IPersistFile *iface)
687 HTMLDocument *This = impl_from_IPersistFile(iface);
688 return htmldoc_addref(This);
691 static ULONG WINAPI PersistFile_Release(IPersistFile *iface)
693 HTMLDocument *This = impl_from_IPersistFile(iface);
694 return htmldoc_release(This);
697 static HRESULT WINAPI PersistFile_GetClassID(IPersistFile *iface, CLSID *pClassID)
699 HTMLDocument *This = impl_from_IPersistFile(iface);
701 TRACE("(%p)->(%p)\n", This, pClassID);
706 *pClassID = CLSID_HTMLDocument;
710 static HRESULT WINAPI PersistFile_IsDirty(IPersistFile *iface)
712 HTMLDocument *This = impl_from_IPersistFile(iface);
714 TRACE("(%p)\n", This);
716 return IPersistStreamInit_IsDirty(&This->IPersistStreamInit_iface);
719 static HRESULT WINAPI PersistFile_Load(IPersistFile *iface, LPCOLESTR pszFileName, DWORD dwMode)
721 HTMLDocument *This = impl_from_IPersistFile(iface);
722 FIXME("(%p)->(%s %08x)\n", This, debugstr_w(pszFileName), dwMode);
726 static HRESULT WINAPI PersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileName, BOOL fRemember)
728 HTMLDocument *This = impl_from_IPersistFile(iface);
734 TRACE("(%p)->(%s %x)\n", This, debugstr_w(pszFileName), fRemember);
736 file = CreateFileW(pszFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
737 FILE_ATTRIBUTE_NORMAL, NULL);
738 if(file == INVALID_HANDLE_VALUE) {
739 WARN("Could not create file: %u\n", GetLastError());
743 hres = get_doc_string(This->doc_node, &str);
745 WriteFile(file, str, strlen(str), &written, NULL);
751 static HRESULT WINAPI PersistFile_SaveCompleted(IPersistFile *iface, LPCOLESTR pszFileName)
753 HTMLDocument *This = impl_from_IPersistFile(iface);
754 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFileName));
758 static HRESULT WINAPI PersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *pszFileName)
760 HTMLDocument *This = impl_from_IPersistFile(iface);
761 FIXME("(%p)->(%p)\n", This, pszFileName);
765 static const IPersistFileVtbl PersistFileVtbl = {
766 PersistFile_QueryInterface,
769 PersistFile_GetClassID,
773 PersistFile_SaveCompleted,
774 PersistFile_GetCurFile
777 static inline HTMLDocument *impl_from_IPersistStreamInit(IPersistStreamInit *iface)
779 return CONTAINING_RECORD(iface, HTMLDocument, IPersistStreamInit_iface);
782 static HRESULT WINAPI PersistStreamInit_QueryInterface(IPersistStreamInit *iface,
783 REFIID riid, void **ppv)
785 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
786 return htmldoc_query_interface(This, riid, ppv);
789 static ULONG WINAPI PersistStreamInit_AddRef(IPersistStreamInit *iface)
791 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
792 return htmldoc_addref(This);
795 static ULONG WINAPI PersistStreamInit_Release(IPersistStreamInit *iface)
797 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
798 return htmldoc_release(This);
801 static HRESULT WINAPI PersistStreamInit_GetClassID(IPersistStreamInit *iface, CLSID *pClassID)
803 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
804 return IPersistFile_GetClassID(&This->IPersistFile_iface, pClassID);
807 static HRESULT WINAPI PersistStreamInit_IsDirty(IPersistStreamInit *iface)
809 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
811 TRACE("(%p)\n", This);
813 if(This->doc_obj->usermode == EDITMODE)
814 return editor_is_dirty(This);
819 static HRESULT WINAPI PersistStreamInit_Load(IPersistStreamInit *iface, LPSTREAM pStm)
821 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
825 TRACE("(%p)->(%p)\n", This, pStm);
827 hres = CreateURLMoniker(NULL, about_blankW, &mon);
829 WARN("CreateURLMoniker failed: %08x\n", hres);
833 prepare_for_binding(This, mon, FALSE);
834 hres = set_moniker(This, mon, NULL, NULL, NULL, TRUE);
835 IMoniker_Release(mon);
839 return channelbsc_load_stream(This->window->pending_window, pStm);
842 static HRESULT WINAPI PersistStreamInit_Save(IPersistStreamInit *iface, LPSTREAM pStm,
845 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
850 TRACE("(%p)->(%p %x)\n", This, pStm, fClearDirty);
852 hres = get_doc_string(This->doc_node, &str);
856 hres = IStream_Write(pStm, str, strlen(str), &written);
858 FIXME("Write failed: %08x\n", hres);
863 set_dirty(This, VARIANT_FALSE);
868 static HRESULT WINAPI PersistStreamInit_GetSizeMax(IPersistStreamInit *iface,
869 ULARGE_INTEGER *pcbSize)
871 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
872 FIXME("(%p)->(%p)\n", This, pcbSize);
876 static HRESULT WINAPI PersistStreamInit_InitNew(IPersistStreamInit *iface)
878 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
882 TRACE("(%p)\n", This);
884 hres = CreateURLMoniker(NULL, about_blankW, &mon);
886 WARN("CreateURLMoniker failed: %08x\n", hres);
890 prepare_for_binding(This, mon, FALSE);
891 hres = set_moniker(This, mon, NULL, NULL, NULL, FALSE);
892 IMoniker_Release(mon);
896 return channelbsc_load_stream(This->window->pending_window, NULL);
899 static const IPersistStreamInitVtbl PersistStreamInitVtbl = {
900 PersistStreamInit_QueryInterface,
901 PersistStreamInit_AddRef,
902 PersistStreamInit_Release,
903 PersistStreamInit_GetClassID,
904 PersistStreamInit_IsDirty,
905 PersistStreamInit_Load,
906 PersistStreamInit_Save,
907 PersistStreamInit_GetSizeMax,
908 PersistStreamInit_InitNew
911 /**********************************************************
912 * IPersistHistory implementation
915 static inline HTMLDocument *impl_from_IPersistHistory(IPersistHistory *iface)
917 return CONTAINING_RECORD(iface, HTMLDocument, IPersistHistory_iface);
920 static HRESULT WINAPI PersistHistory_QueryInterface(IPersistHistory *iface, REFIID riid, void **ppv)
922 HTMLDocument *This = impl_from_IPersistHistory(iface);
923 return htmldoc_query_interface(This, riid, ppv);
926 static ULONG WINAPI PersistHistory_AddRef(IPersistHistory *iface)
928 HTMLDocument *This = impl_from_IPersistHistory(iface);
929 return htmldoc_addref(This);
932 static ULONG WINAPI PersistHistory_Release(IPersistHistory *iface)
934 HTMLDocument *This = impl_from_IPersistHistory(iface);
935 return htmldoc_release(This);
938 static HRESULT WINAPI PersistHistory_GetClassID(IPersistHistory *iface, CLSID *pClassID)
940 HTMLDocument *This = impl_from_IPersistHistory(iface);
941 return IPersistFile_GetClassID(&This->IPersistFile_iface, pClassID);
944 static HRESULT WINAPI PersistHistory_LoadHistory(IPersistHistory *iface, IStream *pStream, IBindCtx *pbc)
946 HTMLDocument *This = impl_from_IPersistHistory(iface);
952 TRACE("(%p)->(%p %p)\n", This, pStream, pbc);
955 FIXME("No current window\n");
960 FIXME("pbc not supported\n");
962 if(This->doc_obj->client) {
963 IOleCommandTarget *cmdtrg = NULL;
965 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget,
967 if(SUCCEEDED(hres)) {
968 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 138, 0, NULL, NULL);
969 IOleCommandTarget_Release(cmdtrg);
973 hres = IStream_Read(pStream, &str_len, sizeof(str_len), &read);
976 if(read != sizeof(str_len))
979 uri_str = heap_alloc((str_len+1)*sizeof(WCHAR));
981 return E_OUTOFMEMORY;
983 hres = IStream_Read(pStream, uri_str, str_len*sizeof(WCHAR), &read);
984 if(SUCCEEDED(hres) && read != str_len*sizeof(WCHAR))
986 if(SUCCEEDED(hres)) {
987 uri_str[str_len] = 0;
988 hres = create_uri(uri_str, 0, &uri);
994 hres = load_uri(This->window, uri, BINDING_FROMHIST);
999 static HRESULT WINAPI PersistHistory_SaveHistory(IPersistHistory *iface, IStream *pStream)
1001 HTMLDocument *This = impl_from_IPersistHistory(iface);
1006 TRACE("(%p)->(%p)\n", This, pStream);
1008 if(!This->window || !This->window->uri) {
1009 FIXME("No current URI\n");
1013 /* NOTE: The format we store is *not* compatible with native MSHTML. We currently
1014 * store only URI of the page (as a length followed by a string) */
1015 hres = IUri_GetDisplayUri(This->window->uri, &display_uri);
1019 len = SysStringLen(display_uri);
1020 hres = IStream_Write(pStream, &len, sizeof(len), &written);
1022 hres = IStream_Write(pStream, display_uri, len*sizeof(WCHAR), &written);
1023 SysFreeString(display_uri);
1027 static HRESULT WINAPI PersistHistory_SetPositionCookie(IPersistHistory *iface, DWORD dwPositioncookie)
1029 HTMLDocument *This = impl_from_IPersistHistory(iface);
1030 FIXME("(%p)->(%x)\n", This, dwPositioncookie);
1034 static HRESULT WINAPI PersistHistory_GetPositionCookie(IPersistHistory *iface, DWORD *pdwPositioncookie)
1036 HTMLDocument *This = impl_from_IPersistHistory(iface);
1037 FIXME("(%p)->(%p)\n", This, pdwPositioncookie);
1041 static const IPersistHistoryVtbl PersistHistoryVtbl = {
1042 PersistHistory_QueryInterface,
1043 PersistHistory_AddRef,
1044 PersistHistory_Release,
1045 PersistHistory_GetClassID,
1046 PersistHistory_LoadHistory,
1047 PersistHistory_SaveHistory,
1048 PersistHistory_SetPositionCookie,
1049 PersistHistory_GetPositionCookie
1052 void HTMLDocument_Persist_Init(HTMLDocument *This)
1054 This->IPersistMoniker_iface.lpVtbl = &PersistMonikerVtbl;
1055 This->IPersistFile_iface.lpVtbl = &PersistFileVtbl;
1056 This->IMonikerProp_iface.lpVtbl = &MonikerPropVtbl;
1057 This->IPersistStreamInit_iface.lpVtbl = &PersistStreamInitVtbl;
1058 This->IPersistHistory_iface.lpVtbl = &PersistHistoryVtbl;