#include "ui/base/clipboard/clipboard_non_backed.h"
#include <stdint.h>
#include <limits>
#include <list>
#include <memory>
#include <optional>
#include <set>
#include <string_view>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h"
#include "base/no_destructor.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/lock.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/types/optional_util.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/clipboard/clipboard_constants.h"
#include "ui/base/clipboard/clipboard_data.h"
#include "ui/base/clipboard/clipboard_format_type.h"
#include "ui/base/clipboard/clipboard_metrics.h"
#include "ui/base/clipboard/clipboard_monitor.h"
#include "ui/base/clipboard/clipboard_sequence_number_token.h"
#include "ui/base/clipboard/clipboard_util.h"
#include "ui/base/clipboard/custom_data_helper.h"
#include "ui/base/clipboard/file_info.h"
#include "ui/base/data_transfer_policy/data_transfer_endpoint.h"
#include "ui/base/data_transfer_policy/data_transfer_policy_controller.h"
namespace ui {
namespace {
InstanceRegistry;
InstanceRegistry* GetInstanceRegistry() { … }
base::Lock& GetInstanceRegistryLock() { … }
void RegisterInstance(const ClipboardNonBacked* clipboard) { … }
void UnregisterInstance(const ClipboardNonBacked* clipboard) { … }
bool IsRegisteredInstance(const Clipboard* clipboard) { … }
}
class ClipboardInternal { … };
class ClipboardDataBuilder { … };
ClipboardData* ClipboardDataBuilder::current_data_ = …;
ClipboardNonBacked* ClipboardNonBacked::GetForCurrentThread() { … }
ClipboardNonBacked::ClipboardNonBacked() { … }
ClipboardNonBacked::~ClipboardNonBacked() { … }
const ClipboardData* ClipboardNonBacked::GetClipboardData(
DataTransferEndpoint* data_dst,
ClipboardBuffer buffer) const { … }
std::unique_ptr<ClipboardData> ClipboardNonBacked::WriteClipboardData(
std::unique_ptr<ClipboardData> data,
ClipboardBuffer buffer) { … }
void ClipboardNonBacked::OnPreShutdown() { … }
std::optional<DataTransferEndpoint> ClipboardNonBacked::GetSource(
ClipboardBuffer buffer) const { … }
const ClipboardSequenceNumberToken& ClipboardNonBacked::GetSequenceNumber(
ClipboardBuffer buffer) const { … }
int ClipboardNonBacked::NumImagesEncodedForTesting(
ClipboardBuffer buffer) const { … }
namespace {
bool IsReadAllowedAndAvailableFormat(
const ClipboardInternal& clipboard_internal,
const DataTransferEndpoint* data_dst,
ClipboardInternalFormat format) { … }
}
bool ClipboardNonBacked::IsFormatAvailable(
const ClipboardFormatType& format,
ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst) const { … }
void ClipboardNonBacked::Clear(ClipboardBuffer buffer) { … }
std::vector<std::u16string> ClipboardNonBacked::GetStandardFormats(
ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst) const { … }
void ClipboardNonBacked::ReadAvailableTypes(
ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::vector<std::u16string>* types) const { … }
void ClipboardNonBacked::ReadText(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::u16string* result) const { … }
void ClipboardNonBacked::ReadAsciiText(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::string* result) const { … }
void ClipboardNonBacked::ReadHTML(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::u16string* markup,
std::string* src_url,
uint32_t* fragment_start,
uint32_t* fragment_end) const { … }
void ClipboardNonBacked::ReadSvg(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::u16string* result) const { … }
void ClipboardNonBacked::ReadRTF(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::string* result) const { … }
void ClipboardNonBacked::ReadPng(ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
ReadPngCallback callback) const { … }
void ClipboardNonBacked::ReadDataTransferCustomData(
ClipboardBuffer buffer,
const std::u16string& type,
const DataTransferEndpoint* data_dst,
std::u16string* result) const { … }
void ClipboardNonBacked::ReadFilenames(
ClipboardBuffer buffer,
const DataTransferEndpoint* data_dst,
std::vector<ui::FileInfo>* result) const { … }
void ClipboardNonBacked::ReadBookmark(const DataTransferEndpoint* data_dst,
std::u16string* title,
std::string* url) const { … }
void ClipboardNonBacked::ReadData(const ClipboardFormatType& format,
const DataTransferEndpoint* data_dst,
std::string* result) const { … }
#if BUILDFLAG(IS_OZONE)
bool ClipboardNonBacked::IsSelectionBufferAvailable() const { … }
#endif
void ClipboardNonBacked::WritePortableAndPlatformRepresentations(
ClipboardBuffer buffer,
const ObjectMap& objects,
std::vector<Clipboard::PlatformRepresentation> platform_representations,
std::unique_ptr<DataTransferEndpoint> data_src,
uint32_t privacy_types) { … }
void ClipboardNonBacked::WriteText(std::string_view text) { … }
void ClipboardNonBacked::WriteHTML(std::string_view markup,
std::optional<std::string_view> source_url) { … }
void ClipboardNonBacked::WriteSvg(std::string_view markup) { … }
void ClipboardNonBacked::WriteRTF(std::string_view rtf) { … }
void ClipboardNonBacked::WriteFilenames(std::vector<ui::FileInfo> filenames) { … }
void ClipboardNonBacked::WriteBookmark(std::string_view title,
std::string_view url) { … }
void ClipboardNonBacked::WriteWebSmartPaste() { … }
void ClipboardNonBacked::WriteBitmap(const SkBitmap& bitmap) { … }
void ClipboardNonBacked::WriteData(const ClipboardFormatType& format,
base::span<const uint8_t> data) { … }
void ClipboardNonBacked::WriteClipboardHistory() { … }
void ClipboardNonBacked::WriteUploadCloudClipboard() { … }
void ClipboardNonBacked::WriteConfidentialDataForPassword() { … }
const ClipboardInternal& ClipboardNonBacked::GetInternalClipboard(
ClipboardBuffer buffer) const { … }
ClipboardInternal& ClipboardNonBacked::GetInternalClipboard(
ClipboardBuffer buffer) { … }
}