Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
webgui: improve CEF messaging close
When close message send by client, server clear all callbacks and
does not reply on the message. Still X is crashing if close called from
window.onunload handler
  • Loading branch information
linev committed Jul 27, 2017
commit 3a63467a7b47a331d1cfbbbe611436527f3420f9
50 changes: 29 additions & 21 deletions gui/canvaspainter/v7/cef/base_handler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,18 @@ class TCefWSEngine : public THttpWSEngine {
{
}

virtual ~TCefWSEngine() {}
virtual ~TCefWSEngine()
{
if (fCallback) fCallback->Failure(0, "close");
}

virtual UInt_t GetId() const
{
const void *ptr = (const void *)this;
return TString::Hash((void *)&ptr, sizeof(void *));
}

virtual void ClearHandle() { fCallback->Failure(0, "close"); }
virtual void ClearHandle() { fCallback = NULL; }

virtual void Send(const void * /*buf*/, int /*len*/)
{
Expand All @@ -64,8 +67,8 @@ class TCefWSEngine : public THttpWSEngine {

virtual void SendCharStar(const char *buf)
{
// printf("CEF sends message to client %s\n", buf);
fCallback->Success(buf); // send next message to JS
// printf("CEF sends message to client %d\n", strlen(buf));
if (fCallback) fCallback->Success(buf); // send next message to JS
}

virtual Bool_t PreviewData(THttpCallArg *arg)
Expand Down Expand Up @@ -96,17 +99,21 @@ class TCefWsCallArg : public THttpCallArg {

virtual void HttpReplied()
{
if (fCallback == NULL) return;
if (!fCallback)
return;

if (Is404()) {
fCallback->Failure(0, "error");
} else {
std::string reply;
if (GetContentLength() > 0) reply.append((const char *)GetContent(), GetContentLength());
if (GetContentLength() > 0)
reply.append((const char *)GetContent(), GetContentLength());
fCallback->Success(reply);
}
fCallback = NULL;
}

void ClearCallBack() { fCallback = NULL; }
};

// Handle messages in the browser process.
Expand All @@ -117,27 +124,22 @@ class RootMessageHandler : public CefMessageRouterBrowserSide::Handler {
public:
explicit RootMessageHandler(THttpServer *serv = 0) : fServer(serv) {}

// Called due to cefQuery execution in message_router.html.
// Called due to cefQuery execution
bool OnQuery(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, int64 query_id, const CefString &request,
bool persistent, CefRefPtr<Callback> callback) OVERRIDE
{
std::string message = request;

if (message == "init_jsroot_done") {
printf("Get message %s\n", message.c_str());
std::string result = "confirm from ROOT";
callback->Success(result);
return true; // processed
}

if (!fServer) return false;
if (!fServer)
return false;

// message format
// <path>::connect, replied with ws handler id
// <path>::<connid>::post::<data> or <path>::<connid>::close

int pos = message.find("::");
if (pos == std::string::npos) return false;
if (pos == std::string::npos)
return false;

std::string url = message.substr(0, pos);
message.erase(0, pos + 2);
Expand All @@ -154,21 +156,25 @@ class RootMessageHandler : public CefMessageRouterBrowserSide::Handler {
printf("Create CEF WS engine with id %u\n", ws->GetId());
} else {
pos = message.find("::");
if (pos == std::string::npos) return false;
if (pos == std::string::npos)
return false;
std::string sid = message.substr(0, pos);
message.erase(0, pos + 2);
unsigned wsid = 0;
sscanf(sid.c_str(), "%u", &wsid);
arg->SetWSId(wsid);
if (message == "close") {
arg->SetMethod("WS_CLOSE");
arg->ClearCallBack();
} else {
arg->SetMethod("WS_DATA");
if (message.length() > 6) arg->SetPostData((void *)(message.c_str() + 6), message.length() - 6, kTRUE);
if (message.length() > 6)
arg->SetPostData((void *)(message.c_str() + 6), message.length() - 6, kTRUE);
}
}

if (fServer->SubmitHttp(arg, kTRUE)) arg->HttpReplied(); // message processed and can be replied
if (fServer->SubmitHttp(arg, kTRUE))
arg->HttpReplied(); // message processed and can be replied

return true;
}
Expand Down Expand Up @@ -288,7 +294,8 @@ void BaseHandler::OnLoadError(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame>
CEF_REQUIRE_UI_THREAD();

// Don't display an error for downloaded files.
if (errorCode == ERR_ABORTED) return;
if (errorCode == ERR_ABORTED)
return;

// Display a load error message.
std::stringstream ss;
Expand All @@ -307,7 +314,8 @@ void BaseHandler::CloseAllBrowsers(bool force_close)
return;
}

if (browser_list_.empty()) return;
if (browser_list_.empty())
return;

BrowserList::const_iterator it = browser_list_.begin();
for (; it != browser_list_.end(); ++it) (*it)->GetHost()->CloseBrowser(force_close);
Expand Down
2 changes: 2 additions & 0 deletions gui/canvaspainter/v7/src/TCanvasPainter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,8 @@ Bool_t TCanvasPainter::ProcessWS(THttpCallArg *arg)
if (strcmp(arg->GetMethod(), "WS_CLOSE") == 0) {
// connection is closed, one can remove handle

printf("Connection closed\n");

if (conn && conn->fHandle) {
conn->fHandle->ClearHandle();
delete conn->fHandle;
Expand Down