Skip to content

Commit 2d11a78

Browse files
committed
[Site Isolation] Printing a specific frame should work with Site Isolation Enabled.
https://bugs.webkit.org/show_bug.cgi?id=299412 <rdar://129267859> Reviewed by Sihui Liu. Adds a new 'sink' option for RemoteSnapshot to generate a bitmap (for print preview) instead of a PDF. Adds new alternative WebPage messages for all the print(-preview) related functionality that generates a RemoteSnapshot (using the existing architecture for generating snapshots across processes) * Source/WebKit/GPUProcess/GPUProcess.cpp: (WebKit::GPUProcess::sinkCompletedSnapshotToPDF): (WebKit::GPUProcess::sinkCompletedSnapshotToBitmap): * Source/WebKit/GPUProcess/GPUProcess.h: * Source/WebKit/GPUProcess/GPUProcess.messages.in: * Source/WebKit/GPUProcess/graphics/RemoteSnapshot.cpp: (WebKit::RemoteSnapshot::drawToPDF): (WebKit::RemoteSnapshot::drawToBitmap): * Source/WebKit/GPUProcess/graphics/RemoteSnapshot.h: * Source/WebKit/Shared/WebImage.cpp: (WebKit::WebImage::create): * Source/WebKit/Shared/WebImage.h: * Source/WebKit/UIProcess/Cocoa/GPUProcessProxyCocoa.mm: (WebKit::GPUProcessProxy::sinkCompletedSnapshotToPDF): * Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp: (WebKit::GPUProcessProxy::sinkCompletedSnapshotToBitmap): * Source/WebKit/UIProcess/GPU/GPUProcessProxy.h: * Source/WebKit/UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::drawRectToImage): (WebKit::WebPageProxy::drawPagesToPDF): * Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm: (WebKit::WebPageProxy::drawToPDFiOS): (WebKit::WebPageProxy::drawToImage): * Source/WebKit/WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::drawPrintingRectToSnapshot): (WebKit::WebPage::drawPrintingPagesToSnapshot): * Source/WebKit/WebProcess/WebPage/WebPage.h: * Source/WebKit/WebProcess/WebPage/WebPage.messages.in: * Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm: (WebKit::WebPage::drawPrintingToSnapshotiOS): (WebKit::WebPage::drawPrintingPagesToSnapshotiOS): Canonical link: https://commits.webkit.org/300550@main
1 parent f066186 commit 2d11a78

File tree

16 files changed

+402
-15
lines changed

16 files changed

+402
-15
lines changed

Source/WebKit/GPUProcess/GPUProcess.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ Ref<RemoteSnapshot> GPUProcess::getOrCreateSnapshot(RemoteSnapshotIdentifier sna
364364

365365
#if PLATFORM(COCOA)
366366

367-
void GPUProcess::sinkCompletedSnapshotToPDF(RemoteSnapshotIdentifier identifier, IntSize size, FrameIdentifier rootFrameIdentifier, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&& completionHandler)
367+
void GPUProcess::sinkCompletedSnapshotToPDF(RemoteSnapshotIdentifier identifier, FloatSize size, FrameIdentifier rootFrameIdentifier, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&& completionHandler)
368368
{
369369
RefPtr<RemoteSnapshot> snapshot;
370370
{
@@ -391,6 +391,26 @@ void GPUProcess::sinkCompletedSnapshotToPDF(RemoteSnapshotIdentifier identifier,
391391

392392
#endif
393393

394+
void GPUProcess::sinkCompletedSnapshotToBitmap(RemoteSnapshotIdentifier identifier, const FloatSize& size, FrameIdentifier rootFrameIdentifier, CompletionHandler<void(std::optional<WebCore::ShareableBitmap::Handle>&&)>&& completionHandler)
395+
{
396+
RefPtr<RemoteSnapshot> snapshot;
397+
{
398+
Locker locker(m_globalResourceLocker);
399+
snapshot = m_snapshots.take(identifier);
400+
}
401+
if (!snapshot) {
402+
// Currently it's not possible to know if a snapshot exists, hence no ASSERT.
403+
completionHandler({ });
404+
return;
405+
}
406+
if (!snapshot->isComplete()) {
407+
// Currently the callbacks ensure the completeness.
408+
ASSERT_NOT_REACHED();
409+
return;
410+
}
411+
completionHandler(snapshot->drawToBitmap(size, rootFrameIdentifier));
412+
}
413+
394414
void GPUProcess::releaseSnapshot(RemoteSnapshotIdentifier identifier)
395415
{
396416
// Currently it's not possible to know if a snapshot exists, hence no ASSERT.

Source/WebKit/GPUProcess/GPUProcess.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,9 @@ class GPUProcess final : public AuxiliaryProcess, public ThreadSafeRefCounted<GP
235235
void updateProcessName();
236236
#endif
237237
#if PLATFORM(COCOA)
238-
void sinkCompletedSnapshotToPDF(RemoteSnapshotIdentifier, WebCore::IntSize, WebCore::FrameIdentifier, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&&);
238+
void sinkCompletedSnapshotToPDF(RemoteSnapshotIdentifier, WebCore::FloatSize, WebCore::FrameIdentifier, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&&);
239239
#endif
240+
void sinkCompletedSnapshotToBitmap(WebKit::RemoteSnapshotIdentifier, const WebCore::FloatSize&, WebCore::FrameIdentifier, CompletionHandler<void(std::optional<WebCore::ShareableBitmap::Handle>&&)>&&);
240241
void releaseSnapshot(RemoteSnapshotIdentifier);
241242

242243
#if USE(OS_STATE)

Source/WebKit/GPUProcess/GPUProcess.messages.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ messages -> GPUProcess : AuxiliaryProcess {
6464
#endif
6565

6666
#if PLATFORM(COCOA)
67-
SinkCompletedSnapshotToPDF(WebKit::RemoteSnapshotIdentifier identifier, WebCore::IntSize size, WebCore::FrameIdentifier rootFrameIdentifier) -> (RefPtr<WebCore::SharedBuffer> result)
67+
SinkCompletedSnapshotToPDF(WebKit::RemoteSnapshotIdentifier identifier, WebCore::FloatSize size, WebCore::FrameIdentifier rootFrameIdentifier) -> (RefPtr<WebCore::SharedBuffer> result)
6868
#endif
69+
SinkCompletedSnapshotToBitmap(WebKit::RemoteSnapshotIdentifier identifier, WebCore::FloatSize size, WebCore::FrameIdentifier rootFrameIdentifier) -> (std::optional<WebCore::ShareableBitmapHandle> image)
6970
ReleaseSnapshot(WebKit::RemoteSnapshotIdentifier identifier)
7071

7172
#if HAVE(SCREEN_CAPTURE_KIT)

Source/WebKit/GPUProcess/graphics/RemoteSnapshot.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#if ENABLE(GPU_PROCESS)
2929
#include "RemoteSnapshot.h"
3030

31+
#include "WebImage.h"
3132
#include <wtf/TZoneMallocInlines.h>
3233

3334
namespace WebKit {
@@ -106,7 +107,7 @@ RemoteSnapshot::DisplayListAndReleaseDispatcher::~DisplayListAndReleaseDispatche
106107

107108
#if PLATFORM(COCOA)
108109

109-
std::optional<RefPtr<SharedBuffer>> RemoteSnapshot::drawToPDF(const IntSize& size, FrameIdentifier rootIdentifier)
110+
std::optional<RefPtr<SharedBuffer>> RemoteSnapshot::drawToPDF(const FloatSize& size, FrameIdentifier rootIdentifier)
110111
{
111112
ASSERT(isComplete());
112113
RefPtr buffer = ImageBuffer::create(size, RenderingMode::PDFDocument, RenderingPurpose::Snapshot, 1, DestinationColorSpace::SRGB(), PixelFormat::BGRA8);
@@ -123,6 +124,21 @@ std::optional<RefPtr<SharedBuffer>> RemoteSnapshot::drawToPDF(const IntSize& siz
123124

124125
#endif
125126

127+
std::optional<ShareableBitmap::Handle> RemoteSnapshot::drawToBitmap(const FloatSize& size, FrameIdentifier rootFrameIdentifier)
128+
{
129+
ASSERT(isComplete());
130+
RefPtr image = WebImage::create(size, ImageOption::Shareable, DestinationColorSpace::SRGB());
131+
if (!image)
132+
return std::nullopt;
133+
134+
auto& context = *image->context();
135+
136+
if (!applyFrame(rootFrameIdentifier, context))
137+
return std::nullopt;
138+
139+
return image->createHandle(SharedMemory::Protection::ReadOnly);
140+
}
141+
126142
}
127143

128144
#endif

Source/WebKit/GPUProcess/graphics/RemoteSnapshot.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class RemoteSnapshot final : public ThreadSafeRefCounted<RemoteSnapshot> {
5353
[[nodiscard]] bool addFrameReference(WebCore::FrameIdentifier);
5454
[[nodiscard]] bool setFrame(WebCore::FrameIdentifier, Ref<const WebCore::DisplayList::DisplayList>&&, SerialFunctionDispatcher&);
5555
bool isComplete() const;
56-
std::optional<RefPtr<WebCore::SharedBuffer>> drawToPDF(const WebCore::IntSize&, WebCore::FrameIdentifier rootFrameIdentifier);
56+
std::optional<RefPtr<WebCore::SharedBuffer>> drawToPDF(const WebCore::FloatSize&, WebCore::FrameIdentifier rootFrameIdentifier);
57+
std::optional<WebCore::ShareableBitmap::Handle> drawToBitmap(const WebCore::FloatSize&, WebCore::FrameIdentifier rootFrameIdentifier);
5758
[[nodiscard]] bool applyFrame(WebCore::FrameIdentifier, WebCore::GraphicsContext&) const;
5859

5960
private:

Source/WebKit/Shared/WebImage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Ref<WebImage> WebImage::createEmpty()
3939
return adoptRef(*new WebImage(nullptr));
4040
}
4141

42-
Ref<WebImage> WebImage::create(const IntSize& size, ImageOptions options, const DestinationColorSpace& colorSpace, ChromeClient* client)
42+
Ref<WebImage> WebImage::create(const FloatSize& size, ImageOptions options, const DestinationColorSpace& colorSpace, ChromeClient* client)
4343
{
4444
auto pixelFormat = PixelFormat::BGRA8;
4545
#if ENABLE(PIXEL_FORMAT_RGBA16F)

Source/WebKit/Shared/WebImage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class WebImage final : public API::ObjectImpl<API::Object::Type::Image> {
4848
public:
4949
using ParametersAndHandle = std::pair<WebCore::ImageBufferParameters, WebCore::ShareableBitmap::Handle>;
5050

51-
static Ref<WebImage> create(const WebCore::IntSize&, ImageOptions, const WebCore::DestinationColorSpace&, WebCore::ChromeClient* = nullptr);
51+
static Ref<WebImage> create(const WebCore::FloatSize&, ImageOptions, const WebCore::DestinationColorSpace&, WebCore::ChromeClient* = nullptr);
5252
static Ref<WebImage> create(std::optional<ParametersAndHandle>&&);
5353
static Ref<WebImage> create(Ref<WebCore::ImageBuffer>&&);
5454
static Ref<WebImage> createEmpty();

Source/WebKit/UIProcess/Cocoa/GPUProcessProxyCocoa.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
sendWithAsyncReply(Messages::GPUProcess::PostWillTakeSnapshotNotification { }, WTFMove(completionHandler));
129129
}
130130

131-
void GPUProcessProxy::sinkCompletedSnapshotToPDF(RemoteSnapshotIdentifier identifier, const WebCore::IntSize& size, WebCore::FrameIdentifier rootFrameIdentifier, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&& completionHandler)
131+
void GPUProcessProxy::sinkCompletedSnapshotToPDF(RemoteSnapshotIdentifier identifier, const WebCore::FloatSize& size, WebCore::FrameIdentifier rootFrameIdentifier, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&& completionHandler)
132132
{
133133
sendWithAsyncReply(Messages::GPUProcess::SinkCompletedSnapshotToPDF { identifier, size, rootFrameIdentifier }, WTFMove(completionHandler));
134134
}

Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,11 @@ void GPUProcessProxy::unregisterMemoryAttributionID(const String& attributionID,
923923
#endif
924924
#endif
925925

926+
void GPUProcessProxy::sinkCompletedSnapshotToBitmap(RemoteSnapshotIdentifier identifier, const WebCore::FloatSize& size, WebCore::FrameIdentifier rootFrameIdentifier, CompletionHandler<void(std::optional<WebCore::ShareableBitmap::Handle>&&)>&& completionHandler)
927+
{
928+
sendWithAsyncReply(Messages::GPUProcess::SinkCompletedSnapshotToBitmap(identifier, size, rootFrameIdentifier), WTFMove(completionHandler));
929+
}
930+
926931
void GPUProcessProxy::releaseSnapshot(RemoteSnapshotIdentifier identifier)
927932
{
928933
send(Messages::GPUProcess::ReleaseSnapshot(identifier), 0);

Source/WebKit/UIProcess/GPU/GPUProcessProxy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ class GPUProcessProxy final : public AuxiliaryProcessProxy {
175175
#if PLATFORM(COCOA)
176176
void postWillTakeSnapshotNotification(CompletionHandler<void()>&&);
177177

178-
void sinkCompletedSnapshotToPDF(RemoteSnapshotIdentifier, const WebCore::IntSize&, WebCore::FrameIdentifier root, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&&);
178+
void sinkCompletedSnapshotToPDF(RemoteSnapshotIdentifier, const WebCore::FloatSize&, WebCore::FrameIdentifier root, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&&);
179179
#endif
180+
void sinkCompletedSnapshotToBitmap(RemoteSnapshotIdentifier, const WebCore::FloatSize&, WebCore::FrameIdentifier root, CompletionHandler<void(std::optional<WebCore::ShareableBitmap::Handle>&&)>&&);
180181
void releaseSnapshot(RemoteSnapshotIdentifier);
181182

182183
private:

0 commit comments

Comments
 (0)