2 * Copyright 2005 Jacek Caban
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
35 #include "wine/debug.h"
36 #include "wine/unicode.h"
38 #include "mshtml_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
42 static BOOL use_gecko_script(LPCWSTR url)
44 static const WCHAR fileW[] = {'f','i','l','e',':'};
45 static const WCHAR aboutW[] = {'a','b','o','u','t',':'};
47 return strncmpiW(fileW, url, sizeof(fileW)/sizeof(WCHAR))
48 && strncmpiW(aboutW, url, sizeof(aboutW)/sizeof(WCHAR));
51 void set_current_mon(HTMLWindow *This, IMoniker *mon)
56 IMoniker_Release(This->mon);
61 CoTaskMemFree(This->url);
71 hres = IMoniker_GetDisplayName(mon, NULL, NULL, &This->url);
73 WARN("GetDisplayName failed: %08x\n", hres);
75 set_script_mode(This, use_gecko_script(This->url) ? SCRIPTMODE_GECKO : SCRIPTMODE_ACTIVESCRIPT);
78 static void set_progress_proc(task_t *_task)
80 docobj_task_t *task = (docobj_task_t*)_task;
81 IOleCommandTarget *olecmd = NULL;
82 HTMLDocumentObj *doc = task->doc;
88 IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
91 VARIANT progress_max, progress;
93 V_VT(&progress_max) = VT_I4;
94 V_I4(&progress_max) = 0; /* FIXME */
95 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSMAX, OLECMDEXECOPT_DONTPROMPTUSER,
98 V_VT(&progress) = VT_I4;
99 V_I4(&progress) = 0; /* FIXME */
100 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSPOS, OLECMDEXECOPT_DONTPROMPTUSER,
104 if(doc->usermode == EDITMODE && doc->hostui) {
105 DOCHOSTUIINFO hostinfo;
107 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
108 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
109 hres = IDocHostUIHandler_GetHostInfo(doc->hostui, &hostinfo);
111 /* FIXME: use hostinfo */
112 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
113 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
114 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
118 static void set_downloading_proc(task_t *_task)
120 HTMLDocumentObj *doc = ((docobj_task_t*)_task)->doc;
121 IOleCommandTarget *olecmd;
124 TRACE("(%p)\n", doc);
127 IOleInPlaceFrame_SetStatusText(doc->frame, NULL /* FIXME */);
132 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
133 if(SUCCEEDED(hres)) {
139 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETDOWNLOADSTATE, OLECMDEXECOPT_DONTPROMPTUSER,
141 IOleCommandTarget_Release(olecmd);
145 IDropTarget *drop_target = NULL;
147 hres = IDocHostUIHandler_GetDropTarget(doc->hostui, NULL /* FIXME */, &drop_target);
149 FIXME("Use IDropTarget\n");
150 IDropTarget_Release(drop_target);
155 static HRESULT set_moniker(HTMLDocument *This, IMoniker *mon, IBindCtx *pibc, BOOL *bind_complete)
157 nsChannelBSC *bscallback;
164 IUnknown *unk = NULL;
168 * "__PrecreatedObject"
169 * "BIND_CONTEXT_PARAM"
170 * "__HTMLLOADOPTIONS"
174 * "_ITransData_Object_"
178 IBindCtx_GetObjectParam(pibc, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM, &unk);
180 IOleClientSite *client = NULL;
182 hres = IUnknown_QueryInterface(unk, &IID_IOleClientSite, (void**)&client);
183 if(SUCCEEDED(hres)) {
184 TRACE("Got client site %p\n", client);
185 IOleObject_SetClientSite(OLEOBJ(This), client);
186 IOleClientSite_Release(client);
189 IUnknown_Release(unk);
193 set_ready_state(This->window, READYSTATE_LOADING);
194 update_doc(This, UPDATE_TITLE);
196 HTMLDocument_LockContainer(This->doc_obj, TRUE);
198 hres = IMoniker_GetDisplayName(mon, pibc, NULL, &url);
200 WARN("GetDiaplayName failed: %08x\n", hres);
204 TRACE("got url: %s\n", debugstr_w(url));
206 set_current_mon(This->window, mon);
208 if(This->doc_obj->client) {
209 VARIANT silent, offline;
210 IOleCommandTarget *cmdtrg = NULL;
212 hres = get_client_disp_property(This->doc_obj->client, DISPID_AMBIENT_SILENT, &silent);
213 if(SUCCEEDED(hres)) {
214 if(V_VT(&silent) != VT_BOOL)
215 WARN("V_VT(silent) = %d\n", V_VT(&silent));
216 else if(V_BOOL(&silent))
217 FIXME("silent == true\n");
220 hres = get_client_disp_property(This->doc_obj->client,
221 DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
222 if(SUCCEEDED(hres)) {
223 if(V_VT(&silent) != VT_BOOL)
224 WARN("V_VT(offline) = %d\n", V_VT(&silent));
225 else if(V_BOOL(&silent))
226 FIXME("offline == true\n");
229 hres = IOleClientSite_QueryInterface(This->doc_obj->client, &IID_IOleCommandTarget,
231 if(SUCCEEDED(hres)) {
236 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
238 IOleCommandTarget_Release(cmdtrg);
242 bscallback = create_channelbsc(mon);
244 if(This->doc_obj->frame) {
245 task = heap_alloc(sizeof(docobj_task_t));
246 task->doc = This->doc_obj;
247 push_task(&task->header, set_progress_proc, This->doc_obj->basedoc.task_magic);
250 task = heap_alloc(sizeof(docobj_task_t));
251 task->doc = This->doc_obj;
252 push_task(&task->header, set_downloading_proc, This->doc_obj->basedoc.task_magic);
254 if(This->doc_obj->nscontainer) {
255 This->doc_obj->nscontainer->bscallback = bscallback;
256 nsres = nsIWebNavigation_LoadURI(This->doc_obj->nscontainer->navigation, url,
257 LOAD_FLAGS_NONE, NULL, NULL, NULL);
258 This->doc_obj->nscontainer->bscallback = NULL;
259 if(NS_FAILED(nsres)) {
260 WARN("LoadURI failed: %08x\n", nsres);
261 IUnknown_Release((IUnknown*)bscallback);
267 set_window_bscallback(This->window, bscallback);
268 IUnknown_Release((IUnknown*)bscallback);
272 *bind_complete = FALSE;
276 void set_ready_state(HTMLWindow *window, READYSTATE readystate)
278 window->readystate = readystate;
279 if(window->doc_obj->basedoc.window == window)
280 call_property_onchanged(&window->doc_obj->basedoc.cp_propnotif, DISPID_READYSTATE);
283 static HRESULT get_doc_string(HTMLDocumentNode *This, char **str)
291 WARN("NULL nsdoc\n");
295 nsres = nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMNode, (void**)&nsnode);
296 if(NS_FAILED(nsres)) {
297 ERR("Could not get nsIDOMNode failed: %08x\n", nsres);
301 nsAString_Init(&nsstr, NULL);
302 nsnode_to_nsstring(nsnode, &nsstr);
303 nsIDOMNode_Release(nsnode);
305 nsAString_GetData(&nsstr, &strw);
306 TRACE("%s\n", debugstr_w(strw));
308 *str = heap_strdupWtoA(strw);
310 nsAString_Finish(&nsstr);
316 /**********************************************************
317 * IPersistMoniker implementation
320 #define PERSISTMON_THIS(iface) DEFINE_THIS(HTMLDocument, PersistMoniker, iface)
322 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid,
325 HTMLDocument *This = PERSISTMON_THIS(iface);
326 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
329 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
331 HTMLDocument *This = PERSISTMON_THIS(iface);
332 return IHTMLDocument2_AddRef(HTMLDOC(This));
335 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
337 HTMLDocument *This = PERSISTMON_THIS(iface);
338 return IHTMLDocument2_Release(HTMLDOC(This));
341 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
343 HTMLDocument *This = PERSISTMON_THIS(iface);
344 return IPersist_GetClassID(PERSIST(This), pClassID);
347 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
349 HTMLDocument *This = PERSISTMON_THIS(iface);
351 TRACE("(%p)\n", This);
353 return IPersistStreamInit_IsDirty(PERSTRINIT(This));
356 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
357 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
359 HTMLDocument *This = PERSISTMON_THIS(iface);
360 BOOL bind_complete = FALSE;
363 TRACE("(%p)->(%x %p %p %08x)\n", This, fFullyAvailable, pimkName, pibc, grfMode);
365 hres = set_moniker(This, pimkName, pibc, &bind_complete);
370 return start_binding(This->window, NULL, (BSCallback*)This->window->bscallback, pibc);
375 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName,
376 LPBC pbc, BOOL fRemember)
378 HTMLDocument *This = PERSISTMON_THIS(iface);
379 FIXME("(%p)->(%p %p %x)\n", This, pimkName, pbc, fRemember);
383 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
385 HTMLDocument *This = PERSISTMON_THIS(iface);
386 FIXME("(%p)->(%p %p)\n", This, pimkName, pibc);
390 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **ppimkName)
392 HTMLDocument *This = PERSISTMON_THIS(iface);
394 TRACE("(%p)->(%p)\n", This, ppimkName);
396 if(!This->window || !This->window->mon)
399 IMoniker_AddRef(This->window->mon);
400 *ppimkName = This->window->mon;
404 static const IPersistMonikerVtbl PersistMonikerVtbl = {
405 PersistMoniker_QueryInterface,
406 PersistMoniker_AddRef,
407 PersistMoniker_Release,
408 PersistMoniker_GetClassID,
409 PersistMoniker_IsDirty,
412 PersistMoniker_SaveCompleted,
413 PersistMoniker_GetCurMoniker
416 /**********************************************************
417 * IMonikerProp implementation
420 #define MONPROP_THIS(iface) DEFINE_THIS(HTMLDocument, MonikerProp, iface)
422 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppvObject)
424 HTMLDocument *This = MONPROP_THIS(iface);
425 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
428 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
430 HTMLDocument *This = MONPROP_THIS(iface);
431 return IHTMLDocument2_AddRef(HTMLDOC(This));
434 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
436 HTMLDocument *This = MONPROP_THIS(iface);
437 return IHTMLDocument_Release(HTMLDOC(This));
440 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
442 HTMLDocument *This = MONPROP_THIS(iface);
444 TRACE("(%p)->(%d %s)\n", This, mkp, debugstr_w(val));
448 heap_free(This->doc_obj->mime);
449 This->doc_obj->mime = heap_strdupW(val);
456 FIXME("mkp %d\n", mkp);
463 static const IMonikerPropVtbl MonikerPropVtbl = {
464 MonikerProp_QueryInterface,
467 MonikerProp_PutProperty
470 /**********************************************************
471 * IPersistFile implementation
474 #define PERSISTFILE_THIS(iface) DEFINE_THIS(HTMLDocument, PersistFile, iface)
476 static HRESULT WINAPI PersistFile_QueryInterface(IPersistFile *iface, REFIID riid, void **ppvObject)
478 HTMLDocument *This = PERSISTFILE_THIS(iface);
479 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
482 static ULONG WINAPI PersistFile_AddRef(IPersistFile *iface)
484 HTMLDocument *This = PERSISTFILE_THIS(iface);
485 return IHTMLDocument2_AddRef(HTMLDOC(This));
488 static ULONG WINAPI PersistFile_Release(IPersistFile *iface)
490 HTMLDocument *This = PERSISTFILE_THIS(iface);
491 return IHTMLDocument2_Release(HTMLDOC(This));
494 static HRESULT WINAPI PersistFile_GetClassID(IPersistFile *iface, CLSID *pClassID)
496 HTMLDocument *This = PERSISTFILE_THIS(iface);
498 TRACE("(%p)->(%p)\n", This, pClassID);
503 *pClassID = CLSID_HTMLDocument;
507 static HRESULT WINAPI PersistFile_IsDirty(IPersistFile *iface)
509 HTMLDocument *This = PERSISTFILE_THIS(iface);
511 TRACE("(%p)\n", This);
513 return IPersistStreamInit_IsDirty(PERSTRINIT(This));
516 static HRESULT WINAPI PersistFile_Load(IPersistFile *iface, LPCOLESTR pszFileName, DWORD dwMode)
518 HTMLDocument *This = PERSISTFILE_THIS(iface);
519 FIXME("(%p)->(%s %08x)\n", This, debugstr_w(pszFileName), dwMode);
523 static HRESULT WINAPI PersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileName, BOOL fRemember)
525 HTMLDocument *This = PERSISTFILE_THIS(iface);
531 TRACE("(%p)->(%s %x)\n", This, debugstr_w(pszFileName), fRemember);
533 file = CreateFileW(pszFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
534 FILE_ATTRIBUTE_NORMAL, NULL);
535 if(file == INVALID_HANDLE_VALUE) {
536 WARN("Could not create file: %u\n", GetLastError());
540 hres = get_doc_string(This->doc_node, &str);
542 WriteFile(file, str, strlen(str), &written, NULL);
548 static HRESULT WINAPI PersistFile_SaveCompleted(IPersistFile *iface, LPCOLESTR pszFileName)
550 HTMLDocument *This = PERSISTFILE_THIS(iface);
551 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFileName));
555 static HRESULT WINAPI PersistFile_GetCurFile(IPersistFile *iface, LPOLESTR *pszFileName)
557 HTMLDocument *This = PERSISTFILE_THIS(iface);
558 FIXME("(%p)->(%p)\n", This, pszFileName);
562 static const IPersistFileVtbl PersistFileVtbl = {
563 PersistFile_QueryInterface,
566 PersistFile_GetClassID,
570 PersistFile_SaveCompleted,
571 PersistFile_GetCurFile
574 #define PERSTRINIT_THIS(iface) DEFINE_THIS(HTMLDocument, PersistStreamInit, iface)
576 static HRESULT WINAPI PersistStreamInit_QueryInterface(IPersistStreamInit *iface,
577 REFIID riid, void **ppv)
579 HTMLDocument *This = PERSTRINIT_THIS(iface);
580 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
583 static ULONG WINAPI PersistStreamInit_AddRef(IPersistStreamInit *iface)
585 HTMLDocument *This = PERSTRINIT_THIS(iface);
586 return IHTMLDocument2_AddRef(HTMLDOC(This));
589 static ULONG WINAPI PersistStreamInit_Release(IPersistStreamInit *iface)
591 HTMLDocument *This = PERSTRINIT_THIS(iface);
592 return IHTMLDocument2_Release(HTMLDOC(This));
595 static HRESULT WINAPI PersistStreamInit_GetClassID(IPersistStreamInit *iface, CLSID *pClassID)
597 HTMLDocument *This = PERSTRINIT_THIS(iface);
598 return IPersist_GetClassID(PERSIST(This), pClassID);
601 static HRESULT WINAPI PersistStreamInit_IsDirty(IPersistStreamInit *iface)
603 HTMLDocument *This = PERSTRINIT_THIS(iface);
605 TRACE("(%p)\n", This);
607 if(This->doc_obj->usermode == EDITMODE)
608 return editor_is_dirty(This);
613 static HRESULT WINAPI PersistStreamInit_Load(IPersistStreamInit *iface, LPSTREAM pStm)
615 HTMLDocument *This = PERSTRINIT_THIS(iface);
619 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
621 TRACE("(%p)->(%p)\n", This, pStm);
623 hres = CreateURLMoniker(NULL, about_blankW, &mon);
625 WARN("CreateURLMoniker failed: %08x\n", hres);
629 hres = set_moniker(This, mon, NULL, NULL);
630 IMoniker_Release(mon);
634 return channelbsc_load_stream(This->window->bscallback, pStm);
637 static HRESULT WINAPI PersistStreamInit_Save(IPersistStreamInit *iface, LPSTREAM pStm,
640 HTMLDocument *This = PERSTRINIT_THIS(iface);
645 TRACE("(%p)->(%p %x)\n", This, pStm, fClearDirty);
647 hres = get_doc_string(This->doc_node, &str);
651 hres = IStream_Write(pStm, str, strlen(str), &written);
653 FIXME("Write failed: %08x\n", hres);
658 set_dirty(This, VARIANT_FALSE);
663 static HRESULT WINAPI PersistStreamInit_GetSizeMax(IPersistStreamInit *iface,
664 ULARGE_INTEGER *pcbSize)
666 HTMLDocument *This = PERSTRINIT_THIS(iface);
667 FIXME("(%p)->(%p)\n", This, pcbSize);
671 static HRESULT WINAPI PersistStreamInit_InitNew(IPersistStreamInit *iface)
673 HTMLDocument *This = PERSTRINIT_THIS(iface);
674 FIXME("(%p)\n", This);
678 #undef PERSTRINIT_THIS
680 static const IPersistStreamInitVtbl PersistStreamInitVtbl = {
681 PersistStreamInit_QueryInterface,
682 PersistStreamInit_AddRef,
683 PersistStreamInit_Release,
684 PersistStreamInit_GetClassID,
685 PersistStreamInit_IsDirty,
686 PersistStreamInit_Load,
687 PersistStreamInit_Save,
688 PersistStreamInit_GetSizeMax,
689 PersistStreamInit_InitNew
692 /**********************************************************
693 * IPersistHistory implementation
696 #define PERSISTHIST_THIS(iface) DEFINE_THIS(HTMLDocument, PersistHistory, iface)
698 static HRESULT WINAPI PersistHistory_QueryInterface(IPersistHistory *iface, REFIID riid, void **ppvObject)
700 HTMLDocument *This = PERSISTHIST_THIS(iface);
701 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
704 static ULONG WINAPI PersistHistory_AddRef(IPersistHistory *iface)
706 HTMLDocument *This = PERSISTHIST_THIS(iface);
707 return IHTMLDocument2_AddRef(HTMLDOC(This));
710 static ULONG WINAPI PersistHistory_Release(IPersistHistory *iface)
712 HTMLDocument *This = PERSISTHIST_THIS(iface);
713 return IHTMLDocument2_Release(HTMLDOC(This));
716 static HRESULT WINAPI PersistHistory_GetClassID(IPersistHistory *iface, CLSID *pClassID)
718 HTMLDocument *This = PERSISTHIST_THIS(iface);
719 return IPersist_GetClassID(PERSIST(This), pClassID);
722 static HRESULT WINAPI PersistHistory_LoadHistory(IPersistHistory *iface, IStream *pStream, IBindCtx *pbc)
724 HTMLDocument *This = PERSISTHIST_THIS(iface);
725 FIXME("(%p)->(%p %p)\n", This, pStream, pbc);
729 static HRESULT WINAPI PersistHistory_SaveHistory(IPersistHistory *iface, IStream *pStream)
731 HTMLDocument *This = PERSISTHIST_THIS(iface);
732 FIXME("(%p)->(%p)\n", This, pStream);
736 static HRESULT WINAPI PersistHistory_SetPositionCookie(IPersistHistory *iface, DWORD dwPositioncookie)
738 HTMLDocument *This = PERSISTHIST_THIS(iface);
739 FIXME("(%p)->(%x)\n", This, dwPositioncookie);
743 static HRESULT WINAPI PersistHistory_GetPositionCookie(IPersistHistory *iface, DWORD *pdwPositioncookie)
745 HTMLDocument *This = PERSISTHIST_THIS(iface);
746 FIXME("(%p)->(%p)\n", This, pdwPositioncookie);
750 #undef PERSISTHIST_THIS
752 static const IPersistHistoryVtbl PersistHistoryVtbl = {
753 PersistHistory_QueryInterface,
754 PersistHistory_AddRef,
755 PersistHistory_Release,
756 PersistHistory_GetClassID,
757 PersistHistory_LoadHistory,
758 PersistHistory_SaveHistory,
759 PersistHistory_SetPositionCookie,
760 PersistHistory_GetPositionCookie
763 void HTMLDocument_Persist_Init(HTMLDocument *This)
765 This->lpPersistMonikerVtbl = &PersistMonikerVtbl;
766 This->lpPersistFileVtbl = &PersistFileVtbl;
767 This->lpMonikerPropVtbl = &MonikerPropVtbl;
768 This->lpPersistStreamInitVtbl = &PersistStreamInitVtbl;
769 This->lpPersistHistoryVtbl = &PersistHistoryVtbl;