2 * Copyright 2005 Jacek Caban
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/debug.h"
33 #include "mshtml_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
37 /********************************************************************
38 * common ProtocolFactory implementation
42 IInternetProtocolInfo IInternetProtocolInfo_iface
;
43 IClassFactory IClassFactory_iface
;
46 static inline ProtocolFactory
*impl_from_IInternetProtocolInfo(IInternetProtocolInfo
*iface
)
48 return CONTAINING_RECORD(iface
, ProtocolFactory
, IInternetProtocolInfo_iface
);
51 static HRESULT WINAPI
InternetProtocolInfo_QueryInterface(IInternetProtocolInfo
*iface
, REFIID riid
, void **ppv
)
53 ProtocolFactory
*This
= impl_from_IInternetProtocolInfo(iface
);
56 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
57 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
58 *ppv
= &This
->IInternetProtocolInfo_iface
;
59 }else if(IsEqualGUID(&IID_IInternetProtocolInfo
, riid
)) {
60 TRACE("(%p)->(IID_IInternetProtocolInfo %p)\n", This
, ppv
);
61 *ppv
= &This
->IInternetProtocolInfo_iface
;
62 }else if(IsEqualGUID(&IID_IClassFactory
, riid
)) {
63 TRACE("(%p)->(IID_IClassFactory %p)\n", This
, ppv
);
64 *ppv
= &This
->IClassFactory_iface
;
68 WARN("unknown interface %s\n", debugstr_guid(riid
));
72 IInternetProtocolInfo_AddRef(iface
);
76 static ULONG WINAPI
InternetProtocolInfo_AddRef(IInternetProtocolInfo
*iface
)
78 TRACE("(%p)\n", iface
);
82 static ULONG WINAPI
InternetProtocolInfo_Release(IInternetProtocolInfo
*iface
)
84 TRACE("(%p)\n", iface
);
88 static HRESULT WINAPI
InternetProtocolInfo_CombineUrl(IInternetProtocolInfo
*iface
,
89 LPCWSTR pwzBaseUrl
, LPCWSTR pwzRelativeUrl
, DWORD dwCombineFlags
, LPWSTR pwzResult
,
90 DWORD cchResult
, DWORD
* pcchResult
, DWORD dwReserved
)
92 TRACE("%p)->(%s %s %08x %p %d %p %d)\n", iface
, debugstr_w(pwzBaseUrl
),
93 debugstr_w(pwzRelativeUrl
), dwCombineFlags
, pwzResult
, cchResult
,
94 pcchResult
, dwReserved
);
96 return INET_E_USE_DEFAULT_PROTOCOLHANDLER
;
99 static HRESULT WINAPI
InternetProtocolInfo_CompareUrl(IInternetProtocolInfo
*iface
, LPCWSTR pwzUrl1
,
100 LPCWSTR pwzUrl2
, DWORD dwCompareFlags
)
102 TRACE("%p)->(%s %s %08x)\n", iface
, debugstr_w(pwzUrl1
), debugstr_w(pwzUrl2
), dwCompareFlags
);
106 static inline ProtocolFactory
*impl_from_IClassFactory(IClassFactory
*iface
)
108 return CONTAINING_RECORD(iface
, ProtocolFactory
, IClassFactory_iface
);
111 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
113 ProtocolFactory
*This
= impl_from_IClassFactory(iface
);
114 return IInternetProtocolInfo_QueryInterface(&This
->IInternetProtocolInfo_iface
, riid
, ppv
);
117 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
119 ProtocolFactory
*This
= impl_from_IClassFactory(iface
);
120 return IInternetProtocolInfo_AddRef(&This
->IInternetProtocolInfo_iface
);
123 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
125 ProtocolFactory
*This
= impl_from_IClassFactory(iface
);
126 return IInternetProtocolInfo_Release(&This
->IInternetProtocolInfo_iface
);
129 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL dolock
)
131 TRACE("(%p)->(%x)\n", iface
, dolock
);
135 /********************************************************************
136 * AboutProtocol implementation
140 IInternetProtocol IInternetProtocol_iface
;
151 static inline AboutProtocol
*AboutProtocol_from_IInternetProtocol(IInternetProtocol
*iface
)
153 return CONTAINING_RECORD(iface
, AboutProtocol
, IInternetProtocol_iface
);
156 static HRESULT WINAPI
AboutProtocol_QueryInterface(IInternetProtocol
*iface
, REFIID riid
, void **ppv
)
158 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
162 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
163 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
165 return IUnknown_QueryInterface(This
->pUnkOuter
, riid
, ppv
);
166 *ppv
= &This
->IInternetProtocol_iface
;
167 }else if(IsEqualGUID(&IID_IInternetProtocolRoot
, riid
)) {
168 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", iface
, ppv
);
169 *ppv
= &This
->IInternetProtocol_iface
;
170 }else if(IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
171 TRACE("(%p)->(IID_IInternetProtocol %p)\n", iface
, ppv
);
172 *ppv
= &This
->IInternetProtocol_iface
;
173 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
)) {
174 FIXME("IServiceProvider is not implemented\n");
175 return E_NOINTERFACE
;
179 TRACE("unknown interface %s\n", debugstr_guid(riid
));
180 return E_NOINTERFACE
;
183 IInternetProtocol_AddRef(iface
);
187 static ULONG WINAPI
AboutProtocol_AddRef(IInternetProtocol
*iface
)
189 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
190 ULONG ref
= InterlockedIncrement(&This
->ref
);
191 TRACE("(%p) ref=%d\n", iface
, ref
);
192 return This
->pUnkOuter
? IUnknown_AddRef(This
->pUnkOuter
) : ref
;
195 static ULONG WINAPI
AboutProtocol_Release(IInternetProtocol
*iface
)
197 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
198 IUnknown
*pUnkOuter
= This
->pUnkOuter
;
199 ULONG ref
= InterlockedDecrement(&This
->ref
);
201 TRACE("(%p) ref=%x\n", iface
, ref
);
204 heap_free(This
->data
);
208 return pUnkOuter
? IUnknown_Release(pUnkOuter
) : ref
;
211 static HRESULT WINAPI
AboutProtocol_Start(IInternetProtocol
*iface
, LPCWSTR szUrl
,
212 IInternetProtocolSink
* pOIProtSink
, IInternetBindInfo
* pOIBindInfo
,
213 DWORD grfPI
, HANDLE_PTR dwReserved
)
215 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
223 static const WCHAR html_begin
[] = {0xfeff,'<','H','T','M','L','>',0};
224 static const WCHAR html_end
[] = {'<','/','H','T','M','L','>',0};
225 static const WCHAR wszBlank
[] = {'b','l','a','n','k',0};
226 static const WCHAR wszAbout
[] = {'a','b','o','u','t',':'};
227 static const WCHAR wszTextHtml
[] = {'t','e','x','t','/','h','t','m','l',0};
230 * the about protocol seems not to work as I would expect. It creates html document
231 * for a given url, eg. about:some_text -> <HTML>some_text</HTML> except for the case when
232 * some_text = "blank", when document is blank (<HTML></HMTL>). The same happens
233 * when the url does not have "about:" in the beginning.
236 TRACE("(%p)->(%s %p %p %08x %lx)\n", This
, debugstr_w(szUrl
), pOIProtSink
,
237 pOIBindInfo
, grfPI
, dwReserved
);
239 memset(&bindinfo
, 0, sizeof(bindinfo
));
240 bindinfo
.cbSize
= sizeof(BINDINFO
);
241 hres
= IInternetBindInfo_GetBindInfo(pOIBindInfo
, &grfBINDF
, &bindinfo
);
244 ReleaseBindInfo(&bindinfo
);
246 TRACE("bindf %x\n", grfBINDF
);
248 if(strlenW(szUrl
)>=sizeof(wszAbout
)/sizeof(WCHAR
) && !memcmp(wszAbout
, szUrl
, sizeof(wszAbout
))) {
249 text
= szUrl
+ sizeof(wszAbout
)/sizeof(WCHAR
);
250 if(!strcmpW(wszBlank
, text
))
254 data_len
= sizeof(html_begin
)+sizeof(html_end
)-sizeof(WCHAR
)
255 + (text
? strlenW(text
)*sizeof(WCHAR
) : 0);
256 data
= heap_alloc(data_len
);
258 return E_OUTOFMEMORY
;
260 heap_free(This
->data
);
262 This
->data_len
= data_len
;
264 memcpy(This
->data
, html_begin
, sizeof(html_begin
));
266 strcatW((LPWSTR
)This
->data
, text
);
267 strcatW((LPWSTR
)This
->data
, html_end
);
271 IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_MIMETYPEAVAILABLE
, wszTextHtml
);
273 IInternetProtocolSink_ReportData(pOIProtSink
,
274 BSCF_FIRSTDATANOTIFICATION
| BSCF_LASTDATANOTIFICATION
| BSCF_DATAFULLYAVAILABLE
,
275 This
->data_len
, This
->data_len
);
277 IInternetProtocolSink_ReportResult(pOIProtSink
, S_OK
, 0, NULL
);
282 static HRESULT WINAPI
AboutProtocol_Continue(IInternetProtocol
*iface
, PROTOCOLDATA
* pProtocolData
)
284 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
285 FIXME("(%p)->(%p)\n", This
, pProtocolData
);
289 static HRESULT WINAPI
AboutProtocol_Abort(IInternetProtocol
*iface
, HRESULT hrReason
,
292 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
293 FIXME("(%p)->(%08x %08x)\n", This
, hrReason
, dwOptions
);
297 static HRESULT WINAPI
AboutProtocol_Terminate(IInternetProtocol
*iface
, DWORD dwOptions
)
299 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
300 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
304 static HRESULT WINAPI
AboutProtocol_Suspend(IInternetProtocol
*iface
)
306 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
307 FIXME("(%p)\n", This
);
311 static HRESULT WINAPI
AboutProtocol_Resume(IInternetProtocol
*iface
)
313 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
314 FIXME("(%p)\n", This
);
318 static HRESULT WINAPI
AboutProtocol_Read(IInternetProtocol
*iface
, void* pv
, ULONG cb
, ULONG
* pcbRead
)
320 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
322 TRACE("(%p)->(%p %u %p)\n", This
, pv
, cb
, pcbRead
);
327 *pcbRead
= (cb
> This
->data_len
-This
->cur
? This
->data_len
-This
->cur
: cb
);
332 memcpy(pv
, This
->data
+This
->cur
, *pcbRead
);
333 This
->cur
+= *pcbRead
;
338 static HRESULT WINAPI
AboutProtocol_Seek(IInternetProtocol
*iface
, LARGE_INTEGER dlibMove
,
339 DWORD dwOrigin
, ULARGE_INTEGER
* plibNewPosition
)
341 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
342 FIXME("(%p)->(%d %d %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
346 static HRESULT WINAPI
AboutProtocol_LockRequest(IInternetProtocol
*iface
, DWORD dwOptions
)
348 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
350 TRACE("(%p)->(%d)\n", This
, dwOptions
);
355 static HRESULT WINAPI
AboutProtocol_UnlockRequest(IInternetProtocol
*iface
)
357 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
359 TRACE("(%p)\n", This
);
364 static const IInternetProtocolVtbl AboutProtocolVtbl
= {
365 AboutProtocol_QueryInterface
,
366 AboutProtocol_AddRef
,
367 AboutProtocol_Release
,
369 AboutProtocol_Continue
,
371 AboutProtocol_Terminate
,
372 AboutProtocol_Suspend
,
373 AboutProtocol_Resume
,
376 AboutProtocol_LockRequest
,
377 AboutProtocol_UnlockRequest
380 static HRESULT WINAPI
AboutProtocolFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
,
381 REFIID riid
, void **ppv
)
386 TRACE("(%p)->(%p %s %p)\n", iface
, pUnkOuter
, debugstr_guid(riid
), ppv
);
388 ret
= heap_alloc(sizeof(AboutProtocol
));
389 ret
->IInternetProtocol_iface
.lpVtbl
= &AboutProtocolVtbl
;
395 ret
->pUnkOuter
= pUnkOuter
;
399 if(IsEqualGUID(&IID_IUnknown
, riid
))
400 *ppv
= &ret
->IInternetProtocol_iface
;
404 hres
= IInternetProtocol_QueryInterface(&ret
->IInternetProtocol_iface
, riid
, ppv
);
413 static HRESULT WINAPI
AboutProtocolInfo_ParseUrl(IInternetProtocolInfo
*iface
, LPCWSTR pwzUrl
,
414 PARSEACTION ParseAction
, DWORD dwParseFlags
, LPWSTR pwzResult
, DWORD cchResult
,
415 DWORD
* pcchResult
, DWORD dwReserved
)
417 TRACE("%p)->(%s %d %08x %p %d %p %d)\n", iface
, debugstr_w(pwzUrl
), ParseAction
,
418 dwParseFlags
, pwzResult
, cchResult
, pcchResult
, dwReserved
);
420 if(ParseAction
== PARSE_SECURITY_URL
) {
421 unsigned int len
= strlenW(pwzUrl
)+1;
427 memcpy(pwzResult
, pwzUrl
, len
*sizeof(WCHAR
));
431 if(ParseAction
== PARSE_DOMAIN
) {
436 *pcchResult
= strlenW(pwzUrl
)+1;
442 return INET_E_DEFAULT_ACTION
;
445 static HRESULT WINAPI
AboutProtocolInfo_QueryInfo(IInternetProtocolInfo
*iface
, LPCWSTR pwzUrl
,
446 QUERYOPTION QueryOption
, DWORD dwQueryFlags
, LPVOID pBuffer
, DWORD cbBuffer
, DWORD
* pcbBuf
,
449 TRACE("%p)->(%s %08x %08x %p %d %p %d)\n", iface
, debugstr_w(pwzUrl
), QueryOption
, dwQueryFlags
, pBuffer
,
450 cbBuffer
, pcbBuf
, dwReserved
);
452 switch(QueryOption
) {
453 case QUERY_CAN_NAVIGATE
:
454 return INET_E_USE_DEFAULT_PROTOCOLHANDLER
;
456 case QUERY_USES_NETWORK
:
457 if(!pBuffer
|| cbBuffer
< sizeof(DWORD
))
460 *(DWORD
*)pBuffer
= 0;
462 *pcbBuf
= sizeof(DWORD
);
466 case QUERY_IS_CACHED
:
467 FIXME("Unsupported option QUERY_IS_CACHED\n");
469 case QUERY_IS_INSTALLEDENTRY
:
470 FIXME("Unsupported option QUERY_IS_INSTALLEDENTRY\n");
472 case QUERY_IS_CACHED_OR_MAPPED
:
473 FIXME("Unsupported option QUERY_IS_CACHED_OR_MAPPED\n");
475 case QUERY_IS_SECURE
:
476 FIXME("Unsupported option QUERY_IS_SECURE\n");
479 FIXME("Unsupported option QUERY_IS_SAFE\n");
481 case QUERY_USES_HISTORYFOLDER
:
482 FIXME("Unsupported option QUERY_USES_HISTORYFOLDER\n");
484 case QUERY_IS_CACHED_AND_USABLE_OFFLINE
:
485 FIXME("Unsupported option QUERY_IS_CACHED_AND_USABLE_OFFLINE\n");
494 static const IInternetProtocolInfoVtbl AboutProtocolInfoVtbl
= {
495 InternetProtocolInfo_QueryInterface
,
496 InternetProtocolInfo_AddRef
,
497 InternetProtocolInfo_Release
,
498 AboutProtocolInfo_ParseUrl
,
499 InternetProtocolInfo_CombineUrl
,
500 InternetProtocolInfo_CompareUrl
,
501 AboutProtocolInfo_QueryInfo
504 static const IClassFactoryVtbl AboutProtocolFactoryVtbl
= {
505 ClassFactory_QueryInterface
,
507 ClassFactory_Release
,
508 AboutProtocolFactory_CreateInstance
,
509 ClassFactory_LockServer
512 static ProtocolFactory AboutProtocolFactory
= {
513 { &AboutProtocolInfoVtbl
},
514 { &AboutProtocolFactoryVtbl
}
517 /********************************************************************
518 * ResProtocol implementation
522 IInternetProtocol IInternetProtocol_iface
;
532 static inline ResProtocol
*ResProtocol_from_IInternetProtocol(IInternetProtocol
*iface
)
534 return CONTAINING_RECORD(iface
, ResProtocol
, IInternetProtocol_iface
);
537 static HRESULT WINAPI
ResProtocol_QueryInterface(IInternetProtocol
*iface
, REFIID riid
, void **ppv
)
539 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
543 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
544 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
546 return IUnknown_QueryInterface(This
->pUnkOuter
, &IID_IUnknown
, ppv
);
547 *ppv
= &This
->IInternetProtocol_iface
;
548 }else if(IsEqualGUID(&IID_IInternetProtocolRoot
, riid
)) {
549 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", iface
, ppv
);
550 *ppv
= &This
->IInternetProtocol_iface
;
551 }else if(IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
552 TRACE("(%p)->(IID_IInternetProtocol %p)\n", iface
, ppv
);
553 *ppv
= &This
->IInternetProtocol_iface
;
554 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
)) {
555 FIXME("IServiceProvider is not implemented\n");
556 return E_NOINTERFACE
;
560 TRACE("unknown interface %s\n", debugstr_guid(riid
));
561 return E_NOINTERFACE
;
564 IInternetProtocol_AddRef(iface
);
568 static ULONG WINAPI
ResProtocol_AddRef(IInternetProtocol
*iface
)
570 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
571 ULONG ref
= InterlockedIncrement(&This
->ref
);
572 TRACE("(%p) ref=%d\n", iface
, ref
);
573 return This
->pUnkOuter
? IUnknown_AddRef(This
->pUnkOuter
) : ref
;
576 static ULONG WINAPI
ResProtocol_Release(IInternetProtocol
*iface
)
578 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
579 IUnknown
*pUnkOuter
= This
->pUnkOuter
;
580 ULONG ref
= InterlockedDecrement(&This
->ref
);
582 TRACE("(%p) ref=%x\n", iface
, ref
);
585 heap_free(This
->data
);
589 return pUnkOuter
? IUnknown_Release(pUnkOuter
) : ref
;
592 static HRESULT WINAPI
ResProtocol_Start(IInternetProtocol
*iface
, LPCWSTR szUrl
,
593 IInternetProtocolSink
* pOIProtSink
, IInternetBindInfo
* pOIBindInfo
,
594 DWORD grfPI
, HANDLE_PTR dwReserved
)
596 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
597 WCHAR
*url_dll
, *url_file
, *url
, *mime
, *res_type
= (LPWSTR
)RT_HTML
, *ptr
;
598 DWORD grfBINDF
= 0, len
;
604 static const WCHAR wszRes
[] = {'r','e','s',':','/','/'};
606 TRACE("(%p)->(%s %p %p %08x %lx)\n", This
, debugstr_w(szUrl
), pOIProtSink
,
607 pOIBindInfo
, grfPI
, dwReserved
);
609 memset(&bindinfo
, 0, sizeof(bindinfo
));
610 bindinfo
.cbSize
= sizeof(BINDINFO
);
611 hres
= IInternetBindInfo_GetBindInfo(pOIBindInfo
, &grfBINDF
, &bindinfo
);
614 ReleaseBindInfo(&bindinfo
);
616 len
= strlenW(szUrl
)+16;
617 url
= heap_alloc(len
*sizeof(WCHAR
));
618 hres
= CoInternetParseUrl(szUrl
, PARSE_ENCODE
, 0, url
, len
, &len
, 0);
620 WARN("CoInternetParseUrl failed: %08x\n", hres
);
622 IInternetProtocolSink_ReportResult(pOIProtSink
, hres
, 0, NULL
);
626 if(len
< sizeof(wszRes
)/sizeof(wszRes
[0]) || memcmp(url
, wszRes
, sizeof(wszRes
))) {
627 WARN("Wrong protocol of url: %s\n", debugstr_w(url
));
628 IInternetProtocolSink_ReportResult(pOIProtSink
, E_INVALIDARG
, 0, NULL
);
633 url_dll
= url
+ sizeof(wszRes
)/sizeof(wszRes
[0]);
634 if(!(res_type
= strchrW(url_dll
, '/'))) {
635 WARN("wrong url: %s\n", debugstr_w(url
));
636 IInternetProtocolSink_ReportResult(pOIProtSink
, MK_E_SYNTAX
, 0, NULL
);
642 if ((url_file
= strchrW(res_type
, '/'))) {
646 res_type
= (LPWSTR
)RT_HTML
;
649 /* Ignore query and hash parts. */
650 if((ptr
= strchrW(url_file
, '?')))
652 if(*url_file
&& (ptr
= strchrW(url_file
+1, '#')))
655 hdll
= LoadLibraryExW(url_dll
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
657 WARN("Could not open dll: %s\n", debugstr_w(url_dll
));
658 IInternetProtocolSink_ReportResult(pOIProtSink
, HRESULT_FROM_WIN32(GetLastError()), 0, NULL
);
660 return HRESULT_FROM_WIN32(GetLastError());
663 TRACE("trying to find resource type %s, name %s\n", debugstr_w(res_type
), debugstr_w(url_file
));
665 src
= FindResourceW(hdll
, url_file
, res_type
);
667 LPWSTR endpoint
= NULL
;
668 DWORD file_id
= strtolW(url_file
, &endpoint
, 10);
669 if(endpoint
== url_file
+strlenW(url_file
))
670 src
= FindResourceW(hdll
, MAKEINTRESOURCEW(file_id
), res_type
);
673 WARN("Could not find resource\n");
674 IInternetProtocolSink_ReportResult(pOIProtSink
,
675 HRESULT_FROM_WIN32(GetLastError()), 0, NULL
);
677 return HRESULT_FROM_WIN32(GetLastError());
682 WARN("data already loaded\n");
683 heap_free(This
->data
);
686 This
->data_len
= SizeofResource(hdll
, src
);
687 This
->data
= heap_alloc(This
->data_len
);
688 memcpy(This
->data
, LoadResource(hdll
, src
), This
->data_len
);
693 hres
= FindMimeFromData(NULL
, url_file
, This
->data
, This
->data_len
, NULL
, 0, &mime
, 0);
695 if(SUCCEEDED(hres
)) {
696 IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_MIMETYPEAVAILABLE
, mime
);
700 IInternetProtocolSink_ReportData(pOIProtSink
,
701 BSCF_FIRSTDATANOTIFICATION
| BSCF_LASTDATANOTIFICATION
| BSCF_DATAFULLYAVAILABLE
,
702 This
->data_len
, This
->data_len
);
704 IInternetProtocolSink_ReportResult(pOIProtSink
, S_OK
, 0, NULL
);
709 static HRESULT WINAPI
ResProtocol_Continue(IInternetProtocol
*iface
, PROTOCOLDATA
* pProtocolData
)
711 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
712 FIXME("(%p)->(%p)\n", This
, pProtocolData
);
716 static HRESULT WINAPI
ResProtocol_Abort(IInternetProtocol
*iface
, HRESULT hrReason
,
719 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
720 FIXME("(%p)->(%08x %08x)\n", This
, hrReason
, dwOptions
);
724 static HRESULT WINAPI
ResProtocol_Terminate(IInternetProtocol
*iface
, DWORD dwOptions
)
726 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
728 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
730 /* test show that we don't have to do anything here */
734 static HRESULT WINAPI
ResProtocol_Suspend(IInternetProtocol
*iface
)
736 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
737 FIXME("(%p)\n", This
);
741 static HRESULT WINAPI
ResProtocol_Resume(IInternetProtocol
*iface
)
743 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
744 FIXME("(%p)\n", This
);
748 static HRESULT WINAPI
ResProtocol_Read(IInternetProtocol
*iface
, void* pv
, ULONG cb
, ULONG
* pcbRead
)
750 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
752 TRACE("(%p)->(%p %u %p)\n", This
, pv
, cb
, pcbRead
);
757 *pcbRead
= (cb
> This
->data_len
-This
->cur
? This
->data_len
-This
->cur
: cb
);
762 memcpy(pv
, This
->data
+This
->cur
, *pcbRead
);
763 This
->cur
+= *pcbRead
;
768 static HRESULT WINAPI
ResProtocol_Seek(IInternetProtocol
*iface
, LARGE_INTEGER dlibMove
,
769 DWORD dwOrigin
, ULARGE_INTEGER
* plibNewPosition
)
771 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
772 FIXME("(%p)->(%d %d %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
776 static HRESULT WINAPI
ResProtocol_LockRequest(IInternetProtocol
*iface
, DWORD dwOptions
)
778 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
780 TRACE("(%p)->(%d)\n", This
, dwOptions
);
782 /* test show that we don't have to do anything here */
786 static HRESULT WINAPI
ResProtocol_UnlockRequest(IInternetProtocol
*iface
)
788 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
790 TRACE("(%p)\n", This
);
792 /* test show that we don't have to do anything here */
796 static const IInternetProtocolVtbl ResProtocolVtbl
= {
797 ResProtocol_QueryInterface
,
801 ResProtocol_Continue
,
803 ResProtocol_Terminate
,
808 ResProtocol_LockRequest
,
809 ResProtocol_UnlockRequest
812 static HRESULT WINAPI
ResProtocolFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
,
813 REFIID riid
, void **ppv
)
818 TRACE("(%p)->(%p %s %p)\n", iface
, pUnkOuter
, debugstr_guid(riid
), ppv
);
820 ret
= heap_alloc(sizeof(ResProtocol
));
821 ret
->IInternetProtocol_iface
.lpVtbl
= &ResProtocolVtbl
;
826 ret
->pUnkOuter
= pUnkOuter
;
830 if(IsEqualGUID(&IID_IUnknown
, riid
))
831 *ppv
= &ret
->IInternetProtocol_iface
;
835 hres
= IInternetProtocol_QueryInterface(&ret
->IInternetProtocol_iface
, riid
, ppv
);
844 static HRESULT WINAPI
ResProtocolInfo_ParseUrl(IInternetProtocolInfo
*iface
, LPCWSTR pwzUrl
,
845 PARSEACTION ParseAction
, DWORD dwParseFlags
, LPWSTR pwzResult
, DWORD cchResult
,
846 DWORD
* pcchResult
, DWORD dwReserved
)
848 TRACE("%p)->(%s %d %x %p %d %p %d)\n", iface
, debugstr_w(pwzUrl
), ParseAction
,
849 dwParseFlags
, pwzResult
, cchResult
, pcchResult
, dwReserved
);
851 if(ParseAction
== PARSE_SECURITY_URL
) {
852 WCHAR file_part
[MAX_PATH
], full_path
[MAX_PATH
];
856 static const WCHAR wszFile
[] = {'f','i','l','e',':','/','/'};
857 static const WCHAR wszRes
[] = {'r','e','s',':','/','/'};
859 if(strlenW(pwzUrl
) <= sizeof(wszRes
)/sizeof(WCHAR
) || memcmp(pwzUrl
, wszRes
, sizeof(wszRes
)))
862 ptr
= strchrW(pwzUrl
+ sizeof(wszRes
)/sizeof(WCHAR
), '/');
866 len
= ptr
- (pwzUrl
+ sizeof(wszRes
)/sizeof(WCHAR
));
867 if(len
>= sizeof(file_part
)/sizeof(WCHAR
)) {
868 FIXME("Too long URL\n");
872 memcpy(file_part
, pwzUrl
+ sizeof(wszRes
)/sizeof(WCHAR
), len
*sizeof(WCHAR
));
875 len
= SearchPathW(NULL
, file_part
, NULL
, sizeof(full_path
)/sizeof(WCHAR
), full_path
, NULL
);
879 /* SearchPath does not work well with winelib files (like our test executable),
880 * so we also try to load the library here */
881 module
= LoadLibraryExW(file_part
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
883 WARN("Could not find file %s\n", debugstr_w(file_part
));
887 len
= GetModuleFileNameW(module
, full_path
, sizeof(full_path
)/sizeof(WCHAR
));
893 size
= sizeof(wszFile
)/sizeof(WCHAR
) + len
+ 1;
899 memcpy(pwzResult
, wszFile
, sizeof(wszFile
));
900 memcpy(pwzResult
+ sizeof(wszFile
)/sizeof(WCHAR
), full_path
, (len
+1)*sizeof(WCHAR
));
904 if(ParseAction
== PARSE_DOMAIN
) {
909 *pcchResult
= strlenW(pwzUrl
)+1;
915 return INET_E_DEFAULT_ACTION
;
918 static HRESULT WINAPI
ResProtocolInfo_QueryInfo(IInternetProtocolInfo
*iface
, LPCWSTR pwzUrl
,
919 QUERYOPTION QueryOption
, DWORD dwQueryFlags
, LPVOID pBuffer
, DWORD cbBuffer
, DWORD
* pcbBuf
,
922 TRACE("%p)->(%s %08x %08x %p %d %p %d)\n", iface
, debugstr_w(pwzUrl
), QueryOption
, dwQueryFlags
, pBuffer
,
923 cbBuffer
, pcbBuf
, dwReserved
);
925 switch(QueryOption
) {
926 case QUERY_USES_NETWORK
:
927 if(!pBuffer
|| cbBuffer
< sizeof(DWORD
))
930 *(DWORD
*)pBuffer
= 0;
932 *pcbBuf
= sizeof(DWORD
);
935 case QUERY_IS_SECURE
:
936 FIXME("QUERY_IS_SECURE not supported\n");
939 FIXME("QUERY_IS_SAFE not supported\n");
942 return INET_E_USE_DEFAULT_PROTOCOLHANDLER
;
948 static const IInternetProtocolInfoVtbl ResProtocolInfoVtbl
= {
949 InternetProtocolInfo_QueryInterface
,
950 InternetProtocolInfo_AddRef
,
951 InternetProtocolInfo_Release
,
952 ResProtocolInfo_ParseUrl
,
953 InternetProtocolInfo_CombineUrl
,
954 InternetProtocolInfo_CompareUrl
,
955 ResProtocolInfo_QueryInfo
958 static const IClassFactoryVtbl ResProtocolFactoryVtbl
= {
959 ClassFactory_QueryInterface
,
961 ClassFactory_Release
,
962 ResProtocolFactory_CreateInstance
,
963 ClassFactory_LockServer
966 static ProtocolFactory ResProtocolFactory
= {
967 { &ResProtocolInfoVtbl
},
968 { &ResProtocolFactoryVtbl
}
971 /********************************************************************
972 * JSProtocol implementation
975 static HRESULT WINAPI
JSProtocolFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
,
976 REFIID riid
, void **ppv
)
978 FIXME("(%p)->(%p %s %p)\n", iface
, pUnkOuter
, debugstr_guid(riid
), ppv
);
982 static HRESULT WINAPI
JSProtocolInfo_ParseUrl(IInternetProtocolInfo
*iface
, LPCWSTR pwzUrl
,
983 PARSEACTION ParseAction
, DWORD dwParseFlags
, LPWSTR pwzResult
, DWORD cchResult
,
984 DWORD
* pcchResult
, DWORD dwReserved
)
986 TRACE("%p)->(%s %d %x %p %d %p %d)\n", iface
, debugstr_w(pwzUrl
), ParseAction
,
987 dwParseFlags
, pwzResult
, cchResult
, pcchResult
, dwReserved
);
989 switch(ParseAction
) {
990 case PARSE_SECURITY_URL
:
991 FIXME("PARSE_SECURITY_URL\n");
994 FIXME("PARSE_DOMAIN\n");
997 return INET_E_DEFAULT_ACTION
;
1003 static HRESULT WINAPI
JSProtocolInfo_QueryInfo(IInternetProtocolInfo
*iface
, LPCWSTR pwzUrl
,
1004 QUERYOPTION QueryOption
, DWORD dwQueryFlags
, LPVOID pBuffer
, DWORD cbBuffer
, DWORD
* pcbBuf
,
1007 TRACE("%p)->(%s %08x %08x %p %d %p %d)\n", iface
, debugstr_w(pwzUrl
), QueryOption
, dwQueryFlags
, pBuffer
,
1008 cbBuffer
, pcbBuf
, dwReserved
);
1010 switch(QueryOption
) {
1011 case QUERY_USES_NETWORK
:
1012 if(!pBuffer
|| cbBuffer
< sizeof(DWORD
))
1015 *(DWORD
*)pBuffer
= 0;
1017 *pcbBuf
= sizeof(DWORD
);
1020 case QUERY_IS_SECURE
:
1021 FIXME("QUERY_IS_SECURE not supported\n");
1025 return INET_E_USE_DEFAULT_PROTOCOLHANDLER
;
1031 static const IInternetProtocolInfoVtbl JSProtocolInfoVtbl
= {
1032 InternetProtocolInfo_QueryInterface
,
1033 InternetProtocolInfo_AddRef
,
1034 InternetProtocolInfo_Release
,
1035 JSProtocolInfo_ParseUrl
,
1036 InternetProtocolInfo_CombineUrl
,
1037 InternetProtocolInfo_CompareUrl
,
1038 JSProtocolInfo_QueryInfo
1041 static const IClassFactoryVtbl JSProtocolFactoryVtbl
= {
1042 ClassFactory_QueryInterface
,
1043 ClassFactory_AddRef
,
1044 ClassFactory_Release
,
1045 JSProtocolFactory_CreateInstance
,
1046 ClassFactory_LockServer
1049 static ProtocolFactory JSProtocolFactory
= {
1050 { &JSProtocolInfoVtbl
},
1051 { &JSProtocolFactoryVtbl
}
1054 HRESULT
ProtocolFactory_Create(REFCLSID rclsid
, REFIID riid
, void **ppv
)
1056 ProtocolFactory
*cf
= NULL
;
1058 if(IsEqualGUID(&CLSID_AboutProtocol
, rclsid
))
1059 cf
= &AboutProtocolFactory
;
1060 else if(IsEqualGUID(&CLSID_ResProtocol
, rclsid
))
1061 cf
= &ResProtocolFactory
;
1062 else if(IsEqualGUID(&CLSID_JSProtocol
, rclsid
))
1063 cf
= &JSProtocolFactory
;
1066 FIXME("not implemented protocol %s\n", debugstr_guid(rclsid
));
1067 return CLASS_E_CLASSNOTAVAILABLE
;
1070 return IInternetProtocolInfo_QueryInterface(&cf
->IInternetProtocolInfo_iface
, riid
, ppv
);