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
34 #define NO_SHLWAPI_REG
37 #include "wine/debug.h"
39 #include "mshtml_private.h"
40 #include "htmlscript.h"
41 #include "htmlevent.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
47 /* Undocumented notification, see tests */
48 #define CMDID_EXPLORER_UPDATEHISTORY 38
50 static const WCHAR about_blankW
[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
57 } download_proc_task_t
;
59 static BOOL
use_gecko_script(HTMLOuterWindow
*window
)
64 hres
= IInternetSecurityManager_MapUrlToZone(window
->secmgr
, window
->url
, &zone
, 0);
66 WARN("Could not map %s to zone: %08x\n", debugstr_w(window
->url
), hres
);
70 TRACE("zone %d\n", zone
);
71 return zone
== URLZONE_UNTRUSTED
;
74 static void notify_travellog_update(HTMLDocumentObj
*doc
)
76 IOleCommandTarget
*cmdtrg
;
82 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
89 IOleCommandTarget_Exec(cmdtrg
, &CGID_Explorer
, CMDID_EXPLORER_UPDATEHISTORY
, 0, &vin
, NULL
);
90 IOleCommandTarget_Release(cmdtrg
);
94 void set_current_uri(HTMLOuterWindow
*window
, IUri
*uri
)
97 IUri_Release(window
->uri
);
101 if(window
->uri_nofrag
) {
102 IUri_Release(window
->uri_nofrag
);
103 window
->uri_nofrag
= NULL
;
106 SysFreeString(window
->url
);
115 window
->uri_nofrag
= get_uri_nofrag(uri
);
116 if(!window
->uri_nofrag
) {
117 FIXME("get_uri_nofrag failed\n");
119 window
->uri_nofrag
= uri
;
122 IUri_GetDisplayUri(uri
, &window
->url
);
125 void set_current_mon(HTMLOuterWindow
*This
, IMoniker
*mon
, DWORD flags
)
127 IUriContainer
*uri_container
;
132 if(This
->doc_obj
&& !(flags
& (BINDING_REPLACE
|BINDING_REFRESH
))) {
133 if(This
== This
->doc_obj
->basedoc
.window
)
134 notify_travellog_update(This
->doc_obj
);
136 TRACE("Skipping travellog update for frame navigation.\n");
138 IMoniker_Release(This
->mon
);
142 This
->load_flags
= flags
;
146 IMoniker_AddRef(mon
);
149 hres
= IMoniker_QueryInterface(mon
, &IID_IUriContainer
, (void**)&uri_container
);
150 if(SUCCEEDED(hres
)) {
151 hres
= IUriContainer_GetIUri(uri_container
, &uri
);
152 IUriContainer_Release(uri_container
);
154 WARN("GetIUri failed: %08x\n", hres
);
162 hres
= IMoniker_GetDisplayName(mon
, NULL
, NULL
, &url
);
163 if(SUCCEEDED(hres
)) {
164 hres
= create_uri(url
, 0, &uri
);
166 WARN("CreateUri failed: %08x\n", hres
);
167 set_current_uri(This
, NULL
);
168 This
->url
= SysAllocString(url
);
174 WARN("GetDisplayName failed: %08x\n", hres
);
178 set_current_uri(This
, uri
);
181 set_script_mode(This
, use_gecko_script(This
) ? SCRIPTMODE_GECKO
: SCRIPTMODE_ACTIVESCRIPT
);
184 HRESULT
create_uri(const WCHAR
*uri_str
, DWORD flags
, IUri
**uri
)
186 return CreateUri(uri_str
, flags
| Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
, 0, uri
);
189 HRESULT
create_relative_uri(HTMLOuterWindow
*window
, const WCHAR
*rel_uri
, IUri
**uri
)
192 ? CoInternetCombineUrlEx(window
->uri
, rel_uri
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
, uri
, 0)
193 : create_uri(rel_uri
, 0, uri
);
196 void set_download_state(HTMLDocumentObj
*doc
, int state
)
199 IOleCommandTarget
*olecmd
;
202 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&olecmd
);
203 if(SUCCEEDED(hres
)) {
209 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETDOWNLOADSTATE
,
210 OLECMDEXECOPT_DONTPROMPTUSER
, &var
, NULL
);
211 IOleCommandTarget_Release(olecmd
);
215 doc
->download_state
= state
;
218 static void set_progress_proc(task_t
*_task
)
220 docobj_task_t
*task
= (docobj_task_t
*)_task
;
221 IOleCommandTarget
*olecmd
= NULL
;
222 HTMLDocumentObj
*doc
= task
->doc
;
225 TRACE("(%p)\n", doc
);
228 IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&olecmd
);
231 VARIANT progress_max
, progress
;
233 V_VT(&progress_max
) = VT_I4
;
234 V_I4(&progress_max
) = 0; /* FIXME */
235 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETPROGRESSMAX
, OLECMDEXECOPT_DONTPROMPTUSER
,
236 &progress_max
, NULL
);
238 V_VT(&progress
) = VT_I4
;
239 V_I4(&progress
) = 0; /* FIXME */
240 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETPROGRESSPOS
, OLECMDEXECOPT_DONTPROMPTUSER
,
242 IOleCommandTarget_Release(olecmd
);
245 if(doc
->usermode
== EDITMODE
&& doc
->hostui
) {
246 DOCHOSTUIINFO hostinfo
;
248 memset(&hostinfo
, 0, sizeof(DOCHOSTUIINFO
));
249 hostinfo
.cbSize
= sizeof(DOCHOSTUIINFO
);
250 hres
= IDocHostUIHandler_GetHostInfo(doc
->hostui
, &hostinfo
);
252 /* FIXME: use hostinfo */
253 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
254 hostinfo
.cbSize
, hostinfo
.dwFlags
, hostinfo
.dwDoubleClick
,
255 debugstr_w(hostinfo
.pchHostCss
), debugstr_w(hostinfo
.pchHostNS
));
259 static void set_downloading_proc(task_t
*_task
)
261 download_proc_task_t
*task
= (download_proc_task_t
*)_task
;
262 HTMLDocumentObj
*doc
= task
->doc
;
265 TRACE("(%p)\n", doc
);
267 set_statustext(doc
, IDS_STATUS_DOWNLOADINGFROM
, task
->url
);
269 if(task
->set_download
)
270 set_download_state(doc
, 1);
276 IAdviseSink_OnViewChange(doc
->view_sink
, DVASPECT_CONTENT
, -1);
279 IDropTarget
*drop_target
= NULL
;
281 hres
= IDocHostUIHandler_GetDropTarget(doc
->hostui
, NULL
/* FIXME */, &drop_target
);
282 if(SUCCEEDED(hres
) && drop_target
) {
283 FIXME("Use IDropTarget\n");
284 IDropTarget_Release(drop_target
);
289 static void set_downloading_task_destr(task_t
*_task
)
291 download_proc_task_t
*task
= (download_proc_task_t
*)_task
;
293 CoTaskMemFree(task
->url
);
297 void prepare_for_binding(HTMLDocument
*This
, IMoniker
*mon
, DWORD flags
)
301 if(This
->doc_obj
->client
) {
302 VARIANT silent
, offline
;
304 hres
= get_client_disp_property(This
->doc_obj
->client
, DISPID_AMBIENT_SILENT
, &silent
);
305 if(SUCCEEDED(hres
)) {
306 if(V_VT(&silent
) != VT_BOOL
)
307 WARN("silent = %s\n", debugstr_variant(&silent
));
308 else if(V_BOOL(&silent
))
309 FIXME("silent == true\n");
312 hres
= get_client_disp_property(This
->doc_obj
->client
,
313 DISPID_AMBIENT_OFFLINEIFNOTCONNECTED
, &offline
);
314 if(SUCCEEDED(hres
)) {
315 if(V_VT(&offline
) != VT_BOOL
)
316 WARN("offline = %s\n", debugstr_variant(&offline
));
317 else if(V_BOOL(&offline
))
318 FIXME("offline == true\n");
322 if(This
->window
->mon
) {
323 update_doc(This
->doc_obj
, UPDATE_TITLE
|UPDATE_UI
);
325 update_doc(This
->doc_obj
, UPDATE_TITLE
);
326 set_current_mon(This
->window
, mon
, flags
);
329 if(This
->doc_obj
->client
) {
330 IOleCommandTarget
*cmdtrg
= NULL
;
332 hres
= IOleClientSite_QueryInterface(This
->doc_obj
->client
, &IID_IOleCommandTarget
,
334 if(SUCCEEDED(hres
)) {
337 if(flags
& BINDING_NAVIGATED
) {
338 V_VT(&var
) = VT_UNKNOWN
;
339 V_UNKNOWN(&var
) = (IUnknown
*)&This
->window
->base
.IHTMLWindow2_iface
;
340 V_VT(&out
) = VT_EMPTY
;
341 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 63, 0, &var
, &out
);
344 }else if(!(flags
& BINDING_FROMHIST
)) {
347 IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 37, 0, &var
, NULL
);
350 IOleCommandTarget_Release(cmdtrg
);
355 HRESULT
set_moniker(HTMLOuterWindow
*window
, IMoniker
*mon
, IUri
*nav_uri
, IBindCtx
*pibc
, nsChannelBSC
*async_bsc
,
358 download_proc_task_t
*download_task
;
359 HTMLDocumentObj
*doc_obj
= NULL
;
360 nsChannelBSC
*bscallback
;
366 if(window
->doc_obj
&& window
->doc_obj
->basedoc
.window
== window
)
367 doc_obj
= window
->doc_obj
;
369 hres
= IMoniker_GetDisplayName(mon
, pibc
, NULL
, &url
);
371 WARN("GetDiaplayName failed: %08x\n", hres
);
378 hres
= create_uri(url
, 0, &uri
);
385 TRACE("got url: %s\n", debugstr_w(url
));
387 set_ready_state(window
, READYSTATE_LOADING
);
389 hres
= create_doc_uri(window
, uri
, &nsuri
);
392 if(SUCCEEDED(hres
)) {
394 bscallback
= async_bsc
;
396 hres
= create_channelbsc(mon
, NULL
, NULL
, 0, TRUE
, &bscallback
);
399 if(SUCCEEDED(hres
)) {
400 if(window
->base
.inner_window
->doc
)
401 remove_target_tasks(window
->base
.inner_window
->task_magic
);
402 abort_window_bindings(window
->base
.inner_window
);
404 hres
= load_nsuri(window
, nsuri
, NULL
, bscallback
, LOAD_FLAGS_BYPASS_CACHE
);
405 nsISupports_Release((nsISupports
*)nsuri
); /* FIXME */
406 if(SUCCEEDED(hres
)) {
407 hres
= create_pending_window(window
, bscallback
);
408 TRACE("pending window for %p %p %p\n", window
, bscallback
, window
->pending_window
);
410 if(bscallback
!= async_bsc
)
411 IBindStatusCallback_Release(&bscallback
->bsc
.IBindStatusCallback_iface
);
420 HTMLDocument_LockContainer(doc_obj
, TRUE
);
425 task
= heap_alloc(sizeof(docobj_task_t
));
427 hres
= push_task(&task
->header
, set_progress_proc
, NULL
, doc_obj
->task_magic
);
434 download_task
= heap_alloc(sizeof(download_proc_task_t
));
435 download_task
->doc
= doc_obj
;
436 download_task
->set_download
= set_download
;
437 download_task
->url
= url
;
438 return push_task(&download_task
->header
, set_downloading_proc
, set_downloading_task_destr
, doc_obj
->task_magic
);
444 static void notif_readystate(HTMLOuterWindow
*window
)
449 window
->readystate_pending
= FALSE
;
451 if(window
->doc_obj
&& window
->doc_obj
->basedoc
.window
== window
)
452 call_property_onchanged(&window
->doc_obj
->basedoc
.cp_container
, DISPID_READYSTATE
);
454 hres
= create_document_event(window
->base
.inner_window
->doc
, EVENTID_READYSTATECHANGE
, &event
);
455 if(SUCCEEDED(hres
)) {
456 event
->no_event_obj
= TRUE
;
457 dispatch_event(&window
->base
.inner_window
->doc
->node
.event_target
, event
);
458 IDOMEvent_Release(&event
->IDOMEvent_iface
);
461 if(window
->frame_element
) {
462 hres
= create_document_event(window
->frame_element
->element
.node
.doc
, EVENTID_READYSTATECHANGE
, &event
);
463 if(SUCCEEDED(hres
)) {
464 dispatch_event(&window
->frame_element
->element
.node
.event_target
, event
);
465 IDOMEvent_Release(&event
->IDOMEvent_iface
);
472 HTMLOuterWindow
*window
;
475 static void notif_readystate_proc(task_t
*_task
)
477 readystate_task_t
*task
= (readystate_task_t
*)_task
;
478 notif_readystate(task
->window
);
481 static void notif_readystate_destr(task_t
*_task
)
483 readystate_task_t
*task
= (readystate_task_t
*)_task
;
484 IHTMLWindow2_Release(&task
->window
->base
.IHTMLWindow2_iface
);
487 void set_ready_state(HTMLOuterWindow
*window
, READYSTATE readystate
)
489 READYSTATE prev_state
= window
->readystate
;
491 window
->readystate
= readystate
;
493 if(window
->readystate_locked
) {
494 readystate_task_t
*task
;
497 if(window
->readystate_pending
|| prev_state
== readystate
)
500 task
= heap_alloc(sizeof(*task
));
504 IHTMLWindow2_AddRef(&window
->base
.IHTMLWindow2_iface
);
505 task
->window
= window
;
507 hres
= push_task(&task
->header
, notif_readystate_proc
, notif_readystate_destr
, window
->task_magic
);
509 window
->readystate_pending
= TRUE
;
513 notif_readystate(window
);
516 static HRESULT
get_doc_string(HTMLDocumentNode
*This
, char **str
)
525 WARN("NULL nsdoc\n");
529 nsres
= nsIDOMHTMLDocument_QueryInterface(This
->nsdoc
, &IID_nsIDOMNode
, (void**)&nsnode
);
530 if(NS_FAILED(nsres
)) {
531 ERR("Could not get nsIDOMNode failed: %08x\n", nsres
);
535 nsAString_Init(&nsstr
, NULL
);
536 hres
= nsnode_to_nsstring(nsnode
, &nsstr
);
537 nsIDOMNode_Release(nsnode
);
539 nsAString_Finish(&nsstr
);
543 nsAString_GetData(&nsstr
, &strw
);
544 TRACE("%s\n", debugstr_w(strw
));
546 *str
= heap_strdupWtoA(strw
);
548 nsAString_Finish(&nsstr
);
551 return E_OUTOFMEMORY
;
556 /**********************************************************
557 * IPersistMoniker implementation
560 static inline HTMLDocument
*impl_from_IPersistMoniker(IPersistMoniker
*iface
)
562 return CONTAINING_RECORD(iface
, HTMLDocument
, IPersistMoniker_iface
);
565 static HRESULT WINAPI
PersistMoniker_QueryInterface(IPersistMoniker
*iface
, REFIID riid
, void **ppv
)
567 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
568 return htmldoc_query_interface(This
, riid
, ppv
);
571 static ULONG WINAPI
PersistMoniker_AddRef(IPersistMoniker
*iface
)
573 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
574 return htmldoc_addref(This
);
577 static ULONG WINAPI
PersistMoniker_Release(IPersistMoniker
*iface
)
579 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
580 return htmldoc_release(This
);
583 static HRESULT WINAPI
PersistMoniker_GetClassID(IPersistMoniker
*iface
, CLSID
*pClassID
)
585 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
586 return IPersistFile_GetClassID(&This
->IPersistFile_iface
, pClassID
);
589 static HRESULT WINAPI
PersistMoniker_IsDirty(IPersistMoniker
*iface
)
591 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
593 TRACE("(%p)\n", This
);
595 return IPersistStreamInit_IsDirty(&This
->IPersistStreamInit_iface
);
598 static HRESULT WINAPI
PersistMoniker_Load(IPersistMoniker
*iface
, BOOL fFullyAvailable
,
599 IMoniker
*pimkName
, LPBC pibc
, DWORD grfMode
)
601 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
605 TRACE("(%p)->(%x %p %p %08x)\n", This
, fFullyAvailable
, pimkName
, pibc
, grfMode
);
608 IUnknown
*unk
= NULL
;
612 * "__PrecreatedObject"
613 * "BIND_CONTEXT_PARAM"
614 * "__HTMLLOADOPTIONS"
617 * "_ITransData_Object_"
621 hres
= IBindCtx_GetObjectParam(pibc
, (LPOLESTR
)SZ_HTML_CLIENTSITE_OBJECTPARAM
, &unk
);
622 if(SUCCEEDED(hres
) && unk
) {
623 IOleClientSite
*client
= NULL
;
625 hres
= IUnknown_QueryInterface(unk
, &IID_IOleClientSite
, (void**)&client
);
626 if(SUCCEEDED(hres
)) {
627 TRACE("Got client site %p\n", client
);
628 IOleObject_SetClientSite(&This
->IOleObject_iface
, client
);
629 IOleClientSite_Release(client
);
632 IUnknown_Release(unk
);
636 if(This
->doc_obj
->is_mhtml
) {
639 hres
= MimeOleObjectFromMoniker(0, pimkName
, pibc
, &IID_IUnknown
, (void**)&unk
, &mon
);
642 IUnknown_Release(unk
);
645 IMoniker_AddRef(mon
= pimkName
);
648 prepare_for_binding(This
, mon
, FALSE
);
649 call_docview_84(This
->doc_obj
);
650 hres
= set_moniker(This
->window
, mon
, NULL
, pibc
, NULL
, TRUE
);
651 IMoniker_Release(mon
);
655 return start_binding(This
->window
->pending_window
, (BSCallback
*)This
->window
->pending_window
->bscallback
, pibc
);
658 static HRESULT WINAPI
PersistMoniker_Save(IPersistMoniker
*iface
, IMoniker
*pimkName
,
659 LPBC pbc
, BOOL fRemember
)
661 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
662 FIXME("(%p)->(%p %p %x)\n", This
, pimkName
, pbc
, fRemember
);
666 static HRESULT WINAPI
PersistMoniker_SaveCompleted(IPersistMoniker
*iface
, IMoniker
*pimkName
, LPBC pibc
)
668 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
669 FIXME("(%p)->(%p %p)\n", This
, pimkName
, pibc
);
673 static HRESULT WINAPI
PersistMoniker_GetCurMoniker(IPersistMoniker
*iface
, IMoniker
**ppimkName
)
675 HTMLDocument
*This
= impl_from_IPersistMoniker(iface
);
677 TRACE("(%p)->(%p)\n", This
, ppimkName
);
679 if(!This
->window
|| !This
->window
->mon
)
682 IMoniker_AddRef(This
->window
->mon
);
683 *ppimkName
= This
->window
->mon
;
687 static const IPersistMonikerVtbl PersistMonikerVtbl
= {
688 PersistMoniker_QueryInterface
,
689 PersistMoniker_AddRef
,
690 PersistMoniker_Release
,
691 PersistMoniker_GetClassID
,
692 PersistMoniker_IsDirty
,
695 PersistMoniker_SaveCompleted
,
696 PersistMoniker_GetCurMoniker
699 /**********************************************************
700 * IMonikerProp implementation
703 static inline HTMLDocument
*impl_from_IMonikerProp(IMonikerProp
*iface
)
705 return CONTAINING_RECORD(iface
, HTMLDocument
, IMonikerProp_iface
);
708 static HRESULT WINAPI
MonikerProp_QueryInterface(IMonikerProp
*iface
, REFIID riid
, void **ppv
)
710 HTMLDocument
*This
= impl_from_IMonikerProp(iface
);
711 return htmldoc_query_interface(This
, riid
, ppv
);
714 static ULONG WINAPI
MonikerProp_AddRef(IMonikerProp
*iface
)
716 HTMLDocument
*This
= impl_from_IMonikerProp(iface
);
717 return htmldoc_addref(This
);
720 static ULONG WINAPI
MonikerProp_Release(IMonikerProp
*iface
)
722 HTMLDocument
*This
= impl_from_IMonikerProp(iface
);
723 return htmldoc_release(This
);
726 static HRESULT WINAPI
MonikerProp_PutProperty(IMonikerProp
*iface
, MONIKERPROPERTY mkp
, LPCWSTR val
)
728 HTMLDocument
*This
= impl_from_IMonikerProp(iface
);
730 TRACE("(%p)->(%d %s)\n", This
, mkp
, debugstr_w(val
));
734 heap_free(This
->doc_obj
->mime
);
735 This
->doc_obj
->mime
= heap_strdupW(val
);
742 FIXME("mkp %d\n", mkp
);
749 static const IMonikerPropVtbl MonikerPropVtbl
= {
750 MonikerProp_QueryInterface
,
753 MonikerProp_PutProperty
756 /**********************************************************
757 * IPersistFile implementation
760 static inline HTMLDocument
*impl_from_IPersistFile(IPersistFile
*iface
)
762 return CONTAINING_RECORD(iface
, HTMLDocument
, IPersistFile_iface
);
765 static HRESULT WINAPI
PersistFile_QueryInterface(IPersistFile
*iface
, REFIID riid
, void **ppv
)
767 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
768 return htmldoc_query_interface(This
, riid
, ppv
);
771 static ULONG WINAPI
PersistFile_AddRef(IPersistFile
*iface
)
773 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
774 return htmldoc_addref(This
);
777 static ULONG WINAPI
PersistFile_Release(IPersistFile
*iface
)
779 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
780 return htmldoc_release(This
);
783 static HRESULT WINAPI
PersistFile_GetClassID(IPersistFile
*iface
, CLSID
*pClassID
)
785 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
787 TRACE("(%p)->(%p)\n", This
, pClassID
);
792 *pClassID
= CLSID_HTMLDocument
;
796 static HRESULT WINAPI
PersistFile_IsDirty(IPersistFile
*iface
)
798 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
800 TRACE("(%p)\n", This
);
802 return IPersistStreamInit_IsDirty(&This
->IPersistStreamInit_iface
);
805 static HRESULT WINAPI
PersistFile_Load(IPersistFile
*iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
807 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
808 FIXME("(%p)->(%s %08x)\n", This
, debugstr_w(pszFileName
), dwMode
);
812 static HRESULT WINAPI
PersistFile_Save(IPersistFile
*iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
814 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
820 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(pszFileName
), fRemember
);
822 file
= CreateFileW(pszFileName
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
823 FILE_ATTRIBUTE_NORMAL
, NULL
);
824 if(file
== INVALID_HANDLE_VALUE
) {
825 WARN("Could not create file: %u\n", GetLastError());
829 hres
= get_doc_string(This
->doc_node
, &str
);
831 WriteFile(file
, str
, strlen(str
), &written
, NULL
);
837 static HRESULT WINAPI
PersistFile_SaveCompleted(IPersistFile
*iface
, LPCOLESTR pszFileName
)
839 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
840 FIXME("(%p)->(%s)\n", This
, debugstr_w(pszFileName
));
844 static HRESULT WINAPI
PersistFile_GetCurFile(IPersistFile
*iface
, LPOLESTR
*pszFileName
)
846 HTMLDocument
*This
= impl_from_IPersistFile(iface
);
847 FIXME("(%p)->(%p)\n", This
, pszFileName
);
851 static const IPersistFileVtbl PersistFileVtbl
= {
852 PersistFile_QueryInterface
,
855 PersistFile_GetClassID
,
859 PersistFile_SaveCompleted
,
860 PersistFile_GetCurFile
863 static inline HTMLDocument
*impl_from_IPersistStreamInit(IPersistStreamInit
*iface
)
865 return CONTAINING_RECORD(iface
, HTMLDocument
, IPersistStreamInit_iface
);
868 static HRESULT WINAPI
PersistStreamInit_QueryInterface(IPersistStreamInit
*iface
,
869 REFIID riid
, void **ppv
)
871 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
872 return htmldoc_query_interface(This
, riid
, ppv
);
875 static ULONG WINAPI
PersistStreamInit_AddRef(IPersistStreamInit
*iface
)
877 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
878 return htmldoc_addref(This
);
881 static ULONG WINAPI
PersistStreamInit_Release(IPersistStreamInit
*iface
)
883 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
884 return htmldoc_release(This
);
887 static HRESULT WINAPI
PersistStreamInit_GetClassID(IPersistStreamInit
*iface
, CLSID
*pClassID
)
889 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
890 return IPersistFile_GetClassID(&This
->IPersistFile_iface
, pClassID
);
893 static HRESULT WINAPI
PersistStreamInit_IsDirty(IPersistStreamInit
*iface
)
895 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
897 TRACE("(%p)\n", This
);
899 if(This
->doc_obj
->usermode
== EDITMODE
)
900 return editor_is_dirty(This
);
905 static HRESULT WINAPI
PersistStreamInit_Load(IPersistStreamInit
*iface
, IStream
*pStm
)
907 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
911 TRACE("(%p)->(%p)\n", This
, pStm
);
913 hres
= CreateURLMoniker(NULL
, about_blankW
, &mon
);
915 WARN("CreateURLMoniker failed: %08x\n", hres
);
919 prepare_for_binding(This
, mon
, FALSE
);
920 hres
= set_moniker(This
->window
, mon
, NULL
, NULL
, NULL
, TRUE
);
922 hres
= channelbsc_load_stream(This
->window
->pending_window
, mon
, pStm
);
924 IMoniker_Release(mon
);
928 static HRESULT WINAPI
PersistStreamInit_Save(IPersistStreamInit
*iface
, IStream
*pStm
,
931 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
936 TRACE("(%p)->(%p %x)\n", This
, pStm
, fClearDirty
);
938 hres
= get_doc_string(This
->doc_node
, &str
);
942 hres
= IStream_Write(pStm
, str
, strlen(str
), &written
);
944 FIXME("Write failed: %08x\n", hres
);
949 set_dirty(This
, VARIANT_FALSE
);
954 static HRESULT WINAPI
PersistStreamInit_GetSizeMax(IPersistStreamInit
*iface
,
955 ULARGE_INTEGER
*pcbSize
)
957 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
958 FIXME("(%p)->(%p)\n", This
, pcbSize
);
962 static HRESULT WINAPI
PersistStreamInit_InitNew(IPersistStreamInit
*iface
)
964 HTMLDocument
*This
= impl_from_IPersistStreamInit(iface
);
968 TRACE("(%p)\n", This
);
970 hres
= CreateURLMoniker(NULL
, about_blankW
, &mon
);
972 WARN("CreateURLMoniker failed: %08x\n", hres
);
976 prepare_for_binding(This
, mon
, FALSE
);
977 hres
= set_moniker(This
->window
, mon
, NULL
, NULL
, NULL
, FALSE
);
979 hres
= channelbsc_load_stream(This
->window
->pending_window
, mon
, NULL
);
981 IMoniker_Release(mon
);
985 static const IPersistStreamInitVtbl PersistStreamInitVtbl
= {
986 PersistStreamInit_QueryInterface
,
987 PersistStreamInit_AddRef
,
988 PersistStreamInit_Release
,
989 PersistStreamInit_GetClassID
,
990 PersistStreamInit_IsDirty
,
991 PersistStreamInit_Load
,
992 PersistStreamInit_Save
,
993 PersistStreamInit_GetSizeMax
,
994 PersistStreamInit_InitNew
997 /**********************************************************
998 * IPersistHistory implementation
1001 static inline HTMLDocument
*impl_from_IPersistHistory(IPersistHistory
*iface
)
1003 return CONTAINING_RECORD(iface
, HTMLDocument
, IPersistHistory_iface
);
1006 static HRESULT WINAPI
PersistHistory_QueryInterface(IPersistHistory
*iface
, REFIID riid
, void **ppv
)
1008 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1009 return htmldoc_query_interface(This
, riid
, ppv
);
1012 static ULONG WINAPI
PersistHistory_AddRef(IPersistHistory
*iface
)
1014 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1015 return htmldoc_addref(This
);
1018 static ULONG WINAPI
PersistHistory_Release(IPersistHistory
*iface
)
1020 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1021 return htmldoc_release(This
);
1024 static HRESULT WINAPI
PersistHistory_GetClassID(IPersistHistory
*iface
, CLSID
*pClassID
)
1026 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1027 return IPersistFile_GetClassID(&This
->IPersistFile_iface
, pClassID
);
1030 static HRESULT WINAPI
PersistHistory_LoadHistory(IPersistHistory
*iface
, IStream
*pStream
, IBindCtx
*pbc
)
1032 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1033 ULONG str_len
, read
;
1038 TRACE("(%p)->(%p %p)\n", This
, pStream
, pbc
);
1041 FIXME("No current window\n");
1042 return E_UNEXPECTED
;
1046 FIXME("pbc not supported\n");
1048 if(This
->doc_obj
->client
) {
1049 IOleCommandTarget
*cmdtrg
= NULL
;
1051 hres
= IOleClientSite_QueryInterface(This
->doc_obj
->client
, &IID_IOleCommandTarget
,
1053 if(SUCCEEDED(hres
)) {
1054 IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 138, 0, NULL
, NULL
);
1055 IOleCommandTarget_Release(cmdtrg
);
1059 hres
= IStream_Read(pStream
, &str_len
, sizeof(str_len
), &read
);
1062 if(read
!= sizeof(str_len
))
1065 uri_str
= heap_alloc((str_len
+1)*sizeof(WCHAR
));
1067 return E_OUTOFMEMORY
;
1069 hres
= IStream_Read(pStream
, uri_str
, str_len
*sizeof(WCHAR
), &read
);
1070 if(SUCCEEDED(hres
) && read
!= str_len
*sizeof(WCHAR
))
1072 if(SUCCEEDED(hres
)) {
1073 uri_str
[str_len
] = 0;
1074 hres
= create_uri(uri_str
, 0, &uri
);
1080 hres
= load_uri(This
->window
, uri
, BINDING_FROMHIST
);
1085 static HRESULT WINAPI
PersistHistory_SaveHistory(IPersistHistory
*iface
, IStream
*pStream
)
1087 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1092 TRACE("(%p)->(%p)\n", This
, pStream
);
1094 if(!This
->window
|| !This
->window
->uri
) {
1095 FIXME("No current URI\n");
1099 /* NOTE: The format we store is *not* compatible with native MSHTML. We currently
1100 * store only URI of the page (as a length followed by a string) */
1101 hres
= IUri_GetDisplayUri(This
->window
->uri
, &display_uri
);
1105 len
= SysStringLen(display_uri
);
1106 hres
= IStream_Write(pStream
, &len
, sizeof(len
), &written
);
1108 hres
= IStream_Write(pStream
, display_uri
, len
*sizeof(WCHAR
), &written
);
1109 SysFreeString(display_uri
);
1113 static HRESULT WINAPI
PersistHistory_SetPositionCookie(IPersistHistory
*iface
, DWORD dwPositioncookie
)
1115 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1116 FIXME("(%p)->(%x)\n", This
, dwPositioncookie
);
1120 static HRESULT WINAPI
PersistHistory_GetPositionCookie(IPersistHistory
*iface
, DWORD
*pdwPositioncookie
)
1122 HTMLDocument
*This
= impl_from_IPersistHistory(iface
);
1123 FIXME("(%p)->(%p)\n", This
, pdwPositioncookie
);
1127 static const IPersistHistoryVtbl PersistHistoryVtbl
= {
1128 PersistHistory_QueryInterface
,
1129 PersistHistory_AddRef
,
1130 PersistHistory_Release
,
1131 PersistHistory_GetClassID
,
1132 PersistHistory_LoadHistory
,
1133 PersistHistory_SaveHistory
,
1134 PersistHistory_SetPositionCookie
,
1135 PersistHistory_GetPositionCookie
1138 /**********************************************************
1139 * IHlinkTarget implementation
1142 static inline HTMLDocument
*impl_from_IHlinkTarget(IHlinkTarget
*iface
)
1144 return CONTAINING_RECORD(iface
, HTMLDocument
, IHlinkTarget_iface
);
1147 static HRESULT WINAPI
HlinkTarget_QueryInterface(IHlinkTarget
*iface
, REFIID riid
, void **ppv
)
1149 HTMLDocument
*This
= impl_from_IHlinkTarget(iface
);
1150 return htmldoc_query_interface(This
, riid
, ppv
);
1153 static ULONG WINAPI
HlinkTarget_AddRef(IHlinkTarget
*iface
)
1155 HTMLDocument
*This
= impl_from_IHlinkTarget(iface
);
1156 return htmldoc_addref(This
);
1159 static ULONG WINAPI
HlinkTarget_Release(IHlinkTarget
*iface
)
1161 HTMLDocument
*This
= impl_from_IHlinkTarget(iface
);
1162 return htmldoc_release(This
);
1165 static HRESULT WINAPI
HlinkTarget_SetBrowseContext(IHlinkTarget
*iface
, IHlinkBrowseContext
*pihlbc
)
1167 HTMLDocument
*This
= impl_from_IHlinkTarget(iface
);
1168 FIXME("(%p)->(%p)\n", This
, pihlbc
);
1172 static HRESULT WINAPI
HlinkTarget_GetBrowseContext(IHlinkTarget
*iface
, IHlinkBrowseContext
**ppihlbc
)
1174 HTMLDocument
*This
= impl_from_IHlinkTarget(iface
);
1175 FIXME("(%p)->(%p)\n", This
, ppihlbc
);
1179 static HRESULT WINAPI
HlinkTarget_Navigate(IHlinkTarget
*iface
, DWORD grfHLNF
, LPCWSTR pwzJumpLocation
)
1181 HTMLDocument
*This
= impl_from_IHlinkTarget(iface
);
1183 TRACE("(%p)->(%08x %s)\n", This
, grfHLNF
, debugstr_w(pwzJumpLocation
));
1186 FIXME("Unsupported grfHLNF=%08x\n", grfHLNF
);
1188 FIXME("JumpLocation not supported\n");
1190 if(!This
->doc_obj
->client
)
1191 return navigate_new_window(This
->window
, This
->window
->uri
, NULL
, NULL
, NULL
);
1193 return IOleObject_DoVerb(&This
->IOleObject_iface
, OLEIVERB_SHOW
, NULL
, NULL
, -1, NULL
, NULL
);
1196 static HRESULT WINAPI
HlinkTarget_GetMoniker(IHlinkTarget
*iface
, LPCWSTR pwzLocation
, DWORD dwAssign
,
1197 IMoniker
**ppimkLocation
)
1199 HTMLDocument
*This
= impl_from_IHlinkTarget(iface
);
1200 FIXME("(%p)->(%s %08x %p)\n", This
, debugstr_w(pwzLocation
), dwAssign
, ppimkLocation
);
1204 static HRESULT WINAPI
HlinkTarget_GetFriendlyName(IHlinkTarget
*iface
, LPCWSTR pwzLocation
,
1205 LPWSTR
*ppwzFriendlyName
)
1207 HTMLDocument
*This
= impl_from_IHlinkTarget(iface
);
1208 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(pwzLocation
), ppwzFriendlyName
);
1212 static const IHlinkTargetVtbl HlinkTargetVtbl
= {
1213 HlinkTarget_QueryInterface
,
1215 HlinkTarget_Release
,
1216 HlinkTarget_SetBrowseContext
,
1217 HlinkTarget_GetBrowseContext
,
1218 HlinkTarget_Navigate
,
1219 HlinkTarget_GetMoniker
,
1220 HlinkTarget_GetFriendlyName
1223 void HTMLDocument_Persist_Init(HTMLDocument
*This
)
1225 This
->IPersistMoniker_iface
.lpVtbl
= &PersistMonikerVtbl
;
1226 This
->IPersistFile_iface
.lpVtbl
= &PersistFileVtbl
;
1227 This
->IMonikerProp_iface
.lpVtbl
= &MonikerPropVtbl
;
1228 This
->IPersistStreamInit_iface
.lpVtbl
= &PersistStreamInitVtbl
;
1229 This
->IPersistHistory_iface
.lpVtbl
= &PersistHistoryVtbl
;
1230 This
->IHlinkTarget_iface
.lpVtbl
= &HlinkTargetVtbl
;