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: clipboard.writeBuffer raw format access #31116

Merged
merged 7 commits into from
Nov 4, 2021

Conversation

henrit
Copy link
Contributor

@henrit henrit commented Sep 24, 2021

Description of Change

This PR addresses #31115.

It includes a chromium patch to re-expose a mechanism to set raw data on the clipboard that was recently removed.

cc: @deepak1556 @ckerr

Checklist

Release Notes

Notes: Fixed clipboard.writeBuffer(), clipboard.readBuffer() and clipboard.read()'s ability to manipulate platform-specific clipboard formats.

@henrit henrit requested a review from a team as a code owner September 24, 2021 19:41
@welcome
Copy link

welcome bot commented Sep 24, 2021

💖 Thanks for opening this pull request! 💖

We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix.

Examples of commit messages with semantic prefixes:

  • fix: don't overwrite prevent_default if default wasn't prevented
  • feat: add app.isPackaged() method
  • docs: app.isDefaultProtocolClient is now available on Linux

Things that will help get your PR across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Sep 24, 2021
Copy link
Member

@codebytere codebytere left a comment

Choose a reason for hiding this comment

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

Hey @henrit - thanks for this!

Given that the underlying functionality you're adding via patch is something Chromium removed with no intention of re-adding, the approach contained in the patch is something that we'd need to float forever. Generally speaking, we try to keep our patch count to a minimum as each adds nontrivial maintenance burden, and prefer only to add indefinite lifetime patches as a last resort.

I'd prefer we first try to see if we can avoid doing so before trying to move this PR forward (e.g. by subclassing ScopedClipboardWriter to add the missing functionality to Electron's own source tree).


+void ScopedClipboardWriter::WriteUnsafeRawData(const std::u16string& format,
+ mojo_base::BigBuffer data) {
+ RecordWrite(ClipboardFormatMetric::kUnsafeRawData);
Copy link
Member

Choose a reason for hiding this comment

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

Chromium only uses this to record perf metrics - we can remove this and the added enum class value as we don't make use of them in Electron

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the quick feedback. That makes sense.
What would be a good folder to put the subclass?

Should it go next to the rest of the code in shell/common/api/, or maybe one-level up in shell/common/ since it doesn't itself define apis?

Copy link
Member

Choose a reason for hiding this comment

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

let's just go with shell/common/ for now!

Copy link
Contributor Author

@henrit henrit Oct 19, 2021

Choose a reason for hiding this comment

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

Unfortunately I'm not seeing a path to subclass the chromium clipboard code into something useful.
ui::ScopedClipboardWriter keeps its reference to a ui::Clipboard subclass private, and ui::Clipboard itself keeps
all its clipboard writing methods protected, which ScopedClipboardWriter can only access because it's
marked as a friend class.
If I understand this correctly, this code shape limits us to either copying large chunks of clipboard code
into electron, or patch it on the chromium side.

@ckerr

Copy link
Contributor

Choose a reason for hiding this comment

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

@henrit I looked into this and I agree with you on your assessment. Given that we would have to bring over a large amount of the the clipboard code, we should instead proceed with the patch instead. @henrit are you willing to continue working on this? If not, I'd be happy to take it over, but since it's your PR, I'd prefer to defer to you.

Looking at the PR, I think if it is rebased to resolve the conflict and perhaps cleanup the patch with @codebytere's suggestions, we can move this PR forward.

cc @ckerr @codebytere

Copy link
Member

@ckerr ckerr Nov 2, 2021

Choose a reason for hiding this comment

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

I'm a little tardy with this response, but FWIW I've looked into this wrt pickling and also agree with going the patch route first, since it looks like we'd need to copy a decent amount of code if we copied instead of patching.

Some of my review comments don't make sense in a patch context. Feel free to mark resolved at will.

I'm still happy to help via followup review and/or pairing if anyone wants it, whether it's @henrit or @jkleinsc.

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Oct 1, 2021
Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

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

To clarify my review from yesterday a bit -- @codebytere is right that it makes more sense to have this live as standalone code as possible instead of as a patch.

My review comments yesterday are for changes after the code is moved to a subclass, but I didn't make that explicit and looking at my comments again today I don't want to give the impression that I was asking for an updated file in .patches/

@jkleinsc jkleinsc added semver/patch backwards-compatible bug fixes target/15-x-y labels Nov 2, 2021
@jkleinsc jkleinsc merged commit 3c33d70 into electron:main Nov 4, 2021
@welcome
Copy link

welcome bot commented Nov 4, 2021

Congrats on merging your first pull request! 🎉🎉🎉

@release-clerk
Copy link

release-clerk bot commented Nov 4, 2021

Release Notes Persisted

Fixed clipboard.writeBuffer(), clipboard.readBuffer() and clipboard.read()'s ability to manipulate platform-specific clipboard formats.

trop bot pushed a commit that referenced this pull request Nov 4, 2021
* fix: clipboard.writeBuffer raw format access

* test: clipboard.writeBuffer raw format access

* test: clipboard win32 test skip

* fixup spec

* cleanup patch

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
trop bot pushed a commit that referenced this pull request Nov 4, 2021
* fix: clipboard.writeBuffer raw format access

* test: clipboard.writeBuffer raw format access

* test: clipboard win32 test skip

* fixup spec

* cleanup patch

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
@trop
Copy link
Contributor

trop bot commented Nov 4, 2021

I have automatically backported this PR to "16-x-y", please check out #31719

@trop
Copy link
Contributor

trop bot commented Nov 4, 2021

I have automatically backported this PR to "15-x-y", please check out #31720

jkleinsc added a commit that referenced this pull request Nov 4, 2021
* fix: clipboard.writeBuffer raw format access

* test: clipboard.writeBuffer raw format access

* test: clipboard win32 test skip

* fixup spec

* cleanup patch

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>

Co-authored-by: henrit <henrit@gmail.com>
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
jkleinsc added a commit that referenced this pull request Nov 8, 2021
* fix: clipboard.writeBuffer raw format access (#31116)

* fix: clipboard.writeBuffer raw format access

* test: clipboard.writeBuffer raw format access

* test: clipboard win32 test skip

* fixup spec

* cleanup patch

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>

* fixup .patches file

Co-authored-by: henrit <henrit@gmail.com>
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
t57ser pushed a commit to t57ser/electron that referenced this pull request Jan 25, 2022
* fix: clipboard.writeBuffer raw format access

* test: clipboard.writeBuffer raw format access

* test: clipboard win32 test skip

* fixup spec

* cleanup patch

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants