Handle pasting disallowed clipboard contents on iOS
[LibreOffice.git] / include / sfx2 / docmacromode.hxx
blob2a0421aa0c90424a04a6119ec665423a1f0ac287
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/uno/Reference.hxx>
28 #include <memory>
30 namespace com::sun::star::document { class XEmbeddedScripts; }
31 namespace com::sun::star::embed { class XStorage; }
32 namespace com::sun::star::script { class XLibraryContainer; }
33 namespace com::sun::star::task { class XInteractionHandler; }
36 namespace sfx2
40 //= IMacroDocumentAccess
42 /** provides access to several settings of a document, which are needed by ->DocumentMacroMode
43 to properly determine the current macro execution mode of this document
45 class SAL_NO_VTABLE IMacroDocumentAccess
47 public:
48 /** retrieves the current MacroExecutionMode.
50 Usually, this is initialized from the media descriptor used to load the document,
51 respectively the one passed into the document's XModel::attachResource call.
53 If no such mode was passed there, document implementations should return
54 MacroExecMode::NEVER_EXECUTE.
56 @see css::document::MediaDescriptor::MacroExecutionMode
57 @see css::frame::XComponentLoader::loadComponentFromURL
58 @see css::frame::XModel::attachResource
60 @see setCurrentMacroExecMode
62 @todo
63 Effectively, this is the MacroExecutionMode of the MediaDescriptor of
64 the document. Thus, this setting could be obtained from the XModel
65 directly. We should introduce a getDocumentModel method here, which
66 can be used for this and other purposes.
68 virtual sal_Int16
69 getCurrentMacroExecMode() const = 0;
71 /** sets the MacroExecutionMode of the document, as calculated by the DocumentMacroMode
72 class.
74 Effectively, the existence of this method means that the responsibility
75 to store the current macro execution mode is not with the DocumentMacroMode
76 instance, but with the document instance itself.
78 Usually, a document implementation will simply put the macro execution mode
79 into its media descriptor, as returned by XModel::getArgs.
81 @see css::document::MediaDescriptor::MacroExecutionMode
82 @see css::frame::XComponentLoader::loadComponentFromURL
83 @see css::frame::XModel::attachResource
85 see getCurrentMacroExecMode
87 virtual void
88 setCurrentMacroExecMode( sal_uInt16 ) = 0;
90 /** returns the origin of the document
92 This usually is the document's location, or, if the document has been
93 newly created from a template, then the location of the template. Location
94 here means the complete path of the document, including the file name.
96 @todo
97 This probably can also be obtained from the XModel, by calling getURL
98 or getLocation. If both are empty, then we need a UNO way to obtain
99 the URL of the underlying template document - if any. If we have this,
100 we could replace this method with a newly introduced method
101 getDocumentModel and some internal code.
103 virtual OUString
104 getDocumentLocation() const = 0;
106 /** checks whether the document's storage contains sub storages with macros or scripts
108 A default implementation of this method will simply call DocumentMacroMode::storageHasMacros
109 with the document's root storage. However, there might be document types where this
110 isn't sufficient (e.g. database documents which contain sub documents which can also
111 contain macro/script storages).
113 virtual bool
114 documentStorageHasMacros() const = 0;
116 /** checks whether the document's contained calls to macros or scripts after loading
119 virtual bool
120 macroCallsSeenWhileLoading() const = 0;
122 /** provides access to the XEmbeddedScripts interface of the document
124 Implementations are allowed to return <NULL/> here if and only if they
125 do not (yet) support embedding scripts.
127 @todo
128 can also be replaced with a call to the (to be introduced) getDocumentModel
129 method, and a queryInterface.
131 virtual css::uno::Reference< css::document::XEmbeddedScripts >
132 getEmbeddedDocumentScripts() const = 0;
134 /** returns the state of the signatures for the scripts embedded in the document
136 Note: On the medium run, the signature handling of a document should be outsourced
137 into a dedicated class, instead of being hard-wired into the SfxObjectShell. This
138 class could then be used outside the SfxObjectShell (e.g. in Base documents), too.
139 When this happens, this method here becomes should be replaced by a method at this
140 new class.
142 @seealso <sfx2/signaturestate.hxx>
144 virtual SignatureState
145 getScriptingSignatureState() = 0;
147 /** allows to detect whether there is a trusted scripting signature
149 Note: On the medium run, the signature handling of a document should be outsourced
150 into a dedicated class, instead of being hard-wired into the SfxObjectShell. This
151 class could then be used outside the SfxObjectShell (e.g. in Base documents), too.
152 When this happens, this method here should be replaced by a method at this
153 new class.
155 @seealso <sfx2/signaturestate.hxx>
157 virtual bool
158 hasTrustedScriptingSignature( bool bAllowUIToAddAuthor ) = 0;
160 protected:
161 ~IMacroDocumentAccess() {}
165 //= DocumentMacroMode
167 struct DocumentMacroMode_Data;
169 /** encapsulates handling the macro mode of a document
171 @see css::document::MacroExecMode
173 class SFX2_DLLPUBLIC DocumentMacroMode
175 public:
176 /** creates an instance
178 @param _rDocumentAccess
179 access to the document which this instance works for. Must live as long as the
180 DocumentMacroMode instance lives, at least
182 DocumentMacroMode( IMacroDocumentAccess& _rDocumentAccess );
184 /** allows macro execution in the document
186 Effectively, the macro mode is set to MacroExecMode::ALWAYS_EXECUTE_NO_WARN.
188 @return
189 <TRUE/>, always
191 bool allowMacroExecution();
193 /** disallows macro execution in the document
195 Effectively, the macro mode is set to MacroExecMode::NEVER_EXECUTE.
197 @return
198 <TRUE/>, always
200 bool disallowMacroExecution();
202 /** checks whether the document allows executing contained macros.
204 The method transforms the current macro execution mode into either
205 ALWAYS_EXECUTE_NO_WARN or NEVER_EXECUTE, depending on the current value,
206 possible configuration settings, and possible user interaction.
208 @param _rxInteraction
209 A handler for interactions which might become necessary.
210 This includes
211 <ul><li>Asking the user for confirmation for macro execution.</li>
212 <li>Telling the user that macro execution is disabled.</li>
213 </ul>
215 If the user needs to be asked for macro execution confirmation, and if
216 this parameter is <NULL/>, the most defensive assumptions will be made,
217 effectively disabling macro execution.
219 @param bHasValidContentSignature
220 Whether the document content is signed and the signature is valid.
222 @return
223 <TRUE/> if and only if macro execution in this document is allowed.
225 bool adjustMacroMode(
226 const css::uno::Reference< css::task::XInteractionHandler >& _rxInteraction,
227 bool bHasValidContentSignature = false
230 /** determines whether macro execution is disallowed
232 There's a number of reasons why macro execution could be disallowed:
233 <ul><li>Somebody called ->disallowMacroExecution</li>
234 <li>Macro execution is disabled globally, via the security options</li>
235 <li>Macro execution mode was not defined initially, and the user denied
236 executing macros for this particular document.</li>
237 </ul>
239 Note that if this method returns <FALSE/>, then subsequent calls of
240 ->adjustMacroMode can still return <FALSE/>.
241 That is, if the current macro execution mode for the document is not yet known
242 (and in particular <em>not</em> MacroExecMode::NEVER_EXECUTE), then ->isMacroExecutionDisallowed
243 will return <FALSE/>.
244 However, a subsequent call to ->adjustMacroMode can result in the user
245 denying macro execution, in which ->adjustMacroMode will return <FALSE/>,
246 and the next call to isMacroExecutionDisallowed will return <TRUE/>.
248 bool isMacroExecutionDisallowed() const;
250 /** determines whether the document actually has a macros library
252 Effectively, this method checks the Basic library container (as returned by
253 IMacroDocumentAccess::getEmbeddedDocumentScripts().getBasicLibraries) for
254 content.
256 bool hasMacroLibrary() const;
258 bool hasUnsignedContentError() const;
260 /** determines whether the given document storage has sub storages containing scripts
261 or macros.
263 Effectively, the method checks for the presence of a sub-storage name "Scripts" (where
264 BeanShell-/JavaScript-/Python-Scripts are stored, and a sub storage named "Basic" (where
265 Basic scripts are stored).
267 static bool storageHasMacros( const css::uno::Reference< css::embed::XStorage >& _rxStorage );
269 static bool containerHasBasicMacros( const css::uno::Reference< css::script::XLibraryContainer >& xContainer );
270 /** checks the macro execution mode while loading the document.
272 This must be called when the loading is effectively finished, but before any macro action
273 happened.
275 The method will disallow macro execution for this document if it is disabled
276 globally (SvtSecurityOptions::IsMacroDisabled). Otherwise, it will check whether
277 the document contains a macro storage or macro libraries. If so, it will
278 properly calculate the MacroExecutionMode by calling adjustMacroMode.
280 If the document doesn't contain macros, yet, then the macro execution for this
281 document will be allowed (again: unless disabled globally), since in this case
282 macros which later are newly created by the user should be allowed, of course.
284 @return
285 <TRUE/> if and only if macro execution is allowed in the document
287 @see isMacroExecutionDisallowed
288 @see IMacroDocumentAccess::documentStorageHasMacros
289 @see IMacroDocumentAccess::macroCallsSeenWhileLoading
290 @see hasMacroLibrary
291 @see IMacroDocumentAccess::checkForBrokenScriptingSignatures
293 bool
294 checkMacrosOnLoading(
295 const css::uno::Reference< css::task::XInteractionHandler >& _rxInteraction,
296 bool bHasValidContentSignature = false
299 private:
300 std::shared_ptr< DocumentMacroMode_Data > m_xData;
304 } // namespace sfx2
307 #endif // INCLUDED_SFX2_DOCMACROMODE_HXX
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */