summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-16 01:28:17 +0000
committerdcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-16 01:28:17 +0000
commitda41ae9be8d07ceca1b012c5e33a1dcd7987d400 (patch)
tree9da98f291d9b32407b1faf56040fce859897f9e2
parentcbdc8c2b4b46c7e7886c9e99bc595a0b9936b381 (diff)
downloadchromium_src-da41ae9be8d07ceca1b012c5e33a1dcd7987d400.zip
chromium_src-da41ae9be8d07ceca1b012c5e33a1dcd7987d400.tar.gz
chromium_src-da41ae9be8d07ceca1b012c5e33a1dcd7987d400.tar.bz2
Allow empty strings to be written to the clipboard
BUG=109810 TEST=manual testing Review URL: https://chromiumcodereview.appspot.com/10532168 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142554 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/web_contents/web_contents_drag_win.cc8
-rw-r--r--content/browser/web_contents/web_contents_view_aura.cc24
-rw-r--r--content/browser/web_contents/web_drag_dest_gtk.cc12
-rw-r--r--content/browser/web_contents/web_drag_dest_mac.mm12
-rw-r--r--content/browser/web_contents/web_drag_dest_mac_unittest.mm4
-rw-r--r--content/browser/web_contents/web_drag_source_gtk.cc8
-rw-r--r--content/browser/web_contents/web_drag_source_mac.mm12
-rw-r--r--content/common/drag_messages.h4
-rw-r--r--ui/base/clipboard/scoped_clipboard_writer.cc9
-rw-r--r--webkit/glue/webclipboard_impl.cc6
-rw-r--r--webkit/glue/webdropdata.cc23
-rw-r--r--webkit/glue/webdropdata.h5
-rw-r--r--webkit/glue/webdropdata_win.cc18
13 files changed, 81 insertions, 64 deletions
diff --git a/content/browser/web_contents/web_contents_drag_win.cc b/content/browser/web_contents/web_contents_drag_win.cc
index a68faaa..99c9bd6 100644
--- a/content/browser/web_contents/web_contents_drag_win.cc
+++ b/content/browser/web_contents/web_contents_drag_win.cc
@@ -282,12 +282,12 @@ void WebContentsDragWin::DoDragging(const WebDropData& drop_data,
// a shortcut so we add it first.
if (!drop_data.file_contents.empty())
PrepareDragForFileContents(drop_data, &data);
- if (!drop_data.text_html.empty())
- data.SetHtml(drop_data.text_html, drop_data.html_base_url);
+ if (!drop_data.html.string().empty())
+ data.SetHtml(drop_data.html.string(), drop_data.html_base_url);
// We set the text contents before the URL because the URL also sets text
// content.
- if (!drop_data.plain_text.empty())
- data.SetString(drop_data.plain_text);
+ if (!drop_data.text.string().empty())
+ data.SetString(drop_data.text.string());
if (drop_data.url.is_valid())
PrepareDragForUrl(drop_data, &data);
if (!drop_data.custom_data.empty()) {
diff --git a/content/browser/web_contents/web_contents_view_aura.cc b/content/browser/web_contents/web_contents_view_aura.cc
index 101e58b..448c145 100644
--- a/content/browser/web_contents/web_contents_view_aura.cc
+++ b/content/browser/web_contents/web_contents_view_aura.cc
@@ -94,12 +94,12 @@ class WebDragSourceAura : public MessageLoopForUI::Observer {
// Utility to fill a ui::OSExchangeDataProviderAura object from WebDropData.
void PrepareDragData(const WebDropData& drop_data,
ui::OSExchangeDataProviderAura* provider) {
- if (!drop_data.plain_text.empty())
- provider->SetString(drop_data.plain_text);
+ if (!drop_data.text.string().empty())
+ provider->SetString(drop_data.text.string());
if (drop_data.url.is_valid())
provider->SetURL(drop_data.url, drop_data.url_title);
- if (!drop_data.text_html.empty())
- provider->SetHtml(drop_data.text_html, drop_data.html_base_url);
+ if (!drop_data.html.string().empty())
+ provider->SetHtml(drop_data.html.string(), drop_data.html_base_url);
if (!drop_data.filenames.empty()) {
std::vector<ui::OSExchangeData::FileInfo> filenames;
for (std::vector<WebDropData::FileInfo>::const_iterator it =
@@ -123,20 +123,26 @@ void PrepareDragData(const WebDropData& drop_data,
// Utility to fill a WebDropData object from ui::OSExchangeData.
void PrepareWebDropData(WebDropData* drop_data,
const ui::OSExchangeData& data) {
- string16 plain_text, url_title;
- GURL url;
-
+ string16 plain_text;
data.GetString(&plain_text);
if (!plain_text.empty())
- drop_data->plain_text = plain_text;
+ drop_data->text = NullableString16(plain_text, false);
+ GURL url;
+ string16 url_title;
data.GetURLAndTitle(&url, &url_title);
if (url.is_valid()) {
drop_data->url = url;
drop_data->url_title = url_title;
}
- data.GetHtml(&drop_data->text_html, &drop_data->html_base_url);
+ string16 html;
+ GURL html_base_url;
+ data.GetHtml(&html, &html_base_url);
+ if (!html.empty())
+ drop_data->html = NullableString16(html, false);
+ if (html_base_url.is_valid())
+ drop_data->html_base_url = html_base_url;
std::vector<ui::OSExchangeData::FileInfo> files;
if (data.GetFilenames(&files) && !files.empty()) {
diff --git a/content/browser/web_contents/web_drag_dest_gtk.cc b/content/browser/web_contents/web_drag_dest_gtk.cc
index 3a2fc0d..20093f4 100644
--- a/content/browser/web_contents/web_drag_dest_gtk.cc
+++ b/content/browser/web_contents/web_drag_dest_gtk.cc
@@ -176,8 +176,9 @@ void WebDragDestGtk::OnDragDataReceived(
if (target == ui::GetAtomForTarget(ui::TEXT_PLAIN)) {
guchar* text = gtk_selection_data_get_text(data);
if (text) {
- drop_data_->plain_text =
- UTF8ToUTF16(std::string(reinterpret_cast<const char*>(text)));
+ drop_data_->text = NullableString16(
+ UTF8ToUTF16(std::string(reinterpret_cast<const char*>(text))),
+ false);
g_free(text);
}
} else if (target == ui::GetAtomForTarget(ui::TEXT_URI_LIST)) {
@@ -199,7 +200,7 @@ void WebDragDestGtk::OnDragDataReceived(
// This is a hack. Some file managers also populate text/plain with
// a file URL when dragging files, so we clear it to avoid exposing
// it to the web content.
- drop_data_->plain_text.clear();
+ drop_data_->text = NullableString16(true);
} else if (!drop_data_->url.is_valid()) {
// Also set the first non-file URL as the URL content for the drop.
drop_data_->url = url;
@@ -209,9 +210,10 @@ void WebDragDestGtk::OnDragDataReceived(
}
} else if (target == ui::GetAtomForTarget(ui::TEXT_HTML)) {
// TODO(estade): Can the html have a non-UTF8 encoding?
- drop_data_->text_html =
+ drop_data_->html = NullableString16(
UTF8ToUTF16(std::string(reinterpret_cast<const char*>(raw_data),
- data_length));
+ data_length)),
+ false);
// We leave the base URL empty.
} else if (target == ui::GetAtomForTarget(ui::NETSCAPE_URL)) {
std::string netscape_url(reinterpret_cast<const char*>(raw_data),
diff --git a/content/browser/web_contents/web_drag_dest_mac.mm b/content/browser/web_contents/web_drag_dest_mac.mm
index a502317..7c97892 100644
--- a/content/browser/web_contents/web_drag_dest_mac.mm
+++ b/content/browser/web_contents/web_drag_dest_mac.mm
@@ -239,17 +239,19 @@ int GetModifierFlags() {
// Get plain text.
if ([types containsObject:NSStringPboardType]) {
- data->plain_text =
- base::SysNSStringToUTF16([pboard stringForType:NSStringPboardType]);
+ data->text = NullableString16(
+ base::SysNSStringToUTF16([pboard stringForType:NSStringPboardType]),
+ false);
}
// Get HTML. If there's no HTML, try RTF.
if ([types containsObject:NSHTMLPboardType]) {
- data->text_html =
- base::SysNSStringToUTF16([pboard stringForType:NSHTMLPboardType]);
+ data->html = NullableString16(
+ base::SysNSStringToUTF16([pboard stringForType:NSHTMLPboardType]),
+ false);
} else if ([types containsObject:NSRTFPboardType]) {
NSString* html = [pboard htmlFromRtf];
- data->text_html = base::SysNSStringToUTF16(html);
+ data->html = NullableString16(base::SysNSStringToUTF16(html), false);
}
// Get files.
diff --git a/content/browser/web_contents/web_drag_dest_mac_unittest.mm b/content/browser/web_contents/web_drag_dest_mac_unittest.mm
index ec07e28..76fafbd 100644
--- a/content/browser/web_contents/web_drag_dest_mac_unittest.mm
+++ b/content/browser/web_contents/web_drag_dest_mac_unittest.mm
@@ -157,8 +157,8 @@ TEST_F(WebDragDestTest, Data) {
[pboard setString:textString forType:NSStringPboardType];
[drag_dest_ populateWebDropData:&data fromPasteboard:pboard];
EXPECT_EQ(data.url.spec(), "http://www.google.com/");
- EXPECT_EQ(base::SysNSStringToUTF16(textString), data.plain_text);
- EXPECT_EQ(base::SysNSStringToUTF16(htmlString), data.text_html);
+ EXPECT_EQ(base::SysNSStringToUTF16(textString), data.text.string());
+ EXPECT_EQ(base::SysNSStringToUTF16(htmlString), data.html.string());
[pboard releaseGlobally];
}
diff --git a/content/browser/web_contents/web_drag_source_gtk.cc b/content/browser/web_contents/web_drag_source_gtk.cc
index 4e8518b..3572e75 100644
--- a/content/browser/web_contents/web_drag_source_gtk.cc
+++ b/content/browser/web_contents/web_drag_source_gtk.cc
@@ -85,14 +85,14 @@ void WebDragSourceGtk::StartDragging(const WebDropData& drop_data,
int targets_mask = 0;
- if (!drop_data.plain_text.empty())
+ if (!drop_data.text.string().empty())
targets_mask |= ui::TEXT_PLAIN;
if (drop_data.url.is_valid()) {
targets_mask |= ui::TEXT_URI_LIST;
targets_mask |= ui::CHROME_NAMED_URL;
targets_mask |= ui::NETSCAPE_URL;
}
- if (!drop_data.text_html.empty())
+ if (!drop_data.html.string().empty())
targets_mask |= ui::TEXT_HTML;
if (!drop_data.file_contents.empty())
targets_mask |= ui::CHROME_WEBDROP_FILE_CONTENTS;
@@ -183,7 +183,7 @@ void WebDragSourceGtk::OnDragDataGet(GtkWidget* sender,
switch (target_type) {
case ui::TEXT_PLAIN: {
- std::string utf8_text = UTF16ToUTF8(drop_data_->plain_text);
+ std::string utf8_text = UTF16ToUTF8(drop_data_->text.string());
gtk_selection_data_set_text(selection_data, utf8_text.c_str(),
utf8_text.length());
break;
@@ -192,7 +192,7 @@ void WebDragSourceGtk::OnDragDataGet(GtkWidget* sender,
case ui::TEXT_HTML: {
// TODO(estade): change relative links to be absolute using
// |html_base_url|.
- std::string utf8_text = UTF16ToUTF8(drop_data_->text_html);
+ std::string utf8_text = UTF16ToUTF8(drop_data_->html.string());
gtk_selection_data_set(selection_data,
ui::GetAtomForTarget(ui::TEXT_HTML),
kBitsPerByte,
diff --git a/content/browser/web_contents/web_drag_source_mac.mm b/content/browser/web_contents/web_drag_source_mac.mm
index 875f892..f9e57a4 100644
--- a/content/browser/web_contents/web_drag_source_mac.mm
+++ b/content/browser/web_contents/web_drag_source_mac.mm
@@ -151,9 +151,9 @@ void PromiseWriterHelper(const WebDropData& drop_data,
// HTML.
if ([type isEqualToString:NSHTMLPboardType]) {
- DCHECK(!dropData_->text_html.empty());
+ DCHECK(!dropData_->html.string().empty());
// See comment on |kHtmlHeader| above.
- [pboard setString:SysUTF16ToNSString(kHtmlHeader + dropData_->text_html)
+ [pboard setString:SysUTF16ToNSString(kHtmlHeader + dropData_->html.string())
forType:NSHTMLPboardType];
// URL.
@@ -206,8 +206,8 @@ void PromiseWriterHelper(const WebDropData& drop_data,
// Plain text.
} else if ([type isEqualToString:NSStringPboardType]) {
- DCHECK(!dropData_->plain_text.empty());
- [pboard setString:SysUTF16ToNSString(dropData_->plain_text)
+ DCHECK(!dropData_->text.string().empty());
+ [pboard setString:SysUTF16ToNSString(dropData_->text.string())
forType:NSStringPboardType];
// Custom MIME data.
@@ -375,7 +375,7 @@ void PromiseWriterHelper(const WebDropData& drop_data,
owner:contentsView_];
// HTML.
- if (!dropData_->text_html.empty())
+ if (!dropData_->html.string().empty())
[pasteboard_ addTypes:[NSArray arrayWithObject:NSHTMLPboardType]
owner:contentsView_];
@@ -439,7 +439,7 @@ void PromiseWriterHelper(const WebDropData& drop_data,
}
// Plain text.
- if (!dropData_->plain_text.empty())
+ if (!dropData_->text.string().empty())
[pasteboard_ addTypes:[NSArray arrayWithObject:NSStringPboardType]
owner:contentsView_];
diff --git a/content/common/drag_messages.h b/content/common/drag_messages.h
index 59ee6b3..7714570 100644
--- a/content/common/drag_messages.h
+++ b/content/common/drag_messages.h
@@ -29,8 +29,8 @@ IPC_STRUCT_TRAITS_BEGIN(WebDropData)
IPC_STRUCT_TRAITS_MEMBER(referrer_policy)
IPC_STRUCT_TRAITS_MEMBER(filenames)
IPC_STRUCT_TRAITS_MEMBER(filesystem_id)
- IPC_STRUCT_TRAITS_MEMBER(plain_text)
- IPC_STRUCT_TRAITS_MEMBER(text_html)
+ IPC_STRUCT_TRAITS_MEMBER(text)
+ IPC_STRUCT_TRAITS_MEMBER(html)
IPC_STRUCT_TRAITS_MEMBER(html_base_url)
IPC_STRUCT_TRAITS_MEMBER(file_description_filename)
IPC_STRUCT_TRAITS_MEMBER(file_contents)
diff --git a/ui/base/clipboard/scoped_clipboard_writer.cc b/ui/base/clipboard/scoped_clipboard_writer.cc
index 95cf505..5ecb43c 100644
--- a/ui/base/clipboard/scoped_clipboard_writer.cc
+++ b/ui/base/clipboard/scoped_clipboard_writer.cc
@@ -38,9 +38,6 @@ void ScopedClipboardWriter::WriteURL(const string16& text) {
void ScopedClipboardWriter::WriteHTML(const string16& markup,
const std::string& source_url) {
- if (markup.empty())
- return;
-
std::string utf8_markup = UTF16ToUTF8(markup);
Clipboard::ObjectMapParams parameters;
@@ -56,9 +53,6 @@ void ScopedClipboardWriter::WriteHTML(const string16& markup,
}
void ScopedClipboardWriter::WriteRTF(const std::string& rtf_data) {
- if (rtf_data.empty())
- return;
-
Clipboard::ObjectMapParams parameters;
parameters.push_back(Clipboard::ObjectMapParam(rtf_data.begin(),
rtf_data.end()));
@@ -139,9 +133,6 @@ void ScopedClipboardWriter::Reset() {
}
void ScopedClipboardWriter::WriteTextOrURL(const string16& text, bool is_url) {
- if (text.empty())
- return;
-
std::string utf8_text = UTF16ToUTF8(text);
Clipboard::ObjectMapParams parameters;
diff --git a/webkit/glue/webclipboard_impl.cc b/webkit/glue/webclipboard_impl.cc
index b782cd2..eb71a61 100644
--- a/webkit/glue/webclipboard_impl.cc
+++ b/webkit/glue/webclipboard_impl.cc
@@ -235,8 +235,10 @@ void WebClipboardImpl::writeDataObject(const WebDragData& data) {
WebDropData data_object(data);
// TODO(dcheng): Properly support text/uri-list here.
- scw.WriteText(data_object.plain_text);
- scw.WriteHTML(data_object.text_html, "");
+ if (!data_object.text.is_null())
+ scw.WriteText(data_object.text.string());
+ if (!data_object.html.is_null())
+ scw.WriteHTML(data_object.html.string(), "");
// If there is no custom data, avoid calling WritePickledData. This ensures
// that ScopedClipboardWriterGlue's dtor remains a no-op if the page didn't
// modify the DataTransfer object, which is important to avoid stomping on
diff --git a/webkit/glue/webdropdata.cc b/webkit/glue/webdropdata.cc
index 73c89fa..398bc31 100644
--- a/webkit/glue/webdropdata.cc
+++ b/webkit/glue/webdropdata.cc
@@ -31,14 +31,16 @@ WebDropData::FileInfo::FileInfo(const string16& path,
}
WebDropData::WebDropData(const WebDragData& drag_data)
- : referrer_policy(WebKit::WebReferrerPolicyDefault) {
+ : referrer_policy(WebKit::WebReferrerPolicyDefault),
+ text(NullableString16(true)),
+ html(NullableString16(true)) {
const WebVector<WebDragData::Item>& item_list = drag_data.items();
for (size_t i = 0; i < item_list.size(); ++i) {
const WebDragData::Item& item = item_list[i];
switch (item.storageType) {
case WebDragData::Item::StorageTypeString: {
if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeText)) {
- plain_text = item.stringData;
+ text = NullableString16(item.stringData, false);
break;
}
if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeURIList)) {
@@ -51,7 +53,7 @@ WebDropData::WebDropData(const WebDragData& drag_data)
break;
}
if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeHTML)) {
- text_html = item.stringData;
+ html = NullableString16(item.stringData, false);
html_base_url = item.baseURL;
break;
}
@@ -73,7 +75,9 @@ WebDropData::WebDropData(const WebDragData& drag_data)
}
WebDropData::WebDropData()
- : referrer_policy(WebKit::WebReferrerPolicyDefault) {
+ : referrer_policy(WebKit::WebReferrerPolicyDefault),
+ text(NullableString16(true)),
+ html(NullableString16(true)) {
}
WebDropData::~WebDropData() {
@@ -87,15 +91,16 @@ WebDragData WebDropData::ToDragData() const {
DCHECK(file_contents.empty());
DCHECK(file_description_filename.empty());
- // TODO(dcheng): We need a way to distinguish between null and empty strings.
- if (!plain_text.empty()) {
+ if (!text.is_null()) {
WebDragData::Item item;
item.storageType = WebDragData::Item::StorageTypeString;
item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText);
- item.stringData = plain_text;
+ item.stringData = text.string();
item_list.push_back(item);
}
+ // TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it
+ // meaningful to write an empty URL to the clipboard?
if (!url.is_empty()) {
WebDragData::Item item;
item.storageType = WebDragData::Item::StorageTypeString;
@@ -105,11 +110,11 @@ WebDragData WebDropData::ToDragData() const {
item_list.push_back(item);
}
- if (!text_html.empty()) {
+ if (!html.is_null()) {
WebDragData::Item item;
item.storageType = WebDragData::Item::StorageTypeString;
item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML);
- item.stringData = text_html;
+ item.stringData = html.string();
item.baseURL = html_base_url;
item_list.push_back(item);
}
diff --git a/webkit/glue/webdropdata.h b/webkit/glue/webdropdata.h
index 0da3e07..9dd5571 100644
--- a/webkit/glue/webdropdata.h
+++ b/webkit/glue/webdropdata.h
@@ -13,6 +13,7 @@
#include <string>
#include <vector>
+#include "base/nullable_string16.h"
#include "base/string16.h"
#include "googleurl/src/gurl.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebReferrerPolicy.h"
@@ -61,12 +62,12 @@ struct WEBKIT_GLUE_EXPORT WebDropData {
string16 filesystem_id;
// User is dragging plain text into the webview.
- string16 plain_text;
+ NullableString16 text;
// User is dragging text/html into the webview (e.g., out of Firefox).
// |html_base_url| is the URL that the html fragment is taken from (used to
// resolve relative links). It's ok for |html_base_url| to be empty.
- string16 text_html;
+ NullableString16 html;
GURL html_base_url;
// User is dragging data from the webview (e.g., an image).
diff --git a/webkit/glue/webdropdata_win.cc b/webkit/glue/webdropdata_win.cc
index 049df9e..9dd8306 100644
--- a/webkit/glue/webdropdata_win.cc
+++ b/webkit/glue/webdropdata_win.cc
@@ -25,11 +25,19 @@ void WebDropData::PopulateWebDropData(IDataObject* data_object,
ui::ClipboardUtil::GetFilenames(data_object, &filenames);
for (size_t i = 0; i < filenames.size(); ++i)
drop_data->filenames.push_back(FileInfo(filenames[i], string16()));
- ui::ClipboardUtil::GetPlainText(data_object, &drop_data->plain_text);
- std::string base_url;
- ui::ClipboardUtil::GetHtml(data_object, &drop_data->text_html, &base_url);
- if (!base_url.empty()) {
- drop_data->html_base_url = GURL(base_url);
+ string16 text;
+ ui::ClipboardUtil::GetPlainText(data_object, &text);
+ if (!text.empty()) {
+ drop_data->text = NullableString16(text, false);
+ }
+ string16 html;
+ std::string html_base_url;
+ ui::ClipboardUtil::GetHtml(data_object, &html, &html_base_url);
+ if (!html.empty()) {
+ drop_data->html = NullableString16(html, false);
+ }
+ if (!html_base_url.empty()) {
+ drop_data->html_base_url = GURL(html_base_url);
}
ui::ClipboardUtil::GetWebCustomData(data_object,
&drop_data->custom_data);