From 4cac74f8c2656abd94e3ef1303116e6b646ba84f Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Mon, 8 Jun 2020 10:53:09 -0700 Subject: [PATCH] browser(webkit): continue screecast after cross-process navigation (#2499) --- browser_patches/webkit/BUILD_NUMBER | 2 +- browser_patches/webkit/patches/bootstrap.diff | 144 ++++++++++-------- 2 files changed, 80 insertions(+), 66 deletions(-) diff --git a/browser_patches/webkit/BUILD_NUMBER b/browser_patches/webkit/BUILD_NUMBER index 8944e21bb8ffc..e4a7c9900f846 100644 --- a/browser_patches/webkit/BUILD_NUMBER +++ b/browser_patches/webkit/BUILD_NUMBER @@ -1 +1 @@ -1269 +1270 diff --git a/browser_patches/webkit/patches/bootstrap.diff b/browser_patches/webkit/patches/bootstrap.diff index d3dfac9638653..471b4628bef1e 100644 --- a/browser_patches/webkit/patches/bootstrap.diff +++ b/browser_patches/webkit/patches/bootstrap.diff @@ -8476,35 +8476,26 @@ index 6bbd1cabd27ae2847648a8c2edcf9acfcd556ff5..38d101b9a96986e40f6e9f0261fa429a { m_hasReceivedFirstUpdate = true; diff --git a/Source/WebKit/UIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.h b/Source/WebKit/UIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.h -index d7695088e7cfc4f638f157338754f9f157489749..74a3654235d5e24a39d3714ec4d2f45a8803c816 100644 +index d7695088e7cfc4f638f157338754f9f157489749..d7ed4f58f033ebfc13142f2d6e8814d6dd13dd8e 100644 --- a/Source/WebKit/UIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.h +++ b/Source/WebKit/UIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.h -@@ -30,6 +30,8 @@ +@@ -30,6 +30,7 @@ #include "BackingStore.h" #include "DrawingAreaProxy.h" #include "LayerTreeContext.h" +#include -+#include #include namespace WebCore { -@@ -49,6 +51,15 @@ public: +@@ -49,6 +50,7 @@ public: bool isInAcceleratedCompositingMode() const { return !m_layerTreeContext.isEmpty(); } const LayerTreeContext& layerTreeContext() const { return m_layerTreeContext; } + void waitForSizeUpdate(Function&&); -+ -+ using PaintCallback = Function; -+ void setPaintCallback(PaintCallback&& callback) { m_paintCallback = WTFMove(callback); } -+ void didPaint(cairo_surface_t* surface, WebCore::IntSize size) -+ { -+ if (m_paintCallback) -+ m_paintCallback(surface, size); -+ } private: // DrawingAreaProxy -@@ -126,12 +137,15 @@ private: +@@ -126,6 +128,8 @@ private: // For a new Drawing Area don't draw anything until the WebProcess has sent over the first content. bool m_hasReceivedFirstUpdate { false }; @@ -8513,13 +8504,6 @@ index d7695088e7cfc4f638f157338754f9f157489749..74a3654235d5e24a39d3714ec4d2f45a #if !PLATFORM(WPE) bool m_isBackingStoreDiscardable { true }; std::unique_ptr m_backingStore; - RunLoop::Timer m_discardBackingStoreTimer; - #endif - std::unique_ptr m_drawingMonitor; -+ PaintCallback m_paintCallback; - }; - - } // namespace WebKit diff --git a/Source/WebKit/UIProcess/Downloads/DownloadProxy.cpp b/Source/WebKit/UIProcess/Downloads/DownloadProxy.cpp index c5de4e7d0f59194f43a023b089e372c58cf8ee06..211f4c1baf5d1a66cd08ee8147e96f7ec6c0098a 100644 --- a/Source/WebKit/UIProcess/Downloads/DownloadProxy.cpp @@ -8622,10 +8606,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.cpp new file mode 100644 -index 0000000000000000000000000000000000000000..103febd9eed246c6cc1f21f7e5e4f5a56bb03ac5 +index 0000000000000000000000000000000000000000..d796a81ab5dae0627fab017f77074d411c4da40a --- /dev/null +++ b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.cpp -@@ -0,0 +1,257 @@ +@@ -0,0 +1,255 @@ +/* + * Copyright (C) 2020 Microsoft Corporation. + * @@ -8695,6 +8679,14 @@ index 0000000000000000000000000000000000000000..103febd9eed246c6cc1f21f7e5e4f5a5 + stop(errorString); +} + ++#if USE(COORDINATED_GRAPHICS) ++void InspectorScreencastAgent::didPaint(cairo_surface_t* surface) ++{ ++ if (m_encoder) ++ m_encoder->encodeFrame(surface, m_page.drawingArea()->size()); ++} ++#endif ++ +void InspectorScreencastAgent::start(Inspector::ErrorString& errorString, const String& format, const int* quality) +{ + if (m_enabled) @@ -8759,23 +8751,16 @@ index 0000000000000000000000000000000000000000..103febd9eed246c6cc1f21f7e5e4f5a5 + errorString = "Already recording"_s; + return; + } ++ + if (width < 10 || width > 10000 || height < 10 || height > 10000) { + errorString = "Invalid size"_s; + return; + } + -+ if (auto* drawingArea = static_cast(m_page.drawingArea())) { -+ m_encoder = ScreencastEncoder::create(errorString, file, IntSize(width, height)); -+ if (!m_encoder) -+ return; -+ -+ drawingArea->setPaintCallback([encoder = m_encoder.get()] (cairo_surface_t* surface, WebCore::IntSize size) { -+ encoder->encodeFrame(surface, size); -+ }); -+ } else { -+ errorString = "Cannot get drawing area"_s; ++ m_encoder = ScreencastEncoder::create(errorString, file, IntSize(width, height)); ++ if (!m_encoder) + return; -+ } ++ +#else + errorString = "Not implemented"_s; +#endif @@ -8789,9 +8774,6 @@ index 0000000000000000000000000000000000000000..103febd9eed246c6cc1f21f7e5e4f5a5 + return; + } + -+ if (auto* drawingArea = static_cast(m_page.drawingArea())) -+ drawingArea->setPaintCallback(nullptr); -+ + m_encoder->finish([protectRef = m_encoder.copyRef(), callback = WTFMove(callback)] { + callback->sendSuccess(); + }); @@ -8885,10 +8867,10 @@ index 0000000000000000000000000000000000000000..103febd9eed246c6cc1f21f7e5e4f5a5 +} // namespace WebKit diff --git a/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h new file mode 100644 -index 0000000000000000000000000000000000000000..2f96d82a650993bc0b0469453e7634d20771d797 +index 0000000000000000000000000000000000000000..dbdb294ee1b4c04e1dec3f53bd229d2a89e7e767 --- /dev/null +++ b/Source/WebKit/UIProcess/Inspector/Agents/InspectorScreencastAgent.h -@@ -0,0 +1,85 @@ +@@ -0,0 +1,89 @@ +/* + * Copyright (C) 2020 Microsoft Corporation. + * @@ -8945,6 +8927,10 @@ index 0000000000000000000000000000000000000000..2f96d82a650993bc0b0469453e7634d2 + void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override; + void willDestroyFrontendAndBackend(Inspector::DisconnectReason) override; + ++#if USE(COORDINATED_GRAPHICS) ++ void didPaint(cairo_surface_t*); ++#endif ++ + void start(Inspector::ErrorString&, const String& format, const int* quality) override; + void stop(Inspector::ErrorString&) override; + void frameAck(Inspector::ErrorString&) override; @@ -9556,7 +9542,7 @@ index a2239cec8e18850f35f7f88a9c4ebadc62bf4023..79f3ff84327dc075ec96983e04db4b10 } // namespace WebKit diff --git a/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp b/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp -index 1861cff806131196ea49b4f8aca6665beebbf6e8..57cb5bd0a6916b00da01af17b743da9e04094a77 100644 +index 1861cff806131196ea49b4f8aca6665beebbf6e8..fc37922a680f2a46e2512975b558b839d75cff42 100644 --- a/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp +++ b/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp @@ -26,12 +26,20 @@ @@ -9580,7 +9566,7 @@ index 1861cff806131196ea49b4f8aca6665beebbf6e8..57cb5bd0a6916b00da01af17b743da9e #include #include #include -@@ -48,27 +56,104 @@ static String getTargetID(const ProvisionalPageProxy& provisionalPage) +@@ -48,27 +56,106 @@ static String getTargetID(const ProvisionalPageProxy& provisionalPage) return WebPageInspectorTarget::toTargetID(provisionalPage.webPageID()); } @@ -9614,7 +9600,9 @@ index 1861cff806131196ea49b4f8aca6665beebbf6e8..57cb5bd0a6916b00da01af17b743da9e + m_agents.append(WTFMove(inputAgent)); + m_agents.append(makeUnique(m_backendDispatcher.get(), m_frontendRouter.get(), m_page)); +#if !PLATFORM(WPE) && !PLATFORM(WIN) -+ m_agents.append(makeUnique(m_backendDispatcher.get(), m_frontendRouter.get(), m_page)); ++ auto screencastAgent = makeUnique(m_backendDispatcher.get(), m_frontendRouter.get(), m_page); ++ m_screecastAgent = screencastAgent.get(); ++ m_agents.append(WTFMove(screencastAgent)); +#endif + if (s_observer) + s_observer->didCreateInspectorController(m_page); @@ -9688,7 +9676,7 @@ index 1861cff806131196ea49b4f8aca6665beebbf6e8..57cb5bd0a6916b00da01af17b743da9e } bool WebPageInspectorController::hasLocalFrontend() const -@@ -82,6 +167,17 @@ void WebPageInspectorController::connectFrontend(Inspector::FrontendChannel& fro +@@ -82,6 +169,17 @@ void WebPageInspectorController::connectFrontend(Inspector::FrontendChannel& fro bool connectingFirstFrontend = !m_frontendRouter->hasFrontends(); @@ -9706,7 +9694,7 @@ index 1861cff806131196ea49b4f8aca6665beebbf6e8..57cb5bd0a6916b00da01af17b743da9e m_frontendRouter->connectFrontend(frontendChannel); if (connectingFirstFrontend) -@@ -100,8 +196,10 @@ void WebPageInspectorController::disconnectFrontend(FrontendChannel& frontendCha +@@ -100,8 +198,10 @@ void WebPageInspectorController::disconnectFrontend(FrontendChannel& frontendCha m_frontendRouter->disconnectFrontend(frontendChannel); bool disconnectingLastFrontend = !m_frontendRouter->hasFrontends(); @@ -9718,7 +9706,7 @@ index 1861cff806131196ea49b4f8aca6665beebbf6e8..57cb5bd0a6916b00da01af17b743da9e m_page.didChangeInspectorFrontendCount(m_frontendRouter->frontendCount()); -@@ -124,6 +222,8 @@ void WebPageInspectorController::disconnectAllFrontends() +@@ -124,6 +224,8 @@ void WebPageInspectorController::disconnectAllFrontends() // Disconnect any remaining remote frontends. m_frontendRouter->disconnectAllFrontends(); @@ -9727,10 +9715,21 @@ index 1861cff806131196ea49b4f8aca6665beebbf6e8..57cb5bd0a6916b00da01af17b743da9e m_page.didChangeInspectorFrontendCount(m_frontendRouter->frontendCount()); #if ENABLE(REMOTE_INSPECTOR) -@@ -150,6 +250,55 @@ void WebPageInspectorController::setIndicating(bool indicating) +@@ -150,6 +252,66 @@ void WebPageInspectorController::setIndicating(bool indicating) } #endif ++#if USE(COORDINATED_GRAPHICS) ++void WebPageInspectorController::didPaint(cairo_surface_t* surface) ++{ ++ if (!m_frontendRouter->hasFrontends()) ++ return; ++ ++ m_screecastAgent->didPaint(surface); ++} ++#endif ++ ++ +void WebPageInspectorController::navigate(WebCore::ResourceRequest&& request, WebFrameProxy* frame, NavigationHandler&& completionHandler) +{ + auto navigation = m_page.loadRequestForInspector(WTFMove(request), frame); @@ -9783,7 +9782,7 @@ index 1861cff806131196ea49b4f8aca6665beebbf6e8..57cb5bd0a6916b00da01af17b743da9e void WebPageInspectorController::createInspectorTarget(const String& targetId, Inspector::InspectorTargetType type) { addTarget(InspectorTargetProxy::create(m_page, targetId, type)); -@@ -169,6 +318,33 @@ void WebPageInspectorController::sendMessageToInspectorFrontend(const String& ta +@@ -169,6 +331,33 @@ void WebPageInspectorController::sendMessageToInspectorFrontend(const String& ta m_targetAgent->sendMessageFromTargetToFrontend(targetId, message); } @@ -9817,7 +9816,7 @@ index 1861cff806131196ea49b4f8aca6665beebbf6e8..57cb5bd0a6916b00da01af17b743da9e bool WebPageInspectorController::shouldPauseLoading(const ProvisionalPageProxy& provisionalPage) const { if (!m_frontendRouter->hasFrontends()) -@@ -188,7 +364,7 @@ void WebPageInspectorController::setContinueLoadingCallback(const ProvisionalPag +@@ -188,7 +377,7 @@ void WebPageInspectorController::setContinueLoadingCallback(const ProvisionalPag void WebPageInspectorController::didCreateProvisionalPage(ProvisionalPageProxy& provisionalPage) { @@ -9826,7 +9825,7 @@ index 1861cff806131196ea49b4f8aca6665beebbf6e8..57cb5bd0a6916b00da01af17b743da9e } void WebPageInspectorController::willDestroyProvisionalPage(const ProvisionalPageProxy& provisionalPage) -@@ -241,4 +417,20 @@ void WebPageInspectorController::addTarget(std::unique_ptr +@@ -241,4 +430,20 @@ void WebPageInspectorController::addTarget(std::unique_ptr m_targets.set(target->identifier(), WTFMove(target)); } @@ -9848,7 +9847,7 @@ index 1861cff806131196ea49b4f8aca6665beebbf6e8..57cb5bd0a6916b00da01af17b743da9e + } // namespace WebKit diff --git a/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.h b/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.h -index 9ce5ef36b652fd56a843c1d12a4c3c3cf639282c..bb4d6b26bf245aebc2bd0f435a7bb83151331961 100644 +index 9ce5ef36b652fd56a843c1d12a4c3c3cf639282c..ca95d658c1f260020624291aaf5d8ea4172e5b45 100644 --- a/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.h +++ b/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.h @@ -26,17 +26,27 @@ @@ -9879,10 +9878,11 @@ index 9ce5ef36b652fd56a843c1d12a4c3c3cf639282c..bb4d6b26bf245aebc2bd0f435a7bb831 } namespace WebKit { -@@ -44,6 +54,21 @@ namespace WebKit { +@@ -44,6 +54,22 @@ namespace WebKit { class InspectorBrowserAgent; struct WebPageAgentContext; ++class InspectorScreencastAgent; +class WebFrameProxy; +class WebPageInspectorEmulationAgent; +class WebPageInspectorInputAgent; @@ -9901,7 +9901,7 @@ index 9ce5ef36b652fd56a843c1d12a4c3c3cf639282c..bb4d6b26bf245aebc2bd0f435a7bb831 class WebPageInspectorController { WTF_MAKE_NONCOPYABLE(WebPageInspectorController); WTF_MAKE_FAST_ALLOCATED; -@@ -51,7 +76,19 @@ public: +@@ -51,7 +77,19 @@ public: WebPageInspectorController(WebPageProxy&); void init(); @@ -9921,17 +9921,20 @@ index 9ce5ef36b652fd56a843c1d12a4c3c3cf639282c..bb4d6b26bf245aebc2bd0f435a7bb831 bool hasLocalFrontend() const; -@@ -65,10 +102,22 @@ public: +@@ -64,11 +102,25 @@ public: + #if ENABLE(REMOTE_INSPECTOR) void setIndicating(bool); #endif - ++#if USE(COORDINATED_GRAPHICS) ++ void didPaint(cairo_surface_t*); ++#endif + using NavigationHandler = Function; + void navigate(WebCore::ResourceRequest&&, WebFrameProxy*, NavigationHandler&&); + void didReceivePolicyDecision(WebCore::PolicyAction action, uint64_t navigationID); + void didDestroyNavigation(uint64_t navigationID); + + void didFailProvisionalLoadForFrame(uint64_t navigationID, const WebCore::ResourceError& error); -+ + void createInspectorTarget(const String& targetId, Inspector::InspectorTargetType); void destroyInspectorTarget(const String& targetId); void sendMessageToInspectorFrontend(const String& targetId, const String& message); @@ -9944,7 +9947,7 @@ index 9ce5ef36b652fd56a843c1d12a4c3c3cf639282c..bb4d6b26bf245aebc2bd0f435a7bb831 bool shouldPauseLoading(const ProvisionalPageProxy&) const; void setContinueLoadingCallback(const ProvisionalPageProxy&, WTF::Function&&); -@@ -84,6 +133,7 @@ private: +@@ -84,6 +136,7 @@ private: void createLazyAgents(); void addTarget(std::unique_ptr&&); @@ -9952,12 +9955,13 @@ index 9ce5ef36b652fd56a843c1d12a4c3c3cf639282c..bb4d6b26bf245aebc2bd0f435a7bb831 Ref m_frontendRouter; Ref m_backendDispatcher; -@@ -92,11 +142,16 @@ private: +@@ -92,11 +145,17 @@ private: WebPageProxy& m_page; Inspector::InspectorTargetAgent* m_targetAgent; + WebPageInspectorEmulationAgent* m_emulationAgent { nullptr }; + WebPageInspectorInputAgent* m_inputAgent { nullptr }; ++ InspectorScreencastAgent* m_screecastAgent { nullptr }; HashMap> m_targets; InspectorBrowserAgent* m_enabledInspectorBrowserAgent; @@ -12702,10 +12706,10 @@ index 964c6315e38f5e0a0303febce45b1e975054f0b4..117d8c7c74bc81b34cfc0fe2b11a5429 UniqueRef m_soAuthorizationCoordinator; #endif diff --git a/Source/WebKit/UIProcess/cairo/BackingStoreCairo.cpp b/Source/WebKit/UIProcess/cairo/BackingStoreCairo.cpp -index dc0a70b8824afdc7ec3dd1f69f4d9b51942924f6..f31988b5b9b896f17994bcf15c72b5f384d65afb 100644 +index dc0a70b8824afdc7ec3dd1f69f4d9b51942924f6..4da6649c86b46dea36c2750802494ddb9b70cc24 100644 --- a/Source/WebKit/UIProcess/cairo/BackingStoreCairo.cpp +++ b/Source/WebKit/UIProcess/cairo/BackingStoreCairo.cpp -@@ -27,6 +27,7 @@ +@@ -27,9 +27,11 @@ #include "config.h" #include "BackingStore.h" @@ -12713,13 +12717,16 @@ index dc0a70b8824afdc7ec3dd1f69f4d9b51942924f6..f31988b5b9b896f17994bcf15c72b5f3 #include "ShareableBitmap.h" #include "UpdateInfo.h" #include "WebPageProxy.h" -@@ -72,6 +73,10 @@ void BackingStore::paint(cairo_t* context, const IntRect& rect) ++#include "WebPageInspectorController.h" + #include + #include + #include +@@ -72,6 +74,9 @@ void BackingStore::paint(cairo_t* context, const IntRect& rect) cairo_rectangle(context, rect.x(), rect.y(), rect.width(), rect.height()); cairo_fill(context); cairo_restore(context); +#if PLATFORM(GTK) -+ if (auto* drawingArea = static_cast(m_webPageProxy.drawingArea())) -+ drawingArea->didPaint(m_backend->surface(), drawingArea->size()); ++ m_webPageProxy.inspectorController().didPaint(m_backend->surface()); +#endif } @@ -12997,15 +13004,22 @@ index 0000000000000000000000000000000000000000..a073a77390b206deb794efe937df4f35 + +#endif // ENABLE(REMOTE_INSPECTOR) diff --git a/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreX11.cpp b/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreX11.cpp -index be19b6007c9c0fbfffb859e40fd34751493fe7d1..dd51b743f0bb5ba5a537edd1caf0005054c89839 100644 +index be19b6007c9c0fbfffb859e40fd34751493fe7d1..ce214fb7e22f8623aff6e2487cecd0272b21c478 100644 --- a/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreX11.cpp +++ b/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreX11.cpp -@@ -256,6 +256,9 @@ bool AcceleratedBackingStoreX11::paint(cairo_t* cr, const IntRect& clipRect) +@@ -31,6 +31,7 @@ + #include "DrawingAreaProxyCoordinatedGraphics.h" + #include "LayerTreeContext.h" + #include "WebPageProxy.h" ++#include "WebPageInspectorController.h" + #include + #include + #include +@@ -256,6 +257,8 @@ bool AcceleratedBackingStoreX11::paint(cairo_t* cr, const IntRect& clipRect) cairo_restore(cr); -+ if (auto* drawingArea = static_cast(m_webPage.drawingArea())) -+ drawingArea->didPaint(m_surface.get(), drawingArea->size()); ++ m_webPage.inspectorController().didPaint(m_surface.get()); + cairo_surface_flush(m_surface.get());