62140f
From 089026b255697b45c606a7a86d96995fbaa7c8f7 Mon Sep 17 00:00:00 2001
62140f
From: Stephan Bergmann <sbergman@redhat.com>
62140f
Date: Tue, 23 Jun 2015 08:26:36 +0200
62140f
Subject: [PATCH 1/4] LinkUpdateMode is a global setting
62140f
62140f
(cherry picked from commit 77cc71476bae2b3655102e2c29d36af40a393201)
62140f
Conflicts:
62140f
	sw/source/core/doc/DocumentLinksAdministrationManager.cxx
62140f
	sw/source/filter/xml/xmlimp.cxx
62140f
62140f
Reviewed-on: https://gerrit.libreoffice.org/16422
62140f
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
62140f
Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
62140f
(cherry picked from commit 8110d0c3cd79339d1d01b8ab2b11bee72551f083)
62140f
62140f
Change-Id: Ida1257337c6e0916f2228fe053d9c9f085183af6
62140f
---
62140f
 include/unotools/securityoptions.hxx       |  2 +
62140f
 sc/source/filter/xml/xmlimprt.cxx          | 10 +++-
62140f
 sc/source/ui/docshell/docsh4.cxx           | 18 +++++--
62140f
 sw/source/core/doc/docnew.cxx              | 10 ++++
62140f
 sw/source/filter/xml/xmlimp.cxx            | 78 +++++++++++++++---------------
62140f
 unotools/source/config/securityoptions.cxx |  8 +++
62140f
 6 files changed, 84 insertions(+), 42 deletions(-)
62140f
62140f
diff --git a/include/unotools/securityoptions.hxx b/include/unotools/securityoptions.hxx
62140f
index 3bd8807..77e4720 100644
62140f
--- a/include/unotools/securityoptions.hxx
62140f
+++ b/include/unotools/securityoptions.hxx
62140f
@@ -186,6 +186,8 @@ class UNOTOOLS_DLLPUBLIC SAL_WARN_UNUSED SvtSecurityOptions : public utl::detail
62140f
         */
62140f
         bool isTrustedLocationUri(OUString const & uri) const;
62140f
 
62140f
+        bool isTrustedLocationUriForUpdatingLinks(OUString const & uri) const;
62140f
+
62140f
         ::com::sun::star::uno::Sequence< Certificate >  GetTrustedAuthors       (                                                                   ) const;
62140f
         void                                            SetTrustedAuthors       ( const ::com::sun::star::uno::Sequence< Certificate >& rAuthors    );
62140f
 
62140f
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
62140f
index a3fb7d5..bf1beeb 100644
62140f
--- a/sc/source/filter/xml/xmlimprt.cxx
62140f
+++ b/sc/source/filter/xml/xmlimprt.cxx
62140f
@@ -2630,6 +2630,9 @@ void ScXMLImport::SetConfigurationSettings(const uno::Sequence
62140f
             OUString sCTName("TrackedChangesProtectionKey");
62140f
             OUString sVBName("VBACompatibilityMode");
62140f
             OUString sSCName("ScriptConfiguration");
62140f
+            css::uno::Sequence<css::beans::PropertyValue> aFilteredProps(
62140f
+                aConfigProps.getLength());
62140f
+            sal_Int32 nFilteredPropsLen = 0;
62140f
             for (sal_Int32 i = nCount - 1; i >= 0; --i)
62140f
             {
62140f
                 if (aConfigProps[i].Name == sCTName)
62140f
@@ -2664,11 +2667,16 @@ void ScXMLImport::SetConfigurationSettings(const uno::Sequence
62140f
                             xImportInfo->setPropertyValue( aConfigProps[i].Name, aConfigProps[i].Value );
62140f
                     }
62140f
                 }
62140f
+                if (aConfigProps[i].Name != "LinkUpdateMode")
62140f
+                {
62140f
+                    aFilteredProps[nFilteredPropsLen++] = aConfigProps[i];
62140f
+                }
62140f
             }
62140f
+            aFilteredProps.realloc(nFilteredPropsLen);
62140f
             uno::Reference <uno::XInterface> xInterface = xMultiServiceFactory->createInstance("com.sun.star.comp.SpreadsheetSettings");
62140f
             uno::Reference <beans::XPropertySet> xProperties(xInterface, uno::UNO_QUERY);
62140f
             if (xProperties.is())
62140f
-                SvXMLUnitConverter::convertPropertySet(xProperties, aConfigProps);
62140f
+                SvXMLUnitConverter::convertPropertySet(xProperties, aFilteredProps);
62140f
         }
62140f
     }
62140f
 }
62140f
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx
62140f
index 13855e6..3961186 100644
62140f
--- a/sc/source/ui/docshell/docsh4.cxx
62140f
+++ b/sc/source/ui/docshell/docsh4.cxx
62140f
@@ -48,6 +48,7 @@ using namespace ::com::sun::star;
62140f
 #include <svl/PasswordHelper.hxx>
