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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #include "wine/debug.h"
36 #include "wine/unicode.h"
38 #include "mshtml_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
42 /********************************************************************
43 * common ProtocolFactory implementation
46 #define PROTOCOLINFO(x) ((IInternetProtocolInfo*) &(x)->lpInternetProtocolInfoVtbl)
47 #define CLASSFACTORY(x) ((IClassFactory*) &(x)->lpClassFactoryVtbl)
50 const IInternetProtocolInfoVtbl *lpInternetProtocolInfoVtbl;
51 const IClassFactoryVtbl *lpClassFactoryVtbl;
54 #define PROTOCOLINFO_THIS(iface) \
55 (ProtocolFactory*)((char*)(iface)-offsetof(ProtocolFactory,lpInternetProtocolInfoVtbl))
57 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface, REFIID riid, void **ppv)
59 ProtocolFactory *This = PROTOCOLINFO_THIS(iface);
62 if(IsEqualGUID(&IID_IUnknown, riid)) {
63 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
64 *ppv = PROTOCOLINFO(This);
65 }else if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
66 TRACE("(%p)->(IID_IInternetProtocolInfo %p)\n", This, ppv);
67 *ppv = PROTOCOLINFO(This);
68 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
69 TRACE("(%p)->(IID_IClassFactory %p)\n", This, ppv);
70 *ppv = CLASSFACTORY(This);
74 WARN("unknown interface %s\n", debugstr_guid(riid));
78 IInternetProtocolInfo_AddRef(iface);
82 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
84 ProtocolFactory *This = PROTOCOLINFO_THIS(iface);
85 TRACE("(%p)\n", This);
89 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
91 ProtocolFactory *This = PROTOCOLINFO_THIS(iface);
92 TRACE("(%p)\n", This);
96 #undef PROTOCOLINFO_THIS
98 #define CLASSFACTORY_THIS(iface) \
99 (ProtocolFactory*)((char*)(iface)-offsetof(ProtocolFactory,lpClassFactoryVtbl))
101 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
103 ProtocolFactory *This = CLASSFACTORY_THIS(iface);
104 return IInternetProtocolInfo_QueryInterface(PROTOCOLINFO(This), riid, ppv);
107 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
109 ProtocolFactory *This = CLASSFACTORY_THIS(iface);
110 return IInternetProtocolInfo_AddRef(PROTOCOLINFO(This));
113 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
115 ProtocolFactory *This = CLASSFACTORY_THIS(iface);
116 return IInternetProtocolInfo_Release(PROTOCOLINFO(This));
119 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
121 ProtocolFactory *This = CLASSFACTORY_THIS(iface);
122 FIXME("(%p)->(%x)\n", This, dolock);
126 #undef CLASSFACTORY_THIS
128 /********************************************************************
129 * AboutProtocol implementation
133 const IInternetProtocolVtbl *lpInternetProtocolVtbl;
137 static HRESULT WINAPI AboutProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
141 if(IsEqualGUID(&IID_IUnknown, riid)) {
142 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
144 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
145 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", iface, ppv);
147 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
148 TRACE("(%p)->(IID_IInternetProtocol %p)\n", iface, ppv);
150 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
151 FIXME("IServiceProvider is not implemented\n");
152 return E_NOINTERFACE;
156 TRACE("unknown interface %s\n", debugstr_guid(riid));
157 return E_NOINTERFACE;
160 IInternetProtocol_AddRef(iface);
164 static ULONG WINAPI AboutProtocol_AddRef(IInternetProtocol *iface)
166 AboutProtocol *This = (AboutProtocol*)iface;
167 ULONG ref = InterlockedIncrement(&This->ref);
168 TRACE("(%p) ref=%ld\n", iface, ref);
172 static ULONG WINAPI AboutProtocol_Release(IInternetProtocol *iface)
174 AboutProtocol *This = (AboutProtocol*)iface;
175 ULONG ref = InterlockedDecrement(&This->ref);
177 TRACE("(%p) ref=%lx\n", iface, ref);
180 HeapFree(GetProcessHeap(), 0, This);
185 static HRESULT WINAPI AboutProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
186 IInternetProtocolSink* pOIProtSink, IInternetBindInfo* pOIBindInfo,
187 DWORD grfPI, DWORD dwReserved)
189 AboutProtocol *This = (AboutProtocol*)iface;
190 FIXME("(%p)->(%s %p %p %08lx %ld)\n", This, debugstr_w(szUrl), pOIProtSink,
191 pOIBindInfo, grfPI, dwReserved);
195 static HRESULT WINAPI AboutProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA* pProtocolData)
197 AboutProtocol *This = (AboutProtocol*)iface;
198 FIXME("(%p)->(%p)\n", This, pProtocolData);
202 static HRESULT WINAPI AboutProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
205 AboutProtocol *This = (AboutProtocol*)iface;
206 FIXME("(%p)->(%08lx %08lx)\n", This, hrReason, dwOptions);
210 static HRESULT WINAPI AboutProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
212 AboutProtocol *This = (AboutProtocol*)iface;
213 FIXME("(%p)->(%08lx)\n", This, dwOptions);
217 static HRESULT WINAPI AboutProtocol_Suspend(IInternetProtocol *iface)
219 AboutProtocol *This = (AboutProtocol*)iface;
220 FIXME("(%p)\n", This);
224 static HRESULT WINAPI AboutProtocol_Resume(IInternetProtocol *iface)
226 AboutProtocol *This = (AboutProtocol*)iface;
227 FIXME("(%p)\n", This);
231 static HRESULT WINAPI AboutProtocol_Read(IInternetProtocol *iface, void* pv, ULONG cb, ULONG* pcbRead)
233 AboutProtocol *This = (AboutProtocol*)iface;
234 FIXME("(%p)->(%lu %p)\n", This, cb, pcbRead);
238 static HRESULT WINAPI AboutProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
239 DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
241 AboutProtocol *This = (AboutProtocol*)iface;
242 FIXME("(%p)->(%ld %ld %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
246 static HRESULT WINAPI AboutProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
248 AboutProtocol *This = (AboutProtocol*)iface;
249 FIXME("(%p)->(%ld)\n", This, dwOptions);
253 static HRESULT WINAPI AboutProtocol_UnlockRequest(IInternetProtocol *iface)
255 AboutProtocol *This = (AboutProtocol*)iface;
256 FIXME("(%p)\n", This);
260 static const IInternetProtocolVtbl AboutProtocolVtbl = {
261 AboutProtocol_QueryInterface,
262 AboutProtocol_AddRef,
263 AboutProtocol_Release,
265 AboutProtocol_Continue,
267 AboutProtocol_Terminate,
268 AboutProtocol_Suspend,
269 AboutProtocol_Resume,
272 AboutProtocol_LockRequest,
273 AboutProtocol_UnlockRequest
276 static HRESULT WINAPI AboutProtocolFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
277 REFIID riid, void **ppv)
282 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
284 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(AboutProtocol));
285 ret->lpInternetProtocolVtbl = &AboutProtocolVtbl;
288 hres = IUnknown_QueryInterface((IUnknown*)ret, riid, ppv);
291 HeapFree(GetProcessHeap(), 0, ret);
296 static HRESULT WINAPI AboutProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
297 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
298 DWORD* pcchResult, DWORD dwReserved)
300 FIXME("%p)->(%s %08x %08lx %p %ld %p %ld)\n", iface, debugstr_w(pwzUrl), ParseAction,
301 dwParseFlags, pwzResult, cchResult, pcchResult, dwReserved);
305 static HRESULT WINAPI AboutProtocolInfo_CombineUrl(IInternetProtocolInfo *iface, LPCWSTR pwzBaseUrl,
306 LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags, LPWSTR pwzResult, DWORD cchResult,
307 DWORD* pcchResult, DWORD dwReserved)
309 FIXME("%p)->(%s %s %08lx %p %ld %p %ld)\n", iface, debugstr_w(pwzBaseUrl), debugstr_w(pwzRelativeUrl),
310 dwCombineFlags, pwzResult, cchResult, pcchResult, dwReserved);
314 static HRESULT WINAPI AboutProtocolInfo_CompareUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl1,
315 LPCWSTR pwzUrl2, DWORD dwCompareFlags)
317 FIXME("%p)->(%s %s %08lx)\n", iface, debugstr_w(pwzUrl1), debugstr_w(pwzUrl2), dwCompareFlags);
321 static HRESULT WINAPI AboutProtocolInfo_QueryInfo(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
322 QUERYOPTION QueryOption, DWORD dwQueryFlags, LPVOID pBuffer, DWORD cbBuffer, DWORD* pcbBuf,
325 FIXME("%p)->(%s %08x %08lx %p %ld %p %ld)\n", iface, debugstr_w(pwzUrl), QueryOption, dwQueryFlags, pBuffer,
326 cbBuffer, pcbBuf, dwReserved);
330 static const IInternetProtocolInfoVtbl AboutProtocolInfoVtbl = {
331 InternetProtocolInfo_QueryInterface,
332 InternetProtocolInfo_AddRef,
333 InternetProtocolInfo_Release,
334 AboutProtocolInfo_ParseUrl,
335 AboutProtocolInfo_CombineUrl,
336 AboutProtocolInfo_CompareUrl,
337 AboutProtocolInfo_QueryInfo
340 static const IClassFactoryVtbl AboutProtocolFactoryVtbl = {
341 ClassFactory_QueryInterface,
343 ClassFactory_Release,
344 AboutProtocolFactory_CreateInstance,
345 ClassFactory_LockServer
348 static ProtocolFactory AboutProtocolFactory = {
349 &AboutProtocolInfoVtbl,
350 &AboutProtocolFactoryVtbl
353 /********************************************************************
354 * ResProtocol implementation
358 const IInternetProtocolVtbl *lpInternetProtocolVtbl;
366 static HRESULT WINAPI ResProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
370 if(IsEqualGUID(&IID_IUnknown, riid)) {
371 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
373 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
374 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", iface, ppv);
376 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
377 TRACE("(%p)->(IID_IInternetProtocol %p)\n", iface, ppv);
379 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
380 FIXME("IServiceProvider is not implemented\n");
381 return E_NOINTERFACE;
385 TRACE("unknown interface %s\n", debugstr_guid(riid));
386 return E_NOINTERFACE;
389 IInternetProtocol_AddRef(iface);
393 static ULONG WINAPI ResProtocol_AddRef(IInternetProtocol *iface)
395 ResProtocol *This = (ResProtocol*)iface;
396 ULONG ref = InterlockedIncrement(&This->ref);
397 TRACE("(%p) ref=%ld\n", iface, ref);
401 static ULONG WINAPI ResProtocol_Release(IInternetProtocol *iface)
403 ResProtocol *This = (ResProtocol*)iface;
404 ULONG ref = InterlockedDecrement(&This->ref);
406 TRACE("(%p) ref=%lx\n", iface, ref);
409 HeapFree(GetProcessHeap(), 0, This->data);
410 HeapFree(GetProcessHeap(), 0, This);
416 static HRESULT WINAPI ResProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
417 IInternetProtocolSink* pOIProtSink, IInternetBindInfo* pOIBindInfo,
418 DWORD grfPI, DWORD dwReserved)
420 ResProtocol *This = (ResProtocol*)iface;
425 LPCWSTR url_dll, url_file;
429 static const WCHAR wszRes[] = {'r','e','s',':','/','/'};
431 TRACE("(%p)->(%s %p %p %08lx %ld)\n", This, debugstr_w(szUrl), pOIProtSink,
432 pOIBindInfo, grfPI, dwReserved);
434 memset(&bindinfo, 0, sizeof(bindinfo));
435 bindinfo.cbSize = sizeof(BINDINFO);
436 IInternetBindInfo_GetBindInfo(pOIBindInfo, &grfBINDF, &bindinfo);
439 * Implement MIME type checking
440 * Use CoInternetParseUrl (not implemented yet)
443 len = strlenW(szUrl);
444 if(len < sizeof(wszRes)/sizeof(wszRes[0]) || memcmp(szUrl, wszRes, sizeof(wszRes))) {
445 WARN("Wrong protocol of url: %s\n", debugstr_w(szUrl));
446 IInternetProtocolSink_ReportResult(pOIProtSink, MK_E_SYNTAX, 0, NULL);
450 url_dll = szUrl + sizeof(wszRes)/sizeof(wszRes[0]);
451 if(!(url_file = strchrW(url_dll, '/'))) {
452 WARN("wrong url: %s\n", debugstr_w(szUrl));
453 IInternetProtocolSink_ReportResult(pOIProtSink, MK_E_SYNTAX, 0, NULL);
457 memcpy(dll, url_dll, (url_file-url_dll)*sizeof(WCHAR));
458 dll[url_file-url_dll] = 0;
460 hdll = LoadLibraryExW(dll, NULL, LOAD_LIBRARY_AS_DATAFILE);
462 WARN("Could not open dll: %s\n", debugstr_w(dll));
463 IInternetProtocolSink_ReportResult(pOIProtSink, HRESULT_FROM_WIN32(GetLastError()), 0, NULL);
464 return HRESULT_FROM_WIN32(GetLastError());
467 src = FindResourceW(hdll, ++url_file, (LPCWSTR)RT_HTML);
469 WARN("Could not find resource: %s\n", debugstr_w(url_file));
470 IInternetProtocolSink_ReportResult(pOIProtSink, HRESULT_FROM_WIN32(GetLastError()), 0, NULL);
471 return HRESULT_FROM_WIN32(GetLastError());
475 WARN("data already loaded\n");
476 HeapFree(GetProcessHeap(), 0, This->data);
479 This->data_len = SizeofResource(hdll, src);
480 This->data = HeapAlloc(GetProcessHeap(), 0, This->data_len);
481 memcpy(This->data, LoadResource(hdll, src), This->data_len);
486 IInternetProtocolSink_ReportData(pOIProtSink,
487 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE,
488 This->data_len, This->data_len);
490 IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
495 static HRESULT WINAPI ResProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA* pProtocolData)
497 ResProtocol *This = (ResProtocol*)iface;
498 FIXME("(%p)->(%p)\n", This, pProtocolData);
502 static HRESULT WINAPI ResProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
505 ResProtocol *This = (ResProtocol*)iface;
506 FIXME("(%p)->(%08lx %08lx)\n", This, hrReason, dwOptions);
510 static HRESULT WINAPI ResProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
512 ResProtocol *This = (ResProtocol*)iface;
514 TRACE("(%p)->(%08lx)\n", This, dwOptions);
516 /* test show that we don't have to do anything here */
520 static HRESULT WINAPI ResProtocol_Suspend(IInternetProtocol *iface)
522 ResProtocol *This = (ResProtocol*)iface;
523 FIXME("(%p)\n", This);
527 static HRESULT WINAPI ResProtocol_Resume(IInternetProtocol *iface)
529 ResProtocol *This = (ResProtocol*)iface;
530 FIXME("(%p)\n", This);
534 static HRESULT WINAPI ResProtocol_Read(IInternetProtocol *iface, void* pv, ULONG cb, ULONG* pcbRead)
536 ResProtocol *This = (ResProtocol*)iface;
538 TRACE("(%p)->(%p %lu %p)\n", This, pv, cb, pcbRead);
543 *pcbRead = (cb > This->data_len-This->cur ? This->data_len-This->cur : cb);
548 memcpy(pv, This->data, *pcbRead);
549 This->cur += *pcbRead;
554 static HRESULT WINAPI ResProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
555 DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
557 ResProtocol *This = (ResProtocol*)iface;
558 FIXME("(%p)->(%ld %ld %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
562 static HRESULT WINAPI ResProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
564 ResProtocol *This = (ResProtocol*)iface;
566 TRACE("(%p)->(%ld)\n", This, dwOptions);
568 /* test show that we don't have to do anything here */
572 static HRESULT WINAPI ResProtocol_UnlockRequest(IInternetProtocol *iface)
574 ResProtocol *This = (ResProtocol*)iface;
576 TRACE("(%p)\n", This);
578 /* test show that we don't have to do anything here */
582 static const IInternetProtocolVtbl ResProtocolVtbl = {
583 ResProtocol_QueryInterface,
587 ResProtocol_Continue,
589 ResProtocol_Terminate,
594 ResProtocol_LockRequest,
595 ResProtocol_UnlockRequest
598 static HRESULT WINAPI ResProtocolFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
599 REFIID riid, void **ppv)
604 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
606 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(ResProtocol));
607 ret->lpInternetProtocolVtbl = &ResProtocolVtbl;
613 hres = IUnknown_QueryInterface((IUnknown*)ret, riid, ppv);
616 HeapFree(GetProcessHeap(), 0, ret);
621 static HRESULT WINAPI ResProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
622 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
623 DWORD* pcchResult, DWORD dwReserved)
625 FIXME("%p)->(%s %08x %08lx %p %ld %p %ld)\n", iface, debugstr_w(pwzUrl), ParseAction,
626 dwParseFlags, pwzResult, cchResult, pcchResult, dwReserved);
630 static HRESULT WINAPI ResProtocolInfo_CombineUrl(IInternetProtocolInfo *iface, LPCWSTR pwzBaseUrl,
631 LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags, LPWSTR pwzResult, DWORD cchResult,
632 DWORD* pcchResult, DWORD dwReserved)
634 FIXME("%p)->(%s %s %08lx %p %ld %p %ld)\n", iface, debugstr_w(pwzBaseUrl), debugstr_w(pwzRelativeUrl),
635 dwCombineFlags, pwzResult, cchResult, pcchResult, dwReserved);
639 static HRESULT WINAPI ResProtocolInfo_CompareUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl1,
640 LPCWSTR pwzUrl2, DWORD dwCompareFlags)
642 FIXME("%p)->(%s %s %08lx)\n", iface, debugstr_w(pwzUrl1), debugstr_w(pwzUrl2), dwCompareFlags);
646 static HRESULT WINAPI ResProtocolInfo_QueryInfo(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
647 QUERYOPTION QueryOption, DWORD dwQueryFlags, LPVOID pBuffer, DWORD cbBuffer, DWORD* pcbBuf,
650 FIXME("%p)->(%s %08x %08lx %p %ld %p %ld)\n", iface, debugstr_w(pwzUrl), QueryOption, dwQueryFlags, pBuffer,
651 cbBuffer, pcbBuf, dwReserved);
655 static const IInternetProtocolInfoVtbl ResProtocolInfoVtbl = {
656 InternetProtocolInfo_QueryInterface,
657 InternetProtocolInfo_AddRef,
658 InternetProtocolInfo_Release,
659 ResProtocolInfo_ParseUrl,
660 ResProtocolInfo_CombineUrl,
661 ResProtocolInfo_CompareUrl,
662 ResProtocolInfo_QueryInfo
665 static const IClassFactoryVtbl ResProtocolFactoryVtbl = {
666 ClassFactory_QueryInterface,
668 ClassFactory_Release,
669 ResProtocolFactory_CreateInstance,
670 ClassFactory_LockServer
673 static ProtocolFactory ResProtocolFactory = {
674 &ResProtocolInfoVtbl,
675 &ResProtocolFactoryVtbl
678 HRESULT ProtocolFactory_Create(REFCLSID rclsid, REFIID riid, void **ppv)
680 ProtocolFactory *cf = NULL;
682 if(IsEqualGUID(&CLSID_AboutProtocol, rclsid))
683 cf = &AboutProtocolFactory;
684 else if(IsEqualGUID(&CLSID_ResProtocol, rclsid))
685 cf = &ResProtocolFactory;
688 FIXME("not implemented protocol %s\n", debugstr_guid(rclsid));
689 return CLASS_E_CLASSNOTAVAILABLE;
692 return IUnknown_QueryInterface((IUnknown*)cf, riid, ppv);