Skip to content

Commit

Permalink
Cherry-pick 263022.8@webkit-2023.4-embargoed (221c50b). https://bugs.…
Browse files Browse the repository at this point in the history
…webkit.org/show_bug.cgi?id=237291

    Make sure end printing is handled before PrintFrame
    https://bugs.webkit.org/show_bug.cgi?id=237291

    Reviewed by Chris Dumez.

    To ensure end printing is handled (and layer tree is unfrozen)
    introduce a completion handler on EndPrinting and tie its completion
    to the completion handler in WebPageProxy::printFrame.

    Also do not call endPrinting from TestController.cpp since
    WebPageProxy::printFrame takes care of that.

    * LayoutTests/fast/media/print-video-crash-expected.txt: Added.
    * LayoutTests/fast/media/print-video-crash.html: Added.
    * Source/WebKit/UIProcess/WebPageProxy.cpp:
    (WebKit::WebPageProxy::printFrame):
    (WebKit::WebPageProxy::endPrinting):
    * Source/WebKit/UIProcess/WebPageProxy.h:
    * Source/WebKit/WebProcess/WebPage/WebPage.cpp:
    (WebKit::WebPage::endPrinting):
    * Source/WebKit/WebProcess/WebPage/WebPage.h:
    (WebKit::WebPage::endPrinting):
    (WebKit::WebPage::endPrintingDuringDOMPrintOperation):
    * Source/WebKit/WebProcess/WebPage/WebPage.messages.in:
    * Tools/WebKitTestRunner/TestController.cpp:
    (WTR::printFrame):

    Canonical link: https://commits.webkit.org/263022.8@webkit-2023.4-embargoed
  • Loading branch information
rwlbuis authored and mcatanzaro committed Jul 28, 2023
1 parent 36a57b9 commit 8536c77
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 13 deletions.
1 change: 1 addition & 0 deletions LayoutTests/fast/media/print-video-crash-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PASS
13 changes: 13 additions & 0 deletions LayoutTests/fast/media/print-video-crash.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script>
if (window.testRunner)
testRunner.dumpAsText();
visualViewport.onresize = () => {
print();
};
onload = () => {
let video = document.createElement('video');
video.src = 'data:';
document.body.append(video);
};
</script>
PASS
13 changes: 7 additions & 6 deletions Source/WebKit/UIProcess/WebPageProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6672,9 +6672,8 @@ void WebPageProxy::printFrame(FrameIdentifier frameID, const String& title, cons
frame->didChangeTitle(title);

m_uiClient->printFrame(*this, *frame, pdfFirstPageSize, [this, protectedThis = Ref { *this }, completionHandler = WTFMove(completionHandler)] () mutable {
endPrinting(); // Send a message synchronously while m_isPerformingDOMPrintOperation is still true.
endPrinting(WTFMove(completionHandler)); // Send a message synchronously while m_isPerformingDOMPrintOperation is still true.
m_isPerformingDOMPrintOperation = false;
completionHandler();
});
}

Expand Down Expand Up @@ -9561,17 +9560,19 @@ void WebPageProxy::beginPrinting(WebFrameProxy* frame, const PrintInfo& printInf
send(Messages::WebPage::BeginPrinting(frame->frameID(), printInfo));
}

void WebPageProxy::endPrinting()
void WebPageProxy::endPrinting(CompletionHandler<void()>&& callback)
{
if (!m_isInPrintingMode)
if (!m_isInPrintingMode) {
callback();
return;
}

m_isInPrintingMode = false;

if (m_isPerformingDOMPrintOperation)
send(Messages::WebPage::EndPrintingDuringDOMPrintOperation(), IPC::SendOption::DispatchMessageEvenWhenWaitingForUnboundedSyncReply);
sendWithAsyncReply(Messages::WebPage::EndPrintingDuringDOMPrintOperation(), WTFMove(callback), IPC::SendOption::DispatchMessageEvenWhenWaitingForUnboundedSyncReply);
else
send(Messages::WebPage::EndPrinting());
sendWithAsyncReply(Messages::WebPage::EndPrinting(), WTFMove(callback));
}

IPC::Connection::AsyncReplyID WebPageProxy::computePagesForPrinting(FrameIdentifier frameID, const PrintInfo& printInfo, CompletionHandler<void(const Vector<WebCore::IntRect>&, double, const WebCore::FloatBoxExtent&)>&& callback)
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/UIProcess/WebPageProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>
bool canRunModal();

void beginPrinting(WebFrameProxy*, const PrintInfo&);
void endPrinting();
void endPrinting(CompletionHandler<void()>&& = [] { });
IPC::Connection::AsyncReplyID computePagesForPrinting(WebCore::FrameIdentifier, const PrintInfo&, CompletionHandler<void(const Vector<WebCore::IntRect>&, double, const WebCore::FloatBoxExtent&)>&&);
void getPDFFirstPageSize(WebCore::FrameIdentifier, CompletionHandler<void(WebCore::FloatSize)>&&);
#if PLATFORM(COCOA)
Expand Down
4 changes: 3 additions & 1 deletion Source/WebKit/WebProcess/WebPage/WebPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5717,13 +5717,15 @@ void WebPage::beginPrinting(FrameIdentifier frameID, const PrintInfo& printInfo)
#endif
}

void WebPage::endPrinting()
void WebPage::endPrinting(CompletionHandler<void()>&& completionHandler)
{
if (m_inActivePrintContextAccessScope) {
m_shouldEndPrintingImmediately = true;
completionHandler();
return;
}
endPrintingImmediately();
completionHandler();
}

void WebPage::endPrintingImmediately()
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/WebProcess/WebPage/WebPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,8 @@ class WebPage : public API::ObjectImpl<API::Object::Type::BundlePage>, public IP

void beginPrinting(WebCore::FrameIdentifier, const PrintInfo&);
void beginPrintingDuringDOMPrintOperation(WebCore::FrameIdentifier frameID, const PrintInfo& printInfo) { beginPrinting(frameID, printInfo); }
void endPrinting();
void endPrintingDuringDOMPrintOperation() { endPrinting(); }
void endPrinting(CompletionHandler<void()>&& = [] { });
void endPrintingDuringDOMPrintOperation(CompletionHandler<void()>&& completionHandler) { endPrinting(WTFMove(completionHandler)); }
void computePagesForPrinting(WebCore::FrameIdentifier, const PrintInfo&, CompletionHandler<void(const Vector<WebCore::IntRect>&, double, const WebCore::FloatBoxExtent&)>&&);
void computePagesForPrintingDuringDOMPrintOperation(WebCore::FrameIdentifier frameID, const PrintInfo& printInfo, CompletionHandler<void(const Vector<WebCore::IntRect>&, double, const WebCore::FloatBoxExtent&)>&& completionHandler) { computePagesForPrinting(frameID, printInfo, WTFMove(completionHandler)); }
void computePagesForPrintingImpl(WebCore::FrameIdentifier, const PrintInfo&, Vector<WebCore::IntRect>& pageRects, double& totalScaleFactor, WebCore::FloatBoxExtent& computedMargin);
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/WebProcess/WebPage/WebPage.messages.in
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ GenerateSyntheticEditingCommand(enum:uint8_t WebKit::SyntheticEditingCommandType
# Printing.
BeginPrinting(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo)
BeginPrintingDuringDOMPrintOperation(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo) AllowedWhenWaitingForSyncReplyDuringUnboundedIPC
EndPrinting()
EndPrintingDuringDOMPrintOperation() AllowedWhenWaitingForSyncReplyDuringUnboundedIPC
EndPrinting() -> ()
EndPrintingDuringDOMPrintOperation() -> () AllowedWhenWaitingForSyncReplyDuringUnboundedIPC
ComputePagesForPrinting(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo) -> (Vector<WebCore::IntRect> pageRects, double totalScaleFactorForPrinting, WebCore::RectEdges<float> computedPageMargin)
ComputePagesForPrintingDuringDOMPrintOperation(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo) -> (Vector<WebCore::IntRect> pageRects, double totalScaleFactorForPrinting, WebCore::RectEdges<float> computedPageMargin) AllowedWhenWaitingForSyncReplyDuringUnboundedIPC
#if PLATFORM(COCOA)
Expand Down
1 change: 0 additions & 1 deletion Tools/WebKitTestRunner/TestController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ static void requestPointerLock(WKPageRef page, const void*)
static void printFrame(WKPageRef page, WKFrameRef frame, const void*)
{
WKPageBeginPrinting(page, frame, WKPrintInfo { 1, 21, 29.7f });
WKPageEndPrinting(page);
}

static bool shouldAllowDeviceOrientationAndMotionAccess(WKPageRef, WKSecurityOriginRef origin, WKFrameInfoRef frame, const void*)
Expand Down

0 comments on commit 8536c77

Please sign in to comment.