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

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