Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pdfjs switch #1069

Merged
merged 2 commits into from Feb 8, 2024
Merged

Add pdfjs switch #1069

merged 2 commits into from Feb 8, 2024

Conversation

msdemlei
Copy link
Contributor

@msdemlei msdemlei commented Jan 7, 2024

This is an attempt to address bug #1052; I'm (well: my machine is) tired of rebuilding luakit to patch out pdf.js.

What this does now is follow Michael's recipe on https://bugs.webkit.org/show_bug.cgi?id=260019#c4 (comment 4) to unconditionally turn off pdfjs using some ugly custom code in widgets/webview.c; that works on a PoC level.

However, assuming that not everyone is as abhorred by pdf.js as I am, this would now need to be made configurable. I think we will still need C code for this, as webkit_settings_get_all_features does not seem to be exposed to lua (and I don't think it should). But I have not found a way to trick that C code into settings.lua; actually, I have not even worked out how settings.lua talks to webkit in "normal" cases.

Does anyone here still understand settings.lua? Well enough to figure out whether we can have a setting that simply calls a C function on toggling, even?

@c0dev0id
Copy link
Member

c0dev0id commented Jan 23, 2024

You don't need to touch settings.lua. You can register a toggle like I have done it when adding dark-mode support here: ea082a5

Except your are registering your toggle in webview.lua and read it from webview.c.
There are already settings being registered in webview.lua. You can add a toggle there.

@msdemlei
Copy link
Contributor Author

msdemlei commented Jan 28, 2024 via email

@msdemlei msdemlei changed the title [DRAFT] Add pdfjs switch Add pdfjs switch Feb 4, 2024
@msdemlei
Copy link
Contributor Author

msdemlei commented Feb 4, 2024

So, I'm now creating an application.enable_pdfjs setting in webview.lua, which is the first application setting in there. To keep that out of libwebkitgtk's view, I'm now doing prefix checking in the init signal handler.

I hope this is ready for review now. One thing someone knowledgeable should definitely look at: do I need to free any of what comes back from the webkit calls in luaH_webview_set_pdfjs except for the result of webkit_settings_get_all_features (where the docs say I own it)? And is it ok to use g_autoptr in luakit? Glib docs say it's only available in gcc and clang – is this something we want to avoid?

@c0dev0id c0dev0id self-requested a review February 4, 2024 21:01
lib/webview.lua Outdated
Comment on lines 578 to 582
default = false,
desc = [=[
Whether to load PDFs in a built-in javascript renderer.
The default is to pass them on to the OS. This setting
only becomes active in new tabs.]=]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit torn weather we should enable or disable it per default.

Without your PR, webkit renders PDFs itself. So your PR changes this behavior.

But before webkit started display PDFs, a download dialog was shown and we had the viewpdf module to handle it.

I tend to enabling pdfjs per default and adding a sentence to the viewpdf documentation that it requires this setting to be toggled off to work.

Comment on lines +734 to +736
-- hand through webview.-prefixed settings
if v ~= nil and k:find('webview.', 1, true) then
k = k:sub(9) -- Strip off prefix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So... it looks like this is the first setting that's retrieved from the webview, but it's actually an application setting. My first thought was that this should go into window.lua/window.c. But then we need to include webview there, which is wrong. Therefore I think this is ok.

@c0dev0id
Copy link
Member

c0dev0id commented Feb 6, 2024

do I need to free any of what comes back from the webkit calls in luaH_webview_set_pdfjs except for the result of webkit_settings_get_all_features

I'm not sure. The memory leak unit test does not complain, so I assume it's okay as it is.

g_autoptr

We can try it. And we change it in case it creates trouble.

Actually, it is default false, which arguably may not match the majority's
taste.  I can be swayed.

In implementation, this adds an application.enable_pdfjs setting that is
evaluated lib/webview.lua on opening a view.  Because the pdfjs setting
is not yet exposed in libwebkitgtk, we have a C-language backend (that,
itself, depends on webkit_settings_get_all_features, which was only added
around 2.42.
Hence, amending the viewpdf documentation that you must turn it off
for viewpdf to work.
@msdemlei
Copy link
Contributor Author

msdemlei commented Feb 8, 2024 via email

@c0dev0id c0dev0id merged commit 6d3a9fd into luakit:develop Feb 8, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants