LibreOffice Module sfx2 (master) 1
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
sfx2::DocumentMacroMode Class Reference

encapsulates handling the macro mode of a document More...

#include <docmacromode.hxx>

Public Member Functions

 DocumentMacroMode (IMacroDocumentAccess &_rDocumentAccess)
 creates an instance More...
 
bool allowMacroExecution ()
 allows macro execution in the document More...
 
bool disallowMacroExecution ()
 disallows macro execution in the document More...
 
bool adjustMacroMode (const css::uno::Reference< css::task::XInteractionHandler > &_rxInteraction, bool bHasValidContentSignature=false)
 checks whether the document allows executing contained macros. More...
 
bool isMacroExecutionDisallowed () const
 determines whether macro execution is disallowed More...
 
bool hasMacroLibrary () const
 determines whether the document actually has a macros library More...
 
bool hasUnsignedContentError () const
 
bool checkMacrosOnLoading (const css::uno::Reference< css::task::XInteractionHandler > &_rxInteraction, bool bHasValidContentSignature=false)
 checks the macro execution mode while loading the document. More...
 

Static Public Member Functions

static bool storageHasMacros (const css::uno::Reference< css::embed::XStorage > &_rxStorage)
 determines whether the given document storage has sub storages containing scripts or macros. More...
 
static bool containerHasBasicMacros (const css::uno::Reference< css::script::XLibraryContainer > &xContainer)
 

Private Attributes

std::shared_ptr< DocumentMacroMode_Datam_xData
 

Detailed Description

encapsulates handling the macro mode of a document

See also
css::document::MacroExecMode

Definition at line 173 of file docmacromode.hxx.

Constructor & Destructor Documentation

◆ DocumentMacroMode()

sfx2::DocumentMacroMode::DocumentMacroMode ( IMacroDocumentAccess _rDocumentAccess)

creates an instance

Parameters
_rDocumentAccessaccess to the document which this instance works for. Must live as long as the DocumentMacroMode instance lives, at least

Definition at line 95 of file docmacromode.cxx.

References make_shared().

Member Function Documentation

◆ adjustMacroMode()

bool sfx2::DocumentMacroMode::adjustMacroMode ( const css::uno::Reference< css::task::XInteractionHandler > &  _rxInteraction,
bool  bHasValidContentSignature = false 
)

checks whether the document allows executing contained macros.

The method transforms the current macro execution mode into either ALWAYS_EXECUTE_NO_WARN or NEVER_EXECUTE, depending on the current value, possible configuration settings, and possible user interaction.

Parameters
_rxInteractionA handler for interactions which might become necessary. This includes
  • Asking the user for confirmation for macro execution.
  • Telling the user that macro execution is disabled.

If the user needs to be asked for macro execution confirmation, and if this parameter is <NULL>, the most defensive assumptions will be made, effectively disabling macro execution.

Parameters
bHasValidContentSignatureWhether the document content is signed and the signature is valid.
Returns
<TRUE> if and only if macro execution in this document is allowed.

Definition at line 112 of file docmacromode.cxx.

References allowMacroExecution(), BROKEN, disallowMacroExecution(), Exception, SvtSecurityOptions::GetMacroSecurityLevel(), INetURLObject::GetMainURL(), SvtSecurityOptions::IsMacroDisabled(), SvtSecurityOptions::IsReadOnly(), m_xData, SvtSecurityOptions::MacroTrustedAuthors, INetURLObject::NONE, NOTVALIDATED, OK, and INetURLObject::removeSegment().

Referenced by checkMacrosOnLoading().

◆ allowMacroExecution()

bool sfx2::DocumentMacroMode::allowMacroExecution ( )

allows macro execution in the document

Effectively, the macro mode is set to MacroExecMode::ALWAYS_EXECUTE_NO_WARN.

Returns
<TRUE>, always

Definition at line 100 of file docmacromode.cxx.

References m_xData.

Referenced by adjustMacroMode(), and checkMacrosOnLoading().

◆ checkMacrosOnLoading()

bool sfx2::DocumentMacroMode::checkMacrosOnLoading ( const css::uno::Reference< css::task::XInteractionHandler > &  _rxInteraction,
bool  bHasValidContentSignature = false 
)

checks the macro execution mode while loading the document.

This must be called when the loading is effectively finished, but before any macro action happened.

