From dc585039bbd426829e3433002023a93f9bedd0c2 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Tue, 28 Jul 2020 20:42:09 +0200 Subject: [PATCH 1/6] CMake: copy resources required for webview sample --- build/cmake/samples/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/cmake/samples/CMakeLists.txt b/build/cmake/samples/CMakeLists.txt index 0f02941a74..93013071fe 100644 --- a/build/cmake/samples/CMakeLists.txt +++ b/build/cmake/samples/CMakeLists.txt @@ -152,7 +152,8 @@ wx_add_sample(typetest typetest.cpp typetest.h) wx_add_sample(uiaction DEPENDS wxUSE_UIACTIONSIMULATOR) wx_add_sample(validate validate.cpp validate.h DEPENDS wxUSE_VALIDATORS) 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) wx_exe_link_libraries(webviewsample wxstc) endif() From 0885057b707a84c99e3f168f6b0835060354357c Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Tue, 28 Jul 2020 20:42:56 +0200 Subject: [PATCH 2/6] Fix typo in wxWebViewIE failure message --- src/msw/webview_ie.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/msw/webview_ie.cpp b/src/msw/webview_ie.cpp index 6b40fbf820..259b4f0959 100644 --- a/src/msw/webview_ie.cpp +++ b/src/msw/webview_ie.cpp @@ -1077,7 +1077,7 @@ void wxWebViewIE::RegisterHandler(wxSharedPtr handler) HRESULT res = (*pfnCoInternetGetSession)(0, &session, 0); if(FAILED(res)) { - wxFAIL_MSG("Could not retrive internet session"); + wxFAIL_MSG("Could not retrieve internet session"); } HRESULT hr = session->RegisterNameSpace(cf, CLSID_FileProtocol, From bcadef5e2cfbf8039ec21a278d800d6b2a3ea95d Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Tue, 28 Jul 2020 20:44:33 +0200 Subject: [PATCH 3/6] Remove obsolete VirtualProtocol IID table The IIDs are now checked inside VirtualProtocol::QueryInterface. --- src/msw/webview_ie.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/msw/webview_ie.cpp b/src/msw/webview_ie.cpp index 259b4f0959..4ca3abdc26 100644 --- a/src/msw/webview_ie.cpp +++ b/src/msw/webview_ie.cpp @@ -1616,12 +1616,6 @@ VirtualProtocol::VirtualProtocol(wxSharedPtr 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) { wxLogQueryInterface(wxT("VirtualProtocol"), riid); From 300fe1a6f9548a60ec76ea0e74dd057ab6360673 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Tue, 28 Jul 2020 20:55:08 +0200 Subject: [PATCH 4/6] Add option to wxWebViewHandler to set a custom security URL This will be used by wxWebViewIE to modify the security URL and domain when parsing a URL. --- include/wx/webview.h | 6 +++++- interface/wx/webview.h | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/wx/webview.h b/include/wx/webview.h index 5fb30dc352..53c78122c2 100644 --- a/include/wx/webview.h +++ b/include/wx/webview.h @@ -89,12 +89,16 @@ enum wxWebViewNavigationActionFlags class WXDLLIMPEXP_WEBVIEW wxWebViewHandler { public: - wxWebViewHandler(const wxString& scheme) : m_scheme(scheme) {} + wxWebViewHandler(const wxString& scheme) + : m_scheme(scheme), m_securityURL() {} virtual ~wxWebViewHandler() {} virtual wxString GetName() const { return m_scheme; } virtual wxFSFile* GetFile(const wxString &uri) = 0; + virtual void SetSecurityURL(const wxString& url) { m_securityURL = url; } + virtual wxString GetSecurityURL() const { return m_securityURL; } private: wxString m_scheme; + wxString m_securityURL; }; extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewNameStr[]; diff --git a/interface/wx/webview.h b/interface/wx/webview.h index b2a05d1c26..b870fbfcd2 100644 --- a/interface/wx/webview.h +++ b/interface/wx/webview.h @@ -252,6 +252,20 @@ public: @return The name of the scheme, as passed to the constructor. */ 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; }; /** From 43f84a9c18ece7ada66cd11bf028ff547ec98ce1 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Tue, 28 Jul 2020 21:01:12 +0200 Subject: [PATCH 5/6] Use security URL from wxWebViewHandler in wxWebViewIE Don't use hard-coded 'http://localhost', but use the URL specified in the wxWebViewHandler. By default, the security URL is empty and no modifications are made when parsing a URL. This fixes using JavaScript in pages loaded with a custom protocol, e.g. from wxWebViewFSHandler or wxWebViewArchiveHandler. Closes #17893 --- src/msw/webview_ie.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/msw/webview_ie.cpp b/src/msw/webview_ie.cpp index 4ca3abdc26..cc85f27c5b 100644 --- a/src/msw/webview_ie.cpp +++ b/src/msw/webview_ie.cpp @@ -1762,25 +1762,23 @@ HRESULT STDMETHODCALLTYPE VirtualProtocol::ParseUrl( DWORD dwReserved) { wxUnusedVar(pwzUrl); - wxUnusedVar(ParseAction); wxUnusedVar(dwParseFlags); - wxUnusedVar(pwzResult); - wxUnusedVar(cchResult); - wxUnusedVar(pcchResult); wxUnusedVar(dwReserved); - switch (ParseAction) + const size_t secLen = m_handler->GetSecurityURL().length(); + if ( secLen > 0 ) { - case wxPARSE_SECURITY_URL: - case wxPARSE_SECURITY_DOMAIN: + switch ( ParseAction ) { - const wchar_t Result[] = L"http://localhost"; - size_t Len = wcslen(Result); - if(cchResult <= Len) - return S_FALSE; - wcscpy(pwzResult, Result); - *pcchResult = Len; - return S_OK; + case wxPARSE_SECURITY_URL: + case wxPARSE_SECURITY_DOMAIN: + { + if ( cchResult <= secLen ) + return S_FALSE; + wcscpy(pwzResult, m_handler->GetSecurityURL().wc_str()); + *pcchResult = secLen; + return S_OK; + } } } From 785c4488708b2c444ecf1ec25423b72239a77a9c Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Tue, 28 Jul 2020 21:05:17 +0200 Subject: [PATCH 6/6] Fix checking size of security URL in wxWebviewIE Allows to utilize the entire buffer when necessary. --- src/msw/webview_ie.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/msw/webview_ie.cpp b/src/msw/webview_ie.cpp index cc85f27c5b..96847b1a01 100644 --- a/src/msw/webview_ie.cpp +++ b/src/msw/webview_ie.cpp @@ -1773,7 +1773,7 @@ HRESULT STDMETHODCALLTYPE VirtualProtocol::ParseUrl( case wxPARSE_SECURITY_URL: case wxPARSE_SECURITY_DOMAIN: { - if ( cchResult <= secLen ) + if ( cchResult < secLen ) return S_FALSE; wcscpy(pwzResult, m_handler->GetSecurityURL().wc_str()); *pcchResult = secLen;