Closed Bug 1788668 Opened 3 years ago Closed 3 years ago

Add the possibility to check that the clipboard contains some pdfjs stuff

Categories

(Core :: DOM: Copy & Paste and Drag & Drop, defect)

defect

Tracking

()

RESOLVED FIXED
106 Branch
Tracking Status
firefox106 --- fixed

People

(Reporter: calixte, Assigned: calixte)

Details

Attachments

(1 file, 1 obsolete file)

We landed a patch in pdf.js:
https://github.com/mozilla/pdf.js/pull/15373
in order to allow to copy/cut/paste some annotations from a pdf to another.
We use a mime type for pdfjs:
https://github.com/mozilla/pdf.js/pull/15373/files#diff-e5ec9751980dd8449e7b036e02292ca16e34c3b6db368b014f2ea17ffb2da27bR501

In order to be able to update the context menu if there's something to paste, we need to know if the clipboard contains a transferable for application/pdfjs (in using for example Services.clipboard.hasDataMatchingFlavors).
But this mimetype isn't in the list because of bug 860857: the user defined mime types are put behind application/x-moz-custom-clipdata (see https://searchfox.org/mozilla-central/rev/fa81b64fc1a339e2b2b1f6a8637a689916e13c4e/dom/events/DataTransfer.cpp#1076).

An idea could be to add a special mime application/x-moz-pdfjs and associate it to a nullptr in the transferable when application/pdfjs is present and then check for this mime type when we need to update the context menu.

:enndeakin, what do you think ?

Flags: needinfo?(enndeakin)

It would probably be easiest to just add application/pdfjs to the list of known formats so it doesn't end up in the custom formats list: https://searchfox.org/mozilla-central/rev/fa81b64fc1a339e2b2b1f6a8637a689916e13c4e/dom/events/DataTransfer.cpp#892

Flags: needinfo?(enndeakin)

This way we can check that the clipboard contains some pdfjs data and
consequently we can update correctly the context menu when we're in
editing mode.

Attachment #9292855 - Attachment is obsolete: true
Pushed by cdenizet@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/10b2c6ab7be7 Add 'application/pdfjs' to the list of known formats r=NeilDeakin

Do we want random websites to be able to use that format? Why didn't we use application/x-moz-pdfjs instead?

Component: PDF Viewer → DOM: Copy & Paste and Drag & Drop
Product: Firefox → Core
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 106 Branch

(In reply to Tom Schuster [:evilpie] from comment #5)

Do we want random websites to be able to use that format?

I don't know. What are the drawbacks ?

Why didn't we use application/x-moz-pdfjs instead?

If I use in this format in pdf.js then it will be wrapped into a application/x-moz-custom-clipdata in the clipboard but then I can't test if the clipboard contains some pdfjs data.
My initial idea was to check for application/pdfjs in the transferable and if present then just add something like transferable->SetTransferData("application/x-moz-pdfjs", nullptr);, this way the pdfjs data are still under application/x-moz-custom-clipdata and I can check for the presence of application/x-moz-pdfjs in the clipboard. FYI, I tested this idea and it was working as expected, the main advantage was to avoid to expose something but it slightly increased the complexity compared to the current patch.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: