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
{
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
)
42 EnterCriticalSection(&This
->section
);
44 task
= This
->task_queue_head
;
46 This
->task_queue_head
= task
->next
;
47 if(!This
->task_queue_head
)
48 This
->task_queue_tail
= NULL
;
51 LeaveCriticalSection(&This
->section
);
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
)
65 case WM_MK_CONTINUE
: {
66 BindProtocol
*This
= (BindProtocol
*)lParam
;
70 IInternetProtocolEx_Release(&This
->IInternetProtocolEx_iface
);
74 tls_data_t
*data
= get_tls_data();
76 if(!--data
->notif_hwnd_cnt
) {
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
);
105 void unregister_notif_wnd_class(void)
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();
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
);
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();
148 if(data
->notif_hwnd
!= hwnd
) {
149 PostMessageW(data
->notif_hwnd
, WM_MK_RELEASE
, 0, 0);
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
;
166 EnterCriticalSection(&This
->section
);
168 if(This
->task_queue_tail
) {
169 This
->task_queue_tail
->next
= task
;
170 This
->task_queue_tail
= task
;
172 This
->task_queue_tail
= This
->task_queue_head
= task
;
173 do_post
= !This
->continue_call
;
176 LeaveCriticalSection(&This
->section
);
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 };
199 hres
= IInternetProtocol_QueryInterface(mime_filter
, &IID_IInternetProtocolSink
, (void**)&This
->protocol_sink_handler
);
201 This
->protocol_sink_handler
= &This
->default_protocol_handler
.IInternetProtocolSink_iface
;
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
);
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
;
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
);
226 static void mime_available(BindProtocol
*This
, LPCWSTR mime
, BOOL verified
)
228 IInternetProtocol
*mime_filter
;
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
);
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
);
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(This
->protocol_unk
) {
288 hres
= IUnknown_QueryInterface(This
->protocol_unk
, riid
, ppv
);
289 TRACE("(%p) aggregated handler returned %08x for %s\n", This
, hres
, debugstr_guid(riid
));
292 WARN("not supported interface %s\n", debugstr_guid(riid
));
296 return E_NOINTERFACE
;
298 IUnknown_AddRef((IUnknown
*)*ppv
);
302 static ULONG WINAPI
BindProtocol_AddRef(IInternetProtocolEx
*iface
)
304 BindProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
305 LONG ref
= InterlockedIncrement(&This
->ref
);
306 TRACE("(%p) ref=%d\n", This
, ref
);
310 static void release_protocol_handler(BindProtocol
*This
)
313 IInternetProtocol_Release(This
->protocol
);
314 This
->protocol
= NULL
;
316 if(This
->protocol_handler
&& This
->protocol_handler
!= &This
->default_protocol_handler
.IInternetProtocol_iface
) {
317 IInternetProtocol_Release(This
->protocol_handler
);
318 This
->protocol_handler
= &This
->default_protocol_handler
.IInternetProtocol_iface
;
320 if(This
->protocol_sink_handler
&&
321 This
->protocol_sink_handler
!= &This
->default_protocol_handler
.IInternetProtocolSink_iface
) {
322 IInternetProtocolSink_Release(This
->protocol_sink_handler
);
323 This
->protocol_sink_handler
= &This
->default_protocol_handler
.IInternetProtocolSink_iface
;
325 if(This
->protocol_unk
) {
326 IUnknown_Release(This
->protocol_unk
);
327 This
->protocol_unk
= NULL
;
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
);
339 release_protocol_handler(This
);
340 if(This
->redirect_callback
)
341 IBindCallbackRedirect_Release(This
->redirect_callback
);
343 IInternetBindInfo_Release(This
->bind_info
);
345 IUri_Release(This
->uri
);
346 SysFreeString(This
->display_uri
);
348 set_binding_sink(This
, NULL
, NULL
);
351 release_notif_hwnd(This
->notif_hwnd
);
352 This
->section
.DebugInfo
->Spare
[0] = 0;
353 DeleteCriticalSection(&This
->section
);
355 heap_free(This
->mime
);
358 URLMON_UnlockModule();
364 static HRESULT WINAPI
BindProtocol_Start(IInternetProtocolEx
*iface
, LPCWSTR szUrl
,
365 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
366 DWORD grfPI
, HANDLE_PTR dwReserved
)
368 BindProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
372 TRACE("(%p)->(%s %p %p %08x %lx)\n", This
, debugstr_w(szUrl
), pOIProtSink
,
373 pOIBindInfo
, grfPI
, dwReserved
);
375 hres
= CreateUri(szUrl
, Uri_CREATE_FILE_USE_DOS_PATH
, 0, &uri
);
379 hres
= IInternetProtocolEx_StartEx(&This
->IInternetProtocolEx_iface
, uri
, pOIProtSink
,
380 pOIBindInfo
, grfPI
, (HANDLE
*)dwReserved
);
386 static HRESULT WINAPI
BindProtocol_Continue(IInternetProtocolEx
*iface
, PROTOCOLDATA
*pProtocolData
)
388 BindProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
390 TRACE("(%p)->(%p)\n", This
, pProtocolData
);
392 return IInternetProtocol_Continue(This
->protocol_handler
, pProtocolData
);
395 static HRESULT WINAPI
BindProtocol_Abort(IInternetProtocolEx
*iface
, HRESULT hrReason
,
398 BindProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
400 TRACE("(%p)->(%08x %08x)\n", This
, hrReason
, dwOptions
);
402 return IInternetProtocol_Abort(This
->protocol_handler
, hrReason
, dwOptions
);
405 static HRESULT WINAPI
BindProtocol_Terminate(IInternetProtocolEx
*iface
, DWORD dwOptions
)
407 BindProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
409 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
411 return IInternetProtocol_Terminate(This
->protocol_handler
, dwOptions
);
414 static HRESULT WINAPI
BindProtocol_Suspend(IInternetProtocolEx
*iface
)
416 BindProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
417 FIXME("(%p)\n", This
);
421 static HRESULT WINAPI
BindProtocol_Resume(IInternetProtocolEx
*iface
)
423 BindProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
424 FIXME("(%p)\n", This
);
428 static HRESULT WINAPI
BindProtocol_Read(IInternetProtocolEx
*iface
, void *pv
,
429 ULONG cb
, ULONG
*pcbRead
)
431 BindProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
433 TRACE("(%p)->(%p %u %p)\n", This
, pv
, cb
, pcbRead
);
437 return IInternetProtocol_Read(This
->protocol_handler
, pv
, cb
, pcbRead
);
440 static HRESULT WINAPI
BindProtocol_Seek(IInternetProtocolEx
*iface
, LARGE_INTEGER dlibMove
,
441 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
443 BindProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
444 FIXME("(%p)->(%d %d %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
448 static HRESULT WINAPI
BindProtocol_LockRequest(IInternetProtocolEx
*iface
, DWORD dwOptions
)
450 BindProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
452 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
454 return IInternetProtocol_LockRequest(This
->protocol_handler
, dwOptions
);
457 static HRESULT WINAPI
BindProtocol_UnlockRequest(IInternetProtocolEx
*iface
)
459 BindProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
461 TRACE("(%p)\n", This
);
463 return IInternetProtocol_UnlockRequest(This
->protocol_handler
);
466 static HRESULT WINAPI
BindProtocol_StartEx(IInternetProtocolEx
*iface
, IUri
*pUri
,
467 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
468 DWORD grfPI
, HANDLE
*dwReserved
)
470 BindProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
471 IInternetProtocol
*protocol
= NULL
;
472 IInternetProtocolEx
*protocolex
;
473 IInternetPriority
*priority
;
474 IServiceProvider
*service_provider
;
475 CLSID clsid
= IID_NULL
;
476 IUnknown
*protocol_unk
= NULL
;
480 TRACE("(%p)->(%p %p %p %08x %p)\n", This
, pUri
, pOIProtSink
, pOIBindInfo
, grfPI
, dwReserved
);
482 if(!pUri
|| !pOIProtSink
|| !pOIBindInfo
)
488 SysFreeString(This
->display_uri
);
489 IUri_Release(This
->uri
);
494 hres
= IInternetProtocolSink_QueryInterface(pOIProtSink
, &IID_IServiceProvider
,
495 (void**)&service_provider
);
496 if(SUCCEEDED(hres
)) {
497 /* FIXME: What's protocol CLSID here? */
498 IServiceProvider_QueryService(service_provider
, &IID_IInternetProtocol
,
499 &IID_IInternetProtocol
, (void**)&protocol
);
500 IServiceProvider_Release(service_provider
);
506 hres
= get_protocol_handler(pUri
, &clsid
, &cf
);
510 hres
= IClassFactory_CreateInstance(cf
, (IUnknown
*)&This
->IInternetBindInfo_iface
,
511 &IID_IUnknown
, (void**)&protocol_unk
);
512 if(SUCCEEDED(hres
)) {
513 hres
= IUnknown_QueryInterface(protocol_unk
, &IID_IInternetProtocol
, (void**)&protocol
);
515 This
->protocol_unk
= protocol_unk
;
517 IUnknown_Release(protocol_unk
);
519 else if(hres
== CLASS_E_NOAGGREGATION
)
520 hres
= IClassFactory_CreateInstance(cf
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
522 IClassFactory_Release(cf
);
527 StringFromCLSID(&clsid
, &clsid_str
);
528 IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_PROTOCOLCLASSID
, clsid_str
);
529 CoTaskMemFree(clsid_str
);
531 This
->protocol_unk
= protocol_unk
;
532 This
->protocol
= protocol
;
535 protocol_unk
= (IUnknown
*)protocol
;
537 set_binding_sink(This
, pOIProtSink
, pOIBindInfo
);
539 hres
= IUnknown_QueryInterface(protocol_unk
, &IID_IInternetPriority
, (void**)&priority
);
540 if(SUCCEEDED(hres
)) {
541 IInternetPriority_SetPriority(priority
, This
->priority
);
542 IInternetPriority_Release(priority
);
545 hres
= IUnknown_QueryInterface(protocol_unk
, &IID_IInternetProtocolEx
, (void**)&protocolex
);
546 if(SUCCEEDED(hres
)) {
547 hres
= IInternetProtocolEx_StartEx(protocolex
, pUri
, &This
->IInternetProtocolSink_iface
,
548 &This
->IInternetBindInfo_iface
, 0, NULL
);
549 IInternetProtocolEx_Release(protocolex
);
551 hres
= IUri_GetDisplayUri(pUri
, &This
->display_uri
);
555 hres
= IInternetProtocol_Start(protocol
, This
->display_uri
, &This
->IInternetProtocolSink_iface
,
556 &This
->IInternetBindInfo_iface
, 0, 0);
564 void set_binding_sink(BindProtocol
*This
, IInternetProtocolSink
*sink
, IInternetBindInfo
*bind_info
)
566 IInternetProtocolSink
*prev_sink
;
567 IServiceProvider
*service_provider
= NULL
;
570 IInternetProtocolSink_AddRef(sink
);
571 prev_sink
= InterlockedExchangePointer((void**)&This
->protocol_sink
, sink
);
573 IInternetProtocolSink_Release(prev_sink
);
576 IInternetProtocolSink_QueryInterface(sink
, &IID_IServiceProvider
, (void**)&service_provider
);
577 service_provider
= InterlockedExchangePointer((void**)&This
->service_provider
, service_provider
);
579 IServiceProvider_Release(service_provider
);
582 IInternetBindInfo_AddRef(bind_info
);
583 bind_info
= InterlockedExchangePointer((void**)&This
->bind_info
, bind_info
);
585 IInternetBindInfo_Release(bind_info
);
588 static const IInternetProtocolExVtbl BindProtocolVtbl
= {
589 BindProtocol_QueryInterface
,
591 BindProtocol_Release
,
593 BindProtocol_Continue
,
595 BindProtocol_Terminate
,
596 BindProtocol_Suspend
,
600 BindProtocol_LockRequest
,
601 BindProtocol_UnlockRequest
,
605 static inline BindProtocol
*impl_from_IInternetProtocol(IInternetProtocol
*iface
)
607 return CONTAINING_RECORD(iface
, BindProtocol
, default_protocol_handler
.IInternetProtocol_iface
);
610 static HRESULT WINAPI
ProtocolHandler_QueryInterface(IInternetProtocol
*iface
, REFIID riid
, void **ppv
)
612 BindProtocol
*This
= impl_from_IInternetProtocol(iface
);
615 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
616 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
617 *ppv
= &This
->default_protocol_handler
.IInternetProtocol_iface
;
618 }else if(IsEqualGUID(&IID_IInternetProtocolRoot
, riid
)) {
619 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This
, ppv
);
620 *ppv
= &This
->default_protocol_handler
.IInternetProtocol_iface
;
621 }else if(IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
622 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This
, ppv
);
623 *ppv
= &This
->default_protocol_handler
.IInternetProtocol_iface
;
624 }else if(IsEqualGUID(&IID_IInternetProtocolSink
, riid
)) {
625 TRACE("(%p)->(IID_IInternetProtocolSink %p)\n", This
, ppv
);
626 *ppv
= &This
->default_protocol_handler
.IInternetProtocolSink_iface
;
630 IInternetProtocol_AddRef(iface
);
634 WARN("not supported interface %s\n", debugstr_guid(riid
));
635 return E_NOINTERFACE
;
638 static ULONG WINAPI
ProtocolHandler_AddRef(IInternetProtocol
*iface
)
640 BindProtocol
*This
= impl_from_IInternetProtocol(iface
);
641 return IInternetProtocolEx_AddRef(&This
->IInternetProtocolEx_iface
);
644 static ULONG WINAPI
ProtocolHandler_Release(IInternetProtocol
*iface
)
646 BindProtocol
*This
= impl_from_IInternetProtocol(iface
);
647 return IInternetProtocolEx_Release(&This
->IInternetProtocolEx_iface
);
650 static HRESULT WINAPI
ProtocolHandler_Start(IInternetProtocol
*iface
, LPCWSTR szUrl
,
651 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
652 DWORD grfPI
, HANDLE_PTR dwReserved
)
654 ERR("Should not be called\n");
658 static HRESULT WINAPI
ProtocolHandler_Continue(IInternetProtocol
*iface
, PROTOCOLDATA
*pProtocolData
)
660 BindProtocol
*This
= impl_from_IInternetProtocol(iface
);
661 IInternetProtocol
*protocol
= NULL
;
664 TRACE("(%p)->(%p)\n", This
, pProtocolData
);
666 /* FIXME: This should not be needed. */
667 if(!This
->protocol
) {
668 if(!This
->protocol_unk
)
670 hres
= IUnknown_QueryInterface(This
->protocol_unk
, &IID_IInternetProtocol
, (void**)&protocol
);
675 hres
= IInternetProtocol_Continue(protocol
? protocol
: This
->protocol
, pProtocolData
);
677 heap_free(pProtocolData
);
679 IInternetProtocol_Release(protocol
);
683 static HRESULT WINAPI
ProtocolHandler_Abort(IInternetProtocol
*iface
, HRESULT hrReason
,
686 BindProtocol
*This
= impl_from_IInternetProtocol(iface
);
688 TRACE("(%p)->(%08x %08x)\n", This
, hrReason
, dwOptions
);
690 if(This
->protocol
&& !This
->reported_result
)
691 return IInternetProtocol_Abort(This
->protocol
, hrReason
, dwOptions
);
696 static HRESULT WINAPI
ProtocolHandler_Terminate(IInternetProtocol
*iface
, DWORD dwOptions
)
698 BindProtocol
*This
= impl_from_IInternetProtocol(iface
);
700 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
702 if(!This
->reported_result
)
705 /* This may get released in Terminate call. */
706 IInternetProtocolEx_AddRef(&This
->IInternetProtocolEx_iface
);
709 IInternetProtocol_Terminate(This
->protocol
, 0);
711 if (This
->protocol_unk
) {
712 IInternetProtocol_Release(This
->protocol
);
713 This
->protocol
= NULL
;
717 set_binding_sink(This
, NULL
, NULL
);
719 if(This
->bind_info
) {
720 IInternetBindInfo_Release(This
->bind_info
);
721 This
->bind_info
= NULL
;
724 if(This
->redirect_callback
) {
725 IBindCallbackRedirect_Release(This
->redirect_callback
);
726 This
->redirect_callback
= NULL
;
729 IInternetProtocolEx_Release(&This
->IInternetProtocolEx_iface
);
733 static HRESULT WINAPI
ProtocolHandler_Suspend(IInternetProtocol
*iface
)
735 BindProtocol
*This
= impl_from_IInternetProtocol(iface
);
736 FIXME("(%p)\n", This
);
740 static HRESULT WINAPI
ProtocolHandler_Resume(IInternetProtocol
*iface
)
742 BindProtocol
*This
= impl_from_IInternetProtocol(iface
);
743 FIXME("(%p)\n", This
);
747 static HRESULT WINAPI
ProtocolHandler_Read(IInternetProtocol
*iface
, void *pv
,
748 ULONG cb
, ULONG
*pcbRead
)
750 BindProtocol
*This
= impl_from_IInternetProtocol(iface
);
754 TRACE("(%p)->(%p %u %p)\n", This
, pv
, cb
, pcbRead
);
757 read
= min(cb
, This
->buf_size
);
758 memcpy(pv
, This
->buf
, read
);
760 if(read
== This
->buf_size
) {
761 heap_free(This
->buf
);
764 memmove(This
->buf
, This
->buf
+cb
, This
->buf_size
-cb
);
767 This
->buf_size
-= read
;
771 IInternetProtocol
*protocol
;
774 /* FIXME: We shouldn't need it, but out binding code currently depends on it. */
775 if(!This
->protocol
&& This
->protocol_unk
) {
776 hres
= IUnknown_QueryInterface(This
->protocol_unk
, &IID_IInternetProtocol
,
781 protocol
= This
->protocol
;
784 if(is_apartment_thread(This
))
785 This
->continue_call
++;
786 hres
= IInternetProtocol_Read(protocol
, (BYTE
*)pv
+read
, cb
-read
, &cread
);
787 if(is_apartment_thread(This
))
788 This
->continue_call
--;
792 IInternetProtocol_Release(protocol
);
799 static HRESULT WINAPI
ProtocolHandler_Seek(IInternetProtocol
*iface
, LARGE_INTEGER dlibMove
,
800 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
802 BindProtocol
*This
= impl_from_IInternetProtocol(iface
);
803 FIXME("(%p)->(%d %d %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
807 static HRESULT WINAPI
ProtocolHandler_LockRequest(IInternetProtocol
*iface
, DWORD dwOptions
)
809 BindProtocol
*This
= impl_from_IInternetProtocol(iface
);
811 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
813 return IInternetProtocol_LockRequest(This
->protocol
, dwOptions
);
816 static HRESULT WINAPI
ProtocolHandler_UnlockRequest(IInternetProtocol
*iface
)
818 BindProtocol
*This
= impl_from_IInternetProtocol(iface
);
820 TRACE("(%p)\n", This
);
822 return IInternetProtocol_UnlockRequest(This
->protocol
);
825 static const IInternetProtocolVtbl InternetProtocolHandlerVtbl
= {
826 ProtocolHandler_QueryInterface
,
827 ProtocolHandler_AddRef
,
828 ProtocolHandler_Release
,
829 ProtocolHandler_Start
,
830 ProtocolHandler_Continue
,
831 ProtocolHandler_Abort
,
832 ProtocolHandler_Terminate
,
833 ProtocolHandler_Suspend
,
834 ProtocolHandler_Resume
,
835 ProtocolHandler_Read
,
836 ProtocolHandler_Seek
,
837 ProtocolHandler_LockRequest
,
838 ProtocolHandler_UnlockRequest
841 static inline BindProtocol
*impl_from_IInternetProtocolSinkHandler(IInternetProtocolSink
*iface
)
843 return CONTAINING_RECORD(iface
, BindProtocol
, default_protocol_handler
.IInternetProtocolSink_iface
);
846 static HRESULT WINAPI
ProtocolSinkHandler_QueryInterface(IInternetProtocolSink
*iface
,
847 REFIID riid
, void **ppvObject
)
849 BindProtocol
*This
= impl_from_IInternetProtocolSinkHandler(iface
);
850 return IInternetProtocol_QueryInterface(&This
->default_protocol_handler
.IInternetProtocol_iface
,
854 static ULONG WINAPI
ProtocolSinkHandler_AddRef(IInternetProtocolSink
*iface
)
856 BindProtocol
*This
= impl_from_IInternetProtocolSinkHandler(iface
);
857 return IInternetProtocolEx_AddRef(&This
->IInternetProtocolEx_iface
);
860 static ULONG WINAPI
ProtocolSinkHandler_Release(IInternetProtocolSink
*iface
)
862 BindProtocol
*This
= impl_from_IInternetProtocolSinkHandler(iface
);
863 return IInternetProtocolEx_Release(&This
->IInternetProtocolEx_iface
);
866 static HRESULT WINAPI
ProtocolSinkHandler_Switch(IInternetProtocolSink
*iface
,
867 PROTOCOLDATA
*pProtocolData
)
869 BindProtocol
*This
= impl_from_IInternetProtocolSinkHandler(iface
);
871 TRACE("(%p)->(%p)\n", This
, pProtocolData
);
873 if(!This
->protocol_sink
) {
874 IInternetProtocol_Continue(This
->protocol_handler
, pProtocolData
);
878 return IInternetProtocolSink_Switch(This
->protocol_sink
, pProtocolData
);
881 static HRESULT WINAPI
ProtocolSinkHandler_ReportProgress(IInternetProtocolSink
*iface
,
882 ULONG status_code
, LPCWSTR status_text
)
884 BindProtocol
*This
= impl_from_IInternetProtocolSinkHandler(iface
);
886 TRACE("(%p)->(%s %s)\n", This
, debugstr_bindstatus(status_code
), debugstr_w(status_text
));
888 if(!This
->protocol_sink
)
891 switch(status_code
) {
892 case BINDSTATUS_FINDINGRESOURCE
:
893 case BINDSTATUS_CONNECTING
:
894 case BINDSTATUS_REDIRECTING
:
895 case BINDSTATUS_SENDINGREQUEST
:
896 case BINDSTATUS_CACHEFILENAMEAVAILABLE
:
897 case BINDSTATUS_DIRECTBIND
:
898 case BINDSTATUS_ACCEPTRANGES
:
899 case BINDSTATUS_DECODING
:
900 IInternetProtocolSink_ReportProgress(This
->protocol_sink
, status_code
, status_text
);
903 case BINDSTATUS_BEGINDOWNLOADDATA
:
904 IInternetProtocolSink_ReportData(This
->protocol_sink
, This
->bscf
, This
->progress
, This
->progress_max
);
907 case BINDSTATUS_MIMETYPEAVAILABLE
:
908 mime_available(This
, status_text
, FALSE
);
911 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE
:
912 mime_available(This
, status_text
, TRUE
);
916 FIXME("unsupported ulStatusCode %u\n", status_code
);
922 static HRESULT WINAPI
ProtocolSinkHandler_ReportData(IInternetProtocolSink
*iface
,
923 DWORD bscf
, ULONG progress
, ULONG progress_max
)
925 BindProtocol
*This
= impl_from_IInternetProtocolSinkHandler(iface
);
927 TRACE("(%p)->(%x %u %u)\n", This
, bscf
, progress
, progress_max
);
930 This
->progress
= progress
;
931 This
->progress_max
= progress_max
;
933 if(!This
->protocol_sink
)
936 if((This
->pi
& PI_MIMEVERIFICATION
) && !This
->reported_mime
) {
937 BYTE buf
[BUFFER_SIZE
];
944 if(is_apartment_thread(This
))
945 This
->continue_call
++;
946 hres
= IInternetProtocol_Read(This
->protocol
, buf
,
947 sizeof(buf
)-This
->buf_size
, &read
);
948 if(is_apartment_thread(This
))
949 This
->continue_call
--;
950 if(FAILED(hres
) && hres
!= E_PENDING
)
954 This
->buf
= heap_alloc(BUFFER_SIZE
);
956 return E_OUTOFMEMORY
;
957 }else if(read
+ This
->buf_size
> BUFFER_SIZE
) {
960 tmp
= heap_realloc(This
->buf
, read
+This
->buf_size
);
962 return E_OUTOFMEMORY
;
966 memcpy(This
->buf
+This
->buf_size
, buf
, read
);
967 This
->buf_size
+= read
;
968 }while(This
->buf_size
< MIME_TEST_SIZE
&& hres
== S_OK
);
970 if(This
->buf_size
< MIME_TEST_SIZE
&& hres
!= S_FALSE
)
973 bscf
= BSCF_FIRSTDATANOTIFICATION
;
975 bscf
|= BSCF_LASTDATANOTIFICATION
|BSCF_DATAFULLYAVAILABLE
;
977 if(!This
->reported_mime
) {
980 hres
= IUri_GetRawUri(This
->uri
, &raw_uri
);
984 hres
= FindMimeFromData(NULL
, raw_uri
, This
->buf
, min(This
->buf_size
, MIME_TEST_SIZE
),
985 This
->mime
, 0, &mime
, 0);
986 SysFreeString(raw_uri
);
990 heap_free(This
->mime
);
991 This
->mime
= heap_strdupW(mime
);
993 This
->reported_mime
= TRUE
;
994 if(This
->protocol_sink
)
995 IInternetProtocolSink_ReportProgress(This
->protocol_sink
, BINDSTATUS_MIMETYPEAVAILABLE
, This
->mime
);
999 if(!This
->protocol_sink
)
1002 return IInternetProtocolSink_ReportData(This
->protocol_sink
, bscf
, progress
, progress_max
);
1005 static HRESULT
handle_redirect(BindProtocol
*This
, const WCHAR
*url
)
1009 if(This
->redirect_callback
) {
1010 VARIANT_BOOL cancel
= VARIANT_FALSE
;
1011 IBindCallbackRedirect_Redirect(This
->redirect_callback
, url
, &cancel
);
1013 return INET_E_REDIRECT_FAILED
;
1016 if(This
->protocol_sink
) {
1017 hres
= IInternetProtocolSink_ReportProgress(This
->protocol_sink
, BINDSTATUS_REDIRECTING
, url
);
1022 IInternetProtocol_Terminate(This
->protocol
, 0); /* should this be done in StartEx? */
1023 release_protocol_handler(This
);
1025 return IInternetProtocolEx_Start(&This
->IInternetProtocolEx_iface
, url
, This
->protocol_sink
, This
->bind_info
, This
->pi
, 0);
1028 static HRESULT WINAPI
ProtocolSinkHandler_ReportResult(IInternetProtocolSink
*iface
,
1029 HRESULT hrResult
, DWORD dwError
, LPCWSTR szResult
)
1031 BindProtocol
*This
= impl_from_IInternetProtocolSinkHandler(iface
);
1033 TRACE("(%p)->(%08x %d %s)\n", This
, hrResult
, dwError
, debugstr_w(szResult
));
1035 if(hrResult
== INET_E_REDIRECT_FAILED
) {
1036 hrResult
= handle_redirect(This
, szResult
);
1037 if(hrResult
== S_OK
)
1042 if(This
->protocol_sink
)
1043 return IInternetProtocolSink_ReportResult(This
->protocol_sink
, hrResult
, dwError
, szResult
);
1047 static const IInternetProtocolSinkVtbl InternetProtocolSinkHandlerVtbl
= {
1048 ProtocolSinkHandler_QueryInterface
,
1049 ProtocolSinkHandler_AddRef
,
1050 ProtocolSinkHandler_Release
,
1051 ProtocolSinkHandler_Switch
,
1052 ProtocolSinkHandler_ReportProgress
,
1053 ProtocolSinkHandler_ReportData
,
1054 ProtocolSinkHandler_ReportResult
1057 static inline BindProtocol
*impl_from_IInternetBindInfo(IInternetBindInfo
*iface
)
1059 return CONTAINING_RECORD(iface
, BindProtocol
, IInternetBindInfo_iface
);
1062 static HRESULT WINAPI
BindInfo_QueryInterface(IInternetBindInfo
*iface
,
1063 REFIID riid
, void **ppv
)
1065 BindProtocol
*This
= impl_from_IInternetBindInfo(iface
);
1066 return IInternetProtocolEx_QueryInterface(&This
->IInternetProtocolEx_iface
, riid
, ppv
);
1069 static ULONG WINAPI
BindInfo_AddRef(IInternetBindInfo
*iface
)
1071 BindProtocol
*This
= impl_from_IInternetBindInfo(iface
);
1072 return IInternetProtocolEx_AddRef(&This
->IInternetProtocolEx_iface
);
1075 static ULONG WINAPI
BindInfo_Release(IInternetBindInfo
*iface
)
1077 BindProtocol
*This
= impl_from_IInternetBindInfo(iface
);
1078 return IInternetProtocolEx_Release(&This
->IInternetProtocolEx_iface
);
1081 static HRESULT WINAPI
BindInfo_GetBindInfo(IInternetBindInfo
*iface
,
1082 DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
1084 BindProtocol
*This
= impl_from_IInternetBindInfo(iface
);
1087 TRACE("(%p)->(%p %p)\n", This
, grfBINDF
, pbindinfo
);
1089 hres
= IInternetBindInfo_GetBindInfo(This
->bind_info
, grfBINDF
, pbindinfo
);
1091 WARN("GetBindInfo failed: %08x\n", hres
);
1095 if((pbindinfo
->dwOptions
& BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS
) && !This
->redirect_callback
) {
1096 IServiceProvider
*service_provider
;
1098 hres
= IInternetProtocolSink_QueryInterface(This
->protocol_sink
, &IID_IServiceProvider
, (void**)&service_provider
);
1099 if(SUCCEEDED(hres
)) {
1100 hres
= IServiceProvider_QueryService(service_provider
, &IID_IBindCallbackRedirect
, &IID_IBindCallbackRedirect
,
1101 (void**)&This
->redirect_callback
);
1102 IServiceProvider_Release(service_provider
);
1106 *grfBINDF
|= BINDF_FROMURLMON
;
1110 static HRESULT WINAPI
BindInfo_GetBindString(IInternetBindInfo
*iface
,
1111 ULONG ulStringType
, LPOLESTR
*ppwzStr
, ULONG cEl
, ULONG
*pcElFetched
)
1113 BindProtocol
*This
= impl_from_IInternetBindInfo(iface
);
1115 TRACE("(%p)->(%d %p %d %p)\n", This
, ulStringType
, ppwzStr
, cEl
, pcElFetched
);
1117 return IInternetBindInfo_GetBindString(This
->bind_info
, ulStringType
, ppwzStr
, cEl
, pcElFetched
);
1120 static const IInternetBindInfoVtbl InternetBindInfoVtbl
= {
1121 BindInfo_QueryInterface
,
1124 BindInfo_GetBindInfo
,
1125 BindInfo_GetBindString
1128 static inline BindProtocol
*impl_from_IInternetPriority(IInternetPriority
*iface
)
1130 return CONTAINING_RECORD(iface
, BindProtocol
, IInternetPriority_iface
);
1133 static HRESULT WINAPI
InternetPriority_QueryInterface(IInternetPriority
*iface
,
1134 REFIID riid
, void **ppv
)
1136 BindProtocol
*This
= impl_from_IInternetPriority(iface
);
1137 return IInternetProtocolEx_QueryInterface(&This
->IInternetProtocolEx_iface
, riid
, ppv
);
1140 static ULONG WINAPI
InternetPriority_AddRef(IInternetPriority
*iface
)
1142 BindProtocol
*This
= impl_from_IInternetPriority(iface
);
1143 return IInternetProtocolEx_AddRef(&This
->IInternetProtocolEx_iface
);
1146 static ULONG WINAPI
InternetPriority_Release(IInternetPriority
*iface
)
1148 BindProtocol
*This
= impl_from_IInternetPriority(iface
);
1149 return IInternetProtocolEx_Release(&This
->IInternetProtocolEx_iface
);
1152 static HRESULT WINAPI
InternetPriority_SetPriority(IInternetPriority
*iface
, LONG nPriority
)
1154 BindProtocol
*This
= impl_from_IInternetPriority(iface
);
1156 TRACE("(%p)->(%d)\n", This
, nPriority
);
1158 This
->priority
= nPriority
;
1162 static HRESULT WINAPI
InternetPriority_GetPriority(IInternetPriority
*iface
, LONG
*pnPriority
)
1164 BindProtocol
*This
= impl_from_IInternetPriority(iface
);
1166 TRACE("(%p)->(%p)\n", This
, pnPriority
);
1168 *pnPriority
= This
->priority
;
1172 static const IInternetPriorityVtbl InternetPriorityVtbl
= {
1173 InternetPriority_QueryInterface
,
1174 InternetPriority_AddRef
,
1175 InternetPriority_Release
,
1176 InternetPriority_SetPriority
,
1177 InternetPriority_GetPriority
1181 static inline BindProtocol
*impl_from_IInternetProtocolSink(IInternetProtocolSink
*iface
)
1183 return CONTAINING_RECORD(iface
, BindProtocol
, IInternetProtocolSink_iface
);
1186 static HRESULT WINAPI
BPInternetProtocolSink_QueryInterface(IInternetProtocolSink
*iface
,
1187 REFIID riid
, void **ppv
)
1189 BindProtocol
*This
= impl_from_IInternetProtocolSink(iface
);
1190 return IInternetProtocolEx_QueryInterface(&This
->IInternetProtocolEx_iface
, riid
, ppv
);
1193 static ULONG WINAPI
BPInternetProtocolSink_AddRef(IInternetProtocolSink
*iface
)
1195 BindProtocol
*This
= impl_from_IInternetProtocolSink(iface
);
1196 return IInternetProtocolEx_AddRef(&This
->IInternetProtocolEx_iface
);
1199 static ULONG WINAPI
BPInternetProtocolSink_Release(IInternetProtocolSink
*iface
)
1201 BindProtocol
*This
= impl_from_IInternetProtocolSink(iface
);
1202 return IInternetProtocolEx_Release(&This
->IInternetProtocolEx_iface
);
1206 task_header_t header
;
1210 static void switch_proc(BindProtocol
*bind
, task_header_t
*t
)
1212 switch_task_t
*task
= (switch_task_t
*)t
;
1214 IInternetProtocol_Continue(bind
->protocol_handler
, task
->data
);
1219 static HRESULT WINAPI
BPInternetProtocolSink_Switch(IInternetProtocolSink
*iface
,
1220 PROTOCOLDATA
*pProtocolData
)
1222 BindProtocol
*This
= impl_from_IInternetProtocolSink(iface
);
1225 TRACE("(%p)->(%p)\n", This
, pProtocolData
);
1227 TRACE("flags %x state %x data %p cb %u\n", pProtocolData
->grfFlags
, pProtocolData
->dwState
,
1228 pProtocolData
->pData
, pProtocolData
->cbData
);
1230 data
= heap_alloc(sizeof(PROTOCOLDATA
));
1232 return E_OUTOFMEMORY
;
1233 memcpy(data
, pProtocolData
, sizeof(PROTOCOLDATA
));
1235 if((This
->pi
&PI_APARTMENTTHREADED
&& pProtocolData
->grfFlags
&PI_FORCE_ASYNC
)
1236 || !do_direct_notif(This
)) {
1237 switch_task_t
*task
;
1239 task
= heap_alloc(sizeof(switch_task_t
));
1243 return E_OUTOFMEMORY
;
1248 push_task(This
, &task
->header
, switch_proc
);
1252 return IInternetProtocolSink_Switch(This
->protocol_sink_handler
, data
);
1256 task_header_t header
;
1260 } on_progress_task_t
;
1262 static void on_progress_proc(BindProtocol
*This
, task_header_t
*t
)
1264 on_progress_task_t
*task
= (on_progress_task_t
*)t
;
1266 IInternetProtocolSink_ReportProgress(This
->protocol_sink_handler
, task
->status_code
, task
->status_text
);
1268 heap_free(task
->status_text
);
1272 static HRESULT WINAPI
BPInternetProtocolSink_ReportProgress(IInternetProtocolSink
*iface
,
1273 ULONG ulStatusCode
, LPCWSTR szStatusText
)
1275 BindProtocol
*This
= impl_from_IInternetProtocolSink(iface
);
1277 TRACE("(%p)->(%u %s)\n", This
, ulStatusCode
, debugstr_w(szStatusText
));
1279 if(do_direct_notif(This
)) {
1280 IInternetProtocolSink_ReportProgress(This
->protocol_sink_handler
, ulStatusCode
, szStatusText
);
1282 on_progress_task_t
*task
;
1284 task
= heap_alloc(sizeof(on_progress_task_t
));
1286 task
->status_code
= ulStatusCode
;
1287 task
->status_text
= heap_strdupW(szStatusText
);
1289 push_task(This
, &task
->header
, on_progress_proc
);
1296 task_header_t header
;
1300 } report_data_task_t
;
1302 static void report_data_proc(BindProtocol
*This
, task_header_t
*t
)
1304 report_data_task_t
*task
= (report_data_task_t
*)t
;
1306 IInternetProtocolSink_ReportData(This
->protocol_sink_handler
,
1307 task
->bscf
, task
->progress
, task
->progress_max
);
1312 static HRESULT WINAPI
BPInternetProtocolSink_ReportData(IInternetProtocolSink
*iface
,
1313 DWORD grfBSCF
, ULONG ulProgress
, ULONG ulProgressMax
)
1315 BindProtocol
*This
= impl_from_IInternetProtocolSink(iface
);
1317 TRACE("(%p)->(%x %u %u)\n", This
, grfBSCF
, ulProgress
, ulProgressMax
);
1319 if(!This
->protocol_sink
)
1322 if(!do_direct_notif(This
)) {
1323 report_data_task_t
*task
;
1325 task
= heap_alloc(sizeof(report_data_task_t
));
1327 return E_OUTOFMEMORY
;
1329 task
->bscf
= grfBSCF
;
1330 task
->progress
= ulProgress
;
1331 task
->progress_max
= ulProgressMax
;
1333 push_task(This
, &task
->header
, report_data_proc
);
1337 return IInternetProtocolSink_ReportData(This
->protocol_sink_handler
,
1338 grfBSCF
, ulProgress
, ulProgressMax
);
1342 task_header_t header
;
1347 } report_result_task_t
;
1349 static void report_result_proc(BindProtocol
*This
, task_header_t
*t
)
1351 report_result_task_t
*task
= (report_result_task_t
*)t
;
1353 IInternetProtocolSink_ReportResult(This
->protocol_sink_handler
, task
->hres
, task
->err
, task
->str
);
1355 heap_free(task
->str
);
1359 static HRESULT WINAPI
BPInternetProtocolSink_ReportResult(IInternetProtocolSink
*iface
,
1360 HRESULT hrResult
, DWORD dwError
, LPCWSTR szResult
)
1362 BindProtocol
*This
= impl_from_IInternetProtocolSink(iface
);
1364 TRACE("(%p)->(%08x %d %s)\n", This
, hrResult
, dwError
, debugstr_w(szResult
));
1366 if(!This
->protocol_sink
)
1368 This
->reported_result
= TRUE
;
1370 if(!do_direct_notif(This
)) {
1371 report_result_task_t
*task
;
1373 task
= heap_alloc(sizeof(report_result_task_t
));
1375 return E_OUTOFMEMORY
;
1377 task
->hres
= hrResult
;
1378 task
->err
= dwError
;
1379 task
->str
= heap_strdupW(szResult
);
1381 push_task(This
, &task
->header
, report_result_proc
);
1385 return IInternetProtocolSink_ReportResult(This
->protocol_sink_handler
, hrResult
, dwError
, szResult
);
1388 static const IInternetProtocolSinkVtbl InternetProtocolSinkVtbl
= {
1389 BPInternetProtocolSink_QueryInterface
,
1390 BPInternetProtocolSink_AddRef
,
1391 BPInternetProtocolSink_Release
,
1392 BPInternetProtocolSink_Switch
,
1393 BPInternetProtocolSink_ReportProgress
,
1394 BPInternetProtocolSink_ReportData
,
1395 BPInternetProtocolSink_ReportResult
1398 static inline BindProtocol
*impl_from_IServiceProvider(IServiceProvider
*iface
)
1400 return CONTAINING_RECORD(iface
, BindProtocol
, IServiceProvider_iface
);
1403 static HRESULT WINAPI
BPServiceProvider_QueryInterface(IServiceProvider
*iface
,
1404 REFIID riid
, void **ppv
)
1406 BindProtocol
*This
= impl_from_IServiceProvider(iface
);
1407 return IInternetProtocolEx_QueryInterface(&This
->IInternetProtocolEx_iface
, riid
, ppv
);
1410 static ULONG WINAPI
BPServiceProvider_AddRef(IServiceProvider
*iface
)
1412 BindProtocol
*This
= impl_from_IServiceProvider(iface
);
1413 return IInternetProtocolEx_AddRef(&This
->IInternetProtocolEx_iface
);
1416 static ULONG WINAPI
BPServiceProvider_Release(IServiceProvider
*iface
)
1418 BindProtocol
*This
= impl_from_IServiceProvider(iface
);
1419 return IInternetProtocolEx_Release(&This
->IInternetProtocolEx_iface
);
1422 static HRESULT WINAPI
BPServiceProvider_QueryService(IServiceProvider
*iface
,
1423 REFGUID guidService
, REFIID riid
, void **ppv
)
1425 BindProtocol
*This
= impl_from_IServiceProvider(iface
);
1427 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_guid(guidService
), debugstr_guid(riid
), ppv
);
1429 if(!This
->service_provider
)
1430 return E_NOINTERFACE
;
1432 return IServiceProvider_QueryService(This
->service_provider
, guidService
, riid
, ppv
);
1435 static const IServiceProviderVtbl ServiceProviderVtbl
= {
1436 BPServiceProvider_QueryInterface
,
1437 BPServiceProvider_AddRef
,
1438 BPServiceProvider_Release
,
1439 BPServiceProvider_QueryService
1442 HRESULT
create_binding_protocol(BindProtocol
**protocol
)
1444 BindProtocol
*ret
= heap_alloc_zero(sizeof(BindProtocol
));
1446 ret
->IInternetProtocolEx_iface
.lpVtbl
= &BindProtocolVtbl
;
1447 ret
->IInternetBindInfo_iface
.lpVtbl
= &InternetBindInfoVtbl
;
1448 ret
->IInternetPriority_iface
.lpVtbl
= &InternetPriorityVtbl
;
1449 ret
->IServiceProvider_iface
.lpVtbl
= &ServiceProviderVtbl
;
1450 ret
->IInternetProtocolSink_iface
.lpVtbl
= &InternetProtocolSinkVtbl
;
1452 ret
->default_protocol_handler
.IInternetProtocol_iface
.lpVtbl
= &InternetProtocolHandlerVtbl
;
1453 ret
->default_protocol_handler
.IInternetProtocolSink_iface
.lpVtbl
= &InternetProtocolSinkHandlerVtbl
;
1456 ret
->apartment_thread
= GetCurrentThreadId();
1457 ret
->notif_hwnd
= get_notif_hwnd();
1458 ret
->protocol_handler
= &ret
->default_protocol_handler
.IInternetProtocol_iface
;
1459 ret
->protocol_sink_handler
= &ret
->default_protocol_handler
.IInternetProtocolSink_iface
;
1460 InitializeCriticalSection(&ret
->section
);
1461 ret
->section
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": BindProtocol.section");
1463 URLMON_LockModule();