Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
browser(webkit): fix geo crash, exit main loop upon close (#435)
Pavel Feldmane13161c894bb
diff --git a/browser_patches/webkit/BUILD_NUMBER b/browser_patches/webkit/BUILD_NUMBERindex bb953c4b7d..6d0c1073d8 100644--- a/browser_patches/webkit/BUILD_NUMBER+++ b/browser_patches/webkit/BUILD_NUMBER@@ -1 +1 @@-1076+1077diff --git a/browser_patches/webkit/patches/bootstrap.diff b/browser_patches/webkit/patches/bootstrap.diffindex 24d14b39c0..3eb30c5134 100644--- a/browser_patches/webkit/patches/bootstrap.diff+++ b/browser_patches/webkit/patches/bootstrap.diff@@ -4854,7 +4854,7 @@ index 2bdb8b9e7256f22096ebaa5d51959aa52389ca0a..2141d9d17497861a6c711f99306de109diff --git a/Source/WebKit/UIProcess/API/glib/WebKitBrowserInspector.cpp b/Source/WebKit/UIProcess/API/glib/WebKitBrowserInspector.cppnew file mode 100644-index 0000000000000000000000000000000000000000..4514f00de0b27620cd170d6ed9b361a3e1506fb1+index 0000000000000000000000000000000000000000..70081db72e035ca99c0279ab02da5cfed9256c57--- /dev/null+++ b/Source/WebKit/UIProcess/API/glib/WebKitBrowserInspector.cpp@@ -0,0 +1,136 @@@@ -4988,10 +4988,10 @@ index 0000000000000000000000000000000000000000..4514f00de0b27620cd170d6ed9b361a3+ * Creates browser inspector and configures pipe handler to communicate with+ * the parent process.+ */-+void webkit_browser_inspector_initialize_pipe(void)++void webkit_browser_inspector_initialize_pipe(GMainLoop* mainLoop)+{+#if ENABLE(REMOTE_INSPECTOR)-+ WebKit::initializeBrowserInspectorPipe(makeUnique<WebKit::InspectorBrowserAgentClientGlib>());++ WebKit::initializeBrowserInspectorPipe(makeUnique<WebKit::InspectorBrowserAgentClientGlib>(mainLoop));+#endif+}diff --git a/Source/WebKit/UIProcess/API/glib/WebKitBrowserInspectorPrivate.h b/Source/WebKit/UIProcess/API/glib/WebKitBrowserInspectorPrivate.h@@ -5179,7 +5179,7 @@ index b1252daf7423bb66a177b5d028563e389b73802a..3edc383f6d7bbc1b43a7b4937eee03c4webkitWebViewBaseForwardNextKeyEvent(webkitWebViewBase);diff --git a/Source/WebKit/UIProcess/API/gtk/WebKitBrowserInspector.h b/Source/WebKit/UIProcess/API/gtk/WebKitBrowserInspector.hnew file mode 100644-index 0000000000000000000000000000000000000000..f933c3479cdb49544fe7c1b22c8b00b052af7fe5+index 0000000000000000000000000000000000000000..a51cfebc270ca5a91cd94645eeeb005ba9a67caf--- /dev/null+++ b/Source/WebKit/UIProcess/API/gtk/WebKitBrowserInspector.h@@ -0,0 +1,79 @@@@ -5257,7 +5257,7 @@ index 0000000000000000000000000000000000000000..f933c3479cdb49544fe7c1b22c8b00b0+webkit_browser_inspector_get_default (void);++WEBKIT_API void-+webkit_browser_inspector_initialize_pipe (void);++webkit_browser_inspector_initialize_pipe (GMainLoop*);++G_END_DECLS+@@ -5276,7 +5276,7 @@ index 930b17b6629e04d0dfa2222bbc3217877c6e1812..395462e5f01c195231e9296d1204167c#include <webkit2/WebKitContextMenuItem.h>diff --git a/Source/WebKit/UIProcess/API/wpe/WebKitBrowserInspector.h b/Source/WebKit/UIProcess/API/wpe/WebKitBrowserInspector.hnew file mode 100644-index 0000000000000000000000000000000000000000..b9392bc9f232f1f8a5be1e9668ec31e11bd8e3f8+index 0000000000000000000000000000000000000000..6dffa4fa10a9a64f778a0a77c760c2e76b2f9968--- /dev/null+++ b/Source/WebKit/UIProcess/API/wpe/WebKitBrowserInspector.h@@ -0,0 +1,79 @@@@ -5354,7 +5354,7 @@ index 0000000000000000000000000000000000000000..b9392bc9f232f1f8a5be1e9668ec31e1+webkit_browser_inspector_get_default (void);++WEBKIT_API void-+webkit_browser_inspector_initialize_pipe (void);++webkit_browser_inspector_initialize_pipe (GMainLoop*);++G_END_DECLS+@@ -8089,12 +8089,98 @@ index b7c955a5f3ebe5805ad7095bc06878e128d11568..ab65f14db987e4e03e0474c9127efad6bool m_ignoreTLSErrors { true };#endif+diff --git a/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.cpp b/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.cpp+index dba2a990d15683216a6fa90a48eb30eebd3c526f..6a8afc7c206765670d25152f7b6a1aa7e5563a27 100644+--- a/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.cpp++++ b/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.cpp+@@ -55,10 +55,11 @@ void GeoclueGeolocationProvider::start(UpdateNotifyFunction&& updateNotifyFuncti+ m_destroyManagerLaterTimer.stop();+ m_updateNotifyFunction = WTFMove(updateNotifyFunction);+ m_isRunning = true;+-+ if (!m_manager) {++ g_cancellable_cancel(m_cancellable_start.get());++ m_cancellable_start = adoptGRef(g_cancellable_new());+ g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, nullptr,+- "org.freedesktop.GeoClue2", "/org/freedesktop/GeoClue2/Manager", "org.freedesktop.GeoClue2.Manager", nullptr,++ "org.freedesktop.GeoClue2", "/org/freedesktop/GeoClue2/Manager", "org.freedesktop.GeoClue2.Manager", m_cancellable_start.get(),+ [](GObject*, GAsyncResult* result, gpointer userData) {+ auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);+ GUniqueOutPtr<GError> error;+@@ -84,6 +85,12 @@ void GeoclueGeolocationProvider::stop()+ m_updateNotifyFunction = nullptr;+ g_cancellable_cancel(m_cancellable.get());+ stopClient();++ g_cancellable_cancel(m_cancellable_start.get());++ m_cancellable_start = nullptr;++ g_cancellable_cancel(m_cancellable_setup.get());++ m_cancellable_setup = nullptr;++ g_cancellable_cancel(m_cancellable_create.get());++ m_cancellable_create = nullptr;+ destroyManagerLater();+ }++@@ -121,7 +128,9 @@ void GeoclueGeolocationProvider::setupManager(GRefPtr<GDBusProxy>&& proxy)+ return;+ }++- g_dbus_proxy_call(m_manager.get(), "CreateClient", nullptr, G_DBUS_CALL_FLAGS_NONE, -1, nullptr,++ g_cancellable_cancel(m_cancellable_setup.get());++ m_cancellable_setup = adoptGRef(g_cancellable_new());++ g_dbus_proxy_call(m_manager.get(), "CreateClient", nullptr, G_DBUS_CALL_FLAGS_NONE, -1, m_cancellable_setup.get(),+ [](GObject* manager, GAsyncResult* result, gpointer userData) {+ auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);+ GUniqueOutPtr<GError> error;+@@ -143,8 +152,10 @@ void GeoclueGeolocationProvider::createClient(const char* clientPath)+ return;+ }+++ g_cancellable_cancel(m_cancellable_create.get());++ m_cancellable_create = adoptGRef(g_cancellable_new());+ g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, nullptr,+- "org.freedesktop.GeoClue2", clientPath, "org.freedesktop.GeoClue2.Client", nullptr,++ "org.freedesktop.GeoClue2", clientPath, "org.freedesktop.GeoClue2.Client", m_cancellable_create.get(),+ [](GObject*, GAsyncResult* result, gpointer userData) {+ auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);+ GUniqueOutPtr<GError> error;+@@ -190,6 +201,7 @@ void GeoclueGeolocationProvider::startClient()++ g_signal_connect(m_client.get(), "g-signal", G_CALLBACK(clientLocationUpdatedCallback), this);+++ g_cancellable_cancel(m_cancellable.get());+ m_cancellable = adoptGRef(g_cancellable_new());+ g_dbus_proxy_call(m_client.get(), "Start", nullptr, G_DBUS_CALL_FLAGS_NONE, -1, m_cancellable.get(),+ [](GObject* client, GAsyncResult* result, gpointer userData) {+@@ -282,7 +294,8 @@ void GeoclueGeolocationProvider::locationUpdated(GRefPtr<GDBusProxy>&& proxy)++ void GeoclueGeolocationProvider::didFail(CString errorMessage)+ {+- m_updateNotifyFunction({ }, errorMessage);++ if (m_updateNotifyFunction)++ m_updateNotifyFunction({ }, errorMessage);+ }++ } // namespace WebKit+diff --git a/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.h b/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.h+index 31d29091985f34a65134a2b0e7cb3ace1dae441d..571ceac8a4b291fa6e91eb8b17065c0aba908ac3 100644+--- a/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.h++++ b/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.h+@@ -71,6 +71,9 @@ private:+ GRefPtr<GDBusProxy> m_manager;+ GRefPtr<GDBusProxy> m_client;+ GRefPtr<GCancellable> m_cancellable;++ GRefPtr<GCancellable> m_cancellable_start;++ GRefPtr<GCancellable> m_cancellable_setup;++ GRefPtr<GCancellable> m_cancellable_create;+ UpdateNotifyFunction m_updateNotifyFunction;+ RunLoop::Timer<GeoclueGeolocationProvider> m_destroyManagerLaterTimer;+ };diff --git a/Source/WebKit/UIProcess/glib/InspectorBrowserAgentClientGLib.cpp b/Source/WebKit/UIProcess/glib/InspectorBrowserAgentClientGLib.cppnew file mode 100644-index 0000000000000000000000000000000000000000..92a1eb339c2b760e9c5e84dc76fe323845bd81ac+index 0000000000000000000000000000000000000000..6b7cc61fff69ea639f1ed6d2a824e4a765e5e80c--- /dev/null+++ b/Source/WebKit/UIProcess/glib/InspectorBrowserAgentClientGLib.cpp-@@ -0,0 +1,125 @@+@@ -0,0 +1,131 @@+/*+ * Copyright (C) 2019 Microsoft Corporation.+ *@@ -8159,7 +8245,8 @@ index 0000000000000000000000000000000000000000..92a1eb339c2b760e9c5e84dc76fe3238+ page->closePage();+}+-+InspectorBrowserAgentClientGlib::InspectorBrowserAgentClientGlib()++InspectorBrowserAgentClientGlib::InspectorBrowserAgentClientGlib(GMainLoop* mainLoop)++ : m_mainLoop(mainLoop)+{+}+@@ -8186,7 +8273,12 @@ index 0000000000000000000000000000000000000000..92a1eb339c2b760e9c5e84dc76fe3238+{+ closeAllPages(Optional<PAL::SessionID>());+ m_idToContext.clear();-+ // FIXME(yurys): call g_main_loop_quit() ?++#if PLATFORM(GTK)++ gtk_main_quit();++#else++ if (g_main_loop_quit)++ g_main_loop_quit(m_mainLoop);++#endif+}++static PAL::SessionID sessionIDFromContext(WebKitWebContext* context)@@ -8222,10 +8314,10 @@ index 0000000000000000000000000000000000000000..92a1eb339c2b760e9c5e84dc76fe3238+#endif // ENABLE(REMOTE_INSPECTOR)diff --git a/Source/WebKit/UIProcess/glib/InspectorBrowserAgentClientGLib.h b/Source/WebKit/UIProcess/glib/InspectorBrowserAgentClientGLib.hnew file mode 100644-index 0000000000000000000000000000000000000000..27c8a4dfb0008bcf190157a0b8a72b7282abd517+index 0000000000000000000000000000000000000000..6fcadb97ebe89699f29afc4dcac6065dbade9a3b--- /dev/null+++ b/Source/WebKit/UIProcess/glib/InspectorBrowserAgentClientGLib.h-@@ -0,0 +1,58 @@+@@ -0,0 +1,59 @@+/*+ * Copyright (C) 2019 Microsoft Corporation.+ *@@ -8267,7 +8359,7 @@ index 0000000000000000000000000000000000000000..27c8a4dfb0008bcf190157a0b8a72b72+class InspectorBrowserAgentClientGlib : public InspectorBrowserAgentClient {+ WTF_MAKE_FAST_ALLOCATED;+public:-+ InspectorBrowserAgentClientGlib();++ InspectorBrowserAgentClientGlib(GMainLoop* mainLoop);+ ~InspectorBrowserAgentClientGlib() override = default;++ RefPtr<WebPageProxy> createPage(WTF::String& error, PAL::SessionID) override;@@ -8279,6 +8371,7 @@ index 0000000000000000000000000000000000000000..27c8a4dfb0008bcf190157a0b8a72b72+ WebKitWebContext* findContext(WTF::String& error, PAL::SessionID);++ HashMap<PAL::SessionID, GRefPtr<WebKitWebContext>> m_idToContext;++ GMainLoop* m_mainLoop;+};++} // namespace API@@ -9631,7 +9724,7 @@ index 1570d65effb5d601ee3c44a2a7461436f4691c2c..456f96cf589320efa70a76f76e230b67typedef struct _BrowserWindow BrowserWindow;diff --git a/Tools/MiniBrowser/gtk/main.c b/Tools/MiniBrowser/gtk/main.c-index 4c5147dcd38a53e2feaeaae0fce38f92dc60eba6..be501274061102f805c43df37a67e4a1cf6d5494 100644+index 4c5147dcd38a53e2feaeaae0fce38f92dc60eba6..85d98782b2beef897221659631384ef379dfe87f 100644--- a/Tools/MiniBrowser/gtk/main.c+++ b/Tools/MiniBrowser/gtk/main.c@@ -53,6 +53,8 @@ static const char *cookiesFile;@@ -9676,7 +9769,7 @@ index 4c5147dcd38a53e2feaeaae0fce38f92dc60eba6..be501274061102f805c43df37a67e4a1+ WebKitBrowserInspector* browserInspector = webkit_browser_inspector_get_default();+ g_signal_connect(browserInspector, "create-new-page", G_CALLBACK(createNewPage), NULL);+-+ webkit_browser_inspector_initialize_pipe();++ webkit_browser_inspector_initialize_pipe(NULL);+}+int main(int argc, char *argv[])@@ -10254,7 +10347,7 @@ index 245f319abf2595e154d03e1ee8b3250d7f46aafd..9cae87b23deade7c163f34aade2b2aed${WPEBACKEND_FDO_INCLUDE_DIRS})diff --git a/Tools/MiniBrowser/wpe/main.cpp b/Tools/MiniBrowser/wpe/main.cpp-index 2d183d394123bd84545dc51f53eb9be796fb8873..7e435b9b9bb3240042269e2ec47b77205de60ba1 100644+index 2d183d394123bd84545dc51f53eb9be796fb8873..ecc8708bcfb51dcc8f55a4fe3115c417d971600c 100644--- a/Tools/MiniBrowser/wpe/main.cpp+++ b/Tools/MiniBrowser/wpe/main.cpp@@ -25,7 +25,7 @@@@ -10291,7 +10384,7 @@ index 2d183d394123bd84545dc51f53eb9be796fb8873..7e435b9b9bb3240042269e2ec47b7720return std::make_unique<WPEToolingBackends::WindowViewBackend>(width, height);}-@@ -172,6 +174,52 @@ static WebKitWebView* createWebView(WebKitWebView* webView, WebKitNavigationActi+@@ -172,6 +174,46 @@ static WebKitWebView* createWebView(WebKitWebView* webView, WebKitNavigationActireturn newWebView;}@@ -10328,28 +10421,22 @@ index 2d183d394123bd84545dc51f53eb9be796fb8873..7e435b9b9bb3240042269e2ec47b7720++}+-+static void closeAll(WebKitBrowserInspector*, GMainLoop* mainLoop)-+{-+ g_main_loop_quit(mainLoop);-+}-+-+static void configureBrowserInspector()++static void configureBrowserInspector(GMainLoop* mainLoop)+{+ WebKitBrowserInspector* browserInspector = webkit_browser_inspector_get_default();+ g_signal_connect(browserInspector, "create-new-page", G_CALLBACK(createNewPage), NULL);-+ // FIXME: This signal is received only when closeAll is called. We should not rely on that.-+ webkit_browser_inspector_initialize_pipe();++ webkit_browser_inspector_initialize_pipe(mainLoop);+}+int main(int argc, char *argv[]){#if ENABLE_DEVELOPER_MODE-@@ -280,6 +328,9 @@ int main(int argc, char *argv[])+@@ -280,6 +322,9 @@ int main(int argc, char *argv[])delete static_cast<WPEToolingBackends::ViewBackend*>(data);}, backend.release());+ if (inspectorPipe)-+ configureBrowserInspector();++ configureBrowserInspector(loop);+auto* webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW,"backend", viewBackend,