LCOV - code coverage report
Current view: top level - include/sfx2 - docmacromode.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 3 0.0 %
Date: 2014-04-14 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_SFX2_DOCMACROMODE_HXX
      21             : #define INCLUDED_SFX2_DOCMACROMODE_HXX
      22             : 
      23             : #include <sfx2/dllapi.h>
      24             : 
      25             : #include <com/sun/star/task/XInteractionHandler.hpp>
      26             : #include <com/sun/star/embed/XStorage.hpp>
      27             : #include <com/sun/star/script/XLibraryContainer.hpp>
      28             : #include <com/sun/star/document/XEmbeddedScripts.hpp>
      29             : 
      30             : #include <boost/shared_ptr.hpp>
      31             : 
      32             : 
      33             : namespace sfx2
      34             : {
      35             : 
      36             : 
      37             : 
      38             :     //= IMacroDocumentAccess
      39             : 
      40             :     /** provides access to several settings of a document, which are needed by ->DocumentMacroMode
      41             :         to properly determine the current macro execution mode of this document
      42             :     */
      43           0 :     class SAL_NO_VTABLE IMacroDocumentAccess
      44             :     {
      45             :     public:
      46             :         /** retrieves the current MacroExecutionMode.
      47             : 
      48             :             Usually, this is initialized from the media descriptor used to load the document,
      49             :             respectively the one passed into the document's XModel::attachResource call.
      50             : 
      51             :             If no such mode was passed there, document implementations should return
      52             :             MacroExecMode::NEVER_EXECUTE.
      53             : 
      54             :             @see ::com::sun::star::document::MediaDescriptor::MacroExecutionMode
      55             :             @see ::com::sun::star::frame::XComponentLoader::loadComponentFromURL
      56             :             @see ::com::sun::star::frame::XModel::attachResource
      57             : 
      58             :             @see setCurrentMacroExecMode
      59             : 
      60             :             @todo
      61             :                 Effectively, this is the MacroExecutionMode of the MediaDescriptor of
      62             :                 the document. Thus, this setting could be obtained from the XModel
      63             :                 directly. We should introduce a getDocumentModel method here, which
      64             :                 can be used for this and other purposes.
      65             :         */
      66             :         virtual sal_Int16
      67             :                     getCurrentMacroExecMode() const = 0;
      68             : 
      69             :         /** sets the MacroExecutionMode of the document, as calculated by the DocumentMacroMode
      70             :             class.
      71             : 
      72             :             Effectively, the existence of this method means that the responsibility
      73             :             to store the current macro execution mode is not with the DocumentMacroMode
      74             :             instance, but with the document instance itself.
      75             : 
      76             :             Usually, a document implementation will simply put the macro execution mode
      77             :             into its media descriptor, as returned by XModel::getArgs.
      78             : 
      79             :             @see ::com::sun::star::document::MediaDescriptor::MacroExecutionMode
      80             :             @see ::com::sun::star::frame::XComponentLoader::loadComponentFromURL
      81             :             @see ::com::sun::star::frame::XModel::attachResource
      82             : 
      83             :             see getCurrentMacroExecMode
      84             :         */
      85             :         virtual bool
      86             :                     setCurrentMacroExecMode( sal_uInt16 ) = 0;
      87             : 
      88             :         /** returns the origin of the document
      89             : 
      90             :             This usually is the document's location, or, if the document has been
      91             :             newly created from a template, then the location of the template. Location
      92             :             here means the complete path of the document, including the file name.
      93             : 
      94             :             @todo
      95             :                 This probably can also be obtained from the XModel, by calling getURL
      96             :                 or getLocation. If both are empty, then we need an UNO way to obtain
      97             :                 the URL of the underlying template document - if any. If we have this,
      98             :                 we could replace this method with a newly introduced method
      99             :                 getDocumentModel and some internal code.
     100             :         */
     101             :         virtual OUString
     102             :                     getDocumentLocation() const = 0;
     103             : 
     104             :         /** returns a zip-storage based on the last commited version of the document,
     105             :             for readonly access
     106             : 
     107             :             The storage is intended to be used for signing. An implementation is
     108             :             allowed to return <NULL/> here if and only if the document
     109             :             does not support signing the script storages.
     110             : 
     111             :             @todo
     112             :                 UNOize this, too. Once we have a getDocumentModel, we should be able to
     113             :                 obtain the "last commit" storage via UNO API, provided it's an
     114             :                 XStorageBasedDocument.
     115             :         */
     116             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
     117             :                     getZipStorageToSign() = 0;
     118             : 
     119             :         /** checks whether the document's storage contains sub storages with macros or scripts
     120             : 
     121             :             A default implementation of this method will simply cann DocumentMacroMode::storageHasMacros
     122             :             with the document's root storage. However, there might be document types where this
     123             :             isn't sufficient (e.g. database documents which contain sub documents which can also
     124             :             contain macro/script storages).
     125             :         */
     126             :         virtual bool
     127             :                     documentStorageHasMacros() const = 0;
     128             : 
     129             :         /** provides access to the XEmbeddedScripts interface of the document
     130             : 
     131             :             Implementations are allowed to return <NULL/> here if and only if they
     132             :             do not (yet) support embedding scripts.
     133             : 
     134             :             @todo
     135             :                 can also be replaced with a call to the (to be introduced) getDocumentModel
     136             :                 method, and a queryInterface.
     137             :         */
     138             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::document::XEmbeddedScripts >
     139             :                     getEmbeddedDocumentScripts() const = 0;
     140             : 
     141             :         /** returns the state of the signatures for the scripts embedded in the document
     142             : 
     143             :             Note: On the medium run, the signature handling of a document should be outsourced
     144             :             into a dedicated class, instead of being hard-wired into the SfxObjectShell. This
     145             :             class could then be used outside the SfxObjectShell (e.g. in Base documents), too.
     146             :             When this happens, this method here becomes should be replaced by a method at this
     147             :             new class.
     148             : 
     149             :             @seealso <sfx2/signaturestate.hxx>
     150             :         */
     151             :         virtual sal_Int16
     152             :                     getScriptingSignatureState() = 0;
     153             : 
     154             :         /** allows to detect whether there is a trusted scripting signature
     155             : 
     156             :             Note: On the medium run, the signature handling of a document should be outsourced
     157             :             into a dedicated class, instead of being hard-wired into the SfxObjectShell. This
     158             :             class could then be used outside the SfxObjectShell (e.g. in Base documents), too.
     159             :             When this happens, this method here should be replaced by a method at this
     160             :             new class.
     161             : 
     162             :             @seealso <sfx2/signaturestate.hxx>
     163             :         */
     164             :         virtual bool
     165             :                     hasTrustedScriptingSignature( bool bAllowUIToAddAuthor ) = 0;
     166             : 
     167             :         /** shows a warning that the document's signature is broken
     168             : 
     169             :             Here, a similar note applies as to getScriptingSignatureState: This method doesn't
     170             :             really belong here. It's just there because SfxObjectShell_Impl::bSignatureErrorIsShown
     171             :             is not accessible where the method is called.
     172             :             So, once the signature handling has been oursourced from SfxObjectShell/_Impl, so it
     173             :             is re-usable in non-SFX contexts as well, this method here is also unneeded, probably.
     174             : 
     175             :             @param _rxInteraction
     176             :                 the interaction handler to use for showing the warning. It is exactly the same
     177             :                 as passed to DocumentMacroMode::adjustMacroMode, so it is <NULL/> if and
     178             :                 only if the instance passed to that method was <NULL/>.
     179             :         */
     180             :         virtual void
     181             :                     showBrokenSignatureWarning(
     182             :                         const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& _rxInteraction
     183             :                     ) const = 0;
     184             : 
     185             :     protected:
     186           0 :         ~IMacroDocumentAccess() {}
     187             :     };
     188             : 
     189             : 
     190             :     //= DocumentMacroMode
     191             : 
     192             :     struct DocumentMacroMode_Data;
     193             : 
     194             :     /** encapsulates handling the macro mode of a document
     195             : 
     196             :         @see com::sun::star::document::MacroExecMode
     197             :     */
     198           0 :     class SFX2_DLLPUBLIC DocumentMacroMode
     199             :     {
     200             :     public:
     201             :         /** creates an instance
     202             : 
     203             :         @param _rDocumentAccess
     204             :             access to the document which this instance works for. Must live as long as the
     205             :             DocumentMacroMode instance lives, at least
     206             :         */
     207             :         DocumentMacroMode( IMacroDocumentAccess& _rDocumentAccess );
     208             :         ~DocumentMacroMode();
     209             : 
     210             :         /** allows macro execution in the document
     211             : 
     212             :             Effectively, the macro mode is set to MacroExecMode::ALWAYS_EXECUTE_NO_WARN.
     213             : 
     214             :             @return
     215             :                 <TRUE/>, always
     216             :         */
     217             :         bool    allowMacroExecution();
     218             : 
     219             :         /** disallows macro execution in the document
     220             : 
     221             :             Effectively, the macro mode is set to MacroExecMode::NEVER_EXECUTE.
     222             : 
     223             :             @return
     224             :                 <TRUE/>, always
     225             :         */
     226             :         bool    disallowMacroExecution();
     227             : 
     228             :         /** checks whether the document allows executing contained macros.
     229             : 
     230             :             The method transforms the current macro execution mode into either
     231             :             ALWAYS_EXECUTE_NO_WARN or NEVER_EXECUTE, depending on the current value,
     232             :             possible configuration settings, and possible user interaction.
     233             : 
     234             :             @param _rxInteraction
     235             :                 A handler for interactions which might become necessary.
     236             :                 This includes
     237             :                 <ul><li>Asking the user for confirmation for macro execution.</li>
     238             :                     <li>Telling the user that macro execution is disabled.</li>
     239             :                 </ul>
     240             : 
     241             :                 If the user needs to be asked for macro execution confirmation, and if
     242             :                 this parameter is <NULL/>, the most defensive assumptions will be made,
     243             :                 effectively disabling macro execution.
     244             : 
     245             :             @return
     246             :                 <TRUE/> if and only if macro execution in this document is allowed.
     247             :         */
     248             :         bool    adjustMacroMode(
     249             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& _rxInteraction
     250             :                 );
     251             : 
     252             :         /** determines whether macro execution is disallowed
     253             : 
     254             :             There's a number of reasons why macro execution could be disallowed:
     255             :             <ul><li>Somebody called ->disallowMacroExecution</li>
     256             :                 <li>Macro execution is disabled globally, via the security options</li>
     257             :                 <li>Macro execution mode was not defined initially, and the user denied
     258             :                     executing macros for this particular document.</li>
     259             :             </ul>
     260             : 
     261             :             Note that if this method returns <FALSE/>, then subsequent calls of
     262             :             ->adjustMacroMode can still return <FALSE/>.
     263             :             That is, if the current macro execution mode for the document is not yet known
     264             :             (and inparticular <em>not</em> MacroExecMode::NEVER_EXECUTE), then ->isMacroExecutionDisallowed
     265             :             will return <FALSE/>.
     266             :             However, a subsequent call to ->adjustMacroMode can result in the user
     267             :             denying macro execution, in which ->adjustMacroMode will return <FALSE/>,
     268             :             and the next call to isMacroExecutionDisallowed will return <TRUE/>.
     269             :         */
     270             :         bool    isMacroExecutionDisallowed() const;
     271             : 
     272             :         /** determines whether the document actually has a macros library
     273             : 
     274             :             Effectively, this method checks the Basic library container (as returned by
     275             :             IMacroDocumentAccess::getEmbeddedDocumentScripts().getBasicLibraries) for
     276             :             content.
     277             :         */
     278             :         bool    hasMacroLibrary() const;
     279             : 
     280             :         /** determines whether the given document storage has sub storages containing scripts
     281             :             or macros.
     282             : 
     283             :             Effectively, the method checks for the presence of a sub-storage name "Scripts" (where
     284             :             BeanShell-/JavaScript-/Python-Scripts are stored, and a sub storage named "Basic" (where
     285             :             Basic scripts are stored).
     286             :         */
     287             :         static bool
     288             :                 storageHasMacros( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage );
     289             : 
     290             :         static bool containerHasBasicMacros( const ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer >& xContainter );
     291             :         /** checks the macro execution mode while loading the document.
     292             : 
     293             :             This must be called when the loading is effectively finished, but before any macro action
     294             :             happened.
     295             : 
     296             :             The method will disallow macro execution for this document if it is disabled
     297             :             globally (SvtSecurityOptions::IsMacroDisabled). Otherwise, it will check whether
     298             :             the document contains a macro storage or macro libraries. If so, it will
     299             :             properly calculate the MacroExecutionMode by calling adjustMacroMode.
     300             : 
     301             :             If the document doesn't contain macros, yet, then the macro execution for this
     302             :             document will be allowed (again: unless disabled globally), since in this case
     303             :             macros which later are newly created by the user should be allowed, of course.
     304             : 
     305             :             @return
     306             :                 <TRUE/> if and only if macro execution is allowed in the document
     307             : 
     308             :             @see isMacroExecutionDisallowed
     309             :             @see IMacroDocumentAccess::documentStorageHasMacros
     310             :             @see hasMacroLibrary
     311             :             @see IMacroDocumentAccess::checkForBrokenScriptingSignatures
     312             :         */
     313             :         bool
     314             :                 checkMacrosOnLoading(
     315             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& _rxInteraction
     316             :                 );
     317             : 
     318             :     private:
     319             :         ::boost::shared_ptr< DocumentMacroMode_Data >   m_pData;
     320             :     };
     321             : 
     322             : 
     323             : } // namespace sfx2
     324             : 
     325             : 
     326             : #endif // INCLUDED_SFX2_DOCMACROMODE_HXX
     327             : 
     328             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10