dpvoice: Turn GetCompressionTypes into a semi-stub.
[wine.git] / dlls / mshtml / persist.c
blob1263f4347e7870babb2ba45b71fdbb9efe103388
1 /*
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
19 #include "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winuser.h"
31 #include "ole2.h"
32 #include "shlguid.h"
33 #include "idispids.h"
35 #define NO_SHLWAPI_REG
36 #include "shlwapi.h"
38 #include "wine/debug.h"
40 #include "mshtml_private.h"
41 #include "htmlscript.h"
42 #include "htmlevent.h"
43 #include "binding.h"
44 #include "resource.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};
53 typedef struct {
54 task_t header;
55 HTMLDocumentObj *doc;
56 BOOL set_download;
57 LPOLESTR url;
58 } download_proc_task_t;
60 static BOOL use_gecko_script(HTMLOuterWindow *window)
62 DWORD zone;
63 HRESULT hres;
65 hres = IInternetSecurityManager_MapUrlToZone(window->secmgr, window->url, &zone, 0);
66 if(FAILED(hres)) {
67 WARN("Could not map %s to zone: %08x\n", debugstr_w(window->url), hres);
68 return TRUE;
71 TRACE("zone %d\n", zone);
72 return zone == URLZONE_UNTRUSTED;
75 static void notify_travellog_update(HTMLDocumentObj *doc)
77 IOleCommandTarget *cmdtrg;
78 HRESULT hres;
80 if(!doc->webbrowser)
81 return;
83 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
84 if(SUCCEEDED(hres)) {
85 VARIANT vin;
87 V_VT(&vin) = VT_I4;
88 V_I4(&vin) = 0;
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)
97 if(window->uri) {
98 IUri_Release(window->uri);
99 window->uri = NULL;
102 if(window->uri_nofrag) {
103 IUri_Release(window->uri_nofrag);
104 window->uri_nofrag = NULL;
107 SysFreeString(window->url);
108 window->url = NULL;
110 if(!uri)
111 return;
113 IUri_AddRef(uri);
114 window->uri = uri;
116 window->uri_nofrag = get_uri_nofrag(uri);
117 if(!window->uri_nofrag) {
118 FIXME("get_uri_nofrag failed\n");
119 IUri_AddRef(uri);
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;
129 IUri *uri = NULL;
130 HRESULT hres;
132 if(This->mon) {
133 if(This->doc_obj && !(flags & (BINDING_REPLACE|BINDING_REFRESH)))
134 notify_travellog_update(This->doc_obj);
135 IMoniker_Release(This->mon);
136 This->mon = NULL;
139 This->load_flags = flags;
140 if(!mon)
141 return;
143 IMoniker_AddRef(mon);
144 This->mon = 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);
150 if(hres != S_OK) {
151 WARN("GetIUri failed: %08x\n", hres);
152 uri = NULL;
156 if(!uri) {
157 WCHAR *url;
159 hres = IMoniker_GetDisplayName(mon, NULL, NULL, &url);
160 if(SUCCEEDED(hres)) {
161 hres = create_uri(url, 0, &uri);
162 if(FAILED(hres)) {
163 WARN("CrateUri failed: %08x\n", hres);
164 set_current_uri(This, NULL);
165 This->url = SysAllocString(url);
166 CoTaskMemFree(url);
167 return;
169 CoTaskMemFree(url);
170 }else {
171 WARN("GetDisplayName failed: %08x\n", hres);
175 set_current_uri(This, uri);
176 if(uri)
177 IUri_Release(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)
188 return window->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)
195 if(doc->client) {
196 IOleCommandTarget *olecmd;
197 HRESULT hres;
199 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
200 if(SUCCEEDED(hres)) {
201 VARIANT var;
203 V_VT(&var) = VT_I4;
204 V_I4(&var) = state;
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;
220 HRESULT hres;
222 TRACE("(%p)\n", doc);
224 if(doc->client)
225 IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
227 if(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,
238 &progress, NULL);
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);
248 if(SUCCEEDED(hres))
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;
260 HRESULT hres;
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);
269 if(!doc->client)
270 return;
272 if(doc->view_sink)
273 IAdviseSink_OnViewChange(doc->view_sink, DVASPECT_CONTENT, -1);
275 if(doc->hostui) {
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);
291 heap_free(task);
294 void prepare_for_binding(HTMLDocument *This, IMoniker *mon, DWORD flags)
296 HRESULT hres;
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);
321 }else {
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,
330 (void**)&cmdtrg);
331 if(SUCCEEDED(hres)) {
332 VARIANT var, out;
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);
339 if(SUCCEEDED(hres))
340 VariantClear(&out);
341 }else if(!(flags & BINDING_FROMHIST)) {
342 V_VT(&var) = VT_I4;
343 V_I4(&var) = 0;
344 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
347 IOleCommandTarget_Release(cmdtrg);
352 HRESULT set_moniker(HTMLOuterWindow *window, IMoniker *mon, IUri *nav_uri, IBindCtx *pibc, nsChannelBSC *async_bsc,
353 BOOL set_download)
355 download_proc_task_t *download_task;
356 HTMLDocumentObj *doc_obj = NULL;
357 nsChannelBSC *bscallback;
358 nsWineURI *nsuri;
359 LPOLESTR url;
360 IUri *uri;
361 HRESULT hres;
363 if(window->doc_obj && window->doc_obj->basedoc.window == window)
364 doc_obj = window->doc_obj;
366 hres = IMoniker_GetDisplayName(mon, pibc, NULL, &url);
367 if(FAILED(hres)) {
368 WARN("GetDiaplayName failed: %08x\n", hres);
369 return hres;
372 if(nav_uri) {
373 uri = nav_uri;
374 }else {
375 hres = create_uri(url, 0, &uri);
376 if(FAILED(hres)) {
377 CoTaskMemFree(url);
378 return hres;
382 TRACE("got url: %s\n", debugstr_w(url));
384 set_ready_state(window, READYSTATE_LOADING);
386 hres = create_doc_uri(window, uri, &nsuri);
387 if(!nav_uri)
388 IUri_Release(uri);
389 if(SUCCEEDED(hres)) {
390 if(async_bsc)
391 bscallback = async_bsc;
392 else
393 hres = create_channelbsc(mon, NULL, NULL, 0, TRUE, &bscallback);
396 if(SUCCEEDED(hres)) {
397 if(window->base.inner_window->doc)
398 remove_target_tasks(window->base.inner_window->task_magic);
399 abort_window_bindings(window->base.inner_window);
401 hres = load_nsuri(window, nsuri, NULL, bscallback, LOAD_FLAGS_BYPASS_CACHE);
402 nsISupports_Release((nsISupports*)nsuri); /* FIXME */
403 if(SUCCEEDED(hres)) {
404 hres = create_pending_window(window, bscallback);
405 TRACE("pending window for %p %p %p\n", window, bscallback, window->pending_window);
407 if(bscallback != async_bsc)
408 IBindStatusCallback_Release(&bscallback->bsc.IBindStatusCallback_iface);
411 if(FAILED(hres)) {
412 CoTaskMemFree(url);
413 return hres;
416 if(doc_obj) {
417 HTMLDocument_LockContainer(doc_obj, TRUE);
419 if(doc_obj->frame) {
420 docobj_task_t *task;
422 task = heap_alloc(sizeof(docobj_task_t));
423 task->doc = doc_obj;
424 hres = push_task(&task->header, set_progress_proc, NULL, doc_obj->basedoc.task_magic);
425 if(FAILED(hres)) {
426 CoTaskMemFree(url);
427 return hres;
431 download_task = heap_alloc(sizeof(download_proc_task_t));
432 download_task->doc = doc_obj;
433 download_task->set_download = set_download;
434 download_task->url = url;
435 return push_task(&download_task->header, set_downloading_proc, set_downloading_task_destr, doc_obj->basedoc.task_magic);
438 return S_OK;
441 static void notif_readystate(HTMLOuterWindow *window)
443 window->readystate_pending = FALSE;
445 if(window->doc_obj && window->doc_obj->basedoc.window == window)
446 call_property_onchanged(&window->doc_obj->basedoc.cp_container, DISPID_READYSTATE);
448 fire_event(window->base.inner_window->doc, EVENTID_READYSTATECHANGE, FALSE,
449 window->base.inner_window->doc->node.nsnode, NULL, NULL);
451 if(window->frame_element)
452 fire_event(window->frame_element->element.node.doc, EVENTID_READYSTATECHANGE,
453 TRUE, window->frame_element->element.node.nsnode, NULL, NULL);
456 typedef struct {
457 task_t header;
458 HTMLOuterWindow *window;
459 } readystate_task_t;
461 static void notif_readystate_proc(task_t *_task)
463 readystate_task_t *task = (readystate_task_t*)_task;
464 notif_readystate(task->window);
467 static void notif_readystate_destr(task_t *_task)
469 readystate_task_t *task = (readystate_task_t*)_task;
470 IHTMLWindow2_Release(&task->window->base.IHTMLWindow2_iface);
473 void set_ready_state(HTMLOuterWindow *window, READYSTATE readystate)
475 READYSTATE prev_state = window->readystate;
477 window->readystate = readystate;
479 if(window->readystate_locked) {
480 readystate_task_t *task;
481 HRESULT hres;
483 if(window->readystate_pending || prev_state == readystate)
484 return;
486 task = heap_alloc(sizeof(*task));
487 if(!task)
488 return;
490 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
491 task->window = window;
493 hres = push_task(&task->header, notif_readystate_proc, notif_readystate_destr, window->task_magic);
494 if(SUCCEEDED(hres))
495 window->readystate_pending = TRUE;
496 return;
499 notif_readystate(window);
502 static HRESULT get_doc_string(HTMLDocumentNode *This, char **str)
504 nsIDOMNode *nsnode;
505 LPCWSTR strw;
506 nsAString nsstr;
507 nsresult nsres;
508 HRESULT hres;
510 if(!This->nsdoc) {
511 WARN("NULL nsdoc\n");
512 return E_UNEXPECTED;
515 nsres = nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
516 if(NS_FAILED(nsres)) {
517 ERR("Could not get nsIDOMNode failed: %08x\n", nsres);
518 return E_FAIL;
521 nsAString_Init(&nsstr, NULL);
522 hres = nsnode_to_nsstring(nsnode, &nsstr);
523 nsIDOMNode_Release(nsnode);
524 if(FAILED(hres)) {
525 nsAString_Finish(&nsstr);
526 return hres;
529 nsAString_GetData(&nsstr, &strw);
530 TRACE("%s\n", debugstr_w(strw));
532 *str = heap_strdupWtoA(strw);
534 nsAString_Finish(&nsstr);
536 if(!*str)
537 return E_OUTOFMEMORY;
538 return S_OK;
542 /**********************************************************
543 * IPersistMoniker implementation
546 static inline HTMLDocument *impl_from_IPersistMoniker(IPersistMoniker *iface)
548 return CONTAINING_RECORD(iface, HTMLDocument, IPersistMoniker_iface);
551 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid, void **ppv)
553 HTMLDocument *This = impl_from_IPersistMoniker(iface);
554 return htmldoc_query_interface(This, riid, ppv);
557 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
559 HTMLDocument *This = impl_from_IPersistMoniker(iface);
560 return htmldoc_addref(This);
563 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
565 HTMLDocument *This = impl_from_IPersistMoniker(iface);
566 return htmldoc_release(This);
569 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
571 HTMLDocument *This = impl_from_IPersistMoniker(iface);
572 return IPersistFile_GetClassID(&This->IPersistFile_iface, pClassID);
575 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
577 HTMLDocument *This = impl_from_IPersistMoniker(iface);
579 TRACE("(%p)\n", This);
581 return IPersistStreamInit_IsDirty(&This->IPersistStreamInit_iface);
584 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
585 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
587 HTMLDocument *This = impl_from_IPersistMoniker(iface);
588 HRESULT hres;
590 TRACE("(%p)->(%x %p %p %08x)\n", This, fFullyAvailable, pimkName, pibc, grfMode);
592 if(pibc) {
593 IUnknown *unk = NULL;
595 /* FIXME:
596 * Use params:
597 * "__PrecreatedObject"
598 * "BIND_CONTEXT_PARAM"
599 * "__HTMLLOADOPTIONS"
600 * "__DWNBINDINFO"
601 * "URL Context"
602 * "_ITransData_Object_"
603 * "_EnumFORMATETC_"
606 hres = IBindCtx_GetObjectParam(pibc, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM, &unk);
607 if(SUCCEEDED(hres) && unk) {
608 IOleClientSite *client = NULL;
610 hres = IUnknown_QueryInterface(unk, &IID_IOleClientSite, (void**)&client);
611 if(SUCCEEDED(hres)) {
612 TRACE("Got client site %p\n", client);
613 IOleObject_SetClientSite(&This->IOleObject_iface, client);
614 IOleClientSite_Release(client);
617 IUnknown_Release(unk);
621 prepare_for_binding(This, pimkName, FALSE);
622 call_docview_84(This->doc_obj);
623 hres = set_moniker(This->window, pimkName, NULL, pibc, NULL, TRUE);
624 if(FAILED(hres))
625 return hres;
627 return start_binding(This->window->pending_window, (BSCallback*)This->window->pending_window->bscallback, pibc);
630 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName,
631 LPBC pbc, BOOL fRemember)
633 HTMLDocument *This = impl_from_IPersistMoniker(iface);
634 FIXME("(%p)->(%p %p %x)\n", This, pimkName, pbc, fRemember);
635 return E_NOTIMPL;
638 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
640 HTMLDocument *This = impl_from_IPersistMoniker(iface);
641 FIXME("(%p)->(%p %p)\n", This, pimkName, pibc);
642 return E_NOTIMPL;
645 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **ppimkName)
647 HTMLDocument *This = impl_from_IPersistMoniker(iface);
649 TRACE("(%p)->(%p)\n", This, ppimkName);
651 if(!This->window || !This->window->mon)
652 return E_UNEXPECTED;
654 IMoniker_AddRef(This->window->mon);
655 *ppimkName = This->window->mon;
656 return S_OK;
659 static const IPersistMonikerVtbl PersistMonikerVtbl = {
660 PersistMoniker_QueryInterface,
661 PersistMoniker_AddRef,
662 PersistMoniker_Release,
663 PersistMoniker_GetClassID,
664 PersistMoniker_IsDirty,
665 PersistMoniker_Load,
666 PersistMoniker_Save,
667 PersistMoniker_SaveCompleted,
668 PersistMoniker_GetCurMoniker
671 /**********************************************************
672 * IMonikerProp implementation
675 static inline HTMLDocument *impl_from_IMonikerProp(IMonikerProp *iface)
677 return CONTAINING_RECORD(iface, HTMLDocument, IMonikerProp_iface);
680 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppv)
682 HTMLDocument *This = impl_from_IMonikerProp(iface);
683 return htmldoc_query_interface(This, riid, ppv);
686 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
688 HTMLDocument *This = impl_from_IMonikerProp(iface);
689 return htmldoc_addref(This);
692 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
694 HTMLDocument *This = impl_from_IMonikerProp(iface);
695 return htmldoc_release(This);
698 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
700 HTMLDocument *This = impl_from_IMonikerProp(iface);
702 TRACE("(%p)->(%d %s)\n", This, mkp, debugstr_w(val));
704 switch(mkp) {
705 case MIMETYPEPROP:
706 heap_free(This->doc_obj->mime);
707 This->doc_obj->mime = heap_strdupW(val);
708 break;
710 case CLASSIDPROP:
711 break;
713 default:
714 FIXME("mkp %d\n", mkp);
715 return E_NOTIMPL;
718 return S_OK;
721 static const IMonikerPropVtbl MonikerPropVtbl = {
722 MonikerProp_QueryInterface,
723 MonikerProp_AddRef,
724 MonikerProp_Release,
725 MonikerProp_PutProperty
728 /**********************************************************
729 * IPersistFile implementation
732 static inline HTMLDocument *impl_from_IPersistFile(IPersistFile *iface)
734 return CONTAINING_RECORD(iface, HTMLDocument, IPersistFile_iface);
737 static HRESULT WINAPI PersistFile_QueryInterface(IPersistFile *iface, REFIID riid, void **ppv)
739 HTMLDocument *This = impl_from_IPersistFile(iface);
740 return htmldoc_query_interface(This, riid, ppv);
743 static ULONG WINAPI PersistFile_AddRef(IPersistFile *iface)
745 HTMLDocument *This = impl_from_IPersistFile(iface);
746 return htmldoc_addref(This);
749 static ULONG WINAPI PersistFile_Release(IPersistFile *iface)
751 HTMLDocument *This = impl_from_IPersistFile(iface);
752 return htmldoc_release(This);
755 static HRESULT WINAPI PersistFile_GetClassID(IPersistFile *iface, CLSID *pClassID)
757 HTMLDocument *This = impl_from_IPersistFile(iface);
759 TRACE("(%p)->(%p)\n", This, pClassID);
761 if(!pClassID)
762 return E_INVALIDARG;
764 *pClassID = CLSID_HTMLDocument;
765 return S_OK;
768 static HRESULT WINAPI PersistFile_IsDirty(IPersistFile *iface)
770 HTMLDocument *This = impl_from_IPersistFile(iface);
772 TRACE("(%p)\n", This);
774 return IPersistStreamInit_IsDirty(&This->IPersistStreamInit_iface);
777 static HRESULT WINAPI PersistFile_Load(IPersistFile *iface, LPCOLESTR pszFileName, DWORD dwMode)
779 HTMLDocument *This = impl_from_IPersistFile(iface);
780 FIXME("(%p)->(%s %08x)\n", This, debugstr_w(pszFileName), dwMode);
781 return E_NOTIMPL;
784 static HRESULT WINAPI PersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileName, BOOL fRemember)
786 HTMLDocument *This = impl_from_IPersistFile(iface);
787 char *str;
788 DWORD written=0;
789 HANDLE file;
790 HRESULT hres;
792 TRACE("(%p)->(%s %x)\n", This, debugstr_w(pszFileName), fRemember);
794 file = CreateFileW(pszFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
795 FILE_ATTRIBUTE_NORMAL, NULL);
796 if(file == INVALID_HANDLE_VALUE) {
797 WARN("Could not create file: %u\n", GetLastError());
798 return E_FAIL;
801 hres = get_doc_string(This->doc_node, &str);
802 if(SUCCEEDED(hres))
803 WriteFile(file, str, strlen(str), &written, NULL);
805 CloseHandle(file);
806 return hres;
809 static HRESULT WINAPI PersistFile_SaveCompleted(IPersistFile *iface, LPCOLESTR pszFileName)
811 HTMLDocument *This = impl_from_IPersistFile(iface);
812 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFileName));
813 return E_NOTIMPL;
816 static HRESULT WINAPI PersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *pszFileName)
818 HTMLDocument *This = impl_from_IPersistFile(iface);
819 FIXME("(%p)->(%p)\n", This, pszFileName);
820 return E_NOTIMPL;
823 static const IPersistFileVtbl PersistFileVtbl = {
824 PersistFile_QueryInterface,
825 PersistFile_AddRef,
826 PersistFile_Release,
827 PersistFile_GetClassID,
828 PersistFile_IsDirty,
829 PersistFile_Load,
830 PersistFile_Save,
831 PersistFile_SaveCompleted,
832 PersistFile_GetCurFile
835 static inline HTMLDocument *impl_from_IPersistStreamInit(IPersistStreamInit *iface)
837 return CONTAINING_RECORD(iface, HTMLDocument, IPersistStreamInit_iface);
840 static HRESULT WINAPI PersistStreamInit_QueryInterface(IPersistStreamInit *iface,
841 REFIID riid, void **ppv)
843 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
844 return htmldoc_query_interface(This, riid, ppv);
847 static ULONG WINAPI PersistStreamInit_AddRef(IPersistStreamInit *iface)
849 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
850 return htmldoc_addref(This);
853 static ULONG WINAPI PersistStreamInit_Release(IPersistStreamInit *iface)
855 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
856 return htmldoc_release(This);
859 static HRESULT WINAPI PersistStreamInit_GetClassID(IPersistStreamInit *iface, CLSID *pClassID)
861 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
862 return IPersistFile_GetClassID(&This->IPersistFile_iface, pClassID);
865 static HRESULT WINAPI PersistStreamInit_IsDirty(IPersistStreamInit *iface)
867 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
869 TRACE("(%p)\n", This);
871 if(This->doc_obj->usermode == EDITMODE)
872 return editor_is_dirty(This);
874 return S_FALSE;
877 static HRESULT WINAPI PersistStreamInit_Load(IPersistStreamInit *iface, LPSTREAM pStm)
879 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
880 IMoniker *mon;
881 HRESULT hres;
883 TRACE("(%p)->(%p)\n", This, pStm);
885 hres = CreateURLMoniker(NULL, about_blankW, &mon);
886 if(FAILED(hres)) {
887 WARN("CreateURLMoniker failed: %08x\n", hres);
888 return hres;
891 prepare_for_binding(This, mon, FALSE);
892 hres = set_moniker(This->window, mon, NULL, NULL, NULL, TRUE);
893 if(FAILED(hres))
894 return hres;
896 hres = channelbsc_load_stream(This->window->pending_window, mon, pStm);
897 IMoniker_Release(mon);
898 return hres;
901 static HRESULT WINAPI PersistStreamInit_Save(IPersistStreamInit *iface, LPSTREAM pStm,
902 BOOL fClearDirty)
904 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
905 char *str;
906 DWORD written=0;
907 HRESULT hres;
909 TRACE("(%p)->(%p %x)\n", This, pStm, fClearDirty);
911 hres = get_doc_string(This->doc_node, &str);
912 if(FAILED(hres))
913 return hres;
915 hres = IStream_Write(pStm, str, strlen(str), &written);
916 if(FAILED(hres))
917 FIXME("Write failed: %08x\n", hres);
919 heap_free(str);
921 if(fClearDirty)
922 set_dirty(This, VARIANT_FALSE);
924 return S_OK;
927 static HRESULT WINAPI PersistStreamInit_GetSizeMax(IPersistStreamInit *iface,
928 ULARGE_INTEGER *pcbSize)
930 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
931 FIXME("(%p)->(%p)\n", This, pcbSize);
932 return E_NOTIMPL;
935 static HRESULT WINAPI PersistStreamInit_InitNew(IPersistStreamInit *iface)
937 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
938 IMoniker *mon;
939 HRESULT hres;
941 TRACE("(%p)\n", This);
943 hres = CreateURLMoniker(NULL, about_blankW, &mon);
944 if(FAILED(hres)) {
945 WARN("CreateURLMoniker failed: %08x\n", hres);
946 return hres;
949 prepare_for_binding(This, mon, FALSE);
950 hres = set_moniker(This->window, mon, NULL, NULL, NULL, FALSE);
951 if(FAILED(hres))
952 return hres;
954 hres = channelbsc_load_stream(This->window->pending_window, mon, NULL);
955 IMoniker_Release(mon);
956 return hres;
959 static const IPersistStreamInitVtbl PersistStreamInitVtbl = {
960 PersistStreamInit_QueryInterface,
961 PersistStreamInit_AddRef,
962 PersistStreamInit_Release,
963 PersistStreamInit_GetClassID,
964 PersistStreamInit_IsDirty,
965 PersistStreamInit_Load,
966 PersistStreamInit_Save,
967 PersistStreamInit_GetSizeMax,
968 PersistStreamInit_InitNew
971 /**********************************************************
972 * IPersistHistory implementation
975 static inline HTMLDocument *impl_from_IPersistHistory(IPersistHistory *iface)
977 return CONTAINING_RECORD(iface, HTMLDocument, IPersistHistory_iface);
980 static HRESULT WINAPI PersistHistory_QueryInterface(IPersistHistory *iface, REFIID riid, void **ppv)
982 HTMLDocument *This = impl_from_IPersistHistory(iface);
983 return htmldoc_query_interface(This, riid, ppv);
986 static ULONG WINAPI PersistHistory_AddRef(IPersistHistory *iface)
988 HTMLDocument *This = impl_from_IPersistHistory(iface);
989 return htmldoc_addref(This);
992 static ULONG WINAPI PersistHistory_Release(IPersistHistory *iface)
994 HTMLDocument *This = impl_from_IPersistHistory(iface);
995 return htmldoc_release(This);
998 static HRESULT WINAPI PersistHistory_GetClassID(IPersistHistory *iface, CLSID *pClassID)
1000 HTMLDocument *This = impl_from_IPersistHistory(iface);
1001 return IPersistFile_GetClassID(&This->IPersistFile_iface, pClassID);
1004 static HRESULT WINAPI PersistHistory_LoadHistory(IPersistHistory *iface, IStream *pStream, IBindCtx *pbc)
1006 HTMLDocument *This = impl_from_IPersistHistory(iface);
1007 ULONG str_len, read;
1008 WCHAR *uri_str;
1009 IUri *uri;
1010 HRESULT hres;
1012 TRACE("(%p)->(%p %p)\n", This, pStream, pbc);
1014 if(!This->window) {
1015 FIXME("No current window\n");
1016 return E_UNEXPECTED;
1019 if(pbc)
1020 FIXME("pbc not supported\n");
1022 if(This->doc_obj->client) {
1023 IOleCommandTarget *cmdtrg = NULL;
1025 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget,
1026 (void**)&cmdtrg);
1027 if(SUCCEEDED(hres)) {
1028 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 138, 0, NULL, NULL);
1029 IOleCommandTarget_Release(cmdtrg);
1033 hres = IStream_Read(pStream, &str_len, sizeof(str_len), &read);
1034 if(FAILED(hres))
1035 return hres;
1036 if(read != sizeof(str_len))
1037 return E_FAIL;
1039 uri_str = heap_alloc((str_len+1)*sizeof(WCHAR));
1040 if(!uri_str)
1041 return E_OUTOFMEMORY;
1043 hres = IStream_Read(pStream, uri_str, str_len*sizeof(WCHAR), &read);
1044 if(SUCCEEDED(hres) && read != str_len*sizeof(WCHAR))
1045 hres = E_FAIL;
1046 if(SUCCEEDED(hres)) {
1047 uri_str[str_len] = 0;
1048 hres = create_uri(uri_str, 0, &uri);
1050 heap_free(uri_str);
1051 if(FAILED(hres))
1052 return hres;
1054 hres = load_uri(This->window, uri, BINDING_FROMHIST);
1055 IUri_Release(uri);
1056 return hres;
1059 static HRESULT WINAPI PersistHistory_SaveHistory(IPersistHistory *iface, IStream *pStream)
1061 HTMLDocument *This = impl_from_IPersistHistory(iface);
1062 ULONG len, written;
1063 BSTR display_uri;
1064 HRESULT hres;
1066 TRACE("(%p)->(%p)\n", This, pStream);
1068 if(!This->window || !This->window->uri) {
1069 FIXME("No current URI\n");
1070 return E_FAIL;
1073 /* NOTE: The format we store is *not* compatible with native MSHTML. We currently
1074 * store only URI of the page (as a length followed by a string) */
1075 hres = IUri_GetDisplayUri(This->window->uri, &display_uri);
1076 if(FAILED(hres))
1077 return hres;
1079 len = SysStringLen(display_uri);
1080 hres = IStream_Write(pStream, &len, sizeof(len), &written);
1081 if(SUCCEEDED(hres))
1082 hres = IStream_Write(pStream, display_uri, len*sizeof(WCHAR), &written);
1083 SysFreeString(display_uri);
1084 return hres;
1087 static HRESULT WINAPI PersistHistory_SetPositionCookie(IPersistHistory *iface, DWORD dwPositioncookie)
1089 HTMLDocument *This = impl_from_IPersistHistory(iface);
1090 FIXME("(%p)->(%x)\n", This, dwPositioncookie);
1091 return E_NOTIMPL;
1094 static HRESULT WINAPI PersistHistory_GetPositionCookie(IPersistHistory *iface, DWORD *pdwPositioncookie)
1096 HTMLDocument *This = impl_from_IPersistHistory(iface);
1097 FIXME("(%p)->(%p)\n", This, pdwPositioncookie);
1098 return E_NOTIMPL;
1101 static const IPersistHistoryVtbl PersistHistoryVtbl = {
1102 PersistHistory_QueryInterface,
1103 PersistHistory_AddRef,
1104 PersistHistory_Release,
1105 PersistHistory_GetClassID,
1106 PersistHistory_LoadHistory,
1107 PersistHistory_SaveHistory,
1108 PersistHistory_SetPositionCookie,
1109 PersistHistory_GetPositionCookie
1112 void HTMLDocument_Persist_Init(HTMLDocument *This)
1114 This->IPersistMoniker_iface.lpVtbl = &PersistMonikerVtbl;
1115 This->IPersistFile_iface.lpVtbl = &PersistFileVtbl;
1116 This->IMonikerProp_iface.lpVtbl = &MonikerPropVtbl;
1117 This->IPersistStreamInit_iface.lpVtbl = &PersistStreamInitVtbl;
1118 This->IPersistHistory_iface.lpVtbl = &PersistHistoryVtbl;