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

8254825: Monitoring available clipboard formats should be done via new Windows APIs #594

Closed
wants to merge 2 commits into from

Conversation

@xavery
Copy link
Contributor

@xavery xavery commented Oct 11, 2020

This change replaces the usage of SetClipboardViewer with Add/RemoveClipboardFormatListener, introduced in Windows Vista. This makes OpenJDK immune to external applications failing to process clipboard messages properly.
I have put this proposal forward in the mailing list, which was tentatively accepted by Mr. Sergey Bylokhov.

The deficiencies of the old APIs are well known and might result in some subscribed applications not receiving notifications from the operating system, as they rely on all the applications in the current clipboard chain processing clipboard messages properly. Porting the code to use the new APIs not only makes OpenJDK immune to these issues, but also results in slightly less code needed to support clipboard-related functionality.

As this is a change that's very platform-specific, I don't think providing a unit test is practical, as it would also require providing a native application that runs alongside the test and deliberately breaks the keyboard chain, resulting in OpenJDK not being able to receive clipboard format change notifications. This is a bug/limitation of the old Windows API, not OpenJDK itself. Anyhow, the already existing ClipboardInterVMTest passes, which shows that already existing functionality is not impacted by this change.

I have prepared a proof-of-concept test which illustrates the deficiencies of the old API, however it is not integrated with the test suite, as it requires compiling a native WinAPI application. I will gladly share the source if needed.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8254825: Monitoring available clipboard formats should be done via new Windows APIs

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/594/head:pull/594
$ git checkout pull/594

This change replaces the usage of SetClipboardViewer with
Add/RemoveClipboardFormatListener, introduced in Windows Vista. This makes
OpenJDK immune to external applications failing to process clipboard messages
properly.
@bridgekeeper bridgekeeper bot added the oca label Oct 11, 2020
@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Oct 11, 2020

Hi @xavery, welcome to this OpenJDK project and thanks for contributing!

We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing /signed in a comment in this pull request.

If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user xavery" as summary for the issue.

If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing /covered in a comment in this pull request.

@xavery
Copy link
Contributor Author

@xavery xavery commented Oct 11, 2020

/signed

@bridgekeeper bridgekeeper bot added the oca-verify label Oct 11, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Oct 11, 2020

@xavery The following labels will be automatically applied to this pull request:

  • 2d
  • awt

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Oct 11, 2020

Thank you! Please allow for up to two weeks to process your OCA, although it is usually done within one to two business days. Also, please note that pull requests that are pending an OCA check will not usually be evaluated, so your patience is appreciated!

@openjdk openjdk bot added 2d awt labels Oct 11, 2020
@xavery
Copy link
Contributor Author

@xavery xavery commented Oct 15, 2020

/issue JDK-8254825

@openjdk openjdk bot changed the title Use new APIs on Windows for monitoring available clipboard formats 8254825: Monitoring available clipboard formats should be done via new Windows APIs Oct 15, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Oct 15, 2020

@xavery The primary solved issue for a PR is set through the PR title. Since the current title does not contain an issue reference, it will now be updated.

@openjdk openjdk bot added the rfr label Oct 15, 2020
@mlbridge
Copy link

@mlbridge mlbridge bot commented Oct 15, 2020

Webrevs

@mrserb
Copy link
Member

@mrserb mrserb commented Oct 25, 2020

Description of possible ways to interact with a clipboard:
https://docs.microsoft.com/en-us/windows/win32/dataxchg/using-the-clipboard

There are three ways of monitoring changes to the clipboard. The oldest method is to create a clipboard viewer window. Windows 2000 added the ability to query the clipboard sequence number, and Windows Vista added support for clipboard format listeners. Clipboard viewer windows are supported for backward compatibility with earlier versions of Windows. New programs should use clipboard format listeners or the clipboard sequence number.

The current fix proposes to change the old "clipboard viewer window" approach:
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setclipboardviewer
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-changeclipboardchain
To the new approach:
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-addclipboardformatlistener

@mrserb
Copy link
Member

@mrserb mrserb commented Oct 25, 2020

I have run the tests and waiting for the results, will sponsor it if the results will be good.

Copy link
Member

@mrserb mrserb left a comment

Please update the second date in the header of the changed files to 2020.

@xavery
Copy link
Contributor Author

@xavery xavery commented Oct 25, 2020

Please update the second date in the header of the changed files to 2020.

Done.

@mrserb
mrserb approved these changes Oct 25, 2020
Copy link
Member

@mrserb mrserb left a comment

Looks fine

@openjdk
Copy link

@openjdk openjdk bot commented Oct 25, 2020

@xavery This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8254825: Monitoring available clipboard formats should be done via new Windows APIs

Reviewed-by: serb

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 260 new commits pushed to the master branch:

  • de05b00: 8255365: Problem list failing client manual tests
  • 49c4978: 8060202: [macosx] Test closed/java/awt/Choice/GetSizeTest/GetSizeTest fails only in MacOSX(10.10)
  • 2b47a58: 8028281: [TEST_BUG] [macosx] javax/swing/JTabbedPane/7024235/Test7024235.java fails
  • 83a91bf: 8253734: C2: Optimize Move nodes
  • 6666dcb: 8237363: Remove automatic is in heap verification in OopIterateClosure
  • fa64477: 8255301: Common and strengthen the code in ciMemberName and ciMethodHandle
  • 9b5a2a6: 8255349: Vector API issues on Big Endian
  • e8b75b1: 8255393: sun/security/util/DerValue/Indefinite.java fails with ---illegal-access=deny
  • 7cafe35: 8255352: Archive important test outputs in submit workflow
  • 888086f: 8255373: Submit workflow artifact name is always "test-results_.zip"
  • ... and 250 more: https://git.openjdk.java.net/jdk/compare/d43f14161e996523e6c2c725d9eb4f70a253267a...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@mrserb) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready label Oct 25, 2020
@xavery
Copy link
Contributor Author

@xavery xavery commented Oct 26, 2020

/integrate

@openjdk openjdk bot added the sponsor label Oct 26, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Oct 26, 2020

@xavery
Your change (at version be1b6cb) is now ready to be sponsored by a Committer.

@mrserb
Copy link
Member

@mrserb mrserb commented Oct 26, 2020

/sponsor

@openjdk openjdk bot closed this Oct 26, 2020
@openjdk openjdk bot added the integrated label Oct 26, 2020
@openjdk openjdk bot removed sponsor ready rfr labels Oct 26, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Oct 26, 2020

@mrserb @xavery Since your change was applied there have been 260 commits pushed to the master branch:

  • de05b00: 8255365: Problem list failing client manual tests
  • 49c4978: 8060202: [macosx] Test closed/java/awt/Choice/GetSizeTest/GetSizeTest fails only in MacOSX(10.10)
  • 2b47a58: 8028281: [TEST_BUG] [macosx] javax/swing/JTabbedPane/7024235/Test7024235.java fails
  • 83a91bf: 8253734: C2: Optimize Move nodes
  • 6666dcb: 8237363: Remove automatic is in heap verification in OopIterateClosure
  • fa64477: 8255301: Common and strengthen the code in ciMemberName and ciMethodHandle
  • 9b5a2a6: 8255349: Vector API issues on Big Endian
  • e8b75b1: 8255393: sun/security/util/DerValue/Indefinite.java fails with ---illegal-access=deny
  • 7cafe35: 8255352: Archive important test outputs in submit workflow
  • 888086f: 8255373: Submit workflow artifact name is always "test-results_.zip"
  • ... and 250 more: https://git.openjdk.java.net/jdk/compare/d43f14161e996523e6c2c725d9eb4f70a253267a...master

Your commit was automatically rebased without conflicts.

Pushed as commit b498433.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@xavery xavery deleted the xavery:new-clipboard-api branch Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants