diff --git a/include/wx/msw/webview_edge.h b/include/wx/msw/webview_edge.h index 3e4d476599..3683a168de 100644 --- a/include/wx/msw/webview_edge.h +++ b/include/wx/msw/webview_edge.h @@ -94,6 +94,8 @@ public: virtual bool SetUserAgent(const wxString& userAgent) override; virtual wxString GetUserAgent() const override; + virtual bool SetProxy(const wxString& proxy) override; + virtual bool RunScript(const wxString& javascript, wxString* output = nullptr) const override; virtual void RunScriptAsync(const wxString& javascript, void* clientData = nullptr) const override; virtual bool AddScriptMessageHandler(const wxString& name) override; diff --git a/interface/wx/webview.h b/interface/wx/webview.h index eac72b8ded..da27d946c3 100644 --- a/interface/wx/webview.h +++ b/interface/wx/webview.h @@ -1217,7 +1217,8 @@ public: The @a proxy string must be a valid proxy specification, e.g. @c http://my.local.proxy.corp:8080 - @note Currently this function is only implemented in WebKit2 backend. + @note Currently this function is only implemented in WebKit2 and Edge + backends and must be called before Create() for the latter one. @return @true if proxy was set successfully or @false if it failed, e.g. because this is not supported by the currently used backend. diff --git a/samples/webview/webview.cpp b/samples/webview/webview.cpp index 382e782549..16079ace90 100644 --- a/samples/webview/webview.cpp +++ b/samples/webview/webview.cpp @@ -423,6 +423,17 @@ WebFrame::WebFrame(const wxString& url, bool isMain, wxWebViewWindowFeatures* wi #endif // Create the webview m_browser = (windowFeatures) ? windowFeatures->GetChildWebView() : wxWebView::New(); + +#if wxUSE_WEBVIEW_EDGE + // With Edge the proxy can only be set before creation, so do it here. + if (wxWebView::IsBackendAvailable(wxWebViewBackendEdge)) + { + wxString proxy; + if (wxGetEnv("http_proxy", &proxy)) + m_browser->SetProxy(proxy); + } +#endif // wxUSE_WEBVIEW_EDGE + #ifdef __WXMAC__ if (m_isMainFrame) { diff --git a/src/msw/webview_edge.cpp b/src/msw/webview_edge.cpp index 1dae4dc9c8..adaaefb1e0 100644 --- a/src/msw/webview_edge.cpp +++ b/src/msw/webview_edge.cpp @@ -268,6 +268,22 @@ public: #endif } + bool SetProxy(const wxString& proxy) + { +#ifdef __VISUALC__ + m_webViewEnvironmentOptions->put_AdditionalBrowserArguments( + wxString::Format("--proxy-server=\"%s\"", proxy).wc_str() + ); + return true; +#else + wxUnusedVar(proxy); + + wxLogError(_("This program was compiled without support for setting Edge proxy.")); + + return false; +#endif + } + virtual void* GetNativeConfiguration() const override { return m_webViewEnvironmentOptions; @@ -1358,6 +1374,16 @@ wxString wxWebViewEdge::GetUserAgent() const } +bool wxWebViewEdge::SetProxy(const wxString& proxy) +{ + wxCHECK_MSG(!m_impl->m_webViewController, false, + "Proxy must be set before calling Create()"); + + auto configImpl = static_cast(m_impl->m_config.GetImpl()); + + return configImpl->SetProxy(proxy); +} + void* wxWebViewEdge::GetNativeBackend() const { return m_impl->m_webView;