Integrate CEF MessageLoop to wxWidgets MessageLoop.
* Enable webview_chromium on Linux, webview_chromium runs normally, but browser window is split out of wxWidget window now and we need to host it in wxWidgets window later. * Make cef messageloop processing in wx::ProcessIdle period, this way works on windows and linux. * Don't use multiple_message_loop on Windows.
This commit is contained in:
parent
08fb3979b6
commit
9eca39a928
3 changed files with 56 additions and 8 deletions
|
|
@ -7,7 +7,6 @@
|
|||
#ifndef _WX_WEBVIEWCHROMIUM_H_
|
||||
#define _WX_WEBVIEWCHROMIUM_H_
|
||||
|
||||
#include <wx/wxprec.h>
|
||||
#include <wx/control.h>
|
||||
#include <wx/webview.h>
|
||||
#include <wx/sharedptr.h>
|
||||
|
|
@ -212,10 +211,17 @@ public:
|
|||
//Virtual Filesystem Support
|
||||
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler);
|
||||
|
||||
#ifdef __WXMSW__
|
||||
static bool StartUp(int &code, const wxString &path = "");
|
||||
#else
|
||||
static bool StartUp(int &code, const wxString &path,
|
||||
int argc, char* argv[]);
|
||||
#endif
|
||||
|
||||
// If using a separate subprocess then return the result of this function
|
||||
static int StartUpSubprocess();
|
||||
static void Shutdown();
|
||||
static void RunMessageLoopOnce();
|
||||
|
||||
protected:
|
||||
virtual void DoSetPage(const wxString& html, const wxString& baseUrl);
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ public:
|
|||
|
||||
virtual bool OnInit();
|
||||
virtual int OnExit();
|
||||
virtual bool ProcessIdle();
|
||||
/*
|
||||
#if wxUSE_CMDLINE_PARSER
|
||||
virtual void OnInitCmdLine(wxCmdLineParser& parser)
|
||||
|
|
@ -221,7 +222,12 @@ bool WebApp::OnInit()
|
|||
{
|
||||
// We spawn a separate subprocess
|
||||
int code = 0;
|
||||
#ifdef __WXMSW__
|
||||
if(!wxWebViewChromium::StartUp(code, ""))
|
||||
#else
|
||||
if(!wxWebViewChromium::StartUp(code, "",
|
||||
wxApp::argc, wxApp::argv))
|
||||
#endif
|
||||
exit(code);
|
||||
|
||||
if ( !wxApp::OnInit() )
|
||||
|
|
@ -260,6 +266,11 @@ int WebApp::OnExit()
|
|||
return wxApp::OnExit();
|
||||
}
|
||||
|
||||
bool WebApp::ProcessIdle() {
|
||||
wxWebViewChromium::RunMessageLoopOnce();
|
||||
return wxApp::ProcessIdle();
|
||||
}
|
||||
|
||||
WebFrame::WebFrame(const wxString& url) :
|
||||
wxFrame(NULL, wxID_ANY, "wxWebView Sample")
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,9 +8,11 @@
|
|||
#include <wx/webview.h>
|
||||
#include <wx/webview_chromium.h>
|
||||
#include <wx/filesys.h>
|
||||
#include <wx/msw/private.h>
|
||||
#include <wx/rtti.h>
|
||||
|
||||
#ifdef __WXMSW__
|
||||
#include <wx/msw/private.h>
|
||||
#endif
|
||||
|
||||
#ifdef __VISUALC__
|
||||
#pragma warning(push)
|
||||
|
|
@ -85,16 +87,29 @@ bool wxWebViewChromium::Create(wxWindow* parent,
|
|||
// Initialize window info to the defaults for a child window
|
||||
info.SetAsChild(GetHWND(), wxGetClientRect(this->GetHWND()));
|
||||
#endif
|
||||
|
||||
#ifdef __WXGTK__
|
||||
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
|
||||
gtk_container_add(GTK_CONTAINER(window), vbox);
|
||||
gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
|
||||
info.SetAsChild(vbox);
|
||||
#endif
|
||||
// Creat the new child browser window, we do this async as we use a multi
|
||||
// threaded message loop
|
||||
|
||||
#if CHROME_VERSION_BUILD >= 1650
|
||||
CefBrowserHost::CreateBrowser(info, static_cast<CefRefPtr<CefClient>>(m_clientHandler),
|
||||
CefBrowserHost::CreateBrowser(info, static_cast<CefRefPtr<CefClient> >(m_clientHandler),
|
||||
url.ToStdString(), browsersettings, NULL);
|
||||
#else
|
||||
CefBrowserHost::CreateBrowser(info, static_cast<CefRefPtr<CefClient>>(m_clientHandler),
|
||||
CefBrowserHost::CreateBrowser(info, static_cast<CefRefPtr<CefClient> >(m_clientHandler),
|
||||
url.ToStdString(), browsersettings);
|
||||
#endif
|
||||
|
||||
#ifndef __WXMSW__
|
||||
// Show browser window.
|
||||
gtk_widget_show_all(GTK_WIDGET(window));
|
||||
#endif
|
||||
this->Bind(wxEVT_SIZE, &wxWebViewChromium::OnSize, this);
|
||||
|
||||
return true;
|
||||
|
|
@ -403,9 +418,17 @@ void wxWebViewChromium::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
|
|||
// We currently don't support custom scheme handlers
|
||||
}
|
||||
|
||||
bool wxWebViewChromium::StartUp(int &code, const wxString &path)
|
||||
#ifdef __WXMSW__
|
||||
bool StartUp(int &code, const wxString &path = "")
|
||||
#else
|
||||
bool wxWebViewChromium::StartUp(int &code, const wxString &path,
|
||||
int argc, char* argv[])
|
||||
#endif
|
||||
{
|
||||
CefMainArgs args(wxGetInstance());
|
||||
#ifdef __WXMSW__
|
||||
CefMainArgs args(wxGetInstance());
|
||||
#else
|
||||
CefMainArgs args(argc, argv);
|
||||
|
||||
// If there is no subprocess then we need to execute on this process
|
||||
if ( path == "" )
|
||||
|
|
@ -418,7 +441,7 @@ bool wxWebViewChromium::StartUp(int &code, const wxString &path)
|
|||
CefSettings settings;
|
||||
// We use a multithreaded message loop so we don't have to integrate
|
||||
// with the wx message loop
|
||||
settings.multi_threaded_message_loop = true;
|
||||
//settings.multi_threaded_message_loop = true;
|
||||
CefString(&settings.browser_subprocess_path) = path.ToStdString();
|
||||
|
||||
return CefInitialize(args, settings, NULL);
|
||||
|
|
@ -426,11 +449,19 @@ bool wxWebViewChromium::StartUp(int &code, const wxString &path)
|
|||
|
||||
int wxWebViewChromium::StartUpSubprocess()
|
||||
{
|
||||
CefMainArgs args(wxGetInstance());
|
||||
#if __WXMSW__
|
||||
CefMainArgs args(wxGetInstance());
|
||||
#else
|
||||
CefMainArgs args;
|
||||
|
||||
return CefExecuteProcess(args, NULL);
|
||||
}
|
||||
|
||||
void wxWebViewChromium::RunMessageLoopOnce()
|
||||
{
|
||||
CefDoMessageLoopWork();
|
||||
}
|
||||
|
||||
void wxWebViewChromium::Shutdown()
|
||||
{
|
||||
CefShutdown();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue