wbemprox: Implement Win32_CDROMDrive.MediaType.
[wine/wine-gecko.git] / dlls / urlmon / bindprot.c
blob7f2bea1c26d9e2438534413f58a287de5a098172
1 /*
2 * Copyright 2007-2009 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 "urlmon_main.h"
20 #include "wine/debug.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
24 typedef void (*task_proc_t)(BindProtocol*,task_header_t*);
26 struct _task_header_t {
27 task_proc_t proc;
28 task_header_t *next;
31 #define BUFFER_SIZE 2048
32 #define MIME_TEST_SIZE 255
34 #define WM_MK_CONTINUE (WM_USER+101)
35 #define WM_MK_RELEASE (WM_USER+102)
37 static void process_tasks(BindProtocol *This)
39 task_header_t *task;
41 while(1) {
42 EnterCriticalSection(&This->section);
44 task = This->task_queue_head;
45 if(task) {
46 This->task_queue_head = task->next;
47 if(!This->task_queue_head)
48 This->task_queue_tail = NULL;
51 LeaveCriticalSection(&This->section);
53 if(!task)
54 break;
56 This->continue_call++;
57 task->proc(This, task);
58 This->continue_call--;
62 static LRESULT WINAPI notif_wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
64 switch(msg) {
65 case WM_MK_CONTINUE: {
66 BindProtocol *This = (BindProtocol*)lParam;
68 process_tasks(This);
70 IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
71 return 0;
73 case WM_MK_RELEASE: {
74 tls_data_t *data = get_tls_data();
76 if(!--data->notif_hwnd_cnt) {
77 DestroyWindow(hwnd);
78 data->notif_hwnd = NULL;
83 return DefWindowProcW(hwnd, msg, wParam, lParam);
86 static const WCHAR wszURLMonikerNotificationWindow[] =
87 {'U','R','L',' ','M','o','n','i','k','e','r',' ',
88 'N','o','t','i','f','i','c','a','t','i','o','n',' ','W','i','n','d','o','w',0};
90 static ATOM notif_wnd_class;
92 static BOOL WINAPI register_notif_wnd_class(INIT_ONCE *once, void *param, void **context)
94 static WNDCLASSEXW wndclass = {
95 sizeof(wndclass), 0, notif_wnd_proc, 0, 0,
96 NULL, NULL, NULL, NULL, NULL,
97 wszURLMonikerNotificationWindow, NULL
100 wndclass.hInstance = hProxyDll;
101 notif_wnd_class = RegisterClassExW(&wndclass);
102 return TRUE;
105 void unregister_notif_wnd_class(void)
107 if(notif_wnd_class)
108 UnregisterClassW(MAKEINTRESOURCEW(notif_wnd_class), hProxyDll);
111 HWND get_notif_hwnd(void)
113 tls_data_t *tls_data;
115 static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
117 tls_data = get_tls_data();
118 if(!tls_data)
119 return NULL;
121 if(tls_data->notif_hwnd_cnt) {
122 tls_data->notif_hwnd_cnt++;
123 return tls_data->notif_hwnd;
126 InitOnceExecuteOnce(&init_once, register_notif_wnd_class, NULL, NULL);
127 if(!notif_wnd_class)
128 return NULL;
130 tls_data->notif_hwnd = CreateWindowExW(0, MAKEINTRESOURCEW(notif_wnd_class),
131 wszURLMonikerNotificationWindow, 0, 0, 0, 0, 0, HWND_MESSAGE,
132 NULL, hProxyDll, NULL);
133 if(tls_data->notif_hwnd)
134 tls_data->notif_hwnd_cnt++;
136 TRACE("hwnd = %p\n", tls_data->notif_hwnd);
138 return tls_data->notif_hwnd;
141 void release_notif_hwnd(HWND hwnd)
143 tls_data_t *data = get_tls_data();
145 if(!data)
146 return;
148 if(data->notif_hwnd != hwnd) {
149 PostMessageW(data->notif_hwnd, WM_MK_RELEASE, 0, 0);
150 return;
153 if(!--data->notif_hwnd_cnt) {
154 DestroyWindow(data->notif_hwnd);
155 data->notif_hwnd = NULL;
159 static void push_task(BindProtocol *This, task_header_t *task, task_proc_t proc)
161 BOOL do_post = FALSE;
163 task->proc = proc;
164 task->next = NULL;
166 EnterCriticalSection(&This->section);
168 if(This->task_queue_tail) {
169 This->task_queue_tail->next = task;
170 This->task_queue_tail = task;
171 }else {
172 This->task_queue_tail = This->task_queue_head = task;
173 do_post = !This->continue_call;
176 LeaveCriticalSection(&This->section);
178 if(do_post) {
179 IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
180 PostMessageW(This->notif_hwnd, WM_MK_CONTINUE, 0, (LPARAM)This);
184 static inline BOOL is_apartment_thread(BindProtocol *This)
186 return This->apartment_thread == GetCurrentThreadId();
189 static inline BOOL do_direct_notif(BindProtocol *This)
191 return !(This->pi & PI_APARTMENTTHREADED) || (is_apartment_thread(This) && !This->continue_call);
194 static HRESULT handle_mime_filter(BindProtocol *This, IInternetProtocol *mime_filter)
196 PROTOCOLFILTERDATA filter_data = { sizeof(PROTOCOLFILTERDATA), NULL, NULL, NULL, 0 };
197 HRESULT hres;
199 hres = IInternetProtocol_QueryInterface(mime_filter, &IID_IInternetProtocolSink, (void**)&This->protocol_sink_handler);
200 if(FAILED(hres)) {
201 This->protocol_sink_handler = &This->default_protocol_handler.IInternetProtocolSink_iface;
202 return hres;
205 IInternetProtocol_AddRef(mime_filter);
206 This->protocol_handler = mime_filter;
208 filter_data.pProtocol = &This->default_protocol_handler.IInternetProtocol_iface;
209 hres = IInternetProtocol_Start(mime_filter, This->mime, &This->default_protocol_handler.IInternetProtocolSink_iface,
210 &This->IInternetBindInfo_iface, PI_FILTER_MODE|PI_FORCE_ASYNC,
211 (HANDLE_PTR)&filter_data);
212 if(FAILED(hres)) {
213 IInternetProtocolSink_Release(This->protocol_sink_handler);
214 IInternetProtocol_Release(This->protocol_handler);
215 This->protocol_sink_handler = &This->default_protocol_handler.IInternetProtocolSink_iface;
216 This->protocol_handler = &This->default_protocol_handler.IInternetProtocol_iface;
217 return hres;
220 /* NOTE: IE9 calls it on the new protocol_sink. It doesn't make sense so it seems to be a bug there. */
221 IInternetProtocolSink_ReportProgress(This->protocol_sink, BINDSTATUS_LOADINGMIMEHANDLER, NULL);
223 return S_OK;
226 static void mime_available(BindProtocol *This, LPCWSTR mime, BOOL verified)
228 IInternetProtocol *mime_filter;
229 HRESULT hres;
231 heap_free(This->mime);
232 This->mime = heap_strdupW(mime);
234 if(This->protocol_handler==&This->default_protocol_handler.IInternetProtocol_iface
235 && (mime_filter = get_mime_filter(mime))) {
236 TRACE("Got mime filter for %s\n", debugstr_w(mime));
238 hres = handle_mime_filter(This, mime_filter);
239 IInternetProtocol_Release(mime_filter);
240 if(FAILED(hres))
241 FIXME("MIME filter failed: %08x\n", hres);
244 if(This->reported_mime || verified || !(This->pi & PI_MIMEVERIFICATION)) {
245 This->reported_mime = TRUE;
246 IInternetProtocolSink_ReportProgress(This->protocol_sink, BINDSTATUS_MIMETYPEAVAILABLE, mime);
250 static inline BindProtocol *impl_from_IInternetProtocolEx(IInternetProtocolEx *iface)
252 return CONTAINING_RECORD(iface, BindProtocol, IInternetProtocolEx_iface);
255 static HRESULT WINAPI BindProtocol_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
257 BindProtocol *This = impl_from_IInternetProtocolEx(iface);
259 *ppv = NULL;
260 if(IsEqualGUID(&IID_IUnknown, riid)) {
261 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
262 *ppv = &This->IInternetProtocolEx_iface;
263 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
264 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
265 *ppv = &This->IInternetProtocolEx_iface;
266 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
267 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
268 *ppv = &This->IInternetProtocolEx_iface;
269 }else if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
270 TRACE("(%p)->(IID_IInternetProtocolEx %p)\n", This, ppv);
271 *ppv = &This->IInternetProtocolEx_iface;
272 }else if(IsEqualGUID(&IID_IInternetBindInfo, riid)) {
273 TRACE("(%p)->(IID_IInternetBindInfo %p)\n", This, ppv);
274 *ppv = &This->IInternetBindInfo_iface;
275 }else if(IsEqualGUID(&IID_IInternetPriority, riid)) {
276 TRACE("(%p)->(IID_IInternetPriority %p)\n", This, ppv);
277 *ppv = &This->IInternetPriority_iface;
278 }else if(IsEqualGUID(&IID_IAuthenticate, riid)) {
279 FIXME("(%p)->(IID_IAuthenticate %p)\n", This, ppv);
280 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
281 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
282 *ppv = &This->IServiceProvider_iface;
283 }else if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
284 TRACE("(%p)->(IID_IInternetProtocolSink %p)\n", This, ppv);
285 *ppv = &This->IInternetProtocolSink_iface;
286 }else if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
287 TRACE("(%p)->(IID_IWinInetInfo %p)\n", This, ppv);
289 if(This->protocol) {
290 IWinInetInfo *inet_info;
291 HRESULT hres;
293 hres = IInternetProtocol_QueryInterface(This->protocol, &IID_IWinInetInfo, (void**)&inet_info);
294 if(SUCCEEDED(hres)) {
295 *ppv = &This->IWinInetHttpInfo_iface;
296 IWinInetInfo_Release(inet_info);
299 }else if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
300 TRACE("(%p)->(IID_IWinInetHttpInfo %p)\n", This, ppv);
302 if(This->protocol) {
303 IWinInetHttpInfo *http_info;
304 HRESULT hres;
306 hres = IInternetProtocol_QueryInterface(This->protocol, &IID_IWinInetHttpInfo, (void**)&http_info);
307 if(SUCCEEDED(hres)) {
308 *ppv = &This->IWinInetHttpInfo_iface;
309 IWinInetHttpInfo_Release(http_info);
312 }else {
313 WARN("not supported interface %s\n", debugstr_guid(riid));
316 if(!*ppv)
317 return E_NOINTERFACE;
319 IUnknown_AddRef((IUnknown*)*ppv);
320 return S_OK;
323 static ULONG WINAPI BindProtocol_AddRef(IInternetProtocolEx *iface)
325 BindProtocol *This = impl_from_IInternetProtocolEx(iface);
326 LONG ref = InterlockedIncrement(&This->ref);
327 TRACE("(%p) ref=%d\n", This, ref);
328 return ref;
331 static ULONG WINAPI BindProtocol_Release(IInternetProtocolEx *iface)
333 BindProtocol *This = impl_from_IInternetProtocolEx(iface);
334 LONG ref = InterlockedDecrement(&This->ref);
336 TRACE("(%p) ref=%d\n", This, ref);
338 if(!ref) {
339 if(This->wininet_info)
340 IWinInetInfo_Release(This->wininet_info);
341 if(This->wininet_http_info)
342 IWinInetHttpInfo_Release(This->wininet_http_info);
343 if(This->protocol)
344 IInternetProtocol_Release(This->protocol);
345 if(This->bind_info)
346 IInternetBindInfo_Release(This->bind_info);
347 if(This->protocol_handler && This->protocol_handler != &This->default_protocol_handler.IInternetProtocol_iface)
348 IInternetProtocol_Release(This->protocol_handler);
349 if(This->protocol_sink_handler &&
350 This->protocol_sink_handler != &This->default_protocol_handler.IInternetProtocolSink_iface)
351 IInternetProtocolSink_Release(This->protocol_sink_handler);
352 if(This->uri)
353 IUri_Release(This->uri);
354 SysFreeString(This->display_uri);
356 set_binding_sink(This, NULL, NULL);
358 if(This->notif_hwnd)
359 release_notif_hwnd(This->notif_hwnd);
360 This->section.DebugInfo->Spare[0] = 0;
361 DeleteCriticalSection(&This->section);
363 heap_free(This->mime);
364 heap_free(This);
366 URLMON_UnlockModule();
369 return ref;
372 static HRESULT WINAPI BindProtocol_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
373 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
374 DWORD grfPI, HANDLE_PTR dwReserved)
376 BindProtocol *This = impl_from_IInternetProtocolEx(iface);
377 IUri *uri;
378 HRESULT hres;
380 TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
381 pOIBindInfo, grfPI, dwReserved);
383 hres = CreateUri(szUrl, Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
384 if(FAILED(hres))
385 return hres;
387 hres = IInternetProtocolEx_StartEx(&This->IInternetProtocolEx_iface, uri, pOIProtSink,
388 pOIBindInfo, grfPI, (HANDLE*)dwReserved);
390 IUri_Release(uri);
391 return hres;
394 static HRESULT WINAPI BindProtocol_Continue(IInternetProtocolEx *iface, PROTOCOLDATA *pProtocolData)
396 BindProtocol *This = impl_from_IInternetProtocolEx(iface);
398 TRACE("(%p)->(%p)\n", This, pProtocolData);
400 return IInternetProtocol_Continue(This->protocol_handler, pProtocolData);
403 static HRESULT WINAPI BindProtocol_Abort(IInternetProtocolEx *iface, HRESULT hrReason,
404 DWORD dwOptions)
406 BindProtocol *This = impl_from_IInternetProtocolEx(iface);
408 TRACE("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
410 return IInternetProtocol_Abort(This->protocol_handler, hrReason, dwOptions);
413 static HRESULT WINAPI BindProtocol_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
415 BindProtocol *This = impl_from_IInternetProtocolEx(iface);
417 TRACE("(%p)->(%08x)\n", This, dwOptions);
419 return IInternetProtocol_Terminate(This->protocol_handler, dwOptions);
422 static HRESULT WINAPI BindProtocol_Suspend(IInternetProtocolEx *iface)
424 BindProtocol *This = impl_from_IInternetProtocolEx(iface);
425 FIXME("(%p)\n", This);
426 return E_NOTIMPL;
429 static HRESULT WINAPI BindProtocol_Resume(IInternetProtocolEx *iface)
431 BindProtocol *This = impl_from_IInternetProtocolEx(iface);
432 FIXME("(%p)\n", This);
433 return E_NOTIMPL;
436 static HRESULT WINAPI BindProtocol_Read(IInternetProtocolEx *iface, void *pv,
437 ULONG cb, ULONG *pcbRead)
439 BindProtocol *This = impl_from_IInternetProtocolEx(iface);
441 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
443 if(pcbRead)
444 *pcbRead = 0;
445 return IInternetProtocol_Read(This->protocol_handler, pv, cb, pcbRead);
448 static HRESULT WINAPI BindProtocol_Seek(IInternetProtocolEx *iface, LARGE_INTEGER dlibMove,
449 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
451 BindProtocol *This = impl_from_IInternetProtocolEx(iface);
452 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
453 return E_NOTIMPL;
456 static HRESULT WINAPI BindProtocol_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
458 BindProtocol *This = impl_from_IInternetProtocolEx(iface);
460 TRACE("(%p)->(%08x)\n", This, dwOptions);
462 return IInternetProtocol_LockRequest(This->protocol_handler, dwOptions);
465 static HRESULT WINAPI BindProtocol_UnlockRequest(IInternetProtocolEx *iface)
467 BindProtocol *This = impl_from_IInternetProtocolEx(iface);
469 TRACE("(%p)\n", This);
471 return IInternetProtocol_UnlockRequest(This->protocol_handler);
474 static HRESULT WINAPI BindProtocol_StartEx(IInternetProtocolEx *iface, IUri *pUri,
475 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
476 DWORD grfPI, HANDLE *dwReserved)
478 BindProtocol *This = impl_from_IInternetProtocolEx(iface);
479 IInternetProtocol *protocol = NULL;
480 IInternetProtocolEx *protocolex;
481 IInternetPriority *priority;
482 IServiceProvider *service_provider;
483 BOOL urlmon_protocol = FALSE;
484 CLSID clsid = IID_NULL;
485 LPOLESTR clsid_str;
486 HRESULT hres;
488 TRACE("(%p)->(%p %p %p %08x %p)\n", This, pUri, pOIProtSink, pOIBindInfo, grfPI, dwReserved);
490 if(!pUri || !pOIProtSink || !pOIBindInfo)
491 return E_INVALIDARG;
493 This->pi = grfPI;
495 IUri_AddRef(pUri);
496 This->uri = pUri;
498 hres = IInternetProtocolSink_QueryInterface(pOIProtSink, &IID_IServiceProvider,
499 (void**)&service_provider);
500 if(SUCCEEDED(hres)) {
501 /* FIXME: What's protocol CLSID here? */
502 IServiceProvider_QueryService(service_provider, &IID_IInternetProtocol,
503 &IID_IInternetProtocol, (void**)&protocol);
504 IServiceProvider_Release(service_provider);
507 if(!protocol) {
508 IClassFactory *cf;
509 IUnknown *unk;
511 hres = get_protocol_handler(pUri, &clsid, &urlmon_protocol, &cf);
512 if(FAILED(hres))
513 return hres;
515 if(This->from_urlmon) {
516 hres = IClassFactory_CreateInstance(cf, NULL, &IID_IInternetProtocol, (void**)&protocol);
517 IClassFactory_Release(cf);
518 if(FAILED(hres))
519 return hres;
520 }else {
521 hres = IClassFactory_CreateInstance(cf, (IUnknown*)&This->IInternetBindInfo_iface,
522 &IID_IUnknown, (void**)&unk);
523 IClassFactory_Release(cf);
524 if(FAILED(hres))
525 return hres;
527 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocol, (void**)&protocol);
528 IUnknown_Release(unk);
529 if(FAILED(hres))
530 return hres;
534 StringFromCLSID(&clsid, &clsid_str);
535 IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_PROTOCOLCLASSID, clsid_str);
536 CoTaskMemFree(clsid_str);
538 This->protocol = protocol;
540 if(urlmon_protocol) {
541 IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&This->wininet_info);
542 IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&This->wininet_http_info);
545 set_binding_sink(This, pOIProtSink, pOIBindInfo);
547 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
548 if(SUCCEEDED(hres)) {
549 IInternetPriority_SetPriority(priority, This->priority);
550 IInternetPriority_Release(priority);
553 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
554 if(SUCCEEDED(hres)) {
555 hres = IInternetProtocolEx_StartEx(protocolex, pUri, &This->IInternetProtocolSink_iface,
556 &This->IInternetBindInfo_iface, 0, NULL);
557 IInternetProtocolEx_Release(protocolex);
558 }else {
559 hres = IUri_GetDisplayUri(pUri, &This->display_uri);
560 if(FAILED(hres))
561 return hres;
563 hres = IInternetProtocol_Start(protocol, This->display_uri, &This->IInternetProtocolSink_iface,
564 &This->IInternetBindInfo_iface, 0, 0);
567 if(SUCCEEDED(hres))
568 process_tasks(This);
569 return hres;
572 void set_binding_sink(BindProtocol *This, IInternetProtocolSink *sink, IInternetBindInfo *bind_info)
574 IInternetProtocolSink *prev_sink;
575 IServiceProvider *service_provider = NULL;
577 if(sink)
578 IInternetProtocolSink_AddRef(sink);
579 prev_sink = InterlockedExchangePointer((void**)&This->protocol_sink, sink);
580 if(prev_sink)
581 IInternetProtocolSink_Release(prev_sink);
583 if(sink)
584 IInternetProtocolSink_QueryInterface(sink, &IID_IServiceProvider, (void**)&service_provider);
585 service_provider = InterlockedExchangePointer((void**)&This->service_provider, service_provider);
586 if(service_provider)
587 IServiceProvider_Release(service_provider);
589 if(bind_info)
590 IInternetBindInfo_AddRef(bind_info);
591 bind_info = InterlockedExchangePointer((void**)&This->bind_info, bind_info);
592 if(bind_info)
593 IInternetBindInfo_Release(bind_info);
596 static const IInternetProtocolExVtbl BindProtocolVtbl = {
597 BindProtocol_QueryInterface,
598 BindProtocol_AddRef,
599 BindProtocol_Release,
600 BindProtocol_Start,
601 BindProtocol_Continue,
602 BindProtocol_Abort,
603 BindProtocol_Terminate,
604 BindProtocol_Suspend,
605 BindProtocol_Resume,
606 BindProtocol_Read,
607 BindProtocol_Seek,
608 BindProtocol_LockRequest,
609 BindProtocol_UnlockRequest,
610 BindProtocol_StartEx
613 static inline BindProtocol *impl_from_IInternetProtocol(IInternetProtocol *iface)
615 return CONTAINING_RECORD(iface, BindProtocol, default_protocol_handler.IInternetProtocol_iface);
618 static HRESULT WINAPI ProtocolHandler_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
620 BindProtocol *This = impl_from_IInternetProtocol(iface);
622 *ppv = NULL;
623 if(IsEqualGUID(&IID_IUnknown, riid)) {
624 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
625 *ppv = &This->default_protocol_handler.IInternetProtocol_iface;
626 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
627 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
628 *ppv = &This->default_protocol_handler.IInternetProtocol_iface;
629 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
630 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
631 *ppv = &This->default_protocol_handler.IInternetProtocol_iface;
632 }else if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
633 TRACE("(%p)->(IID_IInternetProtocolSink %p)\n", This, ppv);
634 *ppv = &This->default_protocol_handler.IInternetProtocolSink_iface;
637 if(*ppv) {
638 IInternetProtocol_AddRef(iface);
639 return S_OK;
642 WARN("not supported interface %s\n", debugstr_guid(riid));
643 return E_NOINTERFACE;
646 static ULONG WINAPI ProtocolHandler_AddRef(IInternetProtocol *iface)
648 BindProtocol *This = impl_from_IInternetProtocol(iface);
649 return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
652 static ULONG WINAPI ProtocolHandler_Release(IInternetProtocol *iface)
654 BindProtocol *This = impl_from_IInternetProtocol(iface);
655 return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
658 static HRESULT WINAPI ProtocolHandler_Start(IInternetProtocol *iface, LPCWSTR szUrl,
659 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
660 DWORD grfPI, HANDLE_PTR dwReserved)
662 ERR("Should not be called\n");
663 return E_NOTIMPL;
666 static HRESULT WINAPI ProtocolHandler_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
668 BindProtocol *This = impl_from_IInternetProtocol(iface);
669 HRESULT hres;
671 TRACE("(%p)->(%p)\n", This, pProtocolData);
673 hres = IInternetProtocol_Continue(This->protocol, pProtocolData);
675 heap_free(pProtocolData);
676 return hres;
679 static HRESULT WINAPI ProtocolHandler_Abort(IInternetProtocol *iface, HRESULT hrReason,
680 DWORD dwOptions)
682 BindProtocol *This = impl_from_IInternetProtocol(iface);
684 TRACE("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
686 if(This->protocol && !This->reported_result)
687 return IInternetProtocol_Abort(This->protocol, hrReason, dwOptions);
689 return S_OK;
692 static HRESULT WINAPI ProtocolHandler_Terminate(IInternetProtocol *iface, DWORD dwOptions)
694 BindProtocol *This = impl_from_IInternetProtocol(iface);
696 TRACE("(%p)->(%08x)\n", This, dwOptions);
698 if(!This->reported_result)
699 return E_FAIL;
701 IInternetProtocol_Terminate(This->protocol, 0);
703 set_binding_sink(This, NULL, NULL);
705 if(This->bind_info) {
706 IInternetBindInfo_Release(This->bind_info);
707 This->bind_info = NULL;
710 return S_OK;
713 static HRESULT WINAPI ProtocolHandler_Suspend(IInternetProtocol *iface)
715 BindProtocol *This = impl_from_IInternetProtocol(iface);
716 FIXME("(%p)\n", This);
717 return E_NOTIMPL;
720 static HRESULT WINAPI ProtocolHandler_Resume(IInternetProtocol *iface)
722 BindProtocol *This = impl_from_IInternetProtocol(iface);
723 FIXME("(%p)\n", This);
724 return E_NOTIMPL;
727 static HRESULT WINAPI ProtocolHandler_Read(IInternetProtocol *iface, void *pv,
728 ULONG cb, ULONG *pcbRead)
730 BindProtocol *This = impl_from_IInternetProtocol(iface);
731 ULONG read = 0;
732 HRESULT hres = S_OK;
734 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
736 if(This->buf_size) {
737 read = min(cb, This->buf_size);
738 memcpy(pv, This->buf, read);
740 if(read == This->buf_size) {
741 heap_free(This->buf);
742 This->buf = NULL;
743 }else {
744 memmove(This->buf, This->buf+cb, This->buf_size-cb);
747 This->buf_size -= read;
750 if(read < cb) {
751 ULONG cread = 0;
753 if(is_apartment_thread(This))
754 This->continue_call++;
755 hres = IInternetProtocol_Read(This->protocol, (BYTE*)pv+read, cb-read, &cread);
756 if(is_apartment_thread(This))
757 This->continue_call--;
758 read += cread;
761 *pcbRead = read;
762 return hres;
765 static HRESULT WINAPI ProtocolHandler_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
766 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
768 BindProtocol *This = impl_from_IInternetProtocol(iface);
769 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
770 return E_NOTIMPL;
773 static HRESULT WINAPI ProtocolHandler_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
775 BindProtocol *This = impl_from_IInternetProtocol(iface);
777 TRACE("(%p)->(%08x)\n", This, dwOptions);
779 return IInternetProtocol_LockRequest(This->protocol, dwOptions);
782 static HRESULT WINAPI ProtocolHandler_UnlockRequest(IInternetProtocol *iface)
784 BindProtocol *This = impl_from_IInternetProtocol(iface);
786 TRACE("(%p)\n", This);
788 return IInternetProtocol_UnlockRequest(This->protocol);
791 static const IInternetProtocolVtbl InternetProtocolHandlerVtbl = {
792 ProtocolHandler_QueryInterface,
793 ProtocolHandler_AddRef,
794 ProtocolHandler_Release,
795 ProtocolHandler_Start,
796 ProtocolHandler_Continue,
797 ProtocolHandler_Abort,
798 ProtocolHandler_Terminate,
799 ProtocolHandler_Suspend,
800 ProtocolHandler_Resume,
801 ProtocolHandler_Read,
802 ProtocolHandler_Seek,
803 ProtocolHandler_LockRequest,
804 ProtocolHandler_UnlockRequest
807 static inline BindProtocol *impl_from_IInternetProtocolSinkHandler(IInternetProtocolSink *iface)
809 return CONTAINING_RECORD(iface, BindProtocol, default_protocol_handler.IInternetProtocolSink_iface);
812 static HRESULT WINAPI ProtocolSinkHandler_QueryInterface(IInternetProtocolSink *iface,
813 REFIID riid, void **ppvObject)
815 BindProtocol *This = impl_from_IInternetProtocolSinkHandler(iface);
816 return IInternetProtocol_QueryInterface(&This->default_protocol_handler.IInternetProtocol_iface,
817 riid, ppvObject);
820 static ULONG WINAPI ProtocolSinkHandler_AddRef(IInternetProtocolSink *iface)
822 BindProtocol *This = impl_from_IInternetProtocolSinkHandler(iface);
823 return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
826 static ULONG WINAPI ProtocolSinkHandler_Release(IInternetProtocolSink *iface)
828 BindProtocol *This = impl_from_IInternetProtocolSinkHandler(iface);
829 return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
832 static HRESULT WINAPI ProtocolSinkHandler_Switch(IInternetProtocolSink *iface,
833 PROTOCOLDATA *pProtocolData)
835 BindProtocol *This = impl_from_IInternetProtocolSinkHandler(iface);
837 TRACE("(%p)->(%p)\n", This, pProtocolData);
839 if(!This->protocol_sink) {
840 IInternetProtocol_Continue(This->protocol_handler, pProtocolData);
841 return S_OK;
844 return IInternetProtocolSink_Switch(This->protocol_sink, pProtocolData);
847 static HRESULT WINAPI ProtocolSinkHandler_ReportProgress(IInternetProtocolSink *iface,
848 ULONG status_code, LPCWSTR status_text)
850 BindProtocol *This = impl_from_IInternetProtocolSinkHandler(iface);
852 TRACE("(%p)->(%s %s)\n", This, debugstr_bindstatus(status_code), debugstr_w(status_text));
854 if(!This->protocol_sink)
855 return S_OK;
857 switch(status_code) {
858 case BINDSTATUS_FINDINGRESOURCE:
859 case BINDSTATUS_CONNECTING:
860 case BINDSTATUS_REDIRECTING:
861 case BINDSTATUS_SENDINGREQUEST:
862 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
863 case BINDSTATUS_DIRECTBIND:
864 case BINDSTATUS_ACCEPTRANGES:
865 case BINDSTATUS_DECODING:
866 IInternetProtocolSink_ReportProgress(This->protocol_sink, status_code, status_text);
867 break;
869 case BINDSTATUS_BEGINDOWNLOADDATA:
870 IInternetProtocolSink_ReportData(This->protocol_sink, This->bscf, This->progress, This->progress_max);
871 break;
873 case BINDSTATUS_MIMETYPEAVAILABLE:
874 mime_available(This, status_text, FALSE);
875 break;
877 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
878 mime_available(This, status_text, TRUE);
879 break;
881 default:
882 FIXME("unsupported ulStatusCode %u\n", status_code);
885 return S_OK;
888 static HRESULT WINAPI ProtocolSinkHandler_ReportData(IInternetProtocolSink *iface,
889 DWORD bscf, ULONG progress, ULONG progress_max)
891 BindProtocol *This = impl_from_IInternetProtocolSinkHandler(iface);
893 TRACE("(%p)->(%x %u %u)\n", This, bscf, progress, progress_max);
895 This->bscf = bscf;
896 This->progress = progress;
897 This->progress_max = progress_max;
899 if(!This->protocol_sink)
900 return S_OK;
902 if((This->pi & PI_MIMEVERIFICATION) && !This->reported_mime) {
903 BYTE buf[BUFFER_SIZE];
904 DWORD read = 0;
905 LPWSTR mime;
906 HRESULT hres;
908 do {
909 read = 0;
910 if(is_apartment_thread(This))
911 This->continue_call++;
912 hres = IInternetProtocol_Read(This->protocol, buf,
913 sizeof(buf)-This->buf_size, &read);
914 if(is_apartment_thread(This))
915 This->continue_call--;
916 if(FAILED(hres) && hres != E_PENDING)
917 return hres;
919 if(!This->buf) {
920 This->buf = heap_alloc(BUFFER_SIZE);
921 if(!This->buf)
922 return E_OUTOFMEMORY;
923 }else if(read + This->buf_size > BUFFER_SIZE) {
924 BYTE *tmp;
926 tmp = heap_realloc(This->buf, read+This->buf_size);
927 if(!tmp)
928 return E_OUTOFMEMORY;
929 This->buf = tmp;
932 memcpy(This->buf+This->buf_size, buf, read);
933 This->buf_size += read;
934 }while(This->buf_size < MIME_TEST_SIZE && hres == S_OK);
936 if(This->buf_size < MIME_TEST_SIZE && hres != S_FALSE)
937 return S_OK;
939 bscf = BSCF_FIRSTDATANOTIFICATION;
940 if(hres == S_FALSE)
941 bscf |= BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE;
943 if(!This->reported_mime) {
944 BSTR raw_uri;
946 hres = IUri_GetRawUri(This->uri, &raw_uri);
947 if(FAILED(hres))
948 return hres;
950 hres = FindMimeFromData(NULL, raw_uri, This->buf, min(This->buf_size, MIME_TEST_SIZE),
951 This->mime, 0, &mime, 0);
952 SysFreeString(raw_uri);
953 if(FAILED(hres))
954 return hres;
956 heap_free(This->mime);
957 This->mime = heap_strdupW(mime);
958 CoTaskMemFree(mime);
959 This->reported_mime = TRUE;
960 if(This->protocol_sink)
961 IInternetProtocolSink_ReportProgress(This->protocol_sink, BINDSTATUS_MIMETYPEAVAILABLE, This->mime);
965 if(!This->protocol_sink)
966 return S_OK;
968 return IInternetProtocolSink_ReportData(This->protocol_sink, bscf, progress, progress_max);
971 static HRESULT WINAPI ProtocolSinkHandler_ReportResult(IInternetProtocolSink *iface,
972 HRESULT hrResult, DWORD dwError, LPCWSTR szResult)
974 BindProtocol *This = impl_from_IInternetProtocolSinkHandler(iface);
976 TRACE("(%p)->(%08x %d %s)\n", This, hrResult, dwError, debugstr_w(szResult));
978 if(This->protocol_sink)
979 return IInternetProtocolSink_ReportResult(This->protocol_sink, hrResult, dwError, szResult);
980 return S_OK;
983 static const IInternetProtocolSinkVtbl InternetProtocolSinkHandlerVtbl = {
984 ProtocolSinkHandler_QueryInterface,
985 ProtocolSinkHandler_AddRef,
986 ProtocolSinkHandler_Release,
987 ProtocolSinkHandler_Switch,
988 ProtocolSinkHandler_ReportProgress,
989 ProtocolSinkHandler_ReportData,
990 ProtocolSinkHandler_ReportResult
993 static inline BindProtocol *impl_from_IInternetBindInfo(IInternetBindInfo *iface)
995 return CONTAINING_RECORD(iface, BindProtocol, IInternetBindInfo_iface);
998 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface,
999 REFIID riid, void **ppv)
1001 BindProtocol *This = impl_from_IInternetBindInfo(iface);
1002 return IInternetProtocolEx_QueryInterface(&This->IInternetProtocolEx_iface, riid, ppv);
1005 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
1007 BindProtocol *This = impl_from_IInternetBindInfo(iface);
1008 return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
1011 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
1013 BindProtocol *This = impl_from_IInternetBindInfo(iface);
1014 return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
1017 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface,
1018 DWORD *grfBINDF, BINDINFO *pbindinfo)
1020 BindProtocol *This = impl_from_IInternetBindInfo(iface);
1021 HRESULT hres;
1023 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
1025 hres = IInternetBindInfo_GetBindInfo(This->bind_info, grfBINDF, pbindinfo);
1026 if(FAILED(hres)) {
1027 WARN("GetBindInfo failed: %08x\n", hres);
1028 return hres;
1031 *grfBINDF |= BINDF_FROMURLMON;
1032 return hres;
1035 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface,
1036 ULONG ulStringType, LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
1038 BindProtocol *This = impl_from_IInternetBindInfo(iface);
1040 TRACE("(%p)->(%d %p %d %p)\n", This, ulStringType, ppwzStr, cEl, pcElFetched);
1042 return IInternetBindInfo_GetBindString(This->bind_info, ulStringType, ppwzStr, cEl, pcElFetched);
1045 static const IInternetBindInfoVtbl InternetBindInfoVtbl = {
1046 BindInfo_QueryInterface,
1047 BindInfo_AddRef,
1048 BindInfo_Release,
1049 BindInfo_GetBindInfo,
1050 BindInfo_GetBindString
1053 static inline BindProtocol *impl_from_IInternetPriority(IInternetPriority *iface)
1055 return CONTAINING_RECORD(iface, BindProtocol, IInternetPriority_iface);
1058 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
1059 REFIID riid, void **ppv)
1061 BindProtocol *This = impl_from_IInternetPriority(iface);
1062 return IInternetProtocolEx_QueryInterface(&This->IInternetProtocolEx_iface, riid, ppv);
1065 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
1067 BindProtocol *This = impl_from_IInternetPriority(iface);
1068 return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
1071 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
1073 BindProtocol *This = impl_from_IInternetPriority(iface);
1074 return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
1077 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
1079 BindProtocol *This = impl_from_IInternetPriority(iface);
1081 TRACE("(%p)->(%d)\n", This, nPriority);
1083 This->priority = nPriority;
1084 return S_OK;
1087 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
1089 BindProtocol *This = impl_from_IInternetPriority(iface);
1091 TRACE("(%p)->(%p)\n", This, pnPriority);
1093 *pnPriority = This->priority;
1094 return S_OK;
1097 static const IInternetPriorityVtbl InternetPriorityVtbl = {
1098 InternetPriority_QueryInterface,
1099 InternetPriority_AddRef,
1100 InternetPriority_Release,
1101 InternetPriority_SetPriority,
1102 InternetPriority_GetPriority
1106 static inline BindProtocol *impl_from_IInternetProtocolSink(IInternetProtocolSink *iface)
1108 return CONTAINING_RECORD(iface, BindProtocol, IInternetProtocolSink_iface);
1111 static HRESULT WINAPI BPInternetProtocolSink_QueryInterface(IInternetProtocolSink *iface,
1112 REFIID riid, void **ppv)
1114 BindProtocol *This = impl_from_IInternetProtocolSink(iface);
1115 return IInternetProtocolEx_QueryInterface(&This->IInternetProtocolEx_iface, riid, ppv);
1118 static ULONG WINAPI BPInternetProtocolSink_AddRef(IInternetProtocolSink *iface)
1120 BindProtocol *This = impl_from_IInternetProtocolSink(iface);
1121 return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
1124 static ULONG WINAPI BPInternetProtocolSink_Release(IInternetProtocolSink *iface)
1126 BindProtocol *This = impl_from_IInternetProtocolSink(iface);
1127 return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
1130 typedef struct {
1131 task_header_t header;
1132 PROTOCOLDATA *data;
1133 } switch_task_t;
1135 static void switch_proc(BindProtocol *bind, task_header_t *t)
1137 switch_task_t *task = (switch_task_t*)t;
1139 IInternetProtocol_Continue(bind->protocol_handler, task->data);
1141 heap_free(task);
1144 static HRESULT WINAPI BPInternetProtocolSink_Switch(IInternetProtocolSink *iface,
1145 PROTOCOLDATA *pProtocolData)
1147 BindProtocol *This = impl_from_IInternetProtocolSink(iface);
1148 PROTOCOLDATA *data;
1150 TRACE("(%p)->(%p)\n", This, pProtocolData);
1152 TRACE("flags %x state %x data %p cb %u\n", pProtocolData->grfFlags, pProtocolData->dwState,
1153 pProtocolData->pData, pProtocolData->cbData);
1155 data = heap_alloc(sizeof(PROTOCOLDATA));
1156 if(!data)
1157 return E_OUTOFMEMORY;
1158 memcpy(data, pProtocolData, sizeof(PROTOCOLDATA));
1160 if((This->pi&PI_APARTMENTTHREADED && pProtocolData->grfFlags&PI_FORCE_ASYNC)
1161 || !do_direct_notif(This)) {
1162 switch_task_t *task;
1164 task = heap_alloc(sizeof(switch_task_t));
1165 if(!task)
1167 heap_free(data);
1168 return E_OUTOFMEMORY;
1171 task->data = data;
1173 push_task(This, &task->header, switch_proc);
1174 return S_OK;
1177 return IInternetProtocolSink_Switch(This->protocol_sink_handler, data);
1180 typedef struct {
1181 task_header_t header;
1183 ULONG status_code;
1184 LPWSTR status_text;
1185 } on_progress_task_t;
1187 static void on_progress_proc(BindProtocol *This, task_header_t *t)
1189 on_progress_task_t *task = (on_progress_task_t*)t;
1191 IInternetProtocolSink_ReportProgress(This->protocol_sink_handler, task->status_code, task->status_text);
1193 heap_free(task->status_text);
1194 heap_free(task);
1197 static HRESULT WINAPI BPInternetProtocolSink_ReportProgress(IInternetProtocolSink *iface,
1198 ULONG ulStatusCode, LPCWSTR szStatusText)
1200 BindProtocol *This = impl_from_IInternetProtocolSink(iface);
1202 TRACE("(%p)->(%u %s)\n", This, ulStatusCode, debugstr_w(szStatusText));
1204 if(do_direct_notif(This)) {
1205 IInternetProtocolSink_ReportProgress(This->protocol_sink_handler, ulStatusCode, szStatusText);
1206 }else {
1207 on_progress_task_t *task;
1209 task = heap_alloc(sizeof(on_progress_task_t));
1211 task->status_code = ulStatusCode;
1212 task->status_text = heap_strdupW(szStatusText);
1214 push_task(This, &task->header, on_progress_proc);
1217 return S_OK;
1220 typedef struct {
1221 task_header_t header;
1222 DWORD bscf;
1223 ULONG progress;
1224 ULONG progress_max;
1225 } report_data_task_t;
1227 static void report_data_proc(BindProtocol *This, task_header_t *t)
1229 report_data_task_t *task = (report_data_task_t*)t;
1231 IInternetProtocolSink_ReportData(This->protocol_sink_handler,
1232 task->bscf, task->progress, task->progress_max);
1234 heap_free(task);
1237 static HRESULT WINAPI BPInternetProtocolSink_ReportData(IInternetProtocolSink *iface,
1238 DWORD grfBSCF, ULONG ulProgress, ULONG ulProgressMax)
1240 BindProtocol *This = impl_from_IInternetProtocolSink(iface);
1242 TRACE("(%p)->(%x %u %u)\n", This, grfBSCF, ulProgress, ulProgressMax);
1244 if(!This->protocol_sink)
1245 return S_OK;
1247 if(!do_direct_notif(This)) {
1248 report_data_task_t *task;
1250 task = heap_alloc(sizeof(report_data_task_t));
1251 if(!task)
1252 return E_OUTOFMEMORY;
1254 task->bscf = grfBSCF;
1255 task->progress = ulProgress;
1256 task->progress_max = ulProgressMax;
1258 push_task(This, &task->header, report_data_proc);
1259 return S_OK;
1262 return IInternetProtocolSink_ReportData(This->protocol_sink_handler,
1263 grfBSCF, ulProgress, ulProgressMax);
1266 typedef struct {
1267 task_header_t header;
1269 HRESULT hres;
1270 DWORD err;
1271 LPWSTR str;
1272 } report_result_task_t;
1274 static void report_result_proc(BindProtocol *This, task_header_t *t)
1276 report_result_task_t *task = (report_result_task_t*)t;
1278 IInternetProtocolSink_ReportResult(This->protocol_sink_handler, task->hres, task->err, task->str);
1280 heap_free(task->str);
1281 heap_free(task);
1284 static HRESULT WINAPI BPInternetProtocolSink_ReportResult(IInternetProtocolSink *iface,
1285 HRESULT hrResult, DWORD dwError, LPCWSTR szResult)
1287 BindProtocol *This = impl_from_IInternetProtocolSink(iface);
1289 TRACE("(%p)->(%08x %d %s)\n", This, hrResult, dwError, debugstr_w(szResult));
1291 if(!This->protocol_sink)
1292 return E_FAIL;
1293 This->reported_result = TRUE;
1295 if(!do_direct_notif(This)) {
1296 report_result_task_t *task;
1298 task = heap_alloc(sizeof(report_result_task_t));
1299 if(!task)
1300 return E_OUTOFMEMORY;
1302 task->hres = hrResult;
1303 task->err = dwError;
1304 task->str = heap_strdupW(szResult);
1306 push_task(This, &task->header, report_result_proc);
1307 return S_OK;
1310 return IInternetProtocolSink_ReportResult(This->protocol_sink_handler, hrResult, dwError, szResult);
1313 static const IInternetProtocolSinkVtbl InternetProtocolSinkVtbl = {
1314 BPInternetProtocolSink_QueryInterface,
1315 BPInternetProtocolSink_AddRef,
1316 BPInternetProtocolSink_Release,
1317 BPInternetProtocolSink_Switch,
1318 BPInternetProtocolSink_ReportProgress,
1319 BPInternetProtocolSink_ReportData,
1320 BPInternetProtocolSink_ReportResult
1323 static inline BindProtocol *impl_from_IWinInetHttpInfo(IWinInetHttpInfo *iface)
1325 return CONTAINING_RECORD(iface, BindProtocol, IWinInetHttpInfo_iface);
1328 static HRESULT WINAPI WinInetHttpInfo_QueryInterface(IWinInetHttpInfo *iface, REFIID riid, void **ppv)
1330 BindProtocol *This = impl_from_IWinInetHttpInfo(iface);
1331 return IInternetProtocolEx_QueryInterface(&This->IInternetProtocolEx_iface, riid, ppv);
1334 static ULONG WINAPI WinInetHttpInfo_AddRef(IWinInetHttpInfo *iface)
1336 BindProtocol *This = impl_from_IWinInetHttpInfo(iface);
1337 return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
1340 static ULONG WINAPI WinInetHttpInfo_Release(IWinInetHttpInfo *iface)
1342 BindProtocol *This = impl_from_IWinInetHttpInfo(iface);
1343 return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
1346 static HRESULT WINAPI WinInetHttpInfo_QueryOption(IWinInetHttpInfo *iface, DWORD dwOption,
1347 void *pBuffer, DWORD *pcbBuffer)
1349 BindProtocol *This = impl_from_IWinInetHttpInfo(iface);
1350 FIXME("(%p)->(%x %p %p)\n", This, dwOption, pBuffer, pcbBuffer);
1351 return E_NOTIMPL;
1354 static HRESULT WINAPI WinInetHttpInfo_QueryInfo(IWinInetHttpInfo *iface, DWORD dwOption,
1355 void *pBuffer, DWORD *pcbBuffer, DWORD *pdwFlags, DWORD *pdwReserved)
1357 BindProtocol *This = impl_from_IWinInetHttpInfo(iface);
1358 FIXME("(%p)->(%x %p %p %p %p)\n", This, dwOption, pBuffer, pcbBuffer, pdwFlags, pdwReserved);
1359 return E_NOTIMPL;
1362 static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl = {
1363 WinInetHttpInfo_QueryInterface,
1364 WinInetHttpInfo_AddRef,
1365 WinInetHttpInfo_Release,
1366 WinInetHttpInfo_QueryOption,
1367 WinInetHttpInfo_QueryInfo
1370 static inline BindProtocol *impl_from_IServiceProvider(IServiceProvider *iface)
1372 return CONTAINING_RECORD(iface, BindProtocol, IServiceProvider_iface);
1375 static HRESULT WINAPI BPServiceProvider_QueryInterface(IServiceProvider *iface,
1376 REFIID riid, void **ppv)
1378 BindProtocol *This = impl_from_IServiceProvider(iface);
1379 return IInternetProtocolEx_QueryInterface(&This->IInternetProtocolEx_iface, riid, ppv);
1382 static ULONG WINAPI BPServiceProvider_AddRef(IServiceProvider *iface)
1384 BindProtocol *This = impl_from_IServiceProvider(iface);
1385 return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
1388 static ULONG WINAPI BPServiceProvider_Release(IServiceProvider *iface)
1390 BindProtocol *This = impl_from_IServiceProvider(iface);
1391 return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
1394 static HRESULT WINAPI BPServiceProvider_QueryService(IServiceProvider *iface,
1395 REFGUID guidService, REFIID riid, void **ppv)
1397 BindProtocol *This = impl_from_IServiceProvider(iface);
1399 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
1401 if(!This->service_provider)
1402 return E_NOINTERFACE;
1404 return IServiceProvider_QueryService(This->service_provider, guidService, riid, ppv);
1407 static const IServiceProviderVtbl ServiceProviderVtbl = {
1408 BPServiceProvider_QueryInterface,
1409 BPServiceProvider_AddRef,
1410 BPServiceProvider_Release,
1411 BPServiceProvider_QueryService
1414 HRESULT create_binding_protocol(BOOL from_urlmon, BindProtocol **protocol)
1416 BindProtocol *ret = heap_alloc_zero(sizeof(BindProtocol));
1418 ret->IInternetProtocolEx_iface.lpVtbl = &BindProtocolVtbl;
1419 ret->IInternetBindInfo_iface.lpVtbl = &InternetBindInfoVtbl;
1420 ret->IInternetPriority_iface.lpVtbl = &InternetPriorityVtbl;
1421 ret->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
1422 ret->IInternetProtocolSink_iface.lpVtbl = &InternetProtocolSinkVtbl;
1423 ret->IWinInetHttpInfo_iface.lpVtbl = &WinInetHttpInfoVtbl;
1425 ret->default_protocol_handler.IInternetProtocol_iface.lpVtbl = &InternetProtocolHandlerVtbl;
1426 ret->default_protocol_handler.IInternetProtocolSink_iface.lpVtbl = &InternetProtocolSinkHandlerVtbl;
1428 ret->ref = 1;
1429 ret->from_urlmon = from_urlmon;
1430 ret->apartment_thread = GetCurrentThreadId();
1431 ret->notif_hwnd = get_notif_hwnd();
1432 ret->protocol_handler = &ret->default_protocol_handler.IInternetProtocol_iface;
1433 ret->protocol_sink_handler = &ret->default_protocol_handler.IInternetProtocolSink_iface;
1434 InitializeCriticalSection(&ret->section);
1435 ret->section.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": BindProtocol.section");
1437 URLMON_LockModule();
1439 *protocol = ret;
1440 return S_OK;