Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Henri Torgemane <henrit@gmail.com>
Date: Thu, 23 Sep 2021 21:30:33 -0500
Subject: add ui::ScopedCliboardWriter::WriteUnsafeRawData
This restores some ability to write to the clipboard using raw formats, which
was removed as part of the Raw Clipboard API scrubbing.
https://bugs.chromium.org/p/chromium/issues/detail?id=1217643
diff --git a/ui/base/clipboard/scoped_clipboard_writer.cc b/ui/base/clipboard/scoped_clipboard_writer.cc
index 069a4481ca6318215dd8a86b71aa7cacfb635173..605c5b8f8a7e50a22c94c6818cbdd95ced14fc15 100644
--- a/ui/base/clipboard/scoped_clipboard_writer.cc
+++ b/ui/base/clipboard/scoped_clipboard_writer.cc
@@ -232,6 +232,16 @@ void ScopedClipboardWriter::WriteEncodedDataTransferEndpointForTesting(
}
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
+void ScopedClipboardWriter::WriteUnsafeRawData(const std::u16string& format,
+ mojo_base::BigBuffer data) {
+ static constexpr int kMaxRegisteredFormats = 100;
+ if (counter_ >= kMaxRegisteredFormats)
+ return;
+ counter_++;
+ platform_representations_.push_back(
+ {base::UTF16ToUTF8(format), std::move(data)});
+}
+
void ScopedClipboardWriter::Reset() {
objects_.clear();
platform_representations_.clear();
diff --git a/ui/base/clipboard/scoped_clipboard_writer.h b/ui/base/clipboard/scoped_clipboard_writer.h
index 2a9964f12a3a17103cd473de74a039d01e117041..873cd66831b7cb4d762d3b7abf5fd08623d3d73b 100644
--- a/ui/base/clipboard/scoped_clipboard_writer.h
+++ b/ui/base/clipboard/scoped_clipboard_writer.h
@@ -87,6 +87,10 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) ScopedClipboardWriter {
// This is only used to write custom format data.
void WriteData(const std::u16string& format, mojo_base::BigBuffer data);
+ // write raw (non-pickled) data to the clipboard
+ void WriteUnsafeRawData(const std::u16string& format,
+ mojo_base::BigBuffer data);
void WriteImage(const SkBitmap& bitmap);
#if BUILDFLAG(IS_CHROMEOS_LACROS)