Implement user agent access for GTK

This commit is contained in:
Tobias Taschner
2021-03-16 15:37:37 +01:00
parent 18f5b01cc6
commit 7f7191066b
2 changed files with 17 additions and 0 deletions

View File

@@ -81,6 +81,7 @@ public:
#if wxUSE_WEBVIEW_WEBKIT2
virtual void EnableAccessToDevTools(bool enable = true) wxOVERRIDE;
virtual bool IsAccessToDevToolsEnabled() const wxOVERRIDE;
virtual bool SetUserAgent(const wxString& userAgent) wxOVERRIDE;
#endif
void SetZoomType(wxWebViewZoomType) wxOVERRIDE;
@@ -176,6 +177,7 @@ private:
#endif
WebKitWebView *m_web_view;
wxString m_customUserAgent;
int m_historyLimit;
wxVector<wxSharedPtr<wxWebViewHandler> > m_handlerList;

View File

@@ -651,6 +651,9 @@ bool wxWebViewWebKit::Create(wxWindow *parent,
GTKCreateScrolledWindowWith(GTK_WIDGET(m_web_view));
g_object_ref(m_widget);
if (!m_customUserAgent.empty())
SetUserAgent(m_customUserAgent);
g_signal_connect(m_web_view, "decide-policy",
G_CALLBACK(wxgtk_webview_webkit_decide_policy),
this);
@@ -756,6 +759,18 @@ bool wxWebViewWebKit::IsAccessToDevToolsEnabled() const
return webkit_settings_get_enable_developer_extras(settings);
}
bool wxWebViewWebKit::SetUserAgent(const wxString& userAgent)
{
if (m_web_view)
{
WebKitSettings* settings = webkit_web_view_get_settings(m_web_view);
webkit_settings_set_user_agent(settings, userAgent.utf8_str());
}
else
m_customUserAgent = userAgent;
return true;
}
void wxWebViewWebKit::Stop()
{
webkit_web_view_stop_loading(m_web_view);