Commit bf8745ed authored by Bret Sepulveda's avatar Bret Sepulveda Committed by Commit Bot

Revert "[ozone] Improved clipboard tests and de-duplicated string constants."

This reverts commit 1523bb86.

Reason for revert: ClipboardTest/TestClipboardTest.TextTest is failing on linux-lacros-tester-rel. See for example https://ci.chromium.org/p/chromium/builders/ci/linux-lacros-tester-rel/944

Original change's description:
> [ozone] Improved clipboard tests and de-duplicated string constants.
> 
> This CL pays a bit of technical debt in the clipboard implementation.
> 
> First, it updates a test that verifies that putting text into clipboard
> registers the proper set of MIME types, as had been suggested in [1].
> 
> Second, it enables for Ozone the test that verifies selection buffers.
> 
> Third, it de-duplicates some string constants.
> 
> [1] https://chromium-review.googlesource.com/c/chromium/src/+/2306252
> 
> Change-Id: I6beb6b5b3827f0ec09cf19bc1868e7955141f680
> Bug: 911992, 1105892
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2346338
> Reviewed-by: Scott Violet <sky@chromium.org>
> Commit-Queue: Alexander Dunaev <adunaev@igalia.com>
> Cr-Commit-Position: refs/heads/master@{#797572}

TBR=sky@chromium.org,adunaev@igalia.com

Change-Id: I376620331b967c70225b10d67b5e6e467802cf5e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 911992
Bug: 1105892
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2352802Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Commit-Queue: Bret Sepulveda <bsep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797634}
parent 674786ba
......@@ -31,6 +31,8 @@
namespace exo {
namespace {
constexpr char kTextMimeTypeUtf8[] = "text/plain;charset=utf-8";
constexpr char kUtf8String[] = "UTF8_STRING";
constexpr char kTextMimeTypeUtf16[] = "text/plain;charset=utf-16";
constexpr char kTextHtmlMimeTypeUtf8[] = "text/html;charset=utf-8";
constexpr char kTextHtmlMimeTypeUtf16[] = "text/html;charset=utf-16";
......@@ -277,7 +279,7 @@ void DataOffer::SetDropData(FileHelper* file_helper,
base::string16 string_content;
if (data.HasString() && data.GetString(&string_content)) {
const std::string utf8_mime_type = std::string(ui::kMimeTypeTextUtf8);
const std::string utf8_mime_type = std::string(kTextMimeTypeUtf8);
data_.emplace(utf8_mime_type,
EncodeAsRefCountedString(string_content, kUTF8));
delegate_->OnOffer(utf8_mime_type);
......@@ -319,11 +321,10 @@ void DataOffer::SetClipboardData(FileHelper* file_helper,
/* data_dst = */ nullptr)) {
auto utf8_callback =
base::BindRepeating(&ReadTextFromClipboard, std::string(kUTF8));
delegate_->OnOffer(std::string(ui::kMimeTypeTextUtf8));
data_callbacks_.emplace(std::string(ui::kMimeTypeTextUtf8), utf8_callback);
delegate_->OnOffer(std::string(ui::kMimeTypeLinuxUtf8String));
data_callbacks_.emplace(std::string(ui::kMimeTypeLinuxUtf8String),
utf8_callback);
delegate_->OnOffer(std::string(kTextMimeTypeUtf8));
data_callbacks_.emplace(std::string(kTextMimeTypeUtf8), utf8_callback);
delegate_->OnOffer(std::string(kUtf8String));
data_callbacks_.emplace(std::string(kUtf8String), utf8_callback);
delegate_->OnOffer(std::string(kTextMimeTypeUtf16));
data_callbacks_.emplace(
std::string(kTextMimeTypeUtf16),
......
......@@ -22,7 +22,6 @@
#include "net/base/mime_util.h"
#include "third_party/blink/public/common/mime_util/mime_util.h"
#include "third_party/icu/source/common/unicode/ucnv.h"
#include "ui/base/clipboard/clipboard_constants.h"
namespace exo {
......@@ -249,7 +248,7 @@ void DataSource::GetDataForPreferredMimeTypes(
for (auto mime_type : mime_types_) {
if (net::MatchesMimeType(std::string(kTextPlain), mime_type) ||
mime_type == ui::kMimeTypeLinuxUtf8String) {
mime_type == kEncodingUTF8Legacy) {
if (text_reader.is_null())
continue;
......
......@@ -4,8 +4,6 @@
#include "components/exo/mime_utils.h"
#include "ui/base/clipboard/clipboard_constants.h"
namespace {
constexpr char kCharset[] = ";charset=";
......@@ -18,7 +16,7 @@ namespace exo {
std::string GetCharset(const std::string& mime_type) {
// We special case UTF8_STRING to provide minimal handling of X11 apps.
if (mime_type == ui::kMimeTypeLinuxUtf8String)
if (mime_type == kEncodingUTF8Legacy)
return std::string(kEncodingUTF8Charset);
auto pos = mime_type.find(kCharset);
......
......@@ -9,6 +9,8 @@
namespace exo {
constexpr char kEncodingUTF8Legacy[] = "UTF8_STRING";
// Takes a text/* mime type and returns the name of the character set specified
// in the type. If no character set is specified, defaults to US-ASCII.
std::string GetCharset(const std::string& mime_type);
......
......@@ -10,12 +10,15 @@ const char kMimeTypeText[] = "text/plain";
const char kMimeTypeTextUtf8[] = "text/plain;charset=utf-8";
const char kMimeTypeURIList[] = "text/uri-list";
const char kMimeTypeMozillaURL[] = "text/x-moz-url";
// Unstandardized format for downloading files after drop events. Now only
// works in Windows, but used to also work in Linux and MacOS.
// See https://crbug.com/860557 and https://crbug.com/425170.
const char kMimeTypeDownloadURL[] = "downloadurl";
const char kMimeTypeHTML[] = "text/html";
const char kMimeTypeRTF[] = "text/rtf";
const char kMimeTypePNG[] = "image/png";
#if !defined(OS_APPLE)
// TODO(dcheng): This name is temporary. See crbug.com/106449.
const char kMimeTypeWebCustomData[] = "chromium/x-web-custom-data";
const char kMimeTypeWebkitSmartPaste[] = "chromium/x-webkit-paste";
const char kMimeTypePepperCustomData[] = "chromium/x-pepper-custom-data";
......
......@@ -24,9 +24,6 @@ namespace ui {
COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES) extern const char kMimeTypeText[];
COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES) extern const char kMimeTypeTextUtf8[];
COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES) extern const char kMimeTypeURIList[];
// Unstandardized format for downloading files after drop events. Now only
// works in Windows, but used to also work in Linux and MacOS.
// See https://crbug.com/860557 and https://crbug.com/425170.
COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES)
extern const char kMimeTypeDownloadURL[];
COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES)
......@@ -34,19 +31,7 @@ extern const char kMimeTypeMozillaURL[];
COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES) extern const char kMimeTypeHTML[];
COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES) extern const char kMimeTypeRTF[];
COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES) extern const char kMimeTypePNG[];
// Linux-specific MIME type constants (also used in Fuchsia).
#if defined(OS_LINUX) || defined(OS_FUCHSIA)
COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES)
constexpr char kMimeTypeLinuxUtf8String[] = "UTF8_STRING";
COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES)
constexpr char kMimeTypeLinuxString[] = "STRING";
COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES)
constexpr char kMimeTypeLinuxText[] = "TEXT";
#endif // defined(OS_LINUX) || defined(OS_FUCHSIA)
#if !defined(OS_APPLE)
// TODO(dcheng): This name is temporary. See crbug.com/106449.
COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES)
extern const char kMimeTypeWebCustomData[];
COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES)
......
......@@ -38,6 +38,12 @@ namespace ui {
namespace {
// TODO(crbug.com/1105892): those three constants can be found in a few other
// places. Perhaps it would be worth finding some common place for them?
constexpr char kMimeTypeX11String[] = "STRING";
constexpr char kMimeTypeX11Text[] = "TEXT";
constexpr char kMimeTypeX11Utf8String[] = "UTF8_STRING";
// The amount of time to wait for a request to complete before aborting it.
constexpr base::TimeDelta kRequestTimeout = base::TimeDelta::FromSeconds(10);
......@@ -558,8 +564,8 @@ void ClipboardOzone::WritePlatformRepresentations(
void ClipboardOzone::WriteText(const char* text_data, size_t text_len) {
std::vector<uint8_t> data(text_data, text_data + text_len);
async_clipboard_ozone_->InsertData(
std::move(data), {kMimeTypeText, kMimeTypeLinuxText, kMimeTypeLinuxString,
kMimeTypeTextUtf8, kMimeTypeLinuxUtf8String});
std::move(data), {kMimeTypeText, kMimeTypeX11Text, kMimeTypeX11String,
kMimeTypeTextUtf8, kMimeTypeX11Utf8String});
}
void ClipboardOzone::WriteHTML(const char* markup_data,
......
......@@ -27,7 +27,6 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "build/chromecast_buildflags.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -168,11 +167,6 @@ TYPED_TEST(ClipboardTest, TextTest) {
EXPECT_THAT(this->GetAvailableTypes(ClipboardBuffer::kCopyPaste),
Contains(ASCIIToUTF16(kMimeTypeText)));
#if defined(USE_OZONE) && !defined(OS_CHROMEOS) && !defined(OS_FUCHSIA) && \
!BUILDFLAG(IS_CHROMECAST)
EXPECT_THAT(this->GetAvailableTypes(ClipboardBuffer::kCopyPaste),
Contains(ASCIIToUTF16(kMimeTypeTextUtf8)));
#endif
EXPECT_TRUE(this->clipboard().IsFormatAvailable(
ClipboardFormatType::GetPlainTextType(), ClipboardBuffer::kCopyPaste,
/* data_dst = */ nullptr));
......@@ -248,13 +242,10 @@ TYPED_TEST(ClipboardTest, RTFTest) {
}
#endif // !defined(OS_ANDROID)
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// TODO(msisov, tonikitoo): Enable test once ClipboardOzone implements
// selection support. https://crbug.com/911992
#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(USE_OZONE)
TYPED_TEST(ClipboardTest, MultipleBufferTest) {
#if defined(USE_OZONE)
if (!this->clipboard().IsSelectionBufferAvailable())
return;
#endif
base::string16 text(ASCIIToUTF16("Standard")), text_result;
base::string16 markup(ASCIIToUTF16("<string>Selection</string>"));
std::string url("http://www.example.com/"), url_result;
......
......@@ -758,9 +758,9 @@ void ClipboardX11::WriteText(const char* text_data, size_t text_len) {
base::RefCountedString::TakeString(&str));
x11_details_->InsertMapping(kMimeTypeText, mem);
x11_details_->InsertMapping(kMimeTypeLinuxText, mem);
x11_details_->InsertMapping(kMimeTypeLinuxString, mem);
x11_details_->InsertMapping(kMimeTypeLinuxUtf8String, mem);
x11_details_->InsertMapping(kText, mem);
x11_details_->InsertMapping(kString, mem);
x11_details_->InsertMapping(kUtf8String, mem);
}
void ClipboardX11::WriteHTML(const char* markup_data,
......
......@@ -19,13 +19,19 @@
namespace ui {
const char kString[] = "STRING";
const char kText[] = "TEXT";
const char kTextPlain[] = "text/plain";
const char kTextPlainUtf8[] = "text/plain;charset=utf-8";
const char kUtf8String[] = "UTF8_STRING";
std::vector<x11::Atom> GetTextAtomsFrom() {
std::vector<x11::Atom> atoms;
atoms.push_back(gfx::GetAtom(kMimeTypeLinuxUtf8String));
atoms.push_back(gfx::GetAtom(kMimeTypeLinuxString));
atoms.push_back(gfx::GetAtom(kMimeTypeLinuxText));
atoms.push_back(gfx::GetAtom(kMimeTypeText));
atoms.push_back(gfx::GetAtom(kMimeTypeTextUtf8));
atoms.push_back(gfx::GetAtom(kUtf8String));
atoms.push_back(gfx::GetAtom(kString));
atoms.push_back(gfx::GetAtom(kText));
atoms.push_back(gfx::GetAtom(kTextPlain));
atoms.push_back(gfx::GetAtom(kTextPlainUtf8));
return atoms;
}
......@@ -170,12 +176,11 @@ size_t SelectionData::GetSize() const {
}
std::string SelectionData::GetText() const {
if (type_ == gfx::GetAtom(kMimeTypeLinuxUtf8String) ||
type_ == gfx::GetAtom(kMimeTypeLinuxText) ||
type_ == gfx::GetAtom(kMimeTypeTextUtf8)) {
if (type_ == gfx::GetAtom(kUtf8String) || type_ == gfx::GetAtom(kText) ||
type_ == gfx::GetAtom(kTextPlainUtf8)) {
return RefCountedMemoryToString(memory_);
} else if (type_ == gfx::GetAtom(kMimeTypeLinuxString) ||
type_ == gfx::GetAtom(kMimeTypeText)) {
} else if (type_ == gfx::GetAtom(kString) ||
type_ == gfx::GetAtom(kTextPlain)) {
std::string result;
base::ConvertToUtf8AndNormalize(RefCountedMemoryToString(memory_),
base::kCodepageLatin1, &result);
......
......@@ -15,6 +15,10 @@
namespace ui {
class SelectionData;
COMPONENT_EXPORT(UI_BASE_X) extern const char kString[];
COMPONENT_EXPORT(UI_BASE_X) extern const char kText[];
COMPONENT_EXPORT(UI_BASE_X) extern const char kUtf8String[];
// Returns a list of all text atoms that we handle.
COMPONENT_EXPORT(UI_BASE_X) std::vector<x11::Atom> GetTextAtomsFrom();
......
......@@ -97,9 +97,9 @@ void XOSExchangeDataProvider::SetString(const base::string16& text_data) {
base::RefCountedString::TakeString(&utf8));
format_map_.Insert(gfx::GetAtom(kMimeTypeText), mem);
format_map_.Insert(gfx::GetAtom(kMimeTypeLinuxText), mem);
format_map_.Insert(gfx::GetAtom(kMimeTypeLinuxString), mem);
format_map_.Insert(gfx::GetAtom(kMimeTypeLinuxUtf8String), mem);
format_map_.Insert(gfx::GetAtom(kText), mem);
format_map_.Insert(gfx::GetAtom(kString), mem);
format_map_.Insert(gfx::GetAtom(kUtf8String), mem);
}
void XOSExchangeDataProvider::SetURL(const GURL& url,
......
......@@ -9,6 +9,14 @@
namespace ui {
namespace {
const char kString[] = "STRING";
const char kText[] = "TEXT";
const char kUtf8String[] = "UTF8_STRING";
} // namespace
WaylandDataOfferBase::WaylandDataOfferBase() = default;
WaylandDataOfferBase::~WaylandDataOfferBase() = default;
......@@ -18,10 +26,9 @@ void WaylandDataOfferBase::EnsureTextMimeTypeIfNeeded() {
if (std::any_of(mime_types_.begin(), mime_types_.end(),
[](const std::string& mime_type) {
return mime_type == kMimeTypeLinuxString ||
mime_type == kMimeTypeLinuxText ||
return mime_type == kString || mime_type == kText ||
mime_type == kMimeTypeTextUtf8 ||
mime_type == kMimeTypeLinuxUtf8String;
mime_type == kUtf8String;
})) {
mime_types_.push_back(kMimeTypeText);
text_plain_mime_type_inserted_ = true;
......
......@@ -25,21 +25,23 @@ namespace {
const char kChromeSelection[] = "CHROME_SELECTION";
const char kClipboard[] = "CLIPBOARD";
const char kString[] = "STRING";
const char kTargets[] = "TARGETS";
const char kTimestamp[] = "TIMESTAMP";
const char kUtf8String[] = "UTF8_STRING";
// Helps to allow conversions for text/plain[;charset=utf-8] <=> [UTF8_]STRING.
void ExpandTypes(std::vector<std::string>* list) {
bool has_mime_type_text = Contains(*list, ui::kMimeTypeText);
bool has_string = Contains(*list, kMimeTypeLinuxString);
bool has_string = Contains(*list, kString);
bool has_mime_type_utf8 = Contains(*list, kMimeTypeTextUtf8);
bool has_utf8_string = Contains(*list, kMimeTypeLinuxUtf8String);
bool has_utf8_string = Contains(*list, kUtf8String);
if (has_mime_type_text && !has_string)
list->push_back(kMimeTypeLinuxString);
list->push_back(kString);
if (has_string && !has_mime_type_text)
list->push_back(ui::kMimeTypeText);
if (has_mime_type_utf8 && !has_utf8_string)
list->push_back(kMimeTypeLinuxUtf8String);
list->push_back(kUtf8String);
if (has_utf8_string && !has_mime_type_utf8)
list->push_back(kMimeTypeTextUtf8);
}
......@@ -161,11 +163,9 @@ bool X11ClipboardOzone::OnSelectionRequest(
std::string key = target_name;
// Allow conversions for text/plain[;charset=utf-8] <=> [UTF8_]STRING.
if (key == kMimeTypeLinuxUtf8String &&
!Contains(offer_data_map, kMimeTypeLinuxUtf8String)) {
if (key == kUtf8String && !Contains(offer_data_map, kUtf8String)) {
key = kMimeTypeTextUtf8;
} else if (key == kMimeTypeLinuxString &&
!Contains(offer_data_map, kMimeTypeLinuxString)) {
} else if (key == kString && !Contains(offer_data_map, kString)) {
key = kMimeTypeText;
}
auto it = offer_data_map.find(key);
......@@ -314,9 +314,9 @@ void X11ClipboardOzone::ReadRemoteClipboard(x11::Atom selection) {
std::string target = selection_state.data_mime_type;
if (!Contains(selection_state.mime_types, target)) {
if (target == kMimeTypeText) {
target = kMimeTypeLinuxString;
target = kString;
} else if (target == kMimeTypeTextUtf8) {
target = kMimeTypeLinuxUtf8String;
target = kUtf8String;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment