diff options
author | pkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-11 03:40:22 +0000 |
---|---|---|
committer | pkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-11 03:40:22 +0000 |
commit | 54bc61b2ca7a6f6592830f8169be42222273fdc8 (patch) | |
tree | 71c36d14a5eef462602f1b1b4aefdcb52539f220 | |
parent | 222a3e0bfaa14a4348b28640ff50b09b48ea3601 (diff) | |
download | chromium_src-54bc61b2ca7a6f6592830f8169be42222273fdc8.zip chromium_src-54bc61b2ca7a6f6592830f8169be42222273fdc8.tar.gz chromium_src-54bc61b2ca7a6f6592830f8169be42222273fdc8.tar.bz2 |
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
4 files changed, 32 insertions, 0 deletions
diff --git a/content/browser/web_contents/web_contents_view_aura.cc b/content/browser/web_contents/web_contents_view_aura.cc index f0cce65..d9959de 100644 --- a/content/browser/web_contents/web_contents_view_aura.cc +++ b/content/browser/web_contents/web_contents_view_aura.cc @@ -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()) diff --git a/ui/base/dragdrop/os_exchange_data_provider_aura.cc b/ui/base/dragdrop/os_exchange_data_provider_aura.cc index 2a44793..0d4fb90 100644 --- a/ui/base/dragdrop/os_exchange_data_provider_aura.cc +++ b/ui/base/dragdrop/os_exchange_data_provider_aura.cc @@ -44,6 +44,9 @@ bool OSExchangeDataProviderAura::DidOriginateFromRenderer() const { } void OSExchangeDataProviderAura::SetString(const base::string16& data) { + if (HasString()) + return; + string_ = data; formats_ |= OSExchangeData::STRING; } diff --git a/ui/base/dragdrop/os_exchange_data_provider_aurax11.cc b/ui/base/dragdrop/os_exchange_data_provider_aurax11.cc index bf58398..e6de969 100644 --- a/ui/base/dragdrop/os_exchange_data_provider_aurax11.cc +++ b/ui/base/dragdrop/os_exchange_data_provider_aurax11.cc @@ -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)); diff --git a/ui/base/dragdrop/os_exchange_data_unittest.cc b/ui/base/dragdrop/os_exchange_data_unittest.cc index 6087b63..1440c85 100644 --- a/ui/base/dragdrop/os_exchange_data_unittest.cc +++ b/ui/base/dragdrop/os_exchange_data_unittest.cc @@ -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"); |