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"
32 #include "wine/unicode.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
38 /********************************************************************
39 * common ProtocolFactory implementation
43 IInternetProtocolInfo IInternetProtocolInfo_iface
;
44 IClassFactory IClassFactory_iface
;
47 static inline ProtocolFactory
*impl_from_IInternetProtocolInfo(IInternetProtocolInfo
*iface
)
49 return CONTAINING_RECORD(iface
, ProtocolFactory
, IInternetProtocolInfo_iface
);
52 static HRESULT WINAPI
InternetProtocolInfo_QueryInterface(IInternetProtocolInfo
*iface
, REFIID riid
, void **ppv
)
54 ProtocolFactory
*This
= impl_from_IInternetProtocolInfo(iface
);
57 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
58 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
59 *ppv
= &This
->IInternetProtocolInfo_iface
;
60 }else if(IsEqualGUID(&IID_IInternetProtocolInfo
, riid
)) {
61 TRACE("(%p)->(IID_IInternetProtocolInfo %p)\n", This
, ppv
);
62 *ppv
= &This
->IInternetProtocolInfo_iface
;
63 }else if(IsEqualGUID(&IID_IClassFactory
, riid
)) {
64 TRACE("(%p)->(IID_IClassFactory %p)\n", This
, ppv
);
65 *ppv
= &This
->IClassFactory_iface
;
69 WARN("unknown interface %s\n", debugstr_guid(riid
));
73 IInternetProtocolInfo_AddRef(iface
);
77 static ULONG WINAPI
InternetProtocolInfo_AddRef(IInternetProtocolInfo
*iface
)
79 TRACE("(%p)\n", iface
);
83 static ULONG WINAPI
InternetProtocolInfo_Release(IInternetProtocolInfo
*iface
)
85 TRACE("(%p)\n", iface
);
89 static HRESULT WINAPI
InternetProtocolInfo_CombineUrl(IInternetProtocolInfo
*iface
,
90 LPCWSTR pwzBaseUrl
, LPCWSTR pwzRelativeUrl
, DWORD dwCombineFlags
, LPWSTR pwzResult
,
91 DWORD cchResult
, DWORD
* pcchResult
, DWORD dwReserved
)
93 TRACE("%p)->(%s %s %08x %p %d %p %d)\n", iface
, debugstr_w(pwzBaseUrl
),
94 debugstr_w(pwzRelativeUrl
), dwCombineFlags
, pwzResult
, cchResult
,
95 pcchResult
, dwReserved
);
97 return INET_E_USE_DEFAULT_PROTOCOLHANDLER
;
100 static HRESULT WINAPI
InternetProtocolInfo_CompareUrl(IInternetProtocolInfo
*iface
, LPCWSTR pwzUrl1
,
101 LPCWSTR pwzUrl2
, DWORD dwCompareFlags
)
103 TRACE("%p)->(%s %s %08x)\n", iface
, debugstr_w(pwzUrl1
), debugstr_w(pwzUrl2
), dwCompareFlags
);
107 static inline ProtocolFactory
*impl_from_IClassFactory(IClassFactory
*iface
)
109 return CONTAINING_RECORD(iface
, ProtocolFactory
, IClassFactory_iface
);
112 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
114 ProtocolFactory
*This
= impl_from_IClassFactory(iface
);
115 return IInternetProtocolInfo_QueryInterface(&This
->IInternetProtocolInfo_iface
, riid
, ppv
);
118 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
120 ProtocolFactory
*This
= impl_from_IClassFactory(iface
);
121 return IInternetProtocolInfo_AddRef(&This
->IInternetProtocolInfo_iface
);
124 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
126 ProtocolFactory
*This
= impl_from_IClassFactory(iface
);
127 return IInternetProtocolInfo_Release(&This
->IInternetProtocolInfo_iface
);
130 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL dolock
)
132 TRACE("(%p)->(%x)\n", iface
, dolock
);
136 /********************************************************************
137 * AboutProtocol implementation
141 IInternetProtocol IInternetProtocol_iface
;
152 static inline AboutProtocol
*AboutProtocol_from_IInternetProtocol(IInternetProtocol
*iface
)
154 return CONTAINING_RECORD(iface
, AboutProtocol
, IInternetProtocol_iface
);
157 static HRESULT WINAPI
AboutProtocol_QueryInterface(IInternetProtocol
*iface
, REFIID riid
, void **ppv
)
159 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
163 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
164 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
166 return IUnknown_QueryInterface(This
->pUnkOuter
, riid
, ppv
);
167 *ppv
= &This
->IInternetProtocol_iface
;
168 }else if(IsEqualGUID(&IID_IInternetProtocolRoot
, riid
)) {
169 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", iface
, ppv
);
170 *ppv
= &This
->IInternetProtocol_iface
;
171 }else if(IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
172 TRACE("(%p)->(IID_IInternetProtocol %p)\n", iface
, ppv
);
173 *ppv
= &This
->IInternetProtocol_iface
;
174 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
)) {
175 FIXME("IServiceProvider is not implemented\n");
176 return E_NOINTERFACE
;
180 TRACE("unknown interface %s\n", debugstr_guid(riid
));
181 return E_NOINTERFACE
;
184 IInternetProtocol_AddRef(iface
);
188 static ULONG WINAPI
AboutProtocol_AddRef(IInternetProtocol
*iface
)
190 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
191 ULONG ref
= InterlockedIncrement(&This
->ref
);
192 TRACE("(%p) ref=%d\n", iface
, ref
);
193 return This
->pUnkOuter
? IUnknown_AddRef(This
->pUnkOuter
) : ref
;
196 static ULONG WINAPI
AboutProtocol_Release(IInternetProtocol
*iface
)
198 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
199 IUnknown
*pUnkOuter
= This
->pUnkOuter
;
200 ULONG ref
= InterlockedDecrement(&This
->ref
);
202 TRACE("(%p) ref=%x\n", iface
, ref
);
205 heap_free(This
->data
);
209 return pUnkOuter
? IUnknown_Release(pUnkOuter
) : ref
;
212 static HRESULT WINAPI
AboutProtocol_Start(IInternetProtocol
*iface
, LPCWSTR szUrl
,
213 IInternetProtocolSink
* pOIProtSink
, IInternetBindInfo
* pOIBindInfo
,
214 DWORD grfPI
, HANDLE_PTR dwReserved
)
216 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 IInternetBindInfo_GetBindInfo(pOIBindInfo
, &grfBINDF
, &bindinfo
);
242 ReleaseBindInfo(&bindinfo
);
244 TRACE("bindf %x\n", grfBINDF
);
246 if(strlenW(szUrl
)>=sizeof(wszAbout
)/sizeof(WCHAR
) && !memcmp(wszAbout
, szUrl
, sizeof(wszAbout
))) {
247 text
= szUrl
+ sizeof(wszAbout
)/sizeof(WCHAR
);
248 if(!strcmpW(wszBlank
, text
))
252 data_len
= sizeof(html_begin
)+sizeof(html_end
)-sizeof(WCHAR
)
253 + (text
? strlenW(text
)*sizeof(WCHAR
) : 0);
254 data
= heap_alloc(data_len
);
256 return E_OUTOFMEMORY
;
258 heap_free(This
->data
);
260 This
->data_len
= data_len
;
262 memcpy(This
->data
, html_begin
, sizeof(html_begin
));
264 strcatW((LPWSTR
)This
->data
, text
);
265 strcatW((LPWSTR
)This
->data
, html_end
);
269 IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_MIMETYPEAVAILABLE
, wszTextHtml
);
271 IInternetProtocolSink_ReportData(pOIProtSink
,
272 BSCF_FIRSTDATANOTIFICATION
| BSCF_LASTDATANOTIFICATION
| BSCF_DATAFULLYAVAILABLE
,
273 This
->data_len
, This
->data_len
);
275 IInternetProtocolSink_ReportResult(pOIProtSink
, S_OK
, 0, NULL
);
280 static HRESULT WINAPI
AboutProtocol_Continue(IInternetProtocol
*iface
, PROTOCOLDATA
* pProtocolData
)
282 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
283 FIXME("(%p)->(%p)\n", This
, pProtocolData
);
287 static HRESULT WINAPI
AboutProtocol_Abort(IInternetProtocol
*iface
, HRESULT hrReason
,
290 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
291 FIXME("(%p)->(%08x %08x)\n", This
, hrReason
, dwOptions
);
295 static HRESULT WINAPI
AboutProtocol_Terminate(IInternetProtocol
*iface
, DWORD dwOptions
)
297 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
298 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
302 static HRESULT WINAPI
AboutProtocol_Suspend(IInternetProtocol
*iface
)
304 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
305 FIXME("(%p)\n", This
);
309 static HRESULT WINAPI
AboutProtocol_Resume(IInternetProtocol
*iface
)
311 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
312 FIXME("(%p)\n", This
);
316 static HRESULT WINAPI
AboutProtocol_Read(IInternetProtocol
*iface
, void* pv
, ULONG cb
, ULONG
* pcbRead
)
318 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
320 TRACE("(%p)->(%p %u %p)\n", This
, pv
, cb
, pcbRead
);
325 *pcbRead
= (cb
> This
->data_len
-This
->cur
? This
->data_len
-This
->cur
: cb
);
330 memcpy(pv
, This
->data
+This
->cur
, *pcbRead
);
331 This
->cur
+= *pcbRead
;
336 static HRESULT WINAPI
AboutProtocol_Seek(IInternetProtocol
*iface
, LARGE_INTEGER dlibMove
,
337 DWORD dwOrigin
, ULARGE_INTEGER
* plibNewPosition
)
339 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
340 FIXME("(%p)->(%d %d %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
344 static HRESULT WINAPI
AboutProtocol_LockRequest(IInternetProtocol
*iface
, DWORD dwOptions
)
346 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
348 TRACE("(%p)->(%d)\n", This
, dwOptions
);
353 static HRESULT WINAPI
AboutProtocol_UnlockRequest(IInternetProtocol
*iface
)
355 AboutProtocol
*This
= AboutProtocol_from_IInternetProtocol(iface
);
357 TRACE("(%p)\n", This
);
362 static const IInternetProtocolVtbl AboutProtocolVtbl
= {
363 AboutProtocol_QueryInterface
,
364 AboutProtocol_AddRef
,
365 AboutProtocol_Release
,
367 AboutProtocol_Continue
,
369 AboutProtocol_Terminate
,
370 AboutProtocol_Suspend
,
371 AboutProtocol_Resume
,
374 AboutProtocol_LockRequest
,
375 AboutProtocol_UnlockRequest
378 static HRESULT WINAPI
AboutProtocolFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
,
379 REFIID riid
, void **ppv
)
384 TRACE("(%p)->(%p %s %p)\n", iface
, pUnkOuter
, debugstr_guid(riid
), ppv
);
386 ret
= heap_alloc(sizeof(AboutProtocol
));
387 ret
->IInternetProtocol_iface
.lpVtbl
= &AboutProtocolVtbl
;
393 ret
->pUnkOuter
= pUnkOuter
;
397 if(IsEqualGUID(&IID_IUnknown
, riid
))
398 *ppv
= &ret
->IInternetProtocol_iface
;
402 hres
= IInternetProtocol_QueryInterface(&ret
->IInternetProtocol_iface
, riid
, ppv
);
411 static HRESULT WINAPI
AboutProtocolInfo_ParseUrl(IInternetProtocolInfo
*iface
, LPCWSTR pwzUrl
,
412 PARSEACTION ParseAction
, DWORD dwParseFlags
, LPWSTR pwzResult
, DWORD cchResult
,
413 DWORD
* pcchResult
, DWORD dwReserved
)
415 TRACE("%p)->(%s %d %08x %p %d %p %d)\n", iface
, debugstr_w(pwzUrl
), ParseAction
,
416 dwParseFlags
, pwzResult
, cchResult
, pcchResult
, dwReserved
);
418 if(ParseAction
== PARSE_SECURITY_URL
) {
419 unsigned int len
= strlenW(pwzUrl
)+1;
425 memcpy(pwzResult
, pwzUrl
, len
*sizeof(WCHAR
));
429 if(ParseAction
== PARSE_DOMAIN
) {
434 *pcchResult
= strlenW(pwzUrl
)+1;
440 return INET_E_DEFAULT_ACTION
;
443 static HRESULT WINAPI
AboutProtocolInfo_QueryInfo(IInternetProtocolInfo
*iface
, LPCWSTR pwzUrl
,
444 QUERYOPTION QueryOption
, DWORD dwQueryFlags
, LPVOID pBuffer
, DWORD cbBuffer
, DWORD
* pcbBuf
,
447 TRACE("%p)->(%s %08x %08x %p %d %p %d)\n", iface
, debugstr_w(pwzUrl
), QueryOption
, dwQueryFlags
, pBuffer
,
448 cbBuffer
, pcbBuf
, dwReserved
);
450 switch(QueryOption
) {
451 case QUERY_CAN_NAVIGATE
:
452 return INET_E_USE_DEFAULT_PROTOCOLHANDLER
;
454 case QUERY_USES_NETWORK
:
455 if(!pBuffer
|| cbBuffer
< sizeof(DWORD
))
458 *(DWORD
*)pBuffer
= 0;
460 *pcbBuf
= sizeof(DWORD
);
464 case QUERY_IS_CACHED
:
465 FIXME("Unsupported option QUERY_IS_CACHED\n");
467 case QUERY_IS_INSTALLEDENTRY
:
468 FIXME("Unsupported option QUERY_IS_INSTALLEDENTRY\n");
470 case QUERY_IS_CACHED_OR_MAPPED
:
471 FIXME("Unsupported option QUERY_IS_CACHED_OR_MAPPED\n");
473 case QUERY_IS_SECURE
:
474 FIXME("Unsupported option QUERY_IS_SECURE\n");
477 FIXME("Unsupported option QUERY_IS_SAFE\n");
479 case QUERY_USES_HISTORYFOLDER
:
480 FIXME("Unsupported option QUERY_USES_HISTORYFOLDER\n");
489 static const IInternetProtocolInfoVtbl AboutProtocolInfoVtbl
= {
490 InternetProtocolInfo_QueryInterface
,
491 InternetProtocolInfo_AddRef
,
492 InternetProtocolInfo_Release
,
493 AboutProtocolInfo_ParseUrl
,
494 InternetProtocolInfo_CombineUrl
,
495 InternetProtocolInfo_CompareUrl
,
496 AboutProtocolInfo_QueryInfo
499 static const IClassFactoryVtbl AboutProtocolFactoryVtbl
= {
500 ClassFactory_QueryInterface
,
502 ClassFactory_Release
,
503 AboutProtocolFactory_CreateInstance
,
504 ClassFactory_LockServer
507 static ProtocolFactory AboutProtocolFactory
= {
508 { &AboutProtocolInfoVtbl
},
509 { &AboutProtocolFactoryVtbl
}
512 /********************************************************************
513 * ResProtocol implementation
517 IInternetProtocol IInternetProtocol_iface
;
527 static inline ResProtocol
*ResProtocol_from_IInternetProtocol(IInternetProtocol
*iface
)
529 return CONTAINING_RECORD(iface
, ResProtocol
, IInternetProtocol_iface
);
532 static HRESULT WINAPI
ResProtocol_QueryInterface(IInternetProtocol
*iface
, REFIID riid
, void **ppv
)
534 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
538 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
539 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
541 return IUnknown_QueryInterface(This
->pUnkOuter
, &IID_IUnknown
, ppv
);
542 *ppv
= &This
->IInternetProtocol_iface
;
543 }else if(IsEqualGUID(&IID_IInternetProtocolRoot
, riid
)) {
544 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", iface
, ppv
);
545 *ppv
= &This
->IInternetProtocol_iface
;
546 }else if(IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
547 TRACE("(%p)->(IID_IInternetProtocol %p)\n", iface
, ppv
);
548 *ppv
= &This
->IInternetProtocol_iface
;
549 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
)) {
550 FIXME("IServiceProvider is not implemented\n");
551 return E_NOINTERFACE
;
555 TRACE("unknown interface %s\n", debugstr_guid(riid
));
556 return E_NOINTERFACE
;
559 IInternetProtocol_AddRef(iface
);
563 static ULONG WINAPI
ResProtocol_AddRef(IInternetProtocol
*iface
)
565 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
566 ULONG ref
= InterlockedIncrement(&This
->ref
);
567 TRACE("(%p) ref=%d\n", iface
, ref
);
568 return This
->pUnkOuter
? IUnknown_AddRef(This
->pUnkOuter
) : ref
;
571 static ULONG WINAPI
ResProtocol_Release(IInternetProtocol
*iface
)
573 ResProtocol
*This
= (ResProtocol
*)iface
;
574 IUnknown
*pUnkOuter
= This
->pUnkOuter
;
575 ULONG ref
= InterlockedDecrement(&This
->ref
);
577 TRACE("(%p) ref=%x\n", iface
, ref
);
580 heap_free(This
->data
);
584 return pUnkOuter
? IUnknown_Release(pUnkOuter
) : ref
;
587 static HRESULT WINAPI
ResProtocol_Start(IInternetProtocol
*iface
, LPCWSTR szUrl
,
588 IInternetProtocolSink
* pOIProtSink
, IInternetBindInfo
* pOIBindInfo
,
589 DWORD grfPI
, HANDLE_PTR dwReserved
)
591 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
592 DWORD grfBINDF
= 0, len
;
594 LPWSTR url_dll
, url_file
, url
, mime
, res_type
= (LPWSTR
)RT_HTML
;
599 static const WCHAR wszRes
[] = {'r','e','s',':','/','/'};
601 TRACE("(%p)->(%s %p %p %08x %lx)\n", This
, debugstr_w(szUrl
), pOIProtSink
,
602 pOIBindInfo
, grfPI
, dwReserved
);
604 memset(&bindinfo
, 0, sizeof(bindinfo
));
605 bindinfo
.cbSize
= sizeof(BINDINFO
);
606 IInternetBindInfo_GetBindInfo(pOIBindInfo
, &grfBINDF
, &bindinfo
);
607 ReleaseBindInfo(&bindinfo
);
609 len
= strlenW(szUrl
)+16;
610 url
= heap_alloc(len
*sizeof(WCHAR
));
611 hres
= CoInternetParseUrl(szUrl
, PARSE_ENCODE
, 0, url
, len
, &len
, 0);
613 WARN("CoInternetParseUrl failed: %08x\n", hres
);
615 IInternetProtocolSink_ReportResult(pOIProtSink
, hres
, 0, NULL
);
619 if(len
< sizeof(wszRes
)/sizeof(wszRes
[0]) || memcmp(url
, wszRes
, sizeof(wszRes
))) {
620 WARN("Wrong protocol of url: %s\n", debugstr_w(url
));
621 IInternetProtocolSink_ReportResult(pOIProtSink
, E_INVALIDARG
, 0, NULL
);
626 url_dll
= url
+ sizeof(wszRes
)/sizeof(wszRes
[0]);
627 if(!(url_file
= strrchrW(url_dll
, '/'))) {
628 WARN("wrong url: %s\n", debugstr_w(url
));
629 IInternetProtocolSink_ReportResult(pOIProtSink
, MK_E_SYNTAX
, 0, NULL
);
635 hdll
= LoadLibraryExW(url_dll
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
637 if (!(res_type
= strrchrW(url_dll
, '/'))) {
638 WARN("Could not open dll: %s\n", debugstr_w(url_dll
));
639 IInternetProtocolSink_ReportResult(pOIProtSink
, HRESULT_FROM_WIN32(GetLastError()), 0, NULL
);
641 return HRESULT_FROM_WIN32(GetLastError());
645 hdll
= LoadLibraryExW(url_dll
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
647 WARN("Could not open dll: %s\n", debugstr_w(url_dll
));
648 IInternetProtocolSink_ReportResult(pOIProtSink
, HRESULT_FROM_WIN32(GetLastError()), 0, NULL
);
650 return HRESULT_FROM_WIN32(GetLastError());
654 TRACE("trying to find resource type %s, name %s\n", debugstr_w(res_type
), debugstr_w(url_file
));
656 src
= FindResourceW(hdll
, url_file
, res_type
);
658 LPWSTR endpoint
= NULL
;
659 DWORD file_id
= strtolW(url_file
, &endpoint
, 10);
660 if(endpoint
== url_file
+strlenW(url_file
))
661 src
= FindResourceW(hdll
, MAKEINTRESOURCEW(file_id
), MAKEINTRESOURCEW(RT_HTML
));
664 WARN("Could not find resource\n");
665 IInternetProtocolSink_ReportResult(pOIProtSink
,
666 HRESULT_FROM_WIN32(GetLastError()), 0, NULL
);
668 return HRESULT_FROM_WIN32(GetLastError());
673 WARN("data already loaded\n");
674 heap_free(This
->data
);
677 This
->data_len
= SizeofResource(hdll
, src
);
678 This
->data
= heap_alloc(This
->data_len
);
679 memcpy(This
->data
, LoadResource(hdll
, src
), This
->data_len
);
684 hres
= FindMimeFromData(NULL
, url_file
, This
->data
, This
->data_len
, NULL
, 0, &mime
, 0);
686 if(SUCCEEDED(hres
)) {
687 IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_MIMETYPEAVAILABLE
, mime
);
691 IInternetProtocolSink_ReportData(pOIProtSink
,
692 BSCF_FIRSTDATANOTIFICATION
| BSCF_LASTDATANOTIFICATION
| BSCF_DATAFULLYAVAILABLE
,
693 This
->data_len
, This
->data_len
);
695 IInternetProtocolSink_ReportResult(pOIProtSink
, S_OK
, 0, NULL
);
700 static HRESULT WINAPI
ResProtocol_Continue(IInternetProtocol
*iface
, PROTOCOLDATA
* pProtocolData
)
702 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
703 FIXME("(%p)->(%p)\n", This
, pProtocolData
);
707 static HRESULT WINAPI
ResProtocol_Abort(IInternetProtocol
*iface
, HRESULT hrReason
,
710 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
711 FIXME("(%p)->(%08x %08x)\n", This
, hrReason
, dwOptions
);
715 static HRESULT WINAPI
ResProtocol_Terminate(IInternetProtocol
*iface
, DWORD dwOptions
)
717 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
719 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
721 /* test show that we don't have to do anything here */
725 static HRESULT WINAPI
ResProtocol_Suspend(IInternetProtocol
*iface
)
727 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
728 FIXME("(%p)\n", This
);
732 static HRESULT WINAPI
ResProtocol_Resume(IInternetProtocol
*iface
)
734 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
735 FIXME("(%p)\n", This
);
739 static HRESULT WINAPI
ResProtocol_Read(IInternetProtocol
*iface
, void* pv
, ULONG cb
, ULONG
* pcbRead
)
741 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
743 TRACE("(%p)->(%p %u %p)\n", This
, pv
, cb
, pcbRead
);
748 *pcbRead
= (cb
> This
->data_len
-This
->cur
? This
->data_len
-This
->cur
: cb
);
753 memcpy(pv
, This
->data
+This
->cur
, *pcbRead
);
754 This
->cur
+= *pcbRead
;
759 static HRESULT WINAPI
ResProtocol_Seek(IInternetProtocol
*iface
, LARGE_INTEGER dlibMove
,
760 DWORD dwOrigin
, ULARGE_INTEGER
* plibNewPosition
)
762 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
763 FIXME("(%p)->(%d %d %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
767 static HRESULT WINAPI
ResProtocol_LockRequest(IInternetProtocol
*iface
, DWORD dwOptions
)
769 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
771 TRACE("(%p)->(%d)\n", This
, dwOptions
);
773 /* test show that we don't have to do anything here */
777 static HRESULT WINAPI
ResProtocol_UnlockRequest(IInternetProtocol
*iface
)
779 ResProtocol
*This
= ResProtocol_from_IInternetProtocol(iface
);
781 TRACE("(%p)\n", This
);
783 /* test show that we don't have to do anything here */
787 static const IInternetProtocolVtbl ResProtocolVtbl
= {
788 ResProtocol_QueryInterface
,
792 ResProtocol_Continue
,
794 ResProtocol_Terminate
,
799 ResProtocol_LockRequest
,
800 ResProtocol_UnlockRequest
803 static HRESULT WINAPI
ResProtocolFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
,
804 REFIID riid
, void **ppv
)
809 TRACE("(%p)->(%p %s %p)\n", iface
, pUnkOuter
, debugstr_guid(riid
), ppv
);
811 ret
= heap_alloc(sizeof(ResProtocol
));
812 ret
->IInternetProtocol_iface
.lpVtbl
= &ResProtocolVtbl
;
817 ret
->pUnkOuter
= pUnkOuter
;
821 if(IsEqualGUID(&IID_IUnknown
, riid
))
822 *ppv
= &ret
->IInternetProtocol_iface
;
826 hres
= IInternetProtocol_QueryInterface(&ret
->IInternetProtocol_iface
, riid
, ppv
);
835 static HRESULT WINAPI
ResProtocolInfo_ParseUrl(IInternetProtocolInfo
*iface
, LPCWSTR pwzUrl
,
836 PARSEACTION ParseAction
, DWORD dwParseFlags
, LPWSTR pwzResult
, DWORD cchResult
,
837 DWORD
* pcchResult
, DWORD dwReserved
)
839 TRACE("%p)->(%s %d %x %p %d %p %d)\n", iface
, debugstr_w(pwzUrl
), ParseAction
,
840 dwParseFlags
, pwzResult
, cchResult
, pcchResult
, dwReserved
);
842 if(ParseAction
== PARSE_SECURITY_URL
) {
843 WCHAR file_part
[MAX_PATH
], full_path
[MAX_PATH
];
847 static const WCHAR wszFile
[] = {'f','i','l','e',':','/','/'};
848 static const WCHAR wszRes
[] = {'r','e','s',':','/','/'};
850 if(strlenW(pwzUrl
) <= sizeof(wszRes
)/sizeof(WCHAR
) || memcmp(pwzUrl
, wszRes
, sizeof(wszRes
)))
853 ptr
= strchrW(pwzUrl
+ sizeof(wszRes
)/sizeof(WCHAR
), '/');
857 len
= ptr
- (pwzUrl
+ sizeof(wszRes
)/sizeof(WCHAR
));
858 if(len
>= sizeof(file_part
)/sizeof(WCHAR
)) {
859 FIXME("Too long URL\n");
863 memcpy(file_part
, pwzUrl
+ sizeof(wszRes
)/sizeof(WCHAR
), len
*sizeof(WCHAR
));
866 len
= SearchPathW(NULL
, file_part
, NULL
, sizeof(full_path
)/sizeof(WCHAR
), full_path
, NULL
);
868 WARN("Could not find file %s\n", debugstr_w(file_part
));
872 size
= sizeof(wszFile
)/sizeof(WCHAR
) + len
+ 1;
878 memcpy(pwzResult
, wszFile
, sizeof(wszFile
));
879 memcpy(pwzResult
+ sizeof(wszFile
)/sizeof(WCHAR
), full_path
, (len
+1)*sizeof(WCHAR
));
883 if(ParseAction
== PARSE_DOMAIN
) {
888 *pcchResult
= strlenW(pwzUrl
)+1;
894 return INET_E_DEFAULT_ACTION
;
897 static HRESULT WINAPI
ResProtocolInfo_QueryInfo(IInternetProtocolInfo
*iface
, LPCWSTR pwzUrl
,
898 QUERYOPTION QueryOption
, DWORD dwQueryFlags
, LPVOID pBuffer
, DWORD cbBuffer
, DWORD
* pcbBuf
,
901 TRACE("%p)->(%s %08x %08x %p %d %p %d)\n", iface
, debugstr_w(pwzUrl
), QueryOption
, dwQueryFlags
, pBuffer
,
902 cbBuffer
, pcbBuf
, dwReserved
);
904 switch(QueryOption
) {
905 case QUERY_USES_NETWORK
:
906 if(!pBuffer
|| cbBuffer
< sizeof(DWORD
))
909 *(DWORD
*)pBuffer
= 0;
911 *pcbBuf
= sizeof(DWORD
);
914 case QUERY_IS_SECURE
:
915 FIXME("not supporte QUERY_IS_SECURE\n");
918 FIXME("not supporte QUERY_IS_SAFE\n");
921 return INET_E_USE_DEFAULT_PROTOCOLHANDLER
;
927 static const IInternetProtocolInfoVtbl ResProtocolInfoVtbl
= {
928 InternetProtocolInfo_QueryInterface
,
929 InternetProtocolInfo_AddRef
,
930 InternetProtocolInfo_Release
,
931 ResProtocolInfo_ParseUrl
,
932 InternetProtocolInfo_CombineUrl
,
933 InternetProtocolInfo_CompareUrl
,
934 ResProtocolInfo_QueryInfo
937 static const IClassFactoryVtbl ResProtocolFactoryVtbl
= {
938 ClassFactory_QueryInterface
,
940 ClassFactory_Release
,
941 ResProtocolFactory_CreateInstance
,
942 ClassFactory_LockServer
945 static ProtocolFactory ResProtocolFactory
= {
946 { &ResProtocolInfoVtbl
},
947 { &ResProtocolFactoryVtbl
}
950 /********************************************************************
951 * JSProtocol implementation
954 static HRESULT WINAPI
JSProtocolFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
,
955 REFIID riid
, void **ppv
)
957 FIXME("(%p)->(%p %s %p)\n", iface
, pUnkOuter
, debugstr_guid(riid
), ppv
);
961 static HRESULT WINAPI
JSProtocolInfo_ParseUrl(IInternetProtocolInfo
*iface
, LPCWSTR pwzUrl
,
962 PARSEACTION ParseAction
, DWORD dwParseFlags
, LPWSTR pwzResult
, DWORD cchResult
,
963 DWORD
* pcchResult
, DWORD dwReserved
)
965 TRACE("%p)->(%s %d %x %p %d %p %d)\n", iface
, debugstr_w(pwzUrl
), ParseAction
,
966 dwParseFlags
, pwzResult
, cchResult
, pcchResult
, dwReserved
);
968 switch(ParseAction
) {
969 case PARSE_SECURITY_URL
:
970 FIXME("PARSE_SECURITY_URL\n");
973 FIXME("PARSE_DOMAIN\n");
976 return INET_E_DEFAULT_ACTION
;
982 static HRESULT WINAPI
JSProtocolInfo_QueryInfo(IInternetProtocolInfo
*iface
, LPCWSTR pwzUrl
,
983 QUERYOPTION QueryOption
, DWORD dwQueryFlags
, LPVOID pBuffer
, DWORD cbBuffer
, DWORD
* pcbBuf
,
986 TRACE("%p)->(%s %08x %08x %p %d %p %d)\n", iface
, debugstr_w(pwzUrl
), QueryOption
, dwQueryFlags
, pBuffer
,
987 cbBuffer
, pcbBuf
, dwReserved
);
989 switch(QueryOption
) {
990 case QUERY_USES_NETWORK
:
991 if(!pBuffer
|| cbBuffer
< sizeof(DWORD
))
994 *(DWORD
*)pBuffer
= 0;
996 *pcbBuf
= sizeof(DWORD
);
999 case QUERY_IS_SECURE
:
1000 FIXME("not supporte QUERY_IS_SECURE\n");
1004 return INET_E_USE_DEFAULT_PROTOCOLHANDLER
;
1010 static const IInternetProtocolInfoVtbl JSProtocolInfoVtbl
= {
1011 InternetProtocolInfo_QueryInterface
,
1012 InternetProtocolInfo_AddRef
,
1013 InternetProtocolInfo_Release
,
1014 JSProtocolInfo_ParseUrl
,
1015 InternetProtocolInfo_CombineUrl
,
1016 InternetProtocolInfo_CompareUrl
,
1017 JSProtocolInfo_QueryInfo
1020 static const IClassFactoryVtbl JSProtocolFactoryVtbl
= {
1021 ClassFactory_QueryInterface
,
1022 ClassFactory_AddRef
,
1023 ClassFactory_Release
,
1024 JSProtocolFactory_CreateInstance
,
1025 ClassFactory_LockServer
1028 static ProtocolFactory JSProtocolFactory
= {
1029 { &JSProtocolInfoVtbl
},
1030 { &JSProtocolFactoryVtbl
}
1033 HRESULT
ProtocolFactory_Create(REFCLSID rclsid
, REFIID riid
, void **ppv
)
1035 ProtocolFactory
*cf
= NULL
;
1037 if(IsEqualGUID(&CLSID_AboutProtocol
, rclsid
))
1038 cf
= &AboutProtocolFactory
;
1039 else if(IsEqualGUID(&CLSID_ResProtocol
, rclsid
))
1040 cf
= &ResProtocolFactory
;
1041 else if(IsEqualGUID(&CLSID_JSProtocol
, rclsid
))
1042 cf
= &JSProtocolFactory
;
1045 FIXME("not implemented protocol %s\n", debugstr_guid(rclsid
));
1046 return CLASS_E_CLASSNOTAVAILABLE
;
1049 return IInternetProtocolInfo_QueryInterface(&cf
->IInternetProtocolInfo_iface
, riid
, ppv
);