Prevented open clipboard twice #4815

This commit is contained in:
Jerry 2015-07-06 13:00:28 -07:00
parent 6e74655e78
commit 23739f8484
2 changed files with 51 additions and 46 deletions

View File

@ -314,7 +314,10 @@ XWindowsClipboard::add(EFormat format, const String& data)
bool bool
XWindowsClipboard::open(Time time) const XWindowsClipboard::open(Time time) const
{ {
assert(!m_open); if (m_open) {
return false;
LOG((CLOG_DEBUG "failed to open clipboard: already opened"));
}
LOG((CLOG_DEBUG "open clipboard %d", m_id)); LOG((CLOG_DEBUG "open clipboard %d", m_id));

View File

@ -30,36 +30,37 @@ IClipboard::unmarshall(IClipboard* clipboard, const String& data, Time time)
const char* index = data.data(); const char* index = data.data();
// clear existing data if (clipboard->open(time)) {
clipboard->open(time); // clear existing data
clipboard->empty(); clipboard->empty();
// read the number of formats // read the number of formats
const UInt32 numFormats = readUInt32(index); const UInt32 numFormats = readUInt32(index);
index += 4;
// read each format
for (UInt32 i = 0; i < numFormats; ++i) {
// get the format id
IClipboard::EFormat format =
static_cast<IClipboard::EFormat>(readUInt32(index));
index += 4; index += 4;
// get the size of the format data // read each format
UInt32 size = readUInt32(index); for (UInt32 i = 0; i < numFormats; ++i) {
index += 4; // get the format id
IClipboard::EFormat format =
static_cast<IClipboard::EFormat>(readUInt32(index));
index += 4;
// save the data if it's a known format. if either the client // get the size of the format data
// or server supports more clipboard formats than the other UInt32 size = readUInt32(index);
// then one of them will get a format >= kNumFormats here. index += 4;
if (format <IClipboard::kNumFormats) {
clipboard->add(format, String(index, size)); // save the data if it's a known format. if either the client
// or server supports more clipboard formats than the other
// then one of them will get a format >= kNumFormats here.
if (format <IClipboard::kNumFormats) {
clipboard->add(format, String(index, size));
}
index += size;
} }
index += size;
}
// done // done
clipboard->close(); clipboard->close();
}
} }
String String
@ -72,33 +73,34 @@ IClipboard::marshall(const IClipboard* clipboard)
std::vector<String> formatData; std::vector<String> formatData;
formatData.resize(IClipboard::kNumFormats); formatData.resize(IClipboard::kNumFormats);
// FIXME -- use current time // FIXME -- use current time
clipboard->open(0); if (clipboard->open(0)) {
// compute size of marshalled data // compute size of marshalled data
UInt32 size = 4; UInt32 size = 4;
UInt32 numFormats = 0; UInt32 numFormats = 0;
for (UInt32 format = 0; format != IClipboard::kNumFormats; ++format) { for (UInt32 format = 0; format != IClipboard::kNumFormats; ++format) {
if (clipboard->has(static_cast<IClipboard::EFormat>(format))) { if (clipboard->has(static_cast<IClipboard::EFormat>(format))) {
++numFormats; ++numFormats;
formatData[format] = formatData[format] =
clipboard->get(static_cast<IClipboard::EFormat>(format)); clipboard->get(static_cast<IClipboard::EFormat>(format));
size += 4 + 4 + (UInt32)formatData[format].size(); size += 4 + 4 + (UInt32)formatData[format].size();
}
} }
}
// allocate space // allocate space
data.reserve(size); data.reserve(size);
// marshall the data // marshall the data
writeUInt32(&data, numFormats); writeUInt32(&data, numFormats);
for (UInt32 format = 0; format != IClipboard::kNumFormats; ++format) { for (UInt32 format = 0; format != IClipboard::kNumFormats; ++format) {
if (clipboard->has(static_cast<IClipboard::EFormat>(format))) { if (clipboard->has(static_cast<IClipboard::EFormat>(format))) {
writeUInt32(&data, format); writeUInt32(&data, format);
writeUInt32(&data, (UInt32)formatData[format].size()); writeUInt32(&data, (UInt32)formatData[format].size());
data += formatData[format]; data += formatData[format];
}
} }
clipboard->close();
} }
clipboard->close();
return data; return data;
} }