62140f
 #include <svl/documentlockfile.hxx>
62140f
 #include <svl/sharecontrolfile.hxx>
62140f
+#include <unotools/securityoptions.hxx>
62140f
 
62140f
 #include <comphelper/processfactory.hxx>
62140f
 #include "docuno.hxx"
62140f
@@ -423,12 +424,23 @@ void ScDocShell::Execute( SfxRequest& rReq )
62140f
 
62140f
                 if (nCanUpdate == com::sun::star::document::UpdateDocMode::NO_UPDATE)
62140f
                     nSet = LM_NEVER;
62140f
-                else if (nCanUpdate == com::sun::star::document::UpdateDocMode::QUIET_UPDATE &&
62140f
-                    nSet == LM_ON_DEMAND)
62140f
-                    nSet = LM_NEVER;
62140f
                 else if (nCanUpdate == com::sun::star::document::UpdateDocMode::FULL_UPDATE)
62140f
                     nSet = LM_ALWAYS;
62140f
 
62140f
+                if (nSet == LM_ALWAYS
62140f
+                    && !(SvtSecurityOptions()
62140f
+                         .isTrustedLocationUriForUpdatingLinks(
62140f
+                             GetMedium() == 0
62140f
+                             ? OUString() : GetMedium()->GetName())))
62140f
+                {
62140f
+                    nSet = LM_ON_DEMAND;
62140f
+                }
62140f
+                if (nCanUpdate == css::document::UpdateDocMode::QUIET_UPDATE
62140f
+                    && nSet == LM_ON_DEMAND)
62140f
+                {
62140f
+                    nSet = LM_NEVER;
62140f
+                }
62140f
+
62140f
                 if(nSet==LM_ON_DEMAND)
