Commit aa3d8acf authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Add workaround for pasting URL-based images from Chrome

Chrome seems to have a bug. When the user clicks "Copy image",
it adds 'UniformResourceLocatorW' mime data, which contains both,
image description and the URL separated by a newline. That looks
like a bug, though I'm not sure, because Microsoft doesn't specify
the format of this field in its document.

Firefox doesn't have this bug, because it uses CF_HDROP instead.

BUG:438426
parent a31842e0
From 65cc3d26086c8cdbb37931997d4591083f8c724e Mon Sep 17 00:00:00 2001
From: Dmitry Kazakov <dimula73@gmail.com>
Date: Wed, 21 Jul 2021 15:16:56 +0300
Subject: [PATCH] Add workaround for pasting URL-based images from Chrome
Chrome seems to have a bug. When the user clicks "Copy image",
it adds 'UniformResourceLocatorW' mime data, which contains both,
image description and the URL separated by a newline. That looks
like a bug, though I'm not sure, because Microsoft doesn't specify
the format of this field in its document.
Firefox doesn't have this bug, because it uses CF_HDROP instead.
Change-Id: I43ff0f676198d9d0244db3213988fd686880b2d1
---
.../platforms/windows/qwindowsmime.cpp | 37 ++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/src/plugins/platforms/windows/qwindowsmime.cpp b/src/plugins/platforms/windows/qwindowsmime.cpp
index e2ae95d577..f3713852eb 100644
--- a/src/plugins/platforms/windows/qwindowsmime.cpp
+++ b/src/plugins/platforms/windows/qwindowsmime.cpp
@@ -876,9 +876,44 @@ QVariant QWindowsMimeURI::convertToMime(const QString &mimeType, LPDATAOBJECT pD
return urls;
} else if (canGetData(CF_INETURL_W, pDataObj)) {
QByteArray data = getData(CF_INETURL_W, pDataObj);
+
if (data.isEmpty())
return QVariant();
- return QUrl(QString::fromWCharArray(reinterpret_cast<const wchar_t *>(data.constData())));
+
+ const QString dataAsString = QString::fromWCharArray(reinterpret_cast<const wchar_t *>(data.constData()));
+
+ /**
+ * Chrome has a bug, it places the URL alongside its description.
+ * The two strings are separated by a newline.
+ */
+ if (dataAsString.contains(QLatin1String("\n"))) {
+ const QStringList list = dataAsString.split(QLatin1String("\n"));
+
+ if (list.size() > 1) {
+ QList<QVariant> urls;
+
+ for (const QString &urlString : list) {
+ const QUrl url(urlString);
+
+ if (!url.isValid()) continue;
+ urls += url;
+ }
+
+ if (list.size() == 2 && !urls.isEmpty() &&
+ !list.first().startsWith(QLatin1String("http")) &&
+ list.last().startsWith(QLatin1String("http"))) {
+
+ return urls.last();
+
+ } else if (urls.size() > 1) {
+ return urls;
+ } else if (urls.size() == 1) {
+ return urls.first();
+ }
+ }
+ }
+
+ return QUrl(dataAsString);
} else if (canGetData(CF_INETURL, pDataObj)) {
QByteArray data = getData(CF_INETURL, pDataObj);
if (data.isEmpty())
--
2.20.1.windows.1
......@@ -124,6 +124,7 @@ if (WIN32)
COMMAND ${PATCH_COMMAND} -p1 -d qttools -i ${CMAKE_CURRENT_SOURCE_DIR}/0117-windeployqt-Warn-only-in-case-patching-of-Qt5Core-fails.patch
COMMAND ${PATCH_COMMAND} -p1 -d qttools -i ${CMAKE_CURRENT_SOURCE_DIR}/0118-Don-t-patch-QtCore-when--feature-relocatable-is-enabled.patch
COMMAND ${PATCH_COMMAND} -p1 -d qtbase -i ${CMAKE_CURRENT_SOURCE_DIR}/0119-Fix-relocated-Qt-to-be-found-when-its-path-has-non-A.patch
COMMAND ${PATCH_COMMAND} -p1 -d qtbase -i ${CMAKE_CURRENT_SOURCE_DIR}/0120-Add-workaround-for-pasting-URL-based-images-from-Chr.patch
COMMAND ${PATCH_COMMAND} -p1 -d qtbase -i ${CMAKE_CURRENT_SOURCE_DIR}/windows_frac_dpi/0001-Compute-logical-DPI-on-a-per-screen-basis.patch
COMMAND ${PATCH_COMMAND} -p1 -d qtbase -i ${CMAKE_CURRENT_SOURCE_DIR}/windows_frac_dpi/0002-Update-Dpi-and-scale-factor-computation.patch
COMMAND ${PATCH_COMMAND} -p1 -d qtbase -i ${CMAKE_CURRENT_SOURCE_DIR}/windows_frac_dpi/0003-Move-QT_FONT_DPI-to-cross-platform-code.patch
......
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