From f559d1a23c71252b698badf63e4685a3abfa1712 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 16 Nov 2011 23:45:22 +0000 Subject: [PATCH] Move wxWebView-related definitions to webview_ie.cpp and fix them. Ensure that all the GUIDs are defined by including initguid.h to fix linking error with most versions of MinGW. Use "wx" prefix to avoid clashes with the standard GUIDs if they do happen to be defined. Closes #13645. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/missing.h | 127 --------------------------------- include/wx/msw/webview_ie.h | 136 ++++++++++++++++++++++++++++++++++-- src/msw/webview_ie.cpp | 32 ++++++--- 3 files changed, 153 insertions(+), 142 deletions(-) diff --git a/include/wx/msw/missing.h b/include/wx/msw/missing.h index b6ab671844..cfbeea2be6 100644 --- a/include/wx/msw/missing.h +++ b/include/wx/msw/missing.h @@ -660,133 +660,6 @@ typedef enum CommandStateChangeConstants { CSC_NAVIGATEFORWARD = 0x1, CSC_NAVIGATEBACK = 0x2 } CommandStateChangeConstants; -#endif - -//Definitions from w64 mingw-runtime package, in the public domain -//Used by webview - -//The GUIDs are currently not defined in either mingw or mingw-w64 - -#ifdef __MINGW32__ -DEFINE_GUID(IID_IInternetProtocolRoot,0x79eac9e3,0xbaf9,0x11ce,0x8c,0x82,0,0xaa,0,0x4b,0xa9,0xb); -DEFINE_GUID(IID_IInternetProtocol,0x79eac9e4,0xbaf9,0x11ce,0x8c,0x82,0,0xaa,0,0x4b,0xa9,0xb); -#endif - - -#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) - -#define REFRESH_NORMAL 0 -#define REFRESH_COMPLETELY 3 - -EXTERN_C const IID CLSID_FileProtocol; - - -typedef enum __MIDL_IBindStatusCallback_0006 -{ - BSCF_FIRSTDATANOTIFICATION = 0x1, - BSCF_INTERMEDIATEDATANOTIFICATION = 0x2, - BSCF_LASTDATANOTIFICATION = 0x4, - BSCF_DATAFULLYAVAILABLE = 0x8, - BSCF_AVAILABLEDATASIZEUNKNOWN = 0x10 -} BSCF; - -typedef struct _tagPROTOCOLDATA -{ - DWORD grfFlags; - DWORD dwState; - LPVOID pData; - ULONG cbData; -} PROTOCOLDATA; - -typedef struct _tagBINDINFO -{ - ULONG cbSize; - LPWSTR szExtraInfo; - STGMEDIUM stgmedData; - DWORD grfBindInfoF; - DWORD dwBindVerb; - LPWSTR szCustomVerb; - DWORD cbstgmedData; - DWORD dwOptions; - DWORD dwOptionsFlags; - DWORD dwCodePage; - SECURITY_ATTRIBUTES securityAttributes; - IID iid; - IUnknown *pUnk; - DWORD dwReserved; -} BINDINFO; - - -struct IInternetBindInfo : public IUnknown -{ -public: - virtual HRESULT WINAPI GetBindInfo(DWORD *grfBINDF,BINDINFO *pbindinfo) = 0; - virtual HRESULT WINAPI GetBindString(ULONG ulStringType,LPOLESTR *ppwzStr, - ULONG cEl,ULONG *pcElFetched) = 0; -}; - -struct IInternetProtocolSink : public IUnknown -{ -public: - virtual HRESULT WINAPI Switch(PROTOCOLDATA *pProtocolData) = 0; - virtual HRESULT WINAPI ReportProgress(ULONG ulStatusCode, - LPCWSTR szStatusText) = 0; - virtual HRESULT WINAPI ReportData(DWORD grfBSCF,ULONG ulProgress, - ULONG ulProgressMax) = 0; - virtual HRESULT WINAPI ReportResult(HRESULT hrResult,DWORD dwError, - LPCWSTR szResult) = 0; -}; - -struct IInternetProtocolRoot : public IUnknown -{ -public: - virtual HRESULT WINAPI Start(LPCWSTR szUrl,IInternetProtocolSink *pOIProtSink, - IInternetBindInfo *pOIBindInfo,DWORD grfPI, - HANDLE_PTR dwReserved) = 0; - virtual HRESULT WINAPI Continue(PROTOCOLDATA *pProtocolData) = 0; - virtual HRESULT WINAPI Abort(HRESULT hrReason,DWORD dwOptions) = 0; - virtual HRESULT WINAPI Terminate(DWORD dwOptions) = 0; - virtual HRESULT WINAPI Suspend(void) = 0; - virtual HRESULT WINAPI Resume(void) = 0; -}; - -struct IInternetProtocol : public IInternetProtocolRoot -{ -public: - virtual HRESULT WINAPI Read(void *pv,ULONG cb,ULONG *pcbRead) = 0; - virtual HRESULT WINAPI Seek(LARGE_INTEGER dlibMove,DWORD dwOrigin, - ULARGE_INTEGER *plibNewPosition) = 0; - virtual HRESULT WINAPI LockRequest(DWORD dwOptions) = 0; - virtual HRESULT WINAPI UnlockRequest(void) = 0; -}; - -struct IInternetSession : public IUnknown -{ - public: - virtual HRESULT WINAPI RegisterNameSpace(IClassFactory *pCF,REFCLSID rclsid, - LPCWSTR pwzProtocol, - ULONG cPatterns, - const LPCWSTR *ppwzPatterns, - DWORD dwReserved) = 0; - virtual HRESULT WINAPI UnregisterNameSpace(IClassFactory *pCF, - LPCWSTR pszProtocol) = 0; - virtual HRESULT WINAPI RegisterMimeFilter(IClassFactory *pCF, - REFCLSID rclsid, - LPCWSTR pwzType) = 0; - virtual HRESULT WINAPI UnregisterMimeFilter(IClassFactory *pCF, - LPCWSTR pwzType) = 0; - virtual HRESULT WINAPI CreateBinding(LPBC pBC,LPCWSTR szUrl, - IUnknown *pUnkOuter,IUnknown **ppUnk, - IInternetProtocol **ppOInetProt, - DWORD dwOption) = 0; - virtual HRESULT WINAPI SetSessionOption(DWORD dwOption,LPVOID pBuffer, - DWORD dwBufferLength, - DWORD dwReserved) = 0; - virtual HRESULT WINAPI GetSessionOption(DWORD dwOption,LPVOID pBuffer, - DWORD *pdwBufferLength, - DWORD dwReserved) = 0; -}; - #endif /* diff --git a/include/wx/msw/webview_ie.h b/include/wx/msw/webview_ie.h index ce784c9be0..80eeaa3285 100644 --- a/include/wx/msw/webview_ie.h +++ b/include/wx/msw/webview_ie.h @@ -22,6 +22,132 @@ #include "wx/sharedptr.h" #include "wx/vector.h" +/* Classes and definitions from urlmon.h vary in their + * completeness between compilers and versions of compilers. + * We implement our own versions here which should work + * for all compilers. The definitions are taken from the + * mingw-w64 headers which are public domain. + */ + +#ifndef REFRESH_NORMAL +#define REFRESH_NORMAL 0 +#endif + +#ifndef REFRESH_COMPLETELY +#define REFRESH_COMPLETELY 3 +#endif + +typedef enum __wxMIDL_IBindStatusCallback_0006 +{ + wxBSCF_FIRSTDATANOTIFICATION = 0x1, + wxBSCF_INTERMEDIATEDATANOTIFICATION = 0x2, + wxBSCF_LASTDATANOTIFICATION = 0x4, + wxBSCF_DATAFULLYAVAILABLE = 0x8, + wxBSCF_AVAILABLEDATASIZEUNKNOWN = 0x10 +} wxBSCF; + +EXTERN_C const IID CLSID_FileProtocol; + +typedef struct _tagwxBINDINFO +{ + ULONG cbSize; + LPWSTR szExtraInfo; + STGMEDIUM stgmedData; + DWORD grfBindInfoF; + DWORD dwBindVerb; + LPWSTR szCustomVerb; + DWORD cbstgmedData; + DWORD dwOptions; + DWORD dwOptionsFlags; + DWORD dwCodePage; + SECURITY_ATTRIBUTES securityAttributes; + IID iid; + IUnknown *pUnk; + DWORD dwReserved; +} wxBINDINFO; + +typedef struct _tagwxPROTOCOLDATA +{ + DWORD grfFlags; + DWORD dwState; + LPVOID pData; + ULONG cbData; +} wxPROTOCOLDATA; + +class wxIInternetBindInfo : public IUnknown +{ +public: + virtual HRESULT wxSTDCALL GetBindInfo(DWORD *grfBINDF,wxBINDINFO *pbindinfo) = 0; + virtual HRESULT wxSTDCALL GetBindString(ULONG ulStringType,LPOLESTR *ppwzStr, + ULONG cEl,ULONG *pcElFetched) = 0; +}; + +class wxIInternetProtocolSink : public IUnknown +{ +public: + virtual HRESULT wxSTDCALL Switch(wxPROTOCOLDATA *pProtocolData) = 0; + virtual HRESULT wxSTDCALL ReportProgress(ULONG ulStatusCode, + LPCWSTR szStatusText) = 0; + virtual HRESULT wxSTDCALL ReportData(DWORD grfBSCF,ULONG ulProgress, + ULONG ulProgressMax) = 0; + virtual HRESULT wxSTDCALL ReportResult(HRESULT hrResult,DWORD dwError, + LPCWSTR szResult) = 0; +}; + +class wxIInternetProtocolRoot : public IUnknown +{ +public: + virtual HRESULT wxSTDCALL Start(LPCWSTR szUrl,wxIInternetProtocolSink *pOIProtSink, + wxIInternetBindInfo *pOIBindInfo,DWORD grfPI, + HANDLE_PTR dwReserved) = 0; + virtual HRESULT wxSTDCALL Continue(wxPROTOCOLDATA *pProtocolData) = 0; + virtual HRESULT wxSTDCALL Abort(HRESULT hrReason,DWORD dwOptions) = 0; + virtual HRESULT wxSTDCALL Terminate(DWORD dwOptions) = 0; + virtual HRESULT wxSTDCALL Suspend(void) = 0; + virtual HRESULT wxSTDCALL Resume(void) = 0; +}; + + +class wxIInternetProtocol : public wxIInternetProtocolRoot +{ +public: + virtual HRESULT wxSTDCALL Read(void *pv,ULONG cb,ULONG *pcbRead) = 0; + virtual HRESULT wxSTDCALL Seek(LARGE_INTEGER dlibMove,DWORD dwOrigin, + ULARGE_INTEGER *plibNewPosition) = 0; + virtual HRESULT wxSTDCALL LockRequest(DWORD dwOptions) = 0; + virtual HRESULT wxSTDCALL UnlockRequest(void) = 0; +}; + + +class wxIInternetSession : public IUnknown +{ + public: + virtual HRESULT wxSTDCALL RegisterNameSpace(IClassFactory *pCF,REFCLSID rclsid, + LPCWSTR pwzProtocol, + ULONG cPatterns, + const LPCWSTR *ppwzPatterns, + DWORD dwReserved) = 0; + virtual HRESULT wxSTDCALL UnregisterNameSpace(IClassFactory *pCF, + LPCWSTR pszProtocol) = 0; + virtual HRESULT wxSTDCALL RegisterMimeFilter(IClassFactory *pCF, + REFCLSID rclsid, + LPCWSTR pwzType) = 0; + virtual HRESULT wxSTDCALL UnregisterMimeFilter(IClassFactory *pCF, + LPCWSTR pwzType) = 0; + virtual HRESULT wxSTDCALL CreateBinding(LPBC pBC,LPCWSTR szUrl, + IUnknown *pUnkOuter,IUnknown **ppUnk, + wxIInternetProtocol **ppOInetProt, + DWORD dwOption) = 0; + virtual HRESULT wxSTDCALL SetSessionOption(DWORD dwOption,LPVOID pBuffer, + DWORD dwBufferLength, + DWORD dwReserved) = 0; + virtual HRESULT wxSTDCALL GetSessionOption(DWORD dwOption,LPVOID pBuffer, + DWORD *pdwBufferLength, + DWORD dwReserved) = 0; +}; + +/* END OF URLMON.H implementation */ + struct IHTMLDocument2; class wxFSFile; class ClassFactory; @@ -165,11 +291,11 @@ private: wxDECLARE_DYNAMIC_CLASS(wxWebViewIE); }; -class VirtualProtocol : public IInternetProtocol +class VirtualProtocol : public wxIInternetProtocol { protected: ULONG m_refCount; - IInternetProtocolSink* m_protocolSink; + wxIInternetProtocolSink* m_protocolSink; wxString m_html; VOID * fileP; @@ -189,12 +315,12 @@ public: HRESULT STDMETHODCALLTYPE Abort(HRESULT WXUNUSED(hrReason), DWORD WXUNUSED(dwOptions)) { return E_NOTIMPL; } - HRESULT STDMETHODCALLTYPE Continue(PROTOCOLDATA *WXUNUSED(pProtocolData)) + HRESULT STDMETHODCALLTYPE Continue(wxPROTOCOLDATA *WXUNUSED(pProtocolData)) { return S_OK; } HRESULT STDMETHODCALLTYPE Resume() { return S_OK; } HRESULT STDMETHODCALLTYPE Start(LPCWSTR szUrl, - IInternetProtocolSink *pOIProtSink, - IInternetBindInfo *pOIBindInfo, + wxIInternetProtocolSink *pOIProtSink, + wxIInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved); HRESULT STDMETHODCALLTYPE Suspend() { return S_OK; } diff --git a/src/msw/webview_ie.cpp b/src/msw/webview_ie.cpp index 710b48e2a7..76c4583333 100644 --- a/src/msw/webview_ie.cpp +++ b/src/msw/webview_ie.cpp @@ -27,6 +27,18 @@ #include "wx/msw/missing.h" #include "wx/filesys.h" #include "wx/dynlib.h" +#include + +/* These GUID definitions are our own implementation to support interfaces + * normally in urlmon.h. See include/wx/msw/webview_ie.h + */ + +namespace { + +DEFINE_GUID(wxIID_IInternetProtocolRoot,0x79eac9e3,0xbaf9,0x11ce,0x8c,0x82,0,0xaa,0,0x4b,0xa9,0xb); +DEFINE_GUID(wxIID_IInternetProtocol,0x79eac9e4,0xbaf9,0x11ce,0x8c,0x82,0,0xaa,0,0x4b,0xa9,0xb); + +} wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewIE, wxWebView); @@ -698,11 +710,11 @@ void wxWebViewIE::RegisterHandler(wxSharedPtr handler) wxDynamicLibrary urlMon(wxT("urlmon.dll")); if(urlMon.HasSymbol(wxT("CoInternetGetSession"))) { - typedef HRESULT (WINAPI *CoInternetGetSession_t)(DWORD, IInternetSession**, DWORD); + typedef HRESULT (WINAPI *CoInternetGetSession_t)(DWORD, wxIInternetSession**, DWORD); wxDYNLIB_FUNCTION(CoInternetGetSession_t, CoInternetGetSession, urlMon); ClassFactory* cf = new ClassFactory(handler); - IInternetSession* session; + wxIInternetSession* session; HRESULT res = (*pfnCoInternetGetSession)(0, &session, 0); if(FAILED(res)) { @@ -1034,10 +1046,10 @@ ULONG VirtualProtocol::AddRef() HRESULT VirtualProtocol::QueryInterface(REFIID riid, void **ppvObject) { - if(riid == IID_IUnknown || riid == IID_IInternetProtocolRoot || - riid == IID_IInternetProtocol) + if(riid == IID_IUnknown || riid == wxIID_IInternetProtocolRoot || + riid == wxIID_IInternetProtocol) { - *ppvObject = (IInternetProtocol*)this; + *ppvObject = (wxIInternetProtocol*)this; AddRef(); return S_OK; } @@ -1062,8 +1074,8 @@ ULONG VirtualProtocol::Release() } } -HRESULT VirtualProtocol::Start(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSink, - IInternetBindInfo *pOIBindInfo, DWORD grfPI, +HRESULT VirtualProtocol::Start(LPCWSTR szUrl, wxIInternetProtocolSink *pOIProtSink, + wxIInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved) { wxUnusedVar(szUrl); @@ -1082,9 +1094,9 @@ HRESULT VirtualProtocol::Start(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSink //We return the stream length for current and total size as we can always //read the whole file from the stream wxFileOffset length = m_file->GetStream()->GetLength(); - m_protocolSink->ReportData(BSCF_FIRSTDATANOTIFICATION | - BSCF_DATAFULLYAVAILABLE | - BSCF_LASTDATANOTIFICATION, + m_protocolSink->ReportData(wxBSCF_FIRSTDATANOTIFICATION | + wxBSCF_DATAFULLYAVAILABLE | + wxBSCF_LASTDATANOTIFICATION, length, length); return S_OK; } -- 2.45.2