[GTK] Implement printing using the Print portal#26765
Conversation
|
EWS run on previous version of this PR (hash 8348b27) Details
|
|
I'm making this a draft because there is one unresolved problem with the Print portal that I think needs to be solved first: the Print portal offers various output formats (PDF, PS, and SVG) and Skia cannot handle that. I gave this a stab at https://gitlab.gnome.org/GNOME/xdg-desktop-portal-gnome/-/merge_requests/148 but I'm not sure if this approach is even acceptable - it's likely just a workaround to the problem. Maybe we'll need a new parameter to the Print portal itself. But please share your thoughts about the code, I'll apply review comments as usual. |
|
The warning this patch introduces is making the test suite unhappy... |
8348b27 to
003af88
Compare
|
EWS run on previous version of this PR (hash 003af88) Details
|
mcatanzaro
left a comment
There was a problem hiding this comment.
Nice, this is way simpler than I was expecting it would be. Using a temporary file was smart.
I think you should deprecate webkit_print_operation_print(). There's no point in not doing so; applications shouldn't do things that don't work when sandboxed.
|
I don't really know why the style checker skipped so many |
The style checker is not smart enough to check for gboolean vs. bool. It should be able to check for nullptr, though, because using NULL is never allowed. I'm not sure why it doesn't catch that. Maybe it's just something nobody ever bothered to implement.... |
003af88 to
0517e8f
Compare
|
EWS run on previous version of this PR (hash 0517e8f) Details
|
0517e8f to
6a1de80
Compare
|
EWS run on previous version of this PR (hash 6a1de80) Details |
|
Wouldn't it be possible to make the portal print without a dialog? I don't understand why we have to deprecated the feature. |
I don't know for sure, but I don't think this would be possible. The challenge here is that, in a tight sandbox, apps cannot "just" send a print job to the Print portal, because they cannot choose a printer - they don't have access to the hardware in a tight sandbox. The only printer available will effectively be the file printer, but even in that case, the app won't have an output file path. That's selected by the user through the PreparePrint method. So, all in all, I don't see how an tightly sandboxed app would be able to skip the PreparePrint method. Any alternative would require opening sandbox holes - be it the CUPS permission, or add more filesystem permissions for printing into a file. |
|
What I meant is whether it would be possible to add api to the portal to allow printing without showing a dialog. |
The lack of a dialog is the problem. How would WebKit, or any sandboxed app, tell the portal which printer or output file it should print to? |
|
I don't see the point of ever allowing an app to print without first showing the print dialog. Why would an app ever want to do that? And Debian codesearch indicates the only user of this API is our own API test, so it won't be missed. |
6a1de80 to
be461e0
Compare
|
EWS run on previous version of this PR (hash be461e0) Details
|
|
I took the liberty to take a few executive decisions about this PR:
I think this is good to go now. |
be461e0 to
7c14592
Compare
|
EWS run on previous version of this PR (hash 7c14592) Details |
mcatanzaro
left a comment
There was a problem hiding this comment.
Please check with @carlosgcampos before landing, because he might want to review this first. But you pass my review.
There was a problem hiding this comment.
Maybe it woulld be easier if this is a struct instead of a class, and you can create instances using { } without adding explicit constructors
There was a problem hiding this comment.
Done, it this what you had in mind?
7c14592 to
10a3cdb
Compare
|
EWS run on current version of this PR (hash 10a3cdb) Details |
https://bugs.webkit.org/show_bug.cgi?id=192748 Reviewed by Michael Catanzaro. When running inside a sandboxed environment - which is fairly common nowadays - printing is severely limited due to using the legacy GTK print API (GtkPrintUnixDialog & family). Due to WebKit's multi-process architecture, using the modern alternative, GtkPrintOperation, is not really possible, because GtkPrintOperation has the enconded assumption that the rendering of the document pages happens in the same process as of printing. Implement manual support for the Print portal. The portal has two well defined steps: 1. PreparePrint() is where WebKit sends the settings and page setup that are stored in WebKitPrintOperation to the portal. The portal presents a dialog to let users choose their print preferences. This step returns WebKit a token, which is the "authentication" mechanism for the next step. 2. Print() takes a token, and a file descriptor pointing to the file that will be send to the printer. The file descriptor can and often does point to an in-memory buffer! In WebKit's case, it's a tmpfile. This effectively means that webkit_print_operation_print(), which assumes that step 1 can be skipped - cannot work under a sandbox. Deprecate this function, and adjust the tests to ignore this deprecation, as the tests should be adapted separately. * Source/WebKit/UIProcess/API/gtk/WebKitPrintOperation.cpp: (webkitPrintOperationFinished): (webkitPrintOperationFailed): (webkitPrintOperationPrintPagesForFrame): (findFilePrinter): (webkitPrintOperationSendPagesToPrintPortal): (webkitPrintOperationPreparePrint): (webkitPrintOperationRunPortalDialog): (webkitPrintOperationRunDialogForFrame): * Source/WebKit/UIProcess/API/gtk/WebKitPrintOperation.h.in: * Tools/TestWebKitAPI/Tests/WebKitGtk/TestPrinting.cpp: (testPrintOperationPrint): (testPrintOperationErrors): Canonical link: https://commits.webkit.org/277671@main
10a3cdb to
fd47d13
Compare
|
Committed 277671@main (fd47d13): https://commits.webkit.org/277671@main Reviewed commits have been landed. Closing PR #26765 and removing active labels. |
|
Backported as 2de9573 into the 2.44 release branch 👏🏼 |
fd47d13
10a3cdb