The method will disallow macro execution for this document if it is disabled globally (SvtSecurityOptions::IsMacroDisabled). Otherwise, it will check whether the document contains a macro storage or macro libraries. If so, it will properly calculate the MacroExecutionMode by calling adjustMacroMode.

If the document doesn't contain macros, yet, then the macro execution for this document will be allowed (again: unless disabled globally), since in this case macros which later are newly created by the user should be allowed, of course.

Returns
<TRUE> if and only if macro execution is allowed in the document
See also
isMacroExecutionDisallowed
IMacroDocumentAccess::documentStorageHasMacros
IMacroDocumentAccess::macroCallsSeenWhileLoading
hasMacroLibrary
IMacroDocumentAccess::checkForBrokenScriptingSignatures

Definition at line 419 of file docmacromode.cxx.

References adjustMacroMode(), allowMacroExecution(), disallowMacroExecution(), hasMacroLibrary(), SvtSecurityOptions::IsMacroDisabled(), isMacroExecutionDisallowed(), and m_xData.

◆ containerHasBasicMacros()

bool sfx2::DocumentMacroMode::containerHasBasicMacros ( const css::uno::Reference< css::script::XLibraryContainer > &  xContainer)
static

Definition at line 323 of file docmacromode.cxx.

References Any, DBG_UNHANDLED_EXCEPTION, Exception, and u.

Referenced by hasMacroLibrary().

◆ disallowMacroExecution()

bool sfx2::DocumentMacroMode::disallowMacroExecution ( )

disallows macro execution in the document

Effectively, the macro mode is set to MacroExecMode::NEVER_EXECUTE.

Returns
<TRUE>, always

Definition at line 106 of file docmacromode.cxx.

References m_xData.

Referenced by adjustMacroMode(), and checkMacrosOnLoading().

◆ hasMacroLibrary()

bool sfx2::DocumentMacroMode::hasMacroLibrary ( ) const

determines whether the document actually has a macros library

Effectively, this method checks the Basic library container (as returned by IMacroDocumentAccess::getEmbeddedDocumentScripts().getBasicLibraries) for content.

Definition at line 365 of file docmacromode.cxx.

References containerHasBasicMacros(), DBG_UNHANDLED_EXCEPTION, Exception, and m_xData.

Referenced by SfxViewFrame::AppendContainsMacrosInfobar(), and checkMacrosOnLoading().

◆ hasUnsignedContentError()

bool sfx2::DocumentMacroMode::hasUnsignedContentError ( ) const

Definition at line 386 of file docmacromode.cxx.

References m_xData.

Referenced by SfxViewFrame::AppendContainsMacrosInfobar().

◆ isMacroExecutionDisallowed()

bool sfx2::DocumentMacroMode::isMacroExecutionDisallowed ( ) const

determines whether macro execution is disallowed

There's a number of reasons why macro execution could be disallowed:

  • Somebody called ->disallowMacroExecution
  • Macro execution is disabled globally, via the security options
  • Macro execution mode was not defined initially, and the user denied executing macros for this particular document.

Note that if this method returns <FALSE>, then subsequent calls of ->adjustMacroMode can still return <FALSE>. That is, if the current macro execution mode for the document is not yet known (and in particular not MacroExecMode::NEVER_EXECUTE), then ->isMacroExecutionDisallowed will return <FALSE>. However, a subsequent call to ->adjustMacroMode can result in the user denying macro execution, in which ->adjustMacroMode will return <FALSE>, and the next call to isMacroExecutionDisallowed will return <TRUE>.

Definition at line 317 of file docmacromode.cxx.

References m_xData.

Referenced by checkMacrosOnLoading().

◆ storageHasMacros()

bool sfx2::DocumentMacroMode::storageHasMacros ( const css::uno::Reference< css::embed::XStorage > &  _rxStorage)
static

determines whether the given document storage has sub storages containing scripts or macros.

Effectively, the method checks for the presence of a sub-storage name "Scripts" (where BeanShell-/JavaScript-/Python-Scripts are stored, and a sub storage named "Basic" (where Basic scripts are stored).

Definition at line 392 of file docmacromode.cxx.

References DBG_UNHANDLED_EXCEPTION, Exception, and u.

Member Data Documentation

◆ m_xData

std::shared_ptr< DocumentMacroMode_Data > sfx2::DocumentMacroMode::m_xData
private

The documentation for this class was generated from the following files: