Blame SOURCES/0230-lok-Document-paste-check-if-the-given-mime-type-is-s.patch

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