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