Commit 7e82b34a authored by tony@chromium.org's avatar tony@chromium.org

Whenever we set plain text on the standard clipboard, also set

the selection clipboard on Linux.

Most of the time, this happens automatically since the only way to
set the standard clipboard is to select text (which sets the selection
clipboard), but it's possible to set the standard clipboard using
javascript (event.clipboardData.setData('text/plain', ...)).

Since we always set the selection clipboard, I removed some code that
was for handling the "Copy Link Address" context menu item.

I tested on GTK+ and Aura.

BUG=168135
TEST=Right click a link, select "Copy Link Addres", middle click in a text
  field. This should paste the URL. Here's a test case for
  clipboardData.setData: http://jsfiddle.net/LNWMG/

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175387 0039d316-1c4b-4281-b951-d872f2087c98
parent 6a4d7f60
...@@ -213,16 +213,6 @@ class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { ...@@ -213,16 +213,6 @@ class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) {
// kept until the system clipboard is set again. // kept until the system clipboard is set again.
void WriteObjects(Buffer buffer, const ObjectMap& objects); void WriteObjects(Buffer buffer, const ObjectMap& objects);
// On Linux/BSD, we need to know when the clipboard is set to a URL. Most
// platforms don't care.
#if defined(OS_WIN) || defined(OS_MACOSX) \
|| (defined(USE_AURA) && defined(OS_CHROMEOS)) \
|| defined(OS_ANDROID)
void DidWriteURL(const std::string& utf8_text) {}
#else
void DidWriteURL(const std::string& utf8_text);
#endif
// Returns a sequence number which uniquely identifies clipboard state. // Returns a sequence number which uniquely identifies clipboard state.
// This can be used to version the data on the clipboard and determine // This can be used to version the data on the clipboard and determine
// whether it has changed. // whether it has changed.
......
...@@ -894,8 +894,17 @@ void Clipboard::WriteObjects(Buffer buffer, const ObjectMap& objects) { ...@@ -894,8 +894,17 @@ void Clipboard::WriteObjects(Buffer buffer, const ObjectMap& objects) {
iter != objects.end(); ++iter) { iter != objects.end(); ++iter) {
DispatchObject(static_cast<ObjectType>(iter->first), iter->second); DispatchObject(static_cast<ObjectType>(iter->first), iter->second);
} }
aurax11_details_->TakeOwnershipOfSelection(buffer); aurax11_details_->TakeOwnershipOfSelection(buffer);
if (buffer == BUFFER_STANDARD) {
ObjectMap::const_iterator text_iter = objects.find(CBF_TEXT);
if (text_iter != objects.end()) {
aurax11_details_->CreateNewClipboardData();
const ObjectMapParam& char_vector = text_iter->second[0];
WriteText(&char_vector.front(), char_vector.size());
aurax11_details_->TakeOwnershipOfSelection(BUFFER_SELECTION);
}
}
} }
bool Clipboard::IsFormatAvailable(const FormatType& format, bool Clipboard::IsFormatAvailable(const FormatType& format,
...@@ -1047,17 +1056,6 @@ void Clipboard::ReadData(const FormatType& format, std::string* result) const { ...@@ -1047,17 +1056,6 @@ void Clipboard::ReadData(const FormatType& format, std::string* result) const {
data->AssignTo(result); data->AssignTo(result);
} }
// When a URL is copied from a render view context menu (via "copy link
// location", for example), we additionally stick it in the X clipboard. This
// matches other linux browsers.
void Clipboard::DidWriteURL(const std::string& utf8_text) {
DCHECK(CalledOnValidThread());
aurax11_details_->CreateNewClipboardData();
WriteText(utf8_text.c_str(), utf8_text.size());
aurax11_details_->TakeOwnershipOfSelection(BUFFER_SELECTION);
}
uint64 Clipboard::GetSequenceNumber(Buffer buffer) { uint64 Clipboard::GetSequenceNumber(Buffer buffer) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
if (buffer == BUFFER_STANDARD) if (buffer == BUFFER_STANDARD)
......
...@@ -229,15 +229,6 @@ void Clipboard::WriteObjects(Buffer buffer, const ObjectMap& objects) { ...@@ -229,15 +229,6 @@ void Clipboard::WriteObjects(Buffer buffer, const ObjectMap& objects) {
SetGtkClipboard(buffer); SetGtkClipboard(buffer);
} }
// When a URL is copied from a render view context menu (via "copy link
// location", for example), we additionally stick it in the X clipboard. This
// matches other linux browsers.
void Clipboard::DidWriteURL(const std::string& utf8_text) {
DCHECK(CalledOnValidThread());
gtk_clipboard_set_text(primary_selection_, utf8_text.c_str(),
utf8_text.length());
}
// Take ownership of the GTK clipboard and inform it of the targets we support. // Take ownership of the GTK clipboard and inform it of the targets we support.
void Clipboard::SetGtkClipboard(Buffer buffer) { void Clipboard::SetGtkClipboard(Buffer buffer) {
scoped_array<GtkTargetEntry> targets( scoped_array<GtkTargetEntry> targets(
...@@ -262,6 +253,14 @@ void Clipboard::SetGtkClipboard(Buffer buffer) { ...@@ -262,6 +253,14 @@ void Clipboard::SetGtkClipboard(Buffer buffer) {
clipboard_data_->size()); clipboard_data_->size());
} }
if (buffer == BUFFER_STANDARD) {
Clipboard::TargetMap::iterator text_iter = clipboard_data_->find("TEXT");
if (text_iter != clipboard_data_->end()) {
gtk_clipboard_set_text(primary_selection_, text_iter->second.first,
text_iter->second.second);
}
}
// clipboard_data_ now owned by the GtkClipboard. // clipboard_data_ now owned by the GtkClipboard.
clipboard_data_ = NULL; clipboard_data_ = NULL;
} }
......
...@@ -21,11 +21,8 @@ ScopedClipboardWriter::ScopedClipboardWriter(Clipboard* clipboard, ...@@ -21,11 +21,8 @@ ScopedClipboardWriter::ScopedClipboardWriter(Clipboard* clipboard,
} }
ScopedClipboardWriter::~ScopedClipboardWriter() { ScopedClipboardWriter::~ScopedClipboardWriter() {
if (!objects_.empty() && clipboard_) { if (!objects_.empty() && clipboard_)
clipboard_->WriteObjects(buffer_, objects_); clipboard_->WriteObjects(buffer_, objects_);
if (buffer_ == Clipboard::BUFFER_STANDARD && url_text_.length())
clipboard_->DidWriteURL(url_text_);
}
} }
void ScopedClipboardWriter::WriteText(const string16& text) { void ScopedClipboardWriter::WriteText(const string16& text) {
......
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