Blob Blame History Raw
From 9ba9d810d9e17a7e3a3e0885235924f4c480c3b0 Mon Sep 17 00:00:00 2001
From: Kohei Yoshida <kohei.yoshida@collabora.com>
Date: Fri, 11 Jul 2014 10:50:29 -0400
Subject: [PATCH 043/137] bnc#883684: Better fix for this.

Instead of making all chart objects exempt from unloading, check each OLE
object on whether or not it already has its persistent storage created.
If not, don't unload it else it would have nothing to load back from once
unloaded.

(cherry picked from commit a0bd5587a5ac62974bdb10731d3fd21584521a72)

Conflicts:
	svx/source/svdraw/svdetc.cxx
	embeddedobj/source/commonembedding/miscobj.cxx
	embeddedobj/source/commonembedding/persistence.cxx
	include/svx/svdoole2.hxx
	svx/source/svdraw/svdoole2.cxx

Change-Id: I2312e86c9376d3699ef4aa1e0cf2f4c04f706c1e
---
 embeddedobj/source/commonembedding/miscobj.cxx     |  8 +++++-
 embeddedobj/source/commonembedding/persistence.cxx | 10 +++++++-
 embeddedobj/source/inc/commonembobj.hxx            |  8 ++++--
 include/svx/svdoole2.hxx                           |  7 -----
 offapi/UnoApi_offapi.mk                            |  1 +
 offapi/com/sun/star/embed/XEmbedPersist2.idl       | 30 ++++++++++++++++++++++
 svx/source/svdraw/svdetc.cxx                       |  4 ---
 svx/source/svdraw/svdoole2.cxx                     | 16 +++++++-----
 8 files changed, 62 insertions(+), 22 deletions(-)
 create mode 100644 offapi/com/sun/star/embed/XEmbedPersist2.idl

diff --git a/embeddedobj/source/commonembedding/miscobj.cxx b/embeddedobj/source/commonembedding/miscobj.cxx
index 70b8696..8ce2f84 100644
--- a/embeddedobj/source/commonembedding/miscobj.cxx
+++ b/embeddedobj/source/commonembedding/miscobj.cxx
@@ -363,6 +363,11 @@ uno::Any SAL_CALL OCommonEmbeddedObject::queryInterface( const uno::Type& rType
         void * p = static_cast< embed::XEmbeddedObject * >( this );
         return uno::Any( &p, rType );
     }
+    else if (rType == ::getCppuType( (uno::Reference<embed::XEmbedPersist2> const *)0 ))
+    {
+        void* p = static_cast<embed::XEmbedPersist2*>(this);
+        return uno::Any(&p, rType);
+    }
     else
         aReturn <<= ::cppu::queryInterface(
                     rType,
@@ -431,7 +436,8 @@ uno::Sequence< uno::Type > SAL_CALL OCommonEmbeddedObject::getTypes()
                                             ::getCppuType( (const uno::Reference< embed::XInplaceObject >*)NULL ),
                                             ::getCppuType( (const uno::Reference< embed::XCommonEmbedPersist >*)NULL ),
                                             ::getCppuType( (const uno::Reference< container::XChild >*)NULL ),
-                                            ::getCppuType( (const uno::Reference< embed::XEmbedPersist >*)NULL ) );
+                                            ::getCppuType( (const uno::Reference< embed::XEmbedPersist >*)NULL ),
+                                            ::getCppuType( (const uno::Reference< embed::XEmbedPersist2 >*)NULL ) );
 
                 pTypeCollection = &aTypeCollection ;
             }
diff --git a/embeddedobj/source/commonembedding/persistence.cxx b/embeddedobj/source/commonembedding/persistence.cxx
index 4891656..44b4e30 100644
--- a/embeddedobj/source/commonembedding/persistence.cxx
+++ b/embeddedobj/source/commonembedding/persistence.cxx
@@ -1799,7 +1799,15 @@ void SAL_CALL OCommonEmbeddedObject::reload(
     }
 }
 
