[tbb-commits] [tor-browser] 41/46: Bug 1798117 - Only flush clipboard for text data. r=smaug, a=dmeehan
gitolite role
git at cupani.torproject.org
Wed Nov 16 20:43:21 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 154e8535ee87c593f4b856e1ffc681fa94344ca4
Author: Emilio Cobos Álvarez <emilio at crisal.io>
AuthorDate: Tue Nov 1 17:58:45 2022 +0000
Bug 1798117 - Only flush clipboard for text data. r=smaug, a=dmeehan
Otherwise Chromium gets confused when pasting (Signal is an Electron
application).
I need to dig a bit more, but this doesn't prevent the fix for
bug 1774285 from working, and fixes the issue here.
It's probably a Chromium bug that this doesn't work tho since,
as mentioned in comment 0, it works on other Windows applications.
Differential Revision: https://phabricator.services.mozilla.com/D160808
---
widget/windows/nsClipboard.cpp | 52 +++++++++++++++++++-----------------------
1 file changed, 23 insertions(+), 29 deletions(-)
diff --git a/widget/windows/nsClipboard.cpp b/widget/windows/nsClipboard.cpp
index 3cd1102a16da..e09d26fbbb96 100644
--- a/widget/windows/nsClipboard.cpp
+++ b/widget/windows/nsClipboard.cpp
@@ -180,17 +180,10 @@ nsresult nsClipboard::SetupNativeDataObject(
}
auto* dObj = static_cast<nsDataObj*>(aDataObj);
-
if (aMightNeedToFlush) {
*aMightNeedToFlush = MightNeedToFlush::No;
}
- auto MarkAsPotentiallyNeedingToFlush = [&] {
- if (aMightNeedToFlush) {
- *aMightNeedToFlush = MightNeedToFlush::Yes;
- }
- };
-
// Now give the Transferable to the DataObject
// for getting the data out of it
dObj->SetTransferable(aTransferable);
@@ -224,7 +217,9 @@ nsresult nsClipboard::SetupNativeDataObject(
FORMATETC textFE;
SET_FORMATETC(textFE, CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
dObj->AddDataFlavor(kTextMime, &textFE);
- MarkAsPotentiallyNeedingToFlush();
+ if (aMightNeedToFlush) {
+ *aMightNeedToFlush = MightNeedToFlush::Yes;
+ }
} else if (flavorStr.EqualsLiteral(kHTMLMime)) {
// if we find text/html, also advertise win32's html flavor (which we will
// convert on our own in nsDataObj::GetText().
@@ -232,7 +227,6 @@ nsresult nsClipboard::SetupNativeDataObject(
SET_FORMATETC(htmlFE, GetHtmlClipboardFormat(), 0, DVASPECT_CONTENT, -1,
TYMED_HGLOBAL);
dObj->AddDataFlavor(kHTMLMime, &htmlFE);
- MarkAsPotentiallyNeedingToFlush();
} else if (flavorStr.EqualsLiteral(kURLMime)) {
// if we're a url, in addition to also being text, we need to register
// the "file" flavors so that the win32 shell knows to create an internet
@@ -255,7 +249,6 @@ nsresult nsClipboard::SetupNativeDataObject(
SET_FORMATETC(shortcutFE, ::RegisterClipboardFormat(CFSTR_INETURLW), 0,
DVASPECT_CONTENT, -1, TYMED_HGLOBAL)
dObj->AddDataFlavor(kURLMime, &shortcutFE);
- MarkAsPotentiallyNeedingToFlush();
} else if (flavorStr.EqualsLiteral(kPNGImageMime) ||
flavorStr.EqualsLiteral(kJPEGImageMime) ||
flavorStr.EqualsLiteral(kJPGImageMime) ||
@@ -462,23 +455,6 @@ 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__));
@@ -504,8 +480,26 @@ NS_IMETHODIMP nsClipboard::SetNativeClipboardData(int32_t aWhichClipboard) {
getter_AddRefs(dataObj), nullptr,
&mightNeedToFlush))) {
RepeatedlyTryOleSetClipboard(dataObj);
- if (mightNeedToFlush == MightNeedToFlush::Yes &&
- ShouldFlushClipboardAfterWriting()) {
+
+ const bool doFlush = [&] {
+ 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 mightNeedToFlush == MightNeedToFlush::Yes &&
+ NeedsWindows11SuggestedActionsWorkaround();
+ }
+ }();
+ if (doFlush) {
RepeatedlyTry(::OleFlushClipboard, [](HRESULT) {});
}
} else {
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the tbb-commits
mailing list