Linux: cefclient: Fix GTK expectations with OSR multi-threaded-message-loop (fixes issue #3087)

This commit is contained in:
Marshall Greenblatt 2021-02-15 09:54:06 -08:00
parent b3ad79e2c5
commit bf3b7b2c62
1 changed files with 15 additions and 20 deletions

View File

@ -1089,7 +1089,6 @@ void BrowserWindowOsrGtk::SetBounds(int x, int y, size_t width, size_t height) {
void BrowserWindowOsrGtk::SetFocus(bool focus) { void BrowserWindowOsrGtk::SetFocus(bool focus) {
REQUIRE_MAIN_THREAD(); REQUIRE_MAIN_THREAD();
ScopedGdkThreadsEnter scoped_gdk_threads;
if (glarea_ && focus) { if (glarea_ && focus) {
gtk_widget_grab_focus(glarea_); gtk_widget_grab_focus(glarea_);
} }
@ -1314,11 +1313,11 @@ bool BrowserWindowOsrGtk::StartDragging(
return false; return false;
} }
ScopedGdkThreadsEnter scoped_gdk_threads;
DragReset(); DragReset();
drag_data_ = drag_data; drag_data_ = drag_data;
ScopedGdkThreadsEnter scoped_gdk_threads;
// Begin drag. // Begin drag.
if (drag_trigger_event_) { if (drag_trigger_event_) {
LOG(ERROR) << "Dragging started, but last mouse event is missing"; LOG(ERROR) << "Dragging started, but last mouse event is missing";
@ -1433,7 +1432,7 @@ void BrowserWindowOsrGtk::Create(ClientWindowHandle parent_handle) {
gint BrowserWindowOsrGtk::SizeAllocation(GtkWidget* widget, gint BrowserWindowOsrGtk::SizeAllocation(GtkWidget* widget,
GtkAllocation* allocation, GtkAllocation* allocation,
BrowserWindowOsrGtk* self) { BrowserWindowOsrGtk* self) {
CEF_REQUIRE_UI_THREAD(); REQUIRE_MAIN_THREAD();
if (self->browser_.get()) { if (self->browser_.get()) {
// Results in a call to GetViewRect(). // Results in a call to GetViewRect().
self->browser_->GetHost()->WasResized(); self->browser_->GetHost()->WasResized();
@ -1445,7 +1444,7 @@ gint BrowserWindowOsrGtk::SizeAllocation(GtkWidget* widget,
gint BrowserWindowOsrGtk::ClickEvent(GtkWidget* widget, gint BrowserWindowOsrGtk::ClickEvent(GtkWidget* widget,
GdkEventButton* event, GdkEventButton* event,
BrowserWindowOsrGtk* self) { BrowserWindowOsrGtk* self) {
CEF_REQUIRE_UI_THREAD(); REQUIRE_MAIN_THREAD();
if (!self->browser_.get()) if (!self->browser_.get())
return TRUE; return TRUE;
@ -1515,7 +1514,7 @@ gint BrowserWindowOsrGtk::ClickEvent(GtkWidget* widget,
gint BrowserWindowOsrGtk::KeyEvent(GtkWidget* widget, gint BrowserWindowOsrGtk::KeyEvent(GtkWidget* widget,
GdkEventKey* event, GdkEventKey* event,
BrowserWindowOsrGtk* self) { BrowserWindowOsrGtk* self) {
CEF_REQUIRE_UI_THREAD(); REQUIRE_MAIN_THREAD();
if (!self->browser_.get()) if (!self->browser_.get())
return TRUE; return TRUE;
@ -1571,8 +1570,6 @@ gint BrowserWindowOsrGtk::KeyEvent(GtkWidget* widget,
gint BrowserWindowOsrGtk::MoveEvent(GtkWidget* widget, gint BrowserWindowOsrGtk::MoveEvent(GtkWidget* widget,
GdkEventMotion* event, GdkEventMotion* event,
BrowserWindowOsrGtk* self) { BrowserWindowOsrGtk* self) {
CEF_REQUIRE_UI_THREAD();
if (!self->browser_.get()) if (!self->browser_.get())
return TRUE; return TRUE;
@ -1628,7 +1625,7 @@ gint BrowserWindowOsrGtk::MoveEvent(GtkWidget* widget,
gint BrowserWindowOsrGtk::ScrollEvent(GtkWidget* widget, gint BrowserWindowOsrGtk::ScrollEvent(GtkWidget* widget,
GdkEventScroll* event, GdkEventScroll* event,
BrowserWindowOsrGtk* self) { BrowserWindowOsrGtk* self) {
CEF_REQUIRE_UI_THREAD(); REQUIRE_MAIN_THREAD();
if (!self->browser_.get()) if (!self->browser_.get())
return TRUE; return TRUE;
@ -1889,7 +1886,6 @@ void BrowserWindowOsrGtk::RegisterDragDrop() {
} }
void BrowserWindowOsrGtk::UnregisterDragDrop() { void BrowserWindowOsrGtk::UnregisterDragDrop() {
CEF_REQUIRE_UI_THREAD();
ScopedGdkThreadsEnter scoped_gdk_threads; ScopedGdkThreadsEnter scoped_gdk_threads;
gtk_drag_dest_unset(glarea_); gtk_drag_dest_unset(glarea_);
// Drag events are unregistered in OnBeforeClose by calling // Drag events are unregistered in OnBeforeClose by calling
@ -1897,7 +1893,6 @@ void BrowserWindowOsrGtk::UnregisterDragDrop() {
} }
void BrowserWindowOsrGtk::DragReset() { void BrowserWindowOsrGtk::DragReset() {
CEF_REQUIRE_UI_THREAD();
if (drag_trigger_event_) { if (drag_trigger_event_) {
gdk_event_free(drag_trigger_event_); gdk_event_free(drag_trigger_event_);
drag_trigger_event_ = nullptr; drag_trigger_event_ = nullptr;
@ -1916,8 +1911,6 @@ void BrowserWindowOsrGtk::DragReset() {
void BrowserWindowOsrGtk::DragBegin(GtkWidget* widget, void BrowserWindowOsrGtk::DragBegin(GtkWidget* widget,
GdkDragContext* drag_context, GdkDragContext* drag_context,
BrowserWindowOsrGtk* self) { BrowserWindowOsrGtk* self) {
CEF_REQUIRE_UI_THREAD();
// Load drag icon. // Load drag icon.
if (!self->drag_data_->HasImage()) { if (!self->drag_data_->HasImage()) {
LOG(ERROR) << "Failed to set drag icon, drag image not available"; LOG(ERROR) << "Failed to set drag icon, drag image not available";
@ -1940,6 +1933,8 @@ void BrowserWindowOsrGtk::DragBegin(GtkWidget* widget,
return; return;
} }
ScopedGdkThreadsEnter scoped_gdk_threads;
size_t image_size = image_binary->GetSize(); size_t image_size = image_binary->GetSize();
guint8* image_buffer = (guint8*)malloc(image_size); // must free guint8* image_buffer = (guint8*)malloc(image_size); // must free
image_binary->GetData((void*)image_buffer, image_size, 0); image_binary->GetData((void*)image_buffer, image_size, 0);
@ -1987,7 +1982,7 @@ void BrowserWindowOsrGtk::DragDataGet(GtkWidget* widget,
guint info, guint info,
guint time, guint time,
BrowserWindowOsrGtk* self) { BrowserWindowOsrGtk* self) {
CEF_REQUIRE_UI_THREAD(); REQUIRE_MAIN_THREAD();
// No drag targets are set so this callback is never called. // No drag targets are set so this callback is never called.
} }
@ -1995,7 +1990,7 @@ void BrowserWindowOsrGtk::DragDataGet(GtkWidget* widget,
void BrowserWindowOsrGtk::DragEnd(GtkWidget* widget, void BrowserWindowOsrGtk::DragEnd(GtkWidget* widget,
GdkDragContext* drag_context, GdkDragContext* drag_context,
BrowserWindowOsrGtk* self) { BrowserWindowOsrGtk* self) {
CEF_REQUIRE_UI_THREAD(); REQUIRE_MAIN_THREAD();
if (self->browser_) { if (self->browser_) {
// Sometimes there is DragEnd event generated without prior DragDrop. // Sometimes there is DragEnd event generated without prior DragDrop.
@ -2018,7 +2013,7 @@ gboolean BrowserWindowOsrGtk::DragMotion(GtkWidget* widget,
gint y, gint y,
guint time, guint time,
BrowserWindowOsrGtk* self) { BrowserWindowOsrGtk* self) {
CEF_REQUIRE_UI_THREAD(); REQUIRE_MAIN_THREAD();
float device_scale_factor; float device_scale_factor;
{ {
@ -2078,7 +2073,7 @@ void BrowserWindowOsrGtk::DragLeave(GtkWidget* widget,
GdkDragContext* drag_context, GdkDragContext* drag_context,
guint time, guint time,
BrowserWindowOsrGtk* self) { BrowserWindowOsrGtk* self) {
CEF_REQUIRE_UI_THREAD(); REQUIRE_MAIN_THREAD();
// There is no drag-enter event in GTK. The first drag-motion event // There is no drag-enter event in GTK. The first drag-motion event
// after drag-leave will be a drag-enter event. // after drag-leave will be a drag-enter event.
@ -2100,7 +2095,7 @@ gboolean BrowserWindowOsrGtk::DragFailed(GtkWidget* widget,
GdkDragContext* drag_context, GdkDragContext* drag_context,
GtkDragResult result, GtkDragResult result,
BrowserWindowOsrGtk* self) { BrowserWindowOsrGtk* self) {
CEF_REQUIRE_UI_THREAD(); REQUIRE_MAIN_THREAD();
// Send drag end coordinates and system drag ended event. // Send drag end coordinates and system drag ended event.
if (self->browser_) { if (self->browser_) {
@ -2120,7 +2115,7 @@ gboolean BrowserWindowOsrGtk::DragDrop(GtkWidget* widget,
gint y, gint y,
guint time, guint time,
BrowserWindowOsrGtk* self) { BrowserWindowOsrGtk* self) {
CEF_REQUIRE_UI_THREAD(); REQUIRE_MAIN_THREAD();
// Finish GTK drag. // Finish GTK drag.
gtk_drag_finish(drag_context, TRUE, FALSE, time); gtk_drag_finish(drag_context, TRUE, FALSE, time);
@ -2164,7 +2159,7 @@ void BrowserWindowOsrGtk::DragDataReceived(GtkWidget* widget,
guint info, guint info,
guint time, guint time,
BrowserWindowOsrGtk* self) { BrowserWindowOsrGtk* self) {
CEF_REQUIRE_UI_THREAD(); REQUIRE_MAIN_THREAD();
// This callback is never called because DragDrop does not call // This callback is never called because DragDrop does not call
// gtk_drag_get_data, as only dragging inside web view is supported. // gtk_drag_get_data, as only dragging inside web view is supported.
} }