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
33 #define NO_SHLWAPI_REG
36 #include "wine/debug.h"
38 #include "mshtml_private.h"
39 #include "htmlscript.h"
40 #include "htmlevent.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
46 /* Undocumented notification, see tests */
47 #define CMDID_EXPLORER_UPDATEHISTORY 38
49 static const WCHAR about_blankW
[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
56 } download_proc_task_t
;
58 static BOOL
use_gecko_script(HTMLOuterWindow
*window
)
63 hres
= IInternetSecurityManager_MapUrlToZone(window
->secmgr
, window
->url
, &zone
, 0);
65 WARN("Could not map %s to zone: %08x\n", debugstr_w(window
->url
), hres
);
69 TRACE("zone %d\n", zone
);
70 return zone
== URLZONE_UNTRUSTED
;
73 static void notify_travellog_update(HTMLDocumentObj
*doc
)
75 IOleCommandTarget
*cmdtrg
;
81 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
88 IOleCommandTarget_Exec(cmdtrg
, &CGID_Explorer
, CMDID_EXPLORER_UPDATEHISTORY
, 0, &vin
, NULL
);
89 IOleCommandTarget_Release(cmdtrg
);
93 void set_current_uri(HTMLOuterWindow
*window
, IUri
*uri
)
96 IUri_Release(window
->uri
);
100 if(window
->uri_nofrag
) {
101 IUri_Release(window
->uri_nofrag
);
102 window
->uri_nofrag
= NULL
;
105 SysFreeString(window
->url
);
114 window
->uri_nofrag
= get_uri_nofrag(uri
);
115 if(!window
->uri_nofrag
) {
116 FIXME("get_uri_nofrag failed\n");
118 window
->uri_nofrag
= uri
;
121 IUri_GetDisplayUri(uri
, &window
->url
);
124 void set_current_mon(HTMLOuterWindow
*This
, IMoniker
*mon
, DWORD flags
)
126 IUriContainer
*uri_container
;
131 if(This
->doc_obj
&& !(flags
& (BINDING_REPLACE
|BINDING_REFRESH
)))
132 notify_travellog_update(This
->doc_obj
);
133 IMoniker_Release(This
->mon
);
137 This
->load_flags
= flags
;
141 IMoniker_AddRef(mon
);
144 hres
= IMoniker_QueryInterface(mon
, &IID_IUriContainer
, (void**)&uri_container
);
145 if(SUCCEEDED(hres
)) {
146 hres
= IUriContainer_GetIUri(uri_container
, &uri
);
147 IUriContainer_Release(uri_container
);
149 WARN("GetIUri failed: %08x\n", hres
);
157 hres
= IMoniker_GetDisplayName(mon
, NULL
, NULL
, &url
);
158 if(SUCCEEDED(hres
)) {
159 hres
= create_uri(url
, 0, &uri
);
161 WARN("CrateUri failed: %08x\n", hres
);
162 set_current_uri(This
, NULL
);
163 This
->url
= SysAllocString(url
);
169 WARN("GetDisplayName failed: %08x\n", hres
);
173 set_current_uri(This
, uri
);
176 set_script_mode(This
, use_gecko_script(This
) ? SCRIPTMODE_GECKO
: SCRIPTMODE_ACTIVESCRIPT
);
179 HRESULT
create_uri(const WCHAR
*uri_str
, DWORD flags
, IUri
**uri
)
181 return CreateUri(uri_str
, flags
| Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
, 0, uri
);
184 HRESULT
create_relative_uri(HTMLOuterWindow
*window
, const WCHAR
*rel_uri
, IUri
**uri
)
187 ? CoInternetCombineUrlEx(window
->uri
, rel_uri
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
, uri
, 0)
188 : create_uri(rel_uri
, 0, uri
);
191 void set_download_state(HTMLDocumentObj
*doc
, int state
)
194 IOleCommandTarget
*olecmd
;
197 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&olecmd
);
198 if(SUCCEEDED(hres
)) {
204 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETDOWNLOADSTATE
,
205 OLECMDEXECOPT_DONTPROMPTUSER
, &var
, NULL
);
206 IOleCommandTarget_Release(olecmd
);
210 doc
->download_state
= state
;
213 static void set_progress_proc(task_t
*_task
)
215 docobj_task_t
*task
= (docobj_task_t
*)_task
;
216 IOleCommandTarget
*olecmd
= NULL
;
217 HTMLDocumentObj
*doc
= task
->doc
;
220 TRACE("(%p)\n", doc
);
223 IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&olecmd
);
226 VARIANT progress_max
, progress
;
228 V_VT(&progress_max
) = VT_I4
;
229 V_I4(&progress_max
) = 0; /* FIXME */
230 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETPROGRESSMAX
, OLECMDEXECOPT_DONTPROMPTUSER
,
231 &progress_max
, NULL
);
233 V_VT(&progress
) = VT_I4
;
234 V_I4(&progress
) = 0; /* FIXME */
235 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETPROGRESSPOS
, OLECMDEXECOPT_DONTPROMPTUSER
,
237 IOleCommandTarget_Release(olecmd
);
240 if(doc
->usermode
== EDITMODE
&& doc
->hostui
) {
241 DOCHOSTUIINFO hostinfo
;
243 memset(&hostinfo
, 0, sizeof(DOCHOSTUIINFO
));
244 hostinfo
.cbSize
= sizeof(DOCHOSTUIINFO
);
245 hres
= IDocHostUIHandler_GetHostInfo(doc
->hostui
, &hostinfo
);
247 /* FIXME: use hostinfo */
248 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
249 hostinfo
.cbSize
, hostinfo
.dwFlags
, hostinfo
.dwDoubleClick
,
250 debugstr_w(hostinfo
.pchHostCss
), debugstr_w(hostinfo
.pchHostNS
));
254 static void set_downloading_proc(task_t
*_task
)
256 download_proc_task_t
*task
= (download_proc_task_t
*)_task
;
257 HTMLDocumentObj
*doc
= task
->doc
;
260 TRACE("(%p)\n", doc
);
262 set_statustext(doc
, IDS_STATUS_DOWNLOADINGFROM
, task
->url
);
264 if(task
->set_download
)
265 set_download_state(doc
, 1);
271 IAdviseSink_OnViewChange(doc
->view_sink
, DVASPECT_CONTENT
, -1);
274 IDropTarget
*drop_target
= NULL
;
276 hres
= IDocHostUIHandler_GetDropTarget(doc
->hostui
, NULL
/* FIXME */, &drop_target
);
277 if(SUCCEEDED(hres
) && drop_target
) {
278 FIXME("Use IDropTarget\n");
279 IDropTarget_Release(drop_target
);
284 static void set_downloading_task_destr(task_t
*_task
)
286 download_proc_task_t
*task
= (download_proc_task_t
*)_task
;
288 CoTaskMemFree(task
->url
);
292 void prepare_for_binding(HTMLDocument
*This
, IMoniker
*mon
, DWORD flags
)
296 if(This
->doc_obj
->client
) {
297 VARIANT silent
, offline
;
299 hres
= get_client_disp_property(This
->doc_obj
->client
, DISPID_AMBIENT_SILENT
, &silent
);
300 if(SUCCEEDED(hres
)) {
301 if(V_VT(&silent
) != VT_BOOL
)
302 WARN("silent = %s\n", debugstr_variant(&silent
));
303 else if(V_BOOL(&silent
))
304 FIXME("silent == true\n");
307 hres
= get_client_disp_property(This
->doc_obj
->client
,
308 DISPID_AMBIENT_OFFLINEIFNOTCONNECTED
, &offline
);
309 if(SUCCEEDED(hres
)) {
310 if(V_VT(&offline
) != VT_BOOL
)
311 WARN("offline = %s\n", debugstr_variant(&offline
));
312 else if(V_BOOL(&offline
))
313 FIXME("offline == true\n");
317 if(This
->window
->mon
) {
318 update_doc(This
, UPDATE_TITLE
|UPDATE_UI
);
320 update_doc(This
, UPDATE_TITLE
);
321 set_current_mon(This
->window
, mon
, flags
);
324 if(This
->doc_obj
->client
) {
325 IOleCommandTarget
*cmdtrg
= NULL
;
327 hres
= IOleClientSite_QueryInterface(This
->doc_obj
->client
, &IID_IOleCommandTarget
,
329 if(SUCCEEDED(hres
)) {
332 if(flags
& BINDING_NAVIGATED
) {
333 V_VT(&var
) = VT_UNKNOWN
;
334 V_UNKNOWN(&var
) = (IUnknown
*)&This
->window
->base
.IHTMLWindow2_iface
;
335 V_VT(&out
) = VT_EMPTY
;
336 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 63, 0, &var
, &out
);
339 }else if(!(flags
& BINDING_FROMHIST
)) {
342 IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 37, 0, &var
, NULL
);
345 IOleCommandTarget_Release(cmdtrg
);
350 HRESULT
set_moniker(HTMLOuterWindow
*window
, IMoniker
*mon
, IUri
*nav_uri
, IBindCtx
*pibc
, nsChannelBSC
*async_bsc
,
353 download_proc_task_t
*download_task
;
354 HTMLDocumentObj
*doc_obj
= NULL
;
355 nsChannelBSC
*bscallback
;
361 if(window
->doc_obj
&& window
->doc_obj
->basedoc
.window
== window
)
362 doc_obj
= window
->doc_obj
;
364 hres
= IMoniker_GetDisplayName(mon
, pibc
, NULL
, &url
);
366 WARN("GetDiaplayName failed: %08x\n", hres
);
373 hres
= create_uri(url
, 0, &uri
);
380 TRACE("got url: %s\n", debugstr_w(url
));
382 set_ready_state(window
, READYSTATE_LOADING
);
384 hres
= create_doc_uri(window
, uri
, &nsuri
);
387 if(SUCCEEDED(hres
)) {
389 bscallback
= async_bsc
;
391 hres
= create_channelbsc(mon
, NULL
, NULL
, 0, TRUE
, &bscallback
);
394 if(SUCCEEDED(hres
)) {
395 if(window
->base
.inner_window
->doc
)
396 remove_target_tasks(window
->base
.inner_window
->task_magic
);
397 abort_window_bindings(window
->base
.inner_window
);
399 hres
= load_nsuri(window
, nsuri
, NULL
, bscallback
, LOAD_FLAGS_BYPASS_CACHE
);
400 nsISupports_Release((nsISupports
*)nsuri
); /* FIXME */
401 if(SUCCEEDED(hres
)) {
402 hres
= create_pending_window(window
, bscallback
);
403 TRACE("pending window for %p %p %p\n", window
, bscallback
, window
->pending_window
);
405 if(bscallback
!= async_bsc
)
406 IBindStatusCallback_Release(&bscallback
->bsc
.IBindStatusCallback_iface
);
415 HTMLDocument_LockContainer(doc_obj
, TRUE
);
420 task
= heap_alloc(sizeof(docobj_task_t
));
422 hres
= push_task(&task
->header
, set_progress_proc
, NULL
, doc_obj
->basedoc
.task_magic
);
429 download_task
= heap_alloc(sizeof(download_proc_task_t
));
430 download_task
->doc
= doc_obj
;
431 download_task
->set_download
= set_download
;
432 download_task
->url
= url
;
433 return push_task(&download_task
->header
, set_downloading_proc
, set_downloading_task_destr
, doc_obj
->basedoc
.task_magic
);
439 static void notif_readystate(HTMLOuterWindow
*window
)
441 window
->readystate_pending
= FALSE
;
443 if(window
->doc_obj
&& window
->doc_obj
->basedoc
.window
== window
)
444 call_property_onchanged(&window
->doc_obj
->basedoc
.cp_container
, DISPID_READYSTATE
);
446 fire_event(window
->base
.inner_window
->doc
, EVENTID_READYSTATECHANGE
, FALSE
,
447 window
->base
.inner_window
->doc
->node
.nsnode
, NULL
, NULL
);
449 if(window
->frame_element
)
450 fire_event(window
->frame_element
->element
.node
.doc
, EVENTID_READYSTATECHANGE
,
451 TRUE
, window
->frame_element
->element
.node
.nsnode
, NULL
, NULL
);
456 HTMLOuterWindow
*window
;
459 static void notif_readystate_proc(task_t
*_task
)
461 readystate_task_t
*task
= (readystate_task_t
*)_task
;
462 notif_readystate(task
->window
);
465 static void notif_readystate_destr(task_t
*_task
)
467 readystate_task_t
*task
= (readystate_task_t
*)_task
;
468 IHTMLWindow2_Release(&task
->window
->base
.IHTMLWindow2_iface
);
471 void set_ready_state(HTMLOuterWindow
*window
, READYSTATE readystate
)
473 READYSTATE prev_state
= window
->readystate
;
475 window
->readystate
= readystate
;
477 if(window
->readystate_locked
) {
478 readystate_task_t
*task
;
481 if(window
->readystate_pending
|| prev_state
== readystate
)
484 task
= heap_alloc(sizeof(*task
));
488 IHTMLWindow2_AddRef(&window
->base
.IHTMLWindow2_iface
);
489 task
->window
= window
;
491 hres
= push_task(&task
->header
, notif_readystate_proc
, notif_readystate_destr
, window
->task_magic
);
493 window
->readystate_pending
= TRUE
;
497 notif_readystate(window
);
500 static HRESULT
get_doc_string(HTMLDocumentNode
*This
, char **str
)
509 WARN("NULL nsdoc\n");
513 nsres
= nsIDOMHTMLDocument_QueryInterface(This
->nsdoc
, &IID_nsIDOMNode
, (void**)&nsnode
);
514 if(NS_FAILED(nsres
)) {
515 ERR("Could not get nsIDOMNode failed: %08x\n", nsres
);
519 nsAString_Init(&nsstr
, NULL
);
520 hres
= nsnode_to_nsstring(nsnode
, &nsstr
);
521 nsIDOMNode_Release(nsnode
);
523 nsAString_Finish(&nsstr
);
527 nsAString_GetData(&nsstr
, &strw
);
528 TRACE("%s\n", debugstr_w(strw
));
530 *str
= heap_strdupWtoA(strw
);
532 nsAString_Finish(&nsstr
);
535 return E_OUTOFMEMORY
;
540 /**********************************************************
541 * IPersistMoniker implementation
544 static inline HTMLDocument
*impl_from_IPersistMoniker(IPersistMoniker
*iface
)
546 return CONTAINING_RECORD(iface
, HTMLDocument
, IPersistMoniker_iface
);
549 static HRESULT WINAPI
PersistMoniker_QueryInterface(IPersistMoniker
*iface
, REFIID riid
, void **ppv
)
551 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
552 return htmldoc_query_interface(This
, riid
, ppv
);
555 static ULONG WINAPI
PersistMoniker_AddRef(IPersistMoniker
*iface
)
557 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
558 return htmldoc_addref(This
);
561 static ULONG WINAPI
PersistMoniker_Release(IPersistMoniker
*iface
)
563 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
564 return htmldoc_release(This
);
567 static HRESULT WINAPI
PersistMoniker_GetClassID(IPersistMoniker
*iface
, CLSID
*pClassID
)
569 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
570 return IPersistFile_GetClassID(&This
->IPersistFile_iface
, pClassID
);
573 static HRESULT WINAPI
PersistMoniker_IsDirty(IPersistMoniker
*iface
)
575 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
577 TRACE("(%p)\n", This
);
579 return IPersistStreamInit_IsDirty(&This
->IPersistStreamInit_iface
);
582 static HRESULT WINAPI
PersistMoniker_Load(IPersistMoniker
*iface
, BOOL fFullyAvailable
,
583 IMoniker
*pimkName
, LPBC pibc
, DWORD grfMode
)
585 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
588 TRACE("(%p)->(%x %p %p %08x)\n", This
, fFullyAvailable
, pimkName
, pibc
, grfMode
);
591 IUnknown
*unk
= NULL
;
595 * "__PrecreatedObject"
596 * "BIND_CONTEXT_PARAM"
597 * "__HTMLLOADOPTIONS"
600 * "_ITransData_Object_"
604 hres
= IBindCtx_GetObjectParam(pibc
, (LPOLESTR
)SZ_HTML_CLIENTSITE_OBJECTPARAM
, &unk
);
605 if(SUCCEEDED(hres
) && unk
) {
606 IOleClientSite
*client
= NULL
;
608 hres
= IUnknown_QueryInterface(unk
, &IID_IOleClientSite
, (void**)&client
);
609 if(SUCCEEDED(hres
)) {
610 TRACE("Got client site %p\n", client
);
611 IOleObject_SetClientSite(&This
->IOleObject_iface
, client
);
612 IOleClientSite_Release(client
);
615 IUnknown_Release(unk
);
619 prepare_for_binding(This
, pimkName
, FALSE
);
620 call_docview_84(This
->doc_obj
);
621 hres
= set_moniker(This
->window
, pimkName
, NULL
, pibc
, NULL
, TRUE
);
625 return start_binding(This
->window
->pending_window
, (BSCallback
*)This
->window
->pending_window
->bscallback
, pibc
);
628 static HRESULT WINAPI
PersistMoniker_Save(IPersistMoniker
*iface
, IMoniker
*pimkName
,
629 LPBC pbc
, BOOL fRemember
)
631 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
632 FIXME("(%p)->(%p %p %x)\n", This
, pimkName
, pbc
, fRemember
);
636 static HRESULT WINAPI
PersistMoniker_SaveCompleted(IPersistMoniker
*iface
, IMoniker
*pimkName
, LPBC pibc
)
638 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
639 FIXME("(%p)->(%p %p)\n", This
, pimkName
, pibc
);
643 static HRESULT WINAPI
PersistMoniker_GetCurMoniker(IPersistMoniker
*iface
, IMoniker
**ppimkName
)
645 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
647 TRACE("(%p)->(%p)\n", This
, ppimkName
);
649 if(!This
->window
|| !This
->window
->mon
)
652 IMoniker_AddRef(This
->window
->mon
);
653 *ppimkName
= This
->window
->mon
;
657 static const IPersistMonikerVtbl PersistMonikerVtbl
= {
658 PersistMoniker_QueryInterface
,
659 PersistMoniker_AddRef
,
660 PersistMoniker_Release
,
661 PersistMoniker_GetClassID
,
662 PersistMoniker_IsDirty
,
665 PersistMoniker_SaveCompleted
,
666 PersistMoniker_GetCurMoniker
669 /**********************************************************
670 * IMonikerProp implementation
673 static inline HTMLDocument
*impl_from_IMonikerProp(IMonikerProp
*iface
)
675 return CONTAINING_RECORD(iface
, HTMLDocument
, IMonikerProp_iface
);
678 static HRESULT WINAPI
MonikerProp_QueryInterface(IMonikerProp
*iface
, REFIID riid
, void **ppv
)
680 HTMLDocument
*This
= impl_from_IMonikerProp(iface
);
681 return htmldoc_query_interface(This
, riid
, ppv
);
684 static ULONG WINAPI
MonikerProp_AddRef(IMonikerProp
*iface
)
686 HTMLDocument
*This
= impl_from_IMonikerProp(iface
);
687 return htmldoc_addref(This
);
690 static ULONG WINAPI
MonikerProp_Release(IMonikerProp
*iface
)
692 HTMLDocument
*This
= impl_from_IMonikerProp(iface
);
693 return htmldoc_release(This
);
696 static HRESULT WINAPI
MonikerProp_PutProperty(IMonikerProp
*iface
, MONIKERPROPERTY mkp
, LPCWSTR val
)
698 HTMLDocument
*This
= impl_from_IMonikerProp(iface
);
700 TRACE("(%p)->(%d %s)\n", This
, mkp
, debugstr_w(val
));
704 heap_free(This
->doc_obj
->mime
);
705 This
->doc_obj
->mime
= heap_strdupW(val
);
712 FIXME("mkp %d\n", mkp
);
719 static const IMonikerPropVtbl MonikerPropVtbl
= {
720 MonikerProp_QueryInterface
,
723 MonikerProp_PutProperty
726 /**********************************************************
727 * IPersistFile implementation
730 static inline HTMLDocument
*impl_from_IPersistFile(IPersistFile
*iface
)
732 return CONTAINING_RECORD(iface
, HTMLDocument
, IPersistFile_iface
);
735 static HRESULT WINAPI
PersistFile_QueryInterface(IPersistFile
*iface
, REFIID riid
, void **ppv
)
737 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
738 return htmldoc_query_interface(This
, riid
, ppv
);
741 static ULONG WINAPI
PersistFile_AddRef(IPersistFile
*iface
)
743 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
744 return htmldoc_addref(This
);
747 static ULONG WINAPI
PersistFile_Release(IPersistFile
*iface
)
749 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
750 return htmldoc_release(This
);
753 static HRESULT WINAPI
PersistFile_GetClassID(IPersistFile
*iface
, CLSID
*pClassID
)
755 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
757 TRACE("(%p)->(%p)\n", This
, pClassID
);
762 *pClassID
= CLSID_HTMLDocument
;
766 static HRESULT WINAPI
PersistFile_IsDirty(IPersistFile
*iface
)
768 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
770 TRACE("(%p)\n", This
);
772 return IPersistStreamInit_IsDirty(&This
->IPersistStreamInit_iface
);
775 static HRESULT WINAPI
PersistFile_Load(IPersistFile
*iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
777 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
778 FIXME("(%p)->(%s %08x)\n", This
, debugstr_w(pszFileName
), dwMode
);
782 static HRESULT WINAPI
PersistFile_Save(IPersistFile
*iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
784 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
790 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(pszFileName
), fRemember
);
792 file
= CreateFileW(pszFileName
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
793 FILE_ATTRIBUTE_NORMAL
, NULL
);
794 if(file
== INVALID_HANDLE_VALUE
) {
795 WARN("Could not create file: %u\n", GetLastError());
799 hres
= get_doc_string(This
->doc_node
, &str
);
801 WriteFile(file
, str
, strlen(str
), &written
, NULL
);
807 static HRESULT WINAPI
PersistFile_SaveCompleted(IPersistFile
*iface
, LPCOLESTR pszFileName
)
809 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
810 FIXME("(%p)->(%s)\n", This
, debugstr_w(pszFileName
));
814 static HRESULT WINAPI
PersistFile_GetCurFile(IPersistFile
*iface
, LPOLESTR
*pszFileName
)
816 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
817 FIXME("(%p)->(%p)\n", This
, pszFileName
);
821 static const IPersistFileVtbl PersistFileVtbl
= {
822 PersistFile_QueryInterface
,
825 PersistFile_GetClassID
,
829 PersistFile_SaveCompleted
,
830 PersistFile_GetCurFile
833 static inline HTMLDocument
*impl_from_IPersistStreamInit(IPersistStreamInit
*iface
)
835 return CONTAINING_RECORD(iface
, HTMLDocument
, IPersistStreamInit_iface
);
838 static HRESULT WINAPI
PersistStreamInit_QueryInterface(IPersistStreamInit
*iface
,
839 REFIID riid
, void **ppv
)
841 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
842 return htmldoc_query_interface(This
, riid
, ppv
);
845 static ULONG WINAPI
PersistStreamInit_AddRef(IPersistStreamInit
*iface
)
847 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
848 return htmldoc_addref(This
);
851 static ULONG WINAPI
PersistStreamInit_Release(IPersistStreamInit
*iface
)
853 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
854 return htmldoc_release(This
);
857 static HRESULT WINAPI
PersistStreamInit_GetClassID(IPersistStreamInit
*iface
, CLSID
*pClassID
)
859 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
860 return IPersistFile_GetClassID(&This
->IPersistFile_iface
, pClassID
);
863 static HRESULT WINAPI
PersistStreamInit_IsDirty(IPersistStreamInit
*iface
)
865 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
867 TRACE("(%p)\n", This
);
869 if(This
->doc_obj
->usermode
== EDITMODE
)
870 return editor_is_dirty(This
);
875 static HRESULT WINAPI
PersistStreamInit_Load(IPersistStreamInit
*iface
, LPSTREAM pStm
)
877 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
881 TRACE("(%p)->(%p)\n", This
, pStm
);
883 hres
= CreateURLMoniker(NULL
, about_blankW
, &mon
);
885 WARN("CreateURLMoniker failed: %08x\n", hres
);
889 prepare_for_binding(This
, mon
, FALSE
);
890 hres
= set_moniker(This
->window
, mon
, NULL
, NULL
, NULL
, TRUE
);
894 hres
= channelbsc_load_stream(This
->window
->pending_window
, mon
, pStm
);
895 IMoniker_Release(mon
);
899 static HRESULT WINAPI
PersistStreamInit_Save(IPersistStreamInit
*iface
, LPSTREAM pStm
,
902 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
907 TRACE("(%p)->(%p %x)\n", This
, pStm
, fClearDirty
);
909 hres
= get_doc_string(This
->doc_node
, &str
);
913 hres
= IStream_Write(pStm
, str
, strlen(str
), &written
);
915 FIXME("Write failed: %08x\n", hres
);
920 set_dirty(This
, VARIANT_FALSE
);
925 static HRESULT WINAPI
PersistStreamInit_GetSizeMax(IPersistStreamInit
*iface
,
926 ULARGE_INTEGER
*pcbSize
)
928 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
929 FIXME("(%p)->(%p)\n", This
, pcbSize
);
933 static HRESULT WINAPI
PersistStreamInit_InitNew(IPersistStreamInit
*iface
)
935 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
939 TRACE("(%p)\n", This
);
941 hres
= CreateURLMoniker(NULL
, about_blankW
, &mon
);
943 WARN("CreateURLMoniker failed: %08x\n", hres
);
947 prepare_for_binding(This
, mon
, FALSE
);
948 hres
= set_moniker(This
->window
, mon
, NULL
, NULL
, NULL
, FALSE
);
952 hres
= channelbsc_load_stream(This
->window
->pending_window
, mon
, NULL
);
953 IMoniker_Release(mon
);
957 static const IPersistStreamInitVtbl PersistStreamInitVtbl
= {
958 PersistStreamInit_QueryInterface
,
959 PersistStreamInit_AddRef
,
960 PersistStreamInit_Release
,
961 PersistStreamInit_GetClassID
,
962 PersistStreamInit_IsDirty
,
963 PersistStreamInit_Load
,
964 PersistStreamInit_Save
,
965 PersistStreamInit_GetSizeMax
,
966 PersistStreamInit_InitNew
969 /**********************************************************
970 * IPersistHistory implementation
973 static inline HTMLDocument
*impl_from_IPersistHistory(IPersistHistory
*iface
)
975 return CONTAINING_RECORD(iface
, HTMLDocument
, IPersistHistory_iface
);
978 static HRESULT WINAPI
PersistHistory_QueryInterface(IPersistHistory
*iface
, REFIID riid
, void **ppv
)
980 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
981 return htmldoc_query_interface(This
, riid
, ppv
);
984 static ULONG WINAPI
PersistHistory_AddRef(IPersistHistory
*iface
)
986 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
987 return htmldoc_addref(This
);
990 static ULONG WINAPI
PersistHistory_Release(IPersistHistory
*iface
)
992 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
993 return htmldoc_release(This
);
996 static HRESULT WINAPI
PersistHistory_GetClassID(IPersistHistory
*iface
, CLSID
*pClassID
)
998 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
999 return IPersistFile_GetClassID(&This
->IPersistFile_iface
, pClassID
);
1002 static HRESULT WINAPI
PersistHistory_LoadHistory(IPersistHistory
*iface
, IStream
*pStream
, IBindCtx
*pbc
)
1004 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1005 ULONG str_len
, read
;
1010 TRACE("(%p)->(%p %p)\n", This
, pStream
, pbc
);
1013 FIXME("No current window\n");
1014 return E_UNEXPECTED
;
1018 FIXME("pbc not supported\n");
1020 if(This
->doc_obj
->client
) {
1021 IOleCommandTarget
*cmdtrg
= NULL
;
1023 hres
= IOleClientSite_QueryInterface(This
->doc_obj
->client
, &IID_IOleCommandTarget
,
1025 if(SUCCEEDED(hres
)) {
1026 IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 138, 0, NULL
, NULL
);
1027 IOleCommandTarget_Release(cmdtrg
);
1031 hres
= IStream_Read(pStream
, &str_len
, sizeof(str_len
), &read
);
1034 if(read
!= sizeof(str_len
))
1037 uri_str
= heap_alloc((str_len
+1)*sizeof(WCHAR
));
1039 return E_OUTOFMEMORY
;
1041 hres
= IStream_Read(pStream
, uri_str
, str_len
*sizeof(WCHAR
), &read
);
1042 if(SUCCEEDED(hres
) && read
!= str_len
*sizeof(WCHAR
))
1044 if(SUCCEEDED(hres
)) {
1045 uri_str
[str_len
] = 0;
1046 hres
= create_uri(uri_str
, 0, &uri
);
1052 hres
= load_uri(This
->window
, uri
, BINDING_FROMHIST
);
1057 static HRESULT WINAPI
PersistHistory_SaveHistory(IPersistHistory
*iface
, IStream
*pStream
)
1059 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1064 TRACE("(%p)->(%p)\n", This
, pStream
);
1066 if(!This
->window
|| !This
->window
->uri
) {
1067 FIXME("No current URI\n");
1071 /* NOTE: The format we store is *not* compatible with native MSHTML. We currently
1072 * store only URI of the page (as a length followed by a string) */
1073 hres
= IUri_GetDisplayUri(This
->window
->uri
, &display_uri
);
1077 len
= SysStringLen(display_uri
);
1078 hres
= IStream_Write(pStream
, &len
, sizeof(len
), &written
);
1080 hres
= IStream_Write(pStream
, display_uri
, len
*sizeof(WCHAR
), &written
);
1081 SysFreeString(display_uri
);
1085 static HRESULT WINAPI
PersistHistory_SetPositionCookie(IPersistHistory
*iface
, DWORD dwPositioncookie
)
1087 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1088 FIXME("(%p)->(%x)\n", This
, dwPositioncookie
);
1092 static HRESULT WINAPI
PersistHistory_GetPositionCookie(IPersistHistory
*iface
, DWORD
*pdwPositioncookie
)
1094 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1095 FIXME("(%p)->(%p)\n", This
, pdwPositioncookie
);
1099 static const IPersistHistoryVtbl PersistHistoryVtbl
= {
1100 PersistHistory_QueryInterface
,
1101 PersistHistory_AddRef
,
1102 PersistHistory_Release
,
1103 PersistHistory_GetClassID
,
1104 PersistHistory_LoadHistory
,
1105 PersistHistory_SaveHistory
,
1106 PersistHistory_SetPositionCookie
,
1107 PersistHistory_GetPositionCookie
1110 void HTMLDocument_Persist_Init(HTMLDocument
*This
)
1112 This
->IPersistMoniker_iface
.lpVtbl
= &PersistMonikerVtbl
;
1113 This
->IPersistFile_iface
.lpVtbl
= &PersistFileVtbl
;
1114 This
->IMonikerProp_iface
.lpVtbl
= &MonikerPropVtbl
;
1115 This
->IPersistStreamInit_iface
.lpVtbl
= &PersistStreamInitVtbl
;
1116 This
->IPersistHistory_iface
.lpVtbl
= &PersistHistoryVtbl
;