62140f
                 {
62140f
                     QueryBox aBox( GetActiveDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
62140f
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
62140f
index d42dd9f..86447aa 100644
62140f
--- a/sw/source/core/doc/docnew.cxx
62140f
+++ b/sw/source/core/doc/docnew.cxx
62140f
@@ -44,6 +44,7 @@
62140f
 #include <editeng/forbiddencharacterstable.hxx>
62140f
 #include <svl/zforlist.hxx>
62140f
 #include <unotools/lingucfg.hxx>
62140f
+#include <unotools/securityoptions.hxx>
62140f
 #include <svx/svdpage.hxx>
62140f
 #include <paratr.hxx>
62140f
 #include <fchrfmt.hxx>
62140f
@@ -889,6 +890,15 @@ void SwDoc::UpdateLinks( bool bUI )
62140f
                 case document::UpdateDocMode::QUIET_UPDATE:bAskUpdate = false; break;
62140f
                 case document::UpdateDocMode::FULL_UPDATE: bAskUpdate = true; break;
62140f
             }
62140f
+            if (nLinkMode == AUTOMATIC && !bAskUpdate)
62140f
+            {
62140f
+                SfxMedium * medium = GetDocShell()->GetMedium();
62140f
+                if (!SvtSecurityOptions().isTrustedLocationUriForUpdatingLinks(
62140f
+                        medium == 0 ? OUString() : medium->GetName()))
62140f
+                {
62140f
+                    bAskUpdate = true;
62140f
+                }
62140f
+            }
62140f
             if( bUpdate && (bUI || !bAskUpdate) )
62140f
             {
62140f
                 SfxMedium* pMedium = GetDocShell()->GetMedium();
62140f
diff --git a/sw/source/filter/xml/xmlimp.cxx b/sw/source/filter/xml/xmlimp.cxx
62140f
index b04cfbd..2636c95 100644
62140f
--- a/sw/source/filter/xml/xmlimp.cxx
62140f
+++ b/sw/source/filter/xml/xmlimp.cxx
62140f
@@ -1075,46 +1075,46 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC
62140f
     if( !xInfo.is() )
62140f
         return;
62140f
 
62140f
-    boost::unordered_set< OUString, OUStringHash > aSet;
62140f
-    aSet.insert("ForbiddenCharacters");
62140f
-    aSet.insert("IsKernAsianPunctuation");
62140f
-    aSet.insert("CharacterCompressionType");
62140f
-    aSet.insert("LinkUpdateMode");
62140f
-    aSet.insert("FieldAutoUpdate");
62140f
-    aSet.insert("ChartAutoUpdate");
62140f
-    aSet.insert("AddParaTableSpacing");
62140f
-    aSet.insert("AddParaTableSpacingAtStart");
62140f
-    aSet.insert("PrintAnnotationMode");
62140f
-    aSet.insert("PrintBlackFonts");
62140f
-    aSet.insert("PrintControls");
62140f
-    aSet.insert("PrintDrawings");
62140f
-    aSet.insert("PrintGraphics");
62140f
-    aSet.insert("PrintLeftPages");
62140f
-    aSet.insert("PrintPageBackground");
62140f
-    aSet.insert("PrintProspect");
62140f
-    aSet.insert("PrintReversed");
62140f
-    aSet.insert("PrintRightPages");
62140f
-    aSet.insert("PrintFaxName");
62140f
-    aSet.insert("PrintPaperFromSetup");
62140f
-    aSet.insert("PrintTables");
62140f
-    aSet.insert("PrintSingleJobs");
62140f
-    aSet.insert("UpdateFromTemplate");
62140f
-    aSet.insert("PrinterIndependentLayout");
62140f
-    aSet.insert("PrintEmptyPages");
62140f
-    aSet.insert("SmallCapsPercentage66");
62140f
-    aSet.insert("TabOverflow");
62140f
-    aSet.insert("UnbreakableNumberings");
62140f
-    aSet.insert("ClippedPictures");
62140f
-    aSet.insert("BackgroundParaOverDrawings");
62140f
-    aSet.insert("TabOverMargin");
62140f
-    aSet.insert("PropLineSpacingShrinksFirstLine");
62140f
+    boost::unordered_set< OUString, OUStringHash > aExcludeAlways;
62140f
+    aExcludeAlways.insert("LinkUpdateMode");
62140f
+    boost::unordered_set< OUString, OUStringHash > aExcludeWhenNotLoadingUserSettings;
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("ForbiddenCharacters");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("IsKernAsianPunctuation");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("CharacterCompressionType");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("FieldAutoUpdate");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("ChartAutoUpdate");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("AddParaTableSpacing");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("AddParaTableSpacingAtStart");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("PrintAnnotationMode");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("PrintBlackFonts");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("PrintControls");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("PrintDrawings");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("PrintGraphics");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("PrintLeftPages");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("PrintPageBackground");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("PrintProspect");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("PrintReversed");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("PrintRightPages");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("PrintFaxName");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("PrintPaperFromSetup");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("PrintTables");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("PrintSingleJobs");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("UpdateFromTemplate");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("PrinterIndependentLayout");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("PrintEmptyPages");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("SmallCapsPercentage66");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("TabOverflow");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("UnbreakableNumberings");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("ClippedPictures");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("BackgroundParaOverDrawings");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("TabOverMargin");
62140f
+    aExcludeWhenNotLoadingUserSettings.insert("PropLineSpacingShrinksFirstLine");
62140f
 
62140f
     sal_Int32 nCount = aConfigProps.getLength();
62140f
     const PropertyValue* pValues = aConfigProps.getConstArray();
62140f
 
62140f
     SvtSaveOptions aSaveOpt;
62140f
-    bool bIsUserSetting = aSaveOpt.IsLoadUserSettings(),
62140f
-         bSet = bIsUserSetting;
62140f
+    bool bIsUserSetting = aSaveOpt.IsLoadUserSettings();
62140f
 
62140f
     // for some properties we don't want to use the application
62140f
     // default if they're missing. So we watch for them in the loop
62140f
@@ -1150,10 +1150,12 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC
62140f
 
62140f
     while( nCount-- )
62140f
     {
62140f
-        if( !bIsUserSetting )
62140f
+        bool bSet = aExcludeAlways.find(pValues->Name) == aExcludeAlways.end();
62140f
+        if( bSet && !bIsUserSetting
62140f
+            && (aExcludeWhenNotLoadingUserSettings.find(pValues->Name)
62140f
+                != aExcludeWhenNotLoadingUserSettings.end()) )
62140f
         {
62140f
-            // test over the hash value if the entry is in the table.
62140f
-            bSet = aSet.find(pValues->Name) == aSet.end();
62140f
+            bSet = false;
62140f
         }
62140f
 
62140f
         if( bSet )
62140f
diff --git a/unotools/source/config/securityoptions.cxx b/unotools/source/config/securityoptions.cxx
62140f
index 7906ed7..86055c5 100644
62140f
--- a/unotools/source/config/securityoptions.cxx
62140f
+++ b/unotools/source/config/securityoptions.cxx
62140f
@@ -1051,6 +1051,14 @@ bool SvtSecurityOptions::isTrustedLocationUri(OUString const & uri) const {
62140f
     return false;
62140f
 }
62140f
 
62140f
+bool SvtSecurityOptions::isTrustedLocationUriForUpdatingLinks(
62140f
+    OUString const & uri) const
62140f
+{
62140f
+    return GetMacroSecurityLevel() == 0 || uri.isEmpty()
62140f
+        || uri.startsWithIgnoreAsciiCase("private:")
62140f
+        || isTrustedLocationUri(uri);
62140f
+}
62140f
+
62140f
 sal_Int32 SvtSecurityOptions::GetMacroSecurityLevel() const
62140f
 {
62140f
     MutexGuard aGuard( GetInitMutex() );
62140f
-- 
62140f
2.5.0
62140f