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): screencast for WPE (#2516)
Yury Semikhatskyd7f867db47fa
diff --git a/browser_patches/webkit/BUILD_NUMBER b/browser_patches/webkit/BUILD_NUMBERindex f96065a3e9..e5d76887a3 100644--- a/browser_patches/webkit/BUILD_NUMBER+++ b/browser_patches/webkit/BUILD_NUMBER@@ -1 +1 @@-1273+1274diff --git a/browser_patches/webkit/patches/bootstrap.diff b/browser_patches/webkit/patches/bootstrap.diffindex dce9398a73..7e32019e97 100644--- a/browser_patches/webkit/patches/bootstrap.diff+++ b/browser_patches/webkit/patches/bootstrap.diff@@ -6590,7 +6590,7 @@ index b94522c8fca0af886fefd2ce4c982e407715d56b..1af3f476d4aefae58ecfd9fdbfa19907endif ()diff --git a/Source/WebKit/PlatformWPE.cmake b/Source/WebKit/PlatformWPE.cmake-index 8320e310e6c466924a083ee46ae31f5486420fcd..33e1a5f6d846a490bb66848cfc1518a5b17104fd 100644+index 8320e310e6c466924a083ee46ae31f5486420fcd..c8b0adc8263247d1c0031f16e549cc6c92dd9fbd 100644--- a/Source/WebKit/PlatformWPE.cmake+++ b/Source/WebKit/PlatformWPE.cmake@@ -255,6 +255,7 @@ list(APPEND WebKit_INCLUDE_DIRECTORIES@@ -6601,6 +6601,59 @@ index 8320e310e6c466924a083ee46ae31f5486420fcd..33e1a5f6d846a490bb66848cfc1518a5"${WEBKIT_DIR}/UIProcess/gstreamer""${WEBKIT_DIR}/UIProcess/linux""${WEBKIT_DIR}/UIProcess/soup"+@@ -285,8 +286,52 @@ list(APPEND WebKit_SYSTEM_INCLUDE_DIRECTORIES+ ${GSTREAMER_VIDEO_INCLUDE_DIRS}+ ${LIBSECCOMP_INCLUDE_DIRS}+ ${LIBSOUP_INCLUDE_DIRS}++# Playwright begin++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/include"++# Playwright end+ )+++# Playwright begin++list(APPEND WebKit_SOURCES++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/compare.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/compare_common.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/compare_gcc.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/convert.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/convert_argb.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/convert_from.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/convert_from_argb.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/convert_jpeg.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/convert_to_argb.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/convert_to_i420.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/cpu_id.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/mjpeg_decoder.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/mjpeg_validate.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/planar_functions.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/compare_neon.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/compare_neon64.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/rotate.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/rotate_any.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/rotate_argb.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/rotate_common.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/rotate_gcc.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/rotate_neon.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/rotate_neon64.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/row_any.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/row_common.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/row_gcc.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/row_neon.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/row_neon64.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/scale.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/scale_any.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/scale_argb.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/scale_common.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/scale_gcc.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/scale_neon.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/scale_neon64.cc"++ "${THIRDPARTY_DIR}/libwebrtc/Source/third_party/libyuv/source/video_common.cc"++)++# Playwright end+++ list(APPEND WebKit_LIBRARIES+ Cairo::Cairo+ Freetype::Freetypediff --git a/Source/WebKit/PlatformWin.cmake b/Source/WebKit/PlatformWin.cmakeindex 3b94f4dba2c3b9659a1269bfe030d5d010b5b1bd..43dde2ab5a5b925ac6916656d8528b0e172fc564 100644--- a/Source/WebKit/PlatformWin.cmake@@ -7094,7 +7147,7 @@ index 2d5aac953abef23ea5d0233ad0a5be9aa5985b8e..8741e8f94023e8c7c1ab1cde56550d76UIProcess/gtk/WebPasteboardProxyGtk.cppUIProcess/gtk/WebPopupMenuProxyGtk.cppdiff --git a/Source/WebKit/SourcesWPE.txt b/Source/WebKit/SourcesWPE.txt-index 8b934e81e74890eba674f5faaa6a5ade0f605c11..4f5bcc18e576a656709dfcfccd75d09e00f8e80c 100644+index 8b934e81e74890eba674f5faaa6a5ade0f605c11..fe84a45a091cd699cca6dd3ad7db8e4918302c61 100644--- a/Source/WebKit/SourcesWPE.txt+++ b/Source/WebKit/SourcesWPE.txt@@ -125,6 +125,7 @@ UIProcess/API/glib/WebKitAuthenticationRequest.cpp @no-unify@@ -7105,16 +7158,17 @@ index 8b934e81e74890eba674f5faaa6a5ade0f605c11..4f5bcc18e576a656709dfcfccd75d09eUIProcess/API/glib/WebKitContextMenuClient.cpp @no-unifyUIProcess/API/glib/WebKitCookieManager.cpp @no-unifyUIProcess/API/glib/WebKitCredential.cpp @no-unify-@@ -200,7 +201,7 @@ UIProcess/Automation/wpe/WebAutomationSessionWPE.cpp+@@ -200,7 +201,8 @@ UIProcess/Automation/wpe/WebAutomationSessionWPE.cppUIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.cppUIProcess/geoclue/GeoclueGeolocationProvider.cpp-++UIProcess/Inspector/Agents/ScreencastEncoder.cpp+UIProcess/glib/InspectorPlaywrightAgentClientGLib.cppUIProcess/glib/WebProcessPoolGLib.cppUIProcess/glib/WebProcessProxyGLib.cppUIProcess/glib/WebsiteDataStoreGLib.cpp @no-unify-@@ -225,6 +226,10 @@ UIProcess/linux/MemoryPressureMonitor.cpp+@@ -225,6 +227,10 @@ UIProcess/linux/MemoryPressureMonitor.cppUIProcess/soup/WebCookieManagerProxySoup.cppUIProcess/soup/WebProcessPoolSoup.cpp@@ -7879,10 +7933,18 @@ index 041bfb545c6af6220a8266d356ac19d90791cb83..814558c67bfdb9c3cf635f62608349a8/*** WebKitWebContext:use-system-appearance-for-scrollbars:diff --git a/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp b/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp-index e4045c36706575cc7db9f98711efd69004a2a3f0..666427b46a14e682045c06482d9f1dc4451def80 100644+index e4045c36706575cc7db9f98711efd69004a2a3f0..f0089cbd8d82a54d6d43847be756706a2e9341bc 100644--- a/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp+++ b/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp-@@ -130,6 +130,7 @@ enum {+@@ -31,6 +31,7 @@+ #include "WebCertificateInfo.h"+ #include "WebContextMenuItem.h"+ #include "WebContextMenuItemData.h"++#include "WebPageInspectorController.h"+ #include "WebKitAuthenticationRequestPrivate.h"+ #include "WebKitBackForwardListPrivate.h"+ #include "WebKitContextMenuClient.h"+@@ -130,6 +131,7 @@ enum {CLOSE,SCRIPT_DIALOG,@@ -7890,7 +7952,25 @@ index e4045c36706575cc7db9f98711efd69004a2a3f0..666427b46a14e682045c06482d9f1dc4DECIDE_POLICY,PERMISSION_REQUEST,-@@ -1560,6 +1561,15 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)+@@ -431,6 +433,9 @@ void WebKitWebViewClient::handleDownloadRequest(WKWPE::View&, DownloadProxy& dow++ void WebKitWebViewClient::frameDisplayed(WKWPE::View&)+ {++ if (RefPtr<cairo_surface_t> surface = adoptRef(webkitWebViewBackendTakeScreenshot(m_webView->priv->backend.get())))++ getPage(m_webView).inspectorController().didPaint(surface.get());+++ {+ SetForScope<bool> inFrameDisplayedGuard(m_webView->priv->inFrameDisplayed, true);+ for (const auto& callback : m_webView->priv->frameDisplayedCallbacks) {+@@ -461,6 +466,7 @@ void WebKitWebViewClient::didReceiveUserMessage(WKWPE::View&, UserMessage&& mess+ {+ webkitWebViewDidReceiveUserMessage(m_webView, WTFMove(message), WTFMove(completionHandler));+ }+++ #endif++ static gboolean webkitWebViewLoadFail(WebKitWebView* webView, WebKitLoadEvent, const char* failingURI, GError* error)+@@ -1560,6 +1566,15 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)G_TYPE_BOOLEAN, 1,WEBKIT_TYPE_SCRIPT_DIALOG);@@ -7906,7 +7986,7 @@ index e4045c36706575cc7db9f98711efd69004a2a3f0..666427b46a14e682045c06482d9f1dc4/*** WebKitWebView::decide-policy:* @web_view: the #WebKitWebView on which the signal is emitted-@@ -2440,6 +2450,23 @@ void webkitWebViewRunJavaScriptBeforeUnloadConfirm(WebKitWebView* webView, const+@@ -2440,6 +2455,23 @@ void webkitWebViewRunJavaScriptBeforeUnloadConfirm(WebKitWebView* webView, constwebkit_script_dialog_unref(webView->priv->currentScriptDialog);}@@ -8054,6 +8134,19 @@ index 930b17b6629e04d0dfa2222bbc3217877c6e1812..395462e5f01c195231e9296d1204167c#include <webkit2/WebKitContextMenu.h>#include <webkit2/WebKitContextMenuActions.h>#include <webkit2/WebKitContextMenuItem.h>+diff --git a/Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp b/Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp+index c8b41f407774d2337e99cc7f9151ec65be3fc532..22faf21f9a7946a7898cedfc1b6ec1316110a166 100644+--- a/Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp++++ b/Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp+@@ -194,7 +194,7 @@ WebCore::IntPoint PageClientImpl::accessibilityScreenToRootView(const WebCore::I++ WebCore::IntRect PageClientImpl::rootViewToAccessibilityScreen(const WebCore::IntRect& rect)+ {+- return rootViewToScreen(rect);++ return rootViewToScreen(rect);+ }++ void PageClientImpl::doneWithKeyEvent(const NativeWebKeyboardEvent&, bool)diff --git a/Source/WebKit/UIProcess/API/wpe/WebKitBrowserInspector.h b/Source/WebKit/UIProcess/API/wpe/WebKitBrowserInspector.hnew file mode 100644index 0000000000000000000000000000000000000000..0e8b78b60e8f306c98295afb5c7e5ed150e4918e@@ -8141,6 +8234,86 @@ index 0000000000000000000000000000000000000000..0e8b78b60e8f306c98295afb5c7e5ed1+G_END_DECLS++#endif+diff --git a/Source/WebKit/UIProcess/API/wpe/WebKitWebViewBackend.cpp b/Source/WebKit/UIProcess/API/wpe/WebKitWebViewBackend.cpp+index e0fc205b39095cf8aae201a1dcca520461c60de4..872186ad99a7b82f0c61705ff6c5ae4453e5e1d4 100644+--- a/Source/WebKit/UIProcess/API/wpe/WebKitWebViewBackend.cpp++++ b/Source/WebKit/UIProcess/API/wpe/WebKitWebViewBackend.cpp+@@ -54,6 +54,7 @@ struct _WebKitWebViewBackend {+ struct wpe_view_backend* backend;+ GDestroyNotify notifyCallback;+ gpointer notifyCallbackData;++ take_screenshot_callback screenshotCallback;+ int referenceCount { 1 };+ };++@@ -116,6 +117,19 @@ struct wpe_view_backend* webkit_web_view_backend_get_wpe_backend(WebKitWebViewBa+ return viewBackend->backend;+ }+++void webkit_web_view_backend_set_screenshot_callback(WebKitWebViewBackend *view_backend, take_screenshot_callback callback)++{++ view_backend->screenshotCallback = callback;++}++++cairo_surface_t* webkitWebViewBackendTakeScreenshot(WebKitWebViewBackend* view_backend)++{++ if (!view_backend->screenshotCallback)++ return nullptr;++++ return view_backend->screenshotCallback(view_backend->notifyCallbackData);++}+++ namespace WTF {++ template <> WebKitWebViewBackend* refGPtr(WebKitWebViewBackend* ptr)+diff --git a/Source/WebKit/UIProcess/API/wpe/WebKitWebViewBackend.h b/Source/WebKit/UIProcess/API/wpe/WebKitWebViewBackend.h+index 6663964d5abac79e123d90e0351590884c66aa72..13ba5e7c3895c6e4efda95f1f90b9baea1c1bf30 100644+--- a/Source/WebKit/UIProcess/API/wpe/WebKitWebViewBackend.h++++ b/Source/WebKit/UIProcess/API/wpe/WebKitWebViewBackend.h+@@ -27,6 +27,7 @@+ #include <glib-object.h>+ #include <wpe/WebKitDefines.h>+ #include <wpe/wpe.h>++#include <cairo.h>++ G_BEGIN_DECLS++@@ -44,6 +45,12 @@ webkit_web_view_backend_new (struct wpe_view_backend *backend,+ WEBKIT_API struct wpe_view_backend *+ webkit_web_view_backend_get_wpe_backend (WebKitWebViewBackend *view_backend);+++typedef cairo_surface_t* (*take_screenshot_callback)(gpointer user_data);++++WEBKIT_API void++webkit_web_view_backend_set_screenshot_callback (WebKitWebViewBackend *view_backend,++ take_screenshot_callback callback);+++ G_END_DECLS++ #endif /* WebKitWebViewBackend_h */+diff --git a/Source/WebKit/UIProcess/API/wpe/WebKitWebViewBackendPrivate.h b/Source/WebKit/UIProcess/API/wpe/WebKitWebViewBackendPrivate.h+index e4b92ace1531090ae38a7aec3d3d4febf19aee84..43690f9ef4969a39084501613bfc00a77fd5df49 100644+--- a/Source/WebKit/UIProcess/API/wpe/WebKitWebViewBackendPrivate.h++++ b/Source/WebKit/UIProcess/API/wpe/WebKitWebViewBackendPrivate.h+@@ -31,3 +31,5 @@ template <> void derefGPtr(WebKitWebViewBackend* ptr);+ }++ void webkitWebViewBackendUnref(WebKitWebViewBackend*);++++cairo_surface_t* webkitWebViewBackendTakeScreenshot(WebKitWebViewBackend*);+diff --git a/Source/WebKit/UIProcess/API/wpe/docs/wpe-1.0-sections.txt b/Source/WebKit/UIProcess/API/wpe/docs/wpe-1.0-sections.txt+index 02f49add059c0d282e751a7ee69810277112381d..de1f79443e4fe04d2f1196ab3508aa18c76f0ccd 100644+--- a/Source/WebKit/UIProcess/API/wpe/docs/wpe-1.0-sections.txt++++ b/Source/WebKit/UIProcess/API/wpe/docs/wpe-1.0-sections.txt+@@ -315,6 +315,8 @@ WEBKIT_TYPE_WEB_VIEW_BACKEND+ WebKitWebViewBackend+ webkit_web_view_backend_get_wpe_backend+ webkit_web_view_backend_new++take_screenshot_callback++webkit_web_view_backend_set_screenshot_callback++ <SUBSECTION Private>+ webkit_web_view_backend_get_typediff --git a/Source/WebKit/UIProcess/API/wpe/webkit.h b/Source/WebKit/UIProcess/API/wpe/webkit.hindex 02e258253e47fbf6594c20f743d0faeac8a4eefe..e051fdf396dc65717def6b36168b5538e3cb2f4d 100644--- a/Source/WebKit/UIProcess/API/wpe/webkit.h@@ -8603,10 +8776,10 @@ index 59cdfdafab1d85ea3a5aecb3cd2293e6dfb1eb8d..52fe7990b1c18b964ee3cfa9f324e3c2// The timeout we use when waiting for a DidUpdateGeometry message.diff --git a/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.cpp b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.cppnew file mode 100644-index 0000000000000000000000000000000000000000..4da3a8e8e55b60c29240692ce2bb316de8b28cb1+index 0000000000000000000000000000000000000000..88892d0e1128a23f8f586610691800fc306b2a0d--- /dev/null+++ b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.cpp-@@ -0,0 +1,259 @@+@@ -0,0 +1,263 @@+/*+ * Copyright (C) 2020 Microsoft Corporation.+ *@@ -8643,12 +8816,16 @@ index 0000000000000000000000000000000000000000..4da3a8e8e55b60c29240692ce2bb316d+#include <WebCore/NotImplemented.h>++#if PLATFORM(GTK)-+#include "DrawingAreaProxyCoordinatedGraphics.h"++#include "DrawingAreaProxy.h"+#include "ScreencastEncoder.h"+#include <WebCore/ImageBufferUtilitiesCairo.h>+#include <gtk/gtk.h>+#include <wtf/text/Base64.h>+#endif++#if PLATFORM(WPE)++#include "DrawingAreaProxy.h"++#include "ScreencastEncoder.h"++#endif++namespace WebKit {+@@ -8679,7 +8856,7 @@ index 0000000000000000000000000000000000000000..4da3a8e8e55b60c29240692ce2bb316d+#if USE(COORDINATED_GRAPHICS)+void InspectorScreencastAgent::didPaint(cairo_surface_t* surface)+{-+#if PLATFORM(GTK)++#if PLATFORM(GTK) || PLATFORM(WPE)+ if (m_encoder)+ m_encoder->encodeFrame(surface, m_page.drawingArea()->size());+#else@@ -8747,7 +8924,7 @@ index 0000000000000000000000000000000000000000..4da3a8e8e55b60c29240692ce2bb316d++void InspectorScreencastAgent::startVideoRecording(Inspector::ErrorString& errorString, const String& file, int width, int height)+{-+#if PLATFORM(GTK)++#if PLATFORM(GTK) || PLATFORM(WPE)+ if (m_encoder) {+ errorString = "Already recording"_s;+ return;@@ -8769,7 +8946,7 @@ index 0000000000000000000000000000000000000000..4da3a8e8e55b60c29240692ce2bb316d++void InspectorScreencastAgent::stopVideoRecording(Ref<StopVideoRecordingCallback>&& callback)+{-+#if PLATFORM(GTK)++#if PLATFORM(GTK) || PLATFORM(WPE)+ if (!m_encoder) {+ callback->sendFailure("Not recording"_s);+ return;@@ -8868,7 +9045,7 @@ index 0000000000000000000000000000000000000000..4da3a8e8e55b60c29240692ce2bb316d+} // namespace WebKitdiff --git a/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.hnew file mode 100644-index 0000000000000000000000000000000000000000..dbdb294ee1b4c04e1dec3f53bd229d2a89e7e767+index 0000000000000000000000000000000000000000..be0d7aa673210ca4d0c11c7789ee69edd680c2a1--- /dev/null+++ b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h@@ -0,0 +1,89 @@@@ -8955,7 +9132,7 @@ index 0000000000000000000000000000000000000000..dbdb294ee1b4c04e1dec3f53bd229d2a+ enum class ImageFormat { Jpeg, Png };+ ImageFormat m_format { ImageFormat::Jpeg };+ Optional<int> m_quality;-+#if PLATFORM(GTK)++#if PLATFORM(GTK) || PLATFORM(WPE)+ RefPtr<ScreencastEncoder> m_encoder;+#endif+};@@ -8963,10 +9140,10 @@ index 0000000000000000000000000000000000000000..dbdb294ee1b4c04e1dec3f53bd229d2a+} // namespace WebKitdiff --git a/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.cpp b/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.cppnew file mode 100644-index 0000000000000000000000000000000000000000..39ebb8bf0cd3bda7913e9f029eeff5256de3fcac+index 0000000000000000000000000000000000000000..4fe06984b854ec4d36a0b1c7c6ba534d35880c1f--- /dev/null+++ b/Source/WebKit/UIProcess/Inspector/Agents/ScreencastEncoder.cpp-@@ -0,0 +1,395 @@+@@ -0,0 +1,401 @@+/*+ * Copyright (c) 2010, The WebM Project authors. All rights reserved.+ * Copyright (c) 2013 The Chromium Authors. All rights reserved.@@ -9315,6 +9492,10 @@ index 0000000000000000000000000000000000000000..39ebb8bf0cd3bda7913e9f029eeff525+{+ MonotonicTime now = MonotonicTime::now();+ if (m_lastFrameTimestamp) {++ // If previous frame encoding failed for some rason leave the timestampt intact.++ if (!m_lastFrame)++ return;+++ Seconds seconds = now - m_lastFrameTimestamp;+ int duration = 1 + seconds.seconds() * fps; // Duration in timebase units+ m_lastFrame->setDuration(duration);@@ -9327,6 +9508,8 @@ index 0000000000000000000000000000000000000000..39ebb8bf0cd3bda7913e9f029eeff525+{+ fprintf(stderr, "ScreencastEncoder::encodeFrame\n");+ flushLastFrame();++ // Note that in WPE drawing area size is updated asynchronously and may differ from acutal++ // size of the surface.+ if (size.isZero()) {+ fprintf(stderr, "Cairo surface size is 0\n");+ return;@@ -9543,7 +9726,7 @@ index a2239cec8e18850f35f7f88a9c4ebadc62bf4023..79f3ff84327dc075ec96983e04db4b10} // namespace WebKitdiff --git a/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp b/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp-index 1861cff806131196ea49b4f8aca6665beebbf6e8..fc37922a680f2a46e2512975b558b839d75cff42 100644+index 1861cff806131196ea49b4f8aca6665beebbf6e8..2d910fb6867a257e7bd9f1741c192f1e51f02071 100644--- a/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp+++ b/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp@@ -26,12 +26,20 @@@@ -9600,7 +9783,7 @@ index 1861cff806131196ea49b4f8aca6665beebbf6e8..fc37922a680f2a46e2512975b558b839+ m_inputAgent = inputAgent.get();+ m_agents.append(WTFMove(inputAgent));+ m_agents.append(makeUnique<InspectorDialogAgent>(m_backendDispatcher.get(), m_frontendRouter.get(), m_page));-+#if !PLATFORM(WPE) && !PLATFORM(WIN)++#if !PLATFORM(WIN)+ auto screencastAgent = makeUnique<InspectorScreencastAgent>(m_backendDispatcher.get(), m_frontendRouter.get(), m_page);+ m_screecastAgent = screencastAgent.get();+ m_agents.append(WTFMove(screencastAgent));@@ -11250,9 +11433,18 @@ index 7a14cfba15c103a2d4fe263fa49d25af3c396ec2..3ee0e154349661632799057c71f1d1f1BOOL result = ::CreateProcess(0, commandLine.data(), 0, 0, true, 0, 0, 0, &startupInfo, &processInformation);diff --git a/Source/WebKit/UIProcess/PageClient.h b/Source/WebKit/UIProcess/PageClient.h-index ac5d90eb539fb0065265558e2e94615a874fa6cb..9711c488a01f4a15ed98c519ebee072a0c1ddece 100644+index ac5d90eb539fb0065265558e2e94615a874fa6cb..70dc5feb265f56406058560d39d43eba0264d848 100644--- a/Source/WebKit/UIProcess/PageClient.h+++ b/Source/WebKit/UIProcess/PageClient.h+@@ -247,7 +247,7 @@ public:+ virtual void showSafeBrowsingWarning(const SafeBrowsingWarning&, CompletionHandler<void(Variant<ContinueUnsafeLoad, URL>&&)>&& completionHandler) { completionHandler(ContinueUnsafeLoad::Yes); }+ virtual void clearSafeBrowsingWarning() { }+ virtual void clearSafeBrowsingWarningIfForMainFrameNavigation() { }+-+++ #if ENABLE(DRAG_SUPPORT)+ #if PLATFORM(GTK)+ virtual void startDrag(WebCore::SelectionData&&, WebCore::DragOperation, RefPtr<ShareableBitmap>&& dragImage) = 0;@@ -286,6 +286,11 @@ public:virtual void selectionDidChange() = 0;#endif@@ -11265,6 +11457,24 @@ index ac5d90eb539fb0065265558e2e94615a874fa6cb..9711c488a01f4a15ed98c519ebee072a#if PLATFORM(COCOA) || PLATFORM(GTK)virtual RefPtr<ViewSnapshot> takeViewSnapshot(Optional<WebCore::IntRect>&&) = 0;#endif+@@ -346,7 +351,7 @@ public:+ virtual void setTextIndicator(Ref<WebCore::TextIndicator>, WebCore::TextIndicatorWindowLifetime) = 0;+ virtual void clearTextIndicator(WebCore::TextIndicatorWindowDismissalAnimation) = 0;+ virtual void setTextIndicatorAnimationProgress(float) = 0;+-+++ virtual void didPerformDictionaryLookup(const WebCore::DictionaryPopupInfo&) = 0;+ #endif++@@ -476,7 +481,7 @@ public:+ virtual bool hasSafeBrowsingWarning() const { return false; }++ virtual void setMouseEventPolicy(WebCore::MouseEventPolicy) { }+-+++ #if PLATFORM(MAC)+ virtual void didPerformImmediateActionHitTest(const WebHitTestResultData&, bool contentPreventsDefault, API::Object*) = 0;+ virtual NSObject *immediateActionAnimationControllerForHitTestResult(RefPtr<API::HitTestResult>, uint64_t, RefPtr<API::Object>) = 0;diff --git a/Source/WebKit/UIProcess/RemoteInspectorPipe.cpp b/Source/WebKit/UIProcess/RemoteInspectorPipe.cppnew file mode 100644index 0000000000000000000000000000000000000000..f5025df794fd34f1b08d7a37e7a1f3c8a14ada97@@ -15331,7 +15541,7 @@ index 2ff45b938cffabe95fe17137393b8b6c506d4993..79180075025fd323cc9e818c76603d0freturn 0;}diff --git a/Tools/MiniBrowser/wpe/main.cpp b/Tools/MiniBrowser/wpe/main.cpp-index fde24a7cc8ceb8cc6d7810e3548a5129d1c0a187..9344a1edd2f9931583c04de2a25a2ec71b2702e8 100644+index fde24a7cc8ceb8cc6d7810e3548a5129d1c0a187..3f993c33069b063f6f2446e9503b9f095974ee0f 100644--- a/Tools/MiniBrowser/wpe/main.cpp+++ b/Tools/MiniBrowser/wpe/main.cpp@@ -43,6 +43,9 @@ static gboolean headlessMode;@@ -15390,12 +15600,20 @@ index fde24a7cc8ceb8cc6d7810e3548a5129d1c0a187..9344a1edd2f9931583c04de2a25a2ec7{auto backend = createViewBackend(1280, 720);struct wpe_view_backend* wpeBackend = backend->backend();-@@ -166,17 +193,51 @@ static WebKitWebView* createWebView(WebKitWebView* webView, WebKitNavigationActi+@@ -166,17 +193,59 @@ static WebKitWebView* createWebView(WebKitWebView* webView, WebKitNavigationActidelete static_cast<WPEToolingBackends::ViewBackend*>(data);}, backend.release());- auto* newWebView = webkit_web_view_new_with_related_view(viewBackend, webView);- webkit_web_view_set_settings(newWebView, webkit_web_view_get_settings(webView));++// Playwright begin++ if (headlessMode) {++ webkit_web_view_backend_set_screenshot_callback(viewBackend,++ [](gpointer data) {++ return static_cast<WPEToolingBackends::HeadlessViewBackend*>(data)->snapshot();++ });++ }++// Playwright end+ WebKitWebView* newWebView;+ if (webView) {+ newWebView = webkit_web_view_new_with_related_view(viewBackend, webView);@@ -15444,7 +15662,7 @@ index fde24a7cc8ceb8cc6d7810e3548a5129d1c0a187..9344a1edd2f9931583c04de2a25a2ec7int main(int argc, char *argv[]){#if ENABLE_DEVELOPER_MODE-@@ -211,6 +272,16 @@ int main(int argc, char *argv[])+@@ -211,6 +280,16 @@ int main(int argc, char *argv[])}auto* loop = g_main_loop_new(nullptr, FALSE);@@ -15461,7 +15679,7 @@ index fde24a7cc8ceb8cc6d7810e3548a5129d1c0a187..9344a1edd2f9931583c04de2a25a2ec7auto backend = createViewBackend(1280, 720);struct wpe_view_backend* wpeBackend = backend->backend();-@@ -220,7 +291,19 @@ int main(int argc, char *argv[])+@@ -220,7 +299,19 @@ int main(int argc, char *argv[])return 1;}@@ -15482,7 +15700,7 @@ index fde24a7cc8ceb8cc6d7810e3548a5129d1c0a187..9344a1edd2f9931583c04de2a25a2ec7if (cookiesPolicy) {auto* cookieManager = webkit_web_context_get_cookie_manager(webContext);-@@ -238,7 +321,7 @@ int main(int argc, char *argv[])+@@ -238,7 +329,7 @@ int main(int argc, char *argv[])}if (proxy) {@@ -15491,7 +15709,23 @@ index fde24a7cc8ceb8cc6d7810e3548a5129d1c0a187..9344a1edd2f9931583c04de2a25a2ec7webkit_web_context_set_network_proxy_settings(webContext, WEBKIT_NETWORK_PROXY_MODE_CUSTOM, webkitProxySettings);webkit_network_proxy_settings_free(webkitProxySettings);}-@@ -301,8 +384,6 @@ int main(int argc, char *argv[])+@@ -284,7 +375,14 @@ int main(int argc, char *argv[])+ auto* viewBackend = webkit_web_view_backend_new(wpeBackend, [](gpointer data) {+ delete static_cast<WPEToolingBackends::ViewBackend*>(data);+ }, backend.release());+-++// Playwright begin++ if (headlessMode) {++ webkit_web_view_backend_set_screenshot_callback(viewBackend,++ [](gpointer data) {++ return static_cast<WPEToolingBackends::HeadlessViewBackend*>(data)->snapshot();++ });++ }++// Playwright end+ auto* webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW,+ "backend", viewBackend,+ "web-context", webContext,+@@ -301,8 +399,6 @@ int main(int argc, char *argv[])backendPtr->setAccessibleChild(ATK_OBJECT(accessible));#endif@@ -15500,7 +15734,7 @@ index fde24a7cc8ceb8cc6d7810e3548a5129d1c0a187..9344a1edd2f9931583c04de2a25a2ec7webkit_web_context_set_automation_allowed(webContext, automationMode);g_signal_connect(webContext, "automation-started", G_CALLBACK(automationStartedCallback), webView);g_signal_connect(webView, "permission-request", G_CALLBACK(decidePermissionRequest), nullptr);-@@ -318,16 +399,9 @@ int main(int argc, char *argv[])+@@ -318,16 +414,9 @@ int main(int argc, char *argv[])webkit_web_view_set_background_color(webView, &color);if (uriArguments) {@@ -15520,7 +15754,7 @@ index fde24a7cc8ceb8cc6d7810e3548a5129d1c0a187..9344a1edd2f9931583c04de2a25a2ec7webkit_web_view_load_uri(webView, "about:blank");elsewebkit_web_view_load_uri(webView, "https://wpewebkit.org");-@@ -337,8 +411,7 @@ int main(int argc, char *argv[])+@@ -337,8 +426,7 @@ int main(int argc, char *argv[])g_hash_table_destroy(openViews);@@ -15567,3 +15801,58 @@ index e66973b745dee8bacf717cd826cba87cbfa8f499..a6a4d7a28d6330c852f56fcedabf1659};WKPageSetPageUIClient(m_mainWebView->page(), &pageUIClient.base);+diff --git a/Tools/wpe/backends/HeadlessViewBackend.cpp b/Tools/wpe/backends/HeadlessViewBackend.cpp+index d0af19a9aba9aeab8aa3acb2f8c1129f83e07cd7..b32f3eb1495f5f21f059a9eca236bbbf9584b682 100644+--- a/Tools/wpe/backends/HeadlessViewBackend.cpp++++ b/Tools/wpe/backends/HeadlessViewBackend.cpp+@@ -148,27 +148,24 @@ void HeadlessViewBackend::updateSnapshot(struct wpe_fdo_shm_exported_buffer* exp+ return;+ }++- uint32_t bufferStride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, m_width);+- uint8_t* buffer = new uint8_t[bufferStride * m_height];+- memset(buffer, 0, bufferStride * m_height);++ uint32_t width = std::max(0, wl_shm_buffer_get_width(shmBuffer));++ uint32_t height = std::max(0, wl_shm_buffer_get_height(shmBuffer));++ if (!width || !height) {++ fprintf(stderr, "HeadlessViewBackend::updateSnapshot shmBuffer is empty: %ux%u\n", width, height);++ return;++ }+++ uint32_t bufferStride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);++ uint32_t stride = std::max(0, wl_shm_buffer_get_stride(shmBuffer));++ if (bufferStride != stride) {++ fprintf(stderr, "bufferStride != stride: %u != %u\n", bufferStride, stride);++ return;++ }++ uint8_t* buffer = new uint8_t[bufferStride * height];+ {+- uint32_t width = std::min<uint32_t>(m_width, std::max(0, wl_shm_buffer_get_width(shmBuffer)));+- uint32_t height = std::min<uint32_t>(m_height, std::max(0, wl_shm_buffer_get_height(shmBuffer)));+- uint32_t stride = std::max(0, wl_shm_buffer_get_stride(shmBuffer));+-+ wl_shm_buffer_begin_access(shmBuffer);+ auto* data = static_cast<uint8_t*>(wl_shm_buffer_get_data(shmBuffer));+-+- for (uint32_t y = 0; y < height; ++y) {+- for (uint32_t x = 0; x < width; ++x) {+- buffer[bufferStride * y + 4 * x + 0] = data[stride * y + 4 * x + 0];+- buffer[bufferStride * y + 4 * x + 1] = data[stride * y + 4 * x + 1];+- buffer[bufferStride * y + 4 * x + 2] = data[stride * y + 4 * x + 2];+- buffer[bufferStride * y + 4 * x + 3] = data[stride * y + 4 * x + 3];+- }+- }+-++ memcpy(buffer, data, bufferStride * height);+ wl_shm_buffer_end_access(shmBuffer);+ }++@@ -176,7 +173,7 @@ void HeadlessViewBackend::updateSnapshot(struct wpe_fdo_shm_exported_buffer* exp+ cairo_surface_destroy(m_snapshot);++ m_snapshot = cairo_image_surface_create_for_data(buffer, CAIRO_FORMAT_ARGB32,+- m_width, m_height, cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, m_width));++ width, height, cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width));++ static cairo_user_data_key_t bufferKey;+ cairo_surface_set_user_data(m_snapshot, &bufferKey, buffer,