#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "ui/base/clipboard/clipboard_ozone.h"
#include <algorithm>
#include <limits>
#include <optional>
#include <string_view>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/containers/contains.h"
#include "base/containers/flat_map.h"
#include "base/containers/map_util.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "base/timer/timer.h"
#include "base/types/optional_util.h"
#include "base/types/variant_util.h"
#include "build/build_config.h"
#include "clipboard_util.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/clipboard/clipboard_buffer.h"
#include "ui/base/clipboard/clipboard_constants.h"
#include "ui/base/clipboard/clipboard_metrics.h"
#include "ui/base/clipboard/clipboard_monitor.h"
#include "ui/base/clipboard/clipboard_util.h"
#include "ui/base/clipboard/custom_data_helper.h"
#include "ui/base/data_transfer_policy/data_transfer_endpoint.h"
#include "ui/base/data_transfer_policy/data_transfer_endpoint_serializer.h"
#include "ui/base/data_transfer_policy/data_transfer_policy_controller.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/platform_clipboard.h"
namespace ui {
namespace {
constexpr base::TimeDelta kRequestTimeout = …;
bool IsReadAllowed(std::optional<DataTransferEndpoint> data_src,
const DataTransferEndpoint* data_dst,
const base::span<uint8_t> data) { … }
class StubPlatformClipboard : public PlatformClipboard { … };
}
class ClipboardOzone::AsyncClipboardOzone { … };
ClipboardOzone::ClipboardOzone() { … }
ClipboardOzone::~ClipboardOzone() = default;
void ClipboardOzone::OnPreShutdown() { … }
std::optional<DataTransferEndpoint> ClipboardOzone::GetSource(
ClipboardBuffer buffer) const { … }
const ClipboardSequenceNumberToken& ClipboardOzone::GetSequenceNumber(
ClipboardBuffer buffer) const { … }
bool ClipboardOzone::IsFormatAvailable(
const ClipboardFormatType& format,
ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst) const { … }
void ClipboardOzone::Clear(ClipboardBuffer buffer) { … }
std::vector<std::u16string> ClipboardOzone::GetStandardFormats(
ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst) const { … }
void ClipboardOzone::ReadAvailableTypes(
ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::vector<std::u16string>* types) const { … }
void ClipboardOzone::ReadText(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::u16string* result) const { … }
void ClipboardOzone::ReadAsciiText(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::string* result) const { … }
void ClipboardOzone::ReadHTML(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::u16string* markup,
std::string* src_url,
uint32_t* fragment_start,
uint32_t* fragment_end) const { … }
void ClipboardOzone::ReadSvg(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::u16string* result) const { … }
void ClipboardOzone::ReadRTF(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::string* result) const { … }
void ClipboardOzone::ReadPng(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
ReadPngCallback callback) const { … }
void ClipboardOzone::ReadDataTransferCustomData(
ClipboardBuffer buffer,
const std::u16string& type,
const DataTransferEndpoint* data_dst,
std::u16string* result) const { … }
void ClipboardOzone::ReadFilenames(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::vector<ui::FileInfo>* result) const { … }
void ClipboardOzone::ReadBookmark(const DataTransferEndpoint* data_dst,
std::u16string* title,
std::string* url) const { … }
void ClipboardOzone::ReadData(const ClipboardFormatType& format,
const DataTransferEndpoint* data_dst,
std::string* result) const { … }
bool ClipboardOzone::IsSelectionBufferAvailable() const { … }
void ClipboardOzone::WritePortableTextRepresentation(ClipboardBuffer buffer,
const ObjectMap& objects) { … }
void ClipboardOzone::WritePortableAndPlatformRepresentations(
ClipboardBuffer buffer,
const ObjectMap& objects,
std::vector<Clipboard::PlatformRepresentation> platform_representations,
std::unique_ptr<DataTransferEndpoint> data_src,
uint32_t privacy_types) { … }
void ClipboardOzone::WriteText(std::string_view text) { … }
void ClipboardOzone::WriteHTML(
std::string_view markup,
std::optional<std::string_view> ) { … }
void ClipboardOzone::WriteSvg(std::string_view markup) { … }
void ClipboardOzone::WriteRTF(std::string_view rtf) { … }
void ClipboardOzone::WriteFilenames(std::vector<ui::FileInfo> filenames) { … }
void ClipboardOzone::WriteBookmark(std::string_view title,
std::string_view url) { … }
void ClipboardOzone::WriteWebSmartPaste() { … }
void ClipboardOzone::WriteBitmap(const SkBitmap& bitmap) { … }
void ClipboardOzone::WriteData(const ClipboardFormatType& format,
base::span<const uint8_t> data) { … }
void ClipboardOzone::WriteClipboardHistory() { … }
void ClipboardOzone::WriteUploadCloudClipboard() { … }
void ClipboardOzone::WriteConfidentialDataForPassword() { … }
void ClipboardOzone::AddSourceToClipboard(
const ClipboardBuffer buffer,
std::unique_ptr<DataTransferEndpoint> data_src) { … }
}