Add wxWebView methods to enable dev tools
Currently only implemented for the Edge (Chromium) backend.
This commit is contained in:
@@ -111,6 +111,9 @@ public:
|
||||
virtual void EnableContextMenu(bool enable = true) wxOVERRIDE;
|
||||
virtual bool IsContextMenuEnabled() const wxOVERRIDE;
|
||||
|
||||
virtual void EnableDevTools(bool enable = true) wxOVERRIDE;
|
||||
virtual bool IsDevToolsEnabled() const wxOVERRIDE;
|
||||
|
||||
virtual bool RunScript(const wxString& javascript, wxString* output = NULL) wxOVERRIDE;
|
||||
|
||||
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) wxOVERRIDE;
|
||||
|
@@ -159,6 +159,7 @@ public:
|
||||
{
|
||||
m_showMenu = enable;
|
||||
}
|
||||
virtual void EnableDevTools(bool WXUNUSED(enable) = true) { }
|
||||
virtual wxString GetCurrentTitle() const = 0;
|
||||
virtual wxString GetCurrentURL() const = 0;
|
||||
// TODO: handle choosing a frame when calling GetPageSource()?
|
||||
@@ -166,6 +167,7 @@ public:
|
||||
virtual wxString GetPageText() const = 0;
|
||||
virtual bool IsBusy() const = 0;
|
||||
virtual bool IsContextMenuEnabled() const { return m_showMenu; }
|
||||
virtual bool IsDevToolsEnabled() const { return false; }
|
||||
virtual bool IsEditable() const = 0;
|
||||
virtual void LoadURL(const wxString& url) = 0;
|
||||
virtual void Print() = 0;
|
||||
|
@@ -687,6 +687,27 @@ public:
|
||||
*/
|
||||
virtual bool IsContextMenuEnabled() const;
|
||||
|
||||
/**
|
||||
@name Dev Tools
|
||||
*/
|
||||
|
||||
/**
|
||||
Enable or disable access to dev tools for the user.
|
||||
|
||||
This is currently only implemented for the Edge (Chromium) backend
|
||||
where the dev tools are enabled by default.
|
||||
|
||||
@since 3.1.4
|
||||
*/
|
||||
virtual void EnableDevTools(bool enable = true);
|
||||
|
||||
/**
|
||||
Returns @true if dev tools are available to the user.
|
||||
|
||||
@since 3.1.4
|
||||
*/
|
||||
virtual bool IsDevToolsEnabled() const;
|
||||
|
||||
/**
|
||||
@name History
|
||||
*/
|
||||
|
@@ -164,6 +164,7 @@ public:
|
||||
void OnFindText(wxCommandEvent& evt);
|
||||
void OnFindOptions(wxCommandEvent& evt);
|
||||
void OnEnableContextMenu(wxCommandEvent& evt);
|
||||
void OnEnableDevTools(wxCommandEvent& evt);
|
||||
|
||||
private:
|
||||
wxTextCtrl* m_url;
|
||||
@@ -226,6 +227,7 @@ private:
|
||||
wxMenuItem* m_selection_delete;
|
||||
wxMenuItem* m_find;
|
||||
wxMenuItem* m_context_menu;
|
||||
wxMenuItem* m_dev_tools;
|
||||
|
||||
wxInfoBar *m_info;
|
||||
wxStaticText* m_info_text;
|
||||
@@ -468,6 +470,7 @@ WebFrame::WebFrame(const wxString& url) :
|
||||
wxMenuItem* usememoryfs = m_tools_menu->Append(wxID_ANY, _("Memory File System Example"));
|
||||
|
||||
m_context_menu = m_tools_menu->AppendCheckItem(wxID_ANY, _("Enable Context Menu"));
|
||||
m_dev_tools = m_tools_menu->AppendCheckItem(wxID_ANY, _("Enable Dev Tools"));
|
||||
|
||||
//By default we want to handle navigation and new windows
|
||||
m_tools_handle_navigation->Check();
|
||||
@@ -549,6 +552,7 @@ WebFrame::WebFrame(const wxString& url) :
|
||||
Bind(wxEVT_MENU, &WebFrame::OnUseMemoryFS, this, usememoryfs->GetId());
|
||||
Bind(wxEVT_MENU, &WebFrame::OnFind, this, m_find->GetId());
|
||||
Bind(wxEVT_MENU, &WebFrame::OnEnableContextMenu, this, m_context_menu->GetId());
|
||||
Bind(wxEVT_MENU, &WebFrame::OnEnableDevTools, this, m_dev_tools->GetId());
|
||||
|
||||
//Connect the idle events
|
||||
Bind(wxEVT_IDLE, &WebFrame::OnIdle, this);
|
||||
@@ -710,6 +714,11 @@ void WebFrame::OnEnableContextMenu(wxCommandEvent& evt)
|
||||
m_browser->EnableContextMenu(evt.IsChecked());
|
||||
}
|
||||
|
||||
void WebFrame::OnEnableDevTools(wxCommandEvent& evt)
|
||||
{
|
||||
m_browser->EnableDevTools(evt.IsChecked());
|
||||
}
|
||||
|
||||
void WebFrame::OnFind(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
wxString value = m_browser->GetSelectedText();
|
||||
@@ -943,6 +952,7 @@ void WebFrame::OnToolsClicked(wxCommandEvent& WXUNUSED(evt))
|
||||
m_selection_delete->Enable(m_browser->HasSelection());
|
||||
|
||||
m_context_menu->Check(m_browser->IsContextMenuEnabled());
|
||||
m_dev_tools->Check(m_browser->IsDevToolsEnabled());
|
||||
|
||||
//Firstly we clear the existing menu items, then we add the current ones
|
||||
wxMenuHistoryMap::const_iterator it;
|
||||
|
@@ -49,8 +49,7 @@ typedef HRESULT(__stdcall *PFNWXGetWebView2BrowserVersionInfo)(
|
||||
PFNWXCreateWebView2EnvironmentWithDetails wxCreateWebView2EnvironmentWithDetails = NULL;
|
||||
PFNWXGetWebView2BrowserVersionInfo wxGetWebView2BrowserVersionInfo = NULL;
|
||||
|
||||
int wxWebViewEdgeChromium::ms_isAvailable = -1;
|
||||
wxDynamicLibrary wxWebViewEdgeChromium::ms_loaderDll;
|
||||
wxDynamicLibrary wxWebViewEdge::ms_loaderDll;
|
||||
|
||||
bool wxWebViewEdge::IsAvailable()
|
||||
{
|
||||
@@ -655,6 +654,30 @@ bool wxWebViewEdge::IsContextMenuEnabled() const
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxWebViewEdge::EnableDevTools(bool enable)
|
||||
{
|
||||
wxCOMPtr<IWebView2Settings> settings;
|
||||
if (SUCCEEDED(m_webView->get_Settings(&settings)))
|
||||
{
|
||||
settings->put_AreDevToolsEnabled(enable);
|
||||
}
|
||||
}
|
||||
|
||||
bool wxWebViewEdge::IsDevToolsEnabled() const
|
||||
{
|
||||
wxCOMPtr<IWebView2Settings> settings;
|
||||
if (SUCCEEDED(m_webView->get_Settings(&settings)))
|
||||
{
|
||||
BOOL devToolsEnabled = TRUE;
|
||||
settings->get_AreDevToolsEnabled(&devToolsEnabled);
|
||||
|
||||
if (!devToolsEnabled)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxWebViewEdge::RunScriptSync(const wxString& javascript, wxString* output)
|
||||
{
|
||||
bool scriptExecuted = false;
|
||||
|
Reference in New Issue
Block a user