diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-09-06 11:40:41 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-09-06 12:57:21 +0200 |
commit | ecb537e8233c8847d14f36ec3bf698711d6d151a (patch) | |
tree | f9cb367d6e66067970102ed1864f7280f3750ccc /src/core/web_contents_adapter.cpp | |
parent | 9b449045fbd5fd3b58bcaff6cf0c5878cd6e64eb (diff) | |
parent | ad55613c2648edb67353c3882d1956b54fc323b4 (diff) |
Merge branch '5.9' into 5.10
Change-Id: I9fe9946ba47f9ef509a861963c83e275a25fffd0
Diffstat (limited to 'src/core/web_contents_adapter.cpp')
-rw-r--r-- | src/core/web_contents_adapter.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index c9b46b38a..e350aadde 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -92,6 +92,7 @@ #include <QVariant> #include <QtCore/qelapsedtimer.h> #include <QtCore/qmimedata.h> +#include <QtCore/qtemporarydir.h> #include <QtGui/qaccessible.h> #include <QtGui/qdrag.h> #include <QtGui/qpixmap.h> @@ -1203,7 +1204,11 @@ void WebContentsAdapter::startDragging(QObject *dragSource, const content::DropD QDrag::cancel(); }); - drag->setMimeData(mimeDataFromDropData(*d->currentDropData)); + QMimeData *mimeData = mimeDataFromDropData(*d->currentDropData); + if (handleDropDataFileContents(dropData, mimeData)) + allowedActions = Qt::MoveAction; + + drag->setMimeData(mimeData); if (!pixmap.isNull()) { drag->setPixmap(pixmap); drag->setHotSpot(offset); @@ -1229,6 +1234,36 @@ void WebContentsAdapter::startDragging(QObject *dragSource, const content::DropD } } +bool WebContentsAdapter::handleDropDataFileContents(const content::DropData &dropData, + QMimeData *mimeData) +{ + if (dropData.file_contents.empty()) + return false; + + Q_D(WebContentsAdapter); + if (!d->dndTmpDir) { + d->dndTmpDir.reset(new QTemporaryDir); + if (!d->dndTmpDir->isValid()) { + d->dndTmpDir.reset(); + return false; + } + } + + const auto maybeFilename = dropData.GetSafeFilenameForImageFileContents(); + const QString fileName = maybeFilename ? toQt(maybeFilename->AsUTF16Unsafe()) : QString(); + const QString &filePath = d->dndTmpDir->filePath(fileName); + QFile file(filePath); + if (!file.open(QIODevice::WriteOnly)) { + qWarning("Cannot write temporary file %s.", qUtf8Printable(filePath)); + return false; + } + file.write(QByteArray::fromStdString(dropData.file_contents)); + + const QUrl &targetUrl = QUrl::fromLocalFile(filePath); + mimeData->setUrls(QList<QUrl>{targetUrl}); + return true; +} + static void fillDropDataFromMimeData(content::DropData *dropData, const QMimeData *mimeData) { Q_ASSERT(dropData->filenames.empty()); |