comctl32/tooltips: Reset window subclass data when removing tools.
[wine.git] / dlls / mshtml / persist.c
blobb82750a85ea70aa0542b146eda3e355cfb838dba
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
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "ole2.h"
30 #include "shlguid.h"
31 #include "idispids.h"
32 #include "mimeole.h"
34 #define NO_SHLWAPI_REG
35 #include "shlwapi.h"
37 #include "wine/debug.h"
39 #include "mshtml_private.h"
40 #include "htmlscript.h"
41 #include "htmlevent.h"
42 #include "binding.h"
43 #include "resource.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};
52 typedef struct {
53 task_t header;
54 HTMLDocumentObj *doc;
55 BOOL set_download;
56 LPOLESTR url;
57 } download_proc_task_t;
59 static BOOL use_gecko_script(HTMLOuterWindow *window)
61 DWORD zone;
62 HRESULT hres;
64 hres = IInternetSecurityManager_MapUrlToZone(window->secmgr, window->url, &zone, 0);
65 if(FAILED(hres)) {
66 WARN("Could not map %s to zone: %08x\n", debugstr_w(window->url), hres);
67 return TRUE;
70 TRACE("zone %d\n", zone);
71 return zone == URLZONE_UNTRUSTED;
74 static void notify_travellog_update(HTMLDocumentObj *doc)
76 IOleCommandTarget *cmdtrg;
77 HRESULT hres;
79 if(!doc->webbrowser)
80 return;
82 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
83 if(SUCCEEDED(hres)) {
84 VARIANT vin;
86 V_VT(&vin) = VT_I4;
87 V_I4(&vin) = 0;
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)
96 if(window->uri) {
97 IUri_Release(window->uri);
98 window->uri = NULL;
101 if(window->uri_nofrag) {
102 IUri_Release(window->uri_nofrag);
103 window->uri_nofrag = NULL;
106 SysFreeString(window->url);
107 window->url = NULL;
109 if(!uri)
110 return;
112 IUri_AddRef(uri);
113 window->uri = uri;
115 window->uri_nofrag = get_uri_nofrag(uri);
116 if(!window->uri_nofrag) {
117 FIXME("get_uri_nofrag failed\n");
118 IUri_AddRef(uri);
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;
128 IUri *uri = NULL;
129 HRESULT hres;
131 if(This->mon) {
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);
135 else
136 TRACE("Skipping travellog update for frame navigation.\n");
138 IMoniker_Release(This->mon);
139 This->mon = NULL;
142 This->load_flags = flags;
143 if(!mon)
144 return;
146 IMoniker_AddRef(mon);
147 This->mon = 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);
153 if(hres != S_OK) {
154 WARN("GetIUri failed: %08x\n", hres);
155 uri = NULL;
159 if(!uri) {
160 WCHAR *url;
162 hres = IMoniker_GetDisplayName(mon, NULL, NULL, &url);
163 if(SUCCEEDED(hres)) {
164 hres = create_uri(url, 0, &uri);
165 if(FAILED(hres)) {
166 WARN("CreateUri failed: %08x\n", hres);
167 set_current_uri(This, NULL);
168 This->url = SysAllocString(url);
169 CoTaskMemFree(url);
170 return;
172 CoTaskMemFree(url);
173 }else {
174 WARN("GetDisplayName failed: %08x\n", hres);
178 set_current_uri(This, uri);
179 if(uri)
180 IUri_Release(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)
191 return window->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)
198 if(doc->client) {
199 IOleCommandTarget *olecmd;
200 HRESULT hres;
202 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
203 if(SUCCEEDED(hres)) {
204 VARIANT var;
206 V_VT(&var) = VT_I4;
207 V_I4(&var) = state;
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;
223 HRESULT hres;
225 TRACE("(%p)\n", doc);
227 if(doc->client)
228 IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
230 if(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,
241 &progress, NULL);
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);
251 if(SUCCEEDED(hres))
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;
263 HRESULT hres;
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);
272 if(!doc->client)
273 return;
275 if(doc->view_sink)
276 IAdviseSink_OnViewChange(doc->view_sink, DVASPECT_CONTENT, -1);
278 if(doc->hostui) {
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);
294 heap_free(task);
297 void prepare_for_binding(HTMLDocument *This, IMoniker *mon, DWORD flags)
299 HRESULT hres;
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);
324 }else {
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,
333 (void**)&cmdtrg);
334 if(SUCCEEDED(hres)) {
335 VARIANT var, out;
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);
342 if(SUCCEEDED(hres))
343 VariantClear(&out);
344 }else if(!(flags & BINDING_FROMHIST)) {
345 V_VT(&var) = VT_I4;
346 V_I4(&var) = 0;
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,
356 BOOL set_download)
358 download_proc_task_t *download_task;
359 HTMLDocumentObj *doc_obj = NULL;
360 nsChannelBSC *bscallback;
361 nsWineURI *nsuri;
362 LPOLESTR url;
363 IUri *uri;
364 HRESULT hres;
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);
370 if(FAILED(hres)) {
371 WARN("GetDiaplayName failed: %08x\n", hres);
372 return hres;
375 if(nav_uri) {
376 uri = nav_uri;
377 }else {
378 hres = create_uri(url, 0, &uri);
379 if(FAILED(hres)) {
380 CoTaskMemFree(url);
381 return hres;
385 TRACE("got url: %s\n", debugstr_w(url));
387 set_ready_state(window, READYSTATE_LOADING);
389 hres = create_doc_uri(window, uri, &nsuri);
390 if(!nav_uri)
391 IUri_Release(uri);
392 if(SUCCEEDED(hres)) {
393 if(async_bsc)
394 bscallback = async_bsc;
395 else
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);
414 if(FAILED(hres)) {
415 CoTaskMemFree(url);
416 return hres;
419 if(doc_obj) {
420 HTMLDocument_LockContainer(doc_obj, TRUE);
422 if(doc_obj->frame) {
423 docobj_task_t *task;
425 task = heap_alloc(sizeof(docobj_task_t));
426 task->doc = doc_obj;
427 hres = push_task(&task->header, set_progress_proc, NULL, doc_obj->task_magic);
428 if(FAILED(hres)) {
429 CoTaskMemFree(url);
430 return hres;
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);
441 return S_OK;
444 static void notif_readystate(HTMLOuterWindow *window)
446 DOMEvent *event;
447 HRESULT hres;
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);
470 typedef struct {
471 task_t header;
472 HTMLOuterWindow *window;
473 } readystate_task_t;
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;
495 HRESULT hres;
497 if(window->readystate_pending || prev_state == readystate)
498 return;
500 task = heap_alloc(sizeof(*task));
501 if(!task)
502 return;
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);
508 if(SUCCEEDED(hres))
509 window->readystate_pending = TRUE;
510 return;
513 notif_readystate(window);
516 static HRESULT get_doc_string(HTMLDocumentNode *This, char **str)
518 nsIDOMNode *nsnode;
519 LPCWSTR strw;
520 nsAString nsstr;
521 nsresult nsres;
522 HRESULT hres;
524 if(!This->nsdoc) {
525 WARN("NULL nsdoc\n");
526 return E_UNEXPECTED;
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);
532 return E_FAIL;
535 nsAString_Init(&nsstr, NULL);
536 hres = nsnode_to_nsstring(nsnode, &nsstr);
537 nsIDOMNode_Release(nsnode);
538 if(FAILED(hres)) {
539 nsAString_Finish(&nsstr);
540 return hres;
543 nsAString_GetData(&nsstr, &strw);
544 TRACE("%s\n", debugstr_w(strw));
546 *str = heap_strdupWtoA(strw);
548 nsAString_Finish(&nsstr);
550 if(!*str)
551 return E_OUTOFMEMORY;
552 return S_OK;
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);
602 IMoniker *mon;
603 HRESULT hres;
605 TRACE("(%p)->(%x %p %p %08x)\n", This, fFullyAvailable, pimkName, pibc, grfMode);
607 if(pibc) {
608 IUnknown *unk = NULL;
610 /* FIXME:
611 * Use params:
612 * "__PrecreatedObject"
613 * "BIND_CONTEXT_PARAM"
614 * "__HTMLLOADOPTIONS"
615 * "__DWNBINDINFO"
616 * "URL Context"
617 * "_ITransData_Object_"
618 * "_EnumFORMATETC_"
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) {
637 IUnknown *unk;
639 hres = MimeOleObjectFromMoniker(0, pimkName, pibc, &IID_IUnknown, (void**)&unk, &mon);
640 if(FAILED(hres))
641 return hres;
642 IUnknown_Release(unk);
643 pibc = NULL;
644 }else {
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);
652 if(FAILED(hres))
653 return hres;
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);
663 return E_NOTIMPL;
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);
670 return E_NOTIMPL;
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)
680 return E_UNEXPECTED;
682 IMoniker_AddRef(This->window->mon);
683 *ppimkName = This->window->mon;
684 return S_OK;
687 static const IPersistMonikerVtbl PersistMonikerVtbl = {
688 PersistMoniker_QueryInterface,
689 PersistMoniker_AddRef,
690 PersistMoniker_Release,
691 PersistMoniker_GetClassID,
692 PersistMoniker_IsDirty,
693 PersistMoniker_Load,
694 PersistMoniker_Save,
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));
732 switch(mkp) {
733 case MIMETYPEPROP:
734 heap_free(This->doc_obj->mime);
735 This->doc_obj->mime = heap_strdupW(val);
736 break;
738 case CLASSIDPROP:
739 break;
741 default:
742 FIXME("mkp %d\n", mkp);
743 return E_NOTIMPL;
746 return S_OK;
749 static const IMonikerPropVtbl MonikerPropVtbl = {
750 MonikerProp_QueryInterface,
751 MonikerProp_AddRef,
752 MonikerProp_Release,
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);
789 if(!pClassID)
790 return E_INVALIDARG;
792 *pClassID = CLSID_HTMLDocument;
793 return S_OK;
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);
809 return E_NOTIMPL;
812 static HRESULT WINAPI PersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileName, BOOL fRemember)
814 HTMLDocument *This = impl_from_IPersistFile(iface);
815 char *str;
816 DWORD written=0;
817 HANDLE file;
818 HRESULT hres;
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());
826 return E_FAIL;
829 hres = get_doc_string(This->doc_node, &str);
830 if(SUCCEEDED(hres))
831 WriteFile(file, str, strlen(str), &written, NULL);
833 CloseHandle(file);
834 return hres;
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));
841 return E_NOTIMPL;
844 static HRESULT WINAPI PersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *pszFileName)
846 HTMLDocument *This = impl_from_IPersistFile(iface);
847 FIXME("(%p)->(%p)\n", This, pszFileName);
848 return E_NOTIMPL;
851 static const IPersistFileVtbl PersistFileVtbl = {
852 PersistFile_QueryInterface,
853 PersistFile_AddRef,
854 PersistFile_Release,
855 PersistFile_GetClassID,
856 PersistFile_IsDirty,
857 PersistFile_Load,
858 PersistFile_Save,
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);
902 return S_FALSE;
905 static HRESULT WINAPI PersistStreamInit_Load(IPersistStreamInit *iface, IStream *pStm)
907 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
908 IMoniker *mon;
909 HRESULT hres;
911 TRACE("(%p)->(%p)\n", This, pStm);
913 hres = CreateURLMoniker(NULL, about_blankW, &mon);
914 if(FAILED(hres)) {
915 WARN("CreateURLMoniker failed: %08x\n", hres);
916 return hres;
919 prepare_for_binding(This, mon, FALSE);
920 hres = set_moniker(This->window, mon, NULL, NULL, NULL, TRUE);
921 if(SUCCEEDED(hres))
922 hres = channelbsc_load_stream(This->window->pending_window, mon, pStm);
924 IMoniker_Release(mon);
925 return hres;
928 static HRESULT WINAPI PersistStreamInit_Save(IPersistStreamInit *iface, IStream *pStm,
929 BOOL fClearDirty)
931 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
932 char *str;
933 DWORD written=0;
934 HRESULT hres;
936 TRACE("(%p)->(%p %x)\n", This, pStm, fClearDirty);
938 hres = get_doc_string(This->doc_node, &str);
939 if(FAILED(hres))
940 return hres;
942 hres = IStream_Write(pStm, str, strlen(str), &written);
943 if(FAILED(hres))
944 FIXME("Write failed: %08x\n", hres);
946 heap_free(str);
948 if(fClearDirty)
949 set_dirty(This, VARIANT_FALSE);
951 return S_OK;
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);
959 return E_NOTIMPL;
962 static HRESULT WINAPI PersistStreamInit_InitNew(IPersistStreamInit *iface)
964 HTMLDocument *This = impl_from_IPersistStreamInit(iface);
965 IMoniker *mon;
966 HRESULT hres;
968 TRACE("(%p)\n", This);
970 hres = CreateURLMoniker(NULL, about_blankW, &mon);
971 if(FAILED(hres)) {
972 WARN("CreateURLMoniker failed: %08x\n", hres);
973 return hres;
976 prepare_for_binding(This, mon, FALSE);
977 hres = set_moniker(This->window, mon, NULL, NULL, NULL, FALSE);
978 if(SUCCEEDED(hres))
979 hres = channelbsc_load_stream(This->window->pending_window, mon, NULL);
981 IMoniker_Release(mon);
982 return hres;
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;
1034 WCHAR *uri_str;
1035 IUri *uri;
1036 HRESULT hres;
1038 TRACE("(%p)->(%p %p)\n", This, pStream, pbc);
1040 if(!This->window) {
1041 FIXME("No current window\n");
1042 return E_UNEXPECTED;
1045 if(pbc)
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,
1052 (void**)&cmdtrg);
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);
1060 if(FAILED(hres))
1061 return hres;
1062 if(read != sizeof(str_len))
1063 return E_FAIL;
1065 uri_str = heap_alloc((str_len+1)*sizeof(WCHAR));
1066 if(!uri_str)
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))
1071 hres = E_FAIL;
1072 if(SUCCEEDED(hres)) {
1073 uri_str[str_len] = 0;
1074 hres = create_uri(uri_str, 0, &uri);
1076 heap_free(uri_str);
1077 if(FAILED(hres))
1078 return hres;
1080 hres = load_uri(This->window, uri, BINDING_FROMHIST);
1081 IUri_Release(uri);
1082 return hres;
1085 static HRESULT WINAPI PersistHistory_SaveHistory(IPersistHistory *iface, IStream *pStream)
1087 HTMLDocument *This = impl_from_IPersistHistory(iface);
1088 ULONG len, written;
1089 BSTR display_uri;
1090 HRESULT hres;
1092 TRACE("(%p)->(%p)\n", This, pStream);
1094 if(!This->window || !This->window->uri) {
1095 FIXME("No current URI\n");
1096 return E_FAIL;
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);
1102 if(FAILED(hres))
1103 return hres;
1105 len = SysStringLen(display_uri);
1106 hres = IStream_Write(pStream, &len, sizeof(len), &written);
1107 if(SUCCEEDED(hres))
1108 hres = IStream_Write(pStream, display_uri, len*sizeof(WCHAR), &written);
1109 SysFreeString(display_uri);
1110 return hres;
1113 static HRESULT WINAPI PersistHistory_SetPositionCookie(IPersistHistory *iface, DWORD dwPositioncookie)
1115 HTMLDocument *This = impl_from_IPersistHistory(iface);
1116 FIXME("(%p)->(%x)\n", This, dwPositioncookie);
1117 return E_NOTIMPL;
1120 static HRESULT WINAPI PersistHistory_GetPositionCookie(IPersistHistory *iface, DWORD *pdwPositioncookie)
1122 HTMLDocument *This = impl_from_IPersistHistory(iface);
1123 FIXME("(%p)->(%p)\n", This, pdwPositioncookie);
1124 return E_NOTIMPL;
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);
1169 return E_NOTIMPL;
1172 static HRESULT WINAPI HlinkTarget_GetBrowseContext(IHlinkTarget *iface, IHlinkBrowseContext **ppihlbc)
1174 HTMLDocument *This = impl_from_IHlinkTarget(iface);
1175 FIXME("(%p)->(%p)\n", This, ppihlbc);
1176 return E_NOTIMPL;
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));
1185 if(grfHLNF)
1186 FIXME("Unsupported grfHLNF=%08x\n", grfHLNF);
1187 if(pwzJumpLocation)
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);
1201 return E_NOTIMPL;
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);
1209 return E_NOTIMPL;
1212 static const IHlinkTargetVtbl HlinkTargetVtbl = {
1213 HlinkTarget_QueryInterface,
1214 HlinkTarget_AddRef,
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;