bump product version to 4.2.0.1
[LibreOffice.git] / include / sfx2 / docmacromode.hxx
blob095691c5b9d91418cc1c5a9002766f698a0d1a4f
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>
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>
30 #include <boost/shared_ptr.hpp>
32 //........................................................................
33 namespace sfx2
35 //........................................................................
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
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 ::com::sun::star::document::MediaDescriptor::MacroExecutionMode
55 @see ::com::sun::star::frame::XComponentLoader::loadComponentFromURL
56 @see ::com::sun::star::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 ::com::sun::star::document::MediaDescriptor::MacroExecutionMode
80 @see ::com::sun::star::frame::XComponentLoader::loadComponentFromURL
81 @see ::com::sun::star::frame::XModel::attachResource
83 see getCurrentMacroExecMode
85 virtual sal_Bool
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 /** returns a zip-storage based on the last commited version of the document,
105 for readonly access
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.
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.
116 virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
117 getZipStorageToSign() = 0;
119 /** checks whether the document's storage contains sub storages with macros or scripts
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).
126 virtual sal_Bool
127 documentStorageHasMacros() const = 0;
129 /** provides access to the XEmbeddedScripts interface of the document
131 Implementations are allowed to return <NULL/> here if and only if they
132 do not (yet) support embedding scripts.
134 @todo
135 can also be replaced with a call to the (to be introduced) getDocumentModel
136 method, and a queryInterface.
138 virtual ::com::sun::star::uno::Reference< ::com::sun::star::document::XEmbeddedScripts >
139 getEmbeddedDocumentScripts() const = 0;
141 /** returns the state of the signatures for the scripts embedded in the document
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.
149 @seealso <sfx2/signaturestate.hxx>
151 virtual sal_Int16
152 getScriptingSignatureState() = 0;
154 /** allows to detect whether there is a trusted scripting signature
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.
162 @seealso <sfx2/signaturestate.hxx>
164 virtual sal_Bool
165 hasTrustedScriptingSignature( sal_Bool bAllowUIToAddAuthor ) = 0;
167 /** shows a warning that the document's signature is broken
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.
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/>.
180 virtual void
181 showBrokenSignatureWarning(
182 const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& _rxInteraction
183 ) const = 0;
185 protected:
186 ~IMacroDocumentAccess() {}
189 //====================================================================
190 //= DocumentMacroMode
191 //====================================================================
192 struct DocumentMacroMode_Data;
194 /** encapsulates handling the macro mode of a document
196 @see com::sun::star::document::MacroExecMode
198 class SFX2_DLLPUBLIC DocumentMacroMode
200 public:
201 /** creates an instance
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
207 DocumentMacroMode( IMacroDocumentAccess& _rDocumentAccess );
208 ~DocumentMacroMode();
210 /** allows macro execution in the document
212 Effectively, the macro mode is set to MacroExecMode::ALWAYS_EXECUTE_NO_WARN.
214 @return
215 <TRUE/>, always
217 sal_Bool allowMacroExecution();
219 /** disallows macro execution in the document
221 Effectively, the macro mode is set to MacroExecMode::NEVER_EXECUTE.
223 @return
224 <TRUE/>, always
226 sal_Bool disallowMacroExecution();
228 /** checks whether the document allows executing contained macros.
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.
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>
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.
245 @return
246 <TRUE/> if and only if macro execution in this document is allowed.
248 sal_Bool adjustMacroMode(
249 const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& _rxInteraction
252 /** determines whether macro execution is disallowed
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>
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/>.
270 sal_Bool isMacroExecutionDisallowed() const;
272 /** determines whether the document actually has a macros library
274 Effectively, this method checks the Basic library container (as returned by
275 IMacroDocumentAccess::getEmbeddedDocumentScripts().getBasicLibraries) for
276 content.
278 sal_Bool hasMacroLibrary() const;
280 /** determines whether the given document storage has sub storages containing scripts
281 or macros.
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).
287 static sal_Bool
288 storageHasMacros( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage );
290 static sal_Bool containerHasBasicMacros( const ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer >& xContainter );
291 /** checks the macro execution mode while loading the document.
293 This must be called when the loading is effectively finished, but before any macro action
294 happened.
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.
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.
305 @return
306 <TRUE/> if and only if macro execution is allowed in the document
308 @see isMacroExecutionDisallowed
309 @see IMacroDocumentAccess::documentStorageHasMacros
310 @see hasMacroLibrary
311 @see IMacroDocumentAccess::checkForBrokenScriptingSignatures
313 sal_Bool
314 checkMacrosOnLoading(
315 const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& _rxInteraction
318 private:
319 ::boost::shared_ptr< DocumentMacroMode_Data > m_pData;
322 //........................................................................
323 } // namespace sfx2
324 //........................................................................
326 #endif // INCLUDED_SFX2_DOCMACROMODE_HXX
328 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */