Fix using JavaScript in wxWebViewIE with custom scheme.

This repairs a regression in 3.1.4 due to the changes of 6787b0548b
(Merge branch 'webview-ie-fixes', 2020-07-23).

See https://github.com/wxWidgets/wxWidgets/pull/2004
This commit is contained in:
Vadim Zeitlin
2020-08-14 19:23:27 +02:00
4 changed files with 34 additions and 23 deletions

View File

@@ -152,7 +152,8 @@ wx_add_sample(typetest typetest.cpp typetest.h)
wx_add_sample(uiaction DEPENDS wxUSE_UIACTIONSIMULATOR) wx_add_sample(uiaction DEPENDS wxUSE_UIACTIONSIMULATOR)
wx_add_sample(validate validate.cpp validate.h DEPENDS wxUSE_VALIDATORS) wx_add_sample(validate validate.cpp validate.h DEPENDS wxUSE_VALIDATORS)
wx_add_sample(vscroll vstest.cpp) wx_add_sample(vscroll vstest.cpp)
wx_add_sample(webview LIBRARIES wxwebview NAME webviewsample DEPENDS wxUSE_WEBVIEW) wx_add_sample(webview LIBRARIES wxwebview DATA ../help/doc.zip:doc.zip
NAME webviewsample DEPENDS wxUSE_WEBVIEW)
if(TARGET webviewsample AND wxUSE_STC) if(TARGET webviewsample AND wxUSE_STC)
wx_exe_link_libraries(webviewsample wxstc) wx_exe_link_libraries(webviewsample wxstc)
endif() endif()

View File

@@ -89,12 +89,16 @@ enum wxWebViewNavigationActionFlags
class WXDLLIMPEXP_WEBVIEW wxWebViewHandler class WXDLLIMPEXP_WEBVIEW wxWebViewHandler
{ {
public: public:
wxWebViewHandler(const wxString& scheme) : m_scheme(scheme) {} wxWebViewHandler(const wxString& scheme)
: m_scheme(scheme), m_securityURL() {}
virtual ~wxWebViewHandler() {} virtual ~wxWebViewHandler() {}
virtual wxString GetName() const { return m_scheme; } virtual wxString GetName() const { return m_scheme; }
virtual wxFSFile* GetFile(const wxString &uri) = 0; virtual wxFSFile* GetFile(const wxString &uri) = 0;
virtual void SetSecurityURL(const wxString& url) { m_securityURL = url; }
virtual wxString GetSecurityURL() const { return m_securityURL; }
private: private:
wxString m_scheme; wxString m_scheme;
wxString m_securityURL;
}; };
extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewNameStr[]; extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewNameStr[];

View File

@@ -252,6 +252,20 @@ public:
@return The name of the scheme, as passed to the constructor. @return The name of the scheme, as passed to the constructor.
*/ */
virtual wxString GetName() const; virtual wxString GetName() const;
/**
Sets a custom security URL. Only used by wxWebViewIE.
@since 3.1.5
*/
virtual void SetSecurityURL(const wxString& url);
/**
@return The custom security URL. Only used by wxWebViewIE.
@since 3.1.5
*/
virtual wxString GetSecurityURL() const;
}; };
/** /**

View File

@@ -1077,7 +1077,7 @@ void wxWebViewIE::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
HRESULT res = (*pfnCoInternetGetSession)(0, &session, 0); HRESULT res = (*pfnCoInternetGetSession)(0, &session, 0);
if(FAILED(res)) if(FAILED(res))
{ {
wxFAIL_MSG("Could not retrive internet session"); wxFAIL_MSG("Could not retrieve internet session");
} }
HRESULT hr = session->RegisterNameSpace(cf, CLSID_FileProtocol, HRESULT hr = session->RegisterNameSpace(cf, CLSID_FileProtocol,
@@ -1616,12 +1616,6 @@ VirtualProtocol::VirtualProtocol(wxSharedPtr<wxWebViewHandler> handler)
m_handler = handler; m_handler = handler;
} }
BEGIN_IID_TABLE(VirtualProtocol)
ADD_IID(Unknown)
ADD_RAW_IID(wxIID_IInternetProtocolRoot)
ADD_RAW_IID(wxIID_IInternetProtocol)
END_IID_TABLE;
STDMETHODIMP VirtualProtocol::QueryInterface(REFIID riid, void **ppv) STDMETHODIMP VirtualProtocol::QueryInterface(REFIID riid, void **ppv)
{ {
wxLogQueryInterface(wxT("VirtualProtocol"), riid); wxLogQueryInterface(wxT("VirtualProtocol"), riid);
@@ -1768,25 +1762,23 @@ HRESULT STDMETHODCALLTYPE VirtualProtocol::ParseUrl(
DWORD dwReserved) DWORD dwReserved)
{ {
wxUnusedVar(pwzUrl); wxUnusedVar(pwzUrl);
wxUnusedVar(ParseAction);
wxUnusedVar(dwParseFlags); wxUnusedVar(dwParseFlags);
wxUnusedVar(pwzResult);
wxUnusedVar(cchResult);
wxUnusedVar(pcchResult);
wxUnusedVar(dwReserved); wxUnusedVar(dwReserved);
switch (ParseAction) const size_t secLen = m_handler->GetSecurityURL().length();
if ( secLen > 0 )
{ {
case wxPARSE_SECURITY_URL: switch ( ParseAction )
case wxPARSE_SECURITY_DOMAIN:
{ {
const wchar_t Result[] = L"http://localhost"; case wxPARSE_SECURITY_URL:
size_t Len = wcslen(Result); case wxPARSE_SECURITY_DOMAIN:
if(cchResult <= Len) {
return S_FALSE; if ( cchResult < secLen )
wcscpy(pwzResult, Result); return S_FALSE;
*pcchResult = Len; wcscpy(pwzResult, m_handler->GetSecurityURL().wc_str());
return S_OK; *pcchResult = secLen;
return S_OK;
}
} }
} }