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

Fix #2208 #2242

Closed
wants to merge 1 commit into from
Closed

Fix #2208 #2242

wants to merge 1 commit into from

Conversation

Sestowner
Copy link
Member

No description provided.

@PalmerAL
Copy link
Collaborator

Can you explain how this works? I don't see why hasUserGesture would indicate whether the PDF is being saved from the context menu.

This section of code is meant to redirect download events so that if you click on a PDF link in a page, it opens the PDF viewer instead. In the main branch, this fails, because the download event is coming from the UI web contents, and so we send the PDF viewer request to the wrong place. In the multi-window branch (#2237), the download event now comes from the page's web contents, and so we actually open the viewer.

I think that a webpage could trigger a PDF download without a user gesture, in which case we do want to intercept that and show the viewer still. We probably need some other way of notifying the main process that this download is coming from the context menu.

@Sestowner
Copy link
Member Author

Sestowner commented Jun 1, 2023

Can you explain how this works?

hasUserGesture will return false when we call the downloadURL from the context menu, but true when the download button in the pdf viewer is clicked.

This section of code is meant to redirect download events...

So we can remove this section of code now?

@PalmerAL
Copy link
Collaborator

PalmerAL commented Jun 5, 2023

This code is identifying requests that should open in the PDF viewer, which is anything that is a PDF and doesn't have the special "pdfjs.action" string at the end of the URL.

hasUserGesture indicates whether the download was begun by the user. So for the context menu it will be false, since that's started by a call to an Electron API, and for the download button, it will be true, because Chromium knows that download event began as a result of a user click. But a webpage can also programmatically start a download:

var a = document.createElement('a')
a.href = ...
a.click()

In the normal case, this is handled by the other listener we have: https://github.com/minbrowser/min/blob/master/main/download.js#L73. But if the link is to something with content-disposition: attachment set, hasUserGesture will be false (I think).

How about we change the context menu to append the #pdfjs.action=download to the URL? It's not a very nice solution, but I think it will work in all cases.

@Sestowner Sestowner closed this Nov 12, 2023
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.

2 participants