build fix
[LibreOffice.git] / include / sfx2 / docmacromode.hxx
blob01a1d7a3a593ce00ce193fae1a208143ffd5ca6b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SFX2_DOCMACROMODE_HXX
21 #define INCLUDED_SFX2_DOCMACROMODE_HXX
23 #include <sfx2/dllapi.h>
24 #include <sfx2/signaturestate.hxx>
26 #include <com/sun/star/task/XInteractionHandler.hpp>
27 #include <com/sun/star/embed/XStorage.hpp>
28 #include <com/sun/star/script/XLibraryContainer.hpp>
29 #include <com/sun/star/document/XEmbeddedScripts.hpp>
31 #include <memory>
34 namespace sfx2
38 //= IMacroDocumentAccess
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
43 class SAL_NO_VTABLE IMacroDocumentAccess
45 public:
46 /** retrieves the current MacroExecutionMode.
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.
51 If no such mode was passed there, document implementations should return
52 MacroExecMode::NEVER_EXECUTE.
54 @see css::document::MediaDescriptor::MacroExecutionMode
55 @see css::frame::XComponentLoader::loadComponentFromURL
56 @see css::frame::XModel::attachResource
58 @see setCurrentMacroExecMode
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.
66 virtual sal_Int16
67 getCurrentMacroExecMode() const = 0;
69 /** sets the MacroExecutionMode of the document, as calculated by the DocumentMacroMode
70 class.
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.
76 Usually, a document implementation will simply put the macro execution mode
77 into its media descriptor, as returned by XModel::getArgs.
79 @see css::document::MediaDescriptor::MacroExecutionMode
80 @see css::frame::XComponentLoader::loadComponentFromURL
81 @see css::frame::XModel::attachResource
83 see getCurrentMacroExecMode
85 virtual void
86 setCurrentMacroExecMode( sal_uInt16 ) = 0;
88 /** returns the origin of the document
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.
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.
101 virtual OUString
102 getDocumentLocation() const = 0;
104 /** checks whether the document's storage contains sub storages with macros or scripts
106 A default implementation of this method will simply cann DocumentMacroMode::storageHasMacros
107 with the document's root storage. However, there might be document types where this
108 isn't sufficient (e.g. database documents which contain sub documents which can also
109 contain macro/script storages).
111 virtual bool
112 documentStorageHasMacros() const = 0;
114 /** provides access to the XEmbeddedScripts interface of the document
116 Implementations are allowed to return <NULL/> here if and only if they
117 do not (yet) support embedding scripts.
119 @todo
120 can also be replaced with a call to the (to be introduced) getDocumentModel
121 method, and a queryInterface.
123 virtual css::uno::Reference< css::document::XEmbeddedScripts >
124 getEmbeddedDocumentScripts() const = 0;
126 /** returns the state of the signatures for the scripts embedded in the document
128 Note: On the medium run, the signature handling of a document should be outsourced
129 into a dedicated class, instead of being hard-wired into the SfxObjectShell. This
130 class could then be used outside the SfxObjectShell (e.g. in Base documents), too.
131 When this happens, this method here becomes should be replaced by a method at this
132 new class.
134 @seealso <sfx2/signaturestate.hxx>
136 virtual SignatureState
137 getScriptingSignatureState() = 0;
139 /** allows to detect whether there is a trusted scripting signature
141 Note: On the medium run, the signature handling of a document should be outsourced
142 into a dedicated class, instead of being hard-wired into the SfxObjectShell. This
143 class could then be used outside the SfxObjectShell (e.g. in Base documents), too.
144 When this happens, this method here should be replaced by a method at this
145 new class.
147 @seealso <sfx2/signaturestate.hxx>
149 virtual bool
150 hasTrustedScriptingSignature( bool bAllowUIToAddAuthor ) = 0;
152 /** shows a warning that the document's signature is broken
154 Here, a similar note applies as to getScriptingSignatureState: This method doesn't
155 really belong here. It's just there because SfxObjectShell_Impl::bSignatureErrorIsShown
156 is not accessible where the method is called.
157 So, once the signature handling has been oursourced from SfxObjectShell/_Impl, so it
158 is re-usable in non-SFX contexts as well, this method here is also unneeded, probably.
160 @param _rxInteraction
161 the interaction handler to use for showing the warning. It is exactly the same
162 as passed to DocumentMacroMode::adjustMacroMode, so it is <NULL/> if and
163 only if the instance passed to that method was <NULL/>.
165 virtual void
166 showBrokenSignatureWarning(
167 const css::uno::Reference< css::task::XInteractionHandler >& _rxInteraction
168 ) const = 0;
170 protected:
171 ~IMacroDocumentAccess() {}
175 //= DocumentMacroMode
177 struct DocumentMacroMode_Data;
179 /** encapsulates handling the macro mode of a document
181 @see css::document::MacroExecMode
183 class SFX2_DLLPUBLIC DocumentMacroMode
185 public:
186 /** creates an instance
188 @param _rDocumentAccess
189 access to the document which this instance works for. Must live as long as the
190 DocumentMacroMode instance lives, at least
192 DocumentMacroMode( IMacroDocumentAccess& _rDocumentAccess );
194 /** allows macro execution in the document
196 Effectively, the macro mode is set to MacroExecMode::ALWAYS_EXECUTE_NO_WARN.
198 @return
199 <TRUE/>, always
201 bool allowMacroExecution();
203 /** disallows macro execution in the document
205 Effectively, the macro mode is set to MacroExecMode::NEVER_EXECUTE.
207 @return
208 <TRUE/>, always
210 bool disallowMacroExecution();
212 /** checks whether the document allows executing contained macros.
214 The method transforms the current macro execution mode into either
215 ALWAYS_EXECUTE_NO_WARN or NEVER_EXECUTE, depending on the current value,
216 possible configuration settings, and possible user interaction.
218 @param _rxInteraction
219 A handler for interactions which might become necessary.
220 This includes
221 <ul><li>Asking the user for confirmation for macro execution.</li>
222 <li>Telling the user that macro execution is disabled.</li>
223 </ul>
225 If the user needs to be asked for macro execution confirmation, and if
226 this parameter is <NULL/>, the most defensive assumptions will be made,
227 effectively disabling macro execution.
229 @return
230 <TRUE/> if and only if macro execution in this document is allowed.
232 bool adjustMacroMode(
233 const css::uno::Reference< css::task::XInteractionHandler >& _rxInteraction
236 /** determines whether macro execution is disallowed
238 There's a number of reasons why macro execution could be disallowed:
239 <ul><li>Somebody called ->disallowMacroExecution</li>
240 <li>Macro execution is disabled globally, via the security options</li>
241 <li>Macro execution mode was not defined initially, and the user denied
242 executing macros for this particular document.</li>
243 </ul>
245 Note that if this method returns <FALSE/>, then subsequent calls of
246 ->adjustMacroMode can still return <FALSE/>.
247 That is, if the current macro execution mode for the document is not yet known
248 (and inparticular <em>not</em> MacroExecMode::NEVER_EXECUTE), then ->isMacroExecutionDisallowed
249 will return <FALSE/>.
250 However, a subsequent call to ->adjustMacroMode can result in the user
251 denying macro execution, in which ->adjustMacroMode will return <FALSE/>,
252 and the next call to isMacroExecutionDisallowed will return <TRUE/>.
254 bool isMacroExecutionDisallowed() const;
256 /** determines whether the document actually has a macros library
258 Effectively, this method checks the Basic library container (as returned by
259 IMacroDocumentAccess::getEmbeddedDocumentScripts().getBasicLibraries) for
260 content.
262 bool hasMacroLibrary() const;
264 /** determines whether the given document storage has sub storages containing scripts
265 or macros.
267 Effectively, the method checks for the presence of a sub-storage name "Scripts" (where
268 BeanShell-/JavaScript-/Python-Scripts are stored, and a sub storage named "Basic" (where
269 Basic scripts are stored).
271 static bool storageHasMacros( const css::uno::Reference< css::embed::XStorage >& _rxStorage );
273 static bool containerHasBasicMacros( const css::uno::Reference< css::script::XLibraryContainer >& xContainter );
274 /** checks the macro execution mode while loading the document.
276 This must be called when the loading is effectively finished, but before any macro action
277 happened.
279 The method will disallow macro execution for this document if it is disabled
280 globally (SvtSecurityOptions::IsMacroDisabled). Otherwise, it will check whether
281 the document contains a macro storage or macro libraries. If so, it will
282 properly calculate the MacroExecutionMode by calling adjustMacroMode.
284 If the document doesn't contain macros, yet, then the macro execution for this
285 document will be allowed (again: unless disabled globally), since in this case
286 macros which later are newly created by the user should be allowed, of course.
288 @return
289 <TRUE/> if and only if macro execution is allowed in the document
291 @see isMacroExecutionDisallowed
292 @see IMacroDocumentAccess::documentStorageHasMacros
293 @see hasMacroLibrary
294 @see IMacroDocumentAccess::checkForBrokenScriptingSignatures
296 bool
297 checkMacrosOnLoading(
298 const css::uno::Reference< css::task::XInteractionHandler >& _rxInteraction
301 private:
302 std::shared_ptr< DocumentMacroMode_Data > m_xData;
306 } // namespace sfx2
309 #endif // INCLUDED_SFX2_DOCMACROMODE_HXX
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */