#include "ui/base/clipboard/test/test_clipboard.h"
#include <stddef.h>
#include <memory>
#include <optional>
#include <string_view>
#include <utility>
#include "base/containers/contains.h"
#include "base/containers/span.h"
#include "base/memory/ptr_util.h"
#include "base/notreached.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/types/optional_ref.h"
#include "base/types/optional_util.h"
#include "build/build_config.h"
#include "build/buildflag.h"
#include "build/chromecast_buildflags.h"
#include "skia/ext/skia_utils_base.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/clipboard_constants.h"
#include "ui/base/clipboard/clipboard_monitor.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"
namespace ui {
namespace {
bool IsReadAllowed(base::optional_ref<const DataTransferEndpoint> src,
base::optional_ref<const DataTransferEndpoint> dst) { … }
}
TestClipboard::TestClipboard()
: … { … }
TestClipboard::~TestClipboard() = default;
TestClipboard* TestClipboard::CreateForCurrentThread() { … }
void TestClipboard::SetLastModifiedTime(const base::Time& time) { … }
void TestClipboard::OnPreShutdown() { … }
std::optional<DataTransferEndpoint> TestClipboard::GetSource(
ClipboardBuffer buffer) const { … }
const ClipboardSequenceNumberToken& TestClipboard::GetSequenceNumber(
ClipboardBuffer buffer) const { … }
bool TestClipboard::IsFormatAvailable(
const ClipboardFormatType& format,
ClipboardBuffer buffer,
const ui::DataTransferEndpoint* data_dst) const { … }
void TestClipboard::Clear(ClipboardBuffer buffer) { … }
std::vector<std::u16string> TestClipboard::GetStandardFormats(
ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst) const { … }
void TestClipboard::ReadAvailableTypes(
ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::vector<std::u16string>* types) const { … }
void TestClipboard::ReadText(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::u16string* result) const { … }
void TestClipboard::ReadAsciiText(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::string* result) const { … }
void TestClipboard::ReadHTML(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::u16string* markup,
std::string* src_url,
uint32_t* fragment_start,
uint32_t* fragment_end) const { … }
void TestClipboard::ReadSvg(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::u16string* result) const { … }
void TestClipboard::ReadRTF(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::string* result) const { … }
void TestClipboard::ReadPng(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
ReadPngCallback callback) const { … }
void TestClipboard::ReadDataTransferCustomData(
ClipboardBuffer buffer,
const std::u16string& type,
const DataTransferEndpoint* data_dst,
std::u16string* result) const { … }
void TestClipboard::ReadFilenames(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::vector<ui::FileInfo>* result) const { … }
void TestClipboard::ReadBookmark(const DataTransferEndpoint* data_dst,
std::u16string* title,
std::string* url) const { … }
void TestClipboard::ReadData(const ClipboardFormatType& format,
const DataTransferEndpoint* data_dst,
std::string* result) const { … }
base::Time TestClipboard::GetLastModifiedTime() const { … }
void TestClipboard::ClearLastModifiedTime() { … }
#if BUILDFLAG(IS_OZONE)
bool TestClipboard::IsSelectionBufferAvailable() const { … }
#endif
void TestClipboard::WritePortableAndPlatformRepresentations(
ClipboardBuffer buffer,
const ObjectMap& objects,
std::vector<Clipboard::PlatformRepresentation> platform_representations,
std::unique_ptr<DataTransferEndpoint> data_src,
uint32_t privacy_types) { … }
void TestClipboard::WriteText(std::string_view text) { … }
void TestClipboard::WriteHTML(std::string_view markup,
std::optional<std::string_view> source_url) { … }
void TestClipboard::WriteSvg(std::string_view markup) { … }
void TestClipboard::WriteRTF(std::string_view rtf) { … }
void TestClipboard::WriteFilenames(std::vector<ui::FileInfo> filenames) { … }
void TestClipboard::WriteBookmark(std::string_view title,
std::string_view url) { … }
void TestClipboard::WriteWebSmartPaste() { … }
void TestClipboard::WriteBitmap(const SkBitmap& bitmap) { … }
void TestClipboard::WriteData(const ClipboardFormatType& format,
base::span<const uint8_t> data) { … }
void TestClipboard::WriteClipboardHistory() { … }
void TestClipboard::WriteUploadCloudClipboard() { … }
void TestClipboard::WriteConfidentialDataForPassword() { … }
TestClipboard::DataStore::DataStore() = default;
TestClipboard::DataStore::DataStore(const DataStore& other) { … }
TestClipboard::DataStore& TestClipboard::DataStore::operator=(
const DataStore& other) { … }
TestClipboard::DataStore::~DataStore() = default;
void TestClipboard::DataStore::Clear() { … }
void TestClipboard::DataStore::SetDataSource(
std::optional<DataTransferEndpoint> new_data_src) { … }
std::optional<DataTransferEndpoint> TestClipboard::DataStore::GetDataSource()
const { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
void TestClipboard::AddClipboardSourceToDataOffer(
const ClipboardBuffer buffer) {
std::optional<DataTransferEndpoint> data_src = GetSource(buffer);
if (!data_src)
return;
std::string dte_json = ConvertDataTransferEndpointToJson(*data_src);
GetDefaultStore().data[ClipboardFormatType::DataTransferEndpointDataType()] =
dte_json;
}
#endif
bool TestClipboard::MaybeRetrieveSyncedSourceAndCheckIfReadIsAllowed(
ClipboardBuffer buffer,
base::optional_ref<const DataTransferEndpoint> data_src,
const DataTransferEndpoint* data_dst) const { … }
const TestClipboard::DataStore& TestClipboard::GetStore(
ClipboardBuffer buffer) const { … }
TestClipboard::DataStore& TestClipboard::GetStore(ClipboardBuffer buffer) { … }
const TestClipboard::DataStore& TestClipboard::GetDefaultStore() const { … }
TestClipboard::DataStore& TestClipboard::GetDefaultStore() { … }
}