summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2016-12-05 10:48:24 +0100
committerJani Heikkinen <jani.heikkinen@qt.io>2016-12-07 13:17:39 +0000
commit4cb300d4d3042e9357a1b99c8f18342e4f4b38e5 (patch)
treef46c5103cd655dfb71d1f6cc0d2cab325812fa11
parenta3cb920296dcf8847f23ea743f61071fa2866814 (diff)
Avoiding accessing null QMimeData from missing clipboards
Not every Linux QPA has the selection clipboard, and will return a null QMimeData when one is requested for Selection. Task-number: QTBUG-57425 Change-Id: Ib63a0c3589df299ce4a2a5e30cbe6efb0727b5f1 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
-rw-r--r--src/core/clipboard_qt.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/core/clipboard_qt.cpp b/src/core/clipboard_qt.cpp
index 712ff570..3f4b2eb1 100644
--- a/src/core/clipboard_qt.cpp
+++ b/src/core/clipboard_qt.cpp
@@ -275,7 +275,7 @@ void ClipboardQt::WriteData(const FormatType& format, const char* data_data, siz
bool ClipboardQt::IsFormatAvailable(const ui::Clipboard::FormatType& format, ui::ClipboardType type) const
{
const QMimeData *mimeData = QGuiApplication::clipboard()->mimeData(type == ui::CLIPBOARD_TYPE_COPY_PASTE ? QClipboard::Clipboard : QClipboard::Selection);
- return mimeData->hasFormat(QString::fromStdString(format.ToString()));
+ return mimeData && mimeData->hasFormat(QString::fromStdString(format.ToString()));
}
void ClipboardQt::Clear(ui::ClipboardType type)
@@ -292,6 +292,8 @@ void ClipboardQt::ReadAvailableTypes(ui::ClipboardType type, std::vector<base::s
types->clear();
const QMimeData *mimeData = QGuiApplication::clipboard()->mimeData(type == ui::CLIPBOARD_TYPE_COPY_PASTE ? QClipboard::Clipboard : QClipboard::Selection);
+ if (!mimeData)
+ return;
if (mimeData->hasImage())
types->push_back(toString16(QStringLiteral("image/png")));
Q_FOREACH (const QString &mimeType, mimeData->formats())
@@ -306,13 +308,15 @@ void ClipboardQt::ReadAvailableTypes(ui::ClipboardType type, std::vector<base::s
void ClipboardQt::ReadText(ui::ClipboardType type, base::string16* result) const
{
const QMimeData *mimeData = QGuiApplication::clipboard()->mimeData(type == ui::CLIPBOARD_TYPE_COPY_PASTE ? QClipboard::Clipboard : QClipboard::Selection);
- *result = toString16(mimeData->text());
+ if (mimeData)
+ *result = toString16(mimeData->text());
}
void ClipboardQt::ReadAsciiText(ui::ClipboardType type, std::string* result) const
{
const QMimeData *mimeData = QGuiApplication::clipboard()->mimeData(type == ui::CLIPBOARD_TYPE_COPY_PASTE ? QClipboard::Clipboard : QClipboard::Selection);
- *result = mimeData->text().toStdString();
+ if (mimeData)
+ *result = mimeData->text().toStdString();
}
void ClipboardQt::ReadHTML(ui::ClipboardType type, base::string16* markup, std::string* src_url, uint32_t* fragment_start, uint32_t* fragment_end) const
@@ -324,6 +328,8 @@ void ClipboardQt::ReadHTML(ui::ClipboardType type, base::string16* markup, std::
*fragment_end = 0;
const QMimeData *mimeData = QGuiApplication::clipboard()->mimeData(type == ui::CLIPBOARD_TYPE_COPY_PASTE ? QClipboard::Clipboard : QClipboard::Selection);
+ if (!mimeData)
+ return;
*markup = toString16(mimeData->html());
*fragment_end = static_cast<uint32_t>(markup->length());
}
@@ -331,6 +337,8 @@ void ClipboardQt::ReadHTML(ui::ClipboardType type, base::string16* markup, std::
void ClipboardQt::ReadRTF(ui::ClipboardType type, std::string* result) const
{
const QMimeData *mimeData = QGuiApplication::clipboard()->mimeData(type == ui::CLIPBOARD_TYPE_COPY_PASTE ? QClipboard::Clipboard : QClipboard::Selection);
+ if (!mimeData)
+ return;
const QByteArray byteArray = mimeData->data(QString::fromLatin1(kMimeTypeRTF));
*result = std::string(byteArray.constData(), byteArray.length());
}
@@ -338,6 +346,8 @@ void ClipboardQt::ReadRTF(ui::ClipboardType type, std::string* result) const
SkBitmap ClipboardQt::ReadImage(ui::ClipboardType type) const
{
const QMimeData *mimeData = QGuiApplication::clipboard()->mimeData(type == ui::CLIPBOARD_TYPE_COPY_PASTE ? QClipboard::Clipboard : QClipboard::Selection);
+ if (!mimeData)
+ return SkBitmap();
QImage image = qvariant_cast<QImage>(mimeData->imageData());
image = image.convertToFormat(QImage::Format_ARGB32);
@@ -354,6 +364,8 @@ SkBitmap ClipboardQt::ReadImage(ui::ClipboardType type) const
void ClipboardQt::ReadCustomData(ui::ClipboardType clipboard_type, const base::string16& type, base::string16* result) const
{
const QMimeData *mimeData = QGuiApplication::clipboard()->mimeData(clipboard_type == ui::CLIPBOARD_TYPE_COPY_PASTE ? QClipboard::Clipboard : QClipboard::Selection);
+ if (!mimeData)
+ return;
const QByteArray customData = mimeData->data(QString::fromLatin1(kMimeTypeWebCustomDataCopy));
ui::ReadCustomDataForType(customData.constData(), customData.size(), type, result);
}
@@ -366,6 +378,8 @@ void ClipboardQt::ReadBookmark(base::string16* title, std::string* url) const
void ClipboardQt::ReadData(const FormatType& format, std::string* result) const
{
const QMimeData *mimeData = QGuiApplication::clipboard()->mimeData();
+ if (!mimeData)
+ return;
const QByteArray byteArray = mimeData->data(QString::fromStdString(format.ToString()));
*result = std::string(byteArray.constData(), byteArray.length());
}