[tor-commits] [tor-browser] 38/46: Bug 1774285 - On Windows 11 22H2, flush the Windows clipboard immediately after setting it. r=neildeakin, a=dmeehan

gitolite role git at cupani.torproject.org
Wed Nov 16 20:43:18 UTC 2022


This is an automated email from the git hooks/post-receive script.

richard pushed a commit to branch base-browser-102.5.0esr-12.0-1
in repository tor-browser.

commit 06993355bc13ee1f13fa60337f54eff718596e66
Author: James Teh <jteh at mozilla.com>
AuthorDate: Fri Oct 28 14:17:54 2022 +0000

    Bug 1774285 - On Windows 11 22H2, flush the Windows clipboard immediately after setting it. r=neildeakin, a=dmeehan
    
    
    This works around a windows 11 suggested actions bug, see comment.
    
    Differential Revision: https://phabricator.services.mozilla.com/D160646
---
 mfbt/WindowsVersion.h                    |  6 ++++++
 modules/libpref/init/StaticPrefList.yaml | 10 ++++++++++
 widget/windows/nsClipboard.cpp           | 20 ++++++++++++++++++++
 3 files changed, 36 insertions(+)

diff --git a/mfbt/WindowsVersion.h b/mfbt/WindowsVersion.h
index 9fd24d0a44f0..9ee3c421ce72 100644
--- a/mfbt/WindowsVersion.h
+++ b/mfbt/WindowsVersion.h
@@ -204,6 +204,12 @@ inline bool IsWin7AndPre2000Compatible() {
   return info.dwMajorVersion < 5;
 }
 
+// Whether we're a Windows 11 build with "Suggested actions" feature which
+// causes hangs. See bug 1774285.
+MOZ_ALWAYS_INLINE bool NeedsWindows11SuggestedActionsWorkaround() {
+  return IsWindows10BuildOrLater(22621);
+}
+
 }  // namespace mozilla
 
 #endif /* mozilla_WindowsVersion_h */
diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml
index b83f961cbfbb..b7c239fd080b 100644
--- a/modules/libpref/init/StaticPrefList.yaml
+++ b/modules/libpref/init/StaticPrefList.yaml
@@ -13676,6 +13676,16 @@
   mirror: always
 #endif
 
+# Whether to flush the Ole clipboard synchronously.
+# Possible values are:
+#  * 0: never
+#  * 1: always
+#  * 2 (or others): when needed
+- name: widget.windows.sync-clipboard-flush
+  type: uint32_t
+  value: 2
+  mirror: always
+
 # Whether to disable SwipeTracker (e.g. swipe-to-nav).
 - name: widget.disable-swipe-tracker
   type: bool
diff --git a/widget/windows/nsClipboard.cpp b/widget/windows/nsClipboard.cpp
index 2881c5f9c176..2007bd9bdb83 100644
--- a/widget/windows/nsClipboard.cpp
+++ b/widget/windows/nsClipboard.cpp
@@ -450,6 +450,23 @@ static void RepeatedlyTryOleSetClipboard(IDataObject* aDataObj) {
   RepeatedlyTry(::OleSetClipboard, LogOleSetClipboardResult, aDataObj);
 }
 
+static bool ShouldFlushClipboardAfterWriting() {
+  switch (StaticPrefs::widget_windows_sync_clipboard_flush()) {
+    case 0:
+      return false;
+    case 1:
+      return true;
+    default:
+      // Bug 1774285: Windows Suggested Actions (introduced in Windows 11 22H2)
+      // walks the entire a11y tree using UIA if something is placed on the
+      // clipboard using delayed rendering. (The OLE clipboard always uses
+      // delayed rendering.) This a11y tree walk causes an unacceptable hang,
+      // particularly when the a11y cache is disabled. We choose the lesser of
+      // the two performance/memory evils here and force immediate rendering.
+      return NeedsWindows11SuggestedActionsWorkaround();
+  }
+}
+
 //-------------------------------------------------------------------------
 NS_IMETHODIMP nsClipboard::SetNativeClipboardData(int32_t aWhichClipboard) {
   MOZ_LOG(gWin32ClipboardLog, LogLevel::Debug, ("%s", __FUNCTION__));
@@ -470,6 +487,9 @@ NS_IMETHODIMP nsClipboard::SetNativeClipboardData(int32_t aWhichClipboard) {
                                           nullptr))) {  // this add refs dataObj
     RepeatedlyTryOleSetClipboard(dataObj);
     dataObj->Release();
+    if (ShouldFlushClipboardAfterWriting()) {
+      RepeatedlyTry(::OleFlushClipboard, [](HRESULT) {});
+    }
   } else {
     // Clear the native clipboard
     RepeatedlyTryOleSetClipboard(nullptr);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tor-commits mailing list