crypt32: Test CryptStringToBinary with weird Base64.
[wine.git] / dlls / ieframe / dochost.c
blob424868d62e7bffacc13d589054b36ccfc0736e08
1 /*
2 * Copyright 2005-2006 Jacek Caban for CodeWeavers
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 "ieframe.h"
21 #include "exdispid.h"
22 #include "mshtml.h"
23 #include "perhist.h"
24 #include "initguid.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(ieframe);
30 DEFINE_OLEGUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0);
32 #define DOCHOST_DOCCANNAVIGATE 0
34 /* Undocumented notification, see mshtml tests */
35 #define CMDID_EXPLORER_UPDATEHISTORY 38
37 static ATOM doc_view_atom = 0;
39 void push_dochost_task(DocHost *This, task_header_t *task, task_proc_t proc, task_destr_t destr, BOOL send)
41 BOOL is_empty;
43 task->proc = proc;
44 task->destr = destr;
46 is_empty = list_empty(&This->task_queue);
47 list_add_tail(&This->task_queue, &task->entry);
49 if(send)
50 SendMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, 0);
51 else if(is_empty)
52 PostMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, 0);
55 LRESULT process_dochost_tasks(DocHost *This)
57 task_header_t *task;
59 while(!list_empty(&This->task_queue)) {
60 task = LIST_ENTRY(This->task_queue.next, task_header_t, entry);
61 list_remove(&task->entry);
63 task->proc(This, task);
64 task->destr(task);
67 return 0;
70 void abort_dochost_tasks(DocHost *This, task_proc_t proc)
72 task_header_t *task, *cursor;
74 LIST_FOR_EACH_ENTRY_SAFE(task, cursor, &This->task_queue, task_header_t, entry) {
75 if(proc && proc != task->proc)
76 continue;
78 list_remove(&task->entry);
79 task->destr(task);
83 void on_commandstate_change(DocHost *doc_host, LONG command, BOOL enable)
85 DISPPARAMS dispparams;
86 VARIANTARG params[2];
88 TRACE("command=%d enable=%d\n", command, enable);
90 dispparams.cArgs = 2;
91 dispparams.cNamedArgs = 0;
92 dispparams.rgdispidNamedArgs = NULL;
93 dispparams.rgvarg = params;
95 V_VT(params) = VT_BOOL;
96 V_BOOL(params) = enable ? VARIANT_TRUE : VARIANT_FALSE;
98 V_VT(params+1) = VT_I4;
99 V_I4(params+1) = command;
101 call_sink(doc_host->cps.wbe2, DISPID_COMMANDSTATECHANGE, &dispparams);
103 doc_host->container_vtbl->on_command_state_change(doc_host, command, enable);
106 void update_navigation_commands(DocHost *dochost)
108 unsigned pos = dochost->travellog.loading_pos == -1 ? dochost->travellog.position : dochost->travellog.loading_pos;
110 on_commandstate_change(dochost, CSC_NAVIGATEBACK, pos > 0);
111 on_commandstate_change(dochost, CSC_NAVIGATEFORWARD, pos < dochost->travellog.length);
114 static void notif_complete(DocHost *This, DISPID dispid)
116 DISPPARAMS dispparams;
117 VARIANTARG params[2];
118 VARIANT url;
120 dispparams.cArgs = 2;
121 dispparams.cNamedArgs = 0;
122 dispparams.rgdispidNamedArgs = NULL;
123 dispparams.rgvarg = params;
125 V_VT(params) = (VT_BYREF|VT_VARIANT);
126 V_BYREF(params) = &url;
128 V_VT(params+1) = VT_DISPATCH;
129 V_DISPATCH(params+1) = (IDispatch*)This->wb;
131 V_VT(&url) = VT_BSTR;
132 V_BSTR(&url) = SysAllocString(This->url);
134 TRACE("%d >>>\n", dispid);
135 call_sink(This->cps.wbe2, dispid, &dispparams);
136 TRACE("%d <<<\n", dispid);
138 SysFreeString(V_BSTR(&url));
139 This->busy = VARIANT_FALSE;
142 static void object_available(DocHost *This)
144 IHlinkTarget *hlink;
145 HRESULT hres;
147 TRACE("(%p)\n", This);
149 if(!This->document) {
150 WARN("document == NULL\n");
151 return;
154 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
155 if(SUCCEEDED(hres)) {
156 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
157 IHlinkTarget_Release(hlink);
158 if(FAILED(hres))
159 FIXME("Navigate failed\n");
160 }else {
161 IOleObject *ole_object;
162 RECT rect;
164 TRACE("No IHlink iface\n");
166 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&ole_object);
167 if(FAILED(hres)) {
168 FIXME("Could not get IOleObject iface: %08x\n", hres);
169 return;
172 GetClientRect(This->hwnd, &rect);
173 hres = IOleObject_DoVerb(ole_object, OLEIVERB_SHOW, NULL, &This->IOleClientSite_iface, -1, This->hwnd, &rect);
174 IOleObject_Release(ole_object);
175 if(FAILED(hres))
176 FIXME("DoVerb failed: %08x\n", hres);
180 static HRESULT get_doc_ready_state(DocHost *This, READYSTATE *ret)
182 DISPPARAMS dp = {NULL,NULL,0,0};
183 IDispatch *disp;
184 EXCEPINFO ei;
185 VARIANT var;
186 HRESULT hres;
188 hres = IUnknown_QueryInterface(This->document, &IID_IDispatch, (void**)&disp);
189 if(FAILED(hres))
190 return hres;
192 hres = IDispatch_Invoke(disp, DISPID_READYSTATE, &IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET,
193 &dp, &var, &ei, NULL);
194 IDispatch_Release(disp);
195 if(FAILED(hres)) {
196 WARN("Invoke(DISPID_READYSTATE failed: %08x\n", hres);
197 return hres;
200 if(V_VT(&var) != VT_I4) {
201 WARN("V_VT(var) = %d\n", V_VT(&var));
202 VariantClear(&var);
203 return E_FAIL;
206 *ret = V_I4(&var);
207 return S_OK;
210 static void advise_prop_notif(DocHost *This, BOOL set)
212 IConnectionPointContainer *cp_container;
213 IConnectionPoint *cp;
214 HRESULT hres;
216 hres = IUnknown_QueryInterface(This->document, &IID_IConnectionPointContainer, (void**)&cp_container);
217 if(FAILED(hres))
218 return;
220 hres = IConnectionPointContainer_FindConnectionPoint(cp_container, &IID_IPropertyNotifySink, &cp);
221 IConnectionPointContainer_Release(cp_container);
222 if(FAILED(hres))
223 return;
225 if(set)
226 hres = IConnectionPoint_Advise(cp, (IUnknown*)&This->IPropertyNotifySink_iface, &This->prop_notif_cookie);
227 else
228 hres = IConnectionPoint_Unadvise(cp, This->prop_notif_cookie);
229 IConnectionPoint_Release(cp);
231 if(SUCCEEDED(hres))
232 This->is_prop_notif = set;
235 void set_doc_state(DocHost *This, READYSTATE doc_state)
237 This->doc_state = doc_state;
238 if(doc_state > This->ready_state)
239 This->ready_state = doc_state;
242 static void update_ready_state(DocHost *This, READYSTATE ready_state)
244 if(ready_state > READYSTATE_LOADING && This->travellog.loading_pos != -1) {
245 WARN("histupdate not notified\n");
246 This->travellog.position = This->travellog.loading_pos;
247 This->travellog.loading_pos = -1;
250 if(ready_state > READYSTATE_LOADING && This->doc_state <= READYSTATE_LOADING && !This->browser_service /* FIXME */)
251 notif_complete(This, DISPID_NAVIGATECOMPLETE2);
253 if(ready_state == READYSTATE_COMPLETE && This->doc_state < READYSTATE_COMPLETE) {
254 set_doc_state(This, READYSTATE_COMPLETE);
255 if(!This->browser_service) /* FIXME: Not fully correct */
256 notif_complete(This, DISPID_DOCUMENTCOMPLETE);
257 }else {
258 set_doc_state(This, ready_state);
262 typedef struct {
263 task_header_t header;
264 IUnknown *doc;
265 READYSTATE ready_state;
266 } ready_state_task_t;
268 static void ready_state_task_destr(task_header_t *_task)
270 ready_state_task_t *task = (ready_state_task_t*)_task;
272 IUnknown_Release(task->doc);
273 heap_free(task);
276 static void ready_state_proc(DocHost *This, task_header_t *_task)
278 ready_state_task_t *task = (ready_state_task_t*)_task;
280 if(task->doc == This->document)
281 update_ready_state(This, task->ready_state);
284 static void push_ready_state_task(DocHost *This, READYSTATE ready_state)
286 ready_state_task_t *task = heap_alloc(sizeof(ready_state_task_t));
288 IUnknown_AddRef(This->document);
289 task->doc = This->document;
290 task->ready_state = ready_state;
292 push_dochost_task(This, &task->header, ready_state_proc, ready_state_task_destr, FALSE);
295 static void object_available_task_destr(task_header_t *task)
297 heap_free(task);
300 static void object_available_proc(DocHost *This, task_header_t *task)
302 object_available(This);
305 HRESULT dochost_object_available(DocHost *This, IUnknown *doc)
307 READYSTATE ready_state;
308 task_header_t *task;
309 IOleObject *oleobj;
310 HRESULT hres;
312 IUnknown_AddRef(doc);
313 This->document = doc;
315 hres = IUnknown_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
316 if(SUCCEEDED(hres)) {
317 CLSID clsid;
319 hres = IOleObject_GetUserClassID(oleobj, &clsid);
320 if(SUCCEEDED(hres))
321 TRACE("Got clsid %s\n",
322 IsEqualGUID(&clsid, &CLSID_HTMLDocument) ? "CLSID_HTMLDocument" : debugstr_guid(&clsid));
324 hres = IOleObject_SetClientSite(oleobj, &This->IOleClientSite_iface);
325 if(FAILED(hres))
326 FIXME("SetClientSite failed: %08x\n", hres);
328 IOleObject_Release(oleobj);
329 }else {
330 FIXME("Could not get IOleObject iface: %08x\n", hres);
333 /* FIXME: Call SetAdvise */
335 task = heap_alloc(sizeof(*task));
336 push_dochost_task(This, task, object_available_proc, object_available_task_destr, FALSE);
338 hres = get_doc_ready_state(This, &ready_state);
339 if(SUCCEEDED(hres)) {
340 if(ready_state == READYSTATE_COMPLETE)
341 push_ready_state_task(This, READYSTATE_COMPLETE);
342 if(ready_state != READYSTATE_COMPLETE || This->doc_navigate)
343 advise_prop_notif(This, TRUE);
344 }else if(!This->doc_navigate) {
345 /* If we can't get document's ready state, there is not much we can do.
346 * Assume that document is complete at this point. */
347 push_ready_state_task(This, READYSTATE_COMPLETE);
350 return S_OK;
353 static LRESULT resize_document(DocHost *This, LONG width, LONG height)
355 RECT rect = {0, 0, width, height};
357 TRACE("(%p)->(%d %d)\n", This, width, height);
359 if(This->view)
360 IOleDocumentView_SetRect(This->view, &rect);
362 return 0;
365 static LRESULT WINAPI doc_view_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
367 DocHost *This;
369 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
371 if(msg == WM_CREATE) {
372 This = *(DocHost**)lParam;
373 SetPropW(hwnd, wszTHIS, This);
374 }else {
375 This = GetPropW(hwnd, wszTHIS);
378 switch(msg) {
379 case WM_SIZE:
380 return resize_document(This, LOWORD(lParam), HIWORD(lParam));
383 return DefWindowProcW(hwnd, msg, wParam, lParam);
386 static void free_travellog_entry(travellog_entry_t *entry)
388 if(entry->stream)
389 IStream_Release(entry->stream);
390 heap_free(entry->url);
393 static IStream *get_travellog_stream(DocHost *This)
395 IPersistHistory *persist_history;
396 IStream *stream;
397 HRESULT hres;
399 hres = IUnknown_QueryInterface(This->document, &IID_IPersistHistory, (void**)&persist_history);
400 if(FAILED(hres))
401 return NULL;
403 hres = CreateStreamOnHGlobal(NULL, TRUE, &stream);
404 if(SUCCEEDED(hres))
405 hres = IPersistHistory_SaveHistory(persist_history, stream);
406 IPersistHistory_Release(persist_history);
407 if(FAILED(hres)) {
408 IStream_Release(stream);
409 return NULL;
412 return stream;
415 static void dump_travellog(DocHost *This)
417 unsigned i;
419 for(i=0; i < This->travellog.length; i++)
420 TRACE("%d: %s %s\n", i, i == This->travellog.position ? "=>" : " ", debugstr_w(This->travellog.log[i].url));
421 if(i == This->travellog.position)
422 TRACE("%d: =>\n", i);
425 static void update_travellog(DocHost *This)
427 travellog_entry_t *new_entry;
429 static const WCHAR about_schemeW[] = {'a','b','o','u','t',':'};
431 if(This->url && !strncmpiW(This->url, about_schemeW, sizeof(about_schemeW)/sizeof(*about_schemeW))) {
432 TRACE("Skipping about URL\n");
433 return;
436 if(!This->travellog.log) {
437 This->travellog.log = heap_alloc(4 * sizeof(*This->travellog.log));
438 if(!This->travellog.log)
439 return;
441 This->travellog.size = 4;
442 }else if(This->travellog.size < This->travellog.position+1) {
443 travellog_entry_t *new_travellog;
445 new_travellog = heap_realloc(This->travellog.log, This->travellog.size*2*sizeof(*This->travellog.log));
446 if(!new_travellog)
447 return;
449 This->travellog.log = new_travellog;
450 This->travellog.size *= 2;
453 if(This->travellog.loading_pos == -1) {
454 /* Clear forward history. */
455 while(This->travellog.length > This->travellog.position)
456 free_travellog_entry(This->travellog.log + --This->travellog.length);
459 new_entry = This->travellog.log + This->travellog.position;
461 new_entry->url = heap_strdupW(This->url);
462 TRACE("Adding %s at %d\n", debugstr_w(This->url), This->travellog.position);
463 if(!new_entry->url)
464 return;
466 new_entry->stream = get_travellog_stream(This);
468 if(This->travellog.loading_pos == -1) {
469 This->travellog.position++;
470 }else {
471 This->travellog.position = This->travellog.loading_pos;
472 This->travellog.loading_pos = -1;
474 if(This->travellog.position > This->travellog.length)
475 This->travellog.length = This->travellog.position;
477 dump_travellog(This);
480 void create_doc_view_hwnd(DocHost *This)
482 RECT rect;
484 static const WCHAR wszShell_DocObject_View[] =
485 {'S','h','e','l','l',' ','D','o','c','O','b','j','e','c','t',' ','V','i','e','w',0};
487 if(!doc_view_atom) {
488 static WNDCLASSEXW wndclass = {
489 sizeof(wndclass),
490 CS_PARENTDC,
491 doc_view_proc,
492 0, 0 /* native uses 4*/, NULL, NULL, NULL,
493 (HBRUSH)(COLOR_WINDOW + 1), NULL,
494 wszShell_DocObject_View,
495 NULL
498 wndclass.hInstance = ieframe_instance;
500 doc_view_atom = RegisterClassExW(&wndclass);
503 This->container_vtbl->get_docobj_rect(This, &rect);
504 This->hwnd = CreateWindowExW(0, wszShell_DocObject_View,
505 wszShell_DocObject_View,
506 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP,
507 rect.left, rect.top, rect.right, rect.bottom, This->frame_hwnd,
508 NULL, ieframe_instance, This);
511 void deactivate_document(DocHost *This)
513 IOleInPlaceObjectWindowless *winobj;
514 IOleObject *oleobj = NULL;
515 IHlinkTarget *hlink = NULL;
516 HRESULT hres;
518 if(!This->document) return;
520 if(This->doc_navigate) {
521 IUnknown_Release(This->doc_navigate);
522 This->doc_navigate = NULL;
525 if(This->is_prop_notif)
526 advise_prop_notif(This, FALSE);
528 if(This->view)
529 IOleDocumentView_UIActivate(This->view, FALSE);
531 hres = IUnknown_QueryInterface(This->document, &IID_IOleInPlaceObjectWindowless,
532 (void**)&winobj);
533 if(SUCCEEDED(hres)) {
534 IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj);
535 IOleInPlaceObjectWindowless_Release(winobj);
538 if(This->view) {
539 IOleDocumentView_Show(This->view, FALSE);
540 IOleDocumentView_CloseView(This->view, 0);
541 IOleDocumentView_SetInPlaceSite(This->view, NULL);
542 IOleDocumentView_Release(This->view);
543 This->view = NULL;
546 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
547 if(SUCCEEDED(hres))
548 IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
550 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
551 if(SUCCEEDED(hres)) {
552 IHlinkTarget_SetBrowseContext(hlink, NULL);
553 IHlinkTarget_Release(hlink);
556 if(oleobj) {
557 IOleClientSite *client_site = NULL;
559 IOleObject_GetClientSite(oleobj, &client_site);
560 if(client_site) {
561 if(client_site == &This->IOleClientSite_iface)
562 IOleObject_SetClientSite(oleobj, NULL);
563 IOleClientSite_Release(client_site);
566 IOleObject_Release(oleobj);
569 IUnknown_Release(This->document);
570 This->document = NULL;
573 HRESULT refresh_document(DocHost *This, const VARIANT *level)
575 IOleCommandTarget *cmdtrg;
576 VARIANT vin, vout;
577 HRESULT hres;
579 if(level && (V_VT(level) != VT_I4 || V_I4(level) != REFRESH_NORMAL))
580 FIXME("Unsupported refresh level %s\n", debugstr_variant(level));
582 if(!This->document) {
583 FIXME("no document\n");
584 return E_FAIL;
587 hres = IUnknown_QueryInterface(This->document, &IID_IOleCommandTarget, (void**)&cmdtrg);
588 if(FAILED(hres))
589 return hres;
591 V_VT(&vin) = VT_EMPTY;
592 V_VT(&vout) = VT_EMPTY;
593 hres = IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_REFRESH, OLECMDEXECOPT_PROMPTUSER, &vin, &vout);
594 IOleCommandTarget_Release(cmdtrg);
595 if(FAILED(hres))
596 return hres;
598 VariantClear(&vout);
599 return S_OK;
602 void release_dochost_client(DocHost *This)
604 if(This->hwnd) {
605 DestroyWindow(This->hwnd);
606 This->hwnd = NULL;
609 if(This->hostui) {
610 IDocHostUIHandler_Release(This->hostui);
611 This->hostui = NULL;
614 if(This->client_disp) {
615 IDispatch_Release(This->client_disp);
616 This->client_disp = NULL;
619 if(This->frame) {
620 IOleInPlaceFrame_Release(This->frame);
621 This->frame = NULL;
624 if(This->olecmd) {
625 IOleCommandTarget_Release(This->olecmd);
626 This->olecmd = NULL;
630 static inline DocHost *impl_from_IOleCommandTarget(IOleCommandTarget *iface)
632 return CONTAINING_RECORD(iface, DocHost, IOleCommandTarget_iface);
635 static HRESULT WINAPI ClOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
636 REFIID riid, void **ppv)
638 DocHost *This = impl_from_IOleCommandTarget(iface);
639 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
642 static ULONG WINAPI ClOleCommandTarget_AddRef(IOleCommandTarget *iface)
644 DocHost *This = impl_from_IOleCommandTarget(iface);
645 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
648 static ULONG WINAPI ClOleCommandTarget_Release(IOleCommandTarget *iface)
650 DocHost *This = impl_from_IOleCommandTarget(iface);
651 return IOleClientSite_Release(&This->IOleClientSite_iface);
654 static HRESULT WINAPI ClOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
655 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
657 DocHost *This = impl_from_IOleCommandTarget(iface);
658 ULONG i;
660 TRACE("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
661 pCmdText);
662 for(i=0; prgCmds && i < cCmds; i++)
663 TRACE("unsupported command %u (%x)\n", prgCmds[i].cmdID, prgCmds[i].cmdf);
665 return E_NOTIMPL;
668 static HRESULT WINAPI ClOleCommandTarget_Exec(IOleCommandTarget *iface,
669 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
670 VARIANT *pvaOut)
672 DocHost *This = impl_from_IOleCommandTarget(iface);
674 TRACE("(%p)->(%s %d %d %s %s)\n", This, debugstr_guid(pguidCmdGroup), nCmdID, nCmdexecopt,
675 debugstr_variant(pvaIn), debugstr_variant(pvaOut));
677 if(!pguidCmdGroup) {
678 switch(nCmdID) {
679 case OLECMDID_UPDATECOMMANDS:
680 if(!This->olecmd)
681 return E_NOTIMPL;
682 return IOleCommandTarget_Exec(This->olecmd, pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
683 case OLECMDID_SETDOWNLOADSTATE:
684 if(This->olecmd)
685 return IOleCommandTarget_Exec(This->olecmd, pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
687 if(!pvaIn || V_VT(pvaIn) != VT_I4)
688 return E_INVALIDARG;
690 notify_download_state(This, V_I4(pvaIn));
691 return S_OK;
692 default:
693 TRACE("Unimplemented cmdid %d\n", nCmdID);
694 return E_NOTIMPL;
698 if(IsEqualGUID(pguidCmdGroup, &CGID_DocHostCmdPriv)) {
699 switch(nCmdID) {
700 case DOCHOST_DOCCANNAVIGATE:
701 if(!pvaIn || V_VT(pvaIn) != VT_UNKNOWN)
702 return E_INVALIDARG;
704 if(This->doc_navigate)
705 IUnknown_Release(This->doc_navigate);
706 IUnknown_AddRef(V_UNKNOWN(pvaIn));
707 This->doc_navigate = V_UNKNOWN(pvaIn);
708 return S_OK;
710 case 1: {
711 IHTMLWindow2 *win2;
712 SAFEARRAY *sa = V_ARRAY(pvaIn);
713 VARIANT status_code, url, htmlwindow;
714 LONG ind;
715 HRESULT hres;
717 if(V_VT(pvaIn) != VT_ARRAY || !sa || (SafeArrayGetDim(sa) != 1))
718 return E_INVALIDARG;
720 ind = 0;
721 hres = SafeArrayGetElement(sa, &ind, &status_code);
722 if(FAILED(hres) || V_VT(&status_code)!=VT_I4)
723 return E_INVALIDARG;
725 ind = 1;
726 hres = SafeArrayGetElement(sa, &ind, &url);
727 if(FAILED(hres) || V_VT(&url)!=VT_BSTR)
728 return E_INVALIDARG;
730 ind = 3;
731 hres = SafeArrayGetElement(sa, &ind, &htmlwindow);
732 if(FAILED(hres) || V_VT(&htmlwindow)!=VT_UNKNOWN || !V_UNKNOWN(&htmlwindow))
733 return E_INVALIDARG;
735 hres = IUnknown_QueryInterface(V_UNKNOWN(&htmlwindow), &IID_IHTMLWindow2, (void**)&win2);
736 if(FAILED(hres))
737 return E_INVALIDARG;
739 handle_navigation_error(This, V_I4(&status_code), V_BSTR(&url), win2);
740 IHTMLWindow2_Release(win2);
741 return S_OK;
744 default:
745 TRACE("unsupported command %d of CGID_DocHostCmdPriv\n", nCmdID);
746 return E_NOTIMPL;
750 if(IsEqualGUID(pguidCmdGroup, &CGID_Explorer)) {
751 switch(nCmdID) {
752 case CMDID_EXPLORER_UPDATEHISTORY:
753 update_travellog(This);
754 update_navigation_commands(This);
755 return S_OK;
757 default:
758 TRACE("Unimplemented cmdid %d of CGID_Explorer\n", nCmdID);
759 return E_NOTIMPL;
763 if(IsEqualGUID(pguidCmdGroup, &CGID_ShellDocView)) {
764 switch(nCmdID) {
765 default:
766 TRACE("Unimplemented cmdid %d of CGID_ShellDocView\n", nCmdID);
767 return E_NOTIMPL;
771 if(IsEqualGUID(&CGID_DocHostCommandHandler, pguidCmdGroup)) {
772 if(!This->olecmd)
773 return E_NOTIMPL;
774 return IOleCommandTarget_Exec(This->olecmd, pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
777 TRACE("Unimplemented cmdid %d of group %s\n", nCmdID, debugstr_guid(pguidCmdGroup));
778 return E_NOTIMPL;
781 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
782 ClOleCommandTarget_QueryInterface,
783 ClOleCommandTarget_AddRef,
784 ClOleCommandTarget_Release,
785 ClOleCommandTarget_QueryStatus,
786 ClOleCommandTarget_Exec
789 static inline DocHost *impl_from_IDocHostUIHandler2(IDocHostUIHandler2 *iface)
791 return CONTAINING_RECORD(iface, DocHost, IDocHostUIHandler2_iface);
794 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface,
795 REFIID riid, void **ppv)
797 DocHost *This = impl_from_IDocHostUIHandler2(iface);
798 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
801 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
803 DocHost *This = impl_from_IDocHostUIHandler2(iface);
804 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
807 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
809 DocHost *This = impl_from_IDocHostUIHandler2(iface);
810 return IOleClientSite_Release(&This->IOleClientSite_iface);
813 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface,
814 DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
816 DocHost *This = impl_from_IDocHostUIHandler2(iface);
817 HRESULT hres;
819 TRACE("(%p)->(%d %p %p %p)\n", This, dwID, ppt, pcmdtReserved, pdispReserved);
821 if(This->hostui) {
822 hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt, pcmdtReserved,
823 pdispReserved);
824 if(hres == S_OK)
825 return S_OK;
828 FIXME("default action not implemented\n");
829 return E_NOTIMPL;
832 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface,
833 DOCHOSTUIINFO *pInfo)
835 DocHost *This = impl_from_IDocHostUIHandler2(iface);
836 HRESULT hres;
838 TRACE("(%p)->(%p)\n", This, pInfo);
840 if(This->hostui) {
841 hres = IDocHostUIHandler_GetHostInfo(This->hostui, pInfo);
842 if(SUCCEEDED(hres))
843 return hres;
846 pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_OPENNEWWIN
847 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
848 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
849 return S_OK;
852 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
853 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
854 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
856 DocHost *This = impl_from_IDocHostUIHandler2(iface);
857 FIXME("(%p)->(%d %p %p %p %p)\n", This, dwID, pActiveObject, pCommandTarget,
858 pFrame, pDoc);
859 return E_NOTIMPL;
862 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
864 DocHost *This = impl_from_IDocHostUIHandler2(iface);
865 FIXME("(%p)\n", This);
866 return E_NOTIMPL;
869 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
871 DocHost *This = impl_from_IDocHostUIHandler2(iface);
873 TRACE("(%p)\n", This);
875 if(!This->hostui)
876 return S_FALSE;
878 return IDocHostUIHandler_UpdateUI(This->hostui);
881 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
882 BOOL fEnable)
884 DocHost *This = impl_from_IDocHostUIHandler2(iface);
885 FIXME("(%p)->(%x)\n", This, fEnable);
886 return E_NOTIMPL;
889 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
890 BOOL fActivate)
892 DocHost *This = impl_from_IDocHostUIHandler2(iface);
893 FIXME("(%p)->(%x)\n", This, fActivate);
894 return E_NOTIMPL;
897 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
898 BOOL fActivate)
900 DocHost *This = impl_from_IDocHostUIHandler2(iface);
901 FIXME("(%p)->(%x)\n", This, fActivate);
902 return E_NOTIMPL;
905 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface,
906 LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
908 DocHost *This = impl_from_IDocHostUIHandler2(iface);
909 FIXME("(%p)->(%p %p %X)\n", This, prcBorder, pUIWindow, fRameWindow);
910 return E_NOTIMPL;
913 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface,
914 LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
916 DocHost *This = impl_from_IDocHostUIHandler2(iface);
917 HRESULT hr = S_FALSE;
918 TRACE("(%p)->(%p %p %d)\n", This, lpMsg, pguidCmdGroup, nCmdID);
920 if(This->hostui)
921 hr = IDocHostUIHandler_TranslateAccelerator(This->hostui, lpMsg, pguidCmdGroup, nCmdID);
923 return hr;
926 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
927 LPOLESTR *pchKey, DWORD dw)
929 DocHost *This = impl_from_IDocHostUIHandler2(iface);
931 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
933 if(This->hostui)
934 return IDocHostUIHandler_GetOptionKeyPath(This->hostui, pchKey, dw);
936 return S_OK;
939 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
940 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
942 DocHost *This = impl_from_IDocHostUIHandler2(iface);
943 FIXME("(%p)\n", This);
944 return E_NOTIMPL;
947 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
948 IDispatch **ppDispatch)
950 DocHost *This = impl_from_IDocHostUIHandler2(iface);
952 TRACE("(%p)->(%p)\n", This, ppDispatch);
954 if(This->hostui)
955 return IDocHostUIHandler_GetExternal(This->hostui, ppDispatch);
957 if(!This->shell_ui_helper) {
958 HRESULT hres;
960 hres = create_shell_ui_helper(&This->shell_ui_helper);
961 if(FAILED(hres))
962 return hres;
965 *ppDispatch = (IDispatch*)This->shell_ui_helper;
966 IDispatch_AddRef(*ppDispatch);
967 return S_OK;
970 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface,
971 DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
973 DocHost *This = impl_from_IDocHostUIHandler2(iface);
975 TRACE("(%p)->(%d %s %p)\n", This, dwTranslate, debugstr_w(pchURLIn), ppchURLOut);
977 if(This->hostui)
978 return IDocHostUIHandler_TranslateUrl(This->hostui, dwTranslate,
979 pchURLIn, ppchURLOut);
981 return S_FALSE;
984 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface,
985 IDataObject *pDO, IDataObject **ppDORet)
987 DocHost *This = impl_from_IDocHostUIHandler2(iface);
988 FIXME("(%p)->(%p %p)\n", This, pDO, ppDORet);
989 return E_NOTIMPL;
992 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
993 LPOLESTR *pchKey, DWORD dw)
995 DocHost *This = impl_from_IDocHostUIHandler2(iface);
996 IDocHostUIHandler2 *handler;
997 HRESULT hres;
999 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
1001 if(!This->hostui)
1002 return S_OK;
1004 hres = IDocHostUIHandler_QueryInterface(This->hostui, &IID_IDocHostUIHandler2,
1005 (void**)&handler);
1006 if(SUCCEEDED(hres)) {
1007 hres = IDocHostUIHandler2_GetOverrideKeyPath(handler, pchKey, dw);
1008 IDocHostUIHandler2_Release(handler);
1009 return hres;
1012 return S_OK;
1015 static const IDocHostUIHandler2Vtbl DocHostUIHandler2Vtbl = {
1016 DocHostUIHandler_QueryInterface,
1017 DocHostUIHandler_AddRef,
1018 DocHostUIHandler_Release,
1019 DocHostUIHandler_ShowContextMenu,
1020 DocHostUIHandler_GetHostInfo,
1021 DocHostUIHandler_ShowUI,
1022 DocHostUIHandler_HideUI,
1023 DocHostUIHandler_UpdateUI,
1024 DocHostUIHandler_EnableModeless,
1025 DocHostUIHandler_OnDocWindowActivate,
1026 DocHostUIHandler_OnFrameWindowActivate,
1027 DocHostUIHandler_ResizeBorder,
1028 DocHostUIHandler_TranslateAccelerator,
1029 DocHostUIHandler_GetOptionKeyPath,
1030 DocHostUIHandler_GetDropTarget,
1031 DocHostUIHandler_GetExternal,
1032 DocHostUIHandler_TranslateUrl,
1033 DocHostUIHandler_FilterDataObject,
1034 DocHostUIHandler_GetOverrideKeyPath
1037 static inline DocHost *impl_from_IPropertyNotifySink(IPropertyNotifySink *iface)
1039 return CONTAINING_RECORD(iface, DocHost, IPropertyNotifySink_iface);
1042 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
1043 REFIID riid, void **ppv)
1045 DocHost *This = impl_from_IPropertyNotifySink(iface);
1046 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1049 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
1051 DocHost *This = impl_from_IPropertyNotifySink(iface);
1052 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1055 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
1057 DocHost *This = impl_from_IPropertyNotifySink(iface);
1058 return IOleClientSite_Release(&This->IOleClientSite_iface);
1061 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
1063 DocHost *This = impl_from_IPropertyNotifySink(iface);
1065 TRACE("(%p)->(%d)\n", This, dispID);
1067 switch(dispID) {
1068 case DISPID_READYSTATE: {
1069 READYSTATE ready_state;
1070 HRESULT hres;
1072 hres = get_doc_ready_state(This, &ready_state);
1073 if(FAILED(hres))
1074 return hres;
1076 if(ready_state == READYSTATE_COMPLETE && !This->doc_navigate)
1077 advise_prop_notif(This, FALSE);
1079 update_ready_state(This, ready_state);
1080 break;
1082 default:
1083 FIXME("unimplemented dispid %d\n", dispID);
1084 return E_NOTIMPL;
1087 return S_OK;
1090 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
1092 DocHost *This = impl_from_IPropertyNotifySink(iface);
1093 FIXME("(%p)->(%d)\n", This, dispID);
1094 return E_NOTIMPL;
1097 static const IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
1098 PropertyNotifySink_QueryInterface,
1099 PropertyNotifySink_AddRef,
1100 PropertyNotifySink_Release,
1101 PropertyNotifySink_OnChanged,
1102 PropertyNotifySink_OnRequestEdit
1105 void DocHost_Init(DocHost *This, IWebBrowser2 *wb, const IDocHostContainerVtbl* container)
1107 This->IDocHostUIHandler2_iface.lpVtbl = &DocHostUIHandler2Vtbl;
1108 This->IOleCommandTarget_iface.lpVtbl = &OleCommandTargetVtbl;
1109 This->IPropertyNotifySink_iface.lpVtbl = &PropertyNotifySinkVtbl;
1111 This->wb = wb;
1112 This->container_vtbl = container;
1114 This->ready_state = READYSTATE_UNINITIALIZED;
1115 list_init(&This->task_queue);
1117 This->travellog.loading_pos = -1;
1119 DocHost_ClientSite_Init(This);
1120 DocHost_Frame_Init(This);
1122 ConnectionPointContainer_Init(&This->cps, (IUnknown*)wb);
1123 IEHTMLWindow_Init(This);
1124 NewWindowManager_Init(This);
1127 void DocHost_Release(DocHost *This)
1129 if(This->shell_ui_helper)
1130 IShellUIHelper2_Release(This->shell_ui_helper);
1132 abort_dochost_tasks(This, NULL);
1133 release_dochost_client(This);
1134 DocHost_ClientSite_Release(This);
1136 ConnectionPointContainer_Destroy(&This->cps);
1138 while(This->travellog.length)
1139 free_travellog_entry(This->travellog.log + --This->travellog.length);
1140 heap_free(This->travellog.log);
1142 heap_free(This->url);