Modified: trunk/Source/WebKit/ChangeLog (250706 => 250707)
--- trunk/Source/WebKit/ChangeLog 2019-10-04 06:04:52 UTC (rev 250706)
+++ trunk/Source/WebKit/ChangeLog 2019-10-04 06:15:39 UTC (rev 250707)
@@ -1,5 +1,20 @@
2019-10-03 Carlos Garcia Campos <cgar...@igalia.com>
+ [GTK] WebAutomation: make setWindowRect synchronous
+ https://bugs.webkit.org/show_bug.cgi?id=202530
+
+ Reviewed by Carlos Alberto Lopez Perez.
+
+ Move/resize window is asynchronous in GTK, but automation expects it to be synchronous so that get window rect
+ after setting it always returns the value set. Use a nested run loop to wait for the configure events after the
+ move/resize.
+
+ * UIProcess/API/glib/WebKitUIClient.cpp:
+ (UIClient::windowConfigureEventCallback):
+ (UIClient::setWindowFrameTimerFired):
+
+2019-10-03 Carlos Garcia Campos <cgar...@igalia.com>
+
Unreviewed. Address review comments after r250646.
I forgot to include the documentation improvements suggested.
Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp (250706 => 250707)
--- trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp 2019-10-04 06:04:52 UTC (rev 250706)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp 2019-10-04 06:15:39 UTC (rev 250707)
@@ -35,6 +35,7 @@
#include "WebProcessProxy.h"
#include "WebsiteDataStore.h"
#include <wtf/glib/GRefPtr.h>
+#include <wtf/glib/RunLoopSourcePriority.h>
#if PLATFORM(GTK)
#include <WebCore/GtkUtilities.h>
@@ -128,6 +129,22 @@
webkitWindowPropertiesSetResizable(webkit_web_view_get_window_properties(m_webView), resizable);
}
+#if PLATFORM(GTK)
+ static void windowConfigureEventCallback(GtkWindow* window, GdkEventConfigure*, GdkRectangle* targetGeometry)
+ {
+ GdkRectangle geometry = { 0, 0, 0, 0 };
+ gtk_window_get_position(window, &geometry.x, &geometry.y);
+ gtk_window_get_size(window, &geometry.width, &geometry.height);
+ if (geometry.x == targetGeometry->x && geometry.y == targetGeometry->y && geometry.width == targetGeometry->width && geometry.height == targetGeometry->height)
+ RunLoop::current().stop();
+ }
+
+ void setWindowFrameTimerFired()
+ {
+ RunLoop::current().stop();
+ }
+#endif
+
void setWindowFrame(WebPageProxy&, const WebCore::FloatRect& frame) final
{
#if PLATFORM(GTK)
@@ -134,10 +151,23 @@
GdkRectangle geometry = WebCore::IntRect(frame);
GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(m_webView));
if (webkit_web_view_is_controlled_by_automation(m_webView) && WebCore::widgetIsOnscreenToplevelWindow(window) && gtk_widget_get_visible(window)) {
+ if ((geometry.x < 0 || geometry.y < 0) && (geometry.width <= 0 || geometry.height <= 0))
+ return;
+
+ auto signalID = g_signal_connect(window, "configure-event", G_CALLBACK(windowConfigureEventCallback), &geometry);
if (geometry.x >= 0 && geometry.y >= 0)
gtk_window_move(GTK_WINDOW(window), geometry.x, geometry.y);
if (geometry.width > 0 && geometry.height > 0)
gtk_window_resize(GTK_WINDOW(window), geometry.width, geometry.height);
+
+ // We need the move/resize to happen synchronously in automation mode, so we use a nested RunLoop
+ // to wait, up top 1 second, for the configure events.
+ auto timer = makeUnique<RunLoop::Timer<UIClient>>(RunLoop::main(), this, &UIClient::setWindowFrameTimerFired);
+ timer->setPriority(RunLoopSourcePriority::RunLoopTimer);
+ timer->startOneShot(1_s);
+ RunLoop::run();
+ timer = nullptr;
+ g_signal_handler_disconnect(window, signalID);
} else
webkitWindowPropertiesSetGeometry(webkit_web_view_get_window_properties(m_webView), &geometry);
#endif