-//------------------------------------------------------
+sal_Bool SAL_CALL OCommonEmbeddedObject::isStored() throw (css::uno::RuntimeException, std::exception)
+{
+    uno::Reference<container::XNameAccess> xNA(m_xObjectStorage, uno::UNO_QUERY);
+    if (!xNA.is())
+        return false;
+
+    return xNA->getElementNames().getLength() > 0;
+}
+
 void SAL_CALL OCommonEmbeddedObject::breakLink( const uno::Reference< embed::XStorage >& xStorage,
                                                 const OUString& sEntName )
         throw ( lang::IllegalArgumentException,
diff --git a/embeddedobj/source/inc/commonembobj.hxx b/embeddedobj/source/inc/commonembobj.hxx
index 83e4445..4c23325 100644
--- a/embeddedobj/source/inc/commonembobj.hxx
+++ b/embeddedobj/source/inc/commonembobj.hxx
@@ -27,7 +27,7 @@
 #include <com/sun/star/document/XStorageBasedDocument.hpp>
 #include <com/sun/star/embed/XEmbeddedObject.hpp>
 #include <com/sun/star/embed/XVisualObject.hpp>
-#include <com/sun/star/embed/XEmbedPersist.hpp>
+#include <com/sun/star/embed/XEmbedPersist2.hpp>
 #include <com/sun/star/embed/XLinkageSupport.hpp>
 #include <com/sun/star/embed/XClassifiedObject.hpp>
 #include <com/sun/star/embed/XComponentSupplier.hpp>
@@ -72,7 +72,7 @@ namespace comphelper {
 class Interceptor;
 
 class OCommonEmbeddedObject : public ::com::sun::star::embed::XEmbeddedObject
-                            , public ::com::sun::star::embed::XEmbedPersist
+                            , public ::com::sun::star::embed::XEmbedPersist2
                             , public ::com::sun::star::embed::XLinkageSupport
                             , public ::com::sun::star::embed::XInplaceObject
                             , public ::com::sun::star::container::XChild
@@ -431,6 +431,10 @@ public:
                 ::com::sun::star::uno::Exception,
                 ::com::sun::star::uno::RuntimeException );
 
+// XEmbedPersist2
+
+    virtual sal_Bool SAL_CALL isStored()
+        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
 
 // XInplaceObject
 
diff --git a/include/svx/svdoole2.hxx b/include/svx/svdoole2.hxx
index 149dc61..c2cad4b 100644
--- a/include/svx/svdoole2.hxx
+++ b/include/svx/svdoole2.hxx
@@ -170,13 +170,6 @@ public:
     sal_Bool IsChart() const;
     sal_Bool IsCalc() const;
 
-    /**
-     * Unloadable OLE objects are subject to automatic unloading per memory
-     * setting.  The "Number of objects" setting in the Memory option controls
-     * how many OLE objects can be loaded at any given moment.
-     */
-    bool IsUnloadable() const;
-
     sal_Bool UpdateLinkURL_Impl();
     void BreakFileLink_Impl();
     void DisconnectFileLink_Impl();
diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
index 3c1d92e..22d84d2 100755
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -2411,6 +2411,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/embed,\
     XEmbeddedObjectCreator \
 	XEmbedObjectFactory \
 	XEmbedPersist \
+	XEmbedPersist2 \
 	XEmbeddedClient \
 	XEmbeddedObject \
 	XEncryptionProtectedSource \
diff --git a/offapi/com/sun/star/embed/XEmbedPersist2.idl b/offapi/com/sun/star/embed/XEmbedPersist2.idl
new file mode 100644
index 0000000..205b902
--- /dev/null
+++ b/offapi/com/sun/star/embed/XEmbedPersist2.idl
@@ -0,0 +1,30 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef __com_sun_star_XEmbedPersist2_idl__
+#define __com_sun_star_XEmbedPersist2_idl__
+
+#include <com/sun/star/embed/XEmbedPersist.idl>
+
+module com {  module sun {  module star { module embed {
+
+interface XEmbedPersist2 : XEmbedPersist
+{
+    /**
+     * Checks whether or not the object has created its persistent
+     * representation counterpart of its in-memory model.
+     */
+    boolean isStored();
+};
+
+}; }; }; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/svdraw/svdetc.cxx b/svx/source/svdraw/svdetc.cxx
index afcc792..4caca94 100644
--- a/svx/source/svdraw/svdetc.cxx
+++ b/svx/source/svdraw/svdetc.cxx
@@ -165,10 +165,6 @@ void OLEObjCache::UnloadOnDemand()
 
 void OLEObjCache::InsertObj(SdrOle2Obj* pObj)
 {
-    if (!pObj->IsUnloadable())
-        // This OLE object is exempt from automatic unloading.
-        return;
-
     if ( !empty() )
     {
         SdrOle2Obj* pExistingObj = front();
diff --git a/svx/source/svdraw/svdoole2.cxx b/svx/source/svdraw/svdoole2.cxx
index f68f5d7..f1f27a83 100644
--- a/svx/source/svdraw/svdoole2.cxx
+++ b/svx/source/svdraw/svdoole2.cxx
@@ -25,6 +25,7 @@
 #include <com/sun/star/embed/ElementModes.hpp>
 #include <com/sun/star/embed/EmbedMisc.hpp>
 #include <com/sun/star/embed/Aspects.hpp>
+#include <com/sun/star/embed/XEmbedPersist2.hpp>
 #include <com/sun/star/embed/XInplaceClient.hpp>
 #include <com/sun/star/embed/XInplaceObject.hpp>
 #include <com/sun/star/embed/XLinkageSupport.hpp>
@@ -1926,6 +1927,14 @@ void SdrOle2Obj::NbcMove(const Size& rSize)
 
 sal_Bool SdrOle2Obj::CanUnloadRunningObj( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
 {
+    uno::Reference<embed::XEmbedPersist2> xPersist(xObj, uno::UNO_QUERY);
+    if (xPersist.is())
+    {
+        if (!xPersist->isStored())
+            // It doesn't have persistent storage.  We can't unload this.
+            return false;
+    }
+
     sal_Bool bResult = sal_False;
 
     sal_Int32 nState = xObj->getCurrentState();
@@ -2159,13 +2168,6 @@ sal_Bool SdrOle2Obj::IsCalc() const
     return sal_False;
 }
 
-bool SdrOle2Obj::IsUnloadable() const
-{
-    // Right now, chart OLE objects are the only ones exempt from automatic
-    // unloading.
-    return !IsChart();
-}
-
 uno::Reference< frame::XModel > SdrOle2Obj::GetParentXModel() const
 {
     uno::Reference< frame::XModel > xDoc;
-- 
1.9.3