Commit 54bc61b2 authored by pkotwicz@chromium.org's avatar pkotwicz@chromium.org

Fix the HTML5 drag and drop demos at...

Fix the HTML5 drag and drop demos at http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_draganddrop and http://html5demos.com/drag on Linux and CrOS

This CL makes the behavior of OSExchangeData::Provider::SetString() match that of Windows on Linux and CrOS

This CL also changes the string which is dragged out of the omnibox on Linux and CrOS to match the string which is dragged out from the omnibox on Windows.
On Linux and CrOS, with this CL, the dragged out string for URLs no longer includes 'http://' if 'http://' is not visible in the omnibox. For instance, if the user has navigated to 'www.random.org', the dragged out string is 'http://www.random.org' without this CL and 'www.random.org' with this CL.

BUG=355390
TEST=OSExchangeDataTest.URLAndString

Review URL: https://codereview.chromium.org/208313009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282529 0039d316-1c4b-4281-b951-d872f2087c98
parent 222a3e0b
......@@ -362,6 +362,10 @@ void PrepareDragData(const DropData& drop_data,
if (!drop_data.file_contents.empty())
PrepareDragForFileContents(drop_data, provider);
#endif
// Call SetString() before SetURL() when we actually have a custom string.
// SetURL() will itself do SetString() when a string hasn't been set yet,
// but we want to prefer drop_data.text.string() over the URL string if it
// exists.
if (!drop_data.text.string().empty())
provider->SetString(drop_data.text.string());
if (drop_data.url.is_valid())
......
......@@ -44,6 +44,9 @@ bool OSExchangeDataProviderAura::DidOriginateFromRenderer() const {
}
void OSExchangeDataProviderAura::SetString(const base::string16& data) {
if (HasString())
return;
string_ = data;
formats_ |= OSExchangeData::STRING;
}
......
......@@ -127,6 +127,9 @@ bool OSExchangeDataProviderAuraX11::DidOriginateFromRenderer() const {
}
void OSExchangeDataProviderAuraX11::SetString(const base::string16& text_data) {
if (HasString())
return;
std::string utf8 = base::UTF16ToUTF8(text_data);
scoped_refptr<base::RefCountedMemory> mem(
base::RefCountedString::TakeString(&utf8));
......
......@@ -70,6 +70,28 @@ TEST_F(OSExchangeDataTest, TestURLExchangeFormats) {
EXPECT_EQ(url_spec, base::UTF16ToUTF8(output_string));
}
// Test that setting the URL does not overwrite a previously set custom string.
TEST_F(OSExchangeDataTest, URLAndString) {
OSExchangeData data;
base::string16 string = base::ASCIIToUTF16("I can has cheezburger?");
data.SetString(string);
std::string url_spec = "http://www.google.com/";
GURL url(url_spec);
base::string16 url_title = base::ASCIIToUTF16("www.google.com");
data.SetURL(url, url_title);
base::string16 output_string;
EXPECT_TRUE(data.GetString(&output_string));
EXPECT_EQ(string, output_string);
GURL output_url;
base::string16 output_title;
EXPECT_TRUE(data.GetURLAndTitle(
OSExchangeData::CONVERT_FILENAMES, &output_url, &output_title));
EXPECT_EQ(url_spec, output_url.spec());
EXPECT_EQ(url_title, output_title);
}
TEST_F(OSExchangeDataTest, TestPickledData) {
const OSExchangeData::CustomFormat kTestFormat =
ui::Clipboard::GetFormatType("application/vnd.chromium.test");
......
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