From 18c49bbbce655d805447b95fc92733551eb6af51 Mon Sep 17 00:00:00 2001
From: Miklos Vajna <vmiklos@collabora.co.uk>
Date: Mon, 26 Oct 2015 11:28:55 +0100
Subject: [PATCH 230/398] lok::Document::paste: check if the given mime type is
supported
Change-Id: Ib59ea43700815c53cdd4be819e2e9cf35c6f89e9
(cherry picked from commit 7efbbe98d7fe951909234dcacd37f67975f00da2)
---
desktop/qa/desktop_lib/test_desktop_lib.cxx | 5 ++++-
desktop/source/lib/init.cxx | 7 +++++++
include/vcl/ITiledRenderable.hxx | 5 +++++
sw/inc/unotxdoc.hxx | 2 ++
sw/source/uibase/uno/unotxdoc.cxx | 10 ++++++++++
5 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 5816c032a7a5..12831318dde3 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -331,12 +331,15 @@ void DesktopLOKTest::testPasteWriter()
LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
OString aText("hello");
- pDocument->pClass->paste(pDocument, "text/plain;charset=utf-8", aText.getStr(), aText.getLength());
+ CPPUNIT_ASSERT(pDocument->pClass->paste(pDocument, "text/plain;charset=utf-8", aText.getStr(), aText.getLength()));
pDocument->pClass->postUnoCommand(pDocument, ".uno:SelectAll", 0);
char* pText = pDocument->pClass->getTextSelection(pDocument, "text/plain;charset=utf-8", 0);
CPPUNIT_ASSERT_EQUAL(OString("hello"), OString(pText));
free(pText);
+
+ CPPUNIT_ASSERT(!pDocument->pClass->paste(pDocument, "textt/plain;charset=utf-8", aText.getStr(), aText.getLength()));
+
comphelper::LibreOfficeKit::setActive(false);
}
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 0459176c24a0..75df1528fd51 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1016,6 +1016,13 @@ static bool doc_paste(LibreOfficeKitDocument* pThis, const char* pMimeType, cons
}
pWindow->SetClipboard(xClipboard);
+ if (!pDoc->isMimeTypeSupported())
+ {
+ if (gImpl)
+ gImpl->maLastExceptionMsg = "Document doesn't support this mime type";
+ return false;
+ }
+
OUString aCommand(".uno:Paste");
uno::Sequence<beans::PropertyValue> aPropertyValues;
if (!comphelper::dispatchCommand(aCommand, aPropertyValues))
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index 5b3d4681088a..3301b7754f15 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -150,6 +150,11 @@ public:
/// Returns the current vcl::Window of the component.
virtual vcl::Window* getWindow() = 0;
+
+ virtual bool isMimeTypeSupported()
+ {
+ return false;
+ }
};
} // namespace vcl
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index d0eada25b6ef..180ceb891b89 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -436,6 +436,8 @@ public:
virtual OUString getPartPageRectangles() override;
/// @see vcl::ITiledRenderable::getWindow().
virtual vcl::Window* getWindow() override;
+ /// @see vcl::ITiledRenderable::isMimeTypeSupported().
+ virtual bool isMimeTypeSupported() override;
// ::com::sun::star::tiledrendering::XTiledRenderable
virtual void SAL_CALL paintTile( const ::css::uno::Any& Parent, ::sal_Int32 nOutputWidth, ::sal_Int32 nOutputHeight, ::sal_Int32 nTilePosX, ::sal_Int32 nTilePosY, ::sal_Int32 nTileWidth, ::sal_Int32 nTileHeight ) throw (::css::uno::RuntimeException, ::std::exception) SAL_OVERRIDE;
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 658057d7a977..618e6b373162 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3195,6 +3195,16 @@ vcl::Window* SwXTextDocument::getWindow()
return &pDocShell->GetView()->GetEditWin();
}
+bool SwXTextDocument::isMimeTypeSupported()
+{
+ SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+ if (!pWrtShell)
+ return false;
+
+ TransferableDataHelper aDataHelper(TransferableDataHelper::CreateFromSystemClipboard(&pWrtShell->GetView().GetEditWin()));
+ return aDataHelper.GetXTransferable().is() && SwTransferable::IsPaste(*pWrtShell, aDataHelper);
+}
+
int SwXTextDocument::getPart()
{
SolarMutexGuard aGuard;
--
2